From: Daniel Henrique Barboza <danielhb(a)linux.vnet.ibm.com>
Eliminated the parameter validation that is now being done
in API.json.
To simulate the operation of add disks in the mockmodel, for
each disk (which is validated with real data from the host),
for each new disk added a fixed amount is added in the
'capacity' and 'available' fields on the pool.
Signed-off-by: Daniel Henrique Barboza <danielhb(a)linux.vnet.ibm.com>
---
src/kimchi/mockmodel.py | 36 +++++++++++++++++++++++++++++-------
1 file changed, 29 insertions(+), 7 deletions(-)
diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
index 4e276eb..441c0e4 100644
--- a/src/kimchi/mockmodel.py
+++ b/src/kimchi/mockmodel.py
@@ -52,7 +52,7 @@ from kimchi.model.utils import get_vm_name
from kimchi.model.vms import VM_STATIC_UPDATE_PARAMS
from kimchi.objectstore import ObjectStore
from kimchi.screenshot import VMScreenshot
-from kimchi.utils import template_name_from_uri, pool_name_from_uri
+from kimchi.utils import pool_name_from_uri, run_command, template_name_from_uri
from kimchi.vmtemplate import VMTemplate
@@ -315,13 +315,35 @@ class MockModel(object):
storagepool.refresh()
return storagepool.info
+ def _update_lvm_disks(self, pool_name, disks):
+ pool = self._get_storagepool(pool_name)
+ # 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:
+ raise OperationFailed('%s is not a valid disk/partition. '
+ 'Could not add it to the pool %s.', disk,
+ pool_name)
+ # Adding disks to the lvm pool by adding extra capacity.
+ # Fixed amount for each disk present based in the
+ # values used in MockStoragePool.
+ capacity_per_disk = 1024 << 20
+ capacity_added = capacity_per_disk * len(disks)
+ pool.info['capacity'] += capacity_added
+ pool.info['available'] += capacity_added
+
def storagepool_update(self, name, params):
- autostart = params['autostart']
- if autostart not in [True, False]:
- raise InvalidOperation("Autostart flag must be true or false")
- storagepool = self._get_storagepool(name)
- storagepool.info['autostart'] = autostart
- ident = storagepool.name
+ pool = self._get_storagepool(name)
+ if 'autostart' in params:
+ pool.info['autostart'] = params['autostart']
+ if 'disks' in params:
+ # check if pool is type 'logical'
+ if pool.info['type'] != 'logical':
+ raise InvalidOperation("Operation available only for "
+ "'logical' type storage pool.")
+ self._update_lvm_disks(name, params['disks'])
+ ident = pool.name
return ident
def storagepool_activate(self, name):
--
1.8.3.1