Simplify VM metadata reads

Directly call the new common getDomainMetadata function to avoid
excessive Zookeeper calls for this information.
This commit is contained in:
Joshua Boniface 2021-07-13 02:08:54 -04:00
parent 9a199992a1
commit c0a3467b70
2 changed files with 34 additions and 32 deletions

View File

@ -463,27 +463,19 @@ 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
domain_node_limit, domain_node_selector, domain_node_autostart, domain_migrate_method = pvc_common.getDomainMetadata(zkhandler, dom_uuid)
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
'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:

View File

@ -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))