def unplug_aap_port_revert(self, vip, amphora, subnet):
        interface = self._get_plugged_interface(amphora.compute_id,
                                                subnet.network_id,
                                                amphora.lb_network_ip)
        if not interface:
            # Thought about raising PluggedVIPNotFound exception but
            # then that wouldn't evaluate all amphorae, so just continue
            LOG.debug('Cannot get amphora %s interface, skipped',
                      amphora.compute_id)
            return
        try:
            self._remove_allowed_address_pair_from_port(
                interface.port_id, vip.ip_address)
        except Exception:
            message = _('Error unplugging VIP. Could not clear '
                        'allowed address pairs from port '
                        '{port_id}.').format(port_id=vip.port_id)
            LOG.exception(message)
            raise base.UnplugVIPException(message)

        # Delete the VRRP port if we created it
        try:
            port = self.get_port(amphora.vrrp_port_id)
            if port.name.startswith('octavia-lb-vrrp-'):
                self.neutron_client.delete_port(amphora.vrrp_port_id)
        except (neutron_client_exceptions.NotFound,
                neutron_client_exceptions.PortNotFoundClient):
            pass
        except Exception as e:
            LOG.error(
                'Failed to delete port.  Resources may still be in '
                'use for port: %(port)s due to error: %(except)s', {
                    constants.PORT: amphora.vrrp_port_id,
                    'except': str(e)
                })
Exemple #2
0
 def unplug_vip(self, load_balancer, vip):
     try:
         subnet = self.get_subnet(vip.subnet_id)
     except base.SubnetNotFound:
         msg = ("Can't unplug vip because vip subnet {0} was not "
                "found").format(vip.subnet_id)
         raise base.PluggedVIPNotFound(msg)
     for amphora in load_balancer.amphorae:
         interface = self._get_plugged_interface(amphora.compute_id,
                                                 subnet.network_id)
         if not interface:
             # Thought about raising PluggedVIPNotFound exception but
             # then that wouldn't evaluate all amphorae, so just continue
             continue
         try:
             self.unplug_network(amphora.compute_id, subnet.network_id)
         except Exception:
             pass
         try:
             aap_update = {'port': {'allowed_address_pairs': []}}
             self.neutron_client.update_port(interface.port_id, aap_update)
         except Exception:
             message = _LE('Error unplugging VIP. Could not clear '
                           'allowed address pairs from port '
                           '{port_id}.').format(port_id=vip.port_id)
             LOG.exception(message)
             raise base.UnplugVIPException(message)
    def unplug_vip(self, load_balancer, vip):
        if load_balancer.topology == constants.TOPOLOGY_ACTIVE_ACTIVE:
            self._unplug_frontend_port(load_balancer)

        try:
            subnet = self.get_subnet(vip.subnet_id)
        except base.SubnetNotFound:
            msg = ("Can't unplug vip because vip subnet {0} was not "
                   "found").format(vip.subnet_id)
            LOG.exception(msg)
            raise base.PluggedVIPNotFound(msg)
        for amphora in six.moves.filter(
            lambda amp: amp.status == constants.AMPHORA_ALLOCATED,
                load_balancer.amphorae):

            interface = self._get_plugged_interface(
                amphora.compute_id, subnet.network_id, amphora.lb_network_ip)
            if not interface:
                # Thought about raising PluggedVIPNotFound exception but
                # then that wouldn't evaluate all amphorae, so just continue
                LOG.debug('Cannot get amphora %s interface, skipped',
                          amphora.compute_id)
                continue
            try:
                self.unplug_network(amphora.compute_id, subnet.network_id)
            except Exception:
                pass
            try:
                aap_update = {'port': {
                    'allowed_address_pairs': []
                }}
                self.neutron_client.update_port(interface.port_id,
                                                aap_update)
            except Exception:
                message = _('Error unplugging VIP. Could not clear '
                            'allowed address pairs from port '
                            '{port_id}.').format(port_id=vip.port_id)
                LOG.exception(message)
                raise base.UnplugVIPException(message)

            # Delete the VRRP port if we created it
            try:
                port = self.get_port(amphora.vrrp_port_id)
                if port.name.startswith('octavia-lb-vrrp-'):
                    self.neutron_client.delete_port(amphora.vrrp_port_id)
            except (neutron_client_exceptions.NotFound,
                    neutron_client_exceptions.PortNotFoundClient):
                pass
            except Exception as e:
                LOG.error('Failed to delete port.  Resources may still be in '
                          'use for port: %(port)s due to error: %s(except)s',
                          {'port': amphora.vrrp_port_id, 'except': e})
    def _unplug_amphora_frontend_port(self, amphora, load_balancer):

        try:
            frontend_subnet = load_balancer.distributor.frontend_subnet
            subnet = self.get_subnet(frontend_subnet)
        except base.SubnetNotFound:
            msg = ("Can't unplug frontend ip because frontend subnet {0} "
                   "was not found").format(frontend_subnet)
            LOG.exception(msg)
            raise base.PluggedVIPNotFound(msg)

        if (amphora in load_balancer.amphorae and
                amphora.status == constants.AMPHORA_ALLOCATED):
            interface = self._get_plugged_interface(
                amphora.compute_id, subnet.network_id, amphora.lb_network_ip)
            if not interface:
                # Thought about raising PluggedVIPNotFound exception but
                # then that wouldn't evaluate all amphorae, so just continue
                LOG.debug('Cannot get amphora %s interface, skipped',
                          amphora.compute_id)
                return
            try:
                self.unplug_network(amphora.compute_id, subnet.network_id)
            except Exception:
                pass
            try:
                aap_update = {'port': {
                    'allowed_address_pairs': []
                }}
                self.neutron_client.update_port(interface.port_id,
                                                aap_update)
            except Exception:
                message = _('Error unplugging frontend port. Could not clear '
                            'allowed address pairs from port '
                            '{port_id}.').format(port_id=interface.port_id)
                LOG.exception(message)
                raise base.UnplugVIPException(message)

            # Delete the frontend port if we created it
            try:
                port = self.get_port(amphora.frontend_port_id)
                if port.name.startswith('octavia-lb-frentend-'):
                    self.neutron_client.delete_port(amphora.frontend_port_id)
            except (neutron_client_exceptions.NotFound,
                    neutron_client_exceptions.PortNotFoundClient):
                pass
            except Exception as e:
                LOG.error('Failed to delete port.  Resources may still be in '
                          'use for port: %(port)s due to error: %s(except)s',
                          {'port': amphora.frontend_port_id, 'except': e})