[Kimchi-devel] [RFC][PATCH 3/3] VM supports interfaces: update controller

Aline Manera alinefm at linux.vnet.ibm.com
Fri Jan 17 17:38:59 UTC 2014


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

On 01/15/2014 07:53 AM, shaohef at linux.vnet.ibm.com wrote:
> From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
>
> add VmIfaces collection and VmIface resource
>
> Update VM resource.
>
> Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
> ---
>   src/kimchi/control/vm/ifaces.py | 48 +++++++++++++++++++++++++++++++++++++++++
>   src/kimchi/control/vms.py       |  9 ++++++++
>   2 files changed, 57 insertions(+)
>   create mode 100644 src/kimchi/control/vm/ifaces.py
>
> diff --git a/src/kimchi/control/vm/ifaces.py b/src/kimchi/control/vm/ifaces.py
> new file mode 100644
> index 0000000..46f4b46
> --- /dev/null
> +++ b/src/kimchi/control/vm/ifaces.py
> @@ -0,0 +1,48 @@
> +#
> +# Project Kimchi
> +#
> +# Copyright IBM, Corp. 2013
> +#
> +# Authors:
> +#  ShaoHe Feng <shaohef 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 kimchi.template
> +from kimchi.control.base import Collection, Resource
> +from kimchi.control.utils import get_class_name, model_fn
> +
> +
> +class VmIfaces(Collection):
> +    def __init__(self, model, vm):
> +        super(VmIfaces, self).__init__(model)
> +        self.resource = VmIface
> +        self.vm = vm
> +        self.resource_args = [self.vm, ]
> +        self.model_args = [self.vm, ]
> +
> +
> +class VmIface(Resource):
> +    def __init__(self, model, vm, ident):
> +        super(VmIface, self).__init__(model, ident)
> +        self.vm = vm
> +        self.ident = ident
> +        self.info = {}
> +        self.model_args = [self.vm, self.ident]
> +        self.uri_fmt = '/vms/%s/iface/%s'
> +
> +    @property
> +    def data(self):
> +        return self.info
> diff --git a/src/kimchi/control/vms.py b/src/kimchi/control/vms.py
> index 7843be7..8966ef5 100644
> --- a/src/kimchi/control/vms.py
> +++ b/src/kimchi/control/vms.py
> @@ -24,6 +24,7 @@
>
>   from kimchi.control.base import Collection, Resource
>   from kimchi.control.utils import internal_redirect
> +from kimchi.control.vm.ifaces import VmIfaces
>
>
>   class VMs(Collection):
> @@ -57,6 +58,14 @@ class VM(Resource):
>                                'port': self.info['graphics']['port']}
>                   }
>
> +    def _cp_dispatch(self, vpath):
> +        if vpath:
> +            subcollection = vpath.pop(0)
> +            if subcollection == 'ifaces':
> +                # incoming text, from URL, is not unicode, need decode
> +                return VmIfaces(self.model, self.ident.decode("utf-8"))
> +
> +
>
>   class VMScreenShot(Resource):
>       def __init__(self, model, ident):




More information about the Kimchi-devel mailing list