Created
October 20, 2015 21:57
-
-
Save ajayhn/38a4925d5c8399528227 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import os | |
from vnc_api import vnc_api | |
username = os.environ['OS_USERNAME'] | |
password = os.environ['OS_PASSWORD'] | |
tenant_name = os.environ['OS_TENANT_NAME'] | |
lib = vnc_api.VncApi( | |
username=username, password=password, tenant_name=tenant_name) | |
for vn_obj in lib.virtual_networks_list(detail=True): | |
for ipam_ref in vn_obj.get_network_ipam_refs() or []: | |
for ipam_subnet in ipam_ref['attr'].ipam_subnets or []: | |
subnet_key = '%s %s/%s' %(vn_obj.uuid, | |
ipam_subnet.subnet.ip_prefix, | |
ipam_subnet.subnet.ip_prefix_len) | |
subnet_uuid = ipam_subnet.subnet_uuid | |
try: | |
lib.kv_retrieve(subnet_key) | |
except vnc_api.NoIdError: | |
lib.kv_store(subnet_key, subnet_uuid) | |
try: | |
lib.kv_retrieve(subnet_uuid) | |
except vnc_api.NoIdError: | |
lib.kv_store(subnet_uuid, subnet_key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment