[Kimchi-devel] [PATCH v2 1/4] Add disks to LVM pool: control and model changes

Daniel Barboza danielhb at linux.vnet.ibm.com
Mon Feb 10 21:52:42 UTC 2014


From: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>

Added a new update parameter to storagepool resource. Changed the
logic in the model to accept any update parameter ('autostart' or
'disks'). 'disks' parameter will add disks/partitions to the
target LVM pool.

Signed-off-by: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
---
 src/kimchi/control/storagepools.py |  2 +-
 src/kimchi/model/storagepools.py   | 46 +++++++++++++++++++++++++++++++-------
 2 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/src/kimchi/control/storagepools.py b/src/kimchi/control/storagepools.py
index ae5185c..af10acd 100644
--- a/src/kimchi/control/storagepools.py
+++ b/src/kimchi/control/storagepools.py
@@ -80,7 +80,7 @@ class StoragePools(Collection):
 class StoragePool(Resource):
     def __init__(self, model, ident):
         super(StoragePool, self).__init__(model, ident)
-        self.update_params = ["autostart"]
+        self.update_params = ["autostart", "disks"]
         self.uri_fmt = "/storagepools/%s"
         self.activate = self.generate_action_handler('activate')
         self.deactivate = self.generate_action_handler('deactivate')
diff --git a/src/kimchi/model/storagepools.py b/src/kimchi/model/storagepools.py
index 233a8a7..067311f 100644
--- a/src/kimchi/model/storagepools.py
+++ b/src/kimchi/model/storagepools.py
@@ -28,7 +28,7 @@ from kimchi.exception import InvalidOperation, MissingParameter
 from kimchi.exception import NotFoundError, OperationFailed
 from kimchi.model.libvirtstoragepool import StoragePoolDef
 from kimchi.utils import add_task, kimchi_log
-
+from kimchi.utils import run_command
 
 ISO_POOL_NAME = u'kimchi_isos'
 POOL_STATE_MAP = {0: 'inactive',
@@ -200,15 +200,45 @@ class StoragePoolModel(object):
                 pass
         return res
 
+    def _update_lvm_disks(self, pool_name, disks):
+        # check if all the disks/partitions exists in the host
+        for disk in disks:
+            blkid_cmd = ['blkid', disk]
+            output, error, returncode = run_command(blkid_cmd)
+            if returncode != 0:
+                kimchi_log.error('%s is not a valid disk/partition. Could not '
+                                 'add it to the pool %s.', disk, pool_name)
+                raise OperationFailed('%s is not a valid disk/partition. '
+                                      'Could not add it to the pool %s.', disk,
+                                      pool_name)
+        # add disks to the lvm pool using vgextend + virsh refresh
+        vgextend_cmd = ["vgextend", pool_name]
+        vgextend_cmd += disks
+        output, error, returncode = run_command(vgextend_cmd)
+        if returncode != 0:
+            kimchi_log.error('Could not add disks to pool %s, '
+                             'error: %s', pool_name, error)
+            raise OperationFailed('Error while adding disks to pool %s.',
+                                  pool_name)
+        # refreshing pool state
+        pool = self.get_storagepool(pool_name, self.conn)
+        pool.refresh(0)
+
     def update(self, name, params):
-        autostart = params['autostart']
-        if autostart not in [True, False]:
-            raise InvalidOperation("Autostart flag must be true or false")
         pool = self.get_storagepool(name, self.conn)
-        if autostart:
-            pool.setAutostart(1)
-        else:
-            pool.setAutostart(0)
+        if 'autostart' in params:
+            if params['autostart']:
+                pool.setAutostart(1)
+            else:
+                pool.setAutostart(0)
+        if 'disks' in params:
+            # check if pool is type 'logical'
+            xml = pool.XMLDesc(0)
+            pool_type = xmlutils.xpath_get_text(xml, "/pool/@type")[0]
+            if pool_type != 'logical':
+                raise InvalidOperation("Operation available only for "
+                                       "'logical' type storage pool.")
+            self._update_lvm_disks(name, params['disks'])
         ident = pool.name()
         return ident
 
-- 
1.8.3.1




More information about the Kimchi-devel mailing list