Commit 644eeef9 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add support for listing instance disk sizes.

Reviewed-by: imsnah
parent a02bc76e
......@@ -2052,7 +2052,8 @@ class LUQueryInstances(NoHooksLU):
self.dynamic_fields = frozenset(["oper_state", "oper_ram"])
_CheckOutputFields(static=["name", "os", "pnode", "snodes",
"admin_state", "admin_ram",
"disk_template", "ip", "mac", "bridge"],
"disk_template", "ip", "mac", "bridge",
"sda_size", "sdb_size"],
......@@ -2126,6 +2127,12 @@ class LUQueryInstances(NoHooksLU):
val = instance.nics[0].bridge
elif field == "mac":
val = instance.nics[0].mac
elif field == "sda_size" or field == "sdb_size":
disk = instance.FindDisk(field[:3])
if disk is None:
val = "N/A"
val = disk.size
raise errors.ParameterError(field)
val = str(val)
......@@ -379,6 +379,18 @@ class Instance(ConfigObject, TaggableObject):
return ret
def FindDisk(self, name):
"""Find a disk given having a specified name.
This will return the disk which has the given iv_name.
for disk in self.disks:
if disk.iv_name == name:
return disk
return None
class OS(ConfigObject):
"""Config object representing an operating system."""
......@@ -50,16 +50,17 @@ def ListInstances(opts, args):
"oper_state": "Status", "admin_ram": "Configured_memory",
"oper_ram": "Memory", "disk_template": "Disk_template",
"ip": "IP Address", "mac": "MAC Address",
"bridge": "Bridge"}
"bridge": "Bridge",
"sda_size": "Disk/0", "sdb_size": "Disk/1"}
headers = None
if opts.human_readable:
unitfields = ["admin_ram", "oper_ram"]
unitfields = ["admin_ram", "oper_ram", "sda_size", "sdb_size"]
unitfields = None
numfields = ["admin_ram", "oper_ram"]
numfields = ["admin_ram", "oper_ram", "sda_size", "sdb_size"]
data = GenerateTable(separator=opts.separator, headers=headers,
fields=selected_fields, unitfields=unitfields,
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