def _bind_segment_to_vif_type(self, context, agent=None): mappings = {} if agent: mappings = agent['configurations'].get('bridge_mappings', {}) for res in self.resource_groups: if agent and res['ResourceGroupName'] not in mappings: continue if res['device_owner'] != context._port['device_owner']: continue network_id = context.network.current['id'] dummy_segment = db.get_dynamic_segment( context.network._plugin_context.session, network_id, physical_network=res['ResourceGroupName']) LOG.debug("1st: dummy segment is %s", dummy_segment) if not dummy_segment: dummy_segment = { api.PHYSICAL_NETWORK: res['ResourceGroupName'], api.NETWORK_TYPE: plugin_const.TYPE_VLAN, api.SEGMENTATION_ID: 0 } db.add_network_segment( context.network._plugin_context.session, network_id, dummy_segment, is_dynamic=True) LOG.debug("2nd: dummy segment is %s", dummy_segment) context.set_binding(dummy_segment[api.ID], self.vif_type, {portbindings.CAP_PORT_FILTER: True, portbindings.OVS_HYBRID_PLUG: True}) return True return False
def _bind_segment_to_vif_type(self, context, agent=None): mappings = {} if agent: mappings = agent['configurations'].get('bridge_mappings', {}) for res in self.resource_groups: if agent and res['ResourceGroupName'] not in mappings: continue if res['device_owner'] != context._port['device_owner']: continue network_id = context.network.current['id'] dummy_segment = db.get_dynamic_segment( context.network._plugin_context.session, network_id, physical_network=res['ResourceGroupName']) LOG.debug("1st: dummy segment is %s", dummy_segment) if not dummy_segment: dummy_segment = { api.PHYSICAL_NETWORK: res['ResourceGroupName'], api.NETWORK_TYPE: plugin_const.TYPE_VLAN, api.SEGMENTATION_ID: 0 } db.add_network_segment(context.network._plugin_context.session, network_id, dummy_segment, is_dynamic=True) LOG.debug("2nd: dummy segment is %s", dummy_segment) context.set_binding( dummy_segment[api.ID], self.vif_type, { portbindings.CAP_PORT_FILTER: True, portbindings.OVS_HYBRID_PLUG: True }) return True return False
def create_network(self, context, network): net_data = network['network'] segments = self._process_provider_create(net_data) tenant_id = self._get_tenant_id_for_create(context, net_data) session = context.session with session.begin(subtransactions=True): self._ensure_default_security_group(context, tenant_id) result = super(Ml2Plugin, self).create_network(context, network) network_id = result['id'] self._process_l3_create(context, result, net_data) # REVISIT(rkukura): Consider moving all segment management # to TypeManager. if segments: for segment in segments: self.type_manager.reserve_provider_segment(session, segment) db.add_network_segment(session, network_id, segment) else: segment = self.type_manager.allocate_tenant_segment(session) db.add_network_segment(session, network_id, segment) self._extend_network_dict_provider(context, result) mech_context = driver_context.NetworkContext(self, context, result) self.mechanism_manager.create_network_precommit(mech_context) try: self.mechanism_manager.create_network_postcommit(mech_context) except ml2_exc.MechanismDriverError: with excutils.save_and_reraise_exception(): LOG.error(_("mechanism_manager.create_network_postcommit " "failed, deleting network '%s'"), result['id']) self.delete_network(context, result['id']) return result
def _add_network_segment(self, session, network_id, segment, mtu, segment_index=0): db.add_network_segment(session, network_id, segment, segment_index) if segment.get(api.MTU, 0) > 0: mtu.append(segment[api.MTU])
def _create_segments(self, segments, is_seg_dynamic=False, network_id="foo-network-id"): self._setup_neutron_network(network_id) for segment in segments: ml2_db.add_network_segment(self.ctx.session, network_id, segment, is_dynamic=is_seg_dynamic) net_segments = ml2_db.get_network_segments(self.ctx.session, network_id, filter_dynamic=is_seg_dynamic) for segment_index, segment in enumerate(segments): self.assertEqual(segment, net_segments[segment_index]) return net_segments
def create_network_segments(self, context, network, tenant_id): """Call type drivers to create network segments.""" segments = self._process_provider_create(network) #验证参数以及创建网络segments session = context.session with session.begin(subtransactions=True): network_id = network['id'] if segments: for segment in segments: segment = self.reserve_provider_segment(session, segment) db.add_network_segment(session, network_id, segment) else: segment = self.allocate_tenant_segment(session) db.add_network_segment(session, network_id, segment)
def allocate_dynamic_segment(self, session, network_id, segment): """Allocate a dynamic segment using a partial or full segment dict.""" dynamic_segment = db.get_dynamic_segment( session, network_id, segment.get(api.PHYSICAL_NETWORK), segment.get(api.SEGMENTATION_ID) ) if dynamic_segment: return dynamic_segment driver = self.drivers.get(segment.get(api.NETWORK_TYPE)) dynamic_segment = driver.obj.reserve_provider_segment(session, segment) db.add_network_segment(session, network_id, dynamic_segment, is_dynamic=True) return dynamic_segment
def allocate_dynamic_segment(self, session, network_id, segment): """Allocate a dynamic segment using a partial or full segment dict.""" dynamic_segment = db.get_dynamic_segment( session, network_id, segment.get(api.PHYSICAL_NETWORK), segment.get(api.SEGMENTATION_ID)) if dynamic_segment: return dynamic_segment driver = self.drivers.get(segment.get(api.NETWORK_TYPE)) dynamic_segment = driver.obj.reserve_provider_segment(session, segment) db.add_network_segment(session, network_id, dynamic_segment, is_dynamic=True) return dynamic_segment
def create_network_segments(self, context, network, tenant_id): """Call type drivers to create network segments.""" segments = self._process_provider_create(network)#验证参数以及创建网络segments session = context.session with session.begin(subtransactions=True): network_id = network['id'] if segments: for segment in segments: segment = self.reserve_provider_segment( session, segment) db.add_network_segment(session, network_id, segment) else: segment = self.allocate_tenant_segment(session) db.add_network_segment(session, network_id, segment)
def _create_segments(self, segments, is_seg_dynamic=False): network_id = 'foo-network-id' self._setup_neutron_network(network_id) for segment in segments: ml2_db.add_network_segment(self.ctx.session, network_id, segment, is_dynamic=is_seg_dynamic) net_segments = ml2_db.get_network_segments( self.ctx.session, network_id, filter_dynamic=is_seg_dynamic) for segment_index, segment in enumerate(segments): self.assertEqual(segment, net_segments[segment_index]) return net_segments
def update_network_segments(self, new_obj): obj_id = new_obj.get('id') LOG.debug("update network segments for %(obj_id)s", {'obj_id': obj_id}) try: new_segments = new_obj.get('segments') if new_segments == None: return LOG.debug("new_segments %(new_segments)s", {'new_segments': new_segments}) session = db_api.get_session() with session.begin(subtransactions=True): segments=db.get_network_segments(session, obj_id) LOG.debug("update network segments when old segments %(segments)s", {'segments': segments}) phy_network = self.physical_network for segment in segments: db.delete_network_segment(session, segment.get(api.ID)) for new_segment in new_segments: network_type = new_segment.get(provider.NETWORK_TYPE) model = None filters = {} segmentation_id = new_segment.get(provider.SEGMENTATION_ID) new_segment_db = {api.NETWORK_TYPE: network_type, api.PHYSICAL_NETWORK: new_segment.get(provider.PHYSICAL_NETWORK), api.SEGMENTATION_ID: segmentation_id} if new_segment.get(provider.NETWORK_TYPE) == 'vlan': segment_index = 0 new_segment_db = {api.NETWORK_TYPE: network_type, api.PHYSICAL_NETWORK: phy_network, api.SEGMENTATION_ID: segmentation_id} model = type_vlan.VlanAllocation filters['physical_network'] = phy_network filters['vlan_id'] = segmentation_id else: segment_index = 1 model = type_vxlan.VxlanAllocation filters['vxlan_vni'] = segmentation_id LOG.debug("update network segments when new segment %(new_segment)s", {'new_segment': new_segment_db}) self.allocate_fully_specified_segment(session, network_type, model, **filters) db.add_network_segment(session, obj_id, new_segment_db, segment_index) except Exception: with excutils.save_and_reraise_exception(): LOG.error(_LE("update network segments error on " "%(object_id)s"), {'object_id': obj_id})
def create_network_segments(self, context, network, tenant_id): """Call type drivers to create network segments.""" segments = self._process_provider_create(network) session = context.session mtu = [] with session.begin(subtransactions=True): network_id = network['id'] if segments: for segment_index, segment in enumerate(segments): segment = self.reserve_provider_segment(session, segment) db.add_network_segment(session, network_id, segment, segment_index) if segment.get(api.MTU) > 0: mtu.append(segment[api.MTU]) else: segment = self.allocate_tenant_segment(session) db.add_network_segment(session, network_id, segment) if segment.get(api.MTU) > 0: mtu.append(segment[api.MTU]) network[api.MTU] = min(mtu) if mtu else 0
def create_network_segments(self, context, network, tenant_id): """Call type drivers to create network segments.""" segments = self._process_provider_create(network) session = context.session mtu = [] with session.begin(subtransactions=True): network_id = network['id'] if segments: for segment_index, segment in enumerate(segments): segment = self.reserve_provider_segment( session, segment) db.add_network_segment(session, network_id, segment, segment_index) if segment.get(api.MTU) > 0: mtu.append(segment[api.MTU]) else: segment = self.allocate_tenant_segment(session) db.add_network_segment(session, network_id, segment) if segment.get(api.MTU) > 0: mtu.append(segment[api.MTU]) network[api.MTU] = min(mtu) if mtu else 0
def _bind_segment_to_vif_type(self, context, physical_network): if self.multi_dc: return network_id = context.network.current['id'] session = context.network._plugin_context.session dummy_segment = db.get_dynamic_segment( session, network_id, physical_network=physical_network) LOG.debug("1st: dummy segment is %s", dummy_segment) if not dummy_segment: dummy_segment = { api.PHYSICAL_NETWORK: physical_network, api.NETWORK_TYPE: plugin_const.TYPE_VLAN, api.SEGMENTATION_ID: 0 } db.add_network_segment( session, network_id, dummy_segment, is_dynamic=True) LOG.debug("2nd: dummy segment is %s", dummy_segment) context.set_binding(dummy_segment[api.ID], self.vif_type, {portbindings.CAP_PORT_FILTER: True, portbindings.OVS_HYBRID_PLUG: True})
def create_network(self, context, network): attrs = network['network'] segment = self._process_provider_create(context, attrs) tenant_id = self._get_tenant_id_for_create(context, attrs) session = context.session with session.begin(subtransactions=True): self._ensure_default_security_group(context, tenant_id) if segment: self.type_manager.reserve_provider_segment(session, segment) else: segment = self.type_manager.allocate_tenant_segment(session) result = super(Ml2Plugin, self).create_network(context, network) id = result['id'] self._process_l3_create(context, result, attrs) # REVISIT(rkukura): Consider moving all segment management # to TypeManager. db.add_network_segment(session, id, segment) self._extend_network_dict_provider(context, result) return result
def _bind_segment_to_vif_type(self, context, physical_network): if self.multi_dc: return network_id = context.network.current['id'] session = context.network._plugin_context.session dummy_segment = db.get_dynamic_segment( session, network_id, physical_network=physical_network) LOG.debug("1st: dummy segment is %s", dummy_segment) if not dummy_segment: dummy_segment = { api.PHYSICAL_NETWORK: physical_network, api.NETWORK_TYPE: plugin_const.TYPE_VLAN, api.SEGMENTATION_ID: 0 } db.add_network_segment(session, network_id, dummy_segment, is_dynamic=True) LOG.debug("2nd: dummy segment is %s", dummy_segment) context.set_binding(dummy_segment[api.ID], self.vif_type, { portbindings.CAP_PORT_FILTER: True, portbindings.OVS_HYBRID_PLUG: True })