Revision 79b2ca83 lib/query.py
b/lib/query.py | ||
---|---|---|
32 | 32 |
- Title for tables, must not contain whitespace and match |
33 | 33 |
L{TITLE_RE} |
34 | 34 |
- Value data type, e.g. L{constants.QFT_NUMBER} |
35 |
- Human-readable description, must not end with punctuation or |
|
36 |
contain newlines |
|
35 | 37 |
- Data request type, see e.g. C{NQ_*} |
36 | 38 |
- A retrieval function, see L{Query.__init__} for description |
37 | 39 |
- Pass list of fields through L{_PrepareFieldList} for preparation and |
... | ... | |
122 | 124 |
constants.VTYPE_INT: QFT_NUMBER, |
123 | 125 |
} |
124 | 126 |
|
127 |
_SERIAL_NO_DOC = "%s object serial number, incremented on each modification" |
|
128 |
|
|
125 | 129 |
|
126 | 130 |
def _GetUnknownField(ctx, item): # pylint: disable-msg=W0613 |
127 | 131 |
"""Gets the contents of an unknown field. |
... | ... | |
147 | 151 |
try: |
148 | 152 |
fdef = fielddefs[name] |
149 | 153 |
except KeyError: |
150 |
fdef = (_MakeField(name, name, QFT_UNKNOWN), None, _GetUnknownField) |
|
154 |
fdef = (_MakeField(name, name, QFT_UNKNOWN, "Unknown field '%s'" % name), |
|
155 |
None, _GetUnknownField) |
|
151 | 156 |
|
152 | 157 |
assert len(fdef) == 3 |
153 | 158 |
|
... | ... | |
308 | 313 |
assert fdef.name and fdef.title, "Name and title are required" |
309 | 314 |
assert FIELD_NAME_RE.match(fdef.name) |
310 | 315 |
assert TITLE_RE.match(fdef.title) |
311 |
assert (fdef.doc is None or
|
|
312 |
(DOC_RE.match(fdef.doc) and len(fdef.doc.splitlines()) == 1 and
|
|
313 |
fdef.doc.strip() == fdef.doc))
|
|
316 |
assert (DOC_RE.match(fdef.doc) and len(fdef.doc.splitlines()) == 1 and
|
|
317 |
fdef.doc.strip() == fdef.doc), \
|
|
318 |
"Invalid description for field '%s'" % fdef.name
|
|
314 | 319 |
assert callable(fn) |
315 | 320 |
assert fdef.name not in result, \ |
316 | 321 |
"Duplicate field name '%s' found" % fdef.name |
... | ... | |
364 | 369 |
return objects.QueryFieldsResponse(fields=fdefs).ToDict() |
365 | 370 |
|
366 | 371 |
|
367 |
def _MakeField(name, title, kind, doc=None):
|
|
372 |
def _MakeField(name, title, kind, doc): |
|
368 | 373 |
"""Wrapper for creating L{objects.QueryFieldDefinition} instances. |
369 | 374 |
|
370 | 375 |
@param name: Field name as a regular expression |
... | ... | |
436 | 441 |
|
437 | 442 |
""" |
438 | 443 |
return [ |
439 |
(_MakeField("ctime", "CTime", QFT_TIMESTAMP), datatype,
|
|
440 |
_GetItemTimestamp(operator.attrgetter("ctime"))), |
|
441 |
(_MakeField("mtime", "MTime", QFT_TIMESTAMP), datatype,
|
|
442 |
_GetItemTimestamp(operator.attrgetter("mtime"))), |
|
444 |
(_MakeField("ctime", "CTime", QFT_TIMESTAMP, "Creation timestamp"),
|
|
445 |
datatype, _GetItemTimestamp(operator.attrgetter("ctime"))),
|
|
446 |
(_MakeField("mtime", "MTime", QFT_TIMESTAMP, "Modification timestamp"),
|
|
447 |
datatype, _GetItemTimestamp(operator.attrgetter("mtime"))),
|
|
443 | 448 |
] |
444 | 449 |
|
445 | 450 |
|
... | ... | |
481 | 486 |
|
482 | 487 |
#: Fields that are direct attributes of an L{objects.Node} object |
483 | 488 |
_NODE_SIMPLE_FIELDS = { |
484 |
"drained": ("Drained", QFT_BOOL), |
|
485 |
"master_candidate": ("MasterC", QFT_BOOL), |
|
486 |
"master_capable": ("MasterCapable", QFT_BOOL), |
|
487 |
"name": ("Node", QFT_TEXT), |
|
488 |
"offline": ("Offline", QFT_BOOL), |
|
489 |
"serial_no": ("SerialNo", QFT_NUMBER), |
|
490 |
"uuid": ("UUID", QFT_TEXT), |
|
491 |
"vm_capable": ("VMCapable", QFT_BOOL), |
|
489 |
"drained": ("Drained", QFT_BOOL, "Whether node is drained"), |
|
490 |
"master_candidate": ("MasterC", QFT_BOOL, |
|
491 |
"Whether node is a master candidate"), |
|
492 |
"master_capable": ("MasterCapable", QFT_BOOL, |
|
493 |
"Whether node can become a master candidate"), |
|
494 |
"name": ("Node", QFT_TEXT, "Node name"), |
|
495 |
"offline": ("Offline", QFT_BOOL, "Whether node is marked offline"), |
|
496 |
"serial_no": ("SerialNo", QFT_NUMBER, _SERIAL_NO_DOC % "Node"), |
|
497 |
"uuid": ("UUID", QFT_TEXT, "Node UUID"), |
|
498 |
"vm_capable": ("VMCapable", QFT_BOOL, "Whether node can host instances"), |
|
492 | 499 |
} |
493 | 500 |
|
494 | 501 |
|
495 | 502 |
#: Fields requiring talking to the node |
496 | 503 |
# Note that none of these are available for non-vm_capable nodes |
497 | 504 |
_NODE_LIVE_FIELDS = { |
498 |
"bootid": ("BootID", QFT_TEXT, "bootid"), |
|
499 |
"cnodes": ("CNodes", QFT_NUMBER, "cpu_nodes"), |
|
500 |
"csockets": ("CSockets", QFT_NUMBER, "cpu_sockets"), |
|
501 |
"ctotal": ("CTotal", QFT_NUMBER, "cpu_total"), |
|
502 |
"dfree": ("DFree", QFT_UNIT, "vg_free"), |
|
503 |
"dtotal": ("DTotal", QFT_UNIT, "vg_size"), |
|
504 |
"mfree": ("MFree", QFT_UNIT, "memory_free"), |
|
505 |
"mnode": ("MNode", QFT_UNIT, "memory_dom0"), |
|
506 |
"mtotal": ("MTotal", QFT_UNIT, "memory_total"), |
|
505 |
"bootid": ("BootID", QFT_TEXT, "bootid", |
|
506 |
"Random UUID renewed for each system reboot, can be used" |
|
507 |
" for detecting reboots by tracking changes"), |
|
508 |
"cnodes": ("CNodes", QFT_NUMBER, "cpu_nodes", |
|
509 |
"Number of NUMA domains on node (if exported by hypervisor)"), |
|
510 |
"csockets": ("CSockets", QFT_NUMBER, "cpu_sockets", |
|
511 |
"Number of physical CPU sockets (if exported by hypervisor)"), |
|
512 |
"ctotal": ("CTotal", QFT_NUMBER, "cpu_total", "Number of logical processors"), |
|
513 |
"dfree": ("DFree", QFT_UNIT, "vg_free", |
|
514 |
"Available disk space in volume group"), |
|
515 |
"dtotal": ("DTotal", QFT_UNIT, "vg_size", |
|
516 |
"Total disk space in volume group used for instance disk" |
|
517 |
" allocation"), |
|
518 |
"mfree": ("MFree", QFT_UNIT, "memory_free", |
|
519 |
"Memory available for instance allocations"), |
|
520 |
"mnode": ("MNode", QFT_UNIT, "memory_dom0", |
|
521 |
"Amount of memory used by node (dom0 for Xen)"), |
|
522 |
"mtotal": ("MTotal", QFT_UNIT, "memory_total", |
|
523 |
"Total amount of memory of physical machine"), |
|
507 | 524 |
} |
508 | 525 |
|
509 | 526 |
|
... | ... | |
614 | 631 |
|
615 | 632 |
""" |
616 | 633 |
fields = [ |
617 |
(_MakeField("pip", "PrimaryIP", QFT_TEXT), NQ_CONFIG,
|
|
618 |
_GetItemAttr("primary_ip")), |
|
619 |
(_MakeField("sip", "SecondaryIP", QFT_TEXT), NQ_CONFIG,
|
|
620 |
_GetItemAttr("secondary_ip")), |
|
621 |
(_MakeField("tags", "Tags", QFT_OTHER), NQ_CONFIG, |
|
634 |
(_MakeField("pip", "PrimaryIP", QFT_TEXT, "Primary IP address"),
|
|
635 |
NQ_CONFIG, _GetItemAttr("primary_ip")),
|
|
636 |
(_MakeField("sip", "SecondaryIP", QFT_TEXT, "Secondary IP address"),
|
|
637 |
NQ_CONFIG, _GetItemAttr("secondary_ip")),
|
|
638 |
(_MakeField("tags", "Tags", QFT_OTHER, "Tags"), NQ_CONFIG,
|
|
622 | 639 |
lambda ctx, node: list(node.GetTags())), |
623 |
(_MakeField("master", "IsMaster", QFT_BOOL), NQ_CONFIG, |
|
624 |
lambda ctx, node: node.name == ctx.master_name), |
|
625 |
(_MakeField("role", "Role", QFT_TEXT), NQ_CONFIG, |
|
626 |
lambda ctx, node: _GetNodeRole(node, ctx.master_name)), |
|
627 |
(_MakeField("group", "Group", QFT_TEXT), NQ_GROUP, |
|
640 |
(_MakeField("master", "IsMaster", QFT_BOOL, "Whether node is master"), |
|
641 |
NQ_CONFIG, lambda ctx, node: node.name == ctx.master_name), |
|
642 |
(_MakeField("group", "Group", QFT_TEXT, "Node group"), NQ_GROUP, |
|
628 | 643 |
_GetGroup(_GetNodeGroup)), |
629 |
(_MakeField("group.uuid", "GroupUUID", QFT_TEXT), |
|
644 |
(_MakeField("group.uuid", "GroupUUID", QFT_TEXT, "UUID of node group"),
|
|
630 | 645 |
NQ_CONFIG, _GetItemAttr("group")), |
631 |
(_MakeField("powered", "Powered", QFT_BOOL), NQ_OOB, _GetNodePower), |
|
632 |
(_MakeField("ndparams", "NodeParameters", QFT_OTHER), NQ_GROUP, |
|
633 |
_GetGroup(_GetNdParams)), |
|
634 |
(_MakeField("custom_ndparams", "CustomNodeParameters", QFT_OTHER), |
|
646 |
(_MakeField("powered", "Powered", QFT_BOOL, |
|
647 |
"Whether node is thought to be powered on"), |
|
648 |
NQ_OOB, _GetNodePower), |
|
649 |
(_MakeField("ndparams", "NodeParameters", QFT_OTHER, |
|
650 |
"Merged node parameters"), |
|
651 |
NQ_GROUP, _GetGroup(_GetNdParams)), |
|
652 |
(_MakeField("custom_ndparams", "CustomNodeParameters", QFT_OTHER, |
|
653 |
"Custom node parameters"), |
|
635 | 654 |
NQ_GROUP, _GetItemAttr("ndparams")), |
636 | 655 |
] |
637 | 656 |
|
657 |
# Node role |
|
658 |
role_values = (constants.NR_MASTER, constants.NR_MCANDIDATE, |
|
659 |
constants.NR_REGULAR, constants.NR_DRAINED, |
|
660 |
constants.NR_OFFLINE) |
|
661 |
role_doc = ("Node role; \"%s\" for master, \"%s\" for master candidate," |
|
662 |
" \"%s\" for regular, \"%s\" for a drained, \"%s\" for offline" % |
|
663 |
role_values) |
|
664 |
fields.append((_MakeField("role", "Role", QFT_TEXT, role_doc), NQ_CONFIG, |
|
665 |
lambda ctx, node: _GetNodeRole(node, ctx.master_name))) |
|
666 |
assert set(role_values) == constants.NR_ALL |
|
667 |
|
|
638 | 668 |
def _GetLength(getter): |
639 | 669 |
return lambda ctx, node: len(getter(ctx)[node.name]) |
640 | 670 |
|
... | ... | |
642 | 672 |
return lambda ctx, node: list(getter(ctx)[node.name]) |
643 | 673 |
|
644 | 674 |
# Add fields operating on instance lists |
645 |
for prefix, titleprefix, getter in \ |
|
646 |
[("p", "Pri", operator.attrgetter("node_to_primary")), |
|
647 |
("s", "Sec", operator.attrgetter("node_to_secondary"))]: |
|
675 |
for prefix, titleprefix, docword, getter in \
|
|
676 |
[("p", "Pri", "primary", operator.attrgetter("node_to_primary")),
|
|
677 |
("s", "Sec", "secondary", operator.attrgetter("node_to_secondary"))]:
|
|
648 | 678 |
fields.extend([ |
649 |
(_MakeField("%sinst_cnt" % prefix, "%sinst" % prefix.upper(), QFT_NUMBER), |
|
679 |
(_MakeField("%sinst_cnt" % prefix, "%sinst" % prefix.upper(), QFT_NUMBER, |
|
680 |
"Number of instances with this node as %s" % docword), |
|
650 | 681 |
NQ_INST, _GetLength(getter)), |
651 | 682 |
(_MakeField("%sinst_list" % prefix, "%sInstances" % titleprefix, |
652 |
QFT_OTHER), |
|
683 |
QFT_OTHER, |
|
684 |
"List of instances with this node as %s" % docword), |
|
653 | 685 |
NQ_INST, _GetList(getter)), |
654 | 686 |
]) |
655 | 687 |
|
656 | 688 |
# Add simple fields |
657 |
fields.extend([(_MakeField(name, title, kind), NQ_CONFIG, _GetItemAttr(name)) |
|
658 |
for (name, (title, kind)) in _NODE_SIMPLE_FIELDS.items()]) |
|
689 |
fields.extend([(_MakeField(name, title, kind, doc), NQ_CONFIG, |
|
690 |
_GetItemAttr(name)) |
|
691 |
for (name, (title, kind, doc)) in _NODE_SIMPLE_FIELDS.items()]) |
|
659 | 692 |
|
660 | 693 |
# Add fields requiring live data |
661 | 694 |
fields.extend([ |
662 |
(_MakeField(name, title, kind), NQ_LIVE, |
|
695 |
(_MakeField(name, title, kind, doc), NQ_LIVE,
|
|
663 | 696 |
compat.partial(_GetLiveNodeField, nfield, kind)) |
664 |
for (name, (title, kind, nfield)) in _NODE_LIVE_FIELDS.items() |
|
697 |
for (name, (title, kind, nfield, doc)) in _NODE_LIVE_FIELDS.items()
|
|
665 | 698 |
]) |
666 | 699 |
|
667 | 700 |
# Add timestamps |
... | ... | |
944 | 977 |
|
945 | 978 |
fields = [ |
946 | 979 |
# All NICs |
947 |
(_MakeField("nic.count", "NICs", QFT_NUMBER), IQ_CONFIG, |
|
948 |
lambda ctx, inst: len(inst.nics)), |
|
949 |
(_MakeField("nic.macs", "NIC_MACs", QFT_OTHER), IQ_CONFIG, |
|
950 |
lambda ctx, inst: [nic.mac for nic in inst.nics]), |
|
951 |
(_MakeField("nic.ips", "NIC_IPs", QFT_OTHER), IQ_CONFIG, |
|
952 |
lambda ctx, inst: [nic.ip for nic in inst.nics]), |
|
953 |
(_MakeField("nic.modes", "NIC_modes", QFT_OTHER), IQ_CONFIG, |
|
980 |
(_MakeField("nic.count", "NICs", QFT_NUMBER, |
|
981 |
"Number of network interfaces"), |
|
982 |
IQ_CONFIG, lambda ctx, inst: len(inst.nics)), |
|
983 |
(_MakeField("nic.macs", "NIC_MACs", QFT_OTHER, |
|
984 |
"List containing each network interface's MAC address"), |
|
985 |
IQ_CONFIG, lambda ctx, inst: [nic.mac for nic in inst.nics]), |
|
986 |
(_MakeField("nic.ips", "NIC_IPs", QFT_OTHER, |
|
987 |
"List containing each network interface's IP address"), |
|
988 |
IQ_CONFIG, lambda ctx, inst: [nic.ip for nic in inst.nics]), |
|
989 |
(_MakeField("nic.modes", "NIC_modes", QFT_OTHER, |
|
990 |
"List containing each network interface's mode"), IQ_CONFIG, |
|
954 | 991 |
lambda ctx, inst: [nicp[constants.NIC_MODE] |
955 | 992 |
for nicp in ctx.inst_nicparams]), |
956 |
(_MakeField("nic.links", "NIC_links", QFT_OTHER), IQ_CONFIG, |
|
993 |
(_MakeField("nic.links", "NIC_links", QFT_OTHER, |
|
994 |
"List containing each network interface's link"), IQ_CONFIG, |
|
957 | 995 |
lambda ctx, inst: [nicp[constants.NIC_LINK] |
958 | 996 |
for nicp in ctx.inst_nicparams]), |
959 |
(_MakeField("nic.bridges", "NIC_bridges", QFT_OTHER), IQ_CONFIG, |
|
997 |
(_MakeField("nic.bridges", "NIC_bridges", QFT_OTHER, |
|
998 |
"List containing each network interface's bridge"), IQ_CONFIG, |
|
960 | 999 |
_GetInstAllNicBridges), |
961 | 1000 |
] |
962 | 1001 |
|
963 | 1002 |
# NICs by number |
964 | 1003 |
for i in range(constants.MAX_NICS): |
1004 |
numtext = utils.FormatOrdinal(i + 1) |
|
965 | 1005 |
fields.extend([ |
966 |
(_MakeField("nic.ip/%s" % i, "NicIP/%s" % i, QFT_TEXT), |
|
1006 |
(_MakeField("nic.ip/%s" % i, "NicIP/%s" % i, QFT_TEXT, |
|
1007 |
"IP address of %s network interface" % numtext), |
|
967 | 1008 |
IQ_CONFIG, _GetInstNic(i, _GetInstNicIp)), |
968 |
(_MakeField("nic.mac/%s" % i, "NicMAC/%s" % i, QFT_TEXT), |
|
1009 |
(_MakeField("nic.mac/%s" % i, "NicMAC/%s" % i, QFT_TEXT, |
|
1010 |
"MAC address of %s network interface" % numtext), |
|
969 | 1011 |
IQ_CONFIG, _GetInstNic(i, nic_mac_fn)), |
970 |
(_MakeField("nic.mode/%s" % i, "NicMode/%s" % i, QFT_TEXT), |
|
1012 |
(_MakeField("nic.mode/%s" % i, "NicMode/%s" % i, QFT_TEXT, |
|
1013 |
"Mode of %s network interface" % numtext), |
|
971 | 1014 |
IQ_CONFIG, _GetInstNic(i, nic_mode_fn)), |
972 |
(_MakeField("nic.link/%s" % i, "NicLink/%s" % i, QFT_TEXT), |
|
1015 |
(_MakeField("nic.link/%s" % i, "NicLink/%s" % i, QFT_TEXT, |
|
1016 |
"Link of %s network interface" % numtext), |
|
973 | 1017 |
IQ_CONFIG, _GetInstNic(i, nic_link_fn)), |
974 |
(_MakeField("nic.bridge/%s" % i, "NicBridge/%s" % i, QFT_TEXT), |
|
1018 |
(_MakeField("nic.bridge/%s" % i, "NicBridge/%s" % i, QFT_TEXT, |
|
1019 |
"Bridge of %s network interface" % numtext), |
|
975 | 1020 |
IQ_CONFIG, _GetInstNic(i, _GetInstNicBridge)), |
976 | 1021 |
]) |
977 | 1022 |
|
... | ... | |
1026 | 1071 |
|
1027 | 1072 |
""" |
1028 | 1073 |
fields = [ |
1029 |
(_MakeField("disk_usage", "DiskUsage", QFT_UNIT), IQ_DISKUSAGE, |
|
1030 |
_GetInstDiskUsage), |
|
1031 |
(_MakeField("disk.count", "Disks", QFT_NUMBER), IQ_CONFIG, |
|
1032 |
lambda ctx, inst: len(inst.disks)), |
|
1033 |
(_MakeField("disk.sizes", "Disk_sizes", QFT_OTHER), IQ_CONFIG, |
|
1034 |
lambda ctx, inst: [disk.size for disk in inst.disks]), |
|
1074 |
(_MakeField("disk_usage", "DiskUsage", QFT_UNIT, |
|
1075 |
"Total disk space used by instance on each of its nodes;" |
|
1076 |
" this is not the disk size visible to the instance, but" |
|
1077 |
" the usage on the node"), |
|
1078 |
IQ_DISKUSAGE, _GetInstDiskUsage), |
|
1079 |
(_MakeField("disk.count", "Disks", QFT_NUMBER, "Number of disks"), |
|
1080 |
IQ_CONFIG, lambda ctx, inst: len(inst.disks)), |
|
1081 |
(_MakeField("disk.sizes", "Disk_sizes", QFT_OTHER, "List of disk sizes"), |
|
1082 |
IQ_CONFIG, lambda ctx, inst: [disk.size for disk in inst.disks]), |
|
1035 | 1083 |
] |
1036 | 1084 |
|
1037 | 1085 |
# Disks by number |
1038 | 1086 |
fields.extend([ |
1039 |
(_MakeField("disk.size/%s" % i, "Disk/%s" % i, QFT_UNIT), |
|
1087 |
(_MakeField("disk.size/%s" % i, "Disk/%s" % i, QFT_UNIT, |
|
1088 |
"Disk size of %s disk" % utils.FormatOrdinal(i + 1)), |
|
1040 | 1089 |
IQ_CONFIG, _GetInstDiskSize(i)) |
1041 | 1090 |
for i in range(constants.MAX_DISKS) |
1042 | 1091 |
]) |
... | ... | |
1071 | 1120 |
|
1072 | 1121 |
fields = [ |
1073 | 1122 |
# Filled parameters |
1074 |
(_MakeField("hvparams", "HypervisorParameters", QFT_OTHER), |
|
1123 |
(_MakeField("hvparams", "HypervisorParameters", QFT_OTHER, |
|
1124 |
"Hypervisor parameters"), |
|
1075 | 1125 |
IQ_CONFIG, lambda ctx, _: ctx.inst_hvparams), |
1076 |
(_MakeField("beparams", "BackendParameters", QFT_OTHER), |
|
1126 |
(_MakeField("beparams", "BackendParameters", QFT_OTHER, |
|
1127 |
"Backend parameters"), |
|
1077 | 1128 |
IQ_CONFIG, lambda ctx, _: ctx.inst_beparams), |
1078 | 1129 |
|
1079 | 1130 |
# Unfilled parameters |
1080 |
(_MakeField("custom_hvparams", "CustomHypervisorParameters", QFT_OTHER), |
|
1131 |
(_MakeField("custom_hvparams", "CustomHypervisorParameters", QFT_OTHER, |
|
1132 |
"Custom hypervisor parameters"), |
|
1081 | 1133 |
IQ_CONFIG, _GetItemAttr("hvparams")), |
1082 |
(_MakeField("custom_beparams", "CustomBackendParameters", QFT_OTHER), |
|
1134 |
(_MakeField("custom_beparams", "CustomBackendParameters", QFT_OTHER, |
|
1135 |
"Custom backend parameters",), |
|
1083 | 1136 |
IQ_CONFIG, _GetItemAttr("beparams")), |
1084 |
(_MakeField("custom_nicparams", "CustomNicParameters", QFT_OTHER), |
|
1137 |
(_MakeField("custom_nicparams", "CustomNicParameters", QFT_OTHER, |
|
1138 |
"Custom network interface parameters"), |
|
1085 | 1139 |
IQ_CONFIG, lambda ctx, inst: [nic.nicparams for nic in inst.nics]), |
1086 | 1140 |
] |
1087 | 1141 |
|
... | ... | |
1091 | 1145 |
|
1092 | 1146 |
fields.extend([ |
1093 | 1147 |
(_MakeField("hv/%s" % name, hv_title.get(name, "hv/%s" % name), |
1094 |
_VTToQFT[kind]), |
|
1148 |
_VTToQFT[kind], "The \"%s\" hypervisor parameter" % name),
|
|
1095 | 1149 |
IQ_CONFIG, _GetInstHvParam(name)) |
1096 | 1150 |
for name, kind in constants.HVS_PARAMETER_TYPES.items() |
1097 | 1151 |
if name not in constants.HVC_GLOBALS |
... | ... | |
1103 | 1157 |
|
1104 | 1158 |
fields.extend([ |
1105 | 1159 |
(_MakeField("be/%s" % name, be_title.get(name, "be/%s" % name), |
1106 |
_VTToQFT[kind]), IQ_CONFIG,
|
|
1107 |
_GetInstBeParam(name)) |
|
1160 |
_VTToQFT[kind], "The \"%s\" backend parameter" % name),
|
|
1161 |
IQ_CONFIG, _GetInstBeParam(name))
|
|
1108 | 1162 |
for name, kind in constants.BES_PARAMETER_TYPES.items() |
1109 | 1163 |
]) |
1110 | 1164 |
|
... | ... | |
1112 | 1166 |
|
1113 | 1167 |
|
1114 | 1168 |
_INST_SIMPLE_FIELDS = { |
1115 |
"disk_template": ("Disk_template", QFT_TEXT), |
|
1116 |
"hypervisor": ("Hypervisor", QFT_TEXT), |
|
1117 |
"name": ("Instance", QFT_TEXT), |
|
1169 |
"disk_template": ("Disk_template", QFT_TEXT, "Instance disk template"),
|
|
1170 |
"hypervisor": ("Hypervisor", QFT_TEXT, "Hypervisor name"),
|
|
1171 |
"name": ("Instance", QFT_TEXT, "Instance name"),
|
|
1118 | 1172 |
# Depending on the hypervisor, the port can be None |
1119 |
"network_port": ("Network_port", QFT_OTHER), |
|
1120 |
"os": ("OS", QFT_TEXT), |
|
1121 |
"serial_no": ("SerialNo", QFT_NUMBER), |
|
1122 |
"uuid": ("UUID", QFT_TEXT), |
|
1173 |
"network_port": ("Network_port", QFT_OTHER, |
|
1174 |
"Instance network port if available (e.g. for VNC console)"), |
|
1175 |
"os": ("OS", QFT_TEXT, "Operating system"), |
|
1176 |
"serial_no": ("SerialNo", QFT_NUMBER, _SERIAL_NO_DOC % "Instance"), |
|
1177 |
"uuid": ("UUID", QFT_TEXT, "Instance UUID"), |
|
1123 | 1178 |
} |
1124 | 1179 |
|
1125 | 1180 |
|
... | ... | |
1128 | 1183 |
|
1129 | 1184 |
""" |
1130 | 1185 |
fields = [ |
1131 |
(_MakeField("pnode", "Primary_node", QFT_TEXT), IQ_CONFIG, |
|
1186 |
(_MakeField("pnode", "Primary_node", QFT_TEXT, "Primary node"), IQ_CONFIG,
|
|
1132 | 1187 |
_GetItemAttr("primary_node")), |
1133 |
(_MakeField("snodes", "Secondary_Nodes", QFT_OTHER), IQ_CONFIG, |
|
1134 |
lambda ctx, inst: list(inst.secondary_nodes)), |
|
1135 |
(_MakeField("admin_state", "Autostart", QFT_BOOL), IQ_CONFIG, |
|
1136 |
_GetItemAttr("admin_up")), |
|
1137 |
(_MakeField("tags", "Tags", QFT_OTHER), IQ_CONFIG, |
|
1188 |
(_MakeField("snodes", "Secondary_Nodes", QFT_OTHER, |
|
1189 |
"Secondary nodes; usually this will just be one node"), |
|
1190 |
IQ_CONFIG, lambda ctx, inst: list(inst.secondary_nodes)), |
|
1191 |
(_MakeField("admin_state", "Autostart", QFT_BOOL, |
|
1192 |
"Desired state of instance (if set, the instance should be" |
|
1193 |
" up)"), |
|
1194 |
IQ_CONFIG, _GetItemAttr("admin_up")), |
|
1195 |
(_MakeField("tags", "Tags", QFT_OTHER, "Tags"), IQ_CONFIG, |
|
1138 | 1196 |
lambda ctx, inst: list(inst.GetTags())), |
1139 |
(_MakeField("console", "Console", QFT_OTHER), IQ_CONSOLE, |
|
1197 |
(_MakeField("console", "Console", QFT_OTHER, |
|
1198 |
"Instance console information"), IQ_CONSOLE, |
|
1140 | 1199 |
_GetInstanceConsole), |
1141 | 1200 |
] |
1142 | 1201 |
|
1143 | 1202 |
# Add simple fields |
1144 |
fields.extend([(_MakeField(name, title, kind), IQ_CONFIG, _GetItemAttr(name)) |
|
1145 |
for (name, (title, kind)) in _INST_SIMPLE_FIELDS.items()]) |
|
1203 |
fields.extend([(_MakeField(name, title, kind, doc), |
|
1204 |
IQ_CONFIG, _GetItemAttr(name)) |
|
1205 |
for (name, (title, kind, doc)) in _INST_SIMPLE_FIELDS.items()]) |
|
1146 | 1206 |
|
1147 | 1207 |
# Fields requiring talking to the node |
1148 | 1208 |
fields.extend([ |
1149 |
(_MakeField("oper_state", "Running", QFT_BOOL), IQ_LIVE, |
|
1150 |
_GetInstOperState), |
|
1151 |
(_MakeField("oper_ram", "Memory", QFT_UNIT), IQ_LIVE, |
|
1152 |
_GetInstLiveData("memory")), |
|
1153 |
(_MakeField("oper_vcpus", "VCPUs", QFT_NUMBER), IQ_LIVE, |
|
1154 |
_GetInstLiveData("vcpus")), |
|
1155 |
(_MakeField("status", "Status", QFT_TEXT), IQ_LIVE, _GetInstStatus), |
|
1209 |
(_MakeField("oper_state", "Running", QFT_BOOL, "Actual state of instance"), |
|
1210 |
IQ_LIVE, _GetInstOperState), |
|
1211 |
(_MakeField("oper_ram", "Memory", QFT_UNIT, |
|
1212 |
"Actual memory usage as seen by hypervisor"), |
|
1213 |
IQ_LIVE, _GetInstLiveData("memory")), |
|
1214 |
(_MakeField("oper_vcpus", "VCPUs", QFT_NUMBER, |
|
1215 |
"Actual number of VCPUs as seen by hypervisor"), |
|
1216 |
IQ_LIVE, _GetInstLiveData("vcpus")), |
|
1156 | 1217 |
]) |
1157 | 1218 |
|
1219 |
# Status field |
|
1220 |
status_values = (constants.INSTST_RUNNING, constants.INSTST_ADMINDOWN, |
|
1221 |
constants.INSTST_WRONGNODE, constants.INSTST_ERRORUP, |
|
1222 |
constants.INSTST_ERRORDOWN, constants.INSTST_NODEDOWN, |
|
1223 |
constants.INSTST_NODEOFFLINE) |
|
1224 |
status_doc = ("Instance status; \"%s\" if instance is set to be running" |
|
1225 |
" and actually is, \"%s\" if instance is stopped and" |
|
1226 |
" is not running, \"%s\" if instance running, but not on its" |
|
1227 |
" designated primary node, \"%s\" if instance should be" |
|
1228 |
" stopped, but is actually running, \"%s\" if instance should" |
|
1229 |
" run, but doesn't, \"%s\" if instance's primary node is down," |
|
1230 |
" \"%s\" if instance's primary node is marked offline" % |
|
1231 |
status_values) |
|
1232 |
fields.append((_MakeField("status", "Status", QFT_TEXT, status_doc), |
|
1233 |
IQ_LIVE, _GetInstStatus)) |
|
1234 |
assert set(status_values) == constants.INSTST_ALL, \ |
|
1235 |
"Status documentation mismatch" |
|
1236 |
|
|
1158 | 1237 |
(network_fields, network_aliases) = _GetInstanceNetworkFields() |
1159 | 1238 |
|
1160 | 1239 |
fields.extend(network_fields) |
... | ... | |
1218 | 1297 |
|
1219 | 1298 |
""" |
1220 | 1299 |
return _PrepareFieldList([ |
1221 |
(_MakeField("name", "Name", QFT_TEXT), None, |
|
1300 |
(_MakeField("name", "Name", QFT_TEXT, "Lock name"), None,
|
|
1222 | 1301 |
lambda ctx, (name, mode, owners, pending): name), |
1223 |
(_MakeField("mode", "Mode", QFT_OTHER), LQ_MODE, |
|
1224 |
lambda ctx, (name, mode, owners, pending): mode), |
|
1225 |
(_MakeField("owner", "Owner", QFT_OTHER), LQ_OWNER, _GetLockOwners), |
|
1226 |
(_MakeField("pending", "Pending", QFT_OTHER), LQ_PENDING, _GetLockPending), |
|
1302 |
(_MakeField("mode", "Mode", QFT_OTHER, |
|
1303 |
"Mode in which the lock is currently acquired" |
|
1304 |
" (exclusive or shared)"), |
|
1305 |
LQ_MODE, lambda ctx, (name, mode, owners, pending): mode), |
|
1306 |
(_MakeField("owner", "Owner", QFT_OTHER, "Current lock owner(s)"), |
|
1307 |
LQ_OWNER, _GetLockOwners), |
|
1308 |
(_MakeField("pending", "Pending", QFT_OTHER, |
|
1309 |
"Threads waiting for the lock"), |
|
1310 |
LQ_PENDING, _GetLockPending), |
|
1227 | 1311 |
], []) |
1228 | 1312 |
|
1229 | 1313 |
|
... | ... | |
1253 | 1337 |
|
1254 | 1338 |
|
1255 | 1339 |
_GROUP_SIMPLE_FIELDS = { |
1256 |
"alloc_policy": ("AllocPolicy", QFT_TEXT), |
|
1257 |
"name": ("Group", QFT_TEXT), |
|
1258 |
"serial_no": ("SerialNo", QFT_NUMBER), |
|
1259 |
"uuid": ("UUID", QFT_TEXT), |
|
1260 |
"ndparams": ("NDParams", QFT_OTHER), |
|
1340 |
"alloc_policy": ("AllocPolicy", QFT_TEXT, "Allocation policy for group"),
|
|
1341 |
"name": ("Group", QFT_TEXT, "Group name"),
|
|
1342 |
"serial_no": ("SerialNo", QFT_NUMBER, _SERIAL_NO_DOC % "Group"),
|
|
1343 |
"uuid": ("UUID", QFT_TEXT, "Group UUID"),
|
|
1344 |
"ndparams": ("NDParams", QFT_OTHER, "Node parameters"),
|
|
1261 | 1345 |
} |
1262 | 1346 |
|
1263 | 1347 |
|
... | ... | |
1266 | 1350 |
|
1267 | 1351 |
""" |
1268 | 1352 |
# Add simple fields |
1269 |
fields = [(_MakeField(name, title, kind), GQ_CONFIG, _GetItemAttr(name)) |
|
1270 |
for (name, (title, kind)) in _GROUP_SIMPLE_FIELDS.items()] |
|
1353 |
fields = [(_MakeField(name, title, kind, doc), GQ_CONFIG, _GetItemAttr(name))
|
|
1354 |
for (name, (title, kind, doc)) in _GROUP_SIMPLE_FIELDS.items()]
|
|
1271 | 1355 |
|
1272 | 1356 |
def _GetLength(getter): |
1273 | 1357 |
return lambda ctx, group: len(getter(ctx)[group.uuid]) |
... | ... | |
1280 | 1364 |
|
1281 | 1365 |
# Add fields for nodes |
1282 | 1366 |
fields.extend([ |
1283 |
(_MakeField("node_cnt", "Nodes", QFT_NUMBER), |
|
1367 |
(_MakeField("node_cnt", "Nodes", QFT_NUMBER, "Number of nodes"),
|
|
1284 | 1368 |
GQ_NODE, _GetLength(group_to_nodes)), |
1285 |
(_MakeField("node_list", "NodeList", QFT_OTHER), |
|
1369 |
(_MakeField("node_list", "NodeList", QFT_OTHER, "List of nodes"),
|
|
1286 | 1370 |
GQ_NODE, _GetSortedList(group_to_nodes)), |
1287 | 1371 |
]) |
1288 | 1372 |
|
1289 | 1373 |
# Add fields for instances |
1290 | 1374 |
fields.extend([ |
1291 |
(_MakeField("pinst_cnt", "Instances", QFT_NUMBER), |
|
1375 |
(_MakeField("pinst_cnt", "Instances", QFT_NUMBER, |
|
1376 |
"Number of primary instances"), |
|
1292 | 1377 |
GQ_INST, _GetLength(group_to_instances)), |
1293 |
(_MakeField("pinst_list", "InstanceList", QFT_OTHER), |
|
1378 |
(_MakeField("pinst_list", "InstanceList", QFT_OTHER, |
|
1379 |
"List of primary instances"), |
|
1294 | 1380 |
GQ_INST, _GetSortedList(group_to_instances)), |
1295 | 1381 |
]) |
1296 | 1382 |
|
Also available in: Unified diff