def AddGroup(opts, args): """Add a node group to the cluster. @param opts: the command line options selected by the user @type args: list @param args: a list of length 1 with the name of the group to create @rtype: int @return: the desired exit code """ ipolicy = CreateIPolicyFromOpts( minmax_ispecs=opts.ipolicy_bounds_specs, ipolicy_vcpu_ratio=opts.ipolicy_vcpu_ratio, ipolicy_spindle_ratio=opts.ipolicy_spindle_ratio, ipolicy_disk_templates=opts.ipolicy_disk_templates, 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, ipolicy=ipolicy, hv_state=hv_state, disk_state=disk_state) SubmitOrSend(op, opts)
def SetNodeParams(opts, args): """Modifies a node. @param opts: the command line options selected by the user @type args: list @param args: should contain only one element, the node name @rtype: int @return: the desired exit code """ all_changes = [opts.master_candidate, opts.drained, opts.offline, opts.master_capable, opts.vm_capable, opts.secondary_ip, opts.ndparams] if (all_changes.count(None) == len(all_changes) and not (opts.hv_state or opts.disk_state)): 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 = {} # Comparing explicitly to false to distinguish between a parameter # modification that doesn't set the node online (where the value will be None) # and modifying the node to bring it online. if opts.offline is False: usertext = ("You are setting this node online manually. If the" " configuration has changed, this can cause issues such as" " split brain. To safely bring a node back online, please use" " --readd instead. If you are confident that the configuration" " hasn't changed, continue?") if not AskUser(usertext): return 1 hv_state = dict(opts.hv_state) op = opcodes.OpNodeSetParams(node_name=args[0], master_candidate=opts.master_candidate, offline=opts.offline, drained=opts.drained, master_capable=opts.master_capable, vm_capable=opts.vm_capable, secondary_ip=opts.secondary_ip, force=opts.force, ndparams=opts.ndparams, auto_promote=opts.auto_promote, powered=opts.node_powered, hv_state=hv_state, disk_state=disk_state) # even if here we process the result, we allow submit only result = SubmitOrSend(op, opts) if result: ToStdout("Modified node %s", args[0]) for param, data in result: ToStdout(" - %-5s -> %s", param, data) return 0
def SetGroupParams(opts, args): """Modifies a node group's parameters. @param opts: the command line options selected by the user @type args: list @param args: should contain only one element, the node group name @rtype: int @return: the desired exit code """ allmods = [ opts.ndparams, opts.alloc_policy, opts.diskparams, opts.hv_state, opts.disk_state, opts.ipolicy_bounds_specs, opts.ipolicy_vcpu_ratio, opts.ipolicy_spindle_ratio, opts.diskparams, opts.ipolicy_disk_templates ] 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) # create ipolicy object ipolicy = CreateIPolicyFromOpts( minmax_ispecs=opts.ipolicy_bounds_specs, ipolicy_disk_templates=opts.ipolicy_disk_templates, ipolicy_vcpu_ratio=opts.ipolicy_vcpu_ratio, ipolicy_spindle_ratio=opts.ipolicy_spindle_ratio, group_ipolicy=True, allowed_values=[constants.VALUE_DEFAULT]) op = opcodes.OpGroupSetParams(group_name=args[0], ndparams=opts.ndparams, alloc_policy=opts.alloc_policy, hv_state=hv_state, disk_state=disk_state, diskparams=diskparams, ipolicy=ipolicy) result = SubmitOrSend(op, opts) if result: ToStdout("Modified node group %s", args[0]) for param, data in result: ToStdout(" - %-5s -> %s", param, data) return 0
def SetNodeParams(opts, args): """Modifies a node. @param opts: the command line options selected by the user @type args: list @param args: should contain only one element, the node name @rtype: int @return: the desired exit code """ all_changes = [ opts.master_candidate, opts.drained, opts.offline, opts.master_capable, opts.vm_capable, opts.secondary_ip, opts.ndparams ] if (all_changes.count(None) == len(all_changes) and not (opts.hv_state or opts.disk_state)): 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) op = opcodes.OpNodeSetParams(node_name=args[0], master_candidate=opts.master_candidate, offline=opts.offline, drained=opts.drained, master_capable=opts.master_capable, vm_capable=opts.vm_capable, secondary_ip=opts.secondary_ip, force=opts.force, ndparams=opts.ndparams, auto_promote=opts.auto_promote, powered=opts.node_powered, hv_state=hv_state, disk_state=disk_state, verbose=opts.verbose, debug=opts.debug > 0) # even if here we process the result, we allow submit only result = SubmitOrSend(op, opts) if result: ToStdout("Modified node %s", args[0]) for param, data in result: ToStdout(" - %-5s -> %s", param, data) return 0
def AddNode(opts, args): """Add a node to the cluster. @param opts: the command line options selected by the user @type args: list @param args: should contain only one element, the new node name @rtype: int @return: the desired exit code """ cl = GetClient() node = netutils.GetHostname(name=args[0]).name readd = opts.readd # Retrieve relevant parameters of the node group. ssh_port = None try: # Passing [] to QueryGroups means query the default group: node_groups = [opts.nodegroup] if opts.nodegroup is not None else [] output = cl.QueryGroups(names=node_groups, fields=["ndp/ssh_port"], use_locking=False) (ssh_port, ) = output[0] except (errors.OpPrereqError, errors.OpExecError): pass try: output = cl.QueryNodes(names=[node], fields=["name", "sip", "master", "ndp/ssh_port"], use_locking=False) if len(output) == 0: node_exists = "" sip = None else: node_exists, sip, is_master, ssh_port = output[0] except (errors.OpPrereqError, errors.OpExecError): node_exists = "" sip = None if readd: if not node_exists: ToStderr("Node %s not in the cluster" " - please retry without '--readd'", node) return 1 if is_master: ToStderr("Node %s is the master, cannot readd", node) return 1 else: if node_exists: ToStderr("Node %s already in the cluster (as %s)" " - please retry with '--readd'", node, node_exists) return 1 sip = opts.secondary_ip # read the cluster name from the master (cluster_name, ) = cl.QueryConfigValues(["cluster_name"]) if opts.node_setup: ToStderr("-- WARNING -- \n" "Performing this operation is going to perform the following\n" "changes to the target machine (%s) and the current cluster\n" "nodes:\n" "* A new SSH daemon key pair is generated is generated on\n" " the target machine.\n" "* The public SSH keys of all master candidates of the cluster\n" " are added to the target machine's 'authorized_keys' file.\n" "* In case the target machine is a master candidate, its newly\n" " generated public SSH key will be distributed to all other\n" " cluster nodes.\n", node) if opts.node_setup: _SetupSSH(opts, cluster_name, node, ssh_port, cl) bootstrap.SetupNodeDaemon(opts, cluster_name, node, ssh_port) if opts.disk_state: disk_state = utils.FlatToDict(opts.disk_state) else: disk_state = {} hv_state = dict(opts.hv_state) op = opcodes.OpNodeAdd(node_name=args[0], secondary_ip=sip, readd=opts.readd, group=opts.nodegroup, vm_capable=opts.vm_capable, ndparams=opts.ndparams, master_capable=opts.master_capable, disk_state=disk_state, hv_state=hv_state, node_setup=opts.node_setup) SubmitOpCode(op, opts=opts)
def AddNode(opts, args): """Add a node to the cluster. @param opts: the command line options selected by the user @type args: list @param args: should contain only one element, the new node name @rtype: int @return: the desired exit code """ cl = GetClient() query_cl = GetClient(query=True) node = netutils.GetHostname(name=args[0]).name readd = opts.readd # Retrieve relevant parameters of the node group. ssh_port = None try: # Passing [] to QueryGroups means query the default group: node_groups = [opts.nodegroup] if opts.nodegroup is not None else [] output = query_cl.QueryGroups(names=node_groups, fields=["ndp/ssh_port"], use_locking=False) (ssh_port, ) = output[0] except (errors.OpPrereqError, errors.OpExecError): pass try: output = query_cl.QueryNodes( names=[node], fields=["name", "sip", "master", "ndp/ssh_port"], use_locking=False) node_exists, sip, is_master, ssh_port = output[0] except (errors.OpPrereqError, errors.OpExecError): node_exists = "" sip = None if readd: if not node_exists: ToStderr( "Node %s not in the cluster" " - please retry without '--readd'", node) return 1 if is_master: ToStderr("Node %s is the master, cannot readd", node) return 1 else: if node_exists: ToStderr( "Node %s already in the cluster (as %s)" " - please retry with '--readd'", node, node_exists) return 1 sip = opts.secondary_ip # read the cluster name from the master (cluster_name, ) = cl.QueryConfigValues(["cluster_name"]) if not readd and opts.node_setup: ToStderr( "-- WARNING -- \n" "Performing this operation is going to replace the ssh daemon" " keypair\n" "on the target machine (%s) with the ones of the" " current one\n" "and grant full intra-cluster ssh root access to/from it\n", node) if opts.node_setup: _SetupSSH(opts, cluster_name, node, ssh_port) bootstrap.SetupNodeDaemon(opts, cluster_name, node, ssh_port) if opts.disk_state: disk_state = utils.FlatToDict(opts.disk_state) else: disk_state = {} hv_state = dict(opts.hv_state) op = opcodes.OpNodeAdd(node_name=args[0], secondary_ip=sip, readd=opts.readd, group=opts.nodegroup, vm_capable=opts.vm_capable, ndparams=opts.ndparams, master_capable=opts.master_capable, disk_state=disk_state, hv_state=hv_state) SubmitOpCode(op, opts=opts)