Exemplo n.º 1
0
    def plug_new(self, network_id, port_id, device_name, mac_address,
                 bridge=None, namespace=None, prefix=None, mtu=None):
        """This method is called by the Dhcp agent or by the L3 agent
        when a new network is created
        """
        ip = ip_lib.IPWrapper()
        tap_name = device_name.replace(prefix or n_const.TAP_DEVICE_PREFIX,
                                       n_const.TAP_DEVICE_PREFIX)

        # Create ns_dev in a namespace if one is configured.
        root_dev, ns_dev = ip.add_veth(tap_name, device_name,
                                       namespace2=namespace)
        root_dev.disable_ipv6()
        ns_dev.link.set_address(mac_address)

        mtu = self.conf.network_device_mtu or mtu
        if mtu:
            ns_dev.link.set_mtu(mtu)
            root_dev.link.set_mtu(mtu)
        else:
            LOG.warning(_LW("No MTU configured for port %s"), port_id)

        ns_dev.link.set_up()
        root_dev.link.set_up()

        cmd = ['mm-ctl', '--bind-port', port_id, device_name]
        utils.execute(cmd, run_as_root=True)
Exemplo n.º 2
0
 def _validate_network_type(self, context, network_id):
     our_types = [m_const.TYPE_MIDONET, m_const.TYPE_UPLINK]
     network = self._core_plugin.get_network(context, network_id)
     for seg in self._segments(network):
         if seg[pnet.NETWORK_TYPE] in our_types:
             return
     LOG.warning(_LW("Incompatible network %s"), network)
     raise n_exc.BadRequest(resource='router', msg='Incompatible network')
Exemplo n.º 3
0
 def _validate_network_type(self, context, network_id):
     our_types = [m_const.TYPE_MIDONET, m_const.TYPE_UPLINK]
     network = self._core_plugin.get_network(context, network_id)
     for seg in self._segments(network):
         if seg[pnet.NETWORK_TYPE] in our_types:
             return
     LOG.warning(_LW("Incompatible network %s"), network)
     raise n_exc.BadRequest(resource='router', msg='Incompatible network')
Exemplo n.º 4
0
    def delete_network(self, context, id):
        LOG.debug("MidonetMixin.delete_network called: id=%r", id)

        with context.session.begin(subtransactions=True):
            self._process_l3_delete(context, id)
            try:
                super(MidonetMixin, self).delete_network(context, id)
            except n_exc.NetworkInUse as ex:
                LOG.warning(_LW("Error deleting network %(net)s, retrying..."),
                            {'net': id})
                # Contention for DHCP port deletion and network deletion occur
                # often which leads to NetworkInUse error.  Retry to get
                # around this problem.
                raise oslo_db_exc.RetryRequest(ex)

            self.client.delete_network_precommit(context, id)

        self.client.delete_network_postcommit(id)

        LOG.debug("MidonetMixin.delete_network exiting: id=%r", id)
Exemplo n.º 5
0
    def delete_network(self, context, id):
        LOG.debug("MidonetPluginV2.delete_network called: id=%r", id)

        with context.session.begin(subtransactions=True):
            c_utils.check_delete_network_precommit(context, id)
            self._process_l3_delete(context, id)
            try:
                super(MidonetPluginV2, self).delete_network(context, id)
            except n_exc.NetworkInUse as ex:
                LOG.warning(_LW("Error deleting network %(net)s, retrying..."),
                            {'net': id})
                # Contention for DHCP port deletion and network deletion occur
                # often which leads to NetworkInUse error.  Retry to get
                # around this problem.
                raise oslo_db_exc.RetryRequest(ex)

            self.client.delete_network_precommit(context, id)

        self.client.delete_network_postcommit(id)

        LOG.debug("MidonetPluginV2.delete_network exiting: id=%r", id)
    def _process_provider_create(self, network):

        net_type = network.get(pnet.NETWORK_TYPE)
        if not attributes.is_attr_set(net_type):
            return None

        if net_type in _MIDONET_TYPES:
            # NOTE(yamamoto): Accept a few well-known types as
            # the default type.  This is a workaround for Horizon, which
            # currently doesn't have a way to specify MidoNet network types
            # or "no provider network".
            # REVISIT(yamamoto): Clean this up once Horizon is fixed
            if net_type != m_const.TYPE_MIDONET:
                LOG.warning(_LW('Unsupported network type %(type)s detected '
                                'in a create network request.'),
                            {'type': net_type})
            return None

        if net_type != m_const.TYPE_UPLINK:
            msg = _('Unsupported network type %(type)s detected '
                    'in a create network request.') % {'type': net_type}
            raise n_exc.InvalidInput(error_message=msg)

        return net_type