def _delete_port(self, context): """delete_port. This call makes the REST request to VSD for un provision VLAN/VPort for the gateway port where sriov instance is connected. """ port = context.current db_context = context._plugin_context LOG.debug("delete_port with port_id %(port_id)s", {'port_id': port['id']}) port_bindings = ext_db.get_switchport_binding_by_neutron_port( db_context, port['id']) if not port_bindings: return for binding in port_bindings: bindings = ext_db.get_switchport_bindings_by_switchport_vlan( db_context, binding['switchport_uuid'], binding['segmentation_id']) if len(bindings) == 1: vport = self.vsdclient.get_nuage_vport_by_id( binding['nuage_vport_id'], required=False) if not vport: LOG.debug("couldn't find a vport") else: LOG.debug("Deleting vport %(vport)s", {'vport': vport}) self.vsdclient.delete_nuage_gateway_vport_no_usergroup( port['tenant_id'], vport) if vport.get('VLANID'): LOG.debug("Deleting vlan %(vlan)s", {'vlan': vport['VLANID']}) self.vsdclient.delete_gateway_port_vlan( vport['VLANID']) ext_db.delete_switchport_binding(db_context, port['id'], binding['segmentation_id'])
def delete_port_precommit(self, context): port = context.current if (port.get(portbindings.VNIC_TYPE, portbindings.VNIC_NORMAL) not in self.supported_vnic_types): return db_context = context._plugin_context nuage_bindings = ext_db.get_switchport_binding_by_neutron_port( db_context, context.current['id']) context.nuage_bindings = nuage_bindings with db_context.session.begin(subtransactions=True): ext_db.delete_switchport_binding(db_context, context.current['id'])
def _create_bridgeport(self, context, bridge, segmentation_id): port = context.current ctx = context._plugin_context host = port[portbindings.HOST_ID] switch_mappings = ext_db.get_switchports_by_host_bridge( ctx, host, bridge) if not switch_mappings: msg = (_( "Failed to retrieve switchport mapping " "for host: %(host)s bridge: %(bridge)s", { 'host': host, 'bridge': bridge })) raise exceptions.NuageBadRequest(msg=msg) port_bindings = ext_db.get_switchport_binding_by_neutron_port( ctx, port['id'], segmentation_id) if port_bindings: LOG.info( "bridge port(s) %(pb)s for port %(port_id)s " "already exist", { 'pb': port_bindings, 'port_id': port['id'] }) return mappings, rg = self._get_redundancy(bridge, switch_mappings, ctx.tenant_id) for switchport in mappings: vports = ext_db.get_switchport_bindings_by_switchport_vlan( ctx, switchport['port_uuid'], segmentation_id) if len(vports) == 0: if rg: gw = self.vsdclient.get_gateway(ctx.tenant_id, rg) else: filters = {'system_id': [switchport['switch_id']]} gws = self.vsdclient.get_gateways(ctx.tenant_id, filters) if len(gws) == 0: msg = (_("No gateway found %s") % filters['system_id'][0]) raise exceptions.NuageBadRequest(msg=msg) gw = gws[0] params = { 'gatewayport': switchport.get('redundant_port_uuid') or switchport['port_uuid'], 'value': segmentation_id, 'redundant': rg is not None, 'personality': gw['gw_type'] } vlan = self.vsdclient.create_gateway_vlan(params) LOG.debug("created vlan: %(vlan_dict)s", {'vlan_dict': vlan}) subnet_mapping = self._get_subnet_mapping( context._plugin_context, port) subnet = context._plugin.get_subnet( context._plugin_context, subnet_mapping['subnet_id']) params = { 'gatewayinterface': vlan['ID'], 'np_id': subnet_mapping['net_partition_id'], 'tenant': port['tenant_id'], 'subnet': subnet, 'enable_dhcp': subnet['enable_dhcp'], 'nuage_managed_subnet': subnet_mapping['nuage_managed_subnet'], 'port_security_enabled': False, 'personality': gw['gw_type'], 'type': p_const.BRIDGE_VPORT_TYPE } vsd_subnet = self.vsdclient.get_nuage_subnet_by_id( subnet_mapping['nuage_subnet_id']) params['vsd_subnet'] = vsd_subnet # policy groups are not supported on netconf # managed gateways create_policy = 'NETCONF' not in gw['gw_type'] vport = self.vsdclient.create_gateway_vport_no_usergroup( ctx.tenant_id, params, create_policy_group=create_policy) LOG.debug("created vport: %(vport_dict)s", {'vport_dict': vport}) bridge_port_id = vport.get('vport').get('ID') else: bridge_port_id = vports[0]['nuage_vport_id'] binding = { 'neutron_port_id': port.get('id'), 'nuage_vport_id': bridge_port_id, 'switchport_uuid': switchport['port_uuid'], 'segmentation_id': segmentation_id, 'switchport_mapping_id': switchport['id'] } ext_db.add_switchport_binding(ctx, binding)
def update_port_precommit(self, context): nuage_bindings = ext_db.get_switchport_binding_by_neutron_port( context._plugin_context, context.current['id']) context.nuage_bindings = nuage_bindings
def _create_nuage_bridge_vport(self, port_dict): """Create a BRIDGE VPort on VSD""" port = port_dict['port'] gw_ports = port.get('link_info') if not gw_ports: raise exceptions.DirectPortSwithportMappingNotFound( port=port['id']) segmentation_id = port_dict['segmentation_id'] ctx = neutron_context.get_admin_context() bridgeports = ext_db.get_switchport_binding_by_neutron_port( ctx, port['id'], segmentation_id) if bridgeports: LOG.info("bridge port(s) %(bp)s for port %(port)s already exist", { 'bp': bridgeports, 'port': port['id'] }) return for gwport in gw_ports: vports = ext_db.get_switchport_bindings_by_switchport_vlan( ctx, gwport['port_id'], segmentation_id) if len(vports) == 0: filters = {'system_id': [gwport['switch_id']]} gws = self.vsdclient.get_gateways(ctx.tenant_id, filters) if len(gws) == 0: msg = (_("No gateway found %s") % filters['system_id'][0]) raise exceptions.NuageBadRequest(msg=msg) gw = gws[0] # gridinv: following code should be removed when # we have proper support of native vlan on cisco/netconf if ('NETCONF_THIRDPARTY' in gw['gw_type'] and segmentation_id == 0): return port_id = gwport['port_id'] params = { 'gatewayport': port_id, 'value': segmentation_id, 'redundant': gwport['redundant'], 'personality': gw['gw_type'] } try: vlan = self.vsdclient.create_gateway_vlan(params) LOG.debug("created vlan: %(vlan_dict)s", {'vlan_dict': vlan}) except ResourceExistsException: allow_flat = self.conf.nuage_sriov.allow_existing_flat_vlan if segmentation_id == 0 and allow_flat: LOG.info( 'Reusing existing vlan due to ' 'allow_existing_flat_vlan=%s', allow_flat) return else: raise # create dummy subnet - we need only id params = { 'gatewayinterface': vlan['ID'], 'np_id': port_dict['subnet_mapping']['net_partition_id'], 'tenant': port['tenant_id'], 'subnet': port_dict['subnet'], 'enable_dhcp': port_dict['enable_dhcp'], 'nuage_managed_subnet': port_dict['subnet_mapping']['nuage_managed_subnet'], 'port_security_enabled': False, 'personality': gw['gw_type'], 'type': nuage_const.BRIDGE_VPORT_TYPE } vsd_subnet = self.vsdclient \ .get_nuage_subnet_by_id( port_dict['subnet_mapping']['nuage_subnet_id']) params['vsd_subnet'] = vsd_subnet vport = self.vsdclient.create_gateway_vport_no_usergroup( ctx.tenant_id, params) # policy groups are not supported on netconf # managed gateways and unmanaged gateways create_policy = (gw['gw_type'] not in [ 'NETCONF_THIRDPARTY_HW_VTEP', 'UNMANAGED_GATEWAY' ]) if create_policy: (domain_type, domain_id) = self._get_domain_type_id_from_vsd_subnet( self.vsdclient, vsd_subnet) self.psec_handler.process_pg_allow_all( ctx, nuage_const.HARDWARE, port_dict['subnet_mapping'], vport['vport'], domain_type, domain_id) LOG.debug("created vport: %(vport_dict)s", {'vport_dict': vport}) bridge_port_id = vport.get('vport').get('ID') else: LOG.debug("bridge port %(bp)s for vlan %(vlan)s already exist", { 'bp': vports[0]['nuage_vport_id'], 'vlan': segmentation_id }) bridge_port_id = vports[0]['nuage_vport_id'] binding = { 'neutron_port_id': port.get('id'), 'nuage_vport_id': bridge_port_id, 'switchport_uuid': gwport['port_id'], 'segmentation_id': segmentation_id, 'switchport_mapping_id': gwport['id'] } ext_db.add_switchport_binding(ctx, binding)
def _create_nuage_bridge_vport(self, port_dict): """Create a BRIDGE VPort on VSD""" port = port_dict['port'] gw_ports = port.get('link_info') if not gw_ports: raise exceptions.DirectPortSwithportMappingNotFound( port=port['id']) segmentation_id = port_dict['segmentation_id'] ctx = neutron_context.get_admin_context() vport_exist = ext_db.get_switchport_binding_by_neutron_port( ctx, port['id'], segmentation_id) if vport_exist: LOG.info( "bridge port %(bp)s for port %(port_id)s already exist", { 'bp': vport_exist['nuage_vport_id'], 'port_id': vport_exist['neutron_port_id'] }) return for gwport in gw_ports: vports = ext_db.get_switchport_bindings_by_switchport_vlan( ctx, gwport['port_id'], segmentation_id) if len(vports) == 0: filters = {'system_id': [gwport['switch_id']]} gws = self.vsdclient.get_gateways(ctx.tenant_id, filters) if len(gws) == 0: msg = (_("No gateway found %s") % filters['system_id'][0]) raise exceptions.NuageBadRequest(msg=msg) gw = gws[0] port_id = gwport['port_id'] params = { 'gatewayport': port_id, 'value': segmentation_id, 'redundant': gwport['redundant'], 'personality': gw['gw_type'] } try: vlan = self.vsdclient.create_gateway_vlan(params) LOG.debug("created vlan: %(vlan_dict)s", {'vlan_dict': vlan}) except ResourceExistsException: allow_flat = self.conf.nuage_sriov.allow_existing_flat_vlan if segmentation_id == 0 and allow_flat: LOG.info( 'Reusing existing vlan due to ' 'allow_existing_flat_vlan=%s', allow_flat) return else: raise # create dummy subnet - we need only id params = { 'gatewayinterface': vlan['ID'], 'np_id': port_dict['subnet_mapping']['net_partition_id'], 'tenant': port['tenant_id'], 'subnet': port_dict['subnet'], 'enable_dhcp': port_dict['enable_dhcp'], 'nuage_managed_subnet': port_dict['subnet_mapping']['nuage_managed_subnet'], 'port_security_enabled': False, 'personality': gw['gw_type'], 'type': nuage_const.BRIDGE_VPORT_TYPE } vsd_subnet = self.vsdclient \ .get_nuage_subnet_by_id( port_dict['subnet_mapping']['nuage_subnet_id']) params['vsd_subnet'] = vsd_subnet # policy groups are not supported on netconf # managed gateways create_policy = 'NETCONF' not in gw['gw_type'] vport = self.vsdclient.create_gateway_vport_no_usergroup( ctx.tenant_id, params, create_policy_group=create_policy) LOG.debug("created vport: %(vport_dict)s", {'vport_dict': vport}) bridge_port_id = vport.get('vport').get('ID') else: LOG.debug("bridge port %(bp)s for vlan %(vlan)s already exist", { 'bp': vports[0]['nuage_vport_id'], 'vlan': segmentation_id }) bridge_port_id = vports[0]['nuage_vport_id'] binding = { 'neutron_port_id': port.get('id'), 'nuage_vport_id': bridge_port_id, 'switchport_uuid': gwport['port_id'], 'segmentation_id': segmentation_id, 'switchport_mapping_id': gwport['id'] } ext_db.add_switchport_binding(ctx, binding)