<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 12/24/2013 04:18 AM, Mark Wu wrote:<br>
</div>
<blockquote cite="mid:52B92740.2010808@linux.vnet.ibm.com"
type="cite">On 12/24/2013 02:41 AM, Aline Manera wrote:
<br>
<blockquote type="cite">From: Aline Manera
<a class="moz-txt-link-rfc2396E" href="mailto:alinefm@br.ibm.com"><alinefm@br.ibm.com></a>
<br>
<br>
StoragePools(Collection), StoragePool(Resource) and
IsoPool(Resource) were moved
<br>
to a new - control/storagepools.py
<br>
That way we can easily know where storage pool resource is
implemented.
<br>
<br>
Signed-off-by: Aline Manera <a class="moz-txt-link-rfc2396E" href="mailto:alinefm@br.ibm.com"><alinefm@br.ibm.com></a>
<br>
---
<br>
Makefile.am | 1 +
<br>
src/kimchi/control/storagepools.py | 125
++++++++++++++++++++++++++++++++++++
<br>
2 files changed, 126 insertions(+)
<br>
create mode 100644 src/kimchi/control/storagepools.py
<br>
<br>
diff --git a/Makefile.am b/Makefile.am
<br>
index a16cd2a..f67af3d 100644
<br>
--- a/Makefile.am
<br>
+++ b/Makefile.am
<br>
@@ -47,6 +47,7 @@ PEP8_WHITELIST = \
<br>
src/kimchi/server.py \
<br>
src/kimchi/control/base.py \
<br>
src/kimchi/control/debugreports.py \
<br>
+ src/kimchi/control/storagepools.py \
<br>
src/kimchi/control/templates.py \
<br>
src/kimchi/control/utils.py \
<br>
src/kimchi/control/vms.py \
<br>
diff --git a/src/kimchi/control/storagepools.py
b/src/kimchi/control/storagepools.py
<br>
new file mode 100644
<br>
index 0000000..f4fffd7
<br>
--- /dev/null
<br>
+++ b/src/kimchi/control/storagepools.py
<br>
@@ -0,0 +1,125 @@
<br>
+#
<br>
+# Project Kimchi
<br>
+#
<br>
+# Copyright IBM, Corp. 2013
<br>
+#
<br>
+# Authors:
<br>
+# Adam Litke <a class="moz-txt-link-rfc2396E" href="mailto:agl@linux.vnet.ibm.com"><agl@linux.vnet.ibm.com></a>
<br>
+# Aline Manera <a class="moz-txt-link-rfc2396E" href="mailto:alinefm@linux.vnet.ibm.com"><alinefm@linux.vnet.ibm.com></a>
<br>
+#
<br>
+# This library is free software; you can redistribute it and/or
<br>
+# modify it under the terms of the GNU Lesser General Public
<br>
+# License as published by the Free Software Foundation; either
<br>
+# version 2.1 of the License, or (at your option) any later
version.
<br>
+#
<br>
+# This library is distributed in the hope that it will be
useful,
<br>
+# but WITHOUT ANY WARRANTY; without even the implied warranty
of
<br>
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU
<br>
+# Lesser General Public License for more details.
<br>
+#
<br>
+# You should have received a copy of the GNU Lesser General
Public
<br>
+# License along with this library; if not, write to the Free
Software
<br>
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301 USA
<br>
+
<br>
+import cherrypy
<br>
+
<br>
+
<br>
+from kimchi.control.base import Collection, Resource
<br>
+from kimchi.control.storagevolumes import IsoVolumes,
StorageVolumes
<br>
+from kimchi.control.utils import get_class_name, model_fn,
parse_request
<br>
+from kimchi.model import ISO_POOL_NAME
<br>
+
<br>
+
<br>
+class StoragePools(Collection):
<br>
+ def __init__(self, model):
<br>
+ super(StoragePools, self).__init__(model)
<br>
+ self.resource = StoragePool
<br>
+ isos = IsoPool(model)
<br>
+ isos.exposed = True
<br>
+ setattr(self, ISO_POOL_NAME, isos)
<br>
+
<br>
+ def create(self, *args):
<br>
+ try:
<br>
+ create = getattr(self.model, model_fn(self,
'create'))
<br>
+ except AttributeError:
<br>
+ raise cherrypy.HTTPError(405,
<br>
+ 'Create is not allowed for %s' %
get_class_name(self))
<br>
+
<br>
+ params = parse_request()
<br>
+ args = self.model_args + [params]
<br>
+ name = create(*args)
<br>
+ args = self.resource_args + [name]
<br>
+ res = self.resource(self.model, *args)
<br>
+ resp = res.get()
<br>
+
<br>
+ if 'task_id' in res.data:
<br>
+ cherrypy.response.status = 202
<br>
+ else:
<br>
+ cherrypy.response.status = 201
<br>
+
<br>
+ return resp
<br>
+
<br>
+ def _get_resources(self):
<br>
+ try:
<br>
+ res_list = super(StoragePools,
self)._get_resources()
<br>
+ # Append reserved pools
<br>
+ isos = getattr(self, ISO_POOL_NAME)
<br>
+ isos.lookup()
<br>
+ res_list.append(isos)
<br>
+ except AttributeError:
<br>
+ pass
<br>
+
<br>
+ return res_list
<br>
+
<br>
+
<br>
+class StoragePool(Resource):
<br>
+ def __init__(self, model, ident):
<br>
+ super(StoragePool, self).__init__(model, ident)
<br>
+ self.update_params = ["autostart"]
<br>
+ self.uri_fmt = "/storagepools/%s"
<br>
+ self.activate = self.generate_action_handler(self,
'activate')
<br>
+ self.deactivate = self.generate_action_handler(self,
'deactivate')
<br>
+
<br>
+ @property
<br>
+ def data(self):
<br>
+ res = {'name': self.ident,
<br>
+ 'state': self.info['state'],
<br>
+ 'capacity': self.info['capacity'],
<br>
+ 'allocated': self.info['allocated'],
<br>
+ 'available': self.info['available'],
<br>
+ 'path': self.info['path'],
<br>
+ 'source': self.info['source'],
<br>
+ 'type': self.info['type'],
<br>
+ 'nr_volumes': self.info['nr_volumes'],
<br>
+ 'autostart': self.info['autostart']}
<br>
+
<br>
+ val = self.info.get('task_id')
<br>
+ if val:
<br>
+ res['task_id'] = val
<br>
+
<br>
+ return res
<br>
+
<br>
+ def _cp_dispatch(self, vpath):
<br>
+ if vpath:
<br>
+ subcollection = vpath.pop(0)
<br>
+ if subcollection == 'storagevolumes':
<br>
+ # incoming text, from URL, is not unicode, need
decode
<br>
+ return StorageVolumes(self.model,
self.ident.decode("utf-8"))
<br>
+
<br>
+
<br>
+class IsoPool(Resource):
<br>
+ def __init__(self, model):
<br>
+ super(IsoPool, self).__init__(model, ISO_POOL_NAME)
<br>
+
<br>
+ @property
<br>
+ def data(self):
<br>
+ return {'name': self.ident,
<br>
+ 'state': self.info['state'],
<br>
+ 'type': self.info['type']}
<br>
+
<br>
+ def _cp_dispatch(self, vpath):
<br>
+ if vpath:
<br>
+ subcollection = vpath.pop(0)
<br>
+ if subcollection == 'storagevolumes':
<br>
+ # incoming text, from URL, is not unicode, need
decode
<br>
+ return IsoVolumes(self.model,
self.ident.decode("utf-8"))
<br>
</blockquote>
PEP8 error:
<br>
src/kimchi/control/base.py:285:17: E128 continuation line
under-indented for visual indent
<br>
<br>
</blockquote>
<br>
<font face="DejaVu Sans Mono">Same as I commented previously.<br>
I didn't get this error.<br>
<br>
alinefm@alinefm:~/kimchi$ sudo make check-local<br>
/usr/bin/pep8 --version<br>
1.2<br>
/usr/bin/pep8 --filename '*.py,*.py.in' src/kimchi/asynctask.py
src/kimchi/auth.py src/kimchi/cachebust.py src/kimchi/config.py.in
src/kimchi/disks.py src/kimchi/root.py src/kimchi/server.py
src/kimchi/control/base.py src/kimchi/control/config.py
src/kimchi/control/debugreports.py src/kimchi/control/host.py
src/kimchi/control/interfaces.py src/kimchi/control/networks.py
src/kimchi/control/plugins.py src/kimchi/control/storagepools.py
src/kimchi/control/storagevolumes.py src/kimchi/control/tasks.py
src/kimchi/control/templates.py src/kimchi/control/utils.py
src/kimchi/control/vms.py plugins/__init__.py
plugins/sample/__init__.py plugins/sample/model.py
tests/test_plugin.py <br>
<br>
</font>
</body>
</html>