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


Python NetworkHelper.create_tunnel方法代码示例

本文整理汇总了Python中f5_openstack_agent.lbaasv2.drivers.bigip.network_helper.NetworkHelper.create_tunnel方法的典型用法代码示例。如果您正苦于以下问题:Python NetworkHelper.create_tunnel方法的具体用法?Python NetworkHelper.create_tunnel怎么用?Python NetworkHelper.create_tunnel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在f5_openstack_agent.lbaasv2.drivers.bigip.network_helper.NetworkHelper的用法示例。


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

示例1: DisconnectedService

# 需要导入模块: from f5_openstack_agent.lbaasv2.drivers.bigip.network_helper import NetworkHelper [as 别名]
# 或者: from f5_openstack_agent.lbaasv2.drivers.bigip.network_helper.NetworkHelper import create_tunnel [as 别名]
class DisconnectedService(object):
    network_name = "disconnected_network"

    def __init__(self):
        self.network_name = DisconnectedService.network_name
        self.network_helper = NetworkHelper()

    # The following method presumes that the plugin driver is aware that we're
    # running in hierarchical mode or not and sets segmentation_id correctly.
    def is_service_connected(self, service):
        networks = service["networks"]
        network_id = service["loadbalancer"]["network_id"]
        network = networks.get(network_id, {})

        if network.get("provider:network_type", "") == "flat":
            return True

        segmentation_id = network.get("provider:segmentation_id", 0)

        return segmentation_id

    def is_virtual_connected(self, virtual, bigips):
        # check if virtual_server is connected on any of our bigips
        connected = True
        for bigip in bigips:
            vsf = bigip.tm.ltm.virtuals.virtual
            if vsf.exists(name=virtual["name"], partition=virtual["partition"]):
                vs = vsf.load(name=virtual["name"], partition=virtual["partition"])
                if getattr(vs, "vlansDisabled", False) or not getattr(vs, "vlansEnabled", True):
                    # accommodate quirk of how big-ip returns virtual server
                    # if vlans are disabled OR vlans are not enabled, then
                    # we're connected
                    continue
                network_path = "/%s/%s" % (virtual["partition"], self.network_name)
                if network_path in getattr(vs, "vlans", []):
                    connected = False
                    break
        return connected

    def network_exists(self, bigip, partition):
        t = bigip.tm.net.tunnels.tunnels.tunnel
        return t.exists(name=self.network_name, partition=partition)

    @log_helpers.log_method_call
    def create_network(self, bigip, partition):
        model = {
            "name": self.network_name,
            "partition": partition,
            "profile": "ppp",
            "description": "Tenant disconnected network",
        }
        t = self.network_helper.create_tunnel(bigip, model)
        return t

    @log_helpers.log_method_call
    def delete_network(self, bigip, partition):
        tf = bigip.tm.net.tunnels.tunnels.tunnel
        if tf.exists(name=self.network_name, partition=partition):
            tf.load(name=self.network_name, partition=partition).delete()
开发者ID:F5Networks,项目名称:f5-openstack-agent,代码行数:61,代码来源:disconnected_service.py

示例2: DisconnectedService

# 需要导入模块: from f5_openstack_agent.lbaasv2.drivers.bigip.network_helper import NetworkHelper [as 别名]
# 或者: from f5_openstack_agent.lbaasv2.drivers.bigip.network_helper.NetworkHelper import create_tunnel [as 别名]
class DisconnectedService(object):
    network_name = 'disconnected_network'

    def __init__(self):
        self.network_name = DisconnectedService.network_name
        self.network_helper = NetworkHelper()

    # The following method presumes that the plugin driver is aware that we're
    # running in hierarchical mode or not and sets segmentation_id correctly.
    def is_service_connected(self, service):
        networks = service['networks']
        network_id = service['loadbalancer']['network_id']
        segmentation_id = networks[network_id]['provider:segmentation_id']
        return (segmentation_id)

    def is_virtual_connected(self, virtual, bigips):
        # check if virtual_server is connected on any of our bigips
        connected = True
        for bigip in bigips:
            vsf = bigip.tm.ltm.virtuals.virtual
            if vsf.exists(name=virtual['name'],
                          partition=virtual['partition']):
                vs = vsf.load(
                    name=virtual['name'], partition=virtual['partition'])
                if (getattr(vs, 'vlansDisabled', False) or
                        not getattr(vs, 'vlansEnabled', True)):
                    # accommodate quirk of how big-ip returns virtual server
                    # if vlans are disabled OR vlans are not enabled, then
                    # we're connected
                    continue
                network_path = "/%s/%s" % (virtual['partition'],
                                           self.network_name)
                if network_path in getattr(vs, 'vlans', []):
                    connected = False
                    break
        return connected

    def network_exists(self, bigip, partition):
        t = bigip.tm.net.tunnels.tunnels.tunnel
        return t.exists(name=self.network_name, partition=partition)

    @log_helpers.log_method_call
    def create_network(self, bigip, partition):
        model = {'name': self.network_name,
                 'partition': partition,
                 'profile': 'ppp',
                 'description': 'Tenant disconnected network'}
        t = self.network_helper.create_tunnel(bigip, model)
        return t

    @log_helpers.log_method_call
    def delete_network(self, bigip, partition):
        tf = bigip.tm.net.tunnels.tunnels.tunnel
        if tf.exists(name=self.network_name, partition=partition):
            tf.load(name=self.network_name, partition=partition).delete()
开发者ID:richbrowne,项目名称:f5-openstack-agent,代码行数:57,代码来源:disconnected_service.py


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