Ejemplo n.º 1
0
 def test_port_exists_with_bad_port(self):
     port_id = uuidutils.generate_uuid()
     with mock.patch('octavia.common.utils.get_network_driver') as net_mock:
         net_mock.return_value.get_port = mock.Mock(
             side_effect=network_base.PortNotFound('Port not found'))
         self.assertRaises(exceptions.InvalidSubresource,
                           validate.port_exists, port_id)
Ejemplo n.º 2
0
 def apply_qos_on_port(self, qos_id, port_id):
     body = {'port': {'qos_policy_id': qos_id}}
     try:
         self.neutron_client.update_port(port_id, body)
     except neutron_client_exceptions.PortNotFoundClient as e:
         raise base.PortNotFound(str(e))
     except Exception as e:
         raise base.NetworkException(str(e))
Ejemplo n.º 3
0
 def _add_security_group_to_port(self, sec_grp_id, port_id):
     port_update = {'port': {'security_groups': [sec_grp_id]}}
     try:
         self.neutron_client.update_port(port_id, port_update)
     except neutron_client_exceptions.PortNotFoundClient as e:
         raise base.PortNotFound(str(e))
     except Exception as e:
         raise base.NetworkException(str(e))
Ejemplo n.º 4
0
 def _remove_security_group(self, port, sec_grp_id):
     port['security_groups'].remove(sec_grp_id)
     payload = {'port': {'security_groups': port['security_groups']}}
     try:
         self.neutron_client.update_port(port['id'], payload)
     except neutron_client_exceptions.PortNotFoundClient as e:
         raise base.PortNotFound(str(e))
     except Exception as e:
         raise base.NetworkException(str(e))
Ejemplo n.º 5
0
 def _add_vip_address_pair(self, port_id, vip_address):
     try:
         self._add_allowed_address_pair_to_port(port_id, vip_address)
     except neutron_client_exceptions.PortNotFoundClient as e:
         raise base.PortNotFound(str(e))
     except Exception:
         message = _('Error adding allowed address pair {ip} '
                     'to port {port_id}.').format(ip=vip_address,
                                                  port_id=port_id)
         LOG.exception(message)
         raise base.PlugVIPException(message)
Ejemplo n.º 6
0
 def _add_security_group_to_port(self, sec_grp_id, port_id):
     port = self.neutron_client.show_port(port_id)
     port['port']['security_groups'].append(sec_grp_id)
     sec_grp_list = port['port']['security_groups']
     payload = {'port': {'security_groups': sec_grp_list}}
     # Note: Neutron accepts the SG even if it already exists
     try:
         self.neutron_client.update_port(port_id, payload)
     except neutron_client_exceptions.PortNotFoundClient as e:
         raise base.PortNotFound(str(e))
     except Exception as e:
         raise base.NetworkException(str(e))
Ejemplo n.º 7
0
 def get_port(self, port_id):
     try:
         port = self.neutron_client.show_port(port_id)
         return utils.convert_port_dict_to_model(port)
     except neutron_client_exceptions.NotFound:
         message = _LE('Port not found '
                       '(port id: {port_id}.').format(port_id=port_id)
         LOG.exception(message)
         raise base.PortNotFound(message)
     except Exception:
         message = _LE('Error retrieving port '
                       '(port id: {port_id}.').format(port_id=port_id)
         LOG.exception(message)
         raise base.NetworkException(message)
Ejemplo n.º 8
0
    def set_port_admin_state_up(self, port_id, state):
        """Set the admin state of a port. True is up, False is down.

        :param port_id: The port ID to update.
        :param state: True for up, False for down.
        :returns: None
        """
        try:
            self.neutron_client.update_port(
                port_id, {constants.PORT: {
                    constants.ADMIN_STATE_UP: state
                }})
        except (neutron_client_exceptions.NotFound,
                neutron_client_exceptions.PortNotFoundClient) as e:
            raise base.PortNotFound(str(e))
        except Exception as e:
            raise exceptions.NetworkServiceError(net_error=str(e))
Ejemplo n.º 9
0
    def failover_preparation(self, amphora):
        interfaces = self.get_plugged_networks(compute_id=amphora.compute_id)

        ports = []
        for interface_ in interfaces:
            port = self.get_port(port_id=interface_.port_id)
            ips = port.fixed_ips
            lb_network = False
            for ip in ips:
                if ip.ip_address == amphora.lb_network_ip:
                    lb_network = True
            if not lb_network:
                ports.append(port)

        for port in ports:
            try:
                self.neutron_client.update_port(port.id,
                                                {'port': {'device_id': ''}})
            except (neutron_client_exceptions.NotFound,
                    neutron_client_exceptions.PortNotFoundClient):
                raise base.PortNotFound()