def remove_interface_pc_and_vpc(infra, switch_profile, switches, interface_type, ports, selector, policy_group): """The interface profile, which enables you to specify the interface you want to configure. """ infra_nodep = NodeP(infra, switch_profile) infra_leafs = LeafS(infra_nodep, switch_profile+'_selector_'+''.join(map(str,switches)), DEFAULT_TYPE) infra_accportp = AccPortP(infra, switch_profile + '_ifselector') infra_hports = HPortS(infra_accportp, selector, DEFAULT_TYPE) infra_leafs.delete() infra_nodep.delete() infra_hports.delete() infra_accportp.delete()
def remove_interface_pc_and_vpc(infra, switch_profile, switches, interface_type, ports, selector, policy_group): """The interface profile, which enables you to specify the interface you want to configure. """ infra_nodep = NodeP(infra, switch_profile) infra_leafs = LeafS( infra_nodep, switch_profile + '_selector_' + ''.join(map(str, switches)), DEFAULT_TYPE) infra_accportp = AccPortP(infra, switch_profile + '_ifselector') infra_hports = HPortS(infra_accportp, selector, DEFAULT_TYPE) infra_leafs.delete() infra_nodep.delete() infra_hports.delete() infra_accportp.delete()
def int_profile(host, user, password, port_policy): print('[BEG] Port Profile Configuration') moDir = apic_login(host, user, password) # Get Top Level Objects polUni = Uni('') infraInfra = Infra(polUni) # Variables to keep Ports Consistent intPName = 'ASA-VPC-INT-PROFILE-Cobra' pSPortP = port_policy pSFexId = '101' pS1 = '15' pS2 = '16' # Port Selector Variables #1 - to be used later for other method of input pSName = 'ASA_VPC_Port_Range_' + pS1 + '_to_' + pS2 + '-Cobra' # Port Selector Variables #2 - to be used later for other method of input print('--- Creating Port Profile ' + intPName) infraAccPortP = AccPortP(infraInfra, name=intPName) print(' Adding ' + pSName + ' to Profile: ' + intPName) infraHPortS = HPortS(infraAccPortP, type=u'range', name=pSName) infraRsAccBaseGrp = RsAccBaseGrp(infraHPortS, fexId=pSFexId, tDn=u'uni/infra/funcprof/accbundle-' + pSPortP) infraPortBlk = PortBlk(infraHPortS, name=u'block2', fromPort=pS1, fromCard=u'1', toPort=pS1, toCard=u'1') infraPortBlk2 = PortBlk(infraHPortS, name=u'block3', fromPort=pS2, fromCard=u'1', toPort=pS2, toCard=u'1') cfg_commit(moDir, infraInfra) print('[END] Port Profile Configuration \n') return intPName
def configure_interface_pc_and_vpc(infra, switch_profile, switch_selector, switches, interface_type, interface_selector_profile, interface_selector, policy_group): """The interface profile, which enables you to specify the interface you want to configure. """ infra_accportp = AccPortP(infra, interface_selector_profile) for int_sel_name in interface_selector.keys(): infra_hports = HPortS(infra_accportp, int_sel_name, DEFAULT_TYPE) block = 0 for port in interface_selector[int_sel_name]: block += 1 card, fromPort, toPort = input_ports(port) infra_portblk = PortBlk(infra_hports, 'block' + str(block), fromCard=card, fromPort=fromPort, toPort=toPort) if interface_type == 'individual': policy_group_type = 'accportgrp' elif interface_type in ['pc', 'PC', 'VPC', 'vpc']: policy_group_type = 'accbundle' else: print 'Invalid interface type. Option of interface type is "individual", "pc" or, "vpc".' sys.exit() infra_rsaccbasegrp = RsAccBaseGrp( infra_hports, tDn='uni/infra/funcprof/' + policy_group_type + '-' + policy_group) infra_nodep = NodeP(infra, switch_profile) infra_leafs = LeafS(infra_nodep, switch_selector, DEFAULT_TYPE) single = 0 for switch in switches: single += 1 infra_nodeblk = NodeBlk(infra_leafs, 'single' + str(single), from_=str(switch), to_=str(switch)) infra_rsaccportp = RsAccPortP( infra_nodep, 'uni/infra/accportprof-' + interface_selector_profile)
def configure_interface_pc_and_vpc(modir, switches, switch_profile, ports, selector, policy_group): # Query a parent infra = modir.lookupByDn('uni/infra') infra_accportp = AccPortP(infra, switch_profile + '_ifselector') infra_hports = HPortS(infra_accportp, selector + '_selector', DEFAULT_TYPE) block = 0 for port in ports: block += 1 card, fromPort, toPort = get_numbers(port) infra_portblk = PortBlk(infra_hports, 'block'+str(block), fromCard=card, fromPort=fromPort, toPort=toPort) infra_rsaccbasegrp = RsAccBaseGrp(infra_hports, tDn='uni/infra/funcprof/accportgrp-'+policy_group) infra_nodep = NodeP(infra, switch_profile) infra_leafs = LeafS(infra_nodep, switch_profile+'_selector_'+''.join(map(str,switches)), DEFAULT_TYPE) single = 0 for switch in switches: single += 1 infra_nodeblk = NodeBlk(infra_leafs, 'single'+str(single), from_=str(switch), to_=str(switch)) infra_rsaccportp = RsAccPortP(infra_nodep, 'uni/infra/accportprof-'+switch_profile+'_ifselector') print_query_xml(infra) commit_change(modir, infra)
def main(): module = AnsibleModule(argument_spec=dict( host=dict(required=True), username=dict(type='str', default=''), password=dict(type='str', default=''), protocol=dict(choices=['http', 'https'], default='https'), state=dict(choices=['present', 'absent'], default='present'), switch_profile=dict(type='str', required=True), interface_type=dict(choices=['individual', 'pc', 'vpc'], default='individual'), interface_policy_group=dict(type='str', default=''), interface_port=dict(type='str', default=''), interface_name=dict(type='str', required=True), interface_overwrite=dict(type='bool', default=False), interface_description=dict(type='str', default='')), supports_check_mode=True) if not HAS_COBRA: module.fail_json(msg='Ensure you have the ACI Cobra SDK installed', error=str(ie)) username = module.params['username'] password = module.params['password'] host = module.params['host'] state = module.params['state'].lower() switch_profile = module.params['switch_profile'] interface_type = module.params['interface_type'].lower() interface_policy_group = module.params['interface_policy_group'] interface_port = module.params['interface_port'] interface_description = module.params['interface_description'] interface_name = module.params['interface_name'] interface_overwrite = module.params['interface_overwrite'] moDir = apic_login(host, username, password) infra = moDir.lookupByDn('uni/infra') infra_accportp = None #module will configure interface if state == 'present': if check_if_mo_exist(moDir, 'uni/infra/accportprof-', switch_profile + '_ifselector', AccPortP, 'Interface Profile', return_false=True, set_mo=False): infra_accportp = AccPortP(infra, switch_profile + '_ifselector') else: module.fail_json( msg='Interface Selector Profile ' + switch_profile + ' does not exist. Look under Fabric -> Access Policies -> Interface Policies -> Profiles -> Leaf Profiles' ) # default hports type is range. interface description becomes host selector name infra_hports = HPortS(infra_accportp, interface_name, 'range') configured = check_if_switchport_configured(moDir, switch_profile, interface_port) if configured and not interface_overwrite: module.fail_json( msg='Interface ' + interface_port + ' on ' + switch_profile + ' is already configured. Check profile under Fabric -> Access Policies -> Interface Policies -> Profiles -> Leaf Profiles' ) else: card, fromPort, toPort = input_ports(interface_port) infra_portblk = PortBlk(infra_hports, 'block0', fromCard=card, fromPort=fromPort, toPort=toPort, descr=interface_description) if interface_type == 'individual': policy_group_type = 'accportgrp' moClass = AccPortGrp elif interface_type in ['pc', 'vpc']: policy_group_type = 'accbundle' moClass = AccBndlGrp else: module.fail_json( msg= 'Invalid interface type. Options are "individual", "pc", or "vpc"' ) if check_if_mo_exist(moDir, 'uni/infra/funcprof/' + policy_group_type + '-', interface_policy_group, moClass, 'Interface Policy Group', return_false=True, set_mo=False): infra_rsaccbasegrp = RsAccBaseGrp(infra_hports, tDn='uni/infra/funcprof/' + policy_group_type + '-' + interface_policy_group) else: module.fail_json( changed=True, msg='Interface Policy Group ' + interface_policy_group + ' does not exist. Look under Fabric -> Access Policies -> Interface Policies -> Policy Groups -> Leaf Policy Groups' ) # module will delete interface elif state == "absent": infra_hports = check_if_mo_exist( moDir, 'uni/infra/accportprof-', switch_profile + '_ifselector/hports-' + interface_name + '-typ-range', HPortS, 'Interface Selector Profile', return_false=True, set_mo=False) if infra_hports: infra_hports.delete() else: module.fail_json(msg=' interface name ' + interface_name + ' does not exist.') else: module.fail_json( msg='Invalid interface status. Options are "present" or "absent"') results = {} xmldoc = '' factsdict = {} changed = False # Build configuration and commit if not run in check-mode if infra_accportp and state == 'present': xmldoc = print_query_xml(infra_accportp) factsdict['configuration'] = xmldoc if module.check_mode: module.exit_json(changed=True, ansible_facts=factsdict) else: changed = True commit_change(moDir, infra_accportp, print_xml=False) elif infra_hports and state == 'absent': xmldoc = print_query_xml(infra_hports) factsdict['configuration'] = xmldoc if module.check_mode: module.exit_json(changed=True, ansible_facts=factsdict) else: changed = True commit_change(moDir, infra_hports, print_xml=False) results['xmldoc'] = xmldoc results['state'] = state results['changed'] = changed module.exit_json(ansible_facts=factsdict, **results)