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
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