def fake_call_xenapi(method, *args): if method == "VM.get_VIFs": return ["fake_vif_ref", "fake_vif_ref_A2"] if method == "VIF.get_record": if args[0] == "fake_vif_ref": return { 'uuid': fake_vif['uuid'], 'MAC': fake_vif['address'], 'network': 'fake_network', 'other_config': { 'neutron-port-id': fake_vif['id'] } } else: raise exception.Exception("Failed get vif record") if method == "VIF.unplug": return if method == "VIF.destroy": if args[0] == "fake_vif_ref": return else: raise exception.Exception("unplug vif failed") if method == "VIF.create": if args[0] == "fake_vif_rec": return "fake_vif_ref" else: raise exception.Exception("VIF existed") return "Unexpected call_xenapi: %s.%s" % (method, args)
def get_vdi_for_vm_safely(session, vm_ref): vdi_refs = VMHelper.lookup_vm_vdis(session, vm_ref) if vdi_refs is None: raise Exception(_("No VDIs found for VM %s") % vm_ref) else: num_vdis = len(vdi_refs) if num_vdis != 1: raise exception.Exception(_("Unexpected number of VDIs" "(%(num_vdis)s) found" " for VM %(vm_ref)s") % locals()) vdi_ref = vdi_refs[0] vdi_rec = session.get_xenapi().VDI.get_record(vdi_ref) return vdi_ref, vdi_rec