Beispiel #1
0
    def plug_port(self, amphora, port):
        try:
            interface = self.nova_client.servers.interface_attach(
                server=amphora.compute_id,
                net_id=None,
                fixed_ip=None,
                port_id=port.id)
            plugged_interface = self._nova_interface_to_octavia_interface(
                amphora.compute_id, interface)
        except nova_client_exceptions.NotFound as e:
            if 'Instance' in str(e):
                raise base.AmphoraNotFound(str(e))
            elif 'Network' in str(e):
                raise base.NetworkNotFound(str(e))
            else:
                raise base.PlugNetworkException(str(e))
        except nova_client_exceptions.Conflict:
            LOG.info('Port %(portid)s is already plugged, '
                     'skipping', {'portid': port.id})
            plugged_interface = n_data_models.Interface(
                compute_id=amphora.compute_id,
                network_id=port.network_id,
                port_id=port.id,
                fixed_ips=port.fixed_ips)
        except Exception:
            message = _('Error plugging amphora (compute_id: '
                        '{compute_id}) into port '
                        '{port_id}.').format(compute_id=amphora.compute_id,
                                             port_id=port.id)
            LOG.exception(message)
            raise base.PlugNetworkException(message)

        return plugged_interface
    def unplug_network(self, compute_id, network_id, ip_address=None):
        interfaces = self.get_plugged_networks(compute_id)
        if not interfaces:
            msg = ('Amphora with compute id {compute_id} does not have any '
                   'plugged networks').format(compute_id=compute_id)
            raise base.AmphoraNotFound(msg)

        unpluggers = self._get_interfaces_to_unplug(interfaces,
                                                    network_id,
                                                    ip_address=ip_address)
        try:
            for index, unplugger in enumerate(unpluggers):
                self.nova_client.servers.interface_detach(
                    server=compute_id, port_id=unplugger.port_id)
        except Exception:
            message = _('Error unplugging amphora {amphora_id} from network '
                        '{network_id}.').format(amphora_id=compute_id,
                                                network_id=network_id)
            if len(unpluggers) > 1:
                message = _('{base} Other interfaces have been successfully '
                            'unplugged: ').format(base=message)
                unpluggeds = unpluggers[:index]
                for unplugged in unpluggeds:
                    message = _('{base} neutron port '
                                '{port_id} ').format(base=message,
                                                     port_id=unplugged.port_id)
            else:
                message = _('{base} No other networks were '
                            'unplugged.').format(base=message)
            LOG.exception(message)
            raise base.UnplugNetworkException(message)
Beispiel #3
0
 def plug_port(self, amphora, port):
     try:
         self.nova_client.servers.interface_attach(
             server=amphora.compute_id,
             net_id=None,
             fixed_ip=None,
             port_id=port.id)
     except nova_client_exceptions.NotFound as e:
         if 'Instance' in e.message:
             raise base.AmphoraNotFound(e.message)
         elif 'Network' in e.message:
             raise base.NetworkNotFound(e.message)
         else:
             raise base.PlugNetworkException(e.message)
     except nova_client_exceptions.Conflict:
         LOG.info(
             _LI('Port %(portid)s is already plugged, '
                 'skipping') % {'portid': port.id})
     except Exception:
         message = _LE('Error plugging amphora (compute_id: '
                       '{compute_id}) into port '
                       '{port_id}.').format(compute_id=amphora.compute_id,
                                            port_id=port.id)
         LOG.exception(message)
         raise base.PlugNetworkException(message)
Beispiel #4
0
    def plug_network(self, compute_id, network_id, ip_address=None):
        try:
            interface = self.compute.attach_network_or_port(
                compute_id=compute_id,
                network_id=network_id,
                ip_address=ip_address)
        except exceptions.NotFound as e:
            if 'Instance' in str(e):
                raise base.AmphoraNotFound(str(e))
            if 'Network' in str(e):
                raise base.NetworkNotFound(str(e))
            raise base.PlugNetworkException(str(e))
        except Exception as e:
            message = _('Error plugging amphora (compute_id: {compute_id}) '
                        'into network {network_id}.').format(
                            compute_id=compute_id, network_id=network_id)
            LOG.exception(message)
            raise base.PlugNetworkException(message) from e

        return self._nova_interface_to_octavia_interface(compute_id, interface)
    def plug_network(self, compute_id, network_id, ip_address=None):
        try:
            interface = self.nova_client.servers.interface_attach(
                server=compute_id, net_id=network_id, fixed_ip=ip_address,
                port_id=None)
        except nova_client_exceptions.NotFound as e:
            if 'Instance' in e.message:
                raise base.AmphoraNotFound(e.message)
            elif 'Network' in e.message:
                raise base.NetworkNotFound(e.message)
            else:
                raise base.PlugNetworkException(e.message)
        except Exception:
            message = _('Error plugging amphora (compute_id: {compute_id}) '
                        'into network {network_id}.').format(
                            compute_id=compute_id,
                            network_id=network_id)
            LOG.exception(message)
            raise base.PlugNetworkException(message)

        return self._nova_interface_to_octavia_interface(compute_id, interface)