The class StorageVolumeModel is instantiated during the creation of
StorageVolumesModel. Thus, the class StorageVolumesModel cannot have
an instance of StorageVolumeModel initialized in its constructor as well,
otherwise it will cause an infinite loop (i.e. StorageVolumeModel creates
an instance of StorageVolumesModel during its initialization, which creates
an instance of StorageVolumeModel...).
On future patches, we will need to use the function
"_get_storagevolume" (StorageVolumeModel) from inside
StorageVolumesModel, and due to the problem described above, it isn't
possible to have an instance of StorageVolumeModel inside
StorageVolumesModel.
Change the function "_get_storagevolume" to static, and rename it to
"get_storagevolume".
Signed-off-by: Crístian Viana <vianac(a)linux.vnet.ibm.com>
---
src/kimchi/model/storagevolumes.py | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/src/kimchi/model/storagevolumes.py b/src/kimchi/model/storagevolumes.py
index 48f715e..56c54fa 100644
--- a/src/kimchi/model/storagevolumes.py
+++ b/src/kimchi/model/storagevolumes.py
@@ -249,8 +249,9 @@ class StorageVolumeModel(object):
self.task = TaskModel(**kargs)
self.storagevolumes = StorageVolumesModel(**kargs)
- def _get_storagevolume(self, poolname, name):
- pool = StoragePoolModel.get_storagepool(poolname, self.conn)
+ @staticmethod
+ def get_storagevolume(poolname, name, conn):
+ pool = StoragePoolModel.get_storagepool(poolname, conn)
if not pool.isActive():
raise InvalidOperation("KCHVOL0006E", {'name': pool})
try:
@@ -263,7 +264,7 @@ class StorageVolumeModel(object):
raise
def lookup(self, pool, name):
- vol = self._get_storagevolume(pool, name)
+ vol = StorageVolumeModel.get_storagevolume(pool, name, self.conn)
path = vol.path()
info = vol.info()
xml = vol.XMLDesc(0)
@@ -297,7 +298,7 @@ class StorageVolumeModel(object):
return res
def wipe(self, pool, name):
- volume = self._get_storagevolume(pool, name)
+ volume = StorageVolumeModel.get_storagevolume(pool, name, self.conn)
try:
volume.wipePattern(libvirt.VIR_STORAGE_VOL_WIPE_ALG_ZERO, 0)
except libvirt.libvirtError as e:
@@ -310,7 +311,7 @@ class StorageVolumeModel(object):
if pool_info['type'] in READONLY_POOL_TYPE:
raise InvalidParameter("KCHVOL0012E", {'type':
pool_info['type']})
- volume = self._get_storagevolume(pool, name)
+ volume = StorageVolumeModel.get_storagevolume(pool, name, self.conn)
try:
volume.delete(0)
except libvirt.libvirtError as e:
@@ -319,7 +320,7 @@ class StorageVolumeModel(object):
def resize(self, pool, name, size):
size = size << 20
- volume = self._get_storagevolume(pool, name)
+ volume = StorageVolumeModel.get_storagevolume(pool, name, self.conn)
try:
volume.resize(size, 0)
except libvirt.libvirtError as e:
@@ -385,8 +386,9 @@ class StorageVolumeModel(object):
try:
cb('setting up volume cloning')
- orig_vir_vol = self._get_storagevolume(orig_pool_name,
- orig_vol_name)
+ orig_vir_vol = StorageVolumeModel.get_storagevolume(orig_pool_name,
+ orig_vol_name,
+ self.conn)
orig_vol = self.lookup(orig_pool_name, orig_vol_name)
new_vir_pool = StoragePoolModel.get_storagepool(new_pool_name,
self.conn)
--
2.1.0