[Kimchi-devel] [PATCH 05/16] Move all resources related to vms to control/vms.py

Mark Wu wudxw at linux.vnet.ibm.com
Tue Dec 24 06:26:18 UTC 2013


On 12/24/2013 02:41 AM, Aline Manera wrote:
> From: Aline Manera <alinefm at br.ibm.com>
>
> VMs(Collection), VM(Resource) and VMScreenshot(Resource) were moved to a new -
> control/vms.py
> That way we can easily know where vm resource is implemented.
>
> Signed-off-by: Aline Manera <alinefm at br.ibm.com>
> ---
>   Makefile.am               |    1 +
>   src/kimchi/control/vms.py |   64 +++++++++++++++++++++++++++++++++++++++++++++
>   2 files changed, 65 insertions(+)
>   create mode 100644 src/kimchi/control/vms.py
>
> diff --git a/Makefile.am b/Makefile.am
> index 997d4cc..3fda86f 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/utils.py \
> +	src/kimchi/control/vms.py \
>   	plugins/__init__.py \
>   	plugins/sample/__init__.py \
>   	plugins/sample/model.py \
> diff --git a/src/kimchi/control/vms.py b/src/kimchi/control/vms.py
> new file mode 100644
> index 0000000..da960cd
> --- /dev/null
> +++ b/src/kimchi/control/vms.py
> @@ -0,0 +1,64 @@
> +#
> +# 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
> +
> +from kimchi.control.base import Collection, Resource
> +from kimchi.control.utils import internal_redirect
> +
> +
> +class VMs(Collection):
> +    def __init__(self, model):
> +        super(VMs, self).__init__(model)
> +        self.resource = VM
> +
> +
> +class VM(Resource):
> +    def __init__(self, model, ident):
> +        super(VM, self).__init__(model, ident)
> +        self.update_params = ["name"]
> +        self.screenshot = VMScreenShot(model, ident)
> +        self.uri_fmt = '/vms/%s'
> +        self.start = self.generate_action_handler(self, 'start')
> +        self.stop = self.generate_action_handler(self, 'stop')
> +        self.connect = self.generate_action_handler(self, 'connect')
> +
> +    @property
> +    def data(self):
> +        return {'name': self.ident,
> +                'uuid': self.info['uuid'],
> +                'stats': self.info['stats'],
> +                'memory': self.info['memory'],
> +                'cpus': self.info['cpus'],
> +                'state': self.info['state'],
> +                'screenshot': self.info['screenshot'],
> +                'icon': self.info['icon'],
> +                'graphics': {'type': self.info['graphics']['type'],
> +                             'port': self.info['graphics']['port']}}
> +
> +
> +class VMScreenShot(Resource):
> +    def __init__(self, model, ident):
> +        super(VMScreenShot, self).__init__(model, ident)
> +
> +    def get(self):
> +        self.lookup()
> +        raise internal_redirect(self.info)
I don't understand why the original code was remained there.




More information about the Kimchi-devel mailing list