diff --git a/lib/cli.py b/lib/cli.py index 14c6c928924982caeb4b859b79b979715841fc5c..566dc47d6e4dbe9e3d12b080782e4e2b7d3d8cfb 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -99,6 +99,7 @@ __all__ = [ "NIC_PARAMS_OPT", "NODE_LIST_OPT", "NODE_PLACEMENT_OPT", + "NODEGROUP_OPT", "NODRBD_STORAGE_OPT", "NOHDR_OPT", "NOIPCHECK_OPT", @@ -737,6 +738,13 @@ NODE_LIST_OPT = cli_option("-n", "--node", dest="nodes", default=[], " times, if not given defaults to all nodes)", completion_suggest=OPT_COMPL_ONE_NODE) +NODEGROUP_OPT = cli_option("-g", "--nodegroup", + dest="nodegroup", + help="Node group (name or uuid)", + metavar="<nodegroup>", + default=None, type="string", + completion_suggest=OPT_COMPL_ONE_NODEGROUP) + SINGLE_NODE_OPT = cli_option("-n", "--node", dest="node", help="Target node", metavar="<node>", completion_suggest=OPT_COMPL_ONE_NODE) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index a13a8beb39ab0141b8f8bca0b2257e8e0be8e184..91957b799633f7a0eaf5088b0efe314c73902db8 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -3668,6 +3668,7 @@ class LUAddNode(LogicalUnit): ("primary_ip", None, _NoType), ("secondary_ip", None, _TMaybeString), ("readd", False, _TBool), + ("nodegroup", None, _TMaybeString) ] def CheckArguments(self): @@ -3676,6 +3677,9 @@ class LUAddNode(LogicalUnit): self.hostname = netutils.GetHostname(name=self.op.node_name, family=self.primary_ip_family) self.op.node_name = self.hostname.name + if self.op.readd and self.op.nodegroup: + raise errors.OpPrereqError("Cannot pass a nodegroup when a node is" + " being readded", errors.ECODE_INVAL) def BuildHooksEnv(self): """Build hooks env. @@ -3790,8 +3794,7 @@ class LUAddNode(LogicalUnit): self.new_node = self.cfg.GetNodeInfo(node) assert self.new_node is not None, "Can't retrieve locked node %s" % node else: - # TODO: process an arbitrary non-default nodegroup - nodegroup = cfg.LookupNodeGroup(None) + nodegroup = cfg.LookupNodeGroup(self.op.nodegroup) self.new_node = objects.Node(name=node, primary_ip=primary_ip, secondary_ip=secondary_ip, diff --git a/lib/opcodes.py b/lib/opcodes.py index 0f633b67faf6d3a49f4f2493c816d70f3752f04f..043f8288c1b13471bcfd9b35ce00f68ade4283ed 100644 --- a/lib/opcodes.py +++ b/lib/opcodes.py @@ -363,7 +363,7 @@ class OpAddNode(OpCode): """ OP_ID = "OP_NODE_ADD" OP_DSC_FIELD = "node_name" - __slots__ = ["node_name", "primary_ip", "secondary_ip", "readd"] + __slots__ = ["node_name", "primary_ip", "secondary_ip", "readd", "nodegroup"] class OpQueryNodes(OpCode): diff --git a/man/gnt-node.sgml b/man/gnt-node.sgml index ae4720b332942944dc83fe0d167da366fa3fd9b8..d1cc18c177aef38b9fa0518778f198a4e2d55cb8 100644 --- a/man/gnt-node.sgml +++ b/man/gnt-node.sgml @@ -64,6 +64,7 @@ <command>add</command> <arg>--readd</arg> <arg>-s <replaceable>secondary_ip</replaceable></arg> + <arg>-g <replaceable>nodegroup</replaceable></arg> <arg choice="req"><replaceable>nodename</replaceable></arg> </cmdsynopsis> @@ -103,11 +104,18 @@ before re-adding it. </para> + <para> + The <option>-g</option> is used to add the new node into a specific + node group, specified by uuid or name. If only one node group exists + you can skip this option, otherwise it's mandatory. + </para> + <para> Example: <screen> # gnt-node add node5.example.com # gnt-node add -s 192.0.2.5 node5.example.com +# gnt-node add -g group2 -s 192.0.2.9 node9.group2.example.com </screen> </para> </refsect2> diff --git a/scripts/gnt-node b/scripts/gnt-node index 114bc2e81f866226e3bbd13673f87ce8ae583882..cd17ad034899fa6ae77bb9994c8d75765a6e6f01 100755 --- a/scripts/gnt-node +++ b/scripts/gnt-node @@ -214,7 +214,7 @@ def AddNode(opts, args): bootstrap.SetupNodeDaemon(cluster_name, node, opts.ssh_key_check) op = opcodes.OpAddNode(node_name=args[0], secondary_ip=sip, - readd=opts.readd) + readd=opts.readd, nodegroup=opts.nodegroup) SubmitOpCode(op, opts=opts) @@ -674,7 +674,7 @@ commands = { 'add': ( AddNode, [ArgHost(min=1, max=1)], [SECONDARY_IP_OPT, READD_OPT, NOSSH_KEYCHECK_OPT, NONODE_SETUP_OPT, - VERBOSE_OPT], + VERBOSE_OPT, NODEGROUP_OPT], "[-s ip] [--readd] [--no-ssh-key-check] [--no-node-setup] [--verbose] " " <node_name>", "Add a node to the cluster"),