Skip to content

Instantly share code, notes, and snippets.

Created Jul 12, 2018
What would you like to do?
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.")
# 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.")
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:
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))
print("Successfully added Interface Group to Segment '{}'".format(segment_name))
except urllib2.HTTPError as e:
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