Created
December 11, 2018 04:22
-
-
Save ranganathanm/3b6681cb0ed2cffb0f25c50058cce673 to your computer and use it in GitHub Desktop.
Determine the internal vlan tag that openstack uses on br-int for a given provider network id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keystoneauth1 import identity | |
from keystoneauth1 import session | |
from neutronclient.v2_0 import client | |
from ovs_vsctl import VSCtl | |
from argparse import ArgumentParser | |
import ovs_vsctl.parser as ovs_vsctl_parser | |
import pdb | |
import os | |
""" | |
If you want to find the internal vlan tag that openstack assigns for a given provider segmentation ID | |
run this script on the neutron node with the following invocation | |
python find-internal-tag-for-network.py 300 | |
""" | |
if __name__ == "__main__": | |
parser = ArgumentParser() | |
parser.add_argument("network_segementation_id", default=None, help="OpenStack Network ID") | |
args = parser.parse_args() | |
network_segmentation_id = args.network_segementation_id | |
username= os.environ.get("OS_USERNAME") | |
password= os.environ.get("OS_PASSWORD") | |
project_name= os.environ.get("OS_PROJECT_NAME") | |
project_domain_id='default' | |
if os.environ.get("OS_PROJECT_DOMAIN_NAME") is not None: | |
project_domain_id = os.environ.get("OS_PROJECT_DOMAIN_NAME") | |
user_domain_id='default' | |
if os.environ.get("OS_USER_DOMAIN_NAME") is not None: | |
user_domain_id= os.environ.get("OS_USER_DOMAIN_NAME") | |
auth_url= os.environ.get("OS_AUTH_URL") | |
if auth_url is None: | |
print "Missing auth url ... set OS_AUTH_URL environment variable" | |
sys.exit() | |
auth = identity.Password(auth_url=auth_url, | |
username=username, | |
password=password, | |
project_name=project_name, | |
project_domain_id=project_domain_id, | |
user_domain_id=user_domain_id) | |
sess = session.Session(auth=auth) | |
neutron = client.Client(session=sess) | |
networks = neutron.list_networks()['networks'] | |
network_id = 0 | |
for network in networks: | |
if network['provider:segmentation_id'] == int(network_segmentation_id): | |
network_id = network['id'] | |
vsctl = VSCtl('tcp', '127.0.0.1', 6640) | |
ports = vsctl.run(command='list port',parser=ovs_vsctl_parser.list_cmd_parser) | |
for port in ports: | |
other_config = port.other_config | |
if 'net_uuid' in other_config and str(other_config['net_uuid']) == network_id: | |
print "internal vlan tag = ", other_config['tag'] | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment