parser = argparse.ArgumentParser(description="Lookup Static Path by EPG") parser.add_argument('tenantName', help='tenant name') parser.add_argument('apName', help='ap name') parser.add_argument('epgName', help='EPG name') args = parser.parse_args() # open yaml files f = open('credentials.yaml', 'r') credentials = yaml.load(f) f.close() apicUrl = credentials['host'] loginSession = LoginSession(apicUrl, credentials['user'], credentials['pass']) moDir = MoDirectory(loginSession) moDir.login() dnQuery = DnQuery('uni/tn-' + args.tenantName + '/ap-' + args.apName + '/epg-' + args.epgName) dnQuery.queryTarget = 'children' dnQuery.subtreeClassFilter = 'fvAEPg' epgMo = moDir.query(dnQuery) for epg in epgMo: #print epg.dn if isinstance(epg, AEPg): print 'AEPg' elif isinstance(epg, RsPathAtt): print str(epg.tDn) + ' ' + epg.encap + ' ' + epg.mode moDir.logout()
parser.add_argument('leafBNumber', help='leaf B number') parser.add_argument('-d','--domain', help='display vPC Domain status and details of vPC',action="store_true") args = parser.parse_args() # open yaml files f = open('credentials.yaml', 'r') credentials = yaml.load(f) f.close() apicUrl = credentials['host'] loginSession = LoginSession(apicUrl, credentials['user'], credentials['pass']) moDir = MoDirectory(loginSession) moDir.login() if args.domain: nodeAQuery = DnQuery('topology/pod-1/node-' + args.leafANumber + '/sys/vpc/inst') nodeAQuery.queryTarget = 'children' nodeAMo = moDir.query(nodeAQuery) for vpcDomain in nodeAMo: if isinstance(vpcDomain,Dom): print "DomainId: " + str(vpcDomain.id) print "PeerState: " + vpcDomain.peerSt print "Role: " + vpcDomain.operRole + ' (operational), ' + vpcDomain.oldRole + ' (configured)' vpcQuery = DnQuery(vpcDomain.dn) vpcQuery.queryTarget = 'children' vpcMo = moDir.query(vpcQuery) #for vpcIf in vpcMo: # print vpcIf.name nodeASysQuery = DnQuery('topology/pod-1/node-' + args.leafANumber + '/sys') nodeASysQuery.queryTarget = 'children'
import yaml import argparse parser = argparse.ArgumentParser(description="Display EPG by Ap") parser.add_argument('tenantName', help='tenant name') parser.add_argument('apName', help='ap name') parser.add_argument('-s', '--separe', help='ap name', action="store_true") args = parser.parse_args() # open yaml files f = open('credentials.yaml', 'r') credentials = yaml.load(f) f.close() apicUrl = credentials['host'] loginSession = LoginSession(apicUrl, credentials['user'], credentials['pass']) moDir = MoDirectory(loginSession) moDir.login() dnQuery = DnQuery('uni/tn-' + args.tenantName + '/ap-' + args.apName) dnQuery.queryTarget = 'children' #dnQuery.subtreeClassFilter = 'fvAEPg' epgMo = moDir.query(dnQuery) for epg in epgMo: if args.separe: print args.tenantName + ' ' + args.apName + ' ' + epg.name else: print epg.dn, epg.name moDir.logout()
from cobra.mit.access import MoDirectory from cobra.mit.session import LoginSession from cobra.mit.access import DnQuery from cobra.model.fv import Tenant, Ctx, BD, RsCtx, Ap, AEPg, RsBd, RsDomAtt apicUrl = 'https://172.16.31.36' loginSession = LoginSession(apicUrl, 'admin', 'Tel1dus!') moDir = MoDirectory(loginSession) moDir.login() dnQuery = DnQuery('uni/tn-LAN01') dnQuery.subtree = 'children' tenantMo = moDir.query(dnQuery) for obj in tenantMo: print obj.dn for _BD in obj.BD: print _BD.dn for _app in obj.AP: print _app.dn moDir.logout()
parser = argparse.ArgumentParser(description="Display Interface Profile") parser.add_argument('intProfName', help='interface profile name') args = parser.parse_args() # open yaml files f = open('credentials.yaml', 'r') credentials = yaml.load(f) f.close() apicUrl = credentials['host'] loginSession = LoginSession(apicUrl, credentials['user'], credentials['pass']) moDir = MoDirectory(loginSession) moDir.login() dnQuery = DnQuery('uni/infra/accportprof-' + args.intProfName) dnQuery.queryTarget = 'children' #dnQuery.subtreeClassFilter = 'fvAEPg' physMo = moDir.query(dnQuery) for obj in physMo: if isinstance(obj, HPortS): objQuery = DnQuery(obj.dn) objQuery.queryTarget = 'children' portsMo = moDir.query(objQuery) for ports in portsMo: if isinstance(ports, PortBlk): print ports.fromCard + '/' + ports.fromPort + '-' + ports.toPort if isinstance(obj, RtAccPortP): print obj.dn moDir.logout()
'--full', help='display all objects', action="store_true") args = parser.parse_args() # open yaml files f = open('credentials.yaml', 'r') credentials = yaml.load(f) f.close() apicUrl = credentials['host'] loginSession = LoginSession(apicUrl, credentials['user'], credentials['pass']) moDir = MoDirectory(loginSession) moDir.login() dnQuery = DnQuery('topology/pod-1/paths-' + args.leafNumber) dnQuery.queryTarget = 'children' #dnQuery.subtreeClassFilter = 'fvAEPg' leafMo = moDir.query(dnQuery) for obj in leafMo: if obj.pathT == 'leaf': if obj.lagT != 'node': #print obj.dn intfL2Pol = 'default' intfPC = '' intQuery = DnQuery('topology/pod-1/node-' + args.leafNumber + '/sys/phys-[' + obj.name + ']') intQuery.queryTarget = 'children' intMo = moDir.query(intQuery) for intAttr in intMo: if isinstance(intAttr, PhysIf):
import yaml import argparse parser = argparse.ArgumentParser(description="Display Physical Domain") parser.add_argument('physName', help='physical domain name') parser.add_argument('-e','--epg', help='wants epg', action="store_true") parser.add_argument('-a','--aaep', help='wants AAeP', action="store_true") args = parser.parse_args() # open yaml files f = open('credentials.yaml', 'r') credentials = yaml.load(f) f.close() apicUrl = credentials['host'] loginSession = LoginSession(apicUrl, credentials['user'], credentials['pass']) moDir = MoDirectory(loginSession) moDir.login() dnQuery = DnQuery('uni/phys-' + args.physName) dnQuery.queryTarget = 'children' #dnQuery.subtreeClassFilter = 'fvAEPg' physMo = moDir.query(dnQuery) for obj in physMo: if args.epg and isinstance(obj,RtDomAtt): print obj.tDn if args.aaep and isinstance(obj,RtDomP): print obj.tDn moDir.logout()
from cobra.mit.access import DnQuery from cobra.model.fv import Tenant, Ctx, BD, RsCtx, Ap, AEPg, RsBd, RsDomAtt, RsPathAtt from cobra.model.top import System import yaml import argparse parser = argparse.ArgumentParser(description="Display Leaf") parser.add_argument('leafNumber', help='leaf number') args = parser.parse_args() # open yaml files f = open('credentials.yaml', 'r') credentials = yaml.load(f) f.close() apicUrl = credentials['host'] loginSession = LoginSession(apicUrl, credentials['user'], credentials['pass']) moDir = MoDirectory(loginSession) moDir.login() dnQuery = DnQuery('topology/pod-1/node-' + args.leafNumber) dnQuery.queryTarget = 'children' #dnQuery.subtreeClassFilter = 'fvAEPg' leafMo = moDir.query(dnQuery) for obj in leafMo: if isinstance(obj, System): print obj.name + ' ' + obj.serial + ' ' + obj.role + ' ' + obj.state + ' ' + str( obj.systemUpTime) moDir.logout()