[Kimchi-devel] [PATCH 5/7] VM supports interfaces: update controller
Aline Manera
alinefm at linux.vnet.ibm.com
Mon Jan 20 19:27:51 UTC 2014
On 01/16/2014 01:56 PM, 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..c121d83
> --- /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
> +
> +from kimchi.control.base import Collection, Resource
> +from kimchi.control.vm import SubCollection
> +
> +
> + at SubCollection('ifaces')
> +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, ]
> +
> +
Just a nit: in other resources we used "VM" at the begging instead of "Vm"
So if we follow the same it should be VMIfaces and VMIface
> +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..312802e 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 import VmDevices
>
>
> class VMs(Collection):
> @@ -57,6 +58,14 @@ class VM(Resource):
> 'port': self.info['graphics']['port']}
> }
>
> + def _cp_dispatch(self, vpath):
> + if vpath:
> + sub_collection = vpath.pop(0)
> + device = VmDevices.get(sub_collection, None)
> + if device:
> + # incoming text, from URL, is not unicode, need decode
> + return device(self.model, self.ident.decode("utf-8"))
> +
>
> class VMScreenShot(Resource):
> def __init__(self, model, ident):
More information about the Kimchi-devel
mailing list