From: ShaoHe Feng <shaohef(a)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(a)linux.vnet.ibm.com>
---
src/kimchi/control/vm/ifaces.py | 1 +
src/kimchi/model/vmifaces.py | 21 +++++++++++++++++++++
2 files changed, 22 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..e377477 100644
--- a/src/kimchi/model/vmifaces.py
+++ b/src/kimchi/model/vmifaces.py
@@ -129,3 +129,24 @@ 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})
+
+ # FIXME we will support to change the live VM configuration later.
+ 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)
+
+ # 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