
From: ShaoHe Feng <shaohef@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@linux.vnet.ibm.com> --- src/kimchi/control/vm/ifaces.py | 1 + src/kimchi/model/vmifaces.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 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..e745114 100644 --- a/src/kimchi/model/vmifaces.py +++ b/src/kimchi/model/vmifaces.py @@ -129,3 +129,28 @@ 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) + conf_flag = (libvirt.VIR_DOMAIN_AFFECT_CONFIG + + libvirt.VIR_DOMAIN_AFFECT_LIVE if dom.isActive() and + dom.isPersistent() else + libvirt.VIR_DOMAIN_AFFECT_CURRENT) + dom.updateDeviceFlags(xml, flags=conf_flag) + + # 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