[Kimchi-devel] [kimchi-devel][PATCH 4/6] Update model for existent VG

lvroyce at linux.vnet.ibm.com lvroyce at linux.vnet.ibm.com
Sun Apr 12 14:13:54 UTC 2015


From: Royce Lv <lvroyce at linux.vnet.ibm.com>

Avoid scan and build VG when using an existent VG to consturct
a logical storage pool.

Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
---
 src/kimchi/model/libvirtstoragepool.py | 11 +++++----
 src/kimchi/model/storagepools.py       | 28 +++++++++++++----------
 src/kimchi/model/vgs.py                | 42 ++++++++++++++++++++++++++++++++++
 src/kimchi/utils.py                    |  4 ++--
 4 files changed, 67 insertions(+), 18 deletions(-)
 create mode 100644 src/kimchi/model/vgs.py

diff --git a/src/kimchi/model/libvirtstoragepool.py b/src/kimchi/model/libvirtstoragepool.py
index c6deafc..b3349c4 100644
--- a/src/kimchi/model/libvirtstoragepool.py
+++ b/src/kimchi/model/libvirtstoragepool.py
@@ -140,15 +140,18 @@ class LogicalPoolDef(StoragePoolDef):
         # Required parameters
         # name:
         # type:
+        # Optional parameters
         # source[devices]:
         pool = E.pool(type='logical')
         pool.append(E.name(self.poolArgs['name']))
 
-        source = E.source()
-        for device_path in self.poolArgs['source']['devices']:
-            source.append(E.device(path=device_path))
+        if 'source' in self.poolArgs:
+            source = E.source()
+            for device_path in self.poolArgs['source']['devices']:
+                source.append(E.device(path=device_path))
+
+            pool.append(source)
 
-        pool.append(source)
         pool.append(E.target(E.path(self.path)))
         return ET.tostring(pool, encoding='unicode', pretty_print=True)
 
diff --git a/src/kimchi/model/storagepools.py b/src/kimchi/model/storagepools.py
index b85f3b4..642496a 100644
--- a/src/kimchi/model/storagepools.py
+++ b/src/kimchi/model/storagepools.py
@@ -68,6 +68,7 @@ class StoragePoolsModel(object):
                                   {'err': e.get_error_message()})
 
     def create(self, params):
+        build = True
         task_id = None
         conn = self.conn.get()
         try:
@@ -79,17 +80,20 @@ class StoragePoolsModel(object):
             # used before but a volume group will already exist with this name
             # So check the volume group does not exist to create the pool
             if params['type'] == 'logical':
-                vgdisplay_cmd = ['vgdisplay', name.encode('utf-8')]
-                output, error, returncode = run_command(vgdisplay_cmd)
-                # From vgdisplay error codes:
-                # 1  error reading VGDA
-                # 2  volume group doesn't exist
-                # 3  not all physical volumes of volume group online
-                # 4  volume group not found
-                # 5  no volume groups found at all
-                # 6  error reading VGDA from lvmtab
-                if returncode not in [2, 4, 5]:
-                    raise InvalidOperation("KCHPOOL0036E", {'name': name})
+                if'source' in params:
+                    vgdisplay_cmd = ['vgdisplay', name.encode('utf-8')]
+                    output, error, returncode = run_command(vgdisplay_cmd)
+                    # From vgdisplay error codes:
+                    # 1  error reading VGDA
+                    # 2  volume group doesn't exist
+                    # 3  not all physical volumes of volume group online
+                    # 4  volume group not found
+                    # 5  no volume groups found at all
+                    # 6  error reading VGDA from lvmtab
+                    if returncode not in [2, 4, 5]:
+                        raise InvalidOperation("KCHPOOL0036E", {'name': name})
+                else:
+                    build = False
 
             if params['type'] == 'kimchi-iso':
                 task_id = self._do_deep_scan(params)
@@ -118,7 +122,7 @@ class StoragePoolsModel(object):
                 return name
 
             pool = conn.storagePoolDefineXML(xml, 0)
-            if params['type'] in ['logical', 'dir', 'netfs', 'scsi']:
+            if build and params['type'] in ['logical', 'dir', 'netfs', 'scsi']:
                 pool.build(libvirt.VIR_STORAGE_POOL_BUILD_NEW)
                 # autostart dir, logical, netfs and scsi storage pools created
                 # from kimchi
diff --git a/src/kimchi/model/vgs.py b/src/kimchi/model/vgs.py
new file mode 100644
index 0000000..2a3c260
--- /dev/null
+++ b/src/kimchi/model/vgs.py
@@ -0,0 +1,42 @@
+#
+# Project Kimchi
+#
+# Copyright IBM, Corp. 2014-2015
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+from kimchi.utils import find_vgs
+from kimchi.model.storagepools import StoragePoolsModel, StoragePoolModel
+
+
+class VGsModel(object):
+    def __init__(self, **kargs):
+        self.conn = kargs['conn']
+        self.objstore = kargs['objstore']
+
+    def get_list(self):
+        def _get_path(name):
+            return StoragePoolModel(
+                conn=self.conn, objstore=self.objstore).lookup(name)['path']
+        vgs = find_vgs()
+        pool_name = StoragePoolsModel(
+            conn=self.conn, objstore=self.objstore).get_list()
+        pool_info = zip(pool_name, map(_get_path, pool_name))
+        for info in pool_info:
+            for vg in vgs:
+                if info[1] == vg['path']:
+                    vg['pool'] = info[0]
+
+        return vgs
diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py
index 0b11fcb..4b08112 100644
--- a/src/kimchi/utils.py
+++ b/src/kimchi/utils.py
@@ -37,7 +37,7 @@ from cherrypy.lib.reprconf import Parser
 
 from kimchi.asynctask import AsyncTask
 from kimchi.config import paths, PluginPaths
-from kimchi.exception import InvalidParameter, TimeoutExpired
+from kimchi.exception import InvalidParameter, TimeoutExpired, OperationFailed
 
 
 kimchi_log = cherrypy.log.error_log
@@ -246,7 +246,7 @@ def parse_cmd_output(output, output_items):
 
 
 def find_vgs():
-    cmd = ["vgs", "--noheadings", "-o", "vg_name, vg_size"]
+    cmd = ["vgs", "--noheadings", "-o", "vg_name,vg_size"]
     try:
         out, error, ret = run_command(cmd, 5)
     except TimeoutExpired:
-- 
2.1.0




More information about the Kimchi-devel mailing list