def main(import_apic, import_cookie): global apic global cookie cookie = import_cookie apic = import_apic while True: clear_screen() location_banner('Show EPGs to interface') all_leaflist = get_All_leafs(apic, cookie) if all_leaflist == []: print( '\x1b[1;31;40mFailed to retrieve active leafs, make leafs are operational...\x1b[0m' ) custom_raw_input('\n#Press enter to continue...') return print('\nSelect leaf(s): ') print('\r') chosenleafs = physical_leaf_selection(all_leaflist, apic, cookie) for leaf in chosenleafs: switchpreviewutil.main(apic, cookie, [leaf], purpose='port_switching') vlanlist = pull_vlan_info_for_leaf(apic, cookie, [leaf]) epgvlanlist = [x.dn for x in vlanlist] interface_epg_pull(apic, cookie, vlanlist, [leaf]) custom_raw_input('Continue...')
def display_vlan_operations(leafs): for leaf in leafs: switchpreviewutil.main(apic,cookie,[leaf], purpose='port_switching') print('\n') bdlist = pull_bd_info_for_leaf(apic, cookie, leaf) #import pdb; pdb.set_trace() vlanlist = pull_vlan_info_for_leaf(apic, cookie, leaf) bdandvlanlist = bdlist + vlanlist finalbdandvlanlistforsorting = [] for x in sorted(bdandvlanlist, key=lambda x : int(x.id)): if hasattr(x, 'encap'): finalbdandvlanlistforsorting.append(('EPG', x.id, x.encap, x)) else: finalbdandvlanlistforsorting.append(('BD', x.id, x.name)) print("{:5} | {:10} | {:10} | {}".format('Type', "Internal #", "Encap", "Name")) print('-' * 80) for x in sorted(finalbdandvlanlistforsorting, key=lambda x: (x[0], int(x[1]))): if len(x) > 3 and 'LDevInst' in x[3].app(x): #import pdb; pdb.set_trace() print("{:5} | {:^10} | {:11} | {}:{}".format(x[0], x[1], x[2], x[3].tenant, x[3].app(x[3]))) elif len(x) > 3: print("{:5} | {:^10} | {:11} | {}:{}:{}".format(x[0], x[1], x[2], x[3].tenant, x[3].app(x[3]), x[3].epg)) else: print("{:5} | {:^10} | {:11} | {}".format(x[0], x[1], '', x[2])) pull_interface_with_vlaninfo(apic, cookie, leaf) print('\n')
def main(import_apic, import_cookie): while True: global apic global cookie cookie = import_cookie apic = import_apic allepglist = get_All_EGPs(apic, cookie) allpclist = get_All_PCs(apic, cookie) allvpclist = get_All_vPCs(apic, cookie) all_leaflist = get_All_leafs(apic, cookie) clear_screen() location_banner('Adding EPGs') selection = interface_menu() if selection == '1': chosenleafs = physical_leaf_selection(all_leaflist, apic, cookie) switchpreviewutil.main(apic, cookie, chosenleafs, purpose='port_switching') returnedlist = physical_interface_selection(apic, cookie, chosenleafs, provideleaf=False) #returnedlist = physical_selection(all_leaflist, apic, cookie) #import pdb; pdb.set_trace() chosenepgs, choseninterfaceobjectlist = display_and_select_epgs( returnedlist, allepglist) #import pdb; pdb.set_trace() interface_type_and_deployement(chosenepgs, choseninterfaceobjectlist, apic) print('\r') custom_raw_input('#Press enter to continue...') elif selection == '2': returnedlist = port_channel_selection(allpclist) chosenepgs, choseninterfaceobjectlist = display_and_select_epgs( returnedlist, allepglist) interface_type_and_deployement(chosenepgs, choseninterfaceobjectlist, apic, type="Port-Channel") #port_channel_selection(allpclist,allepglist) print('\r') custom_raw_input('#Press enter to continue...') elif selection == '3': returnedlist = port_channel_selection(allvpclist) chosenepgs, choseninterfaceobjectlist = display_and_select_epgs( returnedlist, allepglist) interface_type_and_deployement(chosenepgs, choseninterfaceobjectlist, apic, type="vPort-Channel") print('\r') custom_raw_input('#Press enter to continue...')
def main(import_apic,import_cookie): while True: global apic global cookie cookie = import_cookie apic = import_apic allepglist = get_All_EGPs_names(apic,cookie) allpclist = get_All_PCs(apic,cookie) allvpclist = get_All_vPCs(apic,cookie) all_leaflist = get_All_leafs(apic,cookie) clear_screen() location_banner('Removing EPGs') selection = interface_menu() if selection == '1': chosenleafs = physical_leaf_selection(all_leaflist, apic, cookie) switchpreviewutil.main(apic,cookie,chosenleafs, purpose='port_switching') interfacelist = physical_interface_selection(apic, cookie, chosenleafs, provideleaf=False) #interfacelist = physical_selection(all_leaflist, apic, cookie) #print(interfaces) print('What would you like to do for static EPGS on Port(s)?:\n\n' + '1.) Remove ALL EPGs\n' + '2.) Remove Selected from all interfaces\n') #+ '3.) Remove based on individual interface selection\n\n') while True: removaloption = custom_raw_input('Selection: ') if removaloption == '1': while True: verify = custom_raw_input('\nContinue removal of EPGs? [y|n]: ') if verify == '': print("\n\x1b[1;37;41mInvalid option...Try again\x1b[0m\n") continue elif verify[0].lower() == 'y': break elif verify[0].lower() == 'n': raise KeyboardInterrupt else: print("\n\x1b[1;37;41mInvalid option...Try again\x1b[0m\n") continue remove_all_epgs_every_interface(interfacelist, apic, cookie) break elif removaloption == '2': remove_selection_from_all_interfaces(interfacelist, apic, cookie) break #elif removaloption == '3': # remove_per_interface(interfacelist, apic, cookie) # break else: print("\n\x1b[1;37;41mInvalid option...Try again\x1b[0m\n") elif selection == '2': interfacelist = port_channel_selection(allpclist) #print(interfaces) print('What would you like to do for static EPGS on Port(s)?:\n\n' + '1.) Remove ALL EPGs\n' + '2.) Remove Selected from all interfaces\n\n') #+ '3.) Remove based on individual interface selection\n\n') while True: removaloption = custom_raw_input('Selection: ') if removaloption == '1': remove_all_epgs_every_interface(interfacelist, apic, cookie) break elif removaloption == '2': remove_selection_from_all_interfaces(interfacelist, apic, cookie) break #elif removaloption == '3': # remove_per_interface(interfacelist, apic, cookie) # break else: print("\n\x1b[1;37;41mInvalid option...Try again\x1b[0m\n") elif selection == '3': interfacelist = port_channel_selection(allvpclist) print('What would you like to do for static EPGS on Port(s)?:\n\n' + '1.) Remove ALL EPGs\n' + '2.) Remove Selected from all interfaces\n\n') #+ '3.) Remove based on individual interface selection\n\n') while True: removaloption = custom_raw_input('Selection: ') if removaloption == '1': remove_all_epgs_every_interface(interfacelist, apic, cookie) break elif removaloption == '2': remove_selection_from_all_interfaces(interfacelist, apic, cookie) break # elif removaloption == '3': # remove_per_interface(interfacelist, apic, cookie) # break else: print("\n\x1b[1;37;41mInvalid option...Try again\x1b[0m\n")
def main(import_apic, import_cookie): global apic global cookie cookie = import_cookie apic = import_apic clear_screen() location_banner('Show interface counters and EPGs') while True: all_leaflist = get_All_leafs(apic, cookie) if all_leaflist == []: print( '\x1b[1;31;40mFailed to retrieve active leafs, make leafs are operational...\x1b[0m' ) custom_raw_input('\n#Press enter to continue...') return print('\nSelect leaf(s): ') print('\r') # desiredleaf = custom_custom_raw_input("\nWhat is the desired \x1b[1;33;40m'Source and Destination'\x1b[0m leaf for span session?\r") #print("\nWhat is the desired \x1b[1;33;40m'Destination'\x1b[0m leaf for span session?\r") chosenleafs = physical_leaf_selection(all_leaflist, apic, cookie) switchpreviewutil.main(apic, cookie, chosenleafs, purpose='port_switching') chosendestinterfaceobject = physical_interface_selection( apic, cookie, chosenleafs, provideleaf=False) leaf = chosenleafs #chosendestinterfaceobject, leaf = physical_selection(all_leaflist, apic, cookie, provideleaf=True) #import pdb; pdb.set_trace() interface = chosendestinterfaceobject[0].name epgurl = """https://{apic}/api/node-{leaf}/mo/sys/phys-[{interface}].json?rsp-subtree-include=full-deployment&target-node=all&target-path=l1EthIfToEPg""".format( interface=str(interface), leaf=str(leaf[0]), apic=apic) #url = """https://{apic}/api/node/mo/{path}.json?rsp-subtree-include=full-deployment&target-node=all&target-path=l1EthIfToEPg""".format(apic=apic,path=str(chosendestinterfaceobject[0])) logger.info(epgurl) epgresult = GetResponseData(epgurl, cookie) logger.debug(epgresult) url = """https://{apic}/api/node-{leaf}/mo/sys/phys-[{interface}].json?""".format(interface=str(interface),leaf=str(leaf[0]),apic=apic) \ + """query-target=subtree&rsp-subtree-include=stats&target-subtree-class=rmonIfOut,l1PhysIf,""" \ + """rmonIfIn,rmonEtherStats,ethpmPhysIf,l1RsAttEntityPCons,"""\ + """l1RsCdpIfPolCons,l1RtMbrIfs,pcAggrMbrIf,fvDomDef,eqptIngrTotal5min,eqptEgrTotal5min""" logger.info(url) result = GetResponseData(url, cookie) clear_screen() while True: interfaceObject = l1PhysIf(interface) for x in result: if x.get('rmonIfIn'): interfaceObject.rmonIfIn = x['rmonIfIn']['attributes'] elif x.get('rmonIfOut'): interfaceObject.rmonIfOut = x['rmonIfOut']['attributes'] elif x.get('rmonEtherStats'): interfaceObject.rmonEtherStats = x['rmonEtherStats'][ 'attributes'] elif x.get('ethpmPhysIf'): interfaceObject.ethpmPhysIf = x['ethpmPhysIf'][ 'attributes'] elif x.get('l1PhysIf'): interfaceObject.add_phys_attr(x['l1PhysIf']['attributes']) for y in x['l1PhysIf']['children']: if y.get('eqptIngrTotal5min'): interfaceObject.eqptIngrTotal5min = y[ 'eqptIngrTotal5min']['attributes'] elif y.get('eqptEgrTotal5min'): interfaceObject.eqptEgrTotal5min = y[ 'eqptEgrTotal5min']['attributes'] elif x.get('fvDomDef'): interfaceObject.fvDomDef.append( x['fvDomDef']['attributes']) elif x.get('l1RsAttEntityPCons'): interfaceObject.l1RsAttEntityPCons = x[ 'l1RsAttEntityPCons']['attributes'] elif x.get('l1RsCdpIfPolCons'): interfaceObject.l1RsCdpIfPolCons = x['l1RsCdpIfPolCons'][ 'attributes'] elif x.get('l1RtMbrIfs'): interfaceObject.l1RtMbrIfs.append( x['l1RtMbrIfs']['attributes']) elif x.get('pcAggrMbrIf'): interfaceObject.pcAggrMbrIf.append( x['pcAggrMbrIf']['attributes']) if interfaceObject.switchingSt == 'enabled' and interfaceObject.ethpmPhysIf[ 'operSt'] == 'up' and not 'blacklist' in interfaceObject.usage: link_status = 'up/up' elif interfaceObject.switchingSt == 'disabled' and interfaceObject.ethpmPhysIf[ 'operSt'] == 'up' and not 'blacklist' in interfaceObject.usage: link_status = 'up/down' else: link_status = 'down/down' if 'blacklist' in interfaceObject.usage: print('\n {} is Administratively Down'.format( interface.capitalize())) else: print('\n {} is admin {}, link-status is {}'.format( interface.capitalize(), interfaceObject.adminSt, link_status)) print(' Description: {}'.format(interfaceObject.descr)) print(' MAC: {}'.format( interfaceObject.ethpmPhysIf['backplaneMac'])) print(' Speed: {}, Duplex: {}, MTU: {}'.format( interfaceObject.ethpmPhysIf['operSpeed'], interfaceObject.ethpmPhysIf['operDuplex'].upper(), interfaceObject.mtu)) print(' Auto negotiation: {}'.format(interfaceObject.autoNeg)) print(' Operational layer: {}'.format(interfaceObject.layer)) print(' Spanning destination interface: {}'.format( interfaceObject.spanMode)) if interfaceObject.ethpmPhysIf['bundleIndex'] != 'unspecified': print(' Portchannal #: {}, Po name: (incomplete)'.format( interfaceObject.ethpmPhysIf['bundleIndex'])) #if interfaceObject.l1RtMbrIfs: # for interf in interfaceObject.l1RtMbrIfs: #print(interf['tDn']) #print(interf['tSKey']) if interfaceObject.pcAggrMbrIf: for interf in interfaceObject.pcAggrMbrIf: print(' Port-Channel Type: {}'.format( interf['pcMode'])) if interfaceObject.ethpmPhysIf['allowedVlans'] == '': interfaceObject.ethpmPhysIf['allowedVlans'] = 'None,' if interfaceObject.ethpmPhysIf['operVlans'] == '': interfaceObject.ethpmPhysIf['operVlans'] = 'None' print(' Configured internal vlans: {} Working internal vlans: {}'. format(interfaceObject.ethpmPhysIf['allowedVlans'], interfaceObject.ethpmPhysIf['operVlans'])) print('') if interfaceObject.eqptEgrTotal5min == None: print(' [5 min] Input packet rate 0, Input Byte rate: 0') print(' [5 min] Output packet rate 0, Output Byte rate: 0') else: print( ' [5 min] Input packet rate {}, Input Byte rate: {}'. format( round( float( interfaceObject.eqptIngrTotal5min['pktsRate']), 2), round( float(interfaceObject. eqptIngrTotal5min['bytesRate']), 2))) print( ' [5 min] Output packet rate {}, Output Byte rate: {}'. format( round( float( interfaceObject.eqptEgrTotal5min['pktsRate']), 2), round( float( interfaceObject.eqptEgrTotal5min['bytesRate']), 2))) print(' RX') print( ' input packets {}, bytes {}, broadcasts {}, mutlicasts {}' .format(interfaceObject.rmonEtherStats['tXNoErrors'], interfaceObject.rmonIfIn['octets'], interfaceObject.rmonIfIn['broadcastPkts'], interfaceObject.rmonIfIn['multicastPkts'])) print( ' input errors {}, giants {}, crc {}, fragments {}, oversize {}' .format(interfaceObject.rmonIfIn['errors'], interfaceObject.rmonEtherStats['rxGiantPkts'], interfaceObject.rmonEtherStats['cRCAlignErrors'], interfaceObject.rmonEtherStats['fragments'], interfaceObject.rmonEtherStats['rxOversizePkts'])) print(' TX') print( ' output packets {}, bytes {}, broadcasts {}, mutlicasts {}' .format(interfaceObject.rmonEtherStats['rXNoErrors'], interfaceObject.rmonIfOut['octets'], interfaceObject.rmonIfOut['broadcastPkts'], interfaceObject.rmonIfOut['multicastPkts'])) print(' output errors {}, collisions {}, jabbers {}, drops {}'. format(interfaceObject.rmonIfOut['errors'], interfaceObject.rmonEtherStats['collisions'], interfaceObject.rmonEtherStats['jabbers'], interfaceObject.rmonEtherStats['dropEvents'])) print('') print(' EPGs configured: {}'.format(interfaceObject.switchingSt)) #if interfaceObject.switchingSt == 'enabled': print('') print(' {:10}{:15}{}'.format('Tenant', 'APP', 'EPG')) print(' ' + '-' * 40) displayepgs(epgresult) # print(' EPGs: ') print(' Configured usage type: {}'.format(interfaceObject.usage)) print('\n Availabe Domains: ') if interfaceObject.fvDomDef: for interf in interfaceObject.fvDomDef: print(' {}'.format(interf['domPKey'])) print('\n Profiles:') if interfaceObject.l1RsAttEntityPCons: print(' {}'.format(interfaceObject.l1RsAttEntityPCons['tDn'])) if interfaceObject.l1RsCdpIfPolCons: print(' {}'.format(interfaceObject.l1RsCdpIfPolCons['tDn'])) #if interfaceObject.l1RtMbrIfs: # for interf in interfaceObject.l1RtMbrIfs: # print(interf['tDn']) # print(interf['tSKey']) # if interfaceObject.pcAggrMbrIf: # for interf in interfaceObject.pcAggrMbrIf: # print(interf['pcMode']) # print(interf['operSt']) epgresult = GetResponseData(epgurl, cookie) result = GetResponseData(url, cookie) while True: refresh = custom_raw_input('\nRefresh [Y]: ') or 'Y' if refresh.strip().lstrip().upper() == 'Y': clear_screen() break elif refresh.strip().lstrip().upper() == 'N': raise KeyboardInterrupt else: print('\nInvalid Option, Try again..\n')
def main(import_apic,import_cookie): global apic global cookie cookie = import_cookie apic = import_apic #allepglist = get_All_EGPs_names(apic,cookie) allpclist = get_All_PCs(apic,cookie) allvpclist = get_All_vPCs(apic,cookie) all_leaflist = get_All_leafs(apic,cookie) url = """https://{apic}/api/node/class/fvBD.json""".format(apic=apic) logger.info(url) bdresult = GetResponseData(url, cookie) if all_leaflist == []: print('\x1b[1;31;40mFailed to retrieve active leafs, make sure leafs are operational...\x1b[0m') custom_raw_input('\n#Press enter to continue...') return while True: clear_screen() location_banner('Show Endpoints on Interface') #selection = interface_menu() #try: #if selection == '1': print("\nSelect leaf(s): ") print("\r") while True: chosenleafs = physical_leaf_selection(all_leaflist, apic, cookie) if len(chosenleafs) > 1: print('\n\x1b[1;31;40mOne leaf supported at this time, please try again...\x1b[0m') print('\r') else: break switchpreviewutil.main(apic,cookie,chosenleafs, purpose='port_switching') # import pdb; pdb.set_trace() returnedlist = physical_interface_selection(apic, cookie, chosenleafs, provideleaf=False) while True: arplist = gather_arp_entries(chosenleafs) #returnedlist = physical_selection(all_leaflist, apic, cookie) #interface = interfacelist[0].name #interfacelist = physical_selection(all_leaflist, #) #print(returnedlist) #custom_raw_input('#Press enter to continue...') epmMacEplist = pull_mac_and_ip(chosenleafs) epmMacEplist = [x for x in epmMacEplist if 'tunnel' not in x.ifId] if epmMacEplist == []: print('\n\x1b[1;31;40mNo Endpoints found on interfaces\x1b[0m\n') custom_raw_input('#Press Enter to continue...') continue else: polist = pull_port_channel_info(chosenleafs) for po in polist: for epmmacep in epmMacEplist: if po.id == epmmacep.ifId: epmmacep.physlocation = po.activephys #print(chosenleafs) vlanlist = pull_vlan_info_for_leaf(chosenleafs) for x in epmMacEplist: found = False for vlan in vlanlist: if x.bd_encap in vlan.dn: x.foundvlan = vlan.name x.encap = x.encap.replace('vlan-[','')[:-1] found = True if not found: bdfound = False for v in bdresult: bd = x.bd[x.bd.rfind('[')+1:-1].replace('vxlan-','') if bd in v['fvBD']['attributes']['seg']: x.foundvlan = v['fvBD']['attributes']['dn'].replace('tn-','')[4:] x.encap = '' bdfound = True if bdfound == False: x.foundvlan = '' #print('hit') #url = """https://{apic}/api/node/class/fvCEp.json?query-target-filter=eq(fvCEp.mac,"{addr}")""".format(apic=apic,addr=x.addr) #result = GetResponseData(url, cookie) #x.foundvlan = ':'.join(result[0]['fvCEp']['attributes']['dn'].split('/')[1:4]).replace('tn-','').replace('ap-','').replace('epg-','') macsfound = 0 desiredlist = map(lambda x: x.dn, returnedlist) endpointlist = [] #print(len(epmMacEplist)) for macep in epmMacEplist: if hasattr(macep, 'physlocation'): for location in macep.physlocation: # import pdb; pdb.set_trace() #for port in macep.activephys: ethname = location if ethname.count('/') > 1: shortname = ''.join(ethname.split('/')[-2:]) else: shortname = ethname[ethname.rfind('/')+1:] endpointlist.append(endpoint(ethname=ethname,shortname=shortname,**macep.__dict__)) else: ethname = macep.ifId if ethname.count('/') > 1: shortname = ''.join(ethname.split('/')[-3:]).replace('eth','') else: shortname = ethname[ethname.rfind('/')+1:] endpointlist.append(endpoint(ethname=ethname,shortname=shortname,**macep.__dict__)) filteredlist = [] for endp in endpointlist: if endp.ethname.count('/') > 1: localethname = 'eth' + '/'.join(endp.ethname.split('/')[-2:]) expaths = endp.ethname.split('/')[0][3:] topology = ('/'.join(endp.dn.split('/')[:3]) + '/extpaths-' + expaths + '/pathep-[' + localethname + ']').replace('node-','paths-') else: topology = ('/'.join(endp.dn.split('/')[:3]) + '/pathep-[' + endp.ethname + ']').replace('node-','paths-') if topology in desiredlist: filteredlist.append(endp) del endpointlist columndata = ['ethname','addr','foundvlan','encap','ifId','ip'] columnheaders = ('Interface', 'MAC', 'EPG', 'Encap', 'Po #', 'IP') sizes = get_column_sizes(filteredlist, columndata, minimum=5, baseminimum=columnheaders) columnsections = ('column_size0','column_size1','column_size2','column_size3','column_size4','column_size5') sizedict = dict(zip(columnsections,sizes)) fexlist = filter(lambda x: x.ethname.count('/') == 2, filteredlist) nofexlist = filter(lambda x: x.ethname.count('/') == 1, filteredlist) print(('{:{column_size0}} {:{column_size1}} {:{column_size2}} ' + ' {:{column_size3}} {:{column_size4}} {:{column_size5}}').format(*columnheaders,**sizedict)) print(('{blank:-<{column_size0}} {blank:-<{column_size1}} {blank:-<{column_size2}} ' + ' {blank:-<{column_size3}} {blank:-<{column_size4}} {blank:-<{column_size5}}').format(blank='',**sizedict)) rowstring = ('{ep.ethname:{column_size0}} {ep.addr:{column_size1}} {ep.foundvlan:{column_size2}}' +' {ep.encap:{column_size3}} {interface:{column_size4}} {ipgroup:{column_size5}}') for ep in sorted(nofexlist, key=lambda x : int(x.shortname)): if 'po' in ep.ifId: print(rowstring.format(ep=ep, interface = ep.ifId, ipgroup = ",".join(ep.ip),**sizedict)) else: print(rowstring.format(ep=ep, interface = '', ipgroup = ",".join(ep.ip),**sizedict)) macsfound += 1 if fexlist != []: for ep in sorted(fexlist, key=lambda x: ( int(x.ifId.split('/')[-3][-3:]),int(x.ifId.split('/')[-2]),int(x.ifId.split('/')[-1]) )): if 'po' in ep.ifId: print(rowstring.format(ep=ep, epinterface = ep.ifId, epipgroup = ",".join(ep.ip),**sizedict)) #print('{:{inter}} {:{mac}} {:{epg}} {:{encap}} {:{po}} {:{ip}}'.format(ep.ethname,ep.addr,ep.foundvlan,ep.encap,ep.ifId,','.join(ep.ip),inter=sizes[0],mac=sizes[1],epg=sizes[2],encap=sizes[3],po=sizes[4],ip=sizes[5])) else: print(rowstring.format(ep=ep, epinterface = '', epipgroup = ",".join(ep.ip),**sizedict)) #print('{:{inter}} {:{mac}} {:{epg}} {:{encap}} {:{po}} {:{ip}}'.format(ep.ethname,ep.addr,ep.foundvlan,ep.encap,'',','.join(ep.ip),inter=sizes[0],mac=sizes[1],epg=sizes[2],encap=sizes[3],po=sizes[4],ip=sizes[5])) macsfound += 1 if macsfound == 0: print("No endpoints found!") elif macsfound == 1: print('\nFound {} endpoint(s)\n'.format(macsfound)) else: print('\nFound {} endpoint(s)\n'.format(macsfound)) #Desiredlist allows the discovery of 'po' names to interface selection desiredlist = map(lambda x: x.ifId, filteredlist) #Returnedlist is the entire full/shortname of the eth fexid with port number namereturnedlist = compile_ethname(returnedlist) #Only display current leaf arps arpfilteredlist = filter(lambda x:x.location in chosenleafs, arplist) del filteredlist arpfilteredlist = filter(lambda x: (x.physIfId in desiredlist or 'tunnel' in x.physIfId or x.physIfId in namereturnedlist),arpfilteredlist) if arpfilteredlist: print('\r') print('ARP Entries:') print('------------') columnwidthfind = ('ip','mac','tenant_vrf','ifId','physIfId') sizes = get_column_sizes(arpfilteredlist, columnwidthfind, minimum=6) print('\t{:{ip}} {:{mac}} {:{domain}} {:{where}} {:{discovered}}'.format('IP','MAC', 'Domain', 'Where', 'Discovered on Interface',ip=sizes[0],mac=sizes[1],domain=sizes[2],where=sizes[3],discovered=sizes[4])) print('\t{:-<{ip}} {:-<{mac}} {:-<{domain}} {:-<{where}} {:-<{discovered}}'.format('','', '', '', '',ip=sizes[0],mac=sizes[1],domain=sizes[2],where=sizes[3],discovered=sizes[4])) for arp in arpfilteredlist: print('\t{:{ip}} {:{mac}} {:{domain}} {:{where}} {:{discovered}}'.format(arp.ip,arp.mac,arp.tenant_vrf,arp.ifId,arp.physIfId,ip=sizes[0],mac=sizes[1],domain=sizes[2],where=sizes[3],discovered=sizes[4])) print('\nFound {} ARP entrie(s)'.format(len(arpfilteredlist))) askrefresh = custom_raw_input('\n\x1b[1;33;40m#Refresh [y|n]:\x1b[0m ') or 'y' if askrefresh != '' and askrefresh[0].strip().lstrip().lower() == 'y': print('\n\n') continue else: break
def main(import_apic,import_cookie): while True: global apic global cookie cookie = import_cookie apic = import_apic allepglist = get_All_EGPs_names(apic,cookie) allpclist = get_All_PCs(apic,cookie) allvpclist = get_All_vPCs(apic,cookie) all_leaflist = get_All_leafs(apic,cookie) clear_screen() location_banner('Clone Interface and Deploy') selection = interface_menu() if selection == '1': chosenleafs = physical_leaf_selection(all_leaflist, apic, cookie) switchpfound, fexes = fabric_access.display_switch_to_leaf_structure.return_physical_programmed_ports_perleaf(chosenleafs[0], apic, cookie) interfaces_with_APS_defined = [] fexfound = [] for switchp in switchpfound: for leafp in switchp.leafprofiles: interfaces_with_APS_defined.append((switchp.allleafs,leafp.allports)) for portlist in leafp.infraHPortSlist: for x in fexes: if portlist.infraRsAccBaseGrp.tDn != '' and x.dn in portlist.infraRsAccBaseGrp.tDn: if portlist.infraFexPlist: fexfound.append((x,portlist.infraRsAccBaseGrp.fexId)) for fex in fexfound: interfaces_with_APS_defined.append((fex[1],fex[0].allports)) compiledports = [] for interface in interfaces_with_APS_defined: if type(interface[0]) != unicode: for leaf in interface[0]: for modulenum, ports in interface[1].items(): for port in ports: compiledports.append(('eth' + str(modulenum) + '/' + str(port))) else: for modulenum, ports in interface[1].items(): for port in ports: compiledports.append(('eth' + str(interface[0]) + '/' + str(modulenum) + '/' + str(port))) compiledports = list(set(compiledports)) newlist = [] for x in compiledports: newlist.append(l1PhysIf(id = x, shortnum = x.split('/')[-1][0])) switchpreviewutil.main(apic,cookie,chosenleafs, interfacelist=compiledports, purpose='custom') returnedlist = physical_interface_selection(apic, cookie, chosenleafs, provideleaf=False) chosenepgs, choseninterfaceobjectlist = display_and_select_epgs(returnedlist, allepglist) interface_type_and_deployement(chosenepgs, choseninterfaceobjectlist, apic) print('\r') custom_raw_input('#Press enter to continue...') elif selection == '2': while True: returnedlist = port_channel_selection(allpclist) if len(returnedlist) > 1: print("\nPlease select on item\n") continue else: break leafselectorresult, currentleafifselector = retrieve_clone_portchannel_master(apic, cookie, returnedlist) returnedlist = portchannel_clone_and_deploy(apic, cookie, currentleafifselector, leafselectorresult, pctype='pc') chosenepgs, choseninterfaceobjectlist = display_and_select_epgs(returnedlist, allepglist) interface_type_and_deployement(chosenepgs, choseninterfaceobjectlist, apic, type="Port-Channel") print('\r') custom_raw_input('#Press enter to continue...') elif selection == '3': while True: returnedlist = port_channel_selection(allvpclist) if len(returnedlist) > 1: print("\nPlease select on item\n") continue else: break leafselectorresult, currentleafifselector = retrieve_clone_portchannel_master(apic, cookie, returnedlist) returnedlist = portchannel_clone_and_deploy(apic, cookie, currentleafifselector, leafselectorresult, pctype='vpc') chosenepgs, choseninterfaceobjectlist = display_and_select_epgs(returnedlist, allepglist) interface_type_and_deployement(chosenepgs, choseninterfaceobjectlist, apic, type="vPort-Channel") print('\r') custom_raw_input('#Press enter to continue...') #query vpc with name #get infraRtAccBaseGrp in response and all the relationships to policy groups # #display would you like to use same vPC leaf pair. # if not # which leaf ifselector # what is the name of VPC # else continue cloning vpc # ask what is the name of VPC
def main(import_apic, import_cookie): global apic global cookie cookie = import_cookie apic = import_apic clear_screen() location_banner('Show EPGs to interface') while True: all_leaflist = get_All_leafs(apic, cookie) if all_leaflist == []: print( '\x1b[1;31;40mFailed to retrieve active leafs, make leafs are operational...\x1b[0m' ) custom_raw_input('\n#Press enter to continue...') return print('\nSelect leaf(s): ') print('\r') # desiredleaf = custom_custom_raw_input("\nWhat is the desired \x1b[1;33;40m'Source and Destination'\x1b[0m leaf for span session?\r") #print("\nWhat is the desired \x1b[1;33;40m'Destination'\x1b[0m leaf for span session?\r") chosenleafs = physical_leaf_selection(all_leaflist, apic, cookie) switchpreviewutil.main(apic, cookie, chosenleafs, purpose='port_switching') #chosendestinterfaceobject = physical_interface_selection(apic, cookie, chosenleafs, provideleaf=False) leaf = chosenleafs url = """https://{apic}/api/node-{leaf}/class/l1PhysIf.json""".format( leaf=leaf[0], apic=apic) logger.info(url) result = GetResponseData(url, cookie) interfacelist = [x['l1PhysIf']['attributes']['id'] for x in result] #import pdb; pdb.set_trace() interfacelist = interface_epg_pull(apic, cookie, leaf, interfacelist) #import pdb; pdb.set_trace() vlanlist = pull_vlan_info_for_leaf(apic, cookie, leaf) #mport pdb; pdb.set_trace() for interface in interfacelist: for vlan in vlanlist: #import pdb; pdb.set_trace() if interface.epgs != []: for epg in interface.epgs: if epg.name == vlan.epgDn: import pdb pdb.set_trace() epg.encapvlans.append(vlan.encap) epg.internalvlans.append(vlan.fabEncap) import pdb pdb.set_trace() # x,y = interfacelist # if y != None: # #import pdb; pdb.set_trace() # if y == vlan.epgDn: # pass #for z in y: # if z == vlan.epgDn: # print('yes') for interface in sorted(interfacedictwithegps, key=lambda x: (x.split('/')[0], int(x.split('/')[-1]))): print(interface) #import pdb; pdb.set_trace() # if interfacedictwithegps[interface][1] x, y = interfacedictwithegps[interface] if y == None: print('\t{} {}'.format(x, y)) else: #print('\t{}'.format(x)) for yy in sorted(y): pass
def main(import_apic, import_cookie): global apic global cookie cookie = import_cookie apic = import_apic allepglist = get_All_EGPs(apic, cookie) allpclist = get_All_PCs(apic, cookie) allvpclist = get_All_vPCs(apic, cookie) all_leaflist = get_All_leafs(apic, cookie) if all_leaflist == []: print( '\x1b[1;31;40mFailed to retrieve active leafs, make sure leafs are operational...\x1b[0m' ) custom_raw_input('\n#Press enter to continue...') return while True: clear_screen() location_banner('Show Endpoints on Interface') selection = interface_menu() try: if selection == '1': print("\nSelect leaf(s): ") print("\r") chosenleafs = physical_leaf_selection(all_leaflist, apic, cookie) switchpreviewutil.main(apic, cookie, chosenleafs, purpose='port_switching') returnedlist = physical_interface_selection(apic, cookie, chosenleafs, provideleaf=False) #returnedlist = physical_selection(all_leaflist, apic, cookie) #interface = interfacelist[0].name #interfacelist = physical_selection(all_leaflist, allepglist) #print(returnedlist) #custom_raw_input('#Press enter to continue...') elif selection == '2': returnedlist = port_channel_selection(allpclist) #print(returnedlist) #custom_raw_input('#Press enter to continue...') elif selection == '3': returnedlist = port_channel_selection(allvpclist) #print(returnedlist) except Exception as e: print(e) raw_input('Completed. Press enter to return....') #custom_raw_input('#Press enter to continue...') #all_leaflist = get_All_leafs() fvCEplist = mac_path_function() #import pdb; pdb.set_trace() # if fvCEplist == []: macsfound = 0 print('{:20} {:15} {:25} {}'.format('MAC', 'Last IP', 'All Live IPs', 'EPG')) print( '---------------------------------------------------------------------------' ) for x in fvCEplist: #print('\t', x.fvRsCEpToPathEp, interfacelist[0]) if str(x.fvRsCEpToPathEp) == str(returnedlist[0]): print("{:20} {:15} {:25} {}".format( x.mac, x.ip, x.fvIplist, x.dn[x.dn.find('/') + 1:x.dn.rfind('/')])) macsfound += 1 if macsfound == 0 and selection == '1': print( "No endpoints found!\n\n**If this interface is part of a PC or VPC on interface please search using interface type pc/vpc" ) raw_input('\n\n#Press enter to return') elif macsfound == 0: print("No endpoints found!") raw_input('\n\n#Press enter to return') else: raw_input( '\nFound {} endpoints.\n\n #Press enter to return...'.format( macsfound))
def main(import_apic, import_cookie): global apic global cookie cookie = import_cookie apic = import_apic while True: clear_screen() location_banner('Show interface counters and EPGs') all_leaflist = get_All_leafs(apic, cookie) if all_leaflist == []: print( '\x1b[1;31;40mFailed to retrieve active leafs, make leafs are operational...\x1b[0m' ) custom_raw_input('\n#Press enter to continue...') return print('\nSelect leaf(s): ') print('\r') # desiredleaf = custom_custom_raw_input("\nWhat is the desired \x1b[1;33;40m'Source and Destination'\x1b[0m leaf for span session?\r") #print("\nWhat is the desired \x1b[1;33;40m'Destination'\x1b[0m leaf for span session?\r") chosenleafs = physical_leaf_selection(all_leaflist, apic, cookie) switchpreviewutil.main(apic, cookie, chosenleafs, purpose='port_switching') chosendestinterfaceobject = physical_interface_selection( apic, cookie, chosenleafs, provideleaf=False) leaf = chosenleafs #chosendestinterfaceobject, leaf = physical_selection(all_leaflist, apic, cookie, provideleaf=True) #import pdb; pdb.set_trace() interface = chosendestinterfaceobject[0].name #epgurl = """https://{apic}/api/node-{leaf}/mo/sys/phys-[{interface}].json?rsp-subtree-include=full-deployment&target-node=all&target-path=l1EthIfToEPg""".format(interface=str(interface),leaf=str(leaf[0]),apic=apic) ##url = """https://{apic}/api/node/mo/{path}.json?rsp-subtree-include=full-deployment&target-node=all&target-path=l1EthIfToEPg""".format(apic=apic,path=str(chosendestinterfaceobject[0])) #logger.info(epgurl) #epgresult = GetResponseData(epgurl, cookie) #logger.debug(epgresult) #url = """https://{apic}/api/node-{leaf}/mo/sys/phys-[{interface}].json?""".format(interface=str(interface),leaf=str(leaf[0]),apic=apic) \ # + """query-target=subtree&rsp-subtree-include=stats&target-subtree-class=rmonIfOut,l1PhysIf,""" \ # + """rmonIfIn,rmonEtherStats,ethpmPhysIf,l1RsAttEntityPCons,"""\ # + """l1RsCdpIfPolCons,l1RtMbrIfs,pcAggrMbrIf,fvDomDef,eqptIngrTotal5min,eqptEgrTotal5min,""" \ # + """l1RsQosEgressDppIfPolCons,l1RsLldpIfPolCons,l1RsMonPolIfPolCons,l1RsStpIfPolCons,l1RsQosIngressDppIfPolCons,""" \ # + """l1RsL2PortSecurityCons,l1RsStormctrlIfPolCons,l1RsL3IfPolCons,l1RsMacsecPolCons,l1RsDwdmIfPolCons,l1RsMcpIfPolCons,"""\ # + """l1RsL2IfPolCons,l1RsFcIfPolCons,l1RsQosSdIfPolCons,l1RsCoppIfPolCons,l1RsHIfPolCons,l1RsQosPfcIfPolCons,l1RsStpIfPolCons""" while True: clear_screen() epgurl = """https://{apic}/api/node-{leaf}/mo/sys/phys-[{interface}].json?rsp-subtree-include=full-deployment&target-node=all&target-path=l1EthIfToEPg""".format( interface=str(interface), leaf=str(leaf[0]), apic=apic) #url = """https://{apic}/api/node/mo/{path}.json?rsp-subtree-include=full-deployment&target-node=all&target-path=l1EthIfToEPg""".format(apic=apic,path=str(chosendestinterfaceobject[0])) logger.info(epgurl) epgresult = GetResponseData(epgurl, cookie) logger.debug(epgresult) url = """https://{apic}/api/node-{leaf}/mo/sys/phys-[{interface}].json?""".format(interface=str(interface),leaf=str(leaf[0]),apic=apic) \ + """query-target=subtree&rsp-subtree-include=stats&target-subtree-class=rmonIfOut,l1PhysIf,""" \ + """rmonIfIn,rmonEtherStats,ethpmPhysIf,l1RsAttEntityPCons,"""\ + """l1RsCdpIfPolCons,l1RtMbrIfs,pcAggrMbrIf,fvDomDef,eqptIngrTotal5min,eqptEgrTotal5min,""" \ + """l1RsQosEgressDppIfPolCons,l1RsLldpIfPolCons,l1RsMonPolIfPolCons,l1RsStpIfPolCons,l1RsQosIngressDppIfPolCons,""" \ + """l1RsL2PortSecurityCons,l1RsStormctrlIfPolCons,l1RsL3IfPolCons,l1RsMacsecPolCons,l1RsDwdmIfPolCons,l1RsMcpIfPolCons,"""\ + """l1RsL2IfPolCons,l1RsFcIfPolCons,l1RsQosSdIfPolCons,l1RsCoppIfPolCons,l1RsHIfPolCons,l1RsQosPfcIfPolCons,l1RsStpIfPolCons""" result = GetResponseData(url, cookie) logger.info(url) #import pdb; pdb.set_trace() display_interface_stats(epgresult, interface, result) refresh = custom_raw_input('\nRefresh [Y]: ') or 'Y' if refresh.strip().lstrip().upper() == 'Y': clear_screen() continue elif refresh.strip().lstrip().upper() == 'N': break else: print('\nInvalid Option, Try again..\n')
def main(import_apic, import_cookie): while True: cookie = import_cookie apic = import_apic allepglist = get_All_EGPs_names(apic,cookie) allpclist = get_All_PCs(apic,cookie) allvpclist = get_All_vPCs(apic,cookie) all_leaflist = get_All_leafs(apic,cookie) clear_screen() location_banner('Shut and No Shut interfaces') selection = interface_menu() if selection == '1': chosenleafs = physical_leaf_selection(all_leaflist, apic, cookie) switchpreviewutil.main(apic,cookie,chosenleafs) returnedlist = physical_interface_selection(apic, cookie, chosenleafs, provideleaf=False) print('\r') while True: option = custom_raw_input( ("Would you like to do?\n\ \n1.) shut\ \n2.) no shut\ \n3.) bounce \n\ \nSelect a number: ")) if option == '1': print('\n') confirmed = shut_or_noshut_confirmation(returnedlist, operation = '"shut"') if confirmed: print('\n') shutinterfaces(returnedlist, apic, cookie) else: print('\nCancelled\n') break elif option == '2': print('\n') confirmed = shut_or_noshut_confirmation(returnedlist, operation = '"no shut"') if confirmed: print('\n') noshutinterfaces(returnedlist, apic, cookie) else: print('\nCancelled\n') break elif option == '3': print('\n') confirmed = shut_or_noshut_confirmation(returnedlist, operation = '"bounce"') if confirmed: print('\n') shutinterfaces(returnedlist, apic, cookie) noshutinterfaces(returnedlist, apic, cookie) else: print('\nCancelled\n') break else: print('\n\x1b[1;31;40mInvalid option, please try again...\x1b[0m\n') continue custom_raw_input('\n#Press Enter to continue...') elif selection == '2': returnedlist = port_channel_selection(allpclist) print('\r') while True: option = custom_raw_input( ("Would you like to do?\n\ \n1.) shut\ \n2.) no shut\ \n3.) bounce \n\ \nSelect a number: ")) if option == '1': print('\n') confirmed = shut_or_noshut_confirmation(returnedlist, operation = '"shut"') if confirmed: print('\n') shutinterfaces(returnedlist, apic, cookie) else: print('\nCancelled\n') break elif option == '2': print('\n') confirmed = shut_or_noshut_confirmation(returnedlist, operation = '"no shut"') if confirmed: print('\n') noshutinterfaces(returnedlist, apic, cookie) else: print('\nCancelled\n') break elif option == '3': print('\n') confirmed = shut_or_noshut_confirmation(returnedlist, operation = '"bounce"') if confirmed: print('\n') shutinterfaces(returnedlist, apic, cookie) noshutinterfaces(returnedlist, apic, cookie) else: print('\nCancelled\n') break else: print('\n\x1b[1;31;40mInvalid option, please try again...\x1b[0m\n') continue custom_raw_input('\n#Press Enter to continue...') elif selection == '3': returnedlist = port_channel_selection(allvpclist) print('\r') while True: option = custom_raw_input( ("Would you like to do?\n\ \n1.) shut\ \n2.) no shut\ \n3.) bounce \n\ \nSelect a number: ")) if option == '1': print('\n') confirmed = shut_or_noshut_confirmation(returnedlist, operation = '"shut"') if confirmed: print('\n') shutinterfaces(returnedlist, apic, cookie) else: print('\nCancelled\n') break elif option == '2': print('\n') confirmed = shut_or_noshut_confirmation(returnedlist, operation = '"no shut"') if confirmed: print('\n') noshutinterfaces(returnedlist, apic, cookie) else: print('\nCancelled\n') break elif option == '3': print('\n') confirmed = shut_or_noshut_confirmation(returnedlist, operation = '"bounce"') if confirmed: print('\n') shutinterfaces(returnedlist, apic, cookie) noshutinterfaces(returnedlist, apic, cookie) else: print('\nCancelled\n') break else: print('\n\x1b[1;31;40mInvalid option, please try again...\x1b[0m\n') continue custom_raw_input('\n#Press Enter to continue...')