
Newer libvirt versions report 0 when reading the current memory of a shutoff VM by calling the method "domain.info()". So when the VM is shutoff, the REST command "GET /vms/<vm>" is returning an invalid memory value. Read the memory value from the VM's XML descriptor when it is shutoff, and keep returning the value from "domain.info()" otherwise. Fix issue #595 (Memory is set to 0 (null) when editing guest). Signed-off-by: Crístian Viana <vianac@linux.vnet.ibm.com> --- src/kimchi/model/vms.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py index 018df9e..4c5f443 100644 --- a/src/kimchi/model/vms.py +++ b/src/kimchi/model/vms.py @@ -41,8 +41,8 @@ from kimchi.model.utils import get_metadata_node from kimchi.model.utils import set_metadata_node from kimchi.rollbackcontext import RollbackContext from kimchi.screenshot import VMScreenshot -from kimchi.utils import add_task, get_next_clone_name, import_class -from kimchi.utils import kimchi_log, run_setfacl_set_attr +from kimchi.utils import add_task, convert_data_size, get_next_clone_name +from kimchi.utils import import_class, kimchi_log, run_setfacl_set_attr from kimchi.utils import template_name_from_uri from kimchi.xmlutils.utils import xpath_get_text, xml_item_update from kimchi.xmlutils.utils import dictize @@ -70,6 +70,8 @@ XPATH_DOMAIN_NAME = '/domain/name' XPATH_DOMAIN_MAC = "/domain/devices/interface[@type='network']/mac/@address" XPATH_DOMAIN_MAC_BY_ADDRESS = "./devices/interface[@type='network']/"\ "mac[@address='%s']" +XPATH_DOMAIN_MEMORY = '/domain/memory' +XPATH_DOMAIN_MEMORY_UNIT = '/domain/memory/@unit' XPATH_DOMAIN_UUID = '/domain/uuid' @@ -819,11 +821,23 @@ class VMModel(object): res['io_throughput_peak'] = vm_stats.get('max_disk_io', 100) users, groups = self._get_access_info(dom) + if state == 'shutoff': + xml = dom.XMLDesc(0) + val = xpath_get_text(xml, XPATH_DOMAIN_MEMORY)[0] + unit_list = xpath_get_text(xml, XPATH_DOMAIN_MEMORY_UNIT) + if len(unit_list) > 0: + unit = unit_list[0] + else: + unit = 'KiB' + memory = convert_data_size(val, unit, 'MiB') + else: + memory = info[2] >> 10 + return {'name': name, 'state': state, 'stats': res, 'uuid': dom.UUIDString(), - 'memory': info[2] >> 10, + 'memory': memory, 'cpus': info[3], 'screenshot': screenshot, 'icon': icon, -- 2.1.0