[Kimchi-devel] [PATCH 4/7] VM supports interfaces: update model

Aline Manera alinefm at linux.vnet.ibm.com
Mon Jan 20 19:24:28 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>
>
> Support vm ifaces collection GET method
> $ curl -u user -H 'Accept: application/json' -H 'Content-type:
> application/json'  http://localhost:800/vms/vm-name/ifaces/
>
> Support vm iface resource GET method
> $ curl -u user -H 'Accept: application/json' -H 'Content-type:
> application/json'  http://localhost:800/vms/vm-name/ifaces/mac
>
> Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
> ---
>   src/kimchi/model.py | 31 +++++++++++++++++++++++++++++++
>   1 file changed, 31 insertions(+)
>
> diff --git a/src/kimchi/model.py b/src/kimchi/model.py
> index 2c6d3a1..350244b 100644
> --- a/src/kimchi/model.py
> +++ b/src/kimchi/model.py
> @@ -45,6 +45,7 @@ import uuid
>   from cherrypy.process.plugins import BackgroundTask
>   from cherrypy.process.plugins import SimplePlugin
>   from collections import defaultdict
> +from lxml import objectify
>   from xml.etree import ElementTree
>
>
> @@ -967,6 +968,36 @@ class Model(object):
>                       iface.destroy()
>                   iface.undefine()
>
> +    def vmifaces_get_list(self, vm):
> +        dom = self._get_vm(vm)
> +        xml = dom.XMLDesc(0)
> +        root = objectify.fromstring(xml)
> +        macs = [iface.mac.get('address')
> +                for iface in root.devices.findall("interface")]
> +        return macs
> +
> +    def vmiface_lookup(self, vm, name):

use 'mac' instead of 'name'

> +        info = {}
> +        dom = self._get_vm(vm)
> +        xml = dom.XMLDesc(0)
> +        root = objectify.fromstring(xml)
> +
> +        iface = [iface for iface in root.devices.findall("interface")
> +                 if iface.mac.get('address') == name]
> +        if not iface:
> +            raise NotFoundError('iface: "%s"' % name)
> +        iface = iface[0]
> +
> +        info['type'] = iface.attrib['type']
> +        info['name'] = info['mac'] = iface.mac.get('address')

As I commented on previous patch 'name' isn't needed as we will use 
'mac' as iface identifier

> +        info['model'] = iface.model.get('type')
> +        if info['type'] == 'network':
> +            info['network'] = iface.source.get('network')
> +        if info['type'] == 'bridge':
> +            info['bridge'] = iface.source.get('bridge')
> +
> +        return info
> +
>       def add_task(self, target_uri, fn, opaque=None):
>           id = self.next_taskid
>           self.next_taskid = self.next_taskid + 1




More information about the Kimchi-devel mailing list