Revision 892b5258 lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
16231 | 16231 |
|
16232 | 16232 |
assert self.group_uuid in owned_groups |
16233 | 16233 |
|
16234 |
l = lambda value: utils.CommaJoin("%s: %s/%s" % (i[0], i[1], i[2]) |
|
16235 |
for i in value) |
|
16236 |
|
|
16237 | 16234 |
self.netparams = { |
16238 | 16235 |
constants.NIC_MODE: self.network_mode, |
16239 | 16236 |
constants.NIC_LINK: self.network_link, |
... | ... | |
16251 | 16248 |
return |
16252 | 16249 |
|
16253 | 16250 |
if self.op.conflicts_check: |
16254 |
# Check if locked instances are still correct |
|
16255 |
owned_instances = frozenset(self.owned_locks(locking.LEVEL_INSTANCE)) |
|
16256 |
_CheckNodeGroupInstances(self.cfg, self.group_uuid, owned_instances) |
|
16257 |
|
|
16258 |
nobj = self.cfg.GetNetwork(self.network_uuid) |
|
16259 |
pool = network.AddressPool(nobj) |
|
16260 |
conflicting_instances = [] |
|
16261 |
|
|
16262 |
for (_, instance) in self.cfg.GetMultiInstanceInfo(owned_instances): |
|
16263 |
for idx, nic in enumerate(instance.nics): |
|
16264 |
if pool.Contains(nic.ip): |
|
16265 |
conflicting_instances.append((instance.name, idx, nic.ip)) |
|
16266 |
|
|
16267 |
if conflicting_instances: |
|
16268 |
self.LogWarning("Following occurences use IPs from network %s" |
|
16269 |
" that is about to connect to nodegroup %s: %s" % |
|
16270 |
(self.network_name, self.group.name, |
|
16271 |
l(conflicting_instances))) |
|
16272 |
raise errors.OpPrereqError("Conflicting IPs found." |
|
16273 |
" Please remove/modify" |
|
16274 |
" corresponding NICs", |
|
16275 |
errors.ECODE_INVAL) |
|
16251 |
pool = network.AddressPool(self.cfg.GetNetwork(self.network_uuid)) |
|
16252 |
|
|
16253 |
_NetworkConflictCheck(self, lambda nic: pool.Contains(nic.ip), |
|
16254 |
"connect to") |
|
16276 | 16255 |
|
16277 | 16256 |
def Exec(self, feedback_fn): |
16278 | 16257 |
if self.connected: |
... | ... | |
16282 | 16261 |
self.cfg.Update(self.group, feedback_fn) |
16283 | 16262 |
|
16284 | 16263 |
|
16264 |
def _NetworkConflictCheck(lu, check_fn, action): |
|
16265 |
"""Checks for network interface conflicts with a network. |
|
16266 |
|
|
16267 |
@type lu: L{LogicalUnit} |
|
16268 |
@type check_fn: callable receiving one parameter (L{objects.NIC}) and |
|
16269 |
returning boolean |
|
16270 |
@param check_fn: Function checking for conflict |
|
16271 |
@type action: string |
|
16272 |
@param action: Part of error message (see code) |
|
16273 |
@raise errors.OpPrereqError: If conflicting IP addresses are found. |
|
16274 |
|
|
16275 |
""" |
|
16276 |
# Check if locked instances are still correct |
|
16277 |
owned_instances = frozenset(lu.owned_locks(locking.LEVEL_INSTANCE)) |
|
16278 |
_CheckNodeGroupInstances(lu.cfg, lu.group_uuid, owned_instances) |
|
16279 |
|
|
16280 |
conflicts = [] |
|
16281 |
|
|
16282 |
for (_, instance) in lu.cfg.GetMultiInstanceInfo(owned_instances): |
|
16283 |
instconflicts = [(idx, nic.ip) |
|
16284 |
for (idx, nic) in enumerate(instance.nics) |
|
16285 |
if check_fn(nic)] |
|
16286 |
|
|
16287 |
if instconflicts: |
|
16288 |
conflicts.append((instance.name, instconflicts)) |
|
16289 |
|
|
16290 |
if conflicts: |
|
16291 |
lu.LogWarning("IP addresses from network '%s', which is about to %s" |
|
16292 |
" node group '%s', are in use: %s" % |
|
16293 |
(lu.network_name, action, lu.group.name, |
|
16294 |
utils.CommaJoin(("%s: %s" % |
|
16295 |
(name, _FmtNetworkConflict(details))) |
|
16296 |
for (name, details) in conflicts))) |
|
16297 |
|
|
16298 |
raise errors.OpPrereqError("Conflicting IP addresses found; " |
|
16299 |
" remove/modify the corresponding network" |
|
16300 |
" interfaces", errors.ECODE_INVAL) |
|
16301 |
|
|
16302 |
|
|
16303 |
def _FmtNetworkConflict(details): |
|
16304 |
"""Utility for L{_NetworkConflictCheck}. |
|
16305 |
|
|
16306 |
""" |
|
16307 |
return utils.CommaJoin("nic%s/%s" % (idx, ipaddr) |
|
16308 |
for (idx, ipaddr) in details) |
|
16309 |
|
|
16310 |
|
|
16285 | 16311 |
class LUNetworkDisconnect(LogicalUnit): |
16286 | 16312 |
"""Disconnect a network to a nodegroup |
16287 | 16313 |
|
... | ... | |
16335 | 16361 |
|
16336 | 16362 |
assert self.group_uuid in owned_groups |
16337 | 16363 |
|
16338 |
l = lambda value: utils.CommaJoin("%s: %s/%s" % (i[0], i[1], i[2]) |
|
16339 |
for i in value) |
|
16340 |
|
|
16341 | 16364 |
self.group = self.cfg.GetNodeGroup(self.group_uuid) |
16342 | 16365 |
self.connected = True |
16343 | 16366 |
if self.network_uuid not in self.group.networks: |
... | ... | |
16347 | 16370 |
return |
16348 | 16371 |
|
16349 | 16372 |
if self.op.conflicts_check: |
16350 |
# Check if locked instances are still correct |
|
16351 |
owned_instances = frozenset(self.owned_locks(locking.LEVEL_INSTANCE)) |
|
16352 |
_CheckNodeGroupInstances(self.cfg, self.group_uuid, owned_instances) |
|
16353 |
|
|
16354 |
conflicting_instances = [] |
|
16355 |
|
|
16356 |
for (_, instance) in self.cfg.GetMultiInstanceInfo(owned_instances): |
|
16357 |
for idx, nic in enumerate(instance.nics): |
|
16358 |
if nic.network == self.network_name: |
|
16359 |
conflicting_instances.append((instance.name, idx, nic.ip)) |
|
16360 |
|
|
16361 |
if conflicting_instances: |
|
16362 |
self.LogWarning("Following occurences use IPs from network %s" |
|
16363 |
" that is about to disconnected from the nodegroup" |
|
16364 |
" %s: %s" % |
|
16365 |
(self.network_name, self.group.name, |
|
16366 |
l(conflicting_instances))) |
|
16367 |
raise errors.OpPrereqError("Conflicting IPs." |
|
16368 |
" Please remove/modify" |
|
16369 |
" corresponding NICS", |
|
16370 |
errors.ECODE_INVAL) |
|
16373 |
_NetworkConflictCheck(self, lambda nic: nic.network == self.network_name, |
|
16374 |
"disconnect from") |
|
16371 | 16375 |
|
16372 | 16376 |
def Exec(self, feedback_fn): |
16373 | 16377 |
if not self.connected: |
Also available in: Unified diff