[RFC][PATCH 0/3] VM supports interfaces

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> just support get interfaces missing mockmodel and testcase ShaoHe Feng (3): VM supports interfaces: update API VM supports interfaces: update model VM supports interfaces: update controller docs/API.md | 47 ++++++++++++++++++++++++++++++++++++++++ src/kimchi/control/vm/ifaces.py | 48 +++++++++++++++++++++++++++++++++++++++++ src/kimchi/control/vms.py | 9 ++++++++ src/kimchi/model.py | 31 ++++++++++++++++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 src/kimchi/control/vm/ifaces.py -- 1.8.4.2

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Now kimchi supports network get/create/delete/activate/deactivate REST API. We need to support the attach/detach/ a Network to a VM. https://github.com/kimchi-project/kimchi/wiki/customize-VM#organization-of-s... And get the info of Network attached to a VM. more libvirt network interfaces info: http://libvirt.org/formatdomain.html#elementsNICS Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- docs/API.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/docs/API.md b/docs/API.md index 6e240eb..db2837e 100644 --- a/docs/API.md +++ b/docs/API.md @@ -149,6 +149,53 @@ Represents a snapshot of the Virtual Machine's primary monitor. * null: Graphics is disabled or type not supported * listen: The network which the vnc/spice server listens on. +### Sub-Collection: Virtual Machine Network Interfaces + +**URI:** /vms/*:name*/ifaces + +Represents all network interfaces attached to a Virtual Machine. + +**Methods:** + +* **GET**: Retrieve a summarized list of all network interfaces attached to a Virtual Machine. + +* **POST**: attach a network interface to VM + * type: The type of VM network interface that libvirt supports. + Now kimchi just supports 'network' type. + * network *(optional)*: the name of resource network, it is required when the + interface type is network. + * model *(optional)*: model of emulated network interface card. It can be one of these models: + ne2k_pci, i82551, i82557b, i82559er, rtl8139, e1000, pcnet and virtio. + When model is missing, libvirt will set 'rtl8139' as default value. + +### Sub-Resource: Virtual Machine Network Interface + +**URI:** /vms/*:name*/ifaces/*:name* + +A interface represents available network interface on VM. + +**Methods:** + +* **GET**: Retrieve the full description of the VM network interface + * name: The identifier of the network interface. + * type: The type of VM network interface that libvirt supports. + It will be one of these types: 'network', 'bridge', 'user','ethernet', + 'direct', 'hostdev', 'mcast', 'server' and 'client'. + * network *(optional)*: the name of resource network, only be available when the + interface type is network. + * bridge *(optional)*: the name of resource bridge, only be available when the + interface type is bridge. + * mac: Media Access Control Address of the VM interface. + * model: model of emulated network interface card. It will be one of these models: + ne2k_pci, i82551, i82557b, i82559er, rtl8139, e1000, pcnet and virtio. + +* **DELETE**: detach the network interface from VM + +**Actions (POST):** + +*No actions defined* + + ### Resource: Template **URI:** /templates/*:name* -- 1.8.4.2

On 01/15/2014 05:53 PM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
Now kimchi supports network get/create/delete/activate/deactivate REST API.
We need to support the attach/detach/ a Network to a VM. https://github.com/kimchi-project/kimchi/wiki/customize-VM#organization-of-s... And get the info of Network attached to a VM.
more libvirt network interfaces info: http://libvirt.org/formatdomain.html#elementsNICS
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- docs/API.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
diff --git a/docs/API.md b/docs/API.md index 6e240eb..db2837e 100644 --- a/docs/API.md +++ b/docs/API.md @@ -149,6 +149,53 @@ Represents a snapshot of the Virtual Machine's primary monitor. * null: Graphics is disabled or type not supported * listen: The network which the vnc/spice server listens on.
+### Sub-Collection: Virtual Machine Network Interfaces + +**URI:** /vms/*:name*/ifaces + +Represents all network interfaces attached to a Virtual Machine. + +**Methods:** + +* **GET**: Retrieve a summarized list of all network interfaces attached to a Virtual Machine. + +* **POST**: attach a network interface to VM + * type: The type of VM network interface that libvirt supports. + Now kimchi just supports 'network' type. + * network *(optional)*: the name of resource network, it is required when the + interface type is network. + * model *(optional)*: model of emulated network interface card. It can be one of these models: + ne2k_pci, i82551, i82557b, i82559er, rtl8139, e1000, pcnet and virtio. + When model is missing, libvirt will set 'rtl8139' as default value. + +### Sub-Resource: Virtual Machine Network Interface + +**URI:** /vms/*:name*/ifaces/*:name* **URI:** /vms/*:name*/ifaces/*:mac* use mac instead of name? + +A interface represents available network interface on VM. + +**Methods:** + +* **GET**: Retrieve the full description of the VM network interface + * name: The identifier of the network interface. remove name? + * type: The type of VM network interface that libvirt supports. + It will be one of these types: 'network', 'bridge', 'user','ethernet', + 'direct', 'hostdev', 'mcast', 'server' and 'client'. + * network *(optional)*: the name of resource network, only be available when the + interface type is network. + * bridge *(optional)*: the name of resource bridge, only be available when the + interface type is bridge. + * mac: Media Access Control Address of the VM interface. + * model: model of emulated network interface card. It will be one of these models: + ne2k_pci, i82551, i82557b, i82559er, rtl8139, e1000, pcnet and virtio. + +* **DELETE**: detach the network interface from VM + +**Actions (POST):** + +*No actions defined* + + ### Resource: Template
**URI:** /templates/*:name*
-- Thanks and best regards! Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center

On 01/15/2014 12:17 PM, Sheldon wrote:
On 01/15/2014 05:53 PM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
Now kimchi supports network get/create/delete/activate/deactivate REST API.
We need to support the attach/detach/ a Network to a VM. https://github.com/kimchi-project/kimchi/wiki/customize-VM#organization-of-s...
And get the info of Network attached to a VM.
more libvirt network interfaces info: http://libvirt.org/formatdomain.html#elementsNICS
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- docs/API.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
diff --git a/docs/API.md b/docs/API.md index 6e240eb..db2837e 100644 --- a/docs/API.md +++ b/docs/API.md @@ -149,6 +149,53 @@ Represents a snapshot of the Virtual Machine's primary monitor. * null: Graphics is disabled or type not supported * listen: The network which the vnc/spice server listens on.
+### Sub-Collection: Virtual Machine Network Interfaces + +**URI:** /vms/*:name*/ifaces + +Represents all network interfaces attached to a Virtual Machine. + +**Methods:** + +* **GET**: Retrieve a summarized list of all network interfaces attached to a Virtual Machine. + +* **POST**: attach a network interface to VM + * type: The type of VM network interface that libvirt supports. + Now kimchi just supports 'network' type. + * network *(optional)*: the name of resource network, it is required when the + interface type is network. + * model *(optional)*: model of emulated network interface card. It can be one of these models: + ne2k_pci, i82551, i82557b, i82559er, rtl8139, e1000, pcnet and virtio. + When model is missing, libvirt will set 'rtl8139' as default value. + +### Sub-Resource: Virtual Machine Network Interface + +**URI:** /vms/*:name*/ifaces/*:name* **URI:** /vms/*:name*/ifaces/*:mac* use mac instead of name?
Yeap
+ +A interface represents available network interface on VM. + +**Methods:** + +* **GET**: Retrieve the full description of the VM network interface + * name: The identifier of the network interface. remove name?
I think so.
+ * type: The type of VM network interface that libvirt supports. + It will be one of these types: 'network', 'bridge', 'user','ethernet', + 'direct', 'hostdev', 'mcast', 'server' and 'client'. + * network *(optional)*: the name of resource network, only be available when the + interface type is network. + * bridge *(optional)*: the name of resource bridge, only be available when the + interface type is bridge. + * mac: Media Access Control Address of the VM interface. + * model: model of emulated network interface card. It will be one of these models: + ne2k_pci, i82551, i82557b, i82559er, rtl8139, e1000, pcnet and virtio. + +* **DELETE**: detach the network interface from VM + +**Actions (POST):** + +*No actions defined* + + ### Resource: Template
**URI:** /templates/*:name*

On 01/15/2014 07:53 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
Now kimchi supports network get/create/delete/activate/deactivate REST API.
We need to support the attach/detach/ a Network to a VM. https://github.com/kimchi-project/kimchi/wiki/customize-VM#organization-of-s... And get the info of Network attached to a VM.
more libvirt network interfaces info: http://libvirt.org/formatdomain.html#elementsNICS
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- docs/API.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
diff --git a/docs/API.md b/docs/API.md index 6e240eb..db2837e 100644 --- a/docs/API.md +++ b/docs/API.md @@ -149,6 +149,53 @@ Represents a snapshot of the Virtual Machine's primary monitor. * null: Graphics is disabled or type not supported * listen: The network which the vnc/spice server listens on.
+### Sub-Collection: Virtual Machine Network Interfaces + +**URI:** /vms/*:name*/ifaces + +Represents all network interfaces attached to a Virtual Machine. + +**Methods:** + +* **GET**: Retrieve a summarized list of all network interfaces attached to a Virtual Machine. + +* **POST**: attach a network interface to VM + * type: The type of VM network interface that libvirt supports. + Now kimchi just supports 'network' type. + * network *(optional)*: the name of resource network, it is required when the + interface type is network. + * model *(optional)*: model of emulated network interface card. It can be one of these models: + ne2k_pci, i82551, i82557b, i82559er, rtl8139, e1000, pcnet and virtio. + When model is missing, libvirt will set 'rtl8139' as default value. + +### Sub-Resource: Virtual Machine Network Interface + +**URI:** /vms/*:name*/ifaces/*:name*
I think "mac" is safer than using "name"
+ +A interface represents available network interface on VM.
Represents a network interface on VM.
+ +**Methods:** + +* **GET**: Retrieve the full description of the VM network interface + * name: The identifier of the network interface. + * type: The type of VM network interface that libvirt supports. + It will be one of these types: 'network', 'bridge', 'user','ethernet', + 'direct', 'hostdev', 'mcast', 'server' and 'client'. + * network *(optional)*: the name of resource network, only be available when the + interface type is network. + * bridge *(optional)*: the name of resource bridge, only be available when the + interface type is bridge. + * mac: Media Access Control Address of the VM interface. + * model: model of emulated network interface card. It will be one of these models: + ne2k_pci, i82551, i82557b, i82559er, rtl8139, e1000, pcnet and virtio. + +* **DELETE**: detach the network interface from VM + +**Actions (POST):** + +*No actions defined* + + ### Resource: Template
**URI:** /templates/*:name*

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> get/attach/detach interface Signed-off-by: ShaoHe Feng <shaohef@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): + 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') + 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 -- 1.8.4.2

On 01/15/2014 07:53 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
get/attach/detach interface
List all network interfaces attached to a VM.
Signed-off-by: ShaoHe Feng <shaohef@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):
It will be "mac" instead "name", right?
+ 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') + 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

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> add VmIfaces collection and VmIface resource Update VM resource. Signed-off-by: ShaoHe Feng <shaohef@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@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): -- 1.8.4.2

Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com> On 01/15/2014 07:53 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
add VmIfaces collection and VmIface resource
Update VM resource.
Signed-off-by: ShaoHe Feng <shaohef@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@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):

this patch depend on <[PATCH] Add a control.vm module> On 01/15/2014 05:53 PM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
just support get interfaces missing mockmodel and testcase
ShaoHe Feng (3): VM supports interfaces: update API VM supports interfaces: update model VM supports interfaces: update controller
docs/API.md | 47 ++++++++++++++++++++++++++++++++++++++++ src/kimchi/control/vm/ifaces.py | 48 +++++++++++++++++++++++++++++++++++++++++ src/kimchi/control/vms.py | 9 ++++++++ src/kimchi/model.py | 31 ++++++++++++++++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 src/kimchi/control/vm/ifaces.py
-- Thanks and best regards! Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center

On 01/15/2014 11:59 AM, Sheldon wrote:
this patch depend on <[PATCH] Add a control.vm module>
Next time, send all patches in the same patch set
On 01/15/2014 05:53 PM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
just support get interfaces missing mockmodel and testcase
ShaoHe Feng (3): VM supports interfaces: update API VM supports interfaces: update model VM supports interfaces: update controller
docs/API.md | 47 ++++++++++++++++++++++++++++++++++++++++ src/kimchi/control/vm/ifaces.py | 48 +++++++++++++++++++++++++++++++++++++++++ src/kimchi/control/vms.py | 9 ++++++++ src/kimchi/model.py | 31 ++++++++++++++++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 src/kimchi/control/vm/ifaces.py

In addition to other comments, please add/update test cases for it. On 01/15/2014 07:53 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
just support get interfaces missing mockmodel and testcase
ShaoHe Feng (3): VM supports interfaces: update API VM supports interfaces: update model VM supports interfaces: update controller
docs/API.md | 47 ++++++++++++++++++++++++++++++++++++++++ src/kimchi/control/vm/ifaces.py | 48 +++++++++++++++++++++++++++++++++++++++++ src/kimchi/control/vms.py | 9 ++++++++ src/kimchi/model.py | 31 ++++++++++++++++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 src/kimchi/control/vm/ifaces.py
participants (3)
-
Aline Manera
-
shaohef@linux.vnet.ibm.com
-
Sheldon