Skip to content

Instantly share code, notes, and snippets.

@NeilHanlon
Last active July 11, 2018 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NeilHanlon/7b61349311b9d25be122d0672b4558d3 to your computer and use it in GitHub Desktop.
Save NeilHanlon/7b61349311b9d25be122d0672b4558d3 to your computer and use it in GitHub Desktop.
from bcf_methods import BigCloudFabric
import pprint
import csv
import yaml
def main():
segment_info = []
with open('/home/nhanlon/Downloads/Kayak-SomervilleNetwork-Discovery - Segments.csv', 'rb') as f:
data = csv.DictReader(
f,
fieldnames=['Tenant', 'VlanID', 'VlanDescription', 'Subnet', 'Routers', 'RouterIPs', 'FirewallIPs', 'SwitchIPs', 'OSPFArea', 'Comments'],
delimiter=',',
quotechar='"',
)
next(data, None) # Skip over headers
for i in data:
segment_info.append(i)
api = BigCloudFabric(controller_ip="<redacted>", username="admin", password='<redacted>')
for segment in segment_info:
print(segment)
tenant_name = segment['Tenant']
vlan_id = segment['VlanID']
segment_name = segment['VlanDescription']
subnet = segment['Subnet']
res = api.create_tenant(tenant_name)
if not res:
print("Tenant {} already exists".format(tenant_name))
else:
print("Created Tenant: {}".format(tenant_name))
description = yaml.safe_dump(segment, default_flow_style=False)
# Segments can't contain spaces. Make them underscores?
segment_name = segment_name.replace(" ", "_")
# Segment names can't contain Slashes, take everything after the last /
segment_name = segment_name[(segment_name.rfind('/')+1):len(segment_name)]
res = api.create_segment(tenant_name, segment_name, description)
if not res:
print("Segment '{}' already exists in Tenant '{}'".format(segment_name, tenant_name))
else:
print("Created Segment '{}' in Tenant '{}'".format(segment_name, tenant_name))
print len(segment_info)
production_segments = api.get_segments('Production')
pprint.pprint(production_segments[0])
pprint.pprint(yaml.load(production_segments[0]['description']))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment