Skip to content

Instantly share code, notes, and snippets.

@NeilHanlon
Created July 12, 2018 22:12
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/2660f0e3a8298c74948b884675279ed6 to your computer and use it in GitHub Desktop.
Save NeilHanlon/2660f0e3a8298c74948b884675279ed6 to your computer and use it in GitHub Desktop.
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