[Kimchi-devel] [PATCH V3 3/6] VM supports interfaces: update model

Aline Manera alinefm at linux.vnet.ibm.com
Fri Jan 24 02:45:27 UTC 2014


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

On 01/24/2014 12:03 AM, 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 | 35 +++++++++++++++++++++++++++++++++++
>   1 file changed, 35 insertions(+)
>
> diff --git a/src/kimchi/model.py b/src/kimchi/model.py
> index 51a4427..63e748e 100644
> --- a/src/kimchi/model.py
> +++ b/src/kimchi/model.py
> @@ -974,6 +974,41 @@ class Model(object):
>                       iface.destroy()
>                   iface.undefine()
>
> +    def _get_vmifaces(self, vm):
> +        dom = self._get_vm(vm)
> +        xml = dom.XMLDesc(0)
> +        root = objectify.fromstring(xml)
> +
> +        return root.devices.findall("interface")
> +
> +    def _get_vmiface(self, vm, mac):
> +        ifaces = self._get_vmifaces(vm)
> +
> +        for iface in ifaces:
> +           if iface.mac.get('address') == mac:
> +               return iface
> +        return None
> +
> +    def vmifaces_get_list(self, vm):
> +        return [iface.mac.get('address') for iface in self._get_vmifaces(vm)]
> +
> +    def vmiface_lookup(self, vm, mac):
> +        info = {}
> +
> +        iface = self._get_vmiface(vm, mac)
> +        if iface is None:
> +            raise NotFoundError('iface: "%s"' % mac)
> +
> +        info['type'] = iface.attrib['type']
> +        info['mac'] = iface.mac.get('address')
> +        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