From ee93aa8aa67ef66b935ae369f974e28659cdb060 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Thu, 20 Dec 2012 14:06:26 +0100 Subject: [PATCH] gnt-network: Fix CLI issues with node groups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The original implementation reserved the name βallβ to specify all node groups. That would prevent the use of a node group actually named βallβ. This patch changes the order and definition of the command line arguments for βgnt-network connectβ and ββ¦ disconnectβ to have the group(s) as the last argument(s). If no groups are specified all groups are used. Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Guido Trotter <ultrotter@google.com> --- lib/client/gnt_network.py | 43 ++++++++++++++++++--------------------- man/gnt-network.rst | 16 ++++++++------- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/lib/client/gnt_network.py b/lib/client/gnt_network.py index 00c08ad66..34273707a 100644 --- a/lib/client/gnt_network.py +++ b/lib/client/gnt_network.py @@ -83,25 +83,23 @@ def AddNetwork(opts, args): SubmitOrSend(op, opts) -def MapNetwork(opts, args): +def ConnectNetwork(opts, args): """Map a network to a node group. @param opts: the command line options selected by the user @type args: list - @param args: a list of length 3 with network, nodegroup, mode, physlink + @param args: Network, mode, physlink and node groups @rtype: int @return: the desired exit code """ - (network, groups, mode, link) = args + (network, mode, link) = args[:3] + groups = args[3:] cl = GetClient() - # FIXME: This doesn't work with a group named "all" - if groups == "all": - (groups, ) = cl.QueryGroups([], ["name"], False) - else: - groups = [groups] + if not groups: + (groups, ) = cl.QueryGroups([], ["uuid"], False) # TODO: Change logic to support "--submit" for group in groups: @@ -113,25 +111,23 @@ def MapNetwork(opts, args): SubmitOpCode(op, opts=opts, cl=cl) -def UnmapNetwork(opts, args): +def DisconnectNetwork(opts, args): """Unmap a network from a node group. @param opts: the command line options selected by the user @type args: list - @param args: a list of length 3 with network, nodegroup + @param args: Network and node groups @rtype: int @return: the desired exit code """ - (network, groups) = args + (network, ) = args[:1] + groups = args[1:] cl = GetClient() - # FIXME: This doesn't work with a group named "all" - if groups == "all": - (groups, ) = cl.QueryGroups([], ["name"], False) - else: - groups = [groups] + if not groups: + (groups, ) = cl.QueryGroups([], ["uuid"], False) # TODO: Change logic to support "--submit" for group in groups: @@ -327,19 +323,20 @@ commands = { PRIORITY_OPT], "<network_name>", "Alters the parameters of a network"), "connect": ( - MapNetwork, - [ArgNetwork(min=1, max=1), ArgGroup(min=1, max=1), + ConnectNetwork, + [ArgNetwork(min=1, max=1), ArgChoice(min=1, max=1, choices=constants.NIC_VALID_MODES), - ArgUnknown(min=1, max=1)], + ArgUnknown(min=1, max=1), + ArgGroup()], [NOCONFLICTSCHECK_OPT, PRIORITY_OPT], - "<network_name> <node_group> <mode> <link>", + "<network_name> <mode> <link> [<node_group>...]", "Map a given network to the specified node group" " with given mode and link (netparams)"), "disconnect": ( - UnmapNetwork, - [ArgNetwork(min=1, max=1), ArgGroup(min=1, max=1)], + DisconnectNetwork, + [ArgNetwork(min=1, max=1), ArgGroup()], [NOCONFLICTSCHECK_OPT, PRIORITY_OPT], - "<network_name> <node_group>", + "<network_name> [<node_group>...]", "Unmap a given network from a specified node group"), "remove": ( RemoveNetwork, ARGS_ONE_NETWORK, diff --git a/man/gnt-network.rst b/man/gnt-network.rst index d8400cab4..305ad231d 100644 --- a/man/gnt-network.rst +++ b/man/gnt-network.rst @@ -163,15 +163,17 @@ Displays information about a given network. CONNECT ~~~~~~~ -| **connect** {*network*} {*group*} {*mode*} {*link*} -Connect a network to a given nodegroup with the netparams (*mode*, *link*). -Every nic will inherit those netparams if assigned in a network. -*group* can be ``all`` if you want to connect to all existing nodegroups +| **connect** {*network*} {*mode*} {*link*} [*groups*...] + +Connect a network to given node groups (all if not specified) with the network +parameters *mode* and *link*. Every network interface will inherit those +parameters if assigned in a network. DISCONNECT ~~~~~~~~~~ -| **disconnect** {*network*} {*group*} -Disconnect a network to a nodegroup. This is possible only if no instance -is using the network. +| **disconnect** {*network*} [*groups*...] + +Disconnect a network from given node groups (all if not specified). This is +possible only if no instance is using the network. -- GitLab