#
#
-# Copyright (C) 2006, 2007, 2008, 2009, 2010 Google Inc.
+# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# few public methods:
# pylint: disable-msg=R0903
+import logging
+
from ganeti import constants
from ganeti import errors
from ganeti import ht
slots.extend(getattr(parent, "OP_PARAMS", []))
return slots
+ def Validate(self, set_defaults):
+ """Validate opcode parameters, optionally setting default values.
+
+ @type set_defaults: bool
+ @param set_defaults: Whether to set default values
+ @raise errors.OpPrereqError: When a parameter value doesn't match
+ requirements
+
+ """
+ for (attr_name, default, test) in self.GetAllParams():
+ assert test == ht.NoType or callable(test)
+
+ if not hasattr(self, attr_name):
+ if default == ht.NoDefault:
+ raise errors.OpPrereqError("Required parameter '%s.%s' missing" %
+ (self.OP_ID, attr_name),
+ errors.ECODE_INVAL)
+ elif set_defaults:
+ if callable(default):
+ dval = default()
+ else:
+ dval = default
+ setattr(self, attr_name, dval)
+
+ if test == ht.NoType:
+ # no tests here
+ continue
+
+ if set_defaults or hasattr(self, attr_name):
+ attr_val = getattr(self, attr_name)
+ if not test(attr_val):
+ logging.error("OpCode %s, parameter %s, has invalid type %s/value %s",
+ self.OP_ID, attr_name, type(attr_val), attr_val)
+ raise errors.OpPrereqError("Parameter '%s.%s' fails validation" %
+ (self.OP_ID, attr_name),
+ errors.ECODE_INVAL)
+
class OpCode(BaseOpCode):
"""Abstract OpCode.
method for details).
@cvar OP_PARAMS: List of opcode attributes, the default values they should
get if not already defined, and types they must match.
+ @cvar WITH_LU: Boolean that specifies whether this should be included in
+ mcpu's dispatch table
@ivar dry_run: Whether the LU should be run in dry-run mode, i.e. just
the check steps
@ivar priority: Opcode priority for queue
"""
OP_ID = "OP_ABSTRACT"
+ WITH_LU = True
OP_PARAMS = [
("dry_run", None, ht.TMaybeBool),
("debug_level", None, ht.TOr(ht.TNone, ht.TPositiveInt)),
# cluster opcodes
-class OpPostInitCluster(OpCode):
+class OpClusterPostInit(OpCode):
"""Post cluster initialization.
This opcode does not touch the cluster at all. Its purpose is to run hooks
OP_ID = "OP_CLUSTER_POST_INIT"
-class OpDestroyCluster(OpCode):
+class OpClusterDestroy(OpCode):
"""Destroy the cluster.
This opcode has no other parameters. All the state is irreversibly
OP_ID = "OP_CLUSTER_DESTROY"
-class OpQueryClusterInfo(OpCode):
+class OpClusterQuery(OpCode):
"""Query cluster information."""
OP_ID = "OP_CLUSTER_QUERY"
-class OpVerifyCluster(OpCode):
+class OpClusterVerify(OpCode):
"""Verify the cluster state.
@type skip_checks: C{list}
]
-class OpVerifyDisks(OpCode):
+class OpClusterVerifyDisks(OpCode):
"""Verify the cluster disks.
Parameters: none
OP_ID = "OP_CLUSTER_VERIFY_DISKS"
-class OpRepairDiskSizes(OpCode):
+class OpClusterRepairDiskSizes(OpCode):
"""Verify the disk sizes of the instances and fixes configuration
mimatches.
]
-class OpQueryConfigValues(OpCode):
+class OpClusterConfigQuery(OpCode):
"""Query cluster configuration values."""
OP_ID = "OP_CLUSTER_CONFIG_QUERY"
OP_PARAMS = [
]
-class OpRenameCluster(OpCode):
+class OpClusterRename(OpCode):
"""Rename the cluster.
@type name: C{str}
]
-class OpSetClusterParams(OpCode):
+class OpClusterSetParams(OpCode):
"""Change the parameters of the cluster.
@type vg_name: C{str} or C{None}
]
-class OpRedistributeConfig(OpCode):
+class OpClusterRedistConf(OpCode):
"""Force a full push of the cluster configuration.
"""
]
-class OpAddNode(OpCode):
+class OpNodeAdd(OpCode):
"""Add a node to the cluster.
@type node_name: C{str}
# instance opcodes
-class OpCreateInstance(OpCode):
+class OpInstanceCreate(OpCode):
"""Create an instance.
@ivar instance_name: Instance name
]
-class OpReinstallInstance(OpCode):
+class OpInstanceReinstall(OpCode):
"""Reinstall an instance's OS."""
OP_ID = "OP_INSTANCE_REINSTALL"
OP_DSC_FIELD = "instance_name"
]
-class OpRemoveInstance(OpCode):
+class OpInstanceRemove(OpCode):
"""Remove an instance."""
OP_ID = "OP_INSTANCE_REMOVE"
OP_DSC_FIELD = "instance_name"
]
-class OpRenameInstance(OpCode):
+class OpInstanceRename(OpCode):
"""Rename an instance."""
OP_ID = "OP_INSTANCE_RENAME"
OP_PARAMS = [
]
-class OpStartupInstance(OpCode):
+class OpInstanceStartup(OpCode):
"""Startup an instance."""
OP_ID = "OP_INSTANCE_STARTUP"
OP_DSC_FIELD = "instance_name"
]
-class OpShutdownInstance(OpCode):
+class OpInstanceShutdown(OpCode):
"""Shutdown an instance."""
OP_ID = "OP_INSTANCE_SHUTDOWN"
OP_DSC_FIELD = "instance_name"
]
-class OpRebootInstance(OpCode):
+class OpInstanceReboot(OpCode):
"""Reboot an instance."""
OP_ID = "OP_INSTANCE_REBOOT"
OP_DSC_FIELD = "instance_name"
]
-class OpReplaceDisks(OpCode):
+class OpInstanceReplaceDisks(OpCode):
"""Replace the disks of an instance."""
OP_ID = "OP_INSTANCE_REPLACE_DISKS"
OP_DSC_FIELD = "instance_name"
]
-class OpFailoverInstance(OpCode):
+class OpInstanceFailover(OpCode):
"""Failover an instance."""
OP_ID = "OP_INSTANCE_FAILOVER"
OP_DSC_FIELD = "instance_name"
]
-class OpMigrateInstance(OpCode):
+class OpInstanceMigrate(OpCode):
"""Migrate an instance.
This migrates (without shutting down an instance) to its secondary
]
-class OpMoveInstance(OpCode):
+class OpInstanceMove(OpCode):
"""Move an instance.
This move (with shutting down an instance and data copying) to an
]
-class OpConnectConsole(OpCode):
+class OpInstanceConsole(OpCode):
"""Connect to an instance's console."""
OP_ID = "OP_INSTANCE_CONSOLE"
OP_DSC_FIELD = "instance_name"
]
-class OpActivateInstanceDisks(OpCode):
+class OpInstanceActivateDisks(OpCode):
"""Activate an instance's disks."""
OP_ID = "OP_INSTANCE_ACTIVATE_DISKS"
OP_DSC_FIELD = "instance_name"
]
-class OpDeactivateInstanceDisks(OpCode):
+class OpInstanceDeactivateDisks(OpCode):
"""Deactivate an instance's disks."""
OP_ID = "OP_INSTANCE_DEACTIVATE_DISKS"
OP_DSC_FIELD = "instance_name"
]
-class OpRecreateInstanceDisks(OpCode):
+class OpInstanceRecreateDisks(OpCode):
"""Deactivate an instance's disks."""
OP_ID = "OP_INSTANCE_RECREATE_DISKS"
OP_DSC_FIELD = "instance_name"
]
-class OpQueryInstances(OpCode):
+class OpInstanceQuery(OpCode):
"""Compute the list of instances."""
OP_ID = "OP_INSTANCE_QUERY"
OP_PARAMS = [
]
-class OpQueryInstanceData(OpCode):
+class OpInstanceQueryData(OpCode):
"""Compute the run-time status of instances."""
OP_ID = "OP_INSTANCE_QUERY_DATA"
OP_PARAMS = [
]
-class OpSetInstanceParams(OpCode):
+class OpInstanceSetParams(OpCode):
"""Change the parameters of an instance."""
OP_ID = "OP_INSTANCE_SET_PARAMS"
OP_DSC_FIELD = "instance_name"
("disks", ht.EmptyList, ht.TList),
("beparams", ht.EmptyDict, ht.TDict),
("hvparams", ht.EmptyDict, ht.TDict),
- ("disk_template", None, _CheckDiskTemplate),
+ ("disk_template", None, ht.TOr(ht.TNone, _CheckDiskTemplate)),
("remote_node", None, ht.TMaybeString),
("os_name", None, ht.TMaybeString),
("force_variant", False, ht.TBool),
]
-class OpGrowDisk(OpCode):
+class OpInstanceGrowDisk(OpCode):
"""Grow a disk of an instance."""
OP_ID = "OP_INSTANCE_GROW_DISK"
OP_DSC_FIELD = "instance_name"
# Node group opcodes
-class OpAddGroup(OpCode):
+class OpGroupAdd(OpCode):
"""Add a node group to the cluster."""
OP_ID = "OP_GROUP_ADD"
OP_DSC_FIELD = "group_name"
]
-class OpQueryGroups(OpCode):
+class OpGroupAssignNodes(OpCode):
+ """Assign nodes to a node group."""
+ OP_ID = "OP_GROUP_ASSIGN_NODES"
+ OP_DSC_FIELD = "group_name"
+ OP_PARAMS = [
+ _PGroupName,
+ _PForce,
+ ("nodes", ht.NoDefault, ht.TListOf(ht.TNonEmptyString)),
+ ]
+
+
+class OpGroupQuery(OpCode):
"""Compute the list of node groups."""
OP_ID = "OP_GROUP_QUERY"
OP_PARAMS = [
]
-class OpSetGroupParams(OpCode):
+class OpGroupSetParams(OpCode):
"""Change the parameters of a node group."""
OP_ID = "OP_GROUP_SET_PARAMS"
OP_DSC_FIELD = "group_name"
]
-class OpRemoveGroup(OpCode):
+class OpGroupRemove(OpCode):
"""Remove a node group from the cluster."""
OP_ID = "OP_GROUP_REMOVE"
OP_DSC_FIELD = "group_name"
]
-class OpRenameGroup(OpCode):
+class OpGroupRename(OpCode):
"""Rename a node group in the cluster."""
OP_ID = "OP_GROUP_RENAME"
OP_DSC_FIELD = "old_name"
# Exports opcodes
-class OpQueryExports(OpCode):
+class OpBackupQuery(OpCode):
"""Compute the list of exported images."""
OP_ID = "OP_BACKUP_QUERY"
OP_PARAMS = [
]
-class OpPrepareExport(OpCode):
+class OpBackupPrepare(OpCode):
"""Prepares an instance export.
@ivar instance_name: Instance name
]
-class OpExportInstance(OpCode):
+class OpBackupExport(OpCode):
"""Export an instance.
For local exports, the export destination is the node name. For remote
]
-class OpRemoveExport(OpCode):
+class OpBackupRemove(OpCode):
"""Remove an instance's export."""
OP_ID = "OP_BACKUP_REMOVE"
OP_DSC_FIELD = "instance_name"
("messages", ht.NoDefault, ht.NoType),
("fail", ht.NoDefault, ht.NoType),
]
+ WITH_LU = False
def _GetOpList():
"""
return [v for v in globals().values()
if (isinstance(v, type) and issubclass(v, OpCode) and
- hasattr(v, "OP_ID"))]
+ hasattr(v, "OP_ID") and v is not OpCode)]
OP_MAPPING = dict((v.OP_ID, v) for v in _GetOpList())