@raise errors.OpPrereqError: if the item is not found
"""
- full_name = expand_fn(name)
- if full_name is None:
+ (uuid, full_name) = expand_fn(name)
+ if uuid is None or full_name is None:
raise errors.OpPrereqError("%s '%s' not known" % (kind, name),
errors.ECODE_NOENT)
- return full_name
+ return (uuid, full_name)
def ExpandInstanceUuidAndName(cfg, expected_uuid, name):
"""
assert disk_template is not None
- assert disk_template in constants.DISK_TEMPLATES
+ if disk_template not in constants.DISK_TEMPLATES:
+ raise errors.OpPrereqError("'%s' is not a valid disk template."
+ " Valid disk templates are: %s" %
+ (disk_template,
+ ",".join(constants.DISK_TEMPLATES)))
if not disk_template in cluster.enabled_disk_templates:
raise errors.OpPrereqError("Disk template '%s' is not enabled in cluster."
" Enabled disk templates are: %s" %
"""
assert storage_type is not None
- assert storage_type in constants.VALID_STORAGE_TYPES
+ assert storage_type in constants.STORAGE_TYPES
# special case for lvm-pv, because it cannot be enabled
# via disk templates
if storage_type == constants.ST_LVM_PV:
" enabled in this cluster. Enabled disk"
" templates are: %s" % (storage_type,
",".join(cluster.enabled_disk_templates)))
+
+
+def CheckIpolicyVsDiskTemplates(ipolicy, enabled_disk_templates):
+ """Checks ipolicy disk templates against enabled disk tempaltes.
+
+ @type ipolicy: dict
+ @param ipolicy: the new ipolicy
+ @type enabled_disk_templates: list of string
+ @param enabled_disk_templates: list of enabled disk templates on the
+ cluster
+ @raises errors.OpPrereqError: if there is at least one allowed disk
+ template that is not also enabled.
+
+ """
+ assert constants.IPOLICY_DTS in ipolicy
+ allowed_disk_templates = ipolicy[constants.IPOLICY_DTS]
+ not_enabled = set(allowed_disk_templates) - set(enabled_disk_templates)
+ if not_enabled:
+ raise errors.OpPrereqError("The following disk template are allowed"
+ " by the ipolicy, but not enabled on the"
+ " cluster: %s" % utils.CommaJoin(not_enabled))