Revision ea9d3b40 lib/client/gnt_group.py

b/lib/client/gnt_group.py
24 24
# W0401: Wildcard import ganeti.cli
25 25
# W0614: Unused import %s from wildcard import (since we need cli)
26 26

  
27
from cStringIO import StringIO
28

  
27 29
from ganeti.cli import *
28 30
from ganeti import constants
29 31
from ganeti import opcodes
......
313 315
    ])
314 316

  
315 317

  
318
def _GetCreateCommand(group):
319
  (name, ipolicy) = group
320
  buf = StringIO()
321
  buf.write("gnt-group add")
322
  PrintIPolicyCommand(buf, ipolicy, True)
323
  buf.write(" ")
324
  buf.write(name)
325
  return buf.getvalue()
326

  
327

  
328
def ShowCreateCommand(opts, args):
329
  """Shows the command that can be used to re-create a node group.
330

  
331
  Currently it works only for ipolicy specs.
332

  
333
  """
334
  cl = GetClient(query=True)
335
  selected_fields = ["name"]
336
  if opts.include_defaults:
337
    selected_fields += ["ipolicy"]
338
  else:
339
    selected_fields += ["custom_ipolicy"]
340
  result = cl.QueryGroups(names=args, fields=selected_fields,
341
                          use_locking=False)
342

  
343
  for group in result:
344
    ToStdout(_GetCreateCommand(group))
345

  
346

  
316 347
commands = {
317 348
  "add": (
318 349
    AddGroup, ARGS_ONE_GROUP,
......
366 397
  "info": (
367 398
    GroupInfo, ARGS_MANY_GROUPS, [], "[<group_name>...]",
368 399
    "Show group information"),
400
  "show-ispecs-cmd": (
401
    ShowCreateCommand, ARGS_MANY_GROUPS, [INCLUDEDEFAULTS_OPT],
402
    "[--include-defaults] [<group_name>...]",
403
    "Show the command line to re-create a group"),
369 404
  }
370 405

  
371 406

  

Also available in: Unified diff