Revision 286d0218

b/lib/client/gnt_network.py
25 25
# W0614: Unused import %s from wildcard import (since we need cli)
26 26

  
27 27
import textwrap
28
import itertools
28 29

  
29 30
from ganeti.cli import *
30 31
from ganeti import constants
......
83 84
  SubmitOrSend(op, opts)
84 85

  
85 86

  
87
def _GetDefaultGroups(cl, groups):
88
  """Gets list of groups to operate on.
89

  
90
  If C{groups} doesn't contain groups, a list of all groups in the cluster is
91
  returned.
92

  
93
  @type cl: L{luxi.Client}
94
  @type groups: list
95
  @rtype: list
96

  
97
  """
98
  if groups:
99
    return groups
100

  
101
  return list(itertools.chain(*cl.QueryGroups([], ["uuid"], False)))
102

  
103

  
86 104
def ConnectNetwork(opts, args):
87 105
  """Map a network to a node group.
88 106

  
......
93 111
  @return: the desired exit code
94 112

  
95 113
  """
96
  (network, mode, link) = args[:3]
97
  groups = args[3:]
98

  
99 114
  cl = GetClient()
100 115

  
101
  if not groups:
102
    (groups, ) = cl.QueryGroups([], ["uuid"], False)
116
  (network, mode, link) = args[:3]
117
  groups = _GetDefaultGroups(cl, args[3:])
103 118

  
104 119
  # TODO: Change logic to support "--submit"
105 120
  for group in groups:
......
121 136
  @return: the desired exit code
122 137

  
123 138
  """
124
  (network, ) = args[:1]
125
  groups = args[1:]
126

  
127 139
  cl = GetClient()
128 140

  
129
  if not groups:
130
    (groups, ) = cl.QueryGroups([], ["uuid"], False)
141
  (network, ) = args[:1]
142
  groups = _GetDefaultGroups(cl, args[1:])
131 143

  
132 144
  # TODO: Change logic to support "--submit"
133 145
  for group in groups:

Also available in: Unified diff