Commit 3fe22abd authored by Christos Stavrakakis's avatar Christos Stavrakakis Committed by Helga Velroyen
Browse files

Support quering for devices names and UUIDs



Extend instance queries to list 'uuid' and 'name' fields of instance's
Disks and NICs.
Signed-off-by: default avatarChristos Stavrakakis <cstavr@grnet.gr>
Signed-off-by: default avatarDimitris Aragiorgis <dimara@grnet.gr>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent 651cc3e2
...@@ -13037,6 +13037,8 @@ class LUInstanceQueryData(NoHooksLU): ...@@ -13037,6 +13037,8 @@ class LUInstanceQueryData(NoHooksLU):
"children": dev_children, "children": dev_children,
"mode": dev.mode, "mode": dev.mode,
"size": dev.size, "size": dev.size,
"name": dev.name,
"uuid": dev.uuid,
} }
   
def Exec(self, feedback_fn): def Exec(self, feedback_fn):
......
...@@ -1541,28 +1541,75 @@ def _GetInstStatus(ctx, inst): ...@@ -1541,28 +1541,75 @@ def _GetInstStatus(ctx, inst):
return constants.INSTST_ADMINOFFLINE return constants.INSTST_ADMINOFFLINE
def _GetInstDiskSize(index): def _GetInstDisk(index, cb):
"""Build function for retrieving disk size. """Build function for calling another function with an instance Disk.
@type index: int @type index: int
@param index: Disk index @param index: Disk index
@type cb: callable
@param cb: Callback
""" """
def fn(_, inst): def fn(ctx, inst):
"""Get size of a disk. """Call helper function with instance Disk.
@type ctx: L{InstanceQueryData}
@type inst: L{objects.Instance} @type inst: L{objects.Instance}
@param inst: Instance object @param inst: Instance object
""" """
try: try:
return inst.disks[index].size nic = inst.disks[index]
except IndexError: except IndexError:
return _FS_UNAVAIL return _FS_UNAVAIL
return cb(ctx, index, nic)
return fn 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 _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): def _GetInstNic(index, cb):
"""Build function for calling another function with an instance NIC. """Build function for calling another function with an instance NIC.
...@@ -1739,6 +1786,12 @@ def _GetInstanceNetworkFields(): ...@@ -1739,6 +1786,12 @@ def _GetInstanceNetworkFields():
(_MakeField("nic.ips", "NIC_IPs", QFT_OTHER, (_MakeField("nic.ips", "NIC_IPs", QFT_OTHER,
"List containing each network interface's IP address"), "List containing each network interface's IP address"),
IQ_CONFIG, 0, lambda ctx, inst: [nic.ip for nic in inst.nics]), 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, (_MakeField("nic.modes", "NIC_modes", QFT_OTHER,
"List containing each network interface's mode"), IQ_CONFIG, 0, "List containing each network interface's mode"), IQ_CONFIG, 0,
lambda ctx, inst: [nicp[constants.NIC_MODE] lambda ctx, inst: [nicp[constants.NIC_MODE]
...@@ -1768,6 +1821,12 @@ def _GetInstanceNetworkFields(): ...@@ -1768,6 +1821,12 @@ def _GetInstanceNetworkFields():
(_MakeField("nic.mac/%s" % i, "NicMAC/%s" % i, QFT_TEXT, (_MakeField("nic.mac/%s" % i, "NicMAC/%s" % i, QFT_TEXT,
"MAC address of %s network interface" % numtext), "MAC address of %s network interface" % numtext),
IQ_CONFIG, 0, _GetInstNic(i, nic_mac_fn)), 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, (_MakeField("nic.mode/%s" % i, "NicMode/%s" % i, QFT_TEXT,
"Mode of %s network interface" % numtext), "Mode of %s network interface" % numtext),
IQ_CONFIG, 0, _GetInstNic(i, nic_mode_fn)), IQ_CONFIG, 0, _GetInstNic(i, nic_mode_fn)),
...@@ -1846,14 +1905,25 @@ def _GetInstanceDiskFields(): ...@@ -1846,14 +1905,25 @@ def _GetInstanceDiskFields():
IQ_CONFIG, 0, lambda ctx, inst: len(inst.disks)), IQ_CONFIG, 0, lambda ctx, inst: len(inst.disks)),
(_MakeField("disk.sizes", "Disk_sizes", QFT_OTHER, "List of disk sizes"), (_MakeField("disk.sizes", "Disk_sizes", QFT_OTHER, "List of disk sizes"),
IQ_CONFIG, 0, lambda ctx, inst: [disk.size for disk in inst.disks]), IQ_CONFIG, 0, lambda ctx, inst: [disk.size 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 # Disks by number
fields.extend([ for i in range(constants.MAX_DISKS):
(_MakeField("disk.size/%s" % i, "Disk/%s" % i, QFT_UNIT, numtext = utils.FormatOrdinal(i + 1)
"Disk size of %s disk" % utils.FormatOrdinal(i + 1)), fields.extend([
IQ_CONFIG, 0, _GetInstDiskSize(i)) (_MakeField("disk.size/%s" % i, "Disk/%s" % i, QFT_UNIT,
for i in range(constants.MAX_DISKS)]) "Disk size of %s disk" % numtext),
IQ_CONFIG, 0, _GetInstDisk(i, _GetInstDiskSize)),
(_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 return fields
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment