Revision 3a24c527 scripts/gnt-cluster

b/scripts/gnt-cluster
21 21

  
22 22
import sys
23 23
from optparse import make_option
24
import pprint
25 24
import os.path
26 25

  
27 26
from ganeti.cli import *
......
43 42

  
44 43
  """
45 44
  if not opts.lvm_storage and opts.vg_name:
46
    print ("Options --no-lvm-storage and --vg-name conflict.")
45
    ToStderr("Options --no-lvm-storage and --vg-name conflict.")
47 46
    return 1
48 47

  
49 48
  vg_name = opts.vg_name
......
119 118

  
120 119
  """
121 120
  if not opts.yes_do_it:
122
    print ("Destroying a cluster is irreversibly. If you really want destroy"
123
           " this cluster, supply the --yes-do-it option.")
121
    ToStderr("Destroying a cluster is irreversible. If you really want"
122
             " destroy this cluster, supply the --yes-do-it option.")
124 123
    return 1
125 124

  
126 125
  op = opcodes.OpDestroyCluster()
......
162 161
  """
163 162
  op = opcodes.OpQueryClusterInfo()
164 163
  result = SubmitOpCode(op)
165
  print ("Software version: %s" % result["software_version"])
166
  print ("Internode protocol: %s" % result["protocol_version"])
167
  print ("Configuration format: %s" % result["config_version"])
168
  print ("OS api version: %s" % result["os_api_version"])
169
  print ("Export interface: %s" % result["export_version"])
164
  ToStdout("Software version: %s", result["software_version"])
165
  ToStdout("Internode protocol: %s", result["protocol_version"])
166
  ToStdout("Configuration format: %s", result["config_version"])
167
  ToStdout("OS api version: %s", result["os_api_version"])
168
  ToStdout("Export interface: %s", result["export_version"])
170 169
  return 0
171 170

  
172 171

  
......
177 176
    opts - class with options as members
178 177

  
179 178
  """
180
  print GetClient().QueryConfigValues(["master_node"])[0]
179
  ToStdout("%s", GetClient().QueryConfigValues(["master_node"])[0])
181 180
  return 0
182 181

  
183 182

  
......
188 187
  op = opcodes.OpQueryClusterInfo()
189 188
  result = SubmitOpCode(op)
190 189

  
191
  print ("Cluster name: %s" % result["name"])
190
  ToStdout("Cluster name: %s", result["name"])
192 191

  
193
  print ("Master node: %s" % result["master"])
192
  ToStdout("Master node: %s", result["master"])
194 193

  
195
  print ("Architecture (this node): %s (%s)" %
196
         (result["architecture"][0], result["architecture"][1]))
194
  ToStdout("Architecture (this node): %s (%s)",
195
           result["architecture"][0], result["architecture"][1])
197 196

  
198
  print ("Default hypervisor: %s" % result["hypervisor_type"])
199
  print ("Enabled hypervisors: %s" % ", ".join(result["enabled_hypervisors"]))
197
  ToStdout("Default hypervisor: %s", result["hypervisor_type"])
198
  ToStdout("Enabled hypervisors: %s", ", ".join(result["enabled_hypervisors"]))
200 199

  
201
  print "Hypervisor parameters:"
200
  ToStdout("Hypervisor parameters:")
202 201
  for hv_name, hv_dict in result["hvparams"].items():
203
    print "  - %s:" % hv_name
202
    ToStdout("  - %s:", hv_name)
204 203
    for item, val in hv_dict.iteritems():
205
      print "      %s: %s" % (item, val)
204
      ToStdout("      %s: %s", item, val)
206 205

  
207
  print "Cluster parameters:"
206
  ToStdout("Cluster parameters:")
208 207
  for gr_name, gr_dict in result["beparams"].items():
209
    print "  - %s:" % gr_name
208
    ToStdout("  - %s:", gr_name)
210 209
    for item, val in gr_dict.iteritems():
211
      print "      %s: %s" % (item, val)
210
      ToStdout("      %s: %s", item, val)
212 211

  
213 212
  return 0
214 213

  
......
239 238
  srun = ssh.SshRunner(cluster_name=cluster_name)
240 239
  for node in results:
241 240
    if not srun.CopyFileToNode(node, filename):
242
      print >> sys.stderr, ("Copy of file %s to node %s failed" %
243
                            (filename, node))
241
      ToStderr("Copy of file %s to node %s failed", filename, node)
244 242

  
245 243
  return 0
246 244

  
......
273 271

  
274 272
  for name in nodes:
275 273
    result = srun.Run(name, "root", command)
276
    print ("------------------------------------------------")
277
    print ("node: %s" % name)
278
    print ("%s" % result.output)
279
    print ("return code = %s" % result.exit_code)
274
    ToStdout("------------------------------------------------")
275
    ToStdout("node: %s", name)
276
    ToStdout("%s", result.output)
277
    ToStdout("return code = %s", result.exit_code)
280 278

  
281 279
  return 0
282 280

  
......
313 311
  nodes, nlvm, instances, missing = result
314 312

  
315 313
  if nodes:
316
    print "Nodes unreachable or with bad data:"
314
    ToStdout("Nodes unreachable or with bad data:")
317 315
    for name in nodes:
318
      print "\t%s" % name
316
      ToStdout("\t%s", name)
319 317
  retcode = constants.EXIT_SUCCESS
320 318

  
321 319
  if nlvm:
322 320
    for node, text in nlvm.iteritems():
323
      print ("Error on node %s: LVM error: %s" %
324
             (node, text[-400:].encode('string_escape')))
321
      ToStdout("Error on node %s: LVM error: %s",
322
               node, text[-400:].encode('string_escape'))
325 323
      retcode |= 1
326
      print "You need to fix these nodes first before fixing instances"
324
      ToStdout("You need to fix these nodes first before fixing instances")
327 325

  
328 326
  if instances:
329 327
    for iname in instances:
......
331 329
        continue
332 330
      op = opcodes.OpActivateInstanceDisks(instance_name=iname)
333 331
      try:
334
        print "Activating disks for instance '%s'" % iname
332
        ToStdout("Activating disks for instance '%s'", iname)
335 333
        SubmitOpCode(op)
336 334
      except errors.GenericError, err:
337 335
        nret, msg = FormatError(err)
338 336
        retcode |= nret
339
        print >> sys.stderr, ("Error activating disks for instance %s: %s" %
340
                              (iname, msg))
337
        ToStderr("Error activating disks for instance %s: %s", iname, msg)
341 338

  
342 339
  if missing:
343 340
    for iname, ival in missing.iteritems():
344 341
      all_missing = utils.all(ival, lambda x: x[0] in nlvm)
345 342
      if all_missing:
346
        print ("Instance %s cannot be verified as it lives on"
347
               " broken nodes" % iname)
343
        ToStdout("Instance %s cannot be verified as it lives on"
344
                 " broken nodes", iname)
348 345
      else:
349
        print "Instance %s has missing logical volumes:" % iname
346
        ToStdout("Instance %s has missing logical volumes:", iname)
350 347
        ival.sort()
351 348
        for node, vol in ival:
352 349
          if node in nlvm:
353
            print ("\tbroken node %s /dev/xenvg/%s" % (node, vol))
350
            ToStdout("\tbroken node %s /dev/xenvg/%s", node, vol)
354 351
          else:
355
            print ("\t%s /dev/xenvg/%s" % (node, vol))
356
    print ("You need to run replace_disks for all the above"
352
            ToStdout("\t%s /dev/xenvg/%s", node, vol)
353
    ToStdout("You need to run replace_disks for all the above"
357 354
           " instances, if this message persist after fixing nodes.")
358 355
    retcode |= 1
359 356

  
......
382 379
  result = list(result)
383 380
  result.sort()
384 381
  for path, tag in result:
385
    print "%s %s" % (path, tag)
382
    ToStdout("%s %s", path, tag)
386 383

  
387 384

  
388 385
def SetClusterParams(opts, args):
......
395 392
  if not (not opts.lvm_storage or opts.vg_name or
396 393
          opts.enabled_hypervisors or opts.hvparams or
397 394
          opts.beparams):
398
    print "Please give at least one of the parameters."
395
    ToStderr("Please give at least one of the parameters.")
399 396
    return 1
400 397

  
401 398
  vg_name = opts.vg_name
402 399
  if not opts.lvm_storage and opts.vg_name:
403
    print ("Options --no-lvm-storage and --vg-name conflict.")
400
    ToStdout("Options --no-lvm-storage and --vg-name conflict.")
404 401
    return 1
405 402

  
406 403
  hvlist = opts.enabled_hypervisors
......
433 430
    client.SetQueueDrainFlag(drain_flag)
434 431
  elif command == "info":
435 432
    result = client.QueryConfigValues(["drain_flag"])
436
    print "The drain flag is",
437 433
    if result[0]:
438
      print "set"
434
      val = "set"
439 435
    else:
440
      print "unset"
436
      val = "unset"
437
    ToStdout("The drain flag is %s" % val)
441 438
  return 0
442 439

  
443 440
# this is an option common to more than one command, so we declare

Also available in: Unified diff