Usage

Usage

Use from OpenStack CLI

Example commands to use by the admin to create a BGPVPN resource:

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

Example commands to use by the tenant owning the BGPVPN to associate a Network to it:

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

There are more details in the OpenStack Client (OSC) documentation for BGPVPN.

Use from Horizon

See Horizon.

Use from Heat

See Heat.

Use from Python

The python neutroclient library includes support for the BGPVPN API extensions since Ocata release.

Note

For older releases, the dynamic extension of neutronclient provided in networking-bgpvpn is available. In that case, the methods to list, get, create, delete and update network associations and router associations are different from what is documented here:

  • different name: list_network_associations instead of list_bgpvpn_network_assocs`, and same change for all the methods
  • order of parameters: BGPVPN UUID as first parameter, association UUID as second parameter

These old methods are deprecated.

Methods

BGPVPN Resources

API methods for BGPVPN resources
Method Name Description Input parameter(s) Output
list_bgpvpns() Get the list of defined BGPVPN resources for the current tenant. An optional list of BGPVPN parameters can be used as filter.
  1. Use **kwargs as filter, e.g. list_bgpvpn(param1=val1, param2=val2,…) (Optional)
Dictionary of BGPVPN attributes
create_bgpvpn() Create a BGPVPN resource for the current tenant. Extra information about the BGPVPN resource can be provided as input.
  1. Dictionary of BGPVPN attributes (Optional)
Dictionary of BGPVPN attributes
show_bgpvpn() Get all information for a given BGPVPN.
  1. UUID of the said BGPVPN
Dictionary of BGPVPN attributes related to the BGPVPN provided as input
update_bgpvpn() Update the BGPVPN resource with the parameters provided as input.
  1. UUID of the said BGPVPN
  2. Dictionary of BGPVPN attributes to be updated
Dictionary of BGPVPN attributes
delete_bgpvpn() Delete a given BGPVPN resource of which the UUID is provided as input.
  1. UUID of the said BGPVPN
Boolean

Network Association Resources

API methods for Network association resources
Method Name Description Input parameter(s) Output
list_bgpvpn_network_assocs() Get the list of defined NETWORK ASSOCIATION resources for a given BGPVPN. An optional list of NETWORK ASSOCIATION parameters can be used as filter.
  1. UUID of the BGPVPN
  2. Use **kwargs as filter, e.g. list_bgpvpn_network_assocs( BGPVPN UUID, param1=val1, param2=val2,…) (Optional)
List of dictionaries of NETWORK ASSOCIATION attributes, one of each related to a given BGPVPN
create_bgpvpn_network_assoc() Create a NETWORK ASSOCIATION resource for a given BGPVPN. Network UUID must be defined, provided in a NETWORK ASSOCIATION resource as input parameter.
  1. UUID of the said BGPVPN
  2. Dictionary of NETWORK ASSOCIATION parameters
Dictionary of NETWORK ASSOCIATION attributes
show_bgpvpn_network_assoc() Get all parameters for a given NETWORK ASSOCIATION.
  1. UUID of the BGPVPN resource
  2. UUID of the NETWORK ASSOCIATION resource
Dictionary of NETWORK ASSOCIATION parameters
update_bgpvpn_network_assoc() Update the parameters of the NETWORK ASSOCIATION resource provided as input.
  1. UUID of the BGPVPN resource
  2. UUID of the NETWORK ASSOCIATION resource, 3. Dictionary of NETWORK ASSOCIATION parameters
Dictionary of NETWORK ASSOCIATION parameters
delete_bgpvpn_network_assoc() Delete a given NETWORK ASSOCIATION resource of which the UUID is provided as input.
  1. UUID of the BGPVPN resource
  2. UUID of the NETWORK ASSOCIATION resource
Boolean

Router Association Resources

API methods for Router association resources
Method Name Description Input parameter(s) Output
list_bgpvpn_router_assocs() Get the list of defined ROUTER ASSOCIATION resources for a given BGPVPN. An optional list of ROUTER ASSOCIATION parameters can be used as filter.
  1. UUID of the BGPVPN
  2. Use **kwargs as filter, e.g. list_bgpvpn_router_assocs( BGPVPN UUID, param1=val1, param2=val2,…) (Optional)
List of dictionaries of ROUTER ASSOCIATION attributes, one of each related to a given BGPVPN
create_bgpvpn_router_assoc() Create a ROUTER ASSOCIATION resource for a given BGPVPN. Router UUID must be defined, provided in a ROUTER ASSOCIATION resource as input parameter.
  1. UUID of the said BGPVPN
  2. Dictionary of ROUTER ASSOCIATION parameters
Dictionary of ROUTER ASSOCIATION attributes
show_bgpvpn_router_assoc() Get all parameters for a given ROUTER ASSOCIATION.
  1. UUID of the BGPVPN resource
  2. UUID of the ROUTER ASSOCIATION resource
Dictionary of ROUTER ASSOCIATION parameters
update_bgpvpn_router_assoc() Update the parameters of the ROUTER ASSOCIATION resource provided as input.
  1. UUID of the BGPVPN resource
  2. UUID of the ROUTER ASSOCIATION resource, 3. Dictionary of ROUTER ASSOCIATION parameters
Dictionary of ROUTER ASSOCIATION parameters
delete_bgpvpn_router_assoc() Delete a given ROUTER ASSOCIATION resource of which the UUID is provided as input.
  1. UUID of the BGPVPN resource
  2. UUID of the ROUTER ASSOCIATION resource
Boolean

Port Association Resources

API methods for Port association resources
Method Name Description Input parameter(s) Output
list_bgpvpn_port_assocs() Get the list of defined PORT ASSOCIATION resources for a given BGPVPN. An optional list of PORT ASSOCIATION parameters can be used as filter.
  1. UUID of the BGPVPN
  2. Use **kwargs as filter, e.g. list_bgpvpn_port_assocs( BGPVPN UUID, param1=val1, param2=val2,…) (Optional)
List of dictionaries of PORT ASSOCIATION attributes, one of each related to a given BGPVPN
create_bgpvpn_port_assoc() Create a PORT ASSOCIATION resource for a given BGPVPN. Port UUID must be defined, provided in a PORT ASSOCIATION resource as input parameter.
  1. UUID of the said BGPVPN
  2. Dictionary of PORT ASSOCIATION parameters
Dictionary of PORT ASSOCIATION attributes
show_bgpvpn_port_assoc() Get all parameters for a given PORT ASSOCIATION.
  1. UUID of the BGPVPN resource
  2. UUID of the PORT ASSOCIATION resource
Dictionary of PORT ASSOCIATION parameters
update_bgpvpn_port_assoc() Update the parameters of the PORT ASSOCIATION resource provided as input.
  1. UUID of the BGPVPN resource
  2. UUID of the PORT ASSOCIATION resource, 3. Dictionary of PORT ASSOCIATION parameters
Dictionary of PORT ASSOCIATION parameters
delete_bgpvpn_port_assoc() Delete a given PORT ASSOCIATION resource of which the UUID is provided as input.
  1. UUID of the BGPVPN resource
  2. UUID of the PORT ASSOCIATION resource
Boolean

Examples

BGPVPN + Network Association Resources

# 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
#
#         http://www.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']
Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.