#
#
-# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Google Inc.
+# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 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
from ganeti import constants
from ganeti import errors
from ganeti import ht
+from ganeti import objects
# Common opcode attributes
"Legacy setting for live migration, do not use")
#: Tag type
-_PTagKind = ("kind", ht.NoDefault, ht.TElemOf(constants.VALID_TAG_TYPES), None)
+_PTagKind = ("kind", ht.NoDefault, ht.TElemOf(constants.VALID_TAG_TYPES),
+ "Tag kind")
#: List of tag strings
-_PTags = ("tags", ht.NoDefault, ht.TListOf(ht.TNonEmptyString), None)
+_PTags = ("tags", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
+ "List of tag names")
_PForceVariant = ("force_variant", False, ht.TBool,
"Whether to force an unknown OS variant")
ht.TItems([ht.TElemOf(constants.RS_ALL),
ht.TAny])))
+_TQueryResult = ht.TListOf(_TQueryRow)
+
+_TOldQueryRow = ht.TListOf(ht.TAny)
+
+_TOldQueryResult = ht.TListOf(_TOldQueryRow)
+
+
_SUMMARY_PREFIX = {
"CLUSTER_": "C_",
"GROUP_": "G_",
return "_".join(n.upper() for n in elems)
+def _GenerateObjectTypeCheck(obj, fields_types):
+ """Helper to generate type checks for objects.
+
+ @param obj: The object to generate type checks
+ @param fields_types: The fields and their types as a dict
+ @return: A ht type check function
+
+ """
+ assert set(obj.GetAllSlots()) == set(fields_types.keys()), \
+ "%s != %s" % (set(obj.GetAllSlots()), set(fields_types.keys()))
+ return ht.TStrictDict(True, True, fields_types)
+
+
+_TQueryFieldDef = \
+ _GenerateObjectTypeCheck(objects.QueryFieldDefinition, {
+ "name": ht.TNonEmptyString,
+ "title": ht.TNonEmptyString,
+ "kind": ht.TElemOf(constants.QFT_ALL),
+ "doc": ht.TNonEmptyString,
+ })
+
+
def RequireFileStorage():
"""Checks that file storage is enabled.
class OpClusterQuery(OpCode):
"""Query cluster information."""
+ OP_RESULT = ht.TDictOf(ht.TNonEmptyString, ht.TAny)
class OpClusterVerify(OpCode):
_PUseLocking,
("fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
"Requested fields"),
- ("qfilter", None, ht.TOr(ht.TNone, ht.TListOf),
+ ("qfilter", None, ht.TOr(ht.TNone, ht.TList),
"Query filter"),
]
+ OP_RESULT = \
+ _GenerateObjectTypeCheck(objects.QueryResponse, {
+ "fields": ht.TListOf(_TQueryFieldDef),
+ "data": _TQueryResult,
+ })
class OpQueryFields(OpCode):
("fields", None, ht.TMaybeListOf(ht.TNonEmptyString),
"Requested fields; if not given, all are returned"),
]
+ OP_RESULT = \
+ _GenerateObjectTypeCheck(objects.QueryFieldsResponse, {
+ "fields": ht.TListOf(_TQueryFieldDef),
+ })
class OpOobCommand(OpCode):
"Time in seconds to wait between powering on nodes"),
]
# Fixme: Make it more specific with all the special cases in LUOobCommand
- OP_RESULT = ht.TListOf(_TQueryRow)
+ OP_RESULT = _TQueryResult
# node opcodes
("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
"Empty list to query all nodes, node names otherwise"),
]
+ OP_RESULT = _TOldQueryResult
class OpNodeQueryvols(OpCode):
("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "List of nodes"),
("name", None, ht.TMaybeString, "Storage name"),
]
+ OP_RESULT = _TOldQueryResult
class OpNodeModifyStorage(OpCode):
("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
"Empty list to query all instances, instance names otherwise"),
]
+ OP_RESULT = _TOldQueryResult
class OpInstanceQueryData(OpCode):
"Whether to only return configuration data without querying"
" nodes"),
]
+ OP_RESULT = ht.TDictOf(ht.TNonEmptyString, ht.TDict)
def _TestInstSetParamsModList(fn):
_PInstanceName,
_PWaitForSync,
("disk", ht.NoDefault, ht.TInt, "Disk index"),
- ("amount", ht.NoDefault, ht.TInt,
+ ("amount", ht.NoDefault, ht.TPositiveInt,
"Amount of disk space to add (megabytes)"),
+ ("absolute", False, ht.TBool,
+ "Whether the amount parameter is an absolute target or a relative one"),
]
OP_RESULT = ht.TNone
("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
"Empty list to query all groups, group names otherwise"),
]
+ OP_RESULT = _TOldQueryResult
class OpGroupSetParams(OpCode):
("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
"Which operating systems to diagnose"),
]
+ OP_RESULT = _TOldQueryResult
# Exports opcodes
OP_DSC_FIELD = "name"
OP_PARAMS = [
_PTagKind,
+ # Not using _PUseLocking as the default is different for historical reasons
+ ("use_locking", True, ht.TBool, "Whether to use synchronization"),
# Name is only meaningful for nodes and instances
- ("name", ht.NoDefault, ht.TMaybeString, None),
+ ("name", ht.NoDefault, ht.TMaybeString,
+ "Name of object to retrieve tags from"),
]
+ OP_RESULT = ht.TListOf(ht.TNonEmptyString)
class OpTagsSearch(OpCode):
"""Searches the tags in the cluster for a given pattern."""
OP_DSC_FIELD = "pattern"
OP_PARAMS = [
- ("pattern", ht.NoDefault, ht.TNonEmptyString, None),
+ ("pattern", ht.NoDefault, ht.TNonEmptyString,
+ "Search pattern (regular expression)"),
]
+ OP_RESULT = ht.TListOf(ht.TAnd(ht.TIsLength(2), ht.TItems([
+ ht.TNonEmptyString,
+ ht.TNonEmptyString,
+ ])))
class OpTagsSet(OpCode):
_PTagKind,
_PTags,
# Name is only meaningful for nodes and instances
- ("name", ht.NoDefault, ht.TMaybeString, None),
+ ("name", ht.NoDefault, ht.TMaybeString,
+ "Name of object where tag(s) should be added"),
]
+ OP_RESULT = ht.TNone
class OpTagsDel(OpCode):
_PTagKind,
_PTags,
# Name is only meaningful for nodes and instances
- ("name", ht.NoDefault, ht.TMaybeString, None),
+ ("name", ht.NoDefault, ht.TMaybeString,
+ "Name of object where tag(s) should be deleted"),
]
+ OP_RESULT = ht.TNone
# Test opcodes