[Kimchi-devel] [PATCH] Use cherrypy's default dispatcher for subcollection

Aline Manera alinefm at linux.vnet.ibm.com
Mon Jan 20 16:32:44 UTC 2014


Reviewed-by: Aline Manera <alinefm at linux.vnet.ibm.com>

On 01/20/2014 12:57 AM, Mark Wu wrote:
> Currently, we override the dispatchers of resource StoragePool
> and IsoPool when the request targets to storagevolumes it holds.
> But it's not necessary to use a customized dispatcher. It can be
> done by add an attribute to associate with the subcollcetion. In
> this case,  it's 'storagevolumes'.
>
> Signed-off-by: Mark Wu <wudxw at linux.vnet.ibm.com>
> ---
>   src/kimchi/control/storagepools.py | 16 ++--------------
>   1 file changed, 2 insertions(+), 14 deletions(-)
>
> diff --git a/src/kimchi/control/storagepools.py b/src/kimchi/control/storagepools.py
> index 782f5a6..06b7196 100644
> --- a/src/kimchi/control/storagepools.py
> +++ b/src/kimchi/control/storagepools.py
> @@ -83,6 +83,7 @@ class StoragePool(Resource):
>           self.uri_fmt = "/storagepools/%s"
>           self.activate = self.generate_action_handler('activate')
>           self.deactivate = self.generate_action_handler('deactivate')
> +        self.storagevolumes = StorageVolumes(self.model, ident.decode("utf-8"))
>
>       @property
>       def data(self):
> @@ -103,27 +104,14 @@ class StoragePool(Resource):
>
>           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)
> +        self.storagevolumes = IsoVolumes(self.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"))




More information about the Kimchi-devel mailing list