[virt-tools-list] [PATCH 10/11] KvmHypervisor can now manage storage pools.

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


It can define and undefine, as well as create and destroy, storage
pools. It can retrieve a list of storage pools, an individual pool and
also verify that a pool exists.
---
 src/virtlib/hypervisors/kvm.py |   53 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/src/virtlib/hypervisors/kvm.py b/src/virtlib/hypervisors/kvm.py
index ee0f29a..a76aa3c 100644
--- a/src/virtlib/hypervisors/kvm.py
+++ b/src/virtlib/hypervisors/kvm.py
@@ -20,6 +20,8 @@ import libvirt
 
 from base import Hypervisor
 
+DEFAULT_POOL_TARGET_PATH='/var/lib/libvirt/images'
+
 class KvmHypervisor(Hypervisor):
     '''
     A hypervisor that works with the KVM hypervisor on Linux.
@@ -125,3 +127,54 @@ class KvmHypervisor(Hypervisor):
             if _network.isActive():
                 _network.destroy()
 
+    def do_get_storage_pools(self, defined, created):
+        result = []
+
+        if defined:
+            result.extend(self.__conn.listDefinedStoragePools())
+        if created:
+            result.extend(self.__conn.listStoragePools())
+
+        return result
+
+    def do_get_storage_pool(self, pool):
+        return self.__conn.storagePoolLookupByName(pool)
+
+    def do_define_storage_pool(self, name, config):
+        if config is None:
+            pool = virtinst.Storage.DirectoryPool(conn=self.__conn,
+                                                  name=name,
+                                                  target_path=DEFAULT_POOL_TARGET_PATH)
+            newpool = pool.install(build=True, create=True, meter=meter)
+            newpool.setAutostart(True)
+        else:
+            config.create(self.__conn)
+            pool = config.pool
+            pool.target_path = config.target_path
+            if config.needs_hostname:
+                pool.host = config.hostname
+            if config.needs_source_path:
+                pool.source_path = config.source_path
+            if config.needs_format:
+                pool.format = config.format
+            pool.conn = self.__conn
+            pool.get_xml_config()
+            newpool = pool.install(meter=None,
+                                   build=True, # config.get_build_pool(),
+                                   create=True)
+            newpool.setAutostart(True)
+
+    def do_undefine_storage_pool(self, pool):
+        _pool = self.get_storage_pool(pool)
+        _pool.undefine()
+
+    def do_create_storage_pool(self, pool):
+        _pool = self.get_storage_pool(pool)
+        if not _pool.isActive():
+            _pool.create(0)
+
+    def do_destroy_storage_pool(self, pool):
+        _pool = self.get_storage_pool(pool)
+        if _pool.isActive():
+            _pool.destroy()
+
-- 
1.7.4.2




More information about the virt-tools-list mailing list