Statistics
| Branch: | Tag: | Revision:

root / lib / client / gnt_group.py @ 178ad717

History | View | Annotate | Download (11.6 kB)

1 667dbd6b Adeodato Simo
#
2 667dbd6b Adeodato Simo
#
3 667dbd6b Adeodato Simo
4 801bccba Bernardo Dal Seno
# Copyright (C) 2010, 2011, 2012, 2013 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 ea9d3b40 Bernardo Dal Seno
from cStringIO import StringIO
28 ea9d3b40 Bernardo Dal Seno
29 667dbd6b Adeodato Simo
from ganeti.cli import *
30 ca4ac9c9 Adeodato Simo
from ganeti import constants
31 66e884e1 Adeodato Simo
from ganeti import opcodes
32 4edc512c Adeodato Simo
from ganeti import utils
33 b8028dcf Michael Hanselmann
from ganeti import compat
34 667dbd6b Adeodato Simo
35 667dbd6b Adeodato Simo
36 667dbd6b Adeodato Simo
#: default list of fields for L{ListGroups}
37 b288b6f3 René Nussbaumer
_LIST_DEF_FIELDS = ["name", "node_cnt", "pinst_cnt", "alloc_policy", "ndparams"]
38 667dbd6b Adeodato Simo
39 b8028dcf Michael Hanselmann
_ENV_OVERRIDE = compat.UniqueFrozenset(["list"])
40 ef9fa5b9 René Nussbaumer
41 ef9fa5b9 René Nussbaumer
42 66e884e1 Adeodato Simo
def AddGroup(opts, args):
43 66e884e1 Adeodato Simo
  """Add a node group to the cluster.
44 66e884e1 Adeodato Simo

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

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

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

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

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

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

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

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

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

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

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

156 4da7909a Adeodato Simo
  @rtype: int
157 4da7909a Adeodato Simo
  @return: the desired exit code
158 4da7909a Adeodato Simo

159 4da7909a Adeodato Simo
  """
160 fb644e77 Agata Murawska
  allmods = [opts.ndparams, opts.alloc_policy, opts.diskparams, opts.hv_state,
161 919db916 Bernardo Dal Seno
             opts.disk_state, opts.ipolicy_bounds_specs,
162 d2d3935a Bernardo Dal Seno
             opts.ipolicy_vcpu_ratio, opts.ipolicy_spindle_ratio,
163 702243ec Helga Velroyen
             opts.diskparams, opts.ipolicy_disk_templates]
164 fb644e77 Agata Murawska
  if allmods.count(None) == len(allmods):
165 4da7909a Adeodato Simo
    ToStderr("Please give at least one of the parameters.")
166 4da7909a Adeodato Simo
    return 1
167 4da7909a Adeodato Simo
168 a8282327 René Nussbaumer
  if opts.disk_state:
169 a8282327 René Nussbaumer
    disk_state = utils.FlatToDict(opts.disk_state)
170 a8282327 René Nussbaumer
  else:
171 a8282327 René Nussbaumer
    disk_state = {}
172 a8282327 René Nussbaumer
173 a8282327 René Nussbaumer
  hv_state = dict(opts.hv_state)
174 a8282327 René Nussbaumer
175 bc5d0215 Andrea Spadaccini
  diskparams = dict(opts.diskparams)
176 fb644e77 Agata Murawska
177 fb644e77 Agata Murawska
  # create ipolicy object
178 703fa9ab Iustin Pop
  ipolicy = CreateIPolicyFromOpts(
179 d2d3935a Bernardo Dal Seno
    minmax_ispecs=opts.ipolicy_bounds_specs,
180 d04c9d45 Iustin Pop
    ipolicy_disk_templates=opts.ipolicy_disk_templates,
181 eb70f6cf René Nussbaumer
    ipolicy_vcpu_ratio=opts.ipolicy_vcpu_ratio,
182 eb70f6cf René Nussbaumer
    ipolicy_spindle_ratio=opts.ipolicy_spindle_ratio,
183 fb644e77 Agata Murawska
    group_ipolicy=True,
184 fb644e77 Agata Murawska
    allowed_values=[constants.VALUE_DEFAULT])
185 fb644e77 Agata Murawska
186 8e47b5da Michael Hanselmann
  op = opcodes.OpGroupSetParams(group_name=args[0],
187 8e47b5da Michael Hanselmann
                                ndparams=opts.ndparams,
188 bc5d0215 Andrea Spadaccini
                                alloc_policy=opts.alloc_policy,
189 a8282327 René Nussbaumer
                                hv_state=hv_state,
190 a8282327 René Nussbaumer
                                disk_state=disk_state,
191 fb644e77 Agata Murawska
                                diskparams=diskparams,
192 fb644e77 Agata Murawska
                                ipolicy=ipolicy)
193 fb644e77 Agata Murawska
194 4da7909a Adeodato Simo
  result = SubmitOrSend(op, opts)
195 4da7909a Adeodato Simo
196 4da7909a Adeodato Simo
  if result:
197 4da7909a Adeodato Simo
    ToStdout("Modified node group %s", args[0])
198 4da7909a Adeodato Simo
    for param, data in result:
199 4da7909a Adeodato Simo
      ToStdout(" - %-5s -> %s", param, data)
200 4da7909a Adeodato Simo
201 4da7909a Adeodato Simo
  return 0
202 4da7909a Adeodato Simo
203 4da7909a Adeodato Simo
204 66e884e1 Adeodato Simo
def RemoveGroup(opts, args):
205 66e884e1 Adeodato Simo
  """Remove a node group from the cluster.
206 66e884e1 Adeodato Simo

207 66e884e1 Adeodato Simo
  @param opts: the command line options selected by the user
208 66e884e1 Adeodato Simo
  @type args: list
209 66e884e1 Adeodato Simo
  @param args: a list of length 1 with the name of the group to remove
210 66e884e1 Adeodato Simo
  @rtype: int
211 66e884e1 Adeodato Simo
  @return: the desired exit code
212 66e884e1 Adeodato Simo

213 66e884e1 Adeodato Simo
  """
214 66e884e1 Adeodato Simo
  (group_name,) = args
215 4d1baa51 Iustin Pop
  op = opcodes.OpGroupRemove(group_name=group_name)
216 dcbeccd9 Michael Hanselmann
  SubmitOrSend(op, opts)
217 66e884e1 Adeodato Simo
218 66e884e1 Adeodato Simo
219 66e884e1 Adeodato Simo
def RenameGroup(opts, args):
220 66e884e1 Adeodato Simo
  """Rename a node group.
221 66e884e1 Adeodato Simo

222 66e884e1 Adeodato Simo
  @param opts: the command line options selected by the user
223 66e884e1 Adeodato Simo
  @type args: list
224 66e884e1 Adeodato Simo
  @param args: a list of length 2, [old_name, new_name]
225 66e884e1 Adeodato Simo
  @rtype: int
226 66e884e1 Adeodato Simo
  @return: the desired exit code
227 66e884e1 Adeodato Simo

228 66e884e1 Adeodato Simo
  """
229 12da663a Michael Hanselmann
  group_name, new_name = args
230 12da663a Michael Hanselmann
  op = opcodes.OpGroupRename(group_name=group_name, new_name=new_name)
231 dcbeccd9 Michael Hanselmann
  SubmitOrSend(op, opts)
232 66e884e1 Adeodato Simo
233 66e884e1 Adeodato Simo
234 f6eb380d Michael Hanselmann
def EvacuateGroup(opts, args):
235 f6eb380d Michael Hanselmann
  """Evacuate a node group.
236 f6eb380d Michael Hanselmann

237 f6eb380d Michael Hanselmann
  """
238 f6eb380d Michael Hanselmann
  (group_name, ) = args
239 f6eb380d Michael Hanselmann
240 f6eb380d Michael Hanselmann
  cl = GetClient()
241 f6eb380d Michael Hanselmann
242 f6eb380d Michael Hanselmann
  op = opcodes.OpGroupEvacuate(group_name=group_name,
243 f6eb380d Michael Hanselmann
                               iallocator=opts.iallocator,
244 f6eb380d Michael Hanselmann
                               target_groups=opts.to,
245 f6eb380d Michael Hanselmann
                               early_release=opts.early_release)
246 dcbeccd9 Michael Hanselmann
  result = SubmitOrSend(op, opts, cl=cl)
247 f6eb380d Michael Hanselmann
248 f6eb380d Michael Hanselmann
  # Keep track of submitted jobs
249 f6eb380d Michael Hanselmann
  jex = JobExecutor(cl=cl, opts=opts)
250 f6eb380d Michael Hanselmann
251 f6eb380d Michael Hanselmann
  for (status, job_id) in result[constants.JOB_IDS_KEY]:
252 f6eb380d Michael Hanselmann
    jex.AddJobId(None, status, job_id)
253 f6eb380d Michael Hanselmann
254 f6eb380d Michael Hanselmann
  results = jex.GetResults()
255 f6eb380d Michael Hanselmann
  bad_cnt = len([row for row in results if not row[0]])
256 f6eb380d Michael Hanselmann
  if bad_cnt == 0:
257 f6eb380d Michael Hanselmann
    ToStdout("All instances evacuated successfully.")
258 f6eb380d Michael Hanselmann
    rcode = constants.EXIT_SUCCESS
259 f6eb380d Michael Hanselmann
  else:
260 f6eb380d Michael Hanselmann
    ToStdout("There were %s errors during the evacuation.", bad_cnt)
261 f6eb380d Michael Hanselmann
    rcode = constants.EXIT_FAILURE
262 f6eb380d Michael Hanselmann
263 f6eb380d Michael Hanselmann
  return rcode
264 f6eb380d Michael Hanselmann
265 216d23c0 René Nussbaumer
266 801bccba Bernardo Dal Seno
def _FormatGroupInfo(group):
267 801bccba Bernardo Dal Seno
  (name, ndparams, custom_ndparams, diskparams, custom_diskparams,
268 801bccba Bernardo Dal Seno
   ipolicy, custom_ipolicy) = group
269 801bccba Bernardo Dal Seno
  return [
270 801bccba Bernardo Dal Seno
    ("Node group", name),
271 801bccba Bernardo Dal Seno
    ("Node parameters", FormatParamsDictInfo(custom_ndparams, ndparams)),
272 801bccba Bernardo Dal Seno
    ("Disk parameters", FormatParamsDictInfo(custom_diskparams, diskparams)),
273 801bccba Bernardo Dal Seno
    ("Instance policy", FormatPolicyInfo(custom_ipolicy, ipolicy, False)),
274 801bccba Bernardo Dal Seno
    ]
275 216d23c0 René Nussbaumer
276 216d23c0 René Nussbaumer
277 216d23c0 René Nussbaumer
def GroupInfo(_, args):
278 216d23c0 René Nussbaumer
  """Shows info about node group.
279 216d23c0 René Nussbaumer

280 216d23c0 René Nussbaumer
  """
281 9fbf0098 Iustin Pop
  cl = GetClient(query=True)
282 216d23c0 René Nussbaumer
  selected_fields = ["name",
283 216d23c0 René Nussbaumer
                     "ndparams", "custom_ndparams",
284 216d23c0 René Nussbaumer
                     "diskparams", "custom_diskparams",
285 216d23c0 René Nussbaumer
                     "ipolicy", "custom_ipolicy"]
286 216d23c0 René Nussbaumer
  result = cl.QueryGroups(names=args, fields=selected_fields,
287 216d23c0 René Nussbaumer
                          use_locking=False)
288 216d23c0 René Nussbaumer
289 801bccba Bernardo Dal Seno
  PrintGenericInfo([
290 801bccba Bernardo Dal Seno
    _FormatGroupInfo(group) for group in result
291 801bccba Bernardo Dal Seno
    ])
292 216d23c0 René Nussbaumer
293 216d23c0 René Nussbaumer
294 ea9d3b40 Bernardo Dal Seno
def _GetCreateCommand(group):
295 ea9d3b40 Bernardo Dal Seno
  (name, ipolicy) = group
296 ea9d3b40 Bernardo Dal Seno
  buf = StringIO()
297 ea9d3b40 Bernardo Dal Seno
  buf.write("gnt-group add")
298 ea9d3b40 Bernardo Dal Seno
  PrintIPolicyCommand(buf, ipolicy, True)
299 ea9d3b40 Bernardo Dal Seno
  buf.write(" ")
300 ea9d3b40 Bernardo Dal Seno
  buf.write(name)
301 ea9d3b40 Bernardo Dal Seno
  return buf.getvalue()
302 ea9d3b40 Bernardo Dal Seno
303 ea9d3b40 Bernardo Dal Seno
304 ea9d3b40 Bernardo Dal Seno
def ShowCreateCommand(opts, args):
305 ea9d3b40 Bernardo Dal Seno
  """Shows the command that can be used to re-create a node group.
306 ea9d3b40 Bernardo Dal Seno

307 ea9d3b40 Bernardo Dal Seno
  Currently it works only for ipolicy specs.
308 ea9d3b40 Bernardo Dal Seno

309 ea9d3b40 Bernardo Dal Seno
  """
310 ea9d3b40 Bernardo Dal Seno
  cl = GetClient(query=True)
311 ea9d3b40 Bernardo Dal Seno
  selected_fields = ["name"]
312 ea9d3b40 Bernardo Dal Seno
  if opts.include_defaults:
313 ea9d3b40 Bernardo Dal Seno
    selected_fields += ["ipolicy"]
314 ea9d3b40 Bernardo Dal Seno
  else:
315 ea9d3b40 Bernardo Dal Seno
    selected_fields += ["custom_ipolicy"]
316 ea9d3b40 Bernardo Dal Seno
  result = cl.QueryGroups(names=args, fields=selected_fields,
317 ea9d3b40 Bernardo Dal Seno
                          use_locking=False)
318 ea9d3b40 Bernardo Dal Seno
319 ea9d3b40 Bernardo Dal Seno
  for group in result:
320 ea9d3b40 Bernardo Dal Seno
    ToStdout(_GetCreateCommand(group))
321 ea9d3b40 Bernardo Dal Seno
322 ea9d3b40 Bernardo Dal Seno
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 d6cd74dd Klaus Aehlig
     HV_STATE_OPT, DISK_STATE_OPT, PRIORITY_OPT]
328 d6cd74dd Klaus Aehlig
    + SUBMIT_OPTS + 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 d6cd74dd Klaus Aehlig
    [DRY_RUN_OPT, FORCE_OPT, PRIORITY_OPT] + SUBMIT_OPTS,
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 e0e44476 Michele Tartara
    [DRY_RUN_OPT] + SUBMIT_OPTS +
347 e0e44476 Michele Tartara
    [ALLOC_POLICY_OPT, NODE_PARAMS_OPT, HV_STATE_OPT, DISK_STATE_OPT,
348 e0e44476 Michele Tartara
     DISK_PARAMS_OPT, PRIORITY_OPT]
349 d6cd74dd Klaus Aehlig
    + INSTANCE_POLICY_OPTS,
350 4da7909a Adeodato Simo
    "<group_name>", "Alters the parameters of a node group"),
351 66e884e1 Adeodato Simo
  "remove": (
352 d6cd74dd Klaus Aehlig
    RemoveGroup, ARGS_ONE_GROUP, [DRY_RUN_OPT, PRIORITY_OPT] + SUBMIT_OPTS,
353 12da663a Michael Hanselmann
    "[--dry-run] <group-name>",
354 66e884e1 Adeodato Simo
    "Remove an (empty) node group from the cluster"),
355 66e884e1 Adeodato Simo
  "rename": (
356 dcbeccd9 Michael Hanselmann
    RenameGroup, [ArgGroup(min=2, max=2)],
357 d6cd74dd Klaus Aehlig
    [DRY_RUN_OPT] + SUBMIT_OPTS + [PRIORITY_OPT],
358 12da663a Michael Hanselmann
    "[--dry-run] <group-name> <new-name>", "Rename a node group"),
359 f6eb380d Michael Hanselmann
  "evacuate": (
360 f6eb380d Michael Hanselmann
    EvacuateGroup, [ArgGroup(min=1, max=1)],
361 d6cd74dd Klaus Aehlig
    [TO_GROUP_OPT, IALLOCATOR_OPT, EARLY_RELEASE_OPT] + SUBMIT_OPTS,
362 6e80da8b Michael Hanselmann
    "[-I <iallocator>] [--to <group>]",
363 6e80da8b Michael Hanselmann
    "Evacuate all instances within a group"),
364 819cbfe5 Michael Hanselmann
  "list-tags": (
365 6bc3ed14 Michael Hanselmann
    ListTags, ARGS_ONE_GROUP, [],
366 36c70d4d Iustin Pop
    "<group_name>", "List the tags of the given group"),
367 819cbfe5 Michael Hanselmann
  "add-tags": (
368 819cbfe5 Michael Hanselmann
    AddTags, [ArgGroup(min=1, max=1), ArgUnknown()],
369 d6cd74dd Klaus Aehlig
    [TAG_SRC_OPT, PRIORITY_OPT] + SUBMIT_OPTS,
370 36c70d4d Iustin Pop
    "<group_name> tag...", "Add tags to the given group"),
371 819cbfe5 Michael Hanselmann
  "remove-tags": (
372 819cbfe5 Michael Hanselmann
    RemoveTags, [ArgGroup(min=1, max=1), ArgUnknown()],
373 d6cd74dd Klaus Aehlig
    [TAG_SRC_OPT, PRIORITY_OPT] + SUBMIT_OPTS,
374 36c70d4d Iustin Pop
    "<group_name> tag...", "Remove tags from the given group"),
375 216d23c0 René Nussbaumer
  "info": (
376 2c398e80 Bernardo Dal Seno
    GroupInfo, ARGS_MANY_GROUPS, [], "[<group_name>...]",
377 2c398e80 Bernardo Dal Seno
    "Show group information"),
378 ea9d3b40 Bernardo Dal Seno
  "show-ispecs-cmd": (
379 ea9d3b40 Bernardo Dal Seno
    ShowCreateCommand, ARGS_MANY_GROUPS, [INCLUDEDEFAULTS_OPT],
380 ea9d3b40 Bernardo Dal Seno
    "[--include-defaults] [<group_name>...]",
381 ea9d3b40 Bernardo Dal Seno
    "Show the command line to re-create a group"),
382 819cbfe5 Michael Hanselmann
  }
383 667dbd6b Adeodato Simo
384 667dbd6b Adeodato Simo
385 667dbd6b Adeodato Simo
def Main():
386 819cbfe5 Michael Hanselmann
  return GenericMain(commands,
387 ef9fa5b9 René Nussbaumer
                     override={"tag_type": constants.TAG_NODEGROUP},
388 ef9fa5b9 René Nussbaumer
                     env_override=_ENV_OVERRIDE)