Ejemplo n.º 1
0
def main(host, username, password, node, interface):
    apic = "https://%s" % host
    print("Connecting to APIC : %s" % apic)
    moDir = MoDirectory(LoginSession(apic, username, password))
    moDir.login()

    nodeblk_dict = defaultdict(list)
    nodeblk_list = moDir.lookupByClass("infraNodeBlk")
    node_found = False
    for nodeblkMO in nodeblk_list:
        if int(nodeblkMO.from_) > int(node) or int(nodeblkMO.to_) < int(node):
            continue
        else:
            node_found = True
            node_dn = '/'.join(str(nodeblkMO.dn).split('/')[:3])
            nodeblk_dict[node_dn].append(str(nodeblkMO.dn))
    if node_found is False:
        print("Switch Node {", node, "} DOES NOT exist!")
        exit(1)
    if debug is True:
        print("Printing nodeblk_dict.......")
        for key, value in nodeblk_dict.items():
            print(key, ":", value)
        print("-----------------------------")

    port_dict = {}
    RsAccPortP_list = moDir.lookupByClass("infraRsAccPortP")
    for RsAccPortPMO in RsAccPortP_list:
        portk = str(str(RsAccPortPMO.dn).split('[')[1])[:-1]
        port_dict[portk] = '/'.join(str(RsAccPortPMO.dn).split('/')[:3])

    if debug is True:
        print("Printing port_dict.......")
        for key, value in port_dict.items():
            print(key, ":", value)

        print("-----------------------------")

    Portblk_list = moDir.lookupByClass("infraPortBlk")
    interface_found = False
    for temp_port in Portblk_list:
        if int(interface) == int(temp_port.fromPort):
            interface_found = True
            intP = '/'.join(str(temp_port.dn).split('/')[:3])
            if port_dict[intP] in nodeblk_dict:
                m = re.match("accportprof-(?P<first>.+)",
                             str(temp_port.dn).split('/')[2])
                print("Interface Profile Name => ", m.group("first"))
                print("Interface Profile DN =>", intP)
                n = re.match("nprof-(?P<first>.+)",
                             str(port_dict[intP]).split('/')[2])
                print("Switch Node Profile Name =>", n.group("first"))
                print("Switch Node Profile DN =>", port_dict[intP])
    if interface_found is False:
        print("Interface {", interface, "} DOES NOT exist!")
        exit(1)
Ejemplo n.º 2
0
def main(host, username, password, node, interface):
    apic = "https://%s" % host
    print("Connecting to APIC : %s" % apic)
    moDir = MoDirectory(LoginSession(apic, username, password))
    moDir.login()

    nodeblk_dict = defaultdict(list)
    nodeblk_list = moDir.lookupByClass("infraNodeBlk")
    node_found = False
    for nodeblkMO in nodeblk_list:
        if int(nodeblkMO.from_) > int(node) or int(nodeblkMO.to_) < int(node):
            continue
        else:
            node_found = True
            node_dn = '/'.join(str(nodeblkMO.dn).split('/')[:3])
            nodeblk_dict[node_dn].append(str(nodeblkMO.dn))
    if node_found is False:
        print("Switch Node {", node, "} DOES NOT exist!")
        exit(1)
    if debug is True:
        print("Printing nodeblk_dict.......")
        for key, value in nodeblk_dict.items():
            print(key, ":", value)
        print("-----------------------------")

    port_dict = {}
    RsAccPortP_list = moDir.lookupByClass("infraRsAccPortP")
    for RsAccPortPMO in RsAccPortP_list:
        portk = str(str(RsAccPortPMO.dn).split('[')[1])[:-1]
        port_dict[portk] = '/'.join(str(RsAccPortPMO.dn).split('/')[:3])

    if debug is True:
        print("Printing port_dict.......")
        for key, value in port_dict.items():
            print(key, ":", value)

        print("-----------------------------")

    Portblk_list = moDir.lookupByClass("infraPortBlk")
    interface_found = False
    for temp_port in Portblk_list:
        if int(interface) == int(temp_port.fromPort):
            interface_found = True
            intP = '/'.join(str(temp_port.dn).split('/')[:3])
            if port_dict[intP] in nodeblk_dict:
                m = re.match("accportprof-(?P<first>.+)", str(temp_port.dn).split('/')[2])
                print("Interface Profile Name => ", m.group("first"))
                print("Interface Profile DN =>", intP)
                n = re.match("nprof-(?P<first>.+)", str(port_dict[intP]).split('/')[2])
                print("Switch Node Profile Name =>", n.group("first"))
                print("Switch Node Profile DN =>", port_dict[intP])
    if interface_found is False:
        print("Interface {", interface, "} DOES NOT exist!")
        exit(1)
Ejemplo n.º 3
0
def main(host, username, password, tenant):
    apic = "https://%s" % host
    print("Connecting to APIC : %s" % apic)
    moDir = MoDirectory(LoginSession(apic, username, password))
    moDir.login()

    t_obj_list = moDir.lookupByClass("fvTenant")
    for t_mo in t_obj_list:
        print("Tenant name =>",t_mo.dn)
        if t_mo.name == tenant:
            bd_list = moDir.lookupByClass("fvBD", t_mo.dn)
            for mo in bd_list:
                print("NAME: {:10s}".format(mo.name))
                print("DN: {:10s}".format(mo.dn))
                print("MAC: {:10s}".format(mo.mac))
                print("UID: {:10s}".format(mo.uid))
                print("arpFlood: {:10s}".format(mo.arpFlood))
                print("MUT: {:10s}".format(mo.mtu))
                print()
            return
Ejemplo n.º 4
0
def get_tenant():
    with open("/home/app/data/logs.txt", "a") as log_file:
        log_file.write("==================================================" + "\n")
        log_file.write("Received API Request from Client. Sending Response" + "\n")
        log_file.write("==================================================" + "\n")

    apicUrl = 'https://172.17.0.1/'
    loginSession = createCertSession()
    #loginSession = LoginSession(apicUrl, 'admin', 'ins3965!')
    #loginSession = cobra.mit.session.LoginSession('https://10.22.47.171', 'admin', 'ins3965!')
    moDir = MoDirectory(loginSession)
    moDir.login()
    tenantMo = moDir.lookupByClass('fvTenant');
    moDir.logout()
    #print json.dumps(tenantMo)
    return respFormatJsonMos(tenantMo, tenantMo.totalCount)
Ejemplo n.º 5
0
def get_tenant():

    with open("/Users/clakits/aci/myapps/apic/logs.txt", "a") as log_file:
        log_file.write("==================================================" +
                       "\n")
        log_file.write("Received API Request from Client. Sending Response" +
                       "\n")
        log_file.write("==================================================" +
                       "\n")

    apicUrl = 'https://'
    loginSession = LoginSession(apicUrl, 'admin', '')

    #loginSession = createCertSession()

    moDir = MoDirectory(loginSession)
    moDir.login()
    tenantMo = moDir.lookupByClass('fvTenant')
    moDir.logout()

    return respFormatJsonMos(tenantMo, tenantMo.totalCount)
Ejemplo n.º 6
0
# Set just the URLLIB3 logging level to INFO
requests_log.setLevel(logging.INFO)
requests_log.propagate = True

requests.packages.urllib3.disable_warnings()

aci_class = sys.argv[1]
session = LoginSession('https://172.21.208.173', 'admin', 'C1sc0123')
moDir = MoDirectory(session)
moDir.login()

from cobra.mit.request import ConfigRequest

#import the tenant class from the model
from cobra.model.fv import Tenant
# Get the top level policy universe directory
uniMo = moDir.lookupByDn('uni')

## create the tenant object
#fvTenantMo = Tenant(uniMo, 'test1111111111')
#fvTenantMo.delete()#

#configReq = ConfigRequest()
#configReq.addMo(fvTenantMo)
#moDir.commit(configReq)

obj_list = moDir.lookupByClass(aci_class)
#
for mo in obj_list:
    print "{} -> {}".format(mo.name, mo.dn)
Ejemplo n.º 7
0
import logging, json

from cobra.mit.access import MoDirectory
from cobra.mit.session import LoginSession


# uncomment the below to get more verbose output
# for debugging
"""
import httplib as http_client
http_client.HTTPConnection.debuglevel = 1
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
"""

session = LoginSession('https://*****:*****@lw@y')
moDir = MoDirectory(session)
moDir.login()
tenant1Mo = moDir.lookupByClass("dhcpClient")

for c in tenant1Mo:
	print(c.dn, c.model, c.name, c.ip)

moDir.logout()


Ejemplo n.º 8
0
#!/usr/bin/python

from cobra.mit.access import MoDirectory
from cobra.mit.session import LoginSession
from cobra.model.fv import Tenant
from cobra.mit.request import DnQuery

apicUrl = 'https://10.15.254.33'
loginSession = LoginSession(apicUrl, 'admin', 'Cisco321')
moDir = MoDirectory(loginSession)
moDir.login()

tenant1Mo = moDir.lookupByClass(
    "fvTenant", propFilter='and(eq(fvTenant.name, "CobraTenant"))')

print(tenant1Mo)
Ejemplo n.º 9
0
# Set just the URLLIB3 logging level to INFO
requests_log.setLevel(logging.INFO)
requests_log.propagate = True

requests.packages.urllib3.disable_warnings()

aci_class = sys.argv[1]
session = LoginSession('https://172.21.208.173', 'admin','C1sc0123')
moDir = MoDirectory(session)
moDir.login()

from cobra.mit.request import ConfigRequest

#import the tenant class from the model
from cobra.model.fv import Tenant
# Get the top level policy universe directory
uniMo = moDir.lookupByDn('uni')

## create the tenant object
#fvTenantMo = Tenant(uniMo, 'test1111111111')
#fvTenantMo.delete()#

#configReq = ConfigRequest()
#configReq.addMo(fvTenantMo)
#moDir.commit(configReq)

obj_list = moDir.lookupByClass(aci_class)
#
for mo in obj_list:
	print "{} -> {}".format(mo.name,mo.dn)
Ejemplo n.º 10
0
from cobra.mit.access import DnQuery
from cobra.mit.access import ClassQuery
from cobra.model.fv import Tenant, Ctx, BD, RsCtx, Ap, AEPg, RsBd, RsDomAtt, RsPathAtt
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')
#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'
cQuery = ClassQuery(AEPg)
epgMo = moDir.lookupByClass(cQuery)
for epg in epgMo:
    print epg.dn

moDir.logout()
Ejemplo n.º 11
0
    node = re.search('node-(\d+)', dn)
    return int(node.group(1)) < 199


# Returns the node name
def get_node_name(dn):
    node = re.search('node-(\d+)', dn)
    return node.group(1)


session = LoginSession(cred.URL, cred.LOGIN, cred.PASSWORD)
moDir = MoDirectory(session)
moDir.login()
uniMo = moDir.lookupByDn('uni')

lldpAdjEps = moDir.lookupByClass('lldpAdjEp')
if lldpAdjEps:
    print "Found adjacent hosts via LLDP:"
for adjEp in lldpAdjEps:
    print str(adjEp.dn) + " is connected to " + str(adjEp.sysName)

infraInfra = Infra(uniMo)

for adjEp in lldpAdjEps:
    if is_leaf(str(adjEp.dn)):
        infraHPathS = HPathS(infraInfra,
                             name="adjEp-{0}-{1}".format(
                                 str(adjEp.sysName),
                                 get_node_name(str(adjEp.dn))),
                             descr=str(adjEp.sysName))
        infraRsHPathAtt = RsHPathAtt(infraHPathS,