- op = opcodes.OpInitCluster(cluster_name=args[0],
- secondary_ip=opts.secondary_ip,
- hypervisor_type=opts.hypervisor_type,
- vg_name=vg_name,
- mac_prefix=opts.mac_prefix,
- def_bridge=opts.def_bridge,
- master_netdev=opts.master_netdev,
- file_storage_dir=opts.file_storage_dir)
- SubmitOpCode(op)
+ hvlist = opts.enabled_hypervisors
+ if hvlist is not None:
+ hvlist = hvlist.split(",")
+ else:
+ hvlist = [constants.DEFAULT_ENABLED_HYPERVISOR]
+
+ # avoid an impossible situation
+ if opts.default_hypervisor in hvlist:
+ default_hypervisor = opts.default_hypervisor
+ else:
+ default_hypervisor = hvlist[0]
+
+ hvparams = opts.hvparams
+ if hvparams:
+ # a list of (name, dict) we can pass directly to dict()
+ hvparams = dict(opts.hvparams)
+ else:
+ # otherwise init as empty dict
+ hvparams = {}
+
+ beparams = opts.beparams
+ # check for invalid parameters
+ for parameter in beparams:
+ if parameter not in constants.BES_PARAMETERS:
+ ToStderr("Invalid backend parameter: %s", parameter)
+ return 1
+
+ # prepare beparams dict
+ for parameter in constants.BES_PARAMETERS:
+ if parameter not in beparams:
+ beparams[parameter] = constants.BEC_DEFAULTS[parameter]
+
+ # type wrangling
+ try:
+ beparams[constants.BE_VCPUS] = int(beparams[constants.BE_VCPUS])
+ except ValueError:
+ ToStderr("%s must be an integer", constants.BE_VCPUS)
+ return 1
+
+ if not isinstance(beparams[constants.BE_MEMORY], int):
+ beparams[constants.BE_MEMORY] = utils.ParseUnit(
+ beparams[constants.BE_MEMORY])
+
+ # prepare hvparams dict
+ for hv in constants.HYPER_TYPES:
+ if hv not in hvparams:
+ hvparams[hv] = {}
+ for parameter in constants.HVC_DEFAULTS[hv]:
+ if parameter not in hvparams[hv]:
+ hvparams[hv][parameter] = constants.HVC_DEFAULTS[hv][parameter]
+
+ for hv in hvlist:
+ if hv not in constants.HYPER_TYPES:
+ ToStderr("invalid hypervisor: %s", hv)
+ return 1
+
+ bootstrap.InitCluster(cluster_name=args[0],
+ secondary_ip=opts.secondary_ip,
+ vg_name=vg_name,
+ mac_prefix=opts.mac_prefix,
+ def_bridge=opts.def_bridge,
+ master_netdev=opts.master_netdev,
+ file_storage_dir=opts.file_storage_dir,
+ enabled_hypervisors=hvlist,
+ default_hypervisor=default_hypervisor,
+ hvparams=hvparams,
+ beparams=beparams)