[virt-tools-list] [PATCH 04/11] Created the storage pool configuration class.

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


---
 src/virtlib/config.py           |   59 ++++++++++++++++++++++++++++++++
 src/virtlib/storage/__init__.py |   20 +++++++++++
 src/virtlib/storage/config.py   |   72 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 151 insertions(+), 0 deletions(-)
 create mode 100644 src/virtlib/storage/__init__.py
 create mode 100644 src/virtlib/storage/config.py

diff --git a/src/virtlib/config.py b/src/virtlib/config.py
index 5f35c71..f3cd1b4 100644
--- a/src/virtlib/config.py
+++ b/src/virtlib/config.py
@@ -92,3 +92,62 @@ class NetworkConfig:
 
         self.public_ipv4_network = (self.ipv4_address_raw.iptype() == "PUBLIC")
 
+from virtinst import Storage
+
+ROOT_TARGET_PATH='/var/lib/libvirt/images/%s'
+
+class StoragePoolConfig:
+    '''
+    Describes a storage pool.
+    '''
+
+    def __init__(self, name, type):
+        self.name = name
+        self.type = type
+        self.needs_target_path = False
+        self.needs_format      = False
+        self.needs_target_path = False
+        self.needs_format      = False
+        self.needs_hostname    = False
+        self.needs_source_path = False
+        self.needs_build_pool  = False
+        if type is not None:
+            if   type is Storage.StoragePool.TYPE_DIR:
+                self.needs_target_path = True
+                self.target_path = ROOT_TARGET_PATH % self.name
+                self.build_pool = True
+            elif type is Storage.StoragePool.TYPE_DISK:
+                self.needs_target_path = True
+                self.needs_format      = True
+                self.needs_source_path = True
+                self.needs_build_pool  = True
+            elif type is Storage.StoragePool.TYPE_FS:
+                self.needs_target_path = True
+                self.needs_format      = True
+                self.needs_source_path = True
+                self.build_pool  = True
+            elif type is Storage.StoragePool.TYPE_ISCSI:
+                self.needs_target_path = True
+                self.needs_hostname    = True
+                self.needs_source_path = True
+                self.build_pool  = False
+            elif type is Storage.StoragePool.TYPE_LOGICAL:
+                self.needs_target_path = True
+                self.needs_source_path = True
+                self.needs_build_pool  = True
+            elif type is Storage.StoragePool.TYPE_NETFS:
+                self.needs_target_path = True
+                self.needs_format      = True
+                self.needs_hostname    = True
+                self.needs_source_path = True
+                self.build_pool  = True
+            self.pool_class = Storage.StoragePool.get_pool_class(self.type)
+        else:
+            self.type = Storage.StoragePool.get_pool_types()[0]
+
+    def create(self, conn):
+        # create pool
+        self.pool = self.pool_class(name = self.name,
+                                    conn = conn)
+        if self.needs_format:
+            self.format = self.pool.formats[0]
diff --git a/src/virtlib/storage/__init__.py b/src/virtlib/storage/__init__.py
new file mode 100644
index 0000000..c46208d
--- /dev/null
+++ b/src/virtlib/storage/__init__.py
@@ -0,0 +1,20 @@
+# __init__.py - Copyright (C) 2011 Red Hat, Inc.
+# Written by Darryl L. Pierce <dpierce at redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA  02110-1301, USA.  A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+__all__ = ['config']
+
diff --git a/src/virtlib/storage/config.py b/src/virtlib/storage/config.py
new file mode 100644
index 0000000..52c7c16
--- /dev/null
+++ b/src/virtlib/storage/config.py
@@ -0,0 +1,72 @@
+# config.py - Copyright (C) 2011 Red Hat, Inc.
+# Written by Darryl L. Pierce <dpierce at redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA  02110-1301, USA.  A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+from virtinst import Storage
+
+ROOT_TARGET_PATH='/var/lib/libvirt/images/%s'
+
+class Config:
+    def __init__(self, type):
+        self.type = type
+        self.needs_target_path = False
+        self.needs_format      = False
+        self.needs_target_path = False
+        self.needs_format      = False
+        self.needs_hostname    = False
+        self.needs_source_path = False
+        self.needs_build_pool  = False
+        if type is not None:
+            if   type is Storage.StoragePool.TYPE_DIR:
+                self.needs_target_path = True
+                self.target_path = ROOT_TARGET_PATH % self.name
+                self.build_pool = True
+            elif type is Storage.StoragePool.TYPE_DISK:
+                self.needs_target_path = True
+                self.needs_format      = True
+                self.needs_source_path = True
+                self.needs_build_pool  = True
+            elif type is Storage.StoragePool.TYPE_FS:
+                self.needs_target_path = True
+                self.needs_format      = True
+                self.needs_source_path = True
+                self.build_pool  = True
+            elif type is Storage.StoragePool.TYPE_ISCSI:
+                self.needs_target_path = True
+                self.needs_hostname    = True
+                self.needs_source_path = True
+                self.build_pool  = False
+            elif type is Storage.StoragePool.TYPE_LOGICAL:
+                self.needs_target_path = True
+                self.needs_source_path = True
+                self.needs_build_pool  = True
+            elif type is Storage.StoragePool.TYPE_NETFS:
+                self.needs_target_path = True
+                self.needs_format      = True
+                self.needs_hostname    = True
+                self.needs_source_path = True
+                self.build_pool  = True
+        else:
+            self.type = Storage.StoragePool.get_pool_types()[0]
+
+    def create(self, conn):
+        # create pool
+        pool_class = Storage.StoragePool.get_pool_class(self.type)
+        self.pool = pool_class(name = self.name,
+                               conn = conn)
+        if self.needs_format:
+            self.format = self.pool.formats[0]
-- 
1.7.4.2




More information about the virt-tools-list mailing list