[Kimchi-devel] [PATCH 09/16] Move all resources related to storage volume to control/storagevolumes.py
Aline Manera
alinefm at linux.vnet.ibm.com
Mon Dec 23 18:41:24 UTC 2013
From: Aline Manera <alinefm at br.ibm.com>
StorageVolumes(Collection), StorageVolume(Resource) and IsoVolumes(Collection)
were moved to a new - control/storagevolumes.py
That way we can easily know where storage volume resource is implemented.
Signed-off-by: Aline Manera <alinefm at br.ibm.com>
---
Makefile.am | 1 +
src/kimchi/control/storagevolumes.py | 79 ++++++++++++++++++++++++++++++++++
2 files changed, 80 insertions(+)
create mode 100644 src/kimchi/control/storagevolumes.py
diff --git a/Makefile.am b/Makefile.am
index f67af3d..c9a1faf 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -48,6 +48,7 @@ PEP8_WHITELIST = \
src/kimchi/control/base.py \
src/kimchi/control/debugreports.py \
src/kimchi/control/storagepools.py \
+ src/kimchi/control/storagevolumes.py \
src/kimchi/control/templates.py \
src/kimchi/control/utils.py \
src/kimchi/control/vms.py \
diff --git a/src/kimchi/control/storagevolumes.py b/src/kimchi/control/storagevolumes.py
new file mode 100644
index 0000000..14f78a3
--- /dev/null
+++ b/src/kimchi/control/storagevolumes.py
@@ -0,0 +1,79 @@
+#
+# Project Kimchi
+#
+# Copyright IBM, Corp. 2013
+#
+# Authors:
+# Adam Litke <agl at linux.vnet.ibm.com>
+# Aline Manera <alinefm at linux.vnet.ibm.com>
+#
+# 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
+
+import kimchi.template
+from kimchi.control.base import Collection, Resource
+from kimchi.control.utils import get_class_name, model_fn
+
+
+class StorageVolumes(Collection):
+ def __init__(self, model, pool):
+ super(StorageVolumes, self).__init__(model)
+ self.resource = StorageVolume
+ self.pool = pool
+ self.resource_args = [self.pool, ]
+ self.model_args = [self.pool, ]
+
+
+class StorageVolume(Resource):
+ def __init__(self, model, pool, ident):
+ super(StorageVolume, self).__init__(model, ident)
+ self.pool = pool
+ self.ident = ident
+ self.info = {}
+ self.model_args = [self.pool, self.ident]
+ self.uri_fmt = '/storagepools/%s/storagevolumes/%s'
+ self.resize = self.generate_action_handler(self, 'resize', ['size'])
+ self.wipe = self.generate_action_handler(self, 'wipe')
+
+ @property
+ def data(self):
+ res = {'name': self.ident,
+ 'type': self.info['type'],
+ 'capacity': self.info['capacity'],
+ 'allocation': self.info['allocation'],
+ 'path': self.info['path'],
+ 'format': self.info['format']}
+
+ for key in ('os_version', 'os_distro', 'bootable'):
+ val = self.info.get(key)
+ if val:
+ res[key] = val
+
+ return res
+
+
+class IsoVolumes(Collection):
+ def __init__(self, model, pool):
+ super(IsoVolumes, self).__init__(model)
+ self.pool = pool
+
+ def get(self):
+ res_list = []
+ try:
+ get_list = getattr(self.model, model_fn(self, 'get_list'))
+ res_list = get_list(*self.model_args)
+ except AttributeError:
+ pass
+
+ return kimchi.template.render(get_class_name(self), res_list)
--
1.7.10.4
More information about the Kimchi-devel
mailing list