Created
July 12, 2018 22:12
-
-
Save NeilHanlon/2660f0e3a8298c74948b884675279ed6 to your computer and use it in GitHub Desktop.
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
def assign_interface_group_to_segment(vlans, interface_groups): | |
if not ( type(vlans) is list ) and ( type(interface_groups) is list): | |
print("Parameters must be supplied as a list.") | |
return | |
# Lets go ahead and normalize the vlan list into strings because I'm nice to myself... | |
vlans = [str(vlan) for vlan in vlans] | |
segments = [segment for segment in segment_info if segment[':vlan_tag'] in vlans] | |
if not len(segments) > 0: | |
print("No segments matched for VLAN ids.") | |
return | |
for segment in segments: | |
tenant_name = segment[':tenant'] | |
segment_name = segment[':description'] | |
vlan_id = segment[':vlan_tag'] | |
segment_name = api.normalize_segment_name(segment_name) | |
for interface_group in interface_groups: | |
try: | |
res = api.add_interface_group_to_segment(tenant_name, segment_name, interface_group, vlan_id) | |
if not res: | |
print("Interface group not successfully added to Segment '{}' (Or already in segment)".format(segment_name)) | |
else: | |
print("Successfully added Interface Group to Segment '{}'".format(segment_name)) | |
except urllib2.HTTPError as e: | |
resp = e.read() | |
pprint.pprint(resp) | |
if __name__ == '__main__': | |
vlans = ['71', '73', '80', '666'] | |
interface_group = ['Blade23'] | |
assign_interface_group_to_segment(vlans, interface_group) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment