#
#
-# 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 OpQueryConfigValues(OpCode):
+class OpClusterConfigQuery(OpCode):
"""Query cluster configuration values."""
OP_ID = "OP_CLUSTER_CONFIG_QUERY"
OP_PARAMS = [
]
-class OpRedistributeConfig(OpCode):
+class OpClusterRedistConf(OpCode):
"""Force a full push of the cluster configuration.
"""
("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 OpAssignGroupNodes(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 OpQueryGroups(OpCode):
"""Compute the list of node groups."""
OP_ID = "OP_GROUP_QUERY"
# 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())