Statistics
| Branch: | Tag: | Revision:

root / lib / client / gnt_group.py @ 1fa2c40b

History | View | Annotate | Download (11.7 kB)

1 667dbd6b Adeodato Simo
#
2 667dbd6b Adeodato Simo
#
3 667dbd6b Adeodato Simo
4 57dc299a Iustin Pop
# Copyright (C) 2010, 2011, 2012 Google Inc.
5 667dbd6b Adeodato Simo
#
6 667dbd6b Adeodato Simo
# This program is free software; you can redistribute it and/or modify
7 667dbd6b Adeodato Simo
# it under the terms of the GNU General Public License as published by
8 667dbd6b Adeodato Simo
# the Free Software Foundation; either version 2 of the License, or
9 667dbd6b Adeodato Simo
# (at your option) any later version.
10 667dbd6b Adeodato Simo
#
11 667dbd6b Adeodato Simo
# This program is distributed in the hope that it will be useful, but
12 667dbd6b Adeodato Simo
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 667dbd6b Adeodato Simo
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 667dbd6b Adeodato Simo
# General Public License for more details.
15 667dbd6b Adeodato Simo
#
16 667dbd6b Adeodato Simo
# You should have received a copy of the GNU General Public License
17 667dbd6b Adeodato Simo
# along with this program; if not, write to the Free Software
18 667dbd6b Adeodato Simo
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 667dbd6b Adeodato Simo
# 02110-1301, USA.
20 667dbd6b Adeodato Simo
21 667dbd6b Adeodato Simo
"""Node group related commands"""
22 667dbd6b Adeodato Simo
23 b459a848 Andrea Spadaccini
# pylint: disable=W0401,W0614
24 667dbd6b Adeodato Simo
# W0401: Wildcard import ganeti.cli
25 667dbd6b Adeodato Simo
# W0614: Unused import %s from wildcard import (since we need cli)
26 667dbd6b Adeodato Simo
27 667dbd6b Adeodato Simo
from ganeti.cli import *
28 ca4ac9c9 Adeodato Simo
from ganeti import constants
29 66e884e1 Adeodato Simo
from ganeti import opcodes
30 4edc512c Adeodato Simo
from ganeti import utils
31 216d23c0 René Nussbaumer
from cStringIO import StringIO
32 667dbd6b Adeodato Simo
33 667dbd6b Adeodato Simo
34 667dbd6b Adeodato Simo
#: default list of fields for L{ListGroups}
35 b288b6f3 René Nussbaumer
_LIST_DEF_FIELDS = ["name", "node_cnt", "pinst_cnt", "alloc_policy", "ndparams"]
36 667dbd6b Adeodato Simo
37 667dbd6b Adeodato Simo
38 ef9fa5b9 René Nussbaumer
_ENV_OVERRIDE = frozenset(["list"])
39 ef9fa5b9 René Nussbaumer
40 ef9fa5b9 René Nussbaumer
41 66e884e1 Adeodato Simo
def AddGroup(opts, args):
42 66e884e1 Adeodato Simo
  """Add a node group to the cluster.
43 66e884e1 Adeodato Simo

44 66e884e1 Adeodato Simo
  @param opts: the command line options selected by the user
45 66e884e1 Adeodato Simo
  @type args: list
46 66e884e1 Adeodato Simo
  @param args: a list of length 1 with the name of the group to create
47 66e884e1 Adeodato Simo
  @rtype: int
48 66e884e1 Adeodato Simo
  @return: the desired exit code
49 66e884e1 Adeodato Simo

50 66e884e1 Adeodato Simo
  """
51 703fa9ab Iustin Pop
  ipolicy = CreateIPolicyFromOpts(
52 703fa9ab Iustin Pop
    ispecs_mem_size=opts.ispecs_mem_size,
53 703fa9ab Iustin Pop
    ispecs_cpu_count=opts.ispecs_cpu_count,
54 703fa9ab Iustin Pop
    ispecs_disk_count=opts.ispecs_disk_count,
55 703fa9ab Iustin Pop
    ispecs_disk_size=opts.ispecs_disk_size,
56 703fa9ab Iustin Pop
    ispecs_nic_count=opts.ispecs_nic_count,
57 eb70f6cf René Nussbaumer
    ipolicy_vcpu_ratio=opts.ipolicy_vcpu_ratio,
58 eb70f6cf René Nussbaumer
    ipolicy_spindle_ratio=opts.ipolicy_spindle_ratio,
59 703fa9ab Iustin Pop
    group_ipolicy=True)
60 1f5d9bf8 Agata Murawska
61 66e884e1 Adeodato Simo
  (group_name,) = args
62 bc5d0215 Andrea Spadaccini
  diskparams = dict(opts.diskparams)
63 e4c03256 René Nussbaumer
64 e4c03256 René Nussbaumer
  if opts.disk_state:
65 e4c03256 René Nussbaumer
    disk_state = utils.FlatToDict(opts.disk_state)
66 e4c03256 René Nussbaumer
  else:
67 e4c03256 René Nussbaumer
    disk_state = {}
68 e4c03256 René Nussbaumer
  hv_state = dict(opts.hv_state)
69 e4c03256 René Nussbaumer
70 fabf1731 Iustin Pop
  op = opcodes.OpGroupAdd(group_name=group_name, ndparams=opts.ndparams,
71 bc5d0215 Andrea Spadaccini
                          alloc_policy=opts.alloc_policy,
72 e4c03256 René Nussbaumer
                          diskparams=diskparams, ipolicy=ipolicy,
73 e4c03256 René Nussbaumer
                          hv_state=hv_state,
74 e4c03256 René Nussbaumer
                          disk_state=disk_state)
75 dcbeccd9 Michael Hanselmann
  SubmitOrSend(op, opts)
76 66e884e1 Adeodato Simo
77 66e884e1 Adeodato Simo
78 919852da Adeodato Simo
def AssignNodes(opts, args):
79 919852da Adeodato Simo
  """Assign nodes to a group.
80 919852da Adeodato Simo

81 919852da Adeodato Simo
  @param opts: the command line options selected by the user
82 919852da Adeodato Simo
  @type args: list
83 919852da Adeodato Simo
  @param args: args[0]: group to assign nodes to; args[1:]: nodes to assign
84 919852da Adeodato Simo
  @rtype: int
85 919852da Adeodato Simo
  @return: the desired exit code
86 919852da Adeodato Simo

87 919852da Adeodato Simo
  """
88 919852da Adeodato Simo
  group_name = args[0]
89 919852da Adeodato Simo
  node_names = args[1:]
90 919852da Adeodato Simo
91 934704ae Iustin Pop
  op = opcodes.OpGroupAssignNodes(group_name=group_name, nodes=node_names,
92 919852da Adeodato Simo
                                  force=opts.force)
93 dcbeccd9 Michael Hanselmann
  SubmitOrSend(op, opts)
94 919852da Adeodato Simo
95 919852da Adeodato Simo
96 b288b6f3 René Nussbaumer
def _FmtDict(data):
97 b288b6f3 René Nussbaumer
  """Format dict data into command-line format.
98 b288b6f3 René Nussbaumer

99 b288b6f3 René Nussbaumer
  @param data: The input dict to be formatted
100 b288b6f3 René Nussbaumer
  @return: The formatted dict
101 b288b6f3 René Nussbaumer

102 b288b6f3 René Nussbaumer
  """
103 b288b6f3 René Nussbaumer
  if not data:
104 b288b6f3 René Nussbaumer
    return "(empty)"
105 b288b6f3 René Nussbaumer
106 b288b6f3 René Nussbaumer
  return utils.CommaJoin(["%s=%s" % (key, value)
107 b288b6f3 René Nussbaumer
                          for key, value in data.items()])
108 b288b6f3 René Nussbaumer
109 b288b6f3 René Nussbaumer
110 667dbd6b Adeodato Simo
def ListGroups(opts, args):
111 667dbd6b Adeodato Simo
  """List node groups and their properties.
112 667dbd6b Adeodato Simo

113 667dbd6b Adeodato Simo
  @param opts: the command line options selected by the user
114 667dbd6b Adeodato Simo
  @type args: list
115 667dbd6b Adeodato Simo
  @param args: groups to list, or empty for all
116 667dbd6b Adeodato Simo
  @rtype: int
117 667dbd6b Adeodato Simo
  @return: the desired exit code
118 667dbd6b Adeodato Simo

119 667dbd6b Adeodato Simo
  """
120 667dbd6b Adeodato Simo
  desired_fields = ParseFields(opts.output, _LIST_DEF_FIELDS)
121 b288b6f3 René Nussbaumer
  fmtoverride = {
122 b288b6f3 René Nussbaumer
    "node_list": (",".join, False),
123 b288b6f3 René Nussbaumer
    "pinst_list": (",".join, False),
124 b288b6f3 René Nussbaumer
    "ndparams": (_FmtDict, False),
125 b288b6f3 René Nussbaumer
    }
126 667dbd6b Adeodato Simo
127 9fbf0098 Iustin Pop
  cl = GetClient(query=True)
128 9fbf0098 Iustin Pop
129 ca4ac9c9 Adeodato Simo
  return GenericList(constants.QR_GROUP, desired_fields, args, None,
130 ca4ac9c9 Adeodato Simo
                     opts.separator, not opts.no_headers,
131 1b1a08e8 Michael Hanselmann
                     format_override=fmtoverride, verbose=opts.verbose,
132 9fbf0098 Iustin Pop
                     force_filter=opts.force_filter, cl=cl)
133 667dbd6b Adeodato Simo
134 667dbd6b Adeodato Simo
135 ca4ac9c9 Adeodato Simo
def ListGroupFields(opts, args):
136 ca4ac9c9 Adeodato Simo
  """List node fields.
137 667dbd6b Adeodato Simo

138 ca4ac9c9 Adeodato Simo
  @param opts: the command line options selected by the user
139 ca4ac9c9 Adeodato Simo
  @type args: list
140 ca4ac9c9 Adeodato Simo
  @param args: fields to list, or empty for all
141 ca4ac9c9 Adeodato Simo
  @rtype: int
142 ca4ac9c9 Adeodato Simo
  @return: the desired exit code
143 667dbd6b Adeodato Simo

144 ca4ac9c9 Adeodato Simo
  """
145 9fbf0098 Iustin Pop
  cl = GetClient(query=True)
146 9fbf0098 Iustin Pop
147 ca4ac9c9 Adeodato Simo
  return GenericListFields(constants.QR_GROUP, args, opts.separator,
148 9fbf0098 Iustin Pop
                           not opts.no_headers, cl=cl)
149 667dbd6b Adeodato Simo
150 667dbd6b Adeodato Simo
151 4da7909a Adeodato Simo
def SetGroupParams(opts, args):
152 4da7909a Adeodato Simo
  """Modifies a node group's parameters.
153 4da7909a Adeodato Simo

154 fecbc0b6 Stephen Shirley
  @param opts: the command line options selected by the user
155 4da7909a Adeodato Simo
  @type args: list
156 4da7909a Adeodato Simo
  @param args: should contain only one element, the node group name
157 4da7909a Adeodato Simo

158 4da7909a Adeodato Simo
  @rtype: int
159 4da7909a Adeodato Simo
  @return: the desired exit code
160 4da7909a Adeodato Simo

161 4da7909a Adeodato Simo
  """
162 fb644e77 Agata Murawska
  allmods = [opts.ndparams, opts.alloc_policy, opts.diskparams, opts.hv_state,
163 fb644e77 Agata Murawska
             opts.disk_state, opts.ispecs_mem_size, opts.ispecs_cpu_count,
164 fb644e77 Agata Murawska
             opts.ispecs_disk_count, opts.ispecs_disk_size,
165 eb70f6cf René Nussbaumer
             opts.ispecs_nic_count, opts.ipolicy_vcpu_ratio,
166 eb70f6cf René Nussbaumer
             opts.ipolicy_spindle_ratio, opts.diskparams]
167 fb644e77 Agata Murawska
  if allmods.count(None) == len(allmods):
168 4da7909a Adeodato Simo
    ToStderr("Please give at least one of the parameters.")
169 4da7909a Adeodato Simo
    return 1
170 4da7909a Adeodato Simo
171 a8282327 René Nussbaumer
  if opts.disk_state:
172 a8282327 René Nussbaumer
    disk_state = utils.FlatToDict(opts.disk_state)
173 a8282327 René Nussbaumer
  else:
174 a8282327 René Nussbaumer
    disk_state = {}
175 a8282327 René Nussbaumer
176 a8282327 René Nussbaumer
  hv_state = dict(opts.hv_state)
177 a8282327 René Nussbaumer
178 bc5d0215 Andrea Spadaccini
  diskparams = dict(opts.diskparams)
179 fb644e77 Agata Murawska
180 fb644e77 Agata Murawska
  # set the default values
181 fb644e77 Agata Murawska
  to_ipolicy = [
182 fb644e77 Agata Murawska
    opts.ispecs_mem_size,
183 fb644e77 Agata Murawska
    opts.ispecs_cpu_count,
184 fb644e77 Agata Murawska
    opts.ispecs_disk_count,
185 fb644e77 Agata Murawska
    opts.ispecs_disk_size,
186 fb644e77 Agata Murawska
    opts.ispecs_nic_count,
187 fb644e77 Agata Murawska
    ]
188 fb644e77 Agata Murawska
  for ispec in to_ipolicy:
189 fb644e77 Agata Murawska
    for param in ispec:
190 fb644e77 Agata Murawska
      if isinstance(ispec[param], basestring):
191 fb644e77 Agata Murawska
        if ispec[param].lower() == "default":
192 fb644e77 Agata Murawska
          ispec[param] = constants.VALUE_DEFAULT
193 fb644e77 Agata Murawska
  # create ipolicy object
194 703fa9ab Iustin Pop
  ipolicy = CreateIPolicyFromOpts(
195 fb644e77 Agata Murawska
    ispecs_mem_size=opts.ispecs_mem_size,
196 fb644e77 Agata Murawska
    ispecs_cpu_count=opts.ispecs_cpu_count,
197 fb644e77 Agata Murawska
    ispecs_disk_count=opts.ispecs_disk_count,
198 fb644e77 Agata Murawska
    ispecs_disk_size=opts.ispecs_disk_size,
199 fb644e77 Agata Murawska
    ispecs_nic_count=opts.ispecs_nic_count,
200 d04c9d45 Iustin Pop
    ipolicy_disk_templates=opts.ipolicy_disk_templates,
201 eb70f6cf René Nussbaumer
    ipolicy_vcpu_ratio=opts.ipolicy_vcpu_ratio,
202 eb70f6cf René Nussbaumer
    ipolicy_spindle_ratio=opts.ipolicy_spindle_ratio,
203 fb644e77 Agata Murawska
    group_ipolicy=True,
204 fb644e77 Agata Murawska
    allowed_values=[constants.VALUE_DEFAULT])
205 fb644e77 Agata Murawska
206 8e47b5da Michael Hanselmann
  op = opcodes.OpGroupSetParams(group_name=args[0],
207 8e47b5da Michael Hanselmann
                                ndparams=opts.ndparams,
208 bc5d0215 Andrea Spadaccini
                                alloc_policy=opts.alloc_policy,
209 a8282327 René Nussbaumer
                                hv_state=hv_state,
210 a8282327 René Nussbaumer
                                disk_state=disk_state,
211 fb644e77 Agata Murawska
                                diskparams=diskparams,
212 fb644e77 Agata Murawska
                                ipolicy=ipolicy)
213 fb644e77 Agata Murawska
214 4da7909a Adeodato Simo
  result = SubmitOrSend(op, opts)
215 4da7909a Adeodato Simo
216 4da7909a Adeodato Simo
  if result:
217 4da7909a Adeodato Simo
    ToStdout("Modified node group %s", args[0])
218 4da7909a Adeodato Simo
    for param, data in result:
219 4da7909a Adeodato Simo
      ToStdout(" - %-5s -> %s", param, data)
220 4da7909a Adeodato Simo
221 4da7909a Adeodato Simo
  return 0
222 4da7909a Adeodato Simo
223 4da7909a Adeodato Simo
224 66e884e1 Adeodato Simo
def RemoveGroup(opts, args):
225 66e884e1 Adeodato Simo
  """Remove a node group from the cluster.
226 66e884e1 Adeodato Simo

227 66e884e1 Adeodato Simo
  @param opts: the command line options selected by the user
228 66e884e1 Adeodato Simo
  @type args: list
229 66e884e1 Adeodato Simo
  @param args: a list of length 1 with the name of the group to remove
230 66e884e1 Adeodato Simo
  @rtype: int
231 66e884e1 Adeodato Simo
  @return: the desired exit code
232 66e884e1 Adeodato Simo

233 66e884e1 Adeodato Simo
  """
234 66e884e1 Adeodato Simo
  (group_name,) = args
235 4d1baa51 Iustin Pop
  op = opcodes.OpGroupRemove(group_name=group_name)
236 dcbeccd9 Michael Hanselmann
  SubmitOrSend(op, opts)
237 66e884e1 Adeodato Simo
238 66e884e1 Adeodato Simo
239 66e884e1 Adeodato Simo
def RenameGroup(opts, args):
240 66e884e1 Adeodato Simo
  """Rename a node group.
241 66e884e1 Adeodato Simo

242 66e884e1 Adeodato Simo
  @param opts: the command line options selected by the user
243 66e884e1 Adeodato Simo
  @type args: list
244 66e884e1 Adeodato Simo
  @param args: a list of length 2, [old_name, new_name]
245 66e884e1 Adeodato Simo
  @rtype: int
246 66e884e1 Adeodato Simo
  @return: the desired exit code
247 66e884e1 Adeodato Simo

248 66e884e1 Adeodato Simo
  """
249 12da663a Michael Hanselmann
  group_name, new_name = args
250 12da663a Michael Hanselmann
  op = opcodes.OpGroupRename(group_name=group_name, new_name=new_name)
251 dcbeccd9 Michael Hanselmann
  SubmitOrSend(op, opts)
252 66e884e1 Adeodato Simo
253 66e884e1 Adeodato Simo
254 f6eb380d Michael Hanselmann
def EvacuateGroup(opts, args):
255 f6eb380d Michael Hanselmann
  """Evacuate a node group.
256 f6eb380d Michael Hanselmann

257 f6eb380d Michael Hanselmann
  """
258 f6eb380d Michael Hanselmann
  (group_name, ) = args
259 f6eb380d Michael Hanselmann
260 f6eb380d Michael Hanselmann
  cl = GetClient()
261 f6eb380d Michael Hanselmann
262 f6eb380d Michael Hanselmann
  op = opcodes.OpGroupEvacuate(group_name=group_name,
263 f6eb380d Michael Hanselmann
                               iallocator=opts.iallocator,
264 f6eb380d Michael Hanselmann
                               target_groups=opts.to,
265 f6eb380d Michael Hanselmann
                               early_release=opts.early_release)
266 dcbeccd9 Michael Hanselmann
  result = SubmitOrSend(op, opts, cl=cl)
267 f6eb380d Michael Hanselmann
268 f6eb380d Michael Hanselmann
  # Keep track of submitted jobs
269 f6eb380d Michael Hanselmann
  jex = JobExecutor(cl=cl, opts=opts)
270 f6eb380d Michael Hanselmann
271 f6eb380d Michael Hanselmann
  for (status, job_id) in result[constants.JOB_IDS_KEY]:
272 f6eb380d Michael Hanselmann
    jex.AddJobId(None, status, job_id)
273 f6eb380d Michael Hanselmann
274 f6eb380d Michael Hanselmann
  results = jex.GetResults()
275 f6eb380d Michael Hanselmann
  bad_cnt = len([row for row in results if not row[0]])
276 f6eb380d Michael Hanselmann
  if bad_cnt == 0:
277 f6eb380d Michael Hanselmann
    ToStdout("All instances evacuated successfully.")
278 f6eb380d Michael Hanselmann
    rcode = constants.EXIT_SUCCESS
279 f6eb380d Michael Hanselmann
  else:
280 f6eb380d Michael Hanselmann
    ToStdout("There were %s errors during the evacuation.", bad_cnt)
281 f6eb380d Michael Hanselmann
    rcode = constants.EXIT_FAILURE
282 f6eb380d Michael Hanselmann
283 f6eb380d Michael Hanselmann
  return rcode
284 f6eb380d Michael Hanselmann
285 216d23c0 René Nussbaumer
286 216d23c0 René Nussbaumer
def _FormatDict(custom, actual, level=2):
287 216d23c0 René Nussbaumer
  """Helper function to L{cli.FormatParameterDict}.
288 216d23c0 René Nussbaumer

289 216d23c0 René Nussbaumer
  @param custom: The customized dict
290 216d23c0 René Nussbaumer
  @param actual: The fully filled dict
291 216d23c0 René Nussbaumer

292 216d23c0 René Nussbaumer
  """
293 216d23c0 René Nussbaumer
  buf = StringIO()
294 216d23c0 René Nussbaumer
  FormatParameterDict(buf, custom, actual, level=level)
295 216d23c0 René Nussbaumer
  return buf.getvalue().rstrip("\n")
296 216d23c0 René Nussbaumer
297 216d23c0 René Nussbaumer
298 216d23c0 René Nussbaumer
def GroupInfo(_, args):
299 216d23c0 René Nussbaumer
  """Shows info about node group.
300 216d23c0 René Nussbaumer

301 216d23c0 René Nussbaumer
  """
302 9fbf0098 Iustin Pop
  cl = GetClient(query=True)
303 216d23c0 René Nussbaumer
  selected_fields = ["name",
304 216d23c0 René Nussbaumer
                     "ndparams", "custom_ndparams",
305 216d23c0 René Nussbaumer
                     "diskparams", "custom_diskparams",
306 216d23c0 René Nussbaumer
                     "ipolicy", "custom_ipolicy"]
307 216d23c0 René Nussbaumer
  result = cl.QueryGroups(names=args, fields=selected_fields,
308 216d23c0 René Nussbaumer
                          use_locking=False)
309 216d23c0 René Nussbaumer
310 216d23c0 René Nussbaumer
  for (name,
311 216d23c0 René Nussbaumer
       ndparams, custom_ndparams,
312 216d23c0 René Nussbaumer
       diskparams, custom_diskparams,
313 216d23c0 René Nussbaumer
       ipolicy, custom_ipolicy) in result:
314 216d23c0 René Nussbaumer
    ToStdout("Node group: %s" % name)
315 216d23c0 René Nussbaumer
    ToStdout("  Node parameters:")
316 216d23c0 René Nussbaumer
    ToStdout(_FormatDict(custom_ndparams, ndparams))
317 216d23c0 René Nussbaumer
    ToStdout("  Disk parameters:")
318 216d23c0 René Nussbaumer
    ToStdout(_FormatDict(custom_diskparams, diskparams))
319 216d23c0 René Nussbaumer
    ToStdout("  Instance policy:")
320 216d23c0 René Nussbaumer
    ToStdout(_FormatDict(custom_ipolicy, ipolicy))
321 216d23c0 René Nussbaumer
322 216d23c0 René Nussbaumer
323 667dbd6b Adeodato Simo
commands = {
324 66e884e1 Adeodato Simo
  "add": (
325 bc5d0215 Andrea Spadaccini
    AddGroup, ARGS_ONE_GROUP,
326 e4c03256 René Nussbaumer
    [DRY_RUN_OPT, ALLOC_POLICY_OPT, NODE_PARAMS_OPT, DISK_PARAMS_OPT,
327 dcbeccd9 Michael Hanselmann
     HV_STATE_OPT, DISK_STATE_OPT, PRIORITY_OPT,
328 dcbeccd9 Michael Hanselmann
     SUBMIT_OPT] + INSTANCE_POLICY_OPTS,
329 66e884e1 Adeodato Simo
    "<group_name>", "Add a new node group to the cluster"),
330 919852da Adeodato Simo
  "assign-nodes": (
331 dcbeccd9 Michael Hanselmann
    AssignNodes, ARGS_ONE_GROUP + ARGS_MANY_NODES,
332 dcbeccd9 Michael Hanselmann
    [DRY_RUN_OPT, FORCE_OPT, PRIORITY_OPT, SUBMIT_OPT],
333 919852da Adeodato Simo
    "<group_name> <node>...", "Assign nodes to a group"),
334 667dbd6b Adeodato Simo
  "list": (
335 667dbd6b Adeodato Simo
    ListGroups, ARGS_MANY_GROUPS,
336 1b1a08e8 Michael Hanselmann
    [NOHDR_OPT, SEP_OPT, FIELDS_OPT, VERBOSE_OPT, FORCE_FILTER_OPT],
337 4edc512c Adeodato Simo
    "[<group_name>...]",
338 ca4ac9c9 Adeodato Simo
    "Lists the node groups in the cluster. The available fields can be shown"
339 ca4ac9c9 Adeodato Simo
    " using the \"list-fields\" command (see the man page for details)."
340 ca4ac9c9 Adeodato Simo
    " The default list is (in order): %s." % utils.CommaJoin(_LIST_DEF_FIELDS)),
341 ca4ac9c9 Adeodato Simo
  "list-fields": (
342 ca4ac9c9 Adeodato Simo
    ListGroupFields, [ArgUnknown()], [NOHDR_OPT, SEP_OPT], "[fields...]",
343 ca4ac9c9 Adeodato Simo
    "Lists all available fields for node groups"),
344 4da7909a Adeodato Simo
  "modify": (
345 4da7909a Adeodato Simo
    SetGroupParams, ARGS_ONE_GROUP,
346 a8282327 René Nussbaumer
    [DRY_RUN_OPT, SUBMIT_OPT, ALLOC_POLICY_OPT, NODE_PARAMS_OPT, HV_STATE_OPT,
347 dcbeccd9 Michael Hanselmann
     DISK_STATE_OPT, DISK_PARAMS_OPT, PRIORITY_OPT] + INSTANCE_POLICY_OPTS,
348 4da7909a Adeodato Simo
    "<group_name>", "Alters the parameters of a node group"),
349 66e884e1 Adeodato Simo
  "remove": (
350 dcbeccd9 Michael Hanselmann
    RemoveGroup, ARGS_ONE_GROUP, [DRY_RUN_OPT, PRIORITY_OPT, SUBMIT_OPT],
351 12da663a Michael Hanselmann
    "[--dry-run] <group-name>",
352 66e884e1 Adeodato Simo
    "Remove an (empty) node group from the cluster"),
353 66e884e1 Adeodato Simo
  "rename": (
354 dcbeccd9 Michael Hanselmann
    RenameGroup, [ArgGroup(min=2, max=2)],
355 dcbeccd9 Michael Hanselmann
    [DRY_RUN_OPT, SUBMIT_OPT, PRIORITY_OPT],
356 12da663a Michael Hanselmann
    "[--dry-run] <group-name> <new-name>", "Rename a node group"),
357 f6eb380d Michael Hanselmann
  "evacuate": (
358 f6eb380d Michael Hanselmann
    EvacuateGroup, [ArgGroup(min=1, max=1)],
359 dcbeccd9 Michael Hanselmann
    [TO_GROUP_OPT, IALLOCATOR_OPT, EARLY_RELEASE_OPT, SUBMIT_OPT, PRIORITY_OPT],
360 6e80da8b Michael Hanselmann
    "[-I <iallocator>] [--to <group>]",
361 6e80da8b Michael Hanselmann
    "Evacuate all instances within a group"),
362 819cbfe5 Michael Hanselmann
  "list-tags": (
363 6bc3ed14 Michael Hanselmann
    ListTags, ARGS_ONE_GROUP, [],
364 36c70d4d Iustin Pop
    "<group_name>", "List the tags of the given group"),
365 819cbfe5 Michael Hanselmann
  "add-tags": (
366 819cbfe5 Michael Hanselmann
    AddTags, [ArgGroup(min=1, max=1), ArgUnknown()],
367 6bc3ed14 Michael Hanselmann
    [TAG_SRC_OPT, PRIORITY_OPT, SUBMIT_OPT],
368 36c70d4d Iustin Pop
    "<group_name> tag...", "Add tags to the given group"),
369 819cbfe5 Michael Hanselmann
  "remove-tags": (
370 819cbfe5 Michael Hanselmann
    RemoveTags, [ArgGroup(min=1, max=1), ArgUnknown()],
371 6bc3ed14 Michael Hanselmann
    [TAG_SRC_OPT, PRIORITY_OPT, SUBMIT_OPT],
372 36c70d4d Iustin Pop
    "<group_name> tag...", "Remove tags from the given group"),
373 216d23c0 René Nussbaumer
  "info": (
374 216d23c0 René Nussbaumer
    GroupInfo, ARGS_MANY_GROUPS, [], "<group_name>", "Show group information"),
375 819cbfe5 Michael Hanselmann
  }
376 667dbd6b Adeodato Simo
377 667dbd6b Adeodato Simo
378 667dbd6b Adeodato Simo
def Main():
379 819cbfe5 Michael Hanselmann
  return GenericMain(commands,
380 ef9fa5b9 René Nussbaumer
                     override={"tag_type": constants.TAG_NODEGROUP},
381 ef9fa5b9 René Nussbaumer
                     env_override=_ENV_OVERRIDE)