from ganeti.constants import (QFT_UNKNOWN, QFT_TEXT, QFT_BOOL, QFT_NUMBER,
QFT_UNIT, QFT_TIMESTAMP, QFT_OTHER,
- QRFS_NORMAL, QRFS_UNKNOWN, QRFS_NODATA,
- QRFS_UNAVAIL, QRFS_OFFLINE)
+ RS_NORMAL, RS_UNKNOWN, RS_NODATA,
+ RS_UNAVAIL, RS_OFFLINE)
# Constants for requesting data from the caller/data provider. Each property
(IQ_CONFIG,
IQ_LIVE,
- IQ_DISKUSAGE) = range(100, 103)
+ IQ_DISKUSAGE,
+ IQ_CONSOLE) = range(100, 104)
(LQ_MODE,
LQ_OWNER,
"""
if value is _FS_UNKNOWN:
- return (QRFS_UNKNOWN, None)
+ return (RS_UNKNOWN, None)
elif value is _FS_NODATA:
- return (QRFS_NODATA, None)
+ return (RS_NODATA, None)
elif value is _FS_UNAVAIL:
- return (QRFS_UNAVAIL, None)
+ return (RS_UNAVAIL, None)
elif value is _FS_OFFLINE:
- return (QRFS_OFFLINE, None)
+ return (RS_OFFLINE, None)
else:
- return (QRFS_NORMAL, value)
+ return (RS_NORMAL, value)
def _VerifyResultRow(fields, row):
assert len(row) == len(fields)
errs = []
for ((status, value), (fdef, _, _)) in zip(row, fields):
- if status == QRFS_NORMAL:
+ if status == RS_NORMAL:
if not _VERIFY_FN[fdef.kind](value):
errs.append("normal field %s fails validation (value is %s)" %
(fdef.name, value))
(utils.CommaJoin(errors), row))
-def _PrepareFieldList(fields):
+def _PrepareFieldList(fields, aliases):
"""Prepares field list for use by L{Query}.
Converts the list to a dictionary and does some verification.
- @type fields: list of tuples; (L{objects.QueryFieldDefinition}, data kind,
- retrieval function)
- @param fields: List of fields, see L{Query.__init__} for a better description
+ @type fields: list of tuples; (L{objects.QueryFieldDefinition}, data
+ kind, retrieval function)
+ @param fields: List of fields, see L{Query.__init__} for a better
+ description
+ @type aliases: list of tuples; (alias, target)
+ @param aliases: list of tuples containing aliases; for each
+ alias/target pair, a duplicate will be created in the field list
@rtype: dict
@return: Field dictionary for L{Query}
result[fdef.name] = field
- assert len(result) == len(fields)
+ for alias, target in aliases:
+ assert alias not in result, "Alias %s overrides an existing field" % alias
+ assert target in result, "Missing target %s for alias %s" % (target, alias)
+ (fdef, k, fn) = result[target]
+ fdef = fdef.Copy()
+ fdef.name = alias
+ result[alias] = (fdef, k, fn)
+
+ assert len(result) == len(fields) + len(aliases)
assert compat.all(name == fdef.name
for (name, (fdef, _, _)) in result.items())
# Add timestamps
fields.extend(_GetItemTimestampFields(NQ_CONFIG))
- return _PrepareFieldList(fields)
+ return _PrepareFieldList(fields, [])
class InstanceQueryData:
"""
def __init__(self, instances, cluster, disk_usage, offline_nodes, bad_nodes,
- live_data):
+ live_data, wrongnode_inst, console):
"""Initializes this class.
@param instances: List of instance objects
@param bad_nodes: List of faulty nodes
@type live_data: dict; instance name as key
@param live_data: Per-instance live data
+ @type wrongnode_inst: set
+ @param wrongnode_inst: Set of instances running on wrong node(s)
+ @type console: dict; instance name as key
+ @param console: Per-instance console information
"""
assert len(set(bad_nodes) & set(offline_nodes)) == len(offline_nodes), \
self.offline_nodes = offline_nodes
self.bad_nodes = bad_nodes
self.live_data = live_data
+ self.wrongnode_inst = wrongnode_inst
+ self.console = console
# Used for individual rows
self.inst_hvparams = None
@param inst: Instance object
"""
- # Can't use QRFS_OFFLINE here as it would describe the instance to
+ # Can't use RS_OFFLINE here as it would describe the instance to
# be offline when we actually don't know due to missing data
if inst.primary_node in ctx.bad_nodes:
return _FS_NODATA
"""
if (inst.primary_node in ctx.bad_nodes or
inst.primary_node in ctx.offline_nodes):
- # Can't use QRFS_OFFLINE here as it would describe the instance to be
+ # Can't use RS_OFFLINE here as it would describe the instance to be
# offline when we actually don't know due to missing data
return _FS_NODATA
return "ERROR_nodedown"
if bool(ctx.live_data.get(inst.name)):
- if inst.admin_up:
+ if inst.name in ctx.wrongnode_inst:
+ return "ERROR_wrongnode"
+ elif inst.admin_up:
return "running"
else:
return "ERROR_up"
return usage
+def _GetInstanceConsole(ctx, inst):
+ """Get console information for instance.
+
+ @type ctx: L{InstanceQueryData}
+ @type inst: L{objects.Instance}
+ @param inst: Instance object
+
+ """
+ consinfo = ctx.console[inst.name]
+
+ if consinfo is None:
+ return _FS_UNAVAIL
+
+ return consinfo
+
+
def _GetInstanceDiskFields():
"""Get instance fields involving disks.
fields = [
(_MakeField("disk_usage", "DiskUsage", QFT_UNIT), IQ_DISKUSAGE,
_GetInstDiskUsage),
- (_MakeField("sda_size", "LegacyDisk/0", QFT_UNIT), IQ_CONFIG,
- _GetInstDiskSize(0)),
- (_MakeField("sdb_size", "LegacyDisk/1", QFT_UNIT), IQ_CONFIG,
- _GetInstDiskSize(1)),
(_MakeField("disk.count", "Disks", QFT_NUMBER), IQ_CONFIG,
lambda ctx, inst: len(inst.disks)),
(_MakeField("disk.sizes", "Disk_sizes", QFT_OTHER), IQ_CONFIG,
IQ_CONFIG, lambda ctx, _: ctx.inst_hvparams),
(_MakeField("beparams", "BackendParameters", QFT_OTHER),
IQ_CONFIG, lambda ctx, _: ctx.inst_beparams),
- (_MakeField("vcpus", "LegacyVCPUs", QFT_NUMBER), IQ_CONFIG,
- lambda ctx, _: ctx.inst_beparams[constants.BE_VCPUS]),
# Unfilled parameters
(_MakeField("custom_hvparams", "CustomHypervisorParameters", QFT_OTHER),
_GetItemAttr("admin_up")),
(_MakeField("tags", "Tags", QFT_OTHER), IQ_CONFIG,
lambda ctx, inst: list(inst.GetTags())),
+ (_MakeField("console", "Console", QFT_OTHER), IQ_CONSOLE,
+ _GetInstanceConsole),
]
# Add simple fields
fields.extend(_GetInstanceNetworkFields())
fields.extend(_GetItemTimestampFields(IQ_CONFIG))
- return _PrepareFieldList(fields)
+ aliases = [
+ ("vcpus", "be/vcpus"),
+ ("sda_size", "disk.size/0"),
+ ("sdb_size", "disk.size/1"),
+ ]
+
+ return _PrepareFieldList(fields, aliases)
class LockQueryData:
lambda ctx, (name, mode, owners, pending): mode),
(_MakeField("owner", "Owner", QFT_OTHER), LQ_OWNER, _GetLockOwners),
(_MakeField("pending", "Pending", QFT_OTHER), LQ_PENDING, _GetLockPending),
- ])
+ ], [])
class GroupQueryData:
fields.extend(_GetItemTimestampFields(GQ_CONFIG))
- return _PrepareFieldList(fields)
+ return _PrepareFieldList(fields, [])
#: Fields available for node queries