diff --git a/api-daemon/pvcapid/helper.py b/api-daemon/pvcapid/helper.py index 6bc7fceb..4c628e46 100755 --- a/api-daemon/pvcapid/helper.py +++ b/api-daemon/pvcapid/helper.py @@ -463,28 +463,20 @@ def get_vm_meta(zkhandler, vm): """ Get metadata of a VM. """ - retflag, retdata = pvc_vm.get_list(zkhandler, None, None, vm, is_fuzzy=False) + dom_uuid = pvc_vm.getDomainUUID(zkhandler, vm) + if not dom_uuid: + return {"message": "VM not found."}, 404 - if retflag: - if retdata: - retcode = 200 - retdata = { - 'name': vm, - 'node_limit': retdata['node_limit'], - 'node_selector': retdata['node_selector'], - 'node_autostart': retdata['node_autostart'], - 'migration_method': retdata['migration_method'] - } - else: - retcode = 404 - retdata = { - 'message': 'VM not found.' - } - else: - retcode = 400 - retdata = { - 'message': retdata - } + domain_node_limit, domain_node_selector, domain_node_autostart, domain_migrate_method = pvc_common.getDomainMetadata(zkhandler, dom_uuid) + + retcode = 200 + retdata = { + 'name': vm, + 'node_limit': domain_node_limit, + 'node_selector': domain_node_selector, + 'node_autostart': domain_node_autostart, + 'migration_method': domain_migrate_method + } return retdata, retcode @@ -499,6 +491,7 @@ def update_vm_meta(zkhandler, vm, limit, selector, autostart, provisioner_profil autostart = bool(strtobool(autostart)) except Exception: autostart = False + retflag, retdata = pvc_vm.modify_vm_metadata(zkhandler, vm, limit, selector, autostart, provisioner_profile, migration_method) if retflag: diff --git a/daemon-common/common.py b/daemon-common/common.py index 5cd9972e..14d1a17c 100644 --- a/daemon-common/common.py +++ b/daemon-common/common.py @@ -315,18 +315,9 @@ def getDomainTags(zkhandler, dom_uuid): # -# Get domain information from XML +# Get a set of domain metadata # -def getInformationFromXML(zkhandler, uuid): - """ - Gather information about a VM from the Libvirt XML configuration in the Zookeper database - and return a dict() containing it. - """ - domain_state = zkhandler.read(('domain.state', uuid)) - domain_node = zkhandler.read(('domain.node', uuid)) - domain_lastnode = zkhandler.read(('domain.last_node', uuid)) - domain_failedreason = zkhandler.read(('domain.failed_reason', uuid)) - +def getDomainMetadata(zkhandler, dom_uuid): domain_node_limit = zkhandler.read(('domain.meta.node_limit', uuid)) domain_node_selector = zkhandler.read(('domain.meta.node_selector', uuid)) domain_node_autostart = zkhandler.read(('domain.meta.autostart', uuid)) @@ -340,6 +331,24 @@ def getInformationFromXML(zkhandler, uuid): if not domain_node_autostart: domain_node_autostart = None + return domain_node_limit, domain_node_selector, domain_node_autostart, domain_migration_method + + +# +# Get domain information from XML +# +def getInformationFromXML(zkhandler, uuid): + """ + Gather information about a VM from the Libvirt XML configuration in the Zookeper database + and return a dict() containing it. + """ + domain_state = zkhandler.read(('domain.state', uuid)) + domain_node = zkhandler.read(('domain.node', uuid)) + domain_lastnode = zkhandler.read(('domain.last_node', uuid)) + domain_failedreason = zkhandler.read(('domain.failed_reason', uuid)) + + domain_node_limit, domain_node_selector, domain_node_autostart, domain_migration_method = getDomainMetadata(zkhandler, uuid) + domain_profile = zkhandler.read(('domain.profile', uuid)) domain_vnc = zkhandler.read(('domain.console.vnc', uuid))