Exemple #1
0
def getmacentry(device, mac, vlanfilter=None):
    dev = device
    deviceConnection = nxapirest.NXRestAPI(dev.ip, dev.user, dev.passw)
    macaddroutput = deviceConnection.get_JSON_NX_API(
        'show mac address-table address {0}'.format(mac))

    macaddrlist = findkey(macaddroutput, 'ROW_mac_address')
    if not macaddrlist:
        return None

    macentries = []
    for macaddr in macaddrlist:
        if isinstance(macaddr, dict):
            macentries.append(macaddr)
        elif isinstance(macaddr, list):
            macentries.extend(macaddr)

    entries = []
    for macaddr in macentries:
        vlan = macaddr['disp_vlan']
        mac = macaddr['disp_mac_addr']
        entrytype = macaddr['disp_type']
        age = macaddr['disp_age']
        secure = macaddr['disp_is_secure']
        ntfy = macaddr['disp_is_ntfy']
        port = macaddr['disp_port']

        if vlanfilter and vlan != vlanfilter:
            continue

        entries.append([vlan, mac, entrytype, age, secure, ntfy, port, port])

    return entries
Exemple #2
0
def getportchannelmembers(device, port):
    dev = device
    deviceConnection = nxapirest.NXRestAPI(dev.ip, dev.user, dev.passw)
    po = deviceConnection.get_JSON_NX_API(
        'show port-channel summary int {0}'.format(port))
    members = findkey(po, 'port')
    return members
Exemple #3
0
    def process_facts(self):
        headers = {
            'Accept': 'application/json, text/javascript',
            'Content-Type': 'application/json',
            'Accept-Language': 'en-US'
        }

        print 'Processing facts'
        #print self.command_list
        #print self.device.ip

        nx_reqestor = nxapirest.NXRestAPI('http://' + self.device.ip + '/ins')
        for cmd in self.command_list:
            print type(cmd)
            cmdkey, cmdval, payload = self.build_payload(cmd)

            resp = nx_reqestor.get_nexus_info_request(
                headers=headers, payload=json.dumps(payload))
            if resp is not None:
                resp = resp.json()
                resp = resp['ins_api']['outputs']['output']['body']

                dump_dict = {}
                dump_dict[cmdkey.lower()] = resp

                #print dump_dict
                dump = Dumper(dump_dict, self.device.name)
Exemple #4
0
def getportfromchannel(device, portchannel, sourceip, sourceport,
                       destinationip, destinationport):
    dev = device
    deviceConnection = nxapirest.NXRestAPI(dev.ip, dev.user, dev.passw)
    clicommand = deviceConnection.get_ASCII_NX_API(
        'show port-channel load-balance forwarding-path interface port-channel {0} src-ip {1} l4-src-port {2} dst-ip {3} l4-dst-port {4}'
        .format(portchannel, sourceip, sourceport, destinationip,
                destinationport))
    activeMember = clicommand.splitlines()[0]
    activeMember = activeMember.split('PC member: ')[1]
    return activeMember
Exemple #5
0
def getcdpentry(device, port):
    # Next use the interface we found the device on from CAM and look it up in
    # CDP
    dev = device
    deviceConnection = nxapirest.NXRestAPI(dev.ip, dev.user, dev.passw)
    cdp = deviceConnection.get_JSON_NX_API(
        'show cdp neighbor interface {0}'.format(port))
    cdp = findkey(cdp, 'ROW_cdp_neighbor_brief_info')
    if not cdp:
        raise Exception('Unable to find {0} in CDP output'.format(port))
    if len(cdp) > 0:
        cdp = cdp[0]
    return cdp
Exemple #6
0
def getarpentry(device, ip=None, vrf='all'):
    # Check the output of the ARP table for the IP address in question
    dev = device
    deviceConnection = nxapirest.NXRestAPI(dev.ip, dev.user, dev.passw)
    deviceConnection.get_JSON_NX_API('sh ip arp {0} vrf {1}'.format(ip, vrf))
    if ip:
        arpoutput = deviceConnection.get_JSON_NX_API(
            'sh ip arp {0} vrf {1}'.format(ip, vrf))
    else:
        arpoutput = deviceConnection.get_JSON_NX_API(
            'show ip arp vrf {0}'.format(vrf))

    rowadjlist = findkey(arpoutput, 'ROW_adj')
    if not rowadjlist:
        return None

    # flatten out the data received from show ip arp into a list of dicts
    arpentries = []
    for rowadj in rowadjlist:
        if isinstance(rowadj, dict):
            arpentries.append(rowadj)
        elif isinstance(rowadj, list):
            arpentries.extend(rowadj)

    arplist = []
    for arp in arpentries:
        try:
            arplist.append([
                arp['ip-addr-out'], arp['time-stamp'], arp['mac'],
                arp['intf-out']
            ])
        except KeyError:
            continue
    #print "Printing ARP List for {0}".format(dev.name)
    #print arplist
    return arplist