def plug(self, instance, vif): vif_type = vif.get('type') if vif_type != VIF_TYPE_HOSTDEV: self.libvirt_gen_drv.plug(instance, vif) else: try: LOG.debug(_("vif_type=%s"), vif_type) network = vif['network'] vnic_mac = vif['address'] device_id = instance['uuid'] dev_name = None dev = None fabric = network['meta'].get('physical_network') if fabric: dev = utils.execute('ebrctl', 'add-port', vnic_mac, device_id, fabric, vif_type, dev_name, run_as_root=True) if dev: return else: error_msg = "Cannot plug VIF with no allocated device" else: error_msg = "Cannot plug VIF. Fabric is expected" LOG.warning(_(error_msg)) except Exception: LOG.exception(_("Processing Failure during vNIC plug"))
def get_config(self, instance, vif, image_meta, inst_type): vif_type = vif.get('type') if vif_type != VIF_TYPE_HOSTDEV: conf = self.libvirt_gen_drv.get_config(instance, vif, image_meta, inst_type) else: LOG.debug(_("vif_type=%s"), vif_type) dev_name = None dev = None device_id = instance['uuid'] vnic_mac = vif['address'] network = vif['network'] fabric = network['meta'].get('physical_network') try: if fabric: res = utils.execute('ebrctl', 'allocate-port', vnic_mac, device_id, fabric, vif_type, run_as_root=True) dev = res[0].strip() else: LOG.warning(_("Fabric is expected.Got None.")) except processutils.ProcessExecutionError: LOG.exception(_("Failed while config vif"), instance=instance) raise exception.NovaException(_("Processing Failure during " "vNIC allocation")) #Allocation Failed if dev is None: raise exception.NovaException(_("Failed to allocate " "device for vNIC")) conf = self.get_dev_config(vnic_mac, dev) return conf
def unplug(self, instance, vif): vif_type = vif.get('type') if vif_type != VIF_TYPE_HOSTDEV: self.libvirt_gen_drv.unplug(instance, vif) else: try: LOG.debug(_("vif_type=%s"), vif_type) network = vif['network'] vnic_mac = vif['address'] fabric = network['meta'].get('physical_network') if fabric: utils.execute('ebrctl', 'del-port', fabric, vnic_mac, run_as_root=True) else: LOG.warning(_("Cannot unplug VIF. Fabric is expected")) except Exception: LOG.exception(_("Failed while unplugging vif"))
def unplug(self, instance, vif): vif_type = vif.get('type') if vif_type != VIF_TYPE_HOSTDEV: self.libvirt_gen_drv.unplug(instance, vif) else: LOG.debug(_("vif_type=%s"), vif_type) network = vif['network'] vnic_mac = vif['address'] fabric = vif.get_physical_network() if not fabric: raise exception.NetworkMissingPhysicalNetwork( network_uuid=vif['network']['id']) try: utils.execute('ebrctl', 'del-port', fabric, vnic_mac, run_as_root=True) except Exception: LOG.exception(_("Failed while unplugging vif"))