[virt-tools-list] [PATCH 07/11] KvmHypervisor can now connect to libvirt.

Darryl L. Pierce dpierce at redhat.com
Thu Apr 14 18:06:06 UTC 2011


After specifying the URL for a connection, calling the connect() API
establishes a connection to the instance.
---
 src/virtlib/hypervisors/kvm.py |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/src/virtlib/hypervisors/kvm.py b/src/virtlib/hypervisors/kvm.py
index dd746bf..8f990ee 100644
--- a/src/virtlib/hypervisors/kvm.py
+++ b/src/virtlib/hypervisors/kvm.py
@@ -24,3 +24,32 @@ class KvmHypervisor(Hypervisor):
     '''
     A hypervisor that works with the KVM hypervisor on Linux.
     '''
+
+    url = 'qemu:///system'
+    __conn = None
+
+    def set_url(self, url):
+        '''
+        Sets the URl for connecting to libvirt on the target system.
+        '''
+        self.url = url
+
+    def get_url(self):
+        '''
+        Returns the URL for connecting to libvirt on the target machine.
+        '''
+        return self.url
+
+    def do_connect(self):
+        self.__conn = libvirt.open(self.url)
+
+    def do_disconnect(self):
+        if self.__conn is not None:
+            self.__conn.disconnect()
+
+    def get_connection(self):
+        '''
+        Returns the underlying connection.
+        '''
+        return self.__conn
+
-- 
1.7.4.2




More information about the virt-tools-list mailing list