Revision 702243ec lib/cmdlib/group.py
b/lib/cmdlib/group.py | ||
---|---|---|
38 | 38 |
MergeAndVerifyDiskState, GetWantedNodes, GetUpdatedParams, \ |
39 | 39 |
CheckNodeGroupInstances, GetUpdatedIPolicy, \ |
40 | 40 |
ComputeNewInstanceViolations, GetDefaultIAllocator, ShareAll, \ |
41 |
CheckInstancesNodeGroups, LoadNodeEvacResult, MapInstanceLvsToNodes |
|
41 |
CheckInstancesNodeGroups, LoadNodeEvacResult, MapInstanceLvsToNodes, \ |
|
42 |
CheckIpolicyVsDiskTemplates |
|
42 | 43 |
|
43 | 44 |
import ganeti.masterd.instance |
44 | 45 |
|
... | ... | |
59 | 60 |
self.needed_locks = {} |
60 | 61 |
self.add_locks[locking.LEVEL_NODEGROUP] = self.group_uuid |
61 | 62 |
|
63 |
def _CheckIpolicy(self): |
|
64 |
"""Checks the group's ipolicy for consistency and validity. |
|
65 |
|
|
66 |
""" |
|
67 |
if self.op.ipolicy: |
|
68 |
cluster = self.cfg.GetClusterInfo() |
|
69 |
full_ipolicy = cluster.SimpleFillIPolicy(self.op.ipolicy) |
|
70 |
try: |
|
71 |
objects.InstancePolicy.CheckParameterSyntax(full_ipolicy, False) |
|
72 |
except errors.ConfigurationError, err: |
|
73 |
raise errors.OpPrereqError("Invalid instance policy: %s" % err, |
|
74 |
errors.ECODE_INVAL) |
|
75 |
CheckIpolicyVsDiskTemplates(full_ipolicy, |
|
76 |
cluster.enabled_disk_templates) |
|
77 |
|
|
62 | 78 |
def CheckPrereq(self): |
63 | 79 |
"""Check prerequisites. |
64 | 80 |
|
... | ... | |
103 | 119 |
else: |
104 | 120 |
self.new_diskparams = {} |
105 | 121 |
|
106 |
if self.op.ipolicy: |
|
107 |
cluster = self.cfg.GetClusterInfo() |
|
108 |
full_ipolicy = cluster.SimpleFillIPolicy(self.op.ipolicy) |
|
109 |
try: |
|
110 |
objects.InstancePolicy.CheckParameterSyntax(full_ipolicy, False) |
|
111 |
except errors.ConfigurationError, err: |
|
112 |
raise errors.OpPrereqError("Invalid instance policy: %s" % err, |
|
113 |
errors.ECODE_INVAL) |
|
122 |
self._CheckIpolicy() |
|
114 | 123 |
|
115 | 124 |
def BuildHooksEnv(self): |
116 | 125 |
"""Build hooks env. |
... | ... | |
427 | 436 |
utils.ForceDictType(new_params, constants.DISK_DT_TYPES) |
428 | 437 |
return new_params |
429 | 438 |
|
439 |
def _CheckIpolicy(self, cluster, owned_instance_names): |
|
440 |
"""Sanity checks for the ipolicy. |
|
441 |
|
|
442 |
@type cluster: C{objects.Cluster} |
|
443 |
@param cluster: the cluster's configuration |
|
444 |
@type owned_instance_names: list of string |
|
445 |
@param owned_instance_names: list of instances |
|
446 |
|
|
447 |
""" |
|
448 |
if self.op.ipolicy: |
|
449 |
self.new_ipolicy = GetUpdatedIPolicy(self.group.ipolicy, |
|
450 |
self.op.ipolicy, |
|
451 |
group_policy=True) |
|
452 |
|
|
453 |
new_ipolicy = cluster.SimpleFillIPolicy(self.new_ipolicy) |
|
454 |
CheckIpolicyVsDiskTemplates(new_ipolicy, |
|
455 |
cluster.enabled_disk_templates) |
|
456 |
instances = self.cfg.GetMultiInstanceInfoByName(owned_instance_names) |
|
457 |
gmi = ganeti.masterd.instance |
|
458 |
violations = \ |
|
459 |
ComputeNewInstanceViolations(gmi.CalculateGroupIPolicy(cluster, |
|
460 |
self.group), |
|
461 |
new_ipolicy, instances, self.cfg) |
|
462 |
|
|
463 |
if violations: |
|
464 |
self.LogWarning("After the ipolicy change the following instances" |
|
465 |
" violate them: %s", |
|
466 |
utils.CommaJoin(violations)) |
|
467 |
|
|
430 | 468 |
def CheckPrereq(self): |
431 | 469 |
"""Check prerequisites. |
432 | 470 |
|
... | ... | |
475 | 513 |
MergeAndVerifyDiskState(self.op.disk_state, |
476 | 514 |
self.group.disk_state_static) |
477 | 515 |
|
478 |
if self.op.ipolicy: |
|
479 |
self.new_ipolicy = GetUpdatedIPolicy(self.group.ipolicy, |
|
480 |
self.op.ipolicy, |
|
481 |
group_policy=True) |
|
482 |
|
|
483 |
new_ipolicy = cluster.SimpleFillIPolicy(self.new_ipolicy) |
|
484 |
instances = self.cfg.GetMultiInstanceInfoByName(owned_instance_names) |
|
485 |
gmi = ganeti.masterd.instance |
|
486 |
violations = \ |
|
487 |
ComputeNewInstanceViolations(gmi.CalculateGroupIPolicy(cluster, |
|
488 |
self.group), |
|
489 |
new_ipolicy, instances, self.cfg) |
|
490 |
|
|
491 |
if violations: |
|
492 |
self.LogWarning("After the ipolicy change the following instances" |
|
493 |
" violate them: %s", |
|
494 |
utils.CommaJoin(violations)) |
|
516 |
self._CheckIpolicy(cluster, owned_instance_names) |
|
495 | 517 |
|
496 | 518 |
def BuildHooksEnv(self): |
497 | 519 |
"""Build hooks env. |
Also available in: Unified diff