[Kimchi-devel] [PATCH 2/4] vmiface update support: update model.

shaohef at linux.vnet.ibm.com shaohef at linux.vnet.ibm.com
Fri Apr 18 12:46:58 UTC 2014


From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>

For network source, change will be on the active VM instance and
persisted VM configuration.

For model, change will be on the active VM instance only

Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
 src/kimchi/control/vm/ifaces.py |  1 +
 src/kimchi/model/vmifaces.py    | 22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/src/kimchi/control/vm/ifaces.py b/src/kimchi/control/vm/ifaces.py
index 874ef54..1b5dc36 100644
--- a/src/kimchi/control/vm/ifaces.py
+++ b/src/kimchi/control/vm/ifaces.py
@@ -34,6 +34,7 @@ class VMIfaces(Collection):
 class VMIface(Resource):
     def __init__(self, model, vm, ident):
         super(VMIface, self).__init__(model, ident)
+        self.update_params = ["model", "network"]
         self.vm = vm
         self.ident = ident
         self.info = {}
diff --git a/src/kimchi/model/vmifaces.py b/src/kimchi/model/vmifaces.py
index 9bf110e..8a28358 100644
--- a/src/kimchi/model/vmifaces.py
+++ b/src/kimchi/model/vmifaces.py
@@ -129,3 +129,25 @@ class VMIfaceModel(object):
 
         dom.detachDeviceFlags(etree.tostring(iface),
                               libvirt.VIR_DOMAIN_AFFECT_CURRENT)
+
+    def update(self, vm, mac, params):
+        dom = VMModel.get_vm(vm, self.conn)
+        iface = self._get_vmiface(vm, mac)
+
+        if iface is None:
+            raise NotFoundError("KCHVMIF0001E", {'name': vm, 'iface': mac})
+
+        # change on the active VM instance and persisted VM configuration.
+        if iface.attrib['type'] == 'network' and 'network' in params:
+            iface.source.attrib['network'] = params['network']
+            xml = etree.tostring(iface)
+            dom.updateDeviceFlags(xml, flags=libvirt.VIR_DOMAIN_AFFECT_CONFIG +
+                                  libvirt.VIR_DOMAIN_AFFECT_CURRENT)
+
+        # change on the persisted VM configuration only.
+        if 'model' in params and dom.isPersistent():
+            iface.model.attrib["type"] = params['model']
+            xml = etree.tostring(iface)
+            dom.updateDeviceFlags(xml, flags=libvirt.VIR_DOMAIN_AFFECT_CONFIG)
+
+        return mac
-- 
1.9.0




More information about the Kimchi-devel mailing list