1 |
1 |
#
|
2 |
2 |
#
|
3 |
3 |
|
4 |
|
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Google Inc.
|
|
4 |
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Google Inc.
|
5 |
5 |
#
|
6 |
6 |
# This program is free software; you can redistribute it and/or modify
|
7 |
7 |
# it under the terms of the GNU General Public License as published by
|
... | ... | |
28 |
28 |
from ganeti import errors
|
29 |
29 |
from ganeti import locking
|
30 |
30 |
from ganeti import objects
|
|
31 |
from ganeti import opcodes
|
31 |
32 |
from ganeti import utils
|
32 |
33 |
from ganeti.masterd import iallocator
|
33 |
34 |
from ganeti.cmdlib.base import LogicalUnit, NoHooksLU, ResultWithJobs
|
... | ... | |
134 |
135 |
mn = self.cfg.GetMasterNode()
|
135 |
136 |
return ([mn], [mn])
|
136 |
137 |
|
|
138 |
@staticmethod
|
|
139 |
def _ConnectInstanceCommunicationNetwork(cfg, group_uuid, network_name):
|
|
140 |
"""Connect a node group to the instance communication network.
|
|
141 |
|
|
142 |
The group is connected to the instance communication network via
|
|
143 |
the Opcode 'OpNetworkConnect'.
|
|
144 |
|
|
145 |
@type cfg: L{ganeti.config.ConfigWriter}
|
|
146 |
@param cfg: Ganeti configuration
|
|
147 |
|
|
148 |
@type group_uuid: string
|
|
149 |
@param group_uuid: UUID of the group to connect
|
|
150 |
|
|
151 |
@type network_name: string
|
|
152 |
@param network_name: name of the network to connect to
|
|
153 |
|
|
154 |
@rtype: L{ganeti.cmdlib.ResultWithJobs} or L{None}
|
|
155 |
@return: L{ganeti.cmdlib.ResultWithJobs} if the group needs to be
|
|
156 |
connected, otherwise (the group is already connected)
|
|
157 |
L{None}
|
|
158 |
|
|
159 |
"""
|
|
160 |
jobs = []
|
|
161 |
|
|
162 |
try:
|
|
163 |
cfg.LookupNetwork(network_name)
|
|
164 |
network_exists = True
|
|
165 |
except errors.OpPrereqError:
|
|
166 |
network_exists = False
|
|
167 |
|
|
168 |
if network_exists:
|
|
169 |
op = opcodes.OpNetworkConnect(
|
|
170 |
group_name=group_uuid,
|
|
171 |
network_name=network_name,
|
|
172 |
network_mode=constants.NIC_MODE_ROUTED,
|
|
173 |
network_link=constants.INSTANCE_COMMUNICATION_NETWORK_LINK,
|
|
174 |
conflicts_check=True)
|
|
175 |
jobs.append(op)
|
|
176 |
|
|
177 |
if jobs:
|
|
178 |
return ResultWithJobs([jobs])
|
|
179 |
else:
|
|
180 |
return None
|
|
181 |
|
137 |
182 |
def Exec(self, feedback_fn):
|
138 |
183 |
"""Add the node group to the cluster.
|
139 |
184 |
|
... | ... | |
150 |
195 |
self.cfg.AddNodeGroup(group_obj, self.proc.GetECId(), check_uuid=False)
|
151 |
196 |
del self.remove_locks[locking.LEVEL_NODEGROUP]
|
152 |
197 |
|
|
198 |
network_name = self.cfg.GetClusterInfo().instance_communication_network
|
|
199 |
if network_name:
|
|
200 |
return self._ConnectInstanceCommunicationNetwork(self.cfg,
|
|
201 |
self.group_uuid,
|
|
202 |
network_name)
|
|
203 |
|
153 |
204 |
|
154 |
205 |
class LUGroupAssignNodes(NoHooksLU):
|
155 |
206 |
"""Logical unit for assigning nodes to groups.
|