from ganeti import constants
from ganeti import errors
from ganeti import ht
+from ganeti import objects
+from ganeti import query
# Common opcode attributes
ht.Comment("Disk parameters")(ht.TDictOf(ht.TElemOf(constants.IDISK_PARAMS),
ht.TOr(ht.TNonEmptyString, ht.TInt)))
+_TQueryRow = \
+ ht.TListOf(ht.TAnd(ht.TIsLength(2),
+ 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)
+
+
+_TObjFdefs = \
+ _GenerateObjectTypeCheck(objects.QueryFieldDefinition, {
+ "name": ht.TRegex(query.FIELD_NAME_RE),
+ "title": ht.TRegex(query.TITLE_RE),
+ "kind": ht.TElemOf(constants.QFT_ALL),
+ "doc": ht.TRegex(query.DOC_RE),
+ })
+
+
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):
("qfilter", None, ht.TOr(ht.TNone, ht.TListOf),
"Query filter"),
]
+ OP_RESULT = \
+ _GenerateObjectTypeCheck(objects.QueryResponse, {
+ "fields": ht.TListOf(_TObjFdefs),
+ "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(_TObjFdefs),
+ })
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(ht.TAnd(ht.TIsLength(2),
- ht.TItems([ht.TElemOf(constants.RS_ALL),
- ht.TAny])))
+ 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):
("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
("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
"Empty list to query all nodes, node names otherwise"),
]
+ OP_RESULT = ht.TDictOf(ht.TNonEmptyString,
+ ht.TOr(ht.Comment("False on error")(ht.TBool),
+ ht.TListOf(ht.TNonEmptyString)))
class OpBackupPrepare(OpCode):
("destination_x509_ca", None, ht.TMaybeString,
"Destination X509 CA (remote export only)"),
]
+ OP_RESULT = \
+ ht.TAnd(ht.TIsLength(2), ht.TItems([
+ ht.Comment("Finalizing status")(ht.TBool),
+ ht.Comment("Status for every exported disk")(ht.TListOf(ht.TBool)),
+ ]))
class OpBackupRemove(OpCode):
OP_PARAMS = [
_PInstanceName,
]
+ OP_RESULT = ht.TNone
# Tags opcodes