Revision 33a6464e lib/cmdlib/cluster.py
b/lib/cmdlib/cluster.py | ||
---|---|---|
789 | 789 |
enabled_disk_templates = cluster.enabled_disk_templates |
790 | 790 |
return (enabled_disk_templates, new_enabled_disk_templates) |
791 | 791 |
|
792 |
def _CheckIpolicy(self, cluster): |
|
792 |
@staticmethod |
|
793 |
def _CheckIpolicyVsDiskTemplates(ipolicy, enabled_disk_templates): |
|
794 |
"""Checks ipolicy disk templates against enabled disk tempaltes. |
|
795 |
|
|
796 |
@type ipolicy: dict |
|
797 |
@param ipolicy: the new ipolicy |
|
798 |
@type enabled_disk_templates: list of string |
|
799 |
@param enabled_disk_templates: list of enabled disk templates on the |
|
800 |
cluster |
|
801 |
@rtype: errors.OpPrereqError |
|
802 |
@raises: exception if there is at least one allowed disk template that |
|
803 |
is not also enabled. |
|
804 |
|
|
805 |
""" |
|
806 |
assert constants.IPOLICY_DTS in ipolicy |
|
807 |
allowed_disk_templates = ipolicy[constants.IPOLICY_DTS] |
|
808 |
not_enabled = [] |
|
809 |
for allowed_disk_template in allowed_disk_templates: |
|
810 |
if not allowed_disk_template in enabled_disk_templates: |
|
811 |
not_enabled.append(allowed_disk_template) |
|
812 |
if not_enabled: |
|
813 |
raise errors.OpPrereqError("The following disk template are allowed" |
|
814 |
" by the ipolicy, but not enabled on the" |
|
815 |
" cluster: %s" % utils.CommaJoin(not_enabled)) |
|
816 |
|
|
817 |
def _CheckIpolicy(self, cluster, enabled_disk_templates): |
|
793 | 818 |
"""Checks the ipolicy. |
794 | 819 |
|
795 | 820 |
@type cluster: C{objects.Cluster} |
796 | 821 |
@param cluster: the cluster's configuration |
822 |
@type enabled_disk_templates: list of string |
|
823 |
@param enabled_disk_templates: list of (possibly newly) enabled disk |
|
824 |
templates |
|
797 | 825 |
|
798 | 826 |
""" |
827 |
# FIXME: write unit tests for this |
|
799 | 828 |
if self.op.ipolicy: |
800 | 829 |
self.new_ipolicy = GetUpdatedIPolicy(cluster.ipolicy, self.op.ipolicy, |
801 | 830 |
group_policy=False) |
802 | 831 |
|
832 |
self._CheckIpolicyVsDiskTemplates(self.new_ipolicy, |
|
833 |
enabled_disk_templates) |
|
834 |
|
|
803 | 835 |
all_instances = self.cfg.GetAllInstancesInfo().values() |
804 | 836 |
violations = set() |
805 | 837 |
for group in self.cfg.GetAllNodeGroupsInfo().values(): |
... | ... | |
817 | 849 |
self.LogWarning("After the ipolicy change the following instances" |
818 | 850 |
" violate them: %s", |
819 | 851 |
utils.CommaJoin(utils.NiceSort(violations))) |
852 |
else: |
|
853 |
self._CheckIpolicyVsDiskTemplates(cluster.ipolicy, |
|
854 |
enabled_disk_templates) |
|
820 | 855 |
|
821 | 856 |
def CheckPrereq(self): |
822 | 857 |
"""Check prerequisites. |
... | ... | |
902 | 937 |
for name, values in svalues.items())) |
903 | 938 |
for storage, svalues in new_disk_state.items()) |
904 | 939 |
|
905 |
self._CheckIpolicy(cluster) |
|
940 |
self._CheckIpolicy(cluster, enabled_disk_templates)
|
|
906 | 941 |
|
907 | 942 |
if self.op.nicparams: |
908 | 943 |
utils.ForceDictType(self.op.nicparams, constants.NICS_PARAMETER_TYPES) |
Also available in: Unified diff