[Kimchi-devel] [PATCH 08/16] Move all resources related to storage pools to control/storagepools.py
Sheldon
shaohef at linux.vnet.ibm.com
Tue Dec 24 11:07:51 UTC 2013
On 12/24/2013 02:41 AM, Aline Manera wrote:
> From: Aline Manera <alinefm at br.ibm.com>
>
> StoragePools(Collection), StoragePool(Resource) and IsoPool(Resource) were moved
> to a new - control/storagepools.py
> That way we can easily know where storage pool resource is implemented.
>
> Signed-off-by: Aline Manera <alinefm at br.ibm.com>
> ---
> Makefile.am | 1 +
> src/kimchi/control/storagepools.py | 125 ++++++++++++++++++++++++++++++++++++
> 2 files changed, 126 insertions(+)
> create mode 100644 src/kimchi/control/storagepools.py
>
> diff --git a/Makefile.am b/Makefile.am
> index a16cd2a..f67af3d 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -47,6 +47,7 @@ PEP8_WHITELIST = \
> src/kimchi/server.py \
> src/kimchi/control/base.py \
> src/kimchi/control/debugreports.py \
> + src/kimchi/control/storagepools.py \
> src/kimchi/control/templates.py \
> src/kimchi/control/utils.py \
> src/kimchi/control/vms.py \
> diff --git a/src/kimchi/control/storagepools.py b/src/kimchi/control/storagepools.py
> new file mode 100644
> index 0000000..f4fffd7
> --- /dev/null
> +++ b/src/kimchi/control/storagepools.py
> @@ -0,0 +1,125 @@
> +#
> +# Project Kimchi
> +#
> +# Copyright IBM, Corp. 2013
> +#
> +# Authors:
> +# Adam Litke <agl at linux.vnet.ibm.com>
$ git show 44ff8295
$ git show 451c006c
the authors are:
Bing Bu Cao <mars at linux.vnet.ibm.com>
Adam Litke <agl at linux.vnet.ibm.com>
Royce Lv <lvroyce 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 cherrypy
> +
> +
> +from kimchi.control.base import Collection, Resource
> +from kimchi.control.storagevolumes import IsoVolumes, StorageVolumes
> +from kimchi.control.utils import get_class_name, model_fn, parse_request
> +from kimchi.model import ISO_POOL_NAME
> +
> +
> +class StoragePools(Collection):
> + def __init__(self, model):
> + super(StoragePools, self).__init__(model)
> + self.resource = StoragePool
> + isos = IsoPool(model)
> + isos.exposed = True
> + setattr(self, ISO_POOL_NAME, isos)
> +
> + def create(self, *args):
> + try:
> + create = getattr(self.model, model_fn(self, 'create'))
> + except AttributeError:
> + raise cherrypy.HTTPError(405,
> + 'Create is not allowed for %s' % get_class_name(self))
> +
> + params = parse_request()
> + args = self.model_args + [params]
> + name = create(*args)
> + args = self.resource_args + [name]
> + res = self.resource(self.model, *args)
> + resp = res.get()
> +
> + if 'task_id' in res.data:
> + cherrypy.response.status = 202
> + else:
> + cherrypy.response.status = 201
> +
> + return resp
> +
> + def _get_resources(self):
> + try:
> + res_list = super(StoragePools, self)._get_resources()
> + # Append reserved pools
> + isos = getattr(self, ISO_POOL_NAME)
> + isos.lookup()
> + res_list.append(isos)
> + except AttributeError:
> + pass
> +
> + return res_list
> +
> +
> +class StoragePool(Resource):
> + def __init__(self, model, ident):
> + super(StoragePool, self).__init__(model, ident)
> + self.update_params = ["autostart"]
> + self.uri_fmt = "/storagepools/%s"
> + self.activate = self.generate_action_handler(self, 'activate')
> + self.deactivate = self.generate_action_handler(self, 'deactivate')
> +
> + @property
> + def data(self):
> + res = {'name': self.ident,
> + 'state': self.info['state'],
> + 'capacity': self.info['capacity'],
> + 'allocated': self.info['allocated'],
> + 'available': self.info['available'],
> + 'path': self.info['path'],
> + 'source': self.info['source'],
> + 'type': self.info['type'],
> + 'nr_volumes': self.info['nr_volumes'],
> + 'autostart': self.info['autostart']}
> +
> + val = self.info.get('task_id')
> + if val:
> + res['task_id'] = val
> +
> + return res
> +
> + def _cp_dispatch(self, vpath):
> + if vpath:
> + subcollection = vpath.pop(0)
> + if subcollection == 'storagevolumes':
> + # incoming text, from URL, is not unicode, need decode
> + return StorageVolumes(self.model, self.ident.decode("utf-8"))
> +
> +
> +class IsoPool(Resource):
> + def __init__(self, model):
> + super(IsoPool, self).__init__(model, ISO_POOL_NAME)
> +
> + @property
> + def data(self):
> + return {'name': self.ident,
> + 'state': self.info['state'],
> + 'type': self.info['type']}
> +
> + def _cp_dispatch(self, vpath):
> + if vpath:
> + subcollection = vpath.pop(0)
> + if subcollection == 'storagevolumes':
> + # incoming text, from URL, is not unicode, need decode
> + return IsoVolumes(self.model, self.ident.decode("utf-8"))
--
Sheldon Feng(冯少合)<shaohef at linux.vnet.ibm.com>
IBM Linux Technology Center
More information about the Kimchi-devel
mailing list