From 5fbbd0284883b85d969895db041760be8f6ddc02 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Fri, 10 Sep 2010 16:56:50 +0100 Subject: [PATCH] Add nodegroup option to AddNode Signed-off-by: Guido Trotter <ultrotter@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/cli.py | 8 ++++++++ lib/cmdlib.py | 7 +++++-- lib/opcodes.py | 2 +- man/gnt-node.sgml | 8 ++++++++ scripts/gnt-node | 4 ++-- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/cli.py b/lib/cli.py index 14c6c9289..566dc47d6 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 a13a8beb3..91957b799 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 0f633b67f..043f8288c 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 ae4720b33..d1cc18c17 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 114bc2e81..cd17ad034 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"), -- GitLab