[Kimchi-devel] [PATCH 5/7] VM supports interfaces: update controller
Sheldon
shaohef at linux.vnet.ibm.com
Mon Jan 20 06:33:08 UTC 2014
On 01/20/2014 01:36 PM, Mark Wu wrote:
> On 01/16/2014 11: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, ]
>> +
>> +
>> +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"))
>> +
> You don't need to use a customized dispatch handler because it can be
> done by the default cherryp dispatch handler if you add the
> 'subcollection' to your resource as an attribute.
ACK.
it can be same with Root sub collection/resource.
>>
>> class VMScreenShot(Resource):
>> def __init__(self, model, ident):
>
>
>
--
Thanks and best regards!
Sheldon Feng(冯少合)<shaohef at linux.vnet.ibm.com>
IBM Linux Technology Center
More information about the Kimchi-devel
mailing list