当前位置: 首页>>代码示例>>Python>>正文


Python db.get_network_segments函数代码示例

本文整理汇总了Python中neutron.plugins.ml2.db.get_network_segments函数的典型用法代码示例。如果您正苦于以下问题:Python get_network_segments函数的具体用法?Python get_network_segments怎么用?Python get_network_segments使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_network_segments函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sync_highperformance_routers

 def sync_highperformance_routers(self, context, **kwargs):
     routers = self.sync_routers(context, **kwargs)
     for router in routers:
         for snat_port in router.get(constants.SNAT_ROUTER_INTF_KEY, []):
             network_segments = ml2_db.get_network_segments(context.session, 
                                                            snat_port['network_id'])
             if network_segments:
                 snat_port['vni'] = network_segments[0][api.SEGMENTATION_ID]
         gw_port = router.get('gw_port')
         if gw_port:
             network_segments = ml2_db.get_network_segments(context.session, 
                                                            gw_port['network_id'])
             if network_segments:
                 gw_port['vlan'] = network_segments[0][api.SEGMENTATION_ID]
     
     return routers
开发者ID:HybridCloud-dew,项目名称:hws,代码行数:16,代码来源:l3_rpc.py

示例2: test_release_network_segments

    def test_release_network_segments(self):
        data = {
            "network": {
                "name": "net1",
                "admin_state_up": True,
                "shared": False,
                pnet.NETWORK_TYPE: "vlan",
                pnet.PHYSICAL_NETWORK: "physnet1",
                pnet.SEGMENTATION_ID: 1,
                "tenant_id": "tenant_one",
            }
        }
        network_req = self.new_create_request("networks", data)
        res = network_req.get_response(self.api)
        network = self.deserialize(self.fmt, res)
        network_id = network["network"]["id"]
        segment = {driver_api.NETWORK_TYPE: "vlan", driver_api.PHYSICAL_NETWORK: "physnet2"}
        self.driver.type_manager.allocate_dynamic_segment(self.context.session, network_id, segment)
        dynamic_segment = ml2_db.get_dynamic_segment(self.context.session, network_id, "physnet2")
        self.assertEqual("vlan", dynamic_segment[driver_api.NETWORK_TYPE])
        self.assertEqual("physnet2", dynamic_segment[driver_api.PHYSICAL_NETWORK])
        self.assertTrue(dynamic_segment[driver_api.SEGMENTATION_ID] > 0)

        with mock.patch.object(type_vlan.VlanTypeDriver, "release_segment") as rs:
            req = self.new_delete_request("networks", network_id)
            res = req.get_response(self.api)
            self.assertEqual(2, rs.call_count)
        self.assertEqual(ml2_db.get_network_segments(self.context.session, network_id), [])
        self.assertIsNone(ml2_db.get_dynamic_segment(self.context.session, network_id, "physnet2"))
开发者ID:CiscoSystems,项目名称:neutron,代码行数:29,代码来源:test_ml2_plugin.py

示例3: _extend_network_dict_provider

    def _extend_network_dict_provider(self, context, network):
        if 'id' not in network:
            LOG.debug("Network has no id")
            network[provider.NETWORK_TYPE] = None
            network[provider.PHYSICAL_NETWORK] = None
            network[provider.SEGMENTATION_ID] = None
            return

        net_id = network['id']
        segments = db_ml2.get_network_segments(
            context.session, net_id, filter_dynamic=True)

        if not segments:
            LOG.debug("Network %s has no segments", net_id)
            network[provider.NETWORK_TYPE] = None
            network[provider.PHYSICAL_NETWORK] = None
            network[provider.SEGMENTATION_ID] = None
        elif len(segments) > 1:
            network[mpnet.SEGMENTS] = [
                {provider.NETWORK_TYPE: segment[api.NETWORK_TYPE],
                 provider.PHYSICAL_NETWORK: segment[api.PHYSICAL_NETWORK],
                 provider.SEGMENTATION_ID: segment[api.SEGMENTATION_ID]}
                for segment in segments]
        else:
            segment = segments[0]
            network[provider.NETWORK_TYPE] = segment[api.NETWORK_TYPE]
            network[provider.PHYSICAL_NETWORK] = segment[api.PHYSICAL_NETWORK]
            network[provider.SEGMENTATION_ID] = segment[api.SEGMENTATION_ID]
开发者ID:nec-openstack,项目名称:networking-nec,代码行数:28,代码来源:plugin.py

示例4: test_release_network_segments

    def test_release_network_segments(self):
        data = {'network': {'name': 'net1',
                            'admin_state_up': True,
                            'shared': False,
                            pnet.NETWORK_TYPE: 'vlan',
                            pnet.PHYSICAL_NETWORK: 'physnet1',
                            pnet.SEGMENTATION_ID: 1,
                            'tenant_id': 'tenant_one'}}
        network_req = self.new_create_request('networks', data)
        res = network_req.get_response(self.api)
        network = self.deserialize(self.fmt, res)
        network_id = network['network']['id']
        segment = {driver_api.NETWORK_TYPE: 'vlan',
                   driver_api.PHYSICAL_NETWORK: 'physnet2'}
        self.driver.type_manager.allocate_dynamic_segment(
            self.context.session, network_id, segment)
        dynamic_segment = ml2_db.get_dynamic_segment(self.context.session,
                                                     network_id,
                                                     'physnet2')
        self.assertEqual('vlan', dynamic_segment[driver_api.NETWORK_TYPE])
        self.assertEqual('physnet2',
                         dynamic_segment[driver_api.PHYSICAL_NETWORK])
        self.assertTrue(dynamic_segment[driver_api.SEGMENTATION_ID] > 0)

        with mock.patch.object(type_vlan.VlanTypeDriver,
                               'release_segment') as rs:
            req = self.new_delete_request('networks', network_id)
            res = req.get_response(self.api)
            self.assertEqual(2, rs.call_count)
        self.assertEqual(ml2_db.get_network_segments(
            self.context.session, network_id), [])
        self.assertIsNone(ml2_db.get_dynamic_segment(
            self.context.session, network_id, 'physnet2'))
开发者ID:caboucha,项目名称:neutron,代码行数:33,代码来源:test_ml2_plugin.py

示例5: __init__

 def __init__(self, plugin, plugin_context, network,
              original_network=None):
     super(NetworkContext, self).__init__(plugin, plugin_context)
     self._network = network
     self._original_network = original_network
     self._segments = db.get_network_segments(plugin_context.session,
                                              network['id'])
开发者ID:50infivedays,项目名称:neutron,代码行数:7,代码来源:driver_context.py

示例6: get_network_segid

    def get_network_segid(self, sid):
        """Get network segmentation id.

        :param sid: requested segment id
        """
        db_session = db.get_session()
        seg_entry = ml2db.get_network_segments(db_session, sid)
        return seg_entry[0]['segmentation_id']
开发者ID:nishant80,项目名称:neutron,代码行数:8,代码来源:projects_cache_db_v2.py

示例7: get_shared_network_owner_id

 def get_shared_network_owner_id(self, network_id):
     filters = {'id': [network_id]}
     nets = self.get_networks(self.admin_ctx, filters=filters) or []
     segments = ml2_db.get_network_segments(self.admin_ctx.session,
                                            network_id)
     if not nets or not segments:
         return
     if (nets[0]['shared'] and
        segments[0][driver_api.NETWORK_TYPE] == p_const.TYPE_VLAN):
         return nets[0]['tenant_id']
开发者ID:wujcheng,项目名称:networking-arista,代码行数:10,代码来源:db_lib.py

示例8: release_network_segments

    def release_network_segments(self, session, network_id):
        segments = db.get_network_segments(session, network_id, filter_dynamic=None)

        for segment in segments:
            network_type = segment.get(api.NETWORK_TYPE)
            driver = self.drivers.get(network_type)
            if driver:
                driver.obj.release_segment(session, segment)
            else:
                LOG.error(_LE("Failed to release segment '%s' because " "network type is not supported."), segment)
开发者ID:bigswitch,项目名称:neutron,代码行数:10,代码来源:managers.py

示例9: delete_network

    def delete_network(self, context, id):
        session = context.session
        with session.begin(subtransactions=True):
            segments = db.get_network_segments(session, id)
            super(Ml2Plugin, self).delete_network(context, id)
            for segment in segments:
                self.type_manager.release_segment(session, segment)
            # The segment records are deleted via cascade from the
            # network record, so explicit removal is not necessary.

        self.notifier.network_delete(context, id)
开发者ID:CiscoSystems,项目名称:quantum,代码行数:11,代码来源:plugin.py

示例10: _create_segments

    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
开发者ID:qianqunyi,项目名称:neutron,代码行数:11,代码来源:test_db.py

示例11: get_vlan_id_of_physical_network

def get_vlan_id_of_physical_network(context, network_id, physical_network):
    if hasattr(context, 'session'):
        session = context.session
    else:
        session = context.network._plugin_context.session
    segments = db_ml2.get_network_segments(session, network_id)
    if not segments:
        return ''
    for segment in segments:
        if segment[api.PHYSICAL_NETWORK] == physical_network:
            return str(segment[api.SEGMENTATION_ID])
    return str(segments[0][api.SEGMENTATION_ID])
开发者ID:nec-openstack,项目名称:networking-nec-nwa,代码行数:12,代码来源:utils.py

示例12: _log_subnet_information

 def _log_subnet_information(self, method_name, current_context, prev_context):
     driver_logger.info("**** %s ****" % (method_name))
     driver_logger.info("Current Subnet Name: %s" % (current_context['name']))
     driver_logger.info("Current Subnet CIDR: %s" % (current_context['cidr']))
     # Extract the Network ID from the Subnet Context
     network_id = current_context['network_id']
     # Get the Neutron DB Session Handle
     session = db.get_session()
     # Using ML2 DB API, fetch the Network that matches the Network ID
     networks = ml2_db.get_network_segments(session, network_id)
     driver_logger.info("Network associated to the Subnet: %s" % (networks))
     driver_logger.info("**** %s ****" % (method_name))
开发者ID:xchandan,项目名称:packt-openstack-networking-cookbook,代码行数:12,代码来源:ch10_ml2_mech_driver_subnet.py

示例13: _notify_port_updated

 def _notify_port_updated(self, context, port):
     session = context.session
     with session.begin(subtransactions=True):
         network_id = port['network_id']
         segments = db.get_network_segments(session, network_id)
         if not segments:
             LOG.warning(_("In _notify_port_updated() for port %(port_id), "
                           "network %(network_id) has no segments"),
                         {'port_id': port['id'],
                          'network_id': network_id})
             return
         # TODO(rkukura): Use port binding to select segment.
         segment = segments[0]
     self.notifier.port_update(context, port,
                               segment[api.NETWORK_TYPE],
                               segment[api.SEGMENTATION_ID],
                               segment[api.PHYSICAL_NETWORK])
开发者ID:CiscoSystems,项目名称:quantum,代码行数:17,代码来源:plugin.py

示例14: _extend_network_dict_provider

 def _extend_network_dict_provider(self, context, network):
     id = network['id']
     segments = db.get_network_segments(context.session, id)
     if not segments:
         LOG.error(_("Network %s has no segments"), id)
         network[provider.NETWORK_TYPE] = None
         network[provider.PHYSICAL_NETWORK] = None
         network[provider.SEGMENTATION_ID] = None
     elif len(segments) > 1:
         network[provider.NETWORK_TYPE] = TYPE_MULTI_SEGMENT
         network[provider.PHYSICAL_NETWORK] = None
         network[provider.SEGMENTATION_ID] = None
     else:
         segment = segments[0]
         network[provider.NETWORK_TYPE] = segment[api.NETWORK_TYPE]
         network[provider.PHYSICAL_NETWORK] = segment[api.PHYSICAL_NETWORK]
         network[provider.SEGMENTATION_ID] = segment[api.SEGMENTATION_ID]
开发者ID:CiscoSystems,项目名称:quantum,代码行数:17,代码来源:plugin.py

示例15: extend_network_dict_provider

 def extend_network_dict_provider(self, context, network):
     id = network['id']
     segments = db.get_network_segments(context.session, id)
     if not segments:
         LOG.error(_LE("Network %s has no segments"), id)
         for attr in provider.ATTRIBUTES:
             network[attr] = None
     elif len(segments) > 1:
         network[mpnet.SEGMENTS] = [
             {provider.NETWORK_TYPE: segment[api.NETWORK_TYPE],
              provider.PHYSICAL_NETWORK: segment[api.PHYSICAL_NETWORK],
              provider.SEGMENTATION_ID: segment[api.SEGMENTATION_ID]}
             for segment in segments]
     else:
         segment = segments[0]
         network[provider.NETWORK_TYPE] = segment[api.NETWORK_TYPE]
         network[provider.PHYSICAL_NETWORK] = segment[api.PHYSICAL_NETWORK]
         network[provider.SEGMENTATION_ID] = segment[api.SEGMENTATION_ID]
开发者ID:rajamony,项目名称:neutron,代码行数:18,代码来源:managers.py


注:本文中的neutron.plugins.ml2.db.get_network_segments函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。