Commit ee93aa8a authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

gnt-network: Fix CLI issues with node groups



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: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 3fe5484a
......@@ -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,
......
......@@ -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.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment