用法

从 OpenStack CLI 使用

管理员创建 BGPVPN 资源示例命令

openstack bgpvpn create --route-target 64512:1 --project b954279e1e064dc9b8264474cb3e6bd2
openstack bgpvpn list
openstack bgpvpn set <bgpvpn-uuid> --name myBGPVPN

拥有 BGPVPN 的租户关联网络示例命令

openstack bgpvpn network association create myBGPVPN <net-uuid>
# returns <net-assoc-uuid>
openstack bgpvpn network association list myBGPVPN
openstack bgpvpn network association show <net-assoc-uuid> myBGPVPN

openstack bgpvpn network association delete <net-assoc-uuid> myBGPVPN

更多详细信息请参阅 OpenStack 客户端 (OSC) 关于 BGPVPN 的文档

从 Horizon 使用

请参阅 Horizon

从 Heat 使用

请参阅 Heat

从 Python 使用

python neutroclient 库自 Ocata 版本发布以来,就包含对 BGPVPN API 扩展的支持。

注意

对于较旧的版本,networking-bgpvpn 中提供的 neutronclient 的动态扩展可用。在这种情况下,列出、获取、创建、删除和更新网络关联和路由器关联的方法与此处记录的不同

  • 不同的名称:list_network_associations 而不是 list_bgpvpn_network_assocs`,所有方法都相同

  • 参数顺序:BGPVPN UUID 作为第一个参数,关联 UUID 作为第二个参数

这些旧方法已被弃用。

方法

BGPVPN 资源

BGPVPN 资源的 API 方法

方法名称

描述

输入参数

输出

list_bgpvpns()

获取当前租户定义的 BGPVPN 资源的列表。可以使用可选的 BGPVPN 参数列表作为过滤器。

  1. 使用 **kwargs 作为过滤器,例如 list_bgpvpn(param1=val1, param2=val2,…) (可选)

BGPVPN 属性字典

create_bgpvpn()

为当前租户创建一个 BGPVPN 资源。可以提供有关 BGPVPN 资源的额外信息作为输入。

  1. BGPVPN 属性字典 (可选)

BGPVPN 属性字典

show_bgpvpn()

获取给定 BGPVPN 的所有信息。

  1. 所述 BGPVPN 的 UUID

与提供的 BGPVPN 输入相关的 BGPVPN 属性字典

update_bgpvpn()

使用提供的输入参数更新 BGPVPN 资源。

  1. 所述 BGPVPN 的 UUID

  2. 要更新的 BGPVPN 属性字典

BGPVPN 属性字典

delete_bgpvpn()

删除给定 BGPVPN 资源,其 UUID 作为输入提供。

  1. 所述 BGPVPN 的 UUID

布尔值

网络关联资源

网络关联资源的 API 方法

方法名称

描述

输入参数

输出

list_bgpvpn_network_assocs()

获取给定 BGPVPN 的定义的网络关联资源的列表。可以使用可选的网络关联参数列表作为过滤器。

  1. BGPVPN 的 UUID

  2. 使用 **kwargs 作为过滤器,例如 list_bgpvpn_network_assocs( BGPVPN UUID, param1=val1, param2=val2,…) (可选)

网络关联属性字典列表,每个列表对应于给定的 BGPVPN

create_bgpvpn_network_assoc()

为给定的 BGPVPN 创建一个网络关联资源。必须定义网络 UUID,并将其作为输入参数提供在网络关联资源中。

  1. 所述 BGPVPN 的 UUID

  2. 网络关联参数字典

网络关联属性字典

show_bgpvpn_network_assoc()

获取给定网络关联的所有参数。

  1. BGPVPN 资源的 UUID

  2. 网络关联资源的 UUID

网络关联参数字典

update_bgpvpn_network_assoc()

更新提供的输入网络关联资源的参数。

  1. BGPVPN 资源的 UUID

  2. 网络关联资源的 UUID,3. 网络关联参数字典

网络关联参数字典

delete_bgpvpn_network_assoc()

删除给定网络关联资源,其 UUID 作为输入提供。

  1. BGPVPN 资源的 UUID

  2. 网络关联资源的 UUID

布尔值

路由器关联资源

路由器关联资源的 API 方法

方法名称

描述

输入参数

输出

list_bgpvpn_router_assocs()

获取给定 BGPVPN 的定义的路由器关联资源的列表。可以使用可选的路由器关联参数列表作为过滤器。

  1. BGPVPN 的 UUID

  2. 使用 **kwargs 作为过滤器,例如 list_bgpvpn_router_assocs( BGPVPN UUID, param1=val1, param2=val2,…) (可选)

路由器关联属性字典列表,每个列表对应于给定的 BGPVPN

create_bgpvpn_router_assoc()

为给定的 BGPVPN 创建一个路由器关联资源。必须定义路由器 UUID,并将其作为输入参数提供在路由器关联资源中。

  1. 所述 BGPVPN 的 UUID

  2. 路由器关联参数字典

路由器关联属性字典

show_bgpvpn_router_assoc()

获取给定路由器关联的所有参数。

  1. BGPVPN 资源的 UUID

  2. 路由器关联资源的 UUID

路由器关联参数字典

update_bgpvpn_router_assoc()

更新提供的输入路由器关联资源的参数。

  1. BGPVPN 资源的 UUID

  2. 路由器关联资源的 UUID,3. 路由器关联参数字典

路由器关联参数字典

delete_bgpvpn_router_assoc()

删除给定路由器关联资源,其 UUID 作为输入提供。

  1. BGPVPN 资源的 UUID

  2. 路由器关联资源的 UUID

布尔值

端口关联资源

端口关联资源的 API 方法

方法名称

描述

输入参数

输出

list_bgpvpn_port_assocs()

获取给定 BGPVPN 的定义的端口关联资源的列表。可以使用可选的端口关联参数列表作为过滤器。

  1. BGPVPN 的 UUID

  2. 使用 **kwargs 作为过滤器,例如 list_bgpvpn_port_assocs( BGPVPN UUID, param1=val1, param2=val2,…) (可选)

端口关联属性字典列表,每个列表对应于给定的 BGPVPN

create_bgpvpn_port_assoc()

为给定的 BGPVPN 创建一个端口关联资源。必须定义端口 UUID,并将其作为输入参数提供在端口关联资源中。

  1. 所述 BGPVPN 的 UUID

  2. 端口关联参数字典

端口关联属性字典

show_bgpvpn_port_assoc()

获取给定端口关联的所有参数。

  1. BGPVPN 资源的 UUID

  2. 端口关联资源的 UUID

端口关联参数字典

update_bgpvpn_port_assoc()

更新提供的输入端口关联资源的参数。

  1. BGPVPN 资源的 UUID

  2. 端口关联资源的 UUID,3. 端口关联参数字典

端口关联参数字典

delete_bgpvpn_port_assoc()

删除给定端口关联资源,其 UUID 作为输入提供。

  1. BGPVPN 资源的 UUID

  2. 端口关联资源的 UUID

布尔值

示例

BGPVPN + 网络关联资源

# Copyright (c) 2016 Orange.
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         https://apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import os
import sys

from keystoneauth1.identity import v3
from keystoneauth1 import session
from neutronclient.v2_0 import client

# Parameter for subnet neutron object
SUBNET_IP = "192.168.24.0/24"

# Parameters for bgpvpn neutron object
BGPVPN_RT = "64512:2"


# Function to obtain stack parameters from system vars
def get_keystone_creds():
    d = {}
    try:
        d['username'] = os.environ['OS_USERNAME']
        d['password'] = os.environ['OS_PASSWORD']
        d['auth_url'] = os.environ['OS_AUTH_URL']
        d['project_name'] = os.environ['OS_PROJECT_NAME']
        d['project_domain_id'] = os.environ['OS_PROJECT_DOMAIN_ID']
        d['user_domain_id'] = os.environ['OS_USER_DOMAIN_ID']
    except KeyError:
        print("ERROR: Stack environment variables type "
              "OS_* are not properly set")
        sys.exit(1)
    return d


# Main function
def main():
    # Call function that imports (dev)stack vars
    creds = get_keystone_creds()

    # Authentication
    auth = v3.Password(**creds)
    sess = session.Session(auth=auth)

    # Neutron object
    # It dynamically loads the BGPVPN API
    neutron = client.Client(session=sess)

    try:
        # Network object creation. This dummy network will be used to bind the
        # attached subnet to the BGPVPN object.

        # Creation of the Network
        net_obj = neutron.create_network({'network': {'name': "dummyNet"}})
        # Verify creation
        print('Network created\t[network-id:%s]...' %
              net_obj['network']['id'])

        # Creation of the subnet, is attached to the created network
        subnet_obj = neutron.create_subnet(
            {'subnet':
                {'name': "dummySubnet",
                 'cidr': SUBNET_IP,
                 'network_id': net_obj['network']['id'],
                 'ip_version': 4}})
        # Verify
        print("Subnet created\t[subnet-id:%s]..." %
              subnet_obj['subnet']['id'])

        # Creation of a BGPVPN object. This object is created with the
        # required parameter 'routes_targets'.
        # This object can be created with others parameters or be updated with
        # them by calling the update function on the object.

        print("\nBGPVPN object handling.")
        # Creation of the BGPVPN object
        bgpvpn_obj = neutron.create_bgpvpn(
            {'bgpvpn': {'route_targets': [BGPVPN_RT]}})
        print("BGPVPN object created\t[bgpvpn-id:%s]..." %
              bgpvpn_obj['bgpvpn']['id'])
        # Update the BGPVPN object
        bgpvpn_obj = neutron.update_bgpvpn(
            bgpvpn_obj['bgpvpn']['id'], {'bgpvpn': {'name': "dummyBGPVPN"}})
        # List all BGPVPN objects
        list_bgpvpn_obj = neutron.list_bgpvpns()
        print("List of all BGPVPN object\t[%s]" % list_bgpvpn_obj)
        # List of all BGPVPN objects filtered on the type parameter set to l3
        # value
        list_bgpvpn_obj = neutron.list_bgpvpns(type='l3')
        print("List of all BGPVPN object with type=l3\t[%s]" %
              list_bgpvpn_obj)

        # Creation of a BGPVPN Network association.
        print("\nBGPVPN Network Association object handling.")
        # Creation of a Network Association bound on the created BGPVPN object
        bgpvpn_net_assoc_obj = neutron.create_bgpvpn_network_assoc(
            bgpvpn_obj['bgpvpn']['id'],
            {'network_association':
                {'network_id':
                    net_obj['network']['id']}})
        print("BGPVPN Network Association created\t"
              "[network_association:%s]..." %
              bgpvpn_net_assoc_obj['network_association']['id'])
        # List all NETWORK ASSOCIATION object filtered on the network created
        # above
        list_bgpvpn_net_assoc_obj = neutron.list_bgpvpn_network_assocs(
            bgpvpn_obj['bgpvpn']['id'],
            network_id=net_obj['network']['id'])
        print("List of NETWORK ASSOCIATION objects using network_id"
              "[%s]\t[%s]" %
              (net_obj['network']['id'], list_bgpvpn_net_assoc_obj))

        # Deletion of all objects created in this example

        print("\nDeletion of all created objects")
        # First declared associations related of the created BGPVPN object in
        # this example
        neutron.delete_bgpvpn_network_assoc(
            bgpvpn_net_assoc_obj['network_association']['id'],
            bgpvpn_obj['bgpvpn']['id'])
        # Then the BGPVPN object
        neutron.delete_bgpvpn(bgpvpn_obj['bgpvpn']['id'])
        # Subnet
        neutron.delete_subnet(subnet_obj['subnet']['id'])
        # And finally the Network
        neutron.delete_network(net_obj['network']['id'])
    except Exception as e:
        print("[ERROR][%s]" % str(e))
        sys.exit(1)

    print("[Done]")


if __name__ == '__main__':
    main()

__all__ = ['main']