# 02110-1301, USA.
+# pylint: disable-msg=W0401,W0614
+# W0401: Wildcard import ganeti.cli
+# W0614: Unused import %s from wildcard import (since we need cli)
+
import sys
from optparse import make_option
-import pprint
import os.path
from ganeti.cli import *
from ganeti import utils
from ganeti import bootstrap
from ganeti import ssh
-from ganeti import ssconf
def InitCluster(opts, args):
"""
if not opts.lvm_storage and opts.vg_name:
- print ("Options --no-lvm-storage and --vg-name conflict.")
+ ToStderr("Options --no-lvm-storage and --vg-name conflict.")
return 1
vg_name = opts.vg_name
if hvlist is not None:
hvlist = hvlist.split(",")
else:
- hvlist = constants.DEFAULT_ENABLED_HYPERVISOR
+ hvlist = [constants.DEFAULT_ENABLED_HYPERVISOR]
+
+ # avoid an impossible situation
+ if opts.default_hypervisor in hvlist:
+ default_hypervisor = opts.default_hypervisor
+ else:
+ default_hypervisor = hvlist[0]
hvparams = opts.hvparams
if hvparams:
bootstrap.InitCluster(cluster_name=args[0],
secondary_ip=opts.secondary_ip,
- hypervisor_type=opts.hypervisor_type,
vg_name=vg_name,
mac_prefix=opts.mac_prefix,
def_bridge=opts.def_bridge,
master_netdev=opts.master_netdev,
file_storage_dir=opts.file_storage_dir,
enabled_hypervisors=hvlist,
+ default_hypervisor=default_hypervisor,
hvparams=hvparams,
beparams=beparams)
return 0
"""
if not opts.yes_do_it:
- print ("Destroying a cluster is irreversibly. If you really want destroy"
- " this cluster, supply the --yes-do-it option.")
+ ToStderr("Destroying a cluster is irreversible. If you really want"
+ " destroy this cluster, supply the --yes-do-it option.")
return 1
op = opcodes.OpDestroyCluster()
"""
op = opcodes.OpQueryClusterInfo()
result = SubmitOpCode(op)
- print ("Software version: %s" % result["software_version"])
- print ("Internode protocol: %s" % result["protocol_version"])
- print ("Configuration format: %s" % result["config_version"])
- print ("OS api version: %s" % result["os_api_version"])
- print ("Export interface: %s" % result["export_version"])
+ ToStdout("Software version: %s", result["software_version"])
+ ToStdout("Internode protocol: %s", result["protocol_version"])
+ ToStdout("Configuration format: %s", result["config_version"])
+ ToStdout("OS api version: %s", result["os_api_version"])
+ ToStdout("Export interface: %s", result["export_version"])
return 0
opts - class with options as members
"""
- print GetClient().QueryConfigValues(["master_node"])[0]
+ ToStdout("%s", GetClient().QueryConfigValues(["master_node"])[0])
return 0
op = opcodes.OpQueryClusterInfo()
result = SubmitOpCode(op)
- print ("Cluster name: %s" % result["name"])
+ ToStdout("Cluster name: %s", result["name"])
- print ("Master node: %s" % result["master"])
+ ToStdout("Master node: %s", result["master"])
- print ("Architecture (this node): %s (%s)" %
- (result["architecture"][0], result["architecture"][1]))
+ ToStdout("Architecture (this node): %s (%s)",
+ result["architecture"][0], result["architecture"][1])
- print ("Default hypervisor: %s" % result["hypervisor_type"])
- print ("Enabled hypervisors: %s" % ", ".join(result["enabled_hypervisors"]))
+ ToStdout("Default hypervisor: %s", result["default_hypervisor"])
+ ToStdout("Enabled hypervisors: %s", ", ".join(result["enabled_hypervisors"]))
- print "Hypervisor parameters:"
+ ToStdout("Hypervisor parameters:")
for hv_name, hv_dict in result["hvparams"].items():
- print " - %s:" % hv_name
+ ToStdout(" - %s:", hv_name)
for item, val in hv_dict.iteritems():
- print " %s: %s" % (item, val)
+ ToStdout(" %s: %s", item, val)
- print "Cluster parameters:"
+ ToStdout("Cluster parameters:")
for gr_name, gr_dict in result["beparams"].items():
- print " - %s:" % gr_name
+ ToStdout(" - %s:", gr_name)
for item, val in gr_dict.iteritems():
- print " %s: %s" % (item, val)
+ ToStdout(" %s: %s", item, val)
return 0
srun = ssh.SshRunner(cluster_name=cluster_name)
for node in results:
if not srun.CopyFileToNode(node, filename):
- print >> sys.stderr, ("Copy of file %s to node %s failed" %
- (filename, node))
+ ToStderr("Copy of file %s to node %s failed", filename, node)
return 0
for name in nodes:
result = srun.Run(name, "root", command)
- print ("------------------------------------------------")
- print ("node: %s" % name)
- print ("%s" % result.output)
- print ("return code = %s" % result.exit_code)
+ ToStdout("------------------------------------------------")
+ ToStdout("node: %s", name)
+ ToStdout("%s", result.output)
+ ToStdout("return code = %s", result.exit_code)
return 0
nodes, nlvm, instances, missing = result
if nodes:
- print "Nodes unreachable or with bad data:"
+ ToStdout("Nodes unreachable or with bad data:")
for name in nodes:
- print "\t%s" % name
+ ToStdout("\t%s", name)
retcode = constants.EXIT_SUCCESS
if nlvm:
for node, text in nlvm.iteritems():
- print ("Error on node %s: LVM error: %s" %
- (node, text[-400:].encode('string_escape')))
+ ToStdout("Error on node %s: LVM error: %s",
+ node, text[-400:].encode('string_escape'))
retcode |= 1
- print "You need to fix these nodes first before fixing instances"
+ ToStdout("You need to fix these nodes first before fixing instances")
if instances:
for iname in instances:
continue
op = opcodes.OpActivateInstanceDisks(instance_name=iname)
try:
- print "Activating disks for instance '%s'" % iname
+ ToStdout("Activating disks for instance '%s'", iname)
SubmitOpCode(op)
except errors.GenericError, err:
nret, msg = FormatError(err)
retcode |= nret
- print >> sys.stderr, ("Error activating disks for instance %s: %s" %
- (iname, msg))
+ ToStderr("Error activating disks for instance %s: %s", iname, msg)
if missing:
for iname, ival in missing.iteritems():
all_missing = utils.all(ival, lambda x: x[0] in nlvm)
if all_missing:
- print ("Instance %s cannot be verified as it lives on"
- " broken nodes" % iname)
+ ToStdout("Instance %s cannot be verified as it lives on"
+ " broken nodes", iname)
else:
- print "Instance %s has missing logical volumes:" % iname
+ ToStdout("Instance %s has missing logical volumes:", iname)
ival.sort()
for node, vol in ival:
if node in nlvm:
- print ("\tbroken node %s /dev/xenvg/%s" % (node, vol))
+ ToStdout("\tbroken node %s /dev/xenvg/%s", node, vol)
else:
- print ("\t%s /dev/xenvg/%s" % (node, vol))
- print ("You need to run replace_disks for all the above"
+ ToStdout("\t%s /dev/xenvg/%s", node, vol)
+ ToStdout("You need to run replace_disks for all the above"
" instances, if this message persist after fixing nodes.")
retcode |= 1
result = list(result)
result.sort()
for path, tag in result:
- print "%s %s" % (path, tag)
+ ToStdout("%s %s", path, tag)
def SetClusterParams(opts, args):
if not (not opts.lvm_storage or opts.vg_name or
opts.enabled_hypervisors or opts.hvparams or
opts.beparams):
- print "Please give at least one of the parameters."
+ ToStderr("Please give at least one of the parameters.")
return 1
vg_name = opts.vg_name
if not opts.lvm_storage and opts.vg_name:
- print ("Options --no-lvm-storage and --vg-name conflict.")
+ ToStdout("Options --no-lvm-storage and --vg-name conflict.")
return 1
hvlist = opts.enabled_hypervisors
client.SetQueueDrainFlag(drain_flag)
elif command == "info":
result = client.QueryConfigValues(["drain_flag"])
- print "The drain flag is",
if result[0]:
- print "set"
+ val = "set"
else:
- print "unset"
+ val = "unset"
+ ToStdout("The drain flag is %s" % val)
return 0
# this is an option common to more than one command, so we declare
" if given, the entire cluster must have secondary"
" addresses",
metavar="ADDRESS", default=None),
- make_option("-t", "--hypervisor-type", dest="hypervisor_type",
- help="Specify the hypervisor type "
- "(xen-pvm, kvm, fake, xen-hvm)",
- metavar="TYPE", choices=["xen-pvm",
- "kvm",
- "fake",
- "xen-hvm"],
- default="xen-pvm",),
make_option("-m", "--mac-prefix", dest="mac_prefix",
help="Specify the mac prefix for the instance IP"
" addresses, in the format XX:XX:XX",
make_option("--enabled-hypervisors", dest="enabled_hypervisors",
help="Comma-separated list of hypervisors",
type="string", default=None),
+ make_option("-t", "--default-hypervisor",
+ dest="default_hypervisor",
+ help="Default hypervisor to use for instance creation",
+ choices=list(constants.HYPER_TYPES),
+ default=constants.DEFAULT_ENABLED_HYPERVISOR),
ikv_option("-H", "--hypervisor-parameters", dest="hvparams",
help="Hypervisor and hypervisor options, in the"
" format"