From afa1d917827dbda8ae03fc8e8ab0d5b42157a927 Mon Sep 17 00:00:00 2001 From: Jim Yeh Date: Mon, 31 Mar 2014 11:05:31 +0800 Subject: [PATCH] Fix the default url of get_xml function. * This enable a user to configure uri in get_xml function --- cloud/virt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/cloud/virt b/cloud/virt index 78d2aa1ab91..f1d36fc1964 100644 --- a/cloud/virt +++ b/cloud/virt @@ -108,7 +108,7 @@ VIRT_STATE_NAME_MAP = { 6 : "crashed" } -class VMNotFound(Exception): +class VMNotFound(Exception): pass class LibvirtConnection(object): @@ -197,6 +197,10 @@ class LibvirtConnection(object): def get_type(self): return self.conn.getType() + def get_xml(self, vmid): + vm = self.conn.lookupByName(vmid) + return vm.XMLDesc(0) + def get_maxVcpus(self, vmid): vm = self.conn.lookupByName(vmid) return vm.maxVcpus() @@ -361,14 +365,8 @@ class Virt(object): Return an xml describing vm config returned by a libvirt call """ - conn = libvirt.openReadOnly(None) - if not conn: - return (-1,'Failed to open connection to the hypervisor') - try: - domV = conn.lookupByName(vmid) - except: - return (-1,'Failed to find the main domain') - return domV.XMLDesc(0) + self.__get_conn() + return self.conn.get_xml(vmid) def get_maxVcpus(self, vmid): """