def attach_interface(self, instance, image_meta, vif):
    virt_dom = self._lookup_by_name(instance['name'])
    flavor = objects.Flavor.get_by_id(nova_context.get_admin_context(read_deleted='yes'), instance['instance_type_id'])
    self.vif_driver.plug(instance, vif)
    self.firewall_driver.setup_basic_filtering(instance, [vif])
    cfg = self.vif_driver.get_config(instance, vif, image_meta, flavor, CONF.libvirt.virt_type)
    try:
        flags = libvirt.VIR_DOMAIN_AFFECT_CONFIG
        state = LIBVIRT_POWER_STATE[virt_dom.info()[0]]
        if ((state == power_state.RUNNING) or (state == power_state.PAUSED)):
            flags |= libvirt.VIR_DOMAIN_AFFECT_LIVE
        virt_dom.attachDeviceFlags(cfg.to_xml(), flags)
    except libvirt.libvirtError:
        LOG.error(_LE('attaching network adapter failed.'), instance=instance)
        self.vif_driver.unplug(instance, vif)
        raise exception.InterfaceAttachFailed(instance_uuid=instance['uuid'])
def attach_interface(self, instance, image_meta, vif):
    virt_dom = self._lookup_by_name(instance['name'])
    flavor = objects.Flavor.get_by_id(nova_context.get_admin_context(read_deleted='yes'), instance['instance_type_id'])
    self.vif_driver.plug(instance, vif)
    self.firewall_driver.setup_basic_filtering(instance, [vif])
    cfg = self.vif_driver.get_config(instance, vif, image_meta, flavor, CONF.libvirt.virt_type)
    try:
        flags = libvirt.VIR_DOMAIN_AFFECT_CONFIG
        state = LIBVIRT_POWER_STATE[virt_dom.info()[0]]
        if ((state == power_state.RUNNING) or (state == power_state.PAUSED)):
            flags |= libvirt.VIR_DOMAIN_AFFECT_LIVE
        virt_dom.attachDeviceFlags(cfg.to_xml(), flags)
    except libvirt.libvirtError:
        LOG.error(_LE('attaching network adapter failed.'), instance=instance)
        self.vif_driver.unplug(instance, vif)
        raise exception.InterfaceAttachFailed(instance_uuid=instance['uuid'])