Example #1
0
    def create_port(self, context, port):
        with context.session.begin(subtransactions=True):
            # First we allocate port in quantum database
            quantum_db = super(NvpPluginV2, self).create_port(context, port)
            # Update fields obtained from quantum db (eg: MAC address)
            port["port"].update(quantum_db)
            port_data = port['port']
            # Fetch the network and network binding from Quantum db
            network = self._get_network(context, port_data['network_id'])
            network_binding = nicira_db.get_network_binding(
                context.session, port_data['network_id'])
            max_ports = self.nvp_opts.max_lp_per_overlay_ls
            allow_extra_lswitches = False
            if (network_binding and
                network_binding.binding_type in (NetworkTypes.FLAT,
                                                 NetworkTypes.VLAN)):
                max_ports = self.nvp_opts.max_lp_per_bridged_ls
                allow_extra_lswitches = True
            try:
                q_net_id = port_data['network_id']
                cluster = self._find_target_cluster(port_data)
                selected_lswitch = self._handle_lswitch_selection(
                    cluster, network, network_binding, max_ports,
                    allow_extra_lswitches)
                lswitch_uuid = selected_lswitch['uuid']
                lport = nvplib.create_lport(cluster,
                                            lswitch_uuid,
                                            port_data['tenant_id'],
                                            port_data['id'],
                                            port_data['name'],
                                            port_data['device_id'],
                                            port_data['admin_state_up'],
                                            port_data['mac_address'],
                                            port_data['fixed_ips'])
                # Get NVP ls uuid for quantum network
                nvplib.plug_interface(cluster, selected_lswitch['uuid'],
                                      lport['uuid'], "VifAttachment",
                                      port_data['id'])
            except nvp_exc.NvpNoMorePortsException as e:
                LOG.error(_("Number of available ports for network %s "
                            "exhausted"), port_data['network_id'])
                raise e
            except Exception:
                # failed to create port in NVP delete port from quantum_db
                # FIXME (arosen) or the plugin_interface call failed in which
                # case we need to garbage collect the left over port in nvp.
                err_msg = _("An exception occured while plugging the interface"
                            " in NVP for port %s") % port_data['id']
                LOG.exception(err_msg)
                raise nvp_exc.NvpPluginException(err_desc=err_msg)

            LOG.debug(_("create_port completed on NVP for tenant "
                        "%(tenant_id)s: (%(id)s)"), port_data)

            return port_data
Example #2
0
 def _extend_network_dict_provider(self, context, network, binding=None):
     if self._check_provider_view_auth(context, network):
         if not binding:
             binding = nicira_db.get_network_binding(context.session,
                                                     network['id'])
         # With NVP plugin 'normal' overlay networks will have no binding
         # TODO(salvatore-orlando) make sure users can specify a distinct
         # tz_uuid as 'provider network' for STT net type
         if binding:
             network[pnet.NETWORK_TYPE] = binding.binding_type
             network[pnet.PHYSICAL_NETWORK] = binding.tz_uuid
             network[pnet.SEGMENTATION_ID] = binding.vlan_id
Example #3
0
    def create_port(self, context, port):
        """
        Creates a port on the specified Virtual Network.
        Returns:

        {"id": uuid represeting the port.
         "network_id": uuid of network.
         "tenant_id": tenant_id
         "mac_address": mac address to use on this port.
         "admin_state_up": Sets admin state of port. if down, port
                           does not forward packets.
         "status": dicates whether port is currently operational
                   (limit values to "ACTIVE", "DOWN", "BUILD", and "ERROR")
         "fixed_ips": list of subnet ID's and IP addresses to be used on
                      this port
         "device_id": identifies the device (e.g., virtual server) using
                      this port.
        }

        :raises: exception.NetworkNotFound
        :raises: exception.StateInvalid
        """
        tenant_id = self._get_tenant_id_for_create(context, port['port'])
        # Set admin_state_up False since not created in NVP set
        # TODO(salvatore-orlando) : verify whether subtransactions can help
        # us avoiding multiple operations on the db. This might also allow
        # us to use the same identifier for the NVP and the Quantum port
        # Set admin_state_up False since not created in NVP yet
        port["port"]["admin_state_up"] = False

        # First we allocate port in quantum database
        quantum_db = super(NvpPluginV2, self).create_port(context, port)

        # Update fields obtained from quantum db (eg: MAC address)
        port["port"].update(quantum_db)
        # We want port to be up in NVP
        port["port"]["admin_state_up"] = True
        port_data = port['port']
        # Fetch the network and network binding from Quantum db
        network = self._get_network(context, port_data['network_id'])
        network_binding = nicira_db.get_network_binding(
            context.session, port_data['network_id'])
        max_ports = self.nvp_opts.max_lp_per_overlay_ls
        allow_extra_lswitches = False
        if (network_binding and
            network_binding.binding_type in (NetworkTypes.FLAT,
                                             NetworkTypes.VLAN)):
            max_ports = self.nvp_opts.max_lp_per_bridged_ls
            allow_extra_lswitches = True
        try:
            q_net_id = port_data['network_id']
            cluster = self._find_target_cluster(port_data)
            selected_lswitch = self._handle_lswitch_selection(
                cluster, network, network_binding, max_ports,
                allow_extra_lswitches)
            lswitch_uuid = selected_lswitch['uuid']
            lport = nvplib.create_lport(cluster,
                                        lswitch_uuid,
                                        port_data['tenant_id'],
                                        port_data['id'],
                                        port_data['name'],
                                        port_data['device_id'],
                                        port_data['admin_state_up'],
                                        port_data['mac_address'],
                                        port_data['fixed_ips'])
            # Get NVP ls uuid for quantum network
            nvplib.plug_interface(cluster, selected_lswitch['uuid'],
                                  lport['uuid'], "VifAttachment",
                                  port_data['id'])
        except nvp_exc.NvpNoMorePortsException as e:
            LOG.error(_("Number of available ports for network %s exhausted"),
                      port_data['network_id'])
            super(NvpPluginV2, self).delete_port(context, port["port"]["id"])
            raise e
        except Exception:
            # failed to create port in NVP delete port from quantum_db
            err_msg = _("An exception occured while plugging the interface "
                        "in NVP for port %s") % port_data['id']
            LOG.exception(err_msg)
            super(NvpPluginV2, self).delete_port(context, port["port"]["id"])
            raise nvp_exc.NvpPluginException(err_desc=err_msg)

        LOG.debug(_("create_port completed on NVP for tenant %(tenant_id)s: "
                    "(%(id)s)") % port_data)

        # update port on Quantum DB with admin_state_up True
        port_update = {"port": {"admin_state_up": True}}
        return super(NvpPluginV2, self).update_port(context,
                                                    port["port"]["id"],
                                                    port_update)
Example #4
0
    def create_port(self, context, port):
        # If PORTSECURITY is not the default value ATTR_NOT_SPECIFIED
        # then we pass the port to the policy engine. The reason why we don't
        # pass the value to the policy engine when the port is
        # ATTR_NOT_SPECIFIED is for the case where a port is created on a
        # shared network that is not owned by the tenant.
        # TODO(arosen) fix policy engine to do this for us automatically.
        if attributes.is_attr_set(port['port'].get(psec.PORTSECURITY)):
            self._enforce_set_auth(context, port,
                                   self.port_security_enabled_create)
        port_data = port['port']
        with context.session.begin(subtransactions=True):
            # First we allocate port in quantum database
            quantum_db = super(NvpPluginV2, self).create_port(context, port)
            # Update fields obtained from quantum db (eg: MAC address)
            port["port"].update(quantum_db)

            # port security extension checks
            (port_security, has_ip) = self._determine_port_security_and_has_ip(
                context, port_data)
            port_data[psec.PORTSECURITY] = port_security
            self._process_port_security_create(context, port_data)
            # provider networking extension checks
            # Fetch the network and network binding from Quantum db
            network = self._get_network(context, port_data['network_id'])
            network_binding = nicira_db.get_network_binding(
                context.session, port_data['network_id'])
            max_ports = self.nvp_opts.max_lp_per_overlay_ls
            allow_extra_lswitches = False
            if (network_binding and
                network_binding.binding_type in (NetworkTypes.FLAT,
                                                 NetworkTypes.VLAN)):
                max_ports = self.nvp_opts.max_lp_per_bridged_ls
                allow_extra_lswitches = True
            try:
                q_net_id = port_data['network_id']
                cluster = self._find_target_cluster(port_data)
                selected_lswitch = self._handle_lswitch_selection(
                    cluster, network, network_binding, max_ports,
                    allow_extra_lswitches)
                lswitch_uuid = selected_lswitch['uuid']
                lport = nvplib.create_lport(cluster,
                                            lswitch_uuid,
                                            port_data['tenant_id'],
                                            port_data['id'],
                                            port_data['name'],
                                            port_data['device_id'],
                                            port_data['admin_state_up'],
                                            port_data['mac_address'],
                                            port_data['fixed_ips'],
                                            port_data[psec.PORTSECURITY])
                # Get NVP ls uuid for quantum network
                nvplib.plug_interface(cluster, selected_lswitch['uuid'],
                                      lport['uuid'], "VifAttachment",
                                      port_data['id'])
            except nvp_exc.NvpNoMorePortsException as e:
                LOG.error(_("Number of available ports for network %s "
                            "exhausted"), port_data['network_id'])
                raise e
            except Exception:
                # failed to create port in NVP delete port from quantum_db
                # FIXME (arosen) or the plugin_interface call failed in which
                # case we need to garbage collect the left over port in nvp.
                err_msg = _("An exception occured while plugging the interface"
                            " in NVP for port %s") % port_data['id']
                LOG.exception(err_msg)
                raise nvp_exc.NvpPluginException(err_desc=err_msg)

            LOG.debug(_("create_port completed on NVP for tenant "
                        "%(tenant_id)s: (%(id)s)"), port_data)

            self._extend_port_port_security_dict(context, port_data)
        return port_data