Skip to content

Instantly share code, notes, and snippets.

@NeilHanlon
Last active Jul 11, 2018
Embed
What would you like to do?
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