def main_function(self): # set Autonomous System Number bgp_instpol = self.look_up_mo('uni/fabric/bgpInstP-default', '') setAutonomousSystemNumber.set_autonomous_system_number(bgp_instpol, self.autonomous_system_number) self.commit_change() # create Bpg Route Reflector bgp_rrp = self.look_up_mo('uni/fabric/bgpInstP-default/rr', '') for reflector_id in self.reflector_id: createBgpRouteReflector.create_bgp_route_reflector(bgp_rrp, reflector_id) self.commit_change() # create Pod Policy group fabric_funcp = self.look_up_mo('uni/fabric/funcprof/', '') createPodPolicyGroup.create_pod_policy_group(fabric_funcp, self.pod_policy_group['name'], optional_args=self.pod_policy_group['optional_args']) self.commit_change() # select Pod Policy bgp_pods = self.look_up_mo('uni/fabric/podprof-default/pods-default-typ-ALL', '') selectPodPolicy.select_pod_policy(bgp_pods, self.pod_policy_group['name']) # create Bpg Route Outside Network self.check_if_tenant_exist() l3ext_out = createRoutedOutside.create_routed_outside(self.mo, self.routed_outside['name'], optional_args=self.routed_outside['optional_args']) self.commit_change() # create Node-And-Interface Profile l3ext_lnodep = createNodesAndInterfacesProfile.create_node_profile(l3ext_out, self.node_profile['name'], optional_args=self.node_profile['optional_args']) self.commit_change(l3ext_out) # create Nodes And Interfaces createNodes.create_node(l3ext_lnodep, str(self.leaf_id), str(self.router_id)) l3ext_lifp = createInterfaceProfile.create_interface_profile(l3ext_lnodep, self.interface_profile['name']) self.commit_change(l3ext_lnodep) # create Routed Interface Profile createRoutedInterfaceProfile.create_routed_interface_profile(l3ext_lifp, str(self.interface_profile['leaf_id']), str(self.interface_profile['eth_num']), self.interface_profile['ip_address'], optional_args=self.interface_profile['optional_args']) self.commit_change(l3ext_lifp) # create External Network l3ext_instp = createExternalNetwork.create_external_network(l3ext_out, self.external_network_epg['name'], optional_args=self.external_network_epg['optional_args']) self.commit_change(l3ext_out) # configure provider/consumer for L3 outside network. createL3EpgProviderOrConsumerContract.create_L3_epg_provider_or_consumer_contract(l3ext_instp, 'provided', self.provider_contract['name'], optional_args=self.provider_contract['optional_args']) createL3EpgProviderOrConsumerContract.create_L3_epg_provider_or_consumer_contract(l3ext_instp, 'consumed', self.consumer_contract['name'], optional_args=self.consumer_contract['optional_args']) self.commit_change() # Set default settings for private network. self.check_if_mo_exist('uni/tn-' + self.tenant + '/ctx-', self.private_network['name'], Ctx, description='Private Network') setDefaultSettingForPrivateNetwork.set_default_setting_for_private_network(self.mo, optional_args=self.private_network['optional_args']) self.commit_change() # Associate the L3 Outside Network to a Birdge Domain. self.check_if_mo_exist('uni/tn-' + self.tenant + '/BD-', self.bridge_domain, BD, description='Bridge Domain') associateL3OutsideNetworkToBD.associate_l3_outside_network_to_bd(self.mo, self.routed_outside['name'])
def lab7A(modir, pod_policy): """Setup the Pod Policies""" # Set Autonomous System Number set_autonomous_system_number(modir, '1') # Create BGP Route Reflector create_bgp_route_reflector(modir, '103') create_bgp_route_reflector(modir, '104') # Create Policy Group create_pod_policy_group(modir, pod_policy, tnBgpInstPolName='default', tnIsisDomPolName='', tnCoopPolName='', tnDatetimePolName='', tnCommPolName='', tnSnmpPolName='') # Select Fabric Policy Group select_pod_policy(modir, pod_policy)
parser = argparse.ArgumentParser(description='Configure fabric pod policy.') parser.add_argument('yaml', help='Imported yaml file.') args = vars(parser.parse_args()) try: data = read_config_yaml_file(args['yaml'], login_info=False) except IOError: print 'No such file or directory:', args['yaml'] sys.exit() else: host, user, password = get_login_info(data) modir = apic_login(host, user, password) # Set Autonomous System Number set_autonomous_system_number(modir, data['autonomous_system_number']) # Create BGP Route Reflector for reflector in data['reflector_id']: create_bgp_route_reflector(modir, reflector) # Create Policy Group for group in data['pod_policy_group']: create_pod_policy_group(modir, group['name'], tnBgpInstPolName=group[ 'bgp_route_reflector_policy'], tnIsisDomPolName=group['isis_policy'], tnCoopPolName=group['coop_group_policy'], tnDatetimePolName=group['date_time_policy'], tnCommPolName=group['communication_policy'], tnSnmpPolName=group['snmp_policy'])
if __name__ == "__main__": # Login hostname, username, password = input_login_info(msg="") try: modir = apic_login(hostname, username, password) print "Login succeed." except KeyError: print "Login fail." sys.exit() # Wizard starts asking inputs step by step autonomous_system_number = setAutonomousSystemNumber.input_key_args() bgp_route_reflector_array = add_mos(createBgpRouteReflector.input_key_args, "Create a BGP Route Reflector") pod_policy_array = add_mos_with_options( createPodPolicyGroup.input_key_args, createPodPolicyGroup.input_optional_args, "Create a Pod Policy" ) selected_pod_policy = selectPodPolicy.input_key_args() # Running setAutonomousSystemNumber.set_autonomous_system_number(modir, autonomous_system_number) for bgp_route_reflector in bgp_route_reflector_array: createBgpRouteReflector.create_bgp_route_reflector(modir, bgp_route_reflector) for pod_policy in pod_policy_array: print pod_policy createPodPolicyGroup.create_pod_policy_group(modir, pod_policy[0], args_from_CLI=pod_policy[1]) selectPodPolicy.select_pod_policy(modir, selected_pod_policy) modir.logout()
parser = argparse.ArgumentParser( description='Configure fabric pod policy.') parser.add_argument('yaml', help='Imported yaml file.') args = vars(parser.parse_args()) try: data = read_config_yaml_file(args['yaml'], login_info=False) except IOError: print 'No such file or directory:', args['yaml'] sys.exit() else: host, user, password = get_login_info(data) modir = apic_login(host, user, password) # Set Autonomous System Number set_autonomous_system_number(modir, data['autonomous_system_number']) # Create BGP Route Reflector for reflector in data['reflector_id']: create_bgp_route_reflector(modir, reflector) # Create Policy Group for group in data['pod_policy_group']: create_pod_policy_group( modir, group['name'], tnBgpInstPolName=group['bgp_route_reflector_policy'], tnIsisDomPolName=group['isis_policy'], tnCoopPolName=group['coop_group_policy'], tnDatetimePolName=group['date_time_policy'], tnCommPolName=group['communication_policy'],
def main_function(self): # set Autonomous System Number bgp_instpol = self.look_up_mo('uni/fabric/bgpInstP-default', '') setAutonomousSystemNumber.set_autonomous_system_number( bgp_instpol, self.autonomous_system_number) self.commit_change() # create Bpg Route Reflector bgp_rrp = self.look_up_mo('uni/fabric/bgpInstP-default/rr', '') for reflector_id in self.reflector_id: createBgpRouteReflector.create_bgp_route_reflector( bgp_rrp, reflector_id) self.commit_change() # create Pod Policy group fabric_funcp = self.look_up_mo('uni/fabric/funcprof/', '') createPodPolicyGroup.create_pod_policy_group( fabric_funcp, self.pod_policy_group['name'], optional_args=self.pod_policy_group['optional_args']) self.commit_change() # select Pod Policy bgp_pods = self.look_up_mo( 'uni/fabric/podprof-default/pods-default-typ-ALL', '') selectPodPolicy.select_pod_policy(bgp_pods, self.pod_policy_group['name']) # create Bpg Route Outside Network self.check_if_tenant_exist() l3ext_out = createRoutedOutside.create_routed_outside( self.mo, self.routed_outside['name'], optional_args=self.routed_outside['optional_args']) self.commit_change() # create Node-And-Interface Profile l3ext_lnodep = createNodesAndInterfacesProfile.create_node_profile( l3ext_out, self.node_profile['name'], optional_args=self.node_profile['optional_args']) self.commit_change(l3ext_out) # create Nodes And Interfaces createNodes.create_node(l3ext_lnodep, str(self.leaf_id), str(self.router_id)) l3ext_lifp = createInterfaceProfile.create_interface_profile( l3ext_lnodep, self.interface_profile['name']) self.commit_change(l3ext_lnodep) # create Routed Interface Profile createRoutedInterfaceProfile.create_routed_interface_profile( l3ext_lifp, str(self.interface_profile['leaf_id']), str(self.interface_profile['eth_num']), self.interface_profile['ip_address'], optional_args=self.interface_profile['optional_args']) self.commit_change(l3ext_lifp) # create External Network l3ext_instp = createExternalNetwork.create_external_network( l3ext_out, self.external_network_epg['name'], optional_args=self.external_network_epg['optional_args']) self.commit_change(l3ext_out) # configure provider/consumer for L3 outside network. createL3EpgProviderOrConsumerContract.create_L3_epg_provider_or_consumer_contract( l3ext_instp, 'provided', self.provider_contract['name'], optional_args=self.provider_contract['optional_args']) createL3EpgProviderOrConsumerContract.create_L3_epg_provider_or_consumer_contract( l3ext_instp, 'consumed', self.consumer_contract['name'], optional_args=self.consumer_contract['optional_args']) self.commit_change() # Set default settings for private network. self.check_if_mo_exist('uni/tn-' + self.tenant + '/ctx-', self.private_network['name'], Ctx, description='Private Network') setDefaultSettingForPrivateNetwork.set_default_setting_for_private_network( self.mo, optional_args=self.private_network['optional_args']) self.commit_change() # Associate the L3 Outside Network to a Birdge Domain. self.check_if_mo_exist('uni/tn-' + self.tenant + '/BD-', self.bridge_domain, BD, description='Bridge Domain') associateL3OutsideNetworkToBD.associate_l3_outside_network_to_bd( self.mo, self.routed_outside['name'])
import selectPodPolicy if __name__ == '__main__': # Login hostname, username, password = '******', 'admin', 'Cisco123' # input_login_info(msg='') try: modir = apic_login(hostname, username, password) print 'Login succeed.' except KeyError: print 'Login fail.' sys.exit() # Wizard starts asking inputs step by step autonomous_system_number = setAutonomousSystemNumber.input_key_args() bgp_route_reflector_array = add_mos(createBgpRouteReflector.input_key_args, 'Create a BGP Route Reflector') pod_policy_array = add_mos_with_options(createPodPolicyGroup.input_key_args, createPodPolicyGroup.input_optional_args, 'Create a Pod Policy') selected_pod_policy = selectPodPolicy.input_key_args() # Running setAutonomousSystemNumber.set_autonomous_system_number(modir, autonomous_system_number) for bgp_route_reflector in bgp_route_reflector_array: createBgpRouteReflector.create_bgp_route_reflector(modir, bgp_route_reflector) for pod_policy in pod_policy_array: print pod_policy createPodPolicyGroup.create_pod_policy_group(modir, pod_policy[0], args_from_CLI=pod_policy[1]) selectPodPolicy.select_pod_policy(modir, selected_pod_policy) modir.logout()