From 5018a335942266bb66e29911c3149b1daf441f43 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Tue, 14 Oct 2008 10:20:32 +0000 Subject: [PATCH] Change gnt-instance list to the hvparams model This is just a change of the various hvm_ and pvm parameters to the hv model. Parameters are queried via hv/$name or via the whole dict as returned by hvparams. Reviewed-by: ultrotter,imsnah --- lib/cmdlib.py | 30 ++++++++++++------------------ lib/constants.py | 12 ++++++++++++ scripts/gnt-instance | 19 +++++++++++-------- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 6743556a6..43042e1e8 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -2609,12 +2609,9 @@ class LUQueryInstances(NoHooksLU): "admin_state", "admin_ram", "disk_template", "ip", "mac", "bridge", "sda_size", "sdb_size", "vcpus", "tags", - "network_port", "kernel_path", "initrd_path", - "hvm_boot_order", "hvm_acpi", "hvm_pae", - "hvm_cdrom_image_path", "hvm_nic_type", - "hvm_disk_type", "vnc_bind_address", - "serial_no", "hypervisor", - ]) + "network_port", + "serial_no", "hypervisor", "hvparams", + ] + ["hv/%s" % name for name in constants.HVS_PARAMETERS]) _CheckOutputFields(static=self.static_fields, dynamic=self.dynamic_fields, selected=self.op.output_fields) @@ -2683,9 +2680,11 @@ class LUQueryInstances(NoHooksLU): # end data gathering + HVPREFIX = "hv/" output = [] for instance in instance_list: iout = [] + i_hv = self.cfg.GetClusterInfo().FillHV(instance) for field in self.op.output_fields: if field == "name": val = instance.name @@ -2746,18 +2745,13 @@ class LUQueryInstances(NoHooksLU): val = list(instance.GetTags()) elif field == "serial_no": val = instance.serial_no - elif field in ("network_port", "kernel_path", "initrd_path", - "hvm_boot_order", "hvm_acpi", "hvm_pae", - "hvm_cdrom_image_path", "hvm_nic_type", - "hvm_disk_type", "vnc_bind_address"): - val = getattr(instance, field, None) - if val is not None: - pass - elif field in ("hvm_nic_type", "hvm_disk_type", - "kernel_path", "initrd_path"): - val = "default" - else: - val = "-" + elif field == "network_port": + val = instance.network_port + elif (field.startswith(HVPREFIX) and + field[len(HVPREFIX):] in constants.HVS_PARAMETERS): + val = i_hv.get(field[len(HVPREFIX):], None) + elif field == "hvparams": + val = i_hv elif field == "hypervisor": val = instance.hypervisor else: diff --git a/lib/constants.py b/lib/constants.py index 3e252a189..ebeeb70a1 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -263,6 +263,18 @@ HV_PAE = "pae" HV_KERNEL_PATH = "kernel_path" HV_INITRD_PATH = "initrd_path" +HVS_PARAMETERS = frozenset([ + HV_BOOT_ORDER, + HV_CDROM_IMAGE_PATH, + HV_NIC_TYPE, + HV_DISK_TYPE, + HV_VNC_BIND_ADDRESS, + HV_ACPI, + HV_PAE, + HV_KERNEL_PATH, + HV_INITRD_PATH, + ]) + # BE parameter names BE_MEMSIZE = "memory" BE_VCPUS = "vcpus" diff --git a/scripts/gnt-instance b/scripts/gnt-instance index c05bdf579..15b3da380 100755 --- a/scripts/gnt-instance +++ b/scripts/gnt-instance @@ -188,16 +188,17 @@ def ListInstances(opts, args): "sda_size": "Disk/0", "sdb_size": "Disk/1", "status": "Status", "tags": "Tags", "network_port": "Network_port", - "kernel_path": "Kernel_path", - "initrd_path": "Initrd_path", - "hvm_boot_order": "HVM_boot_order", - "hvm_acpi": "HVM_ACPI", - "hvm_pae": "HVM_PAE", - "hvm_cdrom_image_path": "HVM_CDROM_image_path", - "hvm_nic_type": "HVM_NIC_type", - "hvm_disk_type": "HVM_disk_type", + "hv/kernel_path": "Kernel_path", + "hv/initrd_path": "Initrd_path", + "hv/boot_order": "HVM_boot_order", + "hv/acpi": "HVM_ACPI", + "hv/pae": "HVM_PAE", + "hv/cdrom_image_path": "HVM_CDROM_image_path", + "hv/nic_type": "HVM_NIC_type", + "hv/disk_type": "HVM_Disk_type", "vnc_bind_address": "VNC_bind_address", "serial_no": "SerialNo", "hypervisor": "Hypervisor", + "hvparams": "Hypervisor_parameters", } else: headers = None @@ -237,6 +238,8 @@ def ListInstances(opts, args): val = "N/A" elif field in list_type_fields: val = ",".join(val) + elif val is None: + val = "-" row[idx] = str(val) data = GenerateTable(separator=opts.separator, headers=headers, -- GitLab