[Kimchi-devel] [PATCH 06/15] Move all resources related to templates to control/templates.py

Daniel H Barboza danielhb at linux.vnet.ibm.com
Mon Dec 30 17:03:49 UTC 2013


Reviewed-by: Daniel Barboza <danielhb at linux.vnet.ibm.com>

On 12/26/2013 07:48 PM, Aline Manera wrote:
> From: Aline Manera <alinefm at br.ibm.com>
>
> Templates(Collection) and Template(Resource) were moved to a new -
> control/templates.py
> That way we can easily know where template resource is implemented.
>
> Signed-off-by: Aline Manera <alinefm at br.ibm.com>
> ---
>   src/kimchi/control/templates.py |   52 +++++++++++++++++++++++++++++++++++++++
>   src/kimchi/controller.py        |   28 ---------------------
>   src/kimchi/root.py              |    3 ++-
>   3 files changed, 54 insertions(+), 29 deletions(-)
>   create mode 100644 src/kimchi/control/templates.py
>
> diff --git a/src/kimchi/control/templates.py b/src/kimchi/control/templates.py
> new file mode 100644
> index 0000000..30875cd
> --- /dev/null
> +++ b/src/kimchi/control/templates.py
> @@ -0,0 +1,52 @@
> +#
> +# 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
> +
> +
> +class Templates(Collection):
> +    def __init__(self, model):
> +        super(Templates, self).__init__(model)
> +        self.resource = Template
> +
> +
> +class Template(Resource):
> +    def __init__(self, model, ident):
> +        super(Template, self).__init__(model, ident)
> +        self.update_params = ["name", "folder", "icon", "os_distro",
> +                              "storagepool", "os_version", "cpus",
> +                              "memory", "cdrom", "disks"]
> +        self.uri_fmt = "/templates/%s"
> +
> +    @property
> +    def data(self):
> +        return {'name': self.ident,
> +                'icon': self.info['icon'],
> +                'os_distro': self.info['os_distro'],
> +                'os_version': self.info['os_version'],
> +                'cpus': self.info['cpus'],
> +                'memory': self.info['memory'],
> +                'cdrom': self.info['cdrom'],
> +                'disks': self.info['disks'],
> +                'storagepool': self.info['storagepool'],
> +                'folder': self.info.get('folder', [])}
> diff --git a/src/kimchi/controller.py b/src/kimchi/controller.py
> index cca2b57..38ccb7b 100644
> --- a/src/kimchi/controller.py
> +++ b/src/kimchi/controller.py
> @@ -44,34 +44,6 @@ class DebugReportContent(Resource):
>           raise internal_redirect(self.info['file'])
>
>
> -class Templates(Collection):
> -    def __init__(self, model):
> -        super(Templates, self).__init__(model)
> -        self.resource = Template
> -
> -
> -class Template(Resource):
> -    def __init__(self, model, ident):
> -        super(Template, self).__init__(model, ident)
> -        self.update_params = ["name", "folder", "icon", "os_distro",
> -                              "storagepool", "os_version", "cpus",
> -                              "memory", "cdrom", "disks"]
> -        self.uri_fmt = "/templates/%s"
> -
> -    @property
> -    def data(self):
> -        return {'name': self.ident,
> -                'icon': self.info['icon'],
> -                'os_distro': self.info['os_distro'],
> -                'os_version': self.info['os_version'],
> -                'cpus': self.info['cpus'],
> -                'memory': self.info['memory'],
> -                'cdrom': self.info['cdrom'],
> -                'disks': self.info['disks'],
> -                'storagepool': self.info['storagepool'],
> -                'folder': self.info.get('folder', [])}
> -
> -
>   class Interfaces(Collection):
>       def __init__(self, model):
>           super(Interfaces, self).__init__(model)
> diff --git a/src/kimchi/root.py b/src/kimchi/root.py
> index 99185eb..cd4a11f 100644
> --- a/src/kimchi/root.py
> +++ b/src/kimchi/root.py
> @@ -31,6 +31,7 @@ from kimchi import template
>   from kimchi.config import get_api_schema_file
>   from kimchi.control.utils import parse_request
>   from kimchi.control.base import Resource
> +from kimchi.control.templates import Templates
>   from kimchi.control.vms import VMs
>   from kimchi.exception import OperationFailed
>
> @@ -50,7 +51,7 @@ class Root(Resource):
>
>           Resource.__init__(self, model)
>           self.vms = VMs(model)
> -        self.templates = controller.Templates(model)
> +        self.templates = Templates(model)
>           self.storagepools = controller.StoragePools(model)
>           self.interfaces = controller.Interfaces(model)
>           self.networks = controller.Networks(model)




More information about the Kimchi-devel mailing list