errors.ECODE_INVAL)
+def _RestrictIpolicyToEnabledDiskTemplates(ipolicy, enabled_disk_templates):
+ """Restricts the ipolicy's disk templates to the enabled ones.
+
+ This function clears the ipolicy's list of allowed disk templates from the
+ ones that are not enabled by the cluster.
+
+ @type ipolicy: dict
+ @param ipolicy: the instance policy
+ @type enabled_disk_templates: list of string
+ @param enabled_disk_templates: the list of cluster-wide enabled disk
+ templates
+
+ """
+ assert constants.IPOLICY_DTS in ipolicy
+ allowed_disk_templates = ipolicy[constants.IPOLICY_DTS]
+ restricted_disk_templates = list(set(allowed_disk_templates)
+ .intersection(set(enabled_disk_templates)))
+ ipolicy[constants.IPOLICY_DTS] = restricted_disk_templates
+
+
+def _InitCheckDrbdHelper(drbd_helper, drbd_enabled):
+ """Checks the DRBD usermode helper.
+
+ @type drbd_helper: string
+ @param drbd_helper: name of the DRBD usermode helper that the system should
+ use
+
+ """
+ if not drbd_enabled:
+ return
+
+ if drbd_helper is not None:
+ try:
+ curr_helper = drbd.DRBD8.GetUsermodeHelper()
+ except errors.BlockDeviceError, err:
+ raise errors.OpPrereqError("Error while checking drbd helper"
+ " (disable drbd with --enabled-disk-templates"
+ " if you are not using drbd): %s" % str(err),
+ errors.ECODE_ENVIRON)
+ if drbd_helper != curr_helper:
+ raise errors.OpPrereqError("Error: requiring %s as drbd helper but %s"
+ " is the current helper" % (drbd_helper,
+ curr_helper),
+ errors.ECODE_INVAL)
+
+
def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913, R0914
master_netmask, master_netdev, file_storage_dir,
shared_file_storage_dir, candidate_pool_size, secondary_ip=None,
if vgstatus:
raise errors.OpPrereqError("Error: %s" % vgstatus, errors.ECODE_INVAL)
- if drbd_helper is not None:
- try:
- curr_helper = drbd.DRBD8.GetUsermodeHelper()
- except errors.BlockDeviceError, err:
- raise errors.OpPrereqError("Error while checking drbd helper"
- " (specify --no-drbd-storage if you are not"
- " using drbd): %s" % str(err),
- errors.ECODE_ENVIRON)
- if drbd_helper != curr_helper:
- raise errors.OpPrereqError("Error: requiring %s as drbd helper but %s"
- " is the current helper" % (drbd_helper,
- curr_helper),
- errors.ECODE_INVAL)
+ drbd_enabled = constants.DT_DRBD8 in enabled_disk_templates
+ _InitCheckDrbdHelper(drbd_helper, drbd_enabled)
logging.debug("Stopping daemons (if any are running)")
result = utils.RunCmd([pathutils.DAEMON_UTIL, "stop-all"])
objects.NIC.CheckParameterSyntax(nicparams)
full_ipolicy = objects.FillIPolicy(constants.IPOLICY_DEFAULTS, ipolicy)
+ _RestrictIpolicyToEnabledDiskTemplates(full_ipolicy, enabled_disk_templates)
if ndparams is not None:
utils.ForceDictType(ndparams, constants.NDS_PARAMETER_TYPES)