#
#
-# Copyright (C) 2010, 2011, 2012 Google Inc.
+# Copyright (C) 2010, 2011, 2012, 2013 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
IQ_LIVE,
IQ_DISKUSAGE,
IQ_CONSOLE,
- IQ_NODES) = range(100, 105)
+ IQ_NODES,
+ IQ_NETWORKS) = range(100, 106)
(LQ_MODE,
LQ_OWNER,
return lambda _, item: getter(item)
+def _GetItemMaybeAttr(attr):
+ """Returns a field function to return a not-None attribute of the item.
+
+ If the value is None, then C{_FS_UNAVAIL} will be returned instead.
+
+ @param attr: Attribute name
+
+ """
+ def _helper(_, obj):
+ val = getattr(obj, attr)
+ if val is None:
+ return _FS_UNAVAIL
+ else:
+ return val
+ return _helper
+
+
def _GetNDParam(name):
"""Return a field function to return an ND parameter out of the context.
"dtotal": ("DTotal", QFT_UNIT, "vg_size",
"Total disk space in volume group used for instance disk"
" allocation"),
+ "spfree": ("SpFree", QFT_NUMBER, "spindles_free",
+ "Available spindles in volume group (exclusive storage only)"),
+ "sptotal": ("SpTotal", QFT_NUMBER, "spindles_total",
+ "Total spindles in volume group (exclusive storage only)"),
"mfree": ("MFree", QFT_UNIT, "memory_free",
"Memory available for instance allocations"),
"mnode": ("MNode", QFT_UNIT, "memory_dom0",
return lambda ctx, node: len(getter(ctx)[node.name])
def _GetList(getter):
- return lambda ctx, node: list(getter(ctx)[node.name])
+ return lambda ctx, node: utils.NiceSort(list(getter(ctx)[node.name]))
# Add fields operating on instance lists
for prefix, titleprefix, docword, getter in \
"""
def __init__(self, instances, cluster, disk_usage, offline_nodes, bad_nodes,
- live_data, wrongnode_inst, console, nodes, groups):
+ live_data, wrongnode_inst, console, nodes, groups, networks):
"""Initializes this class.
@param instances: List of instance objects
@param console: Per-instance console information
@type nodes: dict; node name as key
@param nodes: Node objects
+ @type networks: dict; net_uuid as key
+ @param networks: Network objects
"""
assert len(set(bad_nodes) & set(offline_nodes)) == len(offline_nodes), \
self.console = console
self.nodes = nodes
self.groups = groups
+ self.networks = networks
# Used for individual rows
self.inst_hvparams = None
return constants.INSTST_ADMINOFFLINE
-def _GetInstDiskSize(index):
- """Build function for retrieving disk size.
+def _GetInstDisk(index, cb):
+ """Build function for calling another function with an instance Disk.
@type index: int
@param index: Disk index
+ @type cb: callable
+ @param cb: Callback
"""
- def fn(_, inst):
- """Get size of a disk.
+ def fn(ctx, inst):
+ """Call helper function with instance Disk.
+ @type ctx: L{InstanceQueryData}
@type inst: L{objects.Instance}
@param inst: Instance object
"""
try:
- return inst.disks[index].size
+ nic = inst.disks[index]
except IndexError:
return _FS_UNAVAIL
+ return cb(ctx, index, nic)
+
return fn
+def _GetInstDiskSize(ctx, _, disk): # pylint: disable=W0613
+ """Get a Disk's size.
+
+ @type ctx: L{InstanceQueryData}
+ @type disk: L{objects.Disk}
+ @param disk: The Disk object
+
+ """
+ if disk.size is None:
+ return _FS_UNAVAIL
+ else:
+ return disk.size
+
+
+def _GetInstDiskSpindles(ctx, _, disk): # pylint: disable=W0613
+ """Get a Disk's spindles.
+
+ @type disk: L{objects.Disk}
+ @param disk: The Disk object
+
+ """
+ if disk.spindles is None:
+ return _FS_UNAVAIL
+ else:
+ return disk.spindles
+
+
+def _GetInstDeviceName(ctx, _, device): # pylint: disable=W0613
+ """Get a Device's Name.
+
+ @type ctx: L{InstanceQueryData}
+ @type device: L{objects.NIC} or L{objects.Disk}
+ @param device: The NIC or Disk object
+
+ """
+ if device.name is None:
+ return _FS_UNAVAIL
+ else:
+ return device.name
+
+
+def _GetInstDeviceUUID(ctx, _, device): # pylint: disable=W0613
+ """Get a Device's UUID.
+
+ @type ctx: L{InstanceQueryData}
+ @type device: L{objects.NIC} or L{objects.Disk}
+ @param device: The NIC or Disk object
+
+ """
+ if device.uuid is None:
+ return _FS_UNAVAIL
+ else:
+ return device.uuid
+
+
def _GetInstNic(index, cb):
"""Build function for calling another function with an instance NIC.
return fn
+def _GetInstNicNetworkName(ctx, _, nic): # pylint: disable=W0613
+ """Get a NIC's Network.
+
+ @type ctx: L{InstanceQueryData}
+ @type nic: L{objects.NIC}
+ @param nic: NIC object
+
+ """
+ if nic.network is None:
+ return _FS_UNAVAIL
+ else:
+ return ctx.networks[nic.network].name
+
+
def _GetInstNicNetwork(ctx, _, nic): # pylint: disable=W0613
"""Get a NIC's Network.
return _FS_UNAVAIL
+def _GetInstAllNicNetworkNames(ctx, inst):
+ """Get all network names for an instance.
+
+ @type ctx: L{InstanceQueryData}
+ @type inst: L{objects.Instance}
+ @param inst: Instance object
+
+ """
+ result = []
+
+ for nic in inst.nics:
+ name = None
+ if nic.network:
+ name = ctx.networks[nic.network].name
+ result.append(name)
+
+ assert len(result) == len(inst.nics)
+
+ return result
+
+
def _GetInstAllNicBridges(ctx, inst):
"""Get all network bridges for an instance.
(_MakeField("nic.ips", "NIC_IPs", QFT_OTHER,
"List containing each network interface's IP address"),
IQ_CONFIG, 0, lambda ctx, inst: [nic.ip for nic in inst.nics]),
+ (_MakeField("nic.names", "NIC_Names", QFT_OTHER,
+ "List containing each network interface's name"),
+ IQ_CONFIG, 0, lambda ctx, inst: [nic.name for nic in inst.nics]),
+ (_MakeField("nic.uuids", "NIC_UUIDs", QFT_OTHER,
+ "List containing each network interface's UUID"),
+ IQ_CONFIG, 0, lambda ctx, inst: [nic.uuid for nic in inst.nics]),
(_MakeField("nic.modes", "NIC_modes", QFT_OTHER,
"List containing each network interface's mode"), IQ_CONFIG, 0,
lambda ctx, inst: [nicp[constants.NIC_MODE]
(_MakeField("nic.networks", "NIC_networks", QFT_OTHER,
"List containing each interface's network"), IQ_CONFIG, 0,
lambda ctx, inst: [nic.network for nic in inst.nics]),
+ (_MakeField("nic.networks.names", "NIC_networks_names", QFT_OTHER,
+ "List containing each interface's network"),
+ IQ_NETWORKS, 0, _GetInstAllNicNetworkNames)
]
# NICs by number
(_MakeField("nic.mac/%s" % i, "NicMAC/%s" % i, QFT_TEXT,
"MAC address of %s network interface" % numtext),
IQ_CONFIG, 0, _GetInstNic(i, nic_mac_fn)),
+ (_MakeField("nic.name/%s" % i, "NicName/%s" % i, QFT_TEXT,
+ "Name address of %s network interface" % numtext),
+ IQ_CONFIG, 0, _GetInstNic(i, _GetInstDeviceName)),
+ (_MakeField("nic.uuid/%s" % i, "NicUUID/%s" % i, QFT_TEXT,
+ "UUID address of %s network interface" % numtext),
+ IQ_CONFIG, 0, _GetInstNic(i, _GetInstDeviceUUID)),
(_MakeField("nic.mode/%s" % i, "NicMode/%s" % i, QFT_TEXT,
"Mode of %s network interface" % numtext),
IQ_CONFIG, 0, _GetInstNic(i, nic_mode_fn)),
(_MakeField("nic.network/%s" % i, "NicNetwork/%s" % i, QFT_TEXT,
"Network of %s network interface" % numtext),
IQ_CONFIG, 0, _GetInstNic(i, _GetInstNicNetwork)),
+ (_MakeField("nic.network.name/%s" % i, "NicNetworkName/%s" % i, QFT_TEXT,
+ "Network name of %s network interface" % numtext),
+ IQ_NETWORKS, 0, _GetInstNic(i, _GetInstNicNetworkName)),
])
aliases = [
IQ_CONFIG, 0, lambda ctx, inst: len(inst.disks)),
(_MakeField("disk.sizes", "Disk_sizes", QFT_OTHER, "List of disk sizes"),
IQ_CONFIG, 0, lambda ctx, inst: [disk.size for disk in inst.disks]),
+ (_MakeField("disk.spindles", "Disk_spindles", QFT_OTHER,
+ "List of disk spindles"),
+ IQ_CONFIG, 0, lambda ctx, inst: [disk.spindles for disk in inst.disks]),
+ (_MakeField("disk.names", "Disk_names", QFT_OTHER, "List of disk names"),
+ IQ_CONFIG, 0, lambda ctx, inst: [disk.name for disk in inst.disks]),
+ (_MakeField("disk.uuids", "Disk_UUIDs", QFT_OTHER, "List of disk UUIDs"),
+ IQ_CONFIG, 0, lambda ctx, inst: [disk.uuid for disk in inst.disks]),
]
# Disks by number
- fields.extend([
- (_MakeField("disk.size/%s" % i, "Disk/%s" % i, QFT_UNIT,
- "Disk size of %s disk" % utils.FormatOrdinal(i + 1)),
- IQ_CONFIG, 0, _GetInstDiskSize(i))
- for i in range(constants.MAX_DISKS)])
+ for i in range(constants.MAX_DISKS):
+ numtext = utils.FormatOrdinal(i + 1)
+ fields.extend([
+ (_MakeField("disk.size/%s" % i, "Disk/%s" % i, QFT_UNIT,
+ "Disk size of %s disk" % numtext),
+ IQ_CONFIG, 0, _GetInstDisk(i, _GetInstDiskSize)),
+ (_MakeField("disk.spindles/%s" % i, "DiskSpindles/%s" % i, QFT_NUMBER,
+ "Spindles of %s disk" % numtext),
+ IQ_CONFIG, 0, _GetInstDisk(i, _GetInstDiskSpindles)),
+ (_MakeField("disk.name/%s" % i, "DiskName/%s" % i, QFT_TEXT,
+ "Name of %s disk" % numtext),
+ IQ_CONFIG, 0, _GetInstDisk(i, _GetInstDeviceName)),
+ (_MakeField("disk.uuid/%s" % i, "DiskUUID/%s" % i, QFT_TEXT,
+ "UUID of %s disk" % numtext),
+ IQ_CONFIG, 0, _GetInstDisk(i, _GetInstDeviceUUID))])
return fields
(_MakeField("admin_up", "Autostart", QFT_BOOL,
"Desired state of instance"),
IQ_CONFIG, 0, lambda ctx, inst: inst.admin_state == constants.ADMINST_UP),
+ (_MakeField("disks_active", "DisksActive", QFT_BOOL,
+ "Desired state of instance disks"),
+ IQ_CONFIG, 0, _GetItemAttr("disks_active")),
(_MakeField("tags", "Tags", QFT_OTHER, "Tags"), IQ_CONFIG, 0,
lambda ctx, inst: list(inst.GetTags())),
(_MakeField("console", "Console", QFT_OTHER,
return _PrepareFieldList(fields, [])
+class ExtStorageInfo(objects.ConfigObject):
+ __slots__ = [
+ "name",
+ "node_status",
+ "nodegroup_status",
+ "parameters",
+ ]
+
+
+def _BuildExtStorageFields():
+ """Builds list of fields for extstorage provider queries.
+
+ """
+ fields = [
+ (_MakeField("name", "Name", QFT_TEXT, "ExtStorage provider name"),
+ None, 0, _GetItemAttr("name")),
+ (_MakeField("node_status", "NodeStatus", QFT_OTHER,
+ "Status from node"),
+ None, 0, _GetItemAttr("node_status")),
+ (_MakeField("nodegroup_status", "NodegroupStatus", QFT_OTHER,
+ "Overall Nodegroup status"),
+ None, 0, _GetItemAttr("nodegroup_status")),
+ (_MakeField("parameters", "Parameters", QFT_OTHER,
+ "ExtStorage provider parameters"),
+ None, 0, _GetItemAttr("parameters")),
+ ]
+
+ return _PrepareFieldList(fields, [])
+
+
def _JobUnavailInner(fn, ctx, (job_id, job)): # pylint: disable=W0613
"""Return L{_FS_UNAVAIL} if job is None.
"""
if expname is None:
- return _FS_UNAVAIL
+ return _FS_NODATA
else:
return expname
"network6": ("IPv6Subnet", QFT_OTHER, 0, "IPv6 subnet"),
"gateway6": ("IPv6Gateway", QFT_OTHER, 0, "IPv6 gateway"),
"mac_prefix": ("MacPrefix", QFT_OTHER, 0, "MAC address prefix"),
- "network_type": ("NetworkType", QFT_OTHER, 0, "Network type"),
"serial_no": ("SerialNo", QFT_NUMBER, 0, _SERIAL_NO_DOC % "Network"),
"uuid": ("UUID", QFT_TEXT, 0, "Network UUID"),
}
# Add simple fields
fields.extend([
(_MakeField(name, title, kind, doc),
- NETQ_CONFIG, 0, _GetItemAttr(name))
+ NETQ_CONFIG, 0, _GetItemMaybeAttr(name))
for (name, (title, kind, _, doc)) in _NETWORK_SIMPLE_FIELDS.items()])
def _GetLength(getter):
#: Fields available for operating system queries
OS_FIELDS = _BuildOsFields()
+#: Fields available for extstorage provider queries
+EXTSTORAGE_FIELDS = _BuildExtStorageFields()
+
#: Fields available for job queries
JOB_FIELDS = _BuildJobFields()
constants.QR_LOCK: LOCK_FIELDS,
constants.QR_GROUP: GROUP_FIELDS,
constants.QR_OS: OS_FIELDS,
+ constants.QR_EXTSTORAGE: EXTSTORAGE_FIELDS,
constants.QR_JOB: JOB_FIELDS,
constants.QR_EXPORT: EXPORT_FIELDS,
constants.QR_NETWORK: NETWORK_FIELDS,