* Michael Hanselmann <[email protected]> [2013-01-23 13:06:47 +0100]:
> From: Dimitris Aragiorgis <[email protected]> > > 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: Dimitris Aragiorgis <[email protected]> > Signed-off-by: Michael Hanselmann <[email protected]> > --- > > Hello Dimitris! > > Thanks for your patch. I allowed myself to modify it slightly to extract the > common code into a separate function. Are you okay with my changes? > > Michael > Hi! ACK. Duplicate code hunts me :) Thanks, dimara > lib/client/gnt_network.py | 32 ++++++++++++++++++++++---------- > 1 file changed, 22 insertions(+), 10 deletions(-) > > diff --git a/lib/client/gnt_network.py b/lib/client/gnt_network.py > index 3427370..7210ab3 100644 > --- a/lib/client/gnt_network.py > +++ b/lib/client/gnt_network.py > @@ -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: > -- > 1.8.1
signature.asc
Description: Digital signature
