def detach_interface(self, instance, 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'])
    cfg = self.vif_driver.get_config(instance, vif, None, flavor, CONF.libvirt.virt_type)
    try:
        self.vif_driver.unplug(instance, vif)
        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.detachDeviceFlags(cfg.to_xml(), flags)
    except libvirt.libvirtError as ex:
        error_code = ex.get_error_code()
        if (error_code == libvirt.VIR_ERR_NO_DOMAIN):
            LOG.warn(_LW('During detach_interface, instance disappeared.'), instance=instance)
        else:
            LOG.error(_LE('detaching network adapter failed.'), instance=instance)
            raise exception.InterfaceDetachFailed(instance_uuid=instance['uuid'])
def detach_interface(self, instance, 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'])
    cfg = self.vif_driver.get_config(instance, vif, None, flavor, CONF.libvirt.virt_type)
    try:
        self.vif_driver.unplug(instance, vif)
        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.detachDeviceFlags(cfg.to_xml(), flags)
    except libvirt.libvirtError as ex:
        error_code = ex.get_error_code()
        if (error_code == libvirt.VIR_ERR_NO_DOMAIN):
            LOG.warn(_LW('During detach_interface, instance disappeared.'), instance=instance)
        else:
            LOG.error(_LE('detaching network adapter failed.'), instance=instance)
            raise exception.InterfaceDetachFailed(instance_uuid=instance['uuid'])