# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
+"""Cluster related commands"""
-# pylint: disable-msg=W0401,W0614
+# pylint: disable-msg=W0401,W0614,C0103
# W0401: Wildcard import ganeti.cli
# W0614: Unused import %s from wildcard import (since we need cli)
+# C0103: Invalid name gnt-cluster
import sys
import os.path
vg_name = constants.DEFAULT_VG
hvlist = opts.enabled_hypervisors
+ if hvlist is None:
+ hvlist = constants.DEFAULT_ENABLED_HYPERVISOR
hvlist = hvlist.split(",")
hvparams = dict(opts.hvparams)
hvparams[hv] = objects.FillDict(constants.HVC_DEFAULTS[hv], hvparams[hv])
utils.ForceDictType(hvparams[hv], constants.HVS_PARAMETER_TYPES)
+ if opts.candidate_pool_size is None:
+ opts.candidate_pool_size = constants.MASTER_POOL_SIZE_DEFAULT
+
+ if opts.mac_prefix is None:
+ opts.mac_prefix = constants.DEFAULT_MAC_PREFIX
+
bootstrap.InitCluster(cluster_name=args[0],
secondary_ip=opts.secondary_ip,
vg_name=vg_name,
nicparams=nicparams,
candidate_pool_size=opts.candidate_pool_size,
modify_etc_hosts=opts.modify_etc_hosts,
+ modify_ssh_setup=opts.modify_ssh_setup,
)
op = opcodes.OpPostInitCluster()
SubmitOpCode(op)
result = cl.QueryClusterInfo()
ToStdout("Cluster name: %s", result["name"])
+ ToStdout("Cluster UUID: %s", result["uuid"])
ToStdout("Creation time: %s", utils.FormatTime(result["ctime"]))
ToStdout("Modification time: %s", utils.FormatTime(result["mtime"]))
result["architecture"][0], result["architecture"][1])
if result["tags"]:
- tags = ", ".join(utils.NiceSort(result["tags"]))
+ tags = utils.CommaJoin(utils.NiceSort(result["tags"]))
else:
tags = "(none)"
ToStdout("Tags: %s", tags)
ToStdout("Default hypervisor: %s", result["default_hypervisor"])
- ToStdout("Enabled hypervisors: %s", ", ".join(result["enabled_hypervisors"]))
+ ToStdout("Enabled hypervisors: %s",
+ utils.CommaJoin(result["enabled_hypervisors"]))
ToStdout("Hypervisor parameters:")
_PrintGroupedParams(result["hvparams"])
"""
filename = args[0]
if not os.path.exists(filename):
- raise errors.OpPrereqError("No such filename '%s'" % filename)
+ raise errors.OpPrereqError("No such filename '%s'" % filename,
+ errors.ECODE_INVAL)
cl = GetClient()
- myname = utils.HostInfo().name
+ myname = utils.GetHostInfo().name
cluster_name = cl.QueryConfigValues(["cluster_name"])[0]
val = "unset"
ToStdout("The drain flag is %s" % val)
else:
- raise errors.OpPrereqError("Command '%s' is not valid." % command)
+ raise errors.OpPrereqError("Command '%s' is not valid." % command,
+ errors.ECODE_INVAL)
return 0
elif command == "pause":
if len(args) < 2:
- raise errors.OpPrereqError("Missing pause duration")
+ raise errors.OpPrereqError("Missing pause duration", errors.ECODE_INVAL)
result = client.SetWatcherPause(time.time() + ParseTimespec(args[1]))
_ShowWatcherPause(result)
_ShowWatcherPause(result)
else:
- raise errors.OpPrereqError("Command '%s' is not valid." % command)
+ raise errors.OpPrereqError("Command '%s' is not valid." % command,
+ errors.ECODE_INVAL)
return 0
commands = {
- 'init': (InitCluster, [ArgHost(min=1, max=1)],
- [DEBUG_OPT,
- cli_option("-s", "--secondary-ip", dest="secondary_ip",
- help="Specify the secondary ip for this node;"
- " if given, the entire cluster must have secondary"
- " addresses",
- metavar="ADDRESS", default=None),
- cli_option("-m", "--mac-prefix", dest="mac_prefix",
- help="Specify the mac prefix for the instance IP"
- " addresses, in the format XX:XX:XX",
- metavar="PREFIX",
- default=constants.DEFAULT_MAC_PREFIX,),
- cli_option("-g", "--vg-name", dest="vg_name",
- help="Specify the volume group name "
- " (cluster-wide) for disk allocation [xenvg]",
- metavar="VG",
- default=None,),
- cli_option("--master-netdev", dest="master_netdev",
- help="Specify the node interface (cluster-wide)"
- " on which the master IP address will be added "
- " [%s]" % constants.DEFAULT_BRIDGE,
- metavar="NETDEV",
- default=constants.DEFAULT_BRIDGE,),
- cli_option("--file-storage-dir", dest="file_storage_dir",
- help="Specify the default directory (cluster-wide)"
- " for storing the file-based disks [%s]" %
- constants.DEFAULT_FILE_STORAGE_DIR,
- metavar="DIR",
- default=constants.DEFAULT_FILE_STORAGE_DIR,),
- cli_option("--no-lvm-storage", dest="lvm_storage",
- help="No support for lvm based instances"
- " (cluster-wide)",
- action="store_false", default=True,),
- cli_option("--no-etc-hosts", dest="modify_etc_hosts",
- help="Don't modify /etc/hosts"
- " (cluster-wide)",
- action="store_false", default=True,),
- cli_option("--enabled-hypervisors", dest="enabled_hypervisors",
- help="Comma-separated list of hypervisors",
- type="string",
- default=constants.DEFAULT_ENABLED_HYPERVISOR),
- HVLIST_OPT,
- BACKEND_OPT,
- cli_option("-N", "--nic-parameters", dest="nicparams",
- type="keyval", default={},
- help="NIC parameters"),
- cli_option("-C", "--candidate-pool-size",
- default=constants.MASTER_POOL_SIZE_DEFAULT,
- help="Set the candidate pool size",
- dest="candidate_pool_size", type="int"),
- ],
- "[opts...] <cluster_name>",
- "Initialises a new cluster configuration"),
- 'destroy': (DestroyCluster, ARGS_NONE,
- [DEBUG_OPT,
- cli_option("--yes-do-it", dest="yes_do_it",
- help="Destroy cluster",
- action="store_true"),
- ],
- "", "Destroy cluster"),
- 'rename': (RenameCluster, [ArgHost(min=1, max=1)],
- [DEBUG_OPT, FORCE_OPT],
- "<new_name>",
- "Renames the cluster"),
- 'redist-conf': (RedistributeConfig, ARGS_NONE, [DEBUG_OPT, SUBMIT_OPT],
- "",
- "Forces a push of the configuration file and ssconf files"
- " to the nodes in the cluster"),
- 'verify': (VerifyCluster, ARGS_NONE,
- [DEBUG_OPT, VERBOSE_OPT, DEBUG_SIMERR_OPT,
- cli_option("--error-codes", dest="error_codes",
- help="Enable parseable error messages",
- action="store_true", default=False),
- cli_option("--no-nplus1-mem", dest="skip_nplusone_mem",
- help="Skip N+1 memory redundancy tests",
- action="store_true", default=False),
- ],
- "", "Does a check on the cluster configuration"),
- 'verify-disks': (VerifyDisks, ARGS_NONE, [DEBUG_OPT],
- "", "Does a check on the cluster disk status"),
- 'repair-disk-sizes': (RepairDiskSizes, ARGS_MANY_INSTANCES, [DEBUG_OPT],
- "", "Updates mismatches in recorded disk sizes"),
- 'masterfailover': (MasterFailover, ARGS_NONE, [DEBUG_OPT,
- cli_option("--no-voting", dest="no_voting",
- help="Skip node agreement check (dangerous)",
- action="store_true",
- default=False,),
- ],
- "", "Makes the current node the master"),
- 'version': (ShowClusterVersion, ARGS_NONE, [DEBUG_OPT],
- "", "Shows the cluster version"),
- 'getmaster': (ShowClusterMaster, ARGS_NONE, [DEBUG_OPT],
- "", "Shows the cluster master"),
- 'copyfile': (ClusterCopyFile, [ArgFile(min=1, max=1)],
- [DEBUG_OPT, NODE_LIST_OPT],
- "[-n node...] <filename>",
- "Copies a file to all (or only some) nodes"),
- 'command': (RunClusterCommand, [ArgCommand(min=1)],
- [DEBUG_OPT, NODE_LIST_OPT],
- "[-n node...] <command>",
- "Runs a command on all (or only some) nodes"),
- 'info': (ShowClusterConfig, ARGS_NONE, [DEBUG_OPT],
- "", "Show cluster configuration"),
- 'list-tags': (ListTags, ARGS_NONE,
- [DEBUG_OPT], "", "List the tags of the cluster"),
- 'add-tags': (AddTags, [ArgUnknown()], [DEBUG_OPT, TAG_SRC_OPT],
- "tag...", "Add tags to the cluster"),
- 'remove-tags': (RemoveTags, [ArgUnknown()], [DEBUG_OPT, TAG_SRC_OPT],
- "tag...", "Remove tags from the cluster"),
- 'search-tags': (SearchTags, [ArgUnknown(min=1, max=1)],
- [DEBUG_OPT], "", "Searches the tags on all objects on"
- " the cluster for a given pattern (regex)"),
- 'queue': (QueueOps,
- [ArgChoice(min=1, max=1, choices=["drain", "undrain", "info"])],
- [DEBUG_OPT],
- "drain|undrain|info", "Change queue properties"),
- 'watcher': (WatcherOps,
- [ArgChoice(min=1, max=1,
- choices=["pause", "continue", "info"]),
- ArgSuggest(min=0, max=1, choices=["30m", "1h", "4h"])],
- [DEBUG_OPT],
- "{pause <timespec>|continue|info}", "Change watcher properties"),
- 'modify': (SetClusterParams, ARGS_NONE,
- [DEBUG_OPT,
- cli_option("-g", "--vg-name", dest="vg_name",
- help="Specify the volume group name "
- " (cluster-wide) for disk allocation "
- "and enable lvm based storage",
- metavar="VG",),
- cli_option("--no-lvm-storage", dest="lvm_storage",
- help="Disable support for lvm based instances"
- " (cluster-wide)",
- action="store_false", default=True,),
- cli_option("--enabled-hypervisors", dest="enabled_hypervisors",
- help="Comma-separated list of hypervisors",
- type="string", default=None),
- HVLIST_OPT,
- BACKEND_OPT,
- cli_option("-N", "--nic-parameters", dest="nicparams",
- type="keyval", default={},
- help="NIC parameters"),
- cli_option("-C", "--candidate-pool-size", default=None,
- help="Set the candidate pool size",
- dest="candidate_pool_size", type="int"),
- ],
- "[opts...]",
- "Alters the parameters of the cluster"),
+ 'init': (
+ InitCluster, [ArgHost(min=1, max=1)],
+ [BACKEND_OPT, CP_SIZE_OPT, ENABLED_HV_OPT, GLOBAL_FILEDIR_OPT,
+ HVLIST_OPT, MAC_PREFIX_OPT, MASTER_NETDEV_OPT, NIC_PARAMS_OPT,
+ NOLVM_STORAGE_OPT, NOMODIFY_ETCHOSTS_OPT, NOMODIFY_SSH_SETUP_OPT,
+ SECONDARY_IP_OPT, VG_NAME_OPT],
+ "[opts...] <cluster_name>", "Initialises a new cluster configuration"),
+ 'destroy': (
+ DestroyCluster, ARGS_NONE, [YES_DOIT_OPT],
+ "", "Destroy cluster"),
+ 'rename': (
+ RenameCluster, [ArgHost(min=1, max=1)],
+ [FORCE_OPT],
+ "<new_name>",
+ "Renames the cluster"),
+ 'redist-conf': (
+ RedistributeConfig, ARGS_NONE, [SUBMIT_OPT],
+ "", "Forces a push of the configuration file and ssconf files"
+ " to the nodes in the cluster"),
+ 'verify': (
+ VerifyCluster, ARGS_NONE,
+ [VERBOSE_OPT, DEBUG_SIMERR_OPT, ERROR_CODES_OPT, NONPLUS1_OPT],
+ "", "Does a check on the cluster configuration"),
+ 'verify-disks': (
+ VerifyDisks, ARGS_NONE, [],
+ "", "Does a check on the cluster disk status"),
+ 'repair-disk-sizes': (
+ RepairDiskSizes, ARGS_MANY_INSTANCES, [],
+ "", "Updates mismatches in recorded disk sizes"),
+ 'masterfailover': (
+ MasterFailover, ARGS_NONE, [NOVOTING_OPT],
+ "", "Makes the current node the master"),
+ 'version': (
+ ShowClusterVersion, ARGS_NONE, [],
+ "", "Shows the cluster version"),
+ 'getmaster': (
+ ShowClusterMaster, ARGS_NONE, [],
+ "", "Shows the cluster master"),
+ 'copyfile': (
+ ClusterCopyFile, [ArgFile(min=1, max=1)],
+ [NODE_LIST_OPT],
+ "[-n node...] <filename>", "Copies a file to all (or only some) nodes"),
+ 'command': (
+ RunClusterCommand, [ArgCommand(min=1)],
+ [NODE_LIST_OPT],
+ "[-n node...] <command>", "Runs a command on all (or only some) nodes"),
+ 'info': (
+ ShowClusterConfig, ARGS_NONE, [],
+ "", "Show cluster configuration"),
+ 'list-tags': (
+ ListTags, ARGS_NONE, [], "", "List the tags of the cluster"),
+ 'add-tags': (
+ AddTags, [ArgUnknown()], [TAG_SRC_OPT],
+ "tag...", "Add tags to the cluster"),
+ 'remove-tags': (
+ RemoveTags, [ArgUnknown()], [TAG_SRC_OPT],
+ "tag...", "Remove tags from the cluster"),
+ 'search-tags': (
+ SearchTags, [ArgUnknown(min=1, max=1)],
+ [], "", "Searches the tags on all objects on"
+ " the cluster for a given pattern (regex)"),
+ 'queue': (
+ QueueOps,
+ [ArgChoice(min=1, max=1, choices=["drain", "undrain", "info"])],
+ [], "drain|undrain|info", "Change queue properties"),
+ 'watcher': (
+ WatcherOps,
+ [ArgChoice(min=1, max=1, choices=["pause", "continue", "info"]),
+ ArgSuggest(min=0, max=1, choices=["30m", "1h", "4h"])],
+ [],
+ "{pause <timespec>|continue|info}", "Change watcher properties"),
+ 'modify': (
+ SetClusterParams, ARGS_NONE,
+ [BACKEND_OPT, CP_SIZE_OPT, ENABLED_HV_OPT, HVLIST_OPT,
+ NIC_PARAMS_OPT, NOLVM_STORAGE_OPT, VG_NAME_OPT],
+ "[opts...]",
+ "Alters the parameters of the cluster"),
}
if __name__ == '__main__':