Antoni Segura Puimedon has uploaded a new change for review. Change subject: [WIP] netwiring: [3/3] Add API definitions. ......................................................................
[WIP] netwiring: [3/3] Add API definitions. Third and final of the Network Wiring feature patches. It adds the implementation for using the new updateVmDevice feature. TODO: Add vdsm startup creation of the DUMMY_BRIDGE. TODO: Add the port mirroring processing. Change-Id: I3b9b4f49f80466a83e3e13f1042ac2a8866c6bcd Signed-off-by: Antoni S. Puimedon <[email protected]> --- M vdsm/API.py M vdsm/define.py M vdsm/libvirtvm.py 3 files changed, 103 insertions(+), 1 deletion(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/62/9562/1 diff --git a/vdsm/API.py b/vdsm/API.py index e87b7e5..966a921 100644 --- a/vdsm/API.py +++ b/vdsm/API.py @@ -353,6 +353,17 @@ response['status']['message'] = 'Hibernation process starting' return response + def updateVmDevice(self, params): + if 'type' not in params: + self.log.error('Missing a required parameters: type') + return {'status': {'code': errCode['MissParam']['status']['code'], + 'message': 'Missing one of required ' + 'parameters: type'}} + v = self._cif.vmContainer.get(self._UUID) + if not v: + return errCode['noVM'] + return v.updateDevice(params) + def hotplugNic(self, params): try: utils.validateMinimalKeySet(params, ('vmId', 'nic')) diff --git a/vdsm/define.py b/vdsm/define.py index 11a6ef6..e2ba196 100644 --- a/vdsm/define.py +++ b/vdsm/define.py @@ -124,6 +124,9 @@ 'replicaErr': {'status': {'code': 55, 'message': 'Drive replication error'}}, + 'updateDevice': {'status': + {'code': 56, + 'message': 'Failed to update device'}}, 'recovery': {'status': {'code': 99, 'message': @@ -137,3 +140,5 @@ #exitCodes ERROR = 1 NORMAL = 0 + +DUMMY_BRIDGE = 'none-br' diff --git a/vdsm/libvirtvm.py b/vdsm/libvirtvm.py index 3439dc3..3fdde03 100644 --- a/vdsm/libvirtvm.py +++ b/vdsm/libvirtvm.py @@ -25,7 +25,7 @@ import threading import vm -from vdsm.define import ERROR, doneCode, errCode +from vdsm.define import ERROR, doneCode, errCode, DUMMY_BRIDGE from vdsm import utils from vdsm import constants import guestIF @@ -1517,6 +1517,92 @@ return {'status': doneCode, 'vmList': self.status()} + def _updateNetDevice(self, params): + try: + utils.validateMinimalKeySet(params, ('alias', 'linkState')) + except ValueError: + self.log.error('Missing at least one of the required parameters: ' + 'alias, linkState') + return {'status': {'code': errCode['MissParam']['status']['code'], + 'message': 'Missing at least one of required ' + 'parameters: alias, linkState'}} + + dev = None + for dev in self.conf['devices']: + if (dev['type'] == vm.NIC_DEVICES and + dev['alias'] == params['alias']): + break + + if dev is None: + self.log.error('Network device %s cannot be updated. It does not' + 'exist', params['alias']) + return {'status': + {'code': errCode['updateDevice']['status']['code'], + 'message': 'Missing net device'}} + + network = dev['network'] + + # Prepare the updateDevice xml + netelem = xml.dom.minidom.Element(params['type']) + netelem.setAttribute('type', 'bridge') + mac = xml.dom.minidom.Element('mac') + mac.setAttribute('address', dev['macAddr']) + netelem.appendChild(mac) + model = xml.dom.minidom.Element('model') + model.setAttribute('type', dev['nicModel']) + netelem.appendChild(model) + + if 'network' not in params: + # If no network is specified we take the vnic to the dummy bridge + # and set the link 'down' always. + source = xml.dom.minidom.Element('source') + source.setAttribute('bridge', DUMMY_BRIDGE) + netelem.appendChild(source) + link = xml.dom.minidom.Element('link') + link.setAttribute('state', 'down') + netelem.appendChild(link) + else: + # There is a network defined. Thus, we either just modify the link + # status or move between network backends. + source = xml.dom.minidom.Element('source') + source.setAttribute('bridge', network) + netelem.appendChild(source) + link = xml.dom.minidom.Element('link') + if network != params['network']: + # If a different network is specified. First we take the link + # down and then update the device to connect to the new bridge. + link.setAttribute('state', 'down') + netelem.appendChild(link) + try: + self._dom.updateDeviceFlags( + netelem.toxml(), + libvirt.libvirt.VIR_DOMAIN_AFFECT_LIVE) + except: + self.log.debug("updateNetDevice failed", exc_info=True) + return {'status': + {'code': errCode['updateDevice']['status']['code'], + 'message': 'Failed to take the link down.'}} + + link.setAttribute('state', params['linkState']) + source.setAttribute('bridge', params['network']) + + try: + self._dom.updateDeviceFlags( + netelem.toxml(), + libvirt.libvirt.VIR_DOMAIN_AFFECT_LIVE) + except: + self.log.debug("updateNetDeviceFlags failed", exc_info=True) + return {'status': + {'code': errCode['updateDevice']['status']['code'], + 'message': 'Failed to take the link %s' % \ + link.getAttribute('state')}} + + def updateDevice(self, params): + if params['type'] == vm.NIC_DEVICES: + return self._updateNetDevice(params) + else: + return errCode['noimpl'] + def hotunplugNic(self, params): if self.isMigrating(): return errCode['migInProgress'] -- To view, visit http://gerrit.ovirt.org/9562 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3b9b4f49f80466a83e3e13f1042ac2a8866c6bcd Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Antoni Segura Puimedon <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
