Revision 415feb2e lib/opcodes.py
b/lib/opcodes.py | ||
---|---|---|
39 | 39 |
from ganeti import constants |
40 | 40 |
from ganeti import errors |
41 | 41 |
from ganeti import ht |
42 |
from ganeti import objects |
|
43 |
from ganeti import query |
|
42 | 44 |
|
43 | 45 |
|
44 | 46 |
# Common opcode attributes |
... | ... | |
198 | 200 |
ht.TItems([ht.TElemOf(constants.RS_ALL), |
199 | 201 |
ht.TAny]))) |
200 | 202 |
|
203 |
_TQueryResult = ht.TListOf(_TQueryRow) |
|
204 |
|
|
205 |
_TOldQueryRow = ht.TListOf(ht.TAny) |
|
206 |
|
|
207 |
_TOldQueryResult = ht.TListOf(_TOldQueryRow) |
|
208 |
|
|
209 |
|
|
201 | 210 |
_SUMMARY_PREFIX = { |
202 | 211 |
"CLUSTER_": "C_", |
203 | 212 |
"GROUP_": "G_", |
... | ... | |
233 | 242 |
return "_".join(n.upper() for n in elems) |
234 | 243 |
|
235 | 244 |
|
245 |
def _GenerateObjectTypeCheck(obj, fields_types): |
|
246 |
"""Helper to generate type checks for objects. |
|
247 |
|
|
248 |
@param obj: The object to generate type checks |
|
249 |
@param fields_types: The fields and their types as a dict |
|
250 |
@return: A ht type check function |
|
251 |
|
|
252 |
""" |
|
253 |
assert set(obj.GetAllSlots()) == set(fields_types.keys()), \ |
|
254 |
"%s != %s" % (set(obj.GetAllSlots()), set(fields_types.keys())) |
|
255 |
return ht.TStrictDict(True, True, fields_types) |
|
256 |
|
|
257 |
|
|
258 |
_TObjFdefs = \ |
|
259 |
_GenerateObjectTypeCheck(objects.QueryFieldDefinition, { |
|
260 |
"name": ht.TRegex(query.FIELD_NAME_RE), |
|
261 |
"title": ht.TRegex(query.TITLE_RE), |
|
262 |
"kind": ht.TElemOf(constants.QFT_ALL), |
|
263 |
"doc": ht.TRegex(query.DOC_RE), |
|
264 |
}) |
|
265 |
|
|
266 |
|
|
236 | 267 |
def RequireFileStorage(): |
237 | 268 |
"""Checks that file storage is enabled. |
238 | 269 |
|
... | ... | |
642 | 673 |
|
643 | 674 |
class OpClusterQuery(OpCode): |
644 | 675 |
"""Query cluster information.""" |
676 |
OP_RESULT = ht.TDictOf(ht.TNonEmptyString, ht.TAny) |
|
645 | 677 |
|
646 | 678 |
|
647 | 679 |
class OpClusterVerify(OpCode): |
... | ... | |
887 | 919 |
("qfilter", None, ht.TOr(ht.TNone, ht.TListOf), |
888 | 920 |
"Query filter"), |
889 | 921 |
] |
922 |
OP_RESULT = \ |
|
923 |
_GenerateObjectTypeCheck(objects.QueryResponse, { |
|
924 |
"fields": ht.TListOf(_TObjFdefs), |
|
925 |
"data": _TQueryResult, |
|
926 |
}) |
|
890 | 927 |
|
891 | 928 |
|
892 | 929 |
class OpQueryFields(OpCode): |
... | ... | |
902 | 939 |
("fields", None, ht.TMaybeListOf(ht.TNonEmptyString), |
903 | 940 |
"Requested fields; if not given, all are returned"), |
904 | 941 |
] |
942 |
OP_RESULT = \ |
|
943 |
_GenerateObjectTypeCheck(objects.QueryFieldsResponse, { |
|
944 |
"fields": ht.TListOf(_TObjFdefs), |
|
945 |
}) |
|
905 | 946 |
|
906 | 947 |
|
907 | 948 |
class OpOobCommand(OpCode): |
... | ... | |
919 | 960 |
"Time in seconds to wait between powering on nodes"), |
920 | 961 |
] |
921 | 962 |
# Fixme: Make it more specific with all the special cases in LUOobCommand |
922 |
OP_RESULT = ht.TListOf(_TQueryRow)
|
|
963 |
OP_RESULT = _TQueryResult
|
|
923 | 964 |
|
924 | 965 |
|
925 | 966 |
# node opcodes |
... | ... | |
993 | 1034 |
("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), |
994 | 1035 |
"Empty list to query all nodes, node names otherwise"), |
995 | 1036 |
] |
1037 |
OP_RESULT = _TOldQueryResult |
|
996 | 1038 |
|
997 | 1039 |
|
998 | 1040 |
class OpNodeQueryvols(OpCode): |
... | ... | |
1013 | 1055 |
("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "List of nodes"), |
1014 | 1056 |
("name", None, ht.TMaybeString, "Storage name"), |
1015 | 1057 |
] |
1058 |
OP_RESULT = _TOldQueryResult |
|
1016 | 1059 |
|
1017 | 1060 |
|
1018 | 1061 |
class OpNodeModifyStorage(OpCode): |
... | ... | |
1402 | 1445 |
("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), |
1403 | 1446 |
"Empty list to query all instances, instance names otherwise"), |
1404 | 1447 |
] |
1448 |
OP_RESULT = _TOldQueryResult |
|
1405 | 1449 |
|
1406 | 1450 |
|
1407 | 1451 |
class OpInstanceQueryData(OpCode): |
... | ... | |
1414 | 1458 |
"Whether to only return configuration data without querying" |
1415 | 1459 |
" nodes"), |
1416 | 1460 |
] |
1461 |
OP_RESULT = ht.TDictOf(ht.TNonEmptyString, ht.TDict) |
|
1417 | 1462 |
|
1418 | 1463 |
|
1419 | 1464 |
def _TestInstSetParamsModList(fn): |
... | ... | |
1546 | 1591 |
("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), |
1547 | 1592 |
"Empty list to query all groups, group names otherwise"), |
1548 | 1593 |
] |
1594 |
OP_RESULT = _TOldQueryResult |
|
1549 | 1595 |
|
1550 | 1596 |
|
1551 | 1597 |
class OpGroupSetParams(OpCode): |
... | ... | |
1602 | 1648 |
("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), |
1603 | 1649 |
"Which operating systems to diagnose"), |
1604 | 1650 |
] |
1651 |
OP_RESULT = _TOldQueryResult |
|
1605 | 1652 |
|
1606 | 1653 |
|
1607 | 1654 |
# Exports opcodes |
Also available in: Unified diff