[Kimchi-devel] [PATCH 08/16] Move all resources related to storage pools to control/storagepools.py

Aline Manera alinefm at linux.vnet.ibm.com
Tue Dec 24 10:51:58 UTC 2013


On 12/24/2013 04:18 AM, Mark Wu wrote:
> 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>
>> +#  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"))
> PEP8 error:
> src/kimchi/control/base.py:285:17: E128 continuation line 
> under-indented for visual indent
>

Same as I commented previously.
I didn't get this error.

alinefm at alinefm:~/kimchi$ sudo make check-local
/usr/bin/pep8 --version
1.2
/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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ovirt.org/pipermail/kimchi-devel/attachments/20131224/f5085eed/attachment.html>


More information about the Kimchi-devel mailing list