示例#1
0
    def create_network(self, context, network):
        (network_type, physical_network,
         vlan_id) = self._process_provider_create(context, network['network'])
        session = context.session
        with session.begin(subtransactions=True):
            if not network_type:
                # tenant network
                network_type = self.tenant_network_type
                if network_type == constants.TYPE_NONE:
                    raise q_exc.TenantNetworksDisabled()
                elif network_type in [constants.TYPE_VLAN, constants.TYPE_IB]:
                    physical_network, vlan_id = db.reserve_network(session)
                else:  # TYPE_LOCAL
                    vlan_id = constants.LOCAL_VLAN_ID
            else:
                # provider network
                if network_type in [
                        constants.TYPE_VLAN, constants.TYPE_IB,
                        constants.TYPE_FLAT
                ]:
                    db.reserve_specific_network(session, physical_network,
                                                vlan_id)
            net = super(MellanoxEswitchPlugin,
                        self).create_network(context, network)
            db.add_network_binding(session, net['id'], network_type,
                                   physical_network, vlan_id)

            self._process_l3_create(context, net, network['network'])
            self._extend_network_dict_provider(context, net)
            # note - exception will rollback entire transaction
            LOG.debug(_("Created network: %s"), net['id'])
            return net
示例#2
0
    def create_network(self, context, network):
        (network_type, physical_network,
         vlan_id) = self._process_provider_create(context,
                                                  network['network'])

        session = context.session
        with session.begin(subtransactions=True):
            #set up default security groups
            tenant_id = self._get_tenant_id_for_create(
                context, network['network'])
            self._ensure_default_security_group(context, tenant_id)

            if not network_type:
                # tenant network
                network_type = self.tenant_network_type
                if network_type == constants.TYPE_NONE:
                    raise q_exc.TenantNetworksDisabled()
                elif network_type == constants.TYPE_VLAN:
                    physical_network, vlan_id = db.reserve_network(session)
                else:  # TYPE_LOCAL
                    vlan_id = constants.LOCAL_VLAN_ID
            else:
                # provider network
                if network_type in [constants.TYPE_VLAN, constants.TYPE_FLAT]:
                    db.reserve_specific_network(session, physical_network,
                                                vlan_id)
                # no reservation needed for TYPE_LOCAL
            net = super(LinuxBridgePluginV2, self).create_network(context,
                                                                  network)
            db.add_network_binding(session, net['id'],
                                   physical_network, vlan_id)
            self._process_l3_create(context, net, network['network'])
            self._extend_network_dict_provider(context, net)
            # note - exception will rollback entire transaction
        return net
示例#3
0
 def _project_read(self, project_id):
     """ Reads the project from the api server. The project will be
     created it does not yet exist.
     """
     for i in range(self._max_project_read_attempts):
         try:
             return self._api.project_read(id=str(uuid.UUID(project_id)))
         except NoIdError:
             pass
         greenthread.sleep(1)
     raise n_exc.TenantNetworksDisabled()
示例#4
0
    def _process_provider_create(self, context, session, attrs):
        network_type = attrs.get(provider.NETWORK_TYPE)
        network_type_set = attributes.is_attr_set(network_type)
        if not network_type_set:
            if self._tenant_network_type == svc_constants.TYPE_NONE:
                raise n_exc.TenantNetworksDisabled()
            network_type = self._tenant_network_type
            attrs[provider.NETWORK_TYPE] = network_type

        if network_type not in self._network_providers_map:
            msg = _("Network type %s not supported") % network_type
            raise n_exc.InvalidInput(error_message=msg)
        p = self._network_providers_map[network_type]
        # Provider specific network creation
        p.create_network(session, attrs)
示例#5
0
    def create_network(self, context, network):
        (network_type, physical_network,
         segmentation_id) = self._process_provider_create(context,
                                                          network['network'])

        session = context.session
        #set up default security groups
        tenant_id = self._get_tenant_id_for_create(
            context, network['network'])
        self._ensure_default_security_group(context, tenant_id)

        with session.begin(subtransactions=True):
            if not network_type:
                # tenant network
                network_type = self.tenant_network_type
                if network_type == svc_constants.TYPE_NONE:
                    raise q_exc.TenantNetworksDisabled()
                elif network_type == svc_constants.TYPE_VLAN:
                    (physical_network,
                     segmentation_id) = ovs_db_v2.reserve_vlan(session)
                elif network_type in constants.TUNNEL_NETWORK_TYPES:
                    segmentation_id = ovs_db_v2.reserve_tunnel(session)
                # no reservation needed for TYPE_LOCAL
            else:
                # provider network
                if network_type in [svc_constants.TYPE_VLAN,
                                    svc_constants.TYPE_FLAT]:
                    ovs_db_v2.reserve_specific_vlan(session, physical_network,
                                                    segmentation_id)
                elif network_type in constants.TUNNEL_NETWORK_TYPES:
                    ovs_db_v2.reserve_specific_tunnel(session, segmentation_id)
                # no reservation needed for TYPE_LOCAL
            net = super(OVSNeutronPluginV2, self).create_network(context,
                                                                 network)
            binding = ovs_db_v2.add_network_binding(session, net['id'],
                                                    network_type,
                                                    physical_network,
                                                    segmentation_id)

            self._process_l3_create(context, net, network['network'])
            # passing None as db model to use binding object
            self._extend_network_dict_provider_ovs(net, None, binding)
            # note - exception will rollback entire transaction
        LOG.debug(_("Created network: %s"), net['id'])
        return net
示例#6
0
    def create_network(self, context, network):
        """
        Create network based on network profile.

        :param context: neutron api request context
        :param network: network dictionary
        :returns: network object
        """
        (network_type, physical_network,
         segmentation_id) = self._process_provider_create(
             context, network['network'])
        self._add_dummy_profile_only_if_testing(network)
        profile_id = self._process_network_profile(context, network['network'])
        LOG.debug(_('create network: profile_id=%s'), profile_id)
        session = context.session
        with session.begin(subtransactions=True):
            if not network_type:
                # tenant network
                (physical_network, network_type, segmentation_id,
                 multicast_ip) = n1kv_db_v2.alloc_network(session, profile_id)
                LOG.debug(
                    _('Physical_network %(phy_net)s, '
                      'seg_type %(net_type)s, '
                      'seg_id %(seg_id)s, '
                      'multicast_ip %(multicast_ip)s'), {
                          'phy_net': physical_network,
                          'net_type': network_type,
                          'seg_id': segmentation_id,
                          'multicast_ip': multicast_ip
                      })
                if not segmentation_id:
                    raise q_exc.TenantNetworksDisabled()
            else:
                # provider network
                if network_type == c_const.NETWORK_TYPE_VLAN:
                    network_profile = self.get_network_profile(
                        context, profile_id)
                    seg_min, seg_max = self._get_segment_range(
                        network_profile['segment_range'])
                    if not seg_min <= segmentation_id <= seg_max:
                        raise cisco_exceptions.VlanIDOutsidePool
                    n1kv_db_v2.reserve_specific_vlan(session, physical_network,
                                                     segmentation_id)
                    multicast_ip = "0.0.0.0"
            net = super(N1kvNeutronPluginV2,
                        self).create_network(context, network)
            n1kv_db_v2.add_network_binding(session, net['id'], network_type,
                                           physical_network, segmentation_id,
                                           multicast_ip, profile_id)
            self._process_l3_create(context, net, network['network'])
            self._extend_network_dict_provider(context, net)
            self._extend_network_dict_profile(context, net)

        try:
            self._send_create_network_request(context, net)
        except (cisco_exceptions.VSMError,
                cisco_exceptions.VSMConnectionFailed):
            super(N1kvNeutronPluginV2, self).delete_network(context, net['id'])
        else:
            # note - exception will rollback entire transaction
            LOG.debug(_("Created network: %s"), net['id'])
            return net