Skip to content
Snippets Groups Projects
Commit 286d0218 authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis Committed by Michael Hanselmann
Browse files

Handle the result of QueryGroups() correctly


If no group is given for the “gnt-network connect“/“… disconnect”
commands, the client uses the result of “QueryGroups()” which is a list
of lists. Use “itertools.chain()” to handle the return value correctly.

Signed-off-by: default avatarDimitris Aragiorgis <dimara@grnet.gr>
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarDimitris Aragiorgis <dimara@grnet.gr>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
(cherry picked from commit af3aea48)
parent 76c364d9
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,7 @@
# W0614: Unused import %s from wildcard import (since we need cli)
import textwrap
import itertools
from ganeti.cli import *
from ganeti import constants
......@@ -83,6 +84,23 @@ def AddNetwork(opts, args):
SubmitOrSend(op, opts)
def _GetDefaultGroups(cl, groups):
"""Gets list of groups to operate on.
If C{groups} doesn't contain groups, a list of all groups in the cluster is
returned.
@type cl: L{luxi.Client}
@type groups: list
@rtype: list
"""
if groups:
return groups
return list(itertools.chain(*cl.QueryGroups([], ["uuid"], False)))
def ConnectNetwork(opts, args):
"""Map a network to a node group.
......@@ -93,13 +111,10 @@ def ConnectNetwork(opts, args):
@return: the desired exit code
"""
(network, mode, link) = args[:3]
groups = args[3:]
cl = GetClient()
if not groups:
(groups, ) = cl.QueryGroups([], ["uuid"], False)
(network, mode, link) = args[:3]
groups = _GetDefaultGroups(cl, args[3:])
# TODO: Change logic to support "--submit"
for group in groups:
......@@ -121,13 +136,10 @@ def DisconnectNetwork(opts, args):
@return: the desired exit code
"""
(network, ) = args[:1]
groups = args[1:]
cl = GetClient()
if not groups:
(groups, ) = cl.QueryGroups([], ["uuid"], False)
(network, ) = args[:1]
groups = _GetDefaultGroups(cl, args[1:])
# TODO: Change logic to support "--submit"
for group in groups:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment