#
#
-# Copyright (C) 2010, 2011 Google Inc.
+# Copyright (C) 2010, 2011, 2012 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
from ganeti.cli import *
from ganeti import constants
+from ganeti import objects
from ganeti import opcodes
from ganeti import utils
@return: the desired exit code
"""
+ ipolicy = \
+ objects.CreateIPolicyFromOpts(ispecs_mem_size=opts.ispecs_mem_size,
+ ispecs_cpu_count=opts.ispecs_cpu_count,
+ ispecs_disk_count=opts.ispecs_disk_count,
+ ispecs_disk_size=opts.ispecs_disk_size,
+ ispecs_nic_count=opts.ispecs_nic_count,
+ group_ipolicy=True)
+
(group_name,) = args
diskparams = dict(opts.diskparams)
+
+ if opts.disk_state:
+ disk_state = utils.FlatToDict(opts.disk_state)
+ else:
+ disk_state = {}
+ hv_state = dict(opts.hv_state)
+
op = opcodes.OpGroupAdd(group_name=group_name, ndparams=opts.ndparams,
alloc_policy=opts.alloc_policy,
- diskparams=diskparams)
+ diskparams=diskparams, ipolicy=ipolicy,
+ hv_state=hv_state,
+ disk_state=disk_state)
SubmitOpCode(op, opts=opts)
@return: the desired exit code
"""
- if (opts.ndparams is None and opts.alloc_policy is None
- and not opts.diskparams):
+ allmods = [opts.ndparams, opts.alloc_policy, opts.diskparams, opts.hv_state,
+ opts.disk_state, opts.ispecs_mem_size, opts.ispecs_cpu_count,
+ opts.ispecs_disk_count, opts.ispecs_disk_size,
+ opts.ispecs_nic_count, opts.diskparams]
+ if allmods.count(None) == len(allmods):
ToStderr("Please give at least one of the parameters.")
return 1
+ if opts.disk_state:
+ disk_state = utils.FlatToDict(opts.disk_state)
+ else:
+ disk_state = {}
+
+ hv_state = dict(opts.hv_state)
+
diskparams = dict(opts.diskparams)
+
+ # set the default values
+ to_ipolicy = [
+ opts.ispecs_mem_size,
+ opts.ispecs_cpu_count,
+ opts.ispecs_disk_count,
+ opts.ispecs_disk_size,
+ opts.ispecs_nic_count,
+ ]
+ for ispec in to_ipolicy:
+ for param in ispec:
+ if isinstance(ispec[param], basestring):
+ if ispec[param].lower() == "default":
+ ispec[param] = constants.VALUE_DEFAULT
+ # create ipolicy object
+ ipolicy = objects.CreateIPolicyFromOpts(\
+ ispecs_mem_size=opts.ispecs_mem_size,
+ ispecs_cpu_count=opts.ispecs_cpu_count,
+ ispecs_disk_count=opts.ispecs_disk_count,
+ ispecs_disk_size=opts.ispecs_disk_size,
+ ispecs_nic_count=opts.ispecs_nic_count,
+ ipolicy_disk_templates=opts.ipolicy_disk_templates,
+ group_ipolicy=True,
+ allowed_values=[constants.VALUE_DEFAULT])
+
op = opcodes.OpGroupSetParams(group_name=args[0],
ndparams=opts.ndparams,
alloc_policy=opts.alloc_policy,
- diskparams=diskparams)
+ hv_state=hv_state,
+ disk_state=disk_state,
+ diskparams=diskparams,
+ ipolicy=ipolicy)
+
result = SubmitOrSend(op, opts)
if result:
return rcode
-
commands = {
"add": (
AddGroup, ARGS_ONE_GROUP,
- [DRY_RUN_OPT, ALLOC_POLICY_OPT, NODE_PARAMS_OPT, DISK_PARAMS_OPT],
+ [DRY_RUN_OPT, ALLOC_POLICY_OPT, NODE_PARAMS_OPT, DISK_PARAMS_OPT,
+ HV_STATE_OPT, DISK_STATE_OPT] + INSTANCE_POLICY_OPTS,
"<group_name>", "Add a new node group to the cluster"),
"assign-nodes": (
AssignNodes, ARGS_ONE_GROUP + ARGS_MANY_NODES, [DRY_RUN_OPT, FORCE_OPT],
"Lists all available fields for node groups"),
"modify": (
SetGroupParams, ARGS_ONE_GROUP,
- [DRY_RUN_OPT, SUBMIT_OPT, ALLOC_POLICY_OPT, NODE_PARAMS_OPT,
- DISK_PARAMS_OPT],
+ [DRY_RUN_OPT, SUBMIT_OPT, ALLOC_POLICY_OPT, NODE_PARAMS_OPT, HV_STATE_OPT,
+ DISK_STATE_OPT, DISK_PARAMS_OPT] + INSTANCE_POLICY_OPTS,
"<group_name>", "Alters the parameters of a node group"),
"remove": (
RemoveGroup, ARGS_ONE_GROUP, [DRY_RUN_OPT],