Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def add_interface_group_to_segment(self, tenant_name, segment_name, interface_group_name, vlan_id):
segments = self.get_segments(tenant_name)
interface_groups = self.get_interface_groups()
segment_membership = self.get_segment_interface_groups(tenant_name, segment_name)
verb = self.verb_check(segment_membership)
segment_exists, dummy = self.resource_exists(segments, 'name', segment_name)
interface_group_exists, dummy = self.resource_exists(interface_groups, 'name', interface_group_name)
interface_assigned_to_segment, dummy = self.resource_exists(segment_membership, 'interface-group', interface_group_name)
if segment_exists and interface_group_exists and not interface_assigned_to_segment:
data = {"vlan": vlan_id, "interface-group": interface_group_name}
uri = '/api/v1/data/controller/applications/bcf/tenant[name="' + tenant_name + '"]/segment[name="%s"]/interface-group-membership-rule' % segment_name
self.api_call(uri, verb, data)
return True
else:
return False # 'Interface already assigned to segment'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment