Allows xenapi 'lookup' to look for rescue mode VMs

When you lookup a VM by name, you can specify if you want it to check if
it has a rescue mode instance running.

If it finds the rescue mode instance, it'll return that one instead
of the original name.

This is useful for operations that should work on the rescue mode vm if
it's there, or the normal one, if it's not.

Work towards bug: 1170237
Change-Id: I41b31e59631b78a62faadb9970b6b824929e7061
This commit is contained in:
Matthew Sherborne
2013-04-18 15:34:31 +10:00
committed by Gerrit Code Review
parent 4ff5d3d4c3
commit 4c887edc88
2 changed files with 36 additions and 2 deletions

View File

@@ -1394,8 +1394,15 @@ def lookup_vm_vdis(session, vm_ref):
return vdi_refs
def lookup(session, name_label):
"""Look the instance up and return it if available."""
def lookup(session, name_label, check_rescue=False):
"""Look the instance up and return it if available.
:param check_rescue: if True will return the 'name'-rescue vm if it
exists, instead of just 'name'
"""
if check_rescue:
result = lookup(session, name_label + '-rescue', False)
if result:
return result
vm_refs = session.call_xenapi("VM.get_by_name_label", name_label)
n = len(vm_refs)
if n == 0: