예제 #1
0
def main():
    '''
    For each of the SRX's interfaces, display: the operational state,
    packets-in, and packets-out. You will probably want to use EthPortTable for
    this.
    '''
    pwd = getpass()
    try:
        a_device = Device(host='184.105.247.76', user='******', password=pwd)
        a_device.open()
        ports = EthPortTable(a_device)
        ports.get()
        print "\n"*2
        for port in ports.keys():
            print "#"*80
            print "Operational state, Packets-in and Packets-out for Port {0} are :".format(port)
            print "#"*80
            print "Operational state is : {0}".format(ports[port]['oper'])
            print "Packets-in are : {0}".format(ports[port]['rx_packets'])
            print " Packets-out are : {0}".format(ports[port]['tx_packets'])
            print "*"*80
            print "\n"*2
        print
    except:
        print
        print "Authentication Error"
        print
예제 #2
0
def getports(thedevice):
    """
    Retrieve ports list
    """
    ports = EthPortTable(thedevice)
    ports.get()
    return ports
예제 #3
0
def main():

    juniper_srx = {
        "host": "184.105.247.76",
        "user": "******",
        "password": "******"
    }

    print("\n\nConnecting to Juniper SRX...\n")
    a_device = Device(**juniper_srx)
    a_device.open()

    eth_ports = EthPortTable(a_device)
    eth_ports.get()

    print("{:>15} {:>12} {:>12} {:>12}".format("INTF", "OPER STATE",
                                               "IN PACKETS", "OUT PACKETS"))
    for intf, eth_stats in eth_ports.items():
        eth_stats = dict(eth_stats)
        oper_state = eth_stats['oper']
        pkts_in = eth_stats['rx_packets']
        pkts_out = eth_stats['tx_packets']
        print("{:>15} {:>12} {:>12} {:>12}".format(intf, oper_state, pkts_in,
                                                   pkts_out))
    print()
예제 #4
0
def getports(thedevice):
    """
    Retrieve ports list
    """
    ports = EthPortTable(thedevice)
    ports.get()
    return ports
예제 #5
0
def main():
    '''
    Connect to Juniper device using PyEZ. Display operational state and pkts_in, pkts_out for all
    of the interfaces.
    '''
    #pwd = getpass()
    pwd = '88newclass'
    #ip_addr = raw_input("Enter Juniper SRX IP: ")
    ip_addr = '50.76.53.27'
    ip_addr = ip_addr.strip()

    juniper_srx = {
        "host": ip_addr,
        "user": "******",
        "password": pwd
    }

    print "\n\nConnecting to Juniper SRX...\n"
    a_device = Device(**juniper_srx)
    a_device.open()

    eth_ports = EthPortTable(a_device)
    eth_ports.get()

    print "{:>15} {:>12} {:>12} {:>12}".format("INTF", "OPER STATE", "IN PACKETS", "OUT PACKETS")
    for intf, eth_stats in eth_ports.items():
        eth_stats = dict(eth_stats)
        oper_state = eth_stats['oper']
        pkts_in = eth_stats['rx_packets']
        pkts_out = eth_stats['tx_packets']
        print "{:>15} {:>12} {:>12} {:>12}".format(intf, oper_state, pkts_in, pkts_out)
    print
예제 #6
0
def main():
    '''
    Connect to Juniper device using PyEZ. Display operational state and pkts_in, pkts_out for all
    of the interfaces.
    '''
    pwd = getpass()
    ip_addr = raw_input("Enter Juniper SRX IP: ")
    ip_addr = ip_addr.strip()

    juniper_srx = {"host": ip_addr, "user": '******', "password": pwd}

    print "\n\nConnecting to Juniper SRX...\n"
    # create device object with all the arguments in the dictionary
    a_device = Device(**juniper_srx)
    a_device.open()
    # get the ethernet port table
    eth_ports = EthPortTable(a_device)
    eth_ports.get()

    print "{:>15} {:>12} {:>12} {:>12}".format("INTF", "OPER STATE",
                                               "IN PACKETS", "OUT PACKETS")
    for intf, eth_stats in eth_ports.items():
        eth_stats = dict(eth_stats)
        oper_state = eth_stats['oper']
        pkts_in = eth_stats['rx_packets']
        pkts_out = eth_stats['tx_packets']
        print "{:>15} {:>12} {:>12} {:>12}".format(intf, oper_state, pkts_in,
                                                   pkts_out)
    print
예제 #7
0
def main():
    '''
    Connect to Juniper device using PyEZ. Display operational state and pkts_in, pkts_out for all
    of the interfaces.
    '''
    pwd = getpass()
    try:
        ip_addr = raw_input("Enter Juniper SRX IP: ")
    except NameError:
        ip_addr = input("Enter Juniper SRX IP: ")
    ip_addr = ip_addr.strip()

    juniper_srx = {"host": ip_addr, "user": "******", "password": pwd}

    print("\n\nConnecting to Juniper SRX...\n")
    a_device = Device(**juniper_srx)
    a_device.open()

    eth_ports = EthPortTable(a_device)
    eth_ports.get()

    print("{:>15} {:>12} {:>12} {:>12}".format("INTF", "OPER STATE",
                                               "IN PACKETS", "OUT PACKETS"))
    for intf, eth_stats in eth_ports.items():
        eth_stats = dict(eth_stats)
        oper_state = eth_stats['oper']
        pkts_in = eth_stats['rx_packets']
        pkts_out = eth_stats['tx_packets']
        print("{:>15} {:>12} {:>12} {:>12}".format(intf, oper_state, pkts_in,
                                                   pkts_out))
    print()
class JuniperObject(object):
    def __init__(self, jnp_dev):
        self.conn = jnp_dev
        self.config = None
        self.ports = {}
        self.routes = {}

    def __get_ports(self):
        self.ports = EthPortTable(self.conn)
        self.ports.get()

    def __get_routes(self):
        self.routes = RouteTable(self.conn)
        self.routes.get()
   
    def config_mode(self):
        self.config = Config(self.conn)
        self.config.lock()

    def send_command(self, command, cmd_format, cmd_merge):
        self.config.load(command, format=cmd_format, merge=cmd_merge)

    def file_command(self, file_path, file_format, file_merge):
        self.config.load(path=file_path, format=file_format, merge=file_merge)
   
    def get_diff(self):
        return self.config.diff()

    def commit(self, comment=None):
        self.config.commit(comment=comment)
   
    def rollback(self):
        self.config.rollback(0)

    def unlock(self):
        self.config.unlock()

    def show_all_interfaces(self):
        self.__get_ports()
        print "Juniper SRX Interface Statistics"
        for my_key in self.ports.keys():
            print "---------------------------------"
            print my_key + ":"
            print "Operational Status: " + self.ports[my_key]['oper']
            print "Packets In: " + self.ports[my_key]['rx_packets']
            print "Packets Out: " + self.ports[my_key]['tx_packets']

    def show_all_routes(self):
        self.__get_routes()
        print "Juniper SRX Routing Table"
        for my_key in self.routes.keys():
            print "---------------------------------"
            print my_key + ":"
            print "  Next Hop: {}".format(self.routes[my_key]['nexthop'])
            print "  Age: {}".format(self.routes[my_key]['age'])
            print "  via: {}".format(self.routes[my_key]['via'])
            print "  Protocol: {}".format(self.routes[my_key]['protocol'])
예제 #9
0
class JuniperObject(object):
    def __init__(self, jnp_dev):
        self.conn = jnp_dev
        self.config = None
        self.ports = {}
        self.routes = {}

    def __get_ports(self):
        self.ports = EthPortTable(self.conn)
        self.ports.get()

    def __get_routes(self):
        self.routes = RouteTable(self.conn)
        self.routes.get()

    def config_mode(self):
        self.config = Config(self.conn)
        self.config.lock()

    def send_command(self, command, cmd_format, cmd_merge):
        self.config.load(command, format=cmd_format, merge=cmd_merge)

    def file_command(self, file_path, file_format, file_merge):
        self.config.load(path=file_path, format=file_format, merge=file_merge)

    def get_diff(self):
        return self.config.diff()

    def commit(self, comment=None):
        self.config.commit(comment=comment)

    def rollback(self):
        self.config.rollback(0)

    def unlock(self):
        self.config.unlock()

    def show_all_interfaces(self):
        self.__get_ports()
        print "Juniper SRX Interface Statistics"
        for my_key in self.ports.keys():
            print "---------------------------------"
            print my_key + ":"
            print "Operational Status: " + self.ports[my_key]['oper']
            print "Packets In: " + self.ports[my_key]['rx_packets']
            print "Packets Out: " + self.ports[my_key]['tx_packets']

    def show_all_routes(self):
        self.__get_routes()
        print "Juniper SRX Routing Table"
        for my_key in self.routes.keys():
            print "---------------------------------"
            print my_key + ":"
            print "  Next Hop: {}".format(self.routes[my_key]['nexthop'])
            print "  Age: {}".format(self.routes[my_key]['age'])
            print "  via: {}".format(self.routes[my_key]['via'])
            print "  Protocol: {}".format(self.routes[my_key]['protocol'])
예제 #10
0
    def _get_interfaces(self):
        eth_ifaces = EthPortTable(self.native)
        eth_ifaces.get()

        loop_ifaces = LoopbackTable(self.native)
        loop_ifaces.get()

        ifaces = eth_ifaces.keys()
        ifaces.extend(loop_ifaces.keys())

        return ifaces
예제 #11
0
    def _get_interfaces(self):
        eth_ifaces = EthPortTable(self.native)
        eth_ifaces.get()

        loop_ifaces = LoopbackTable(self.native)
        loop_ifaces.get()

        ifaces = eth_ifaces.keys()
        ifaces.extend(loop_ifaces.keys())

        return ifaces
예제 #12
0
def main(args):
    '''Acquire necessary input options, interact with SRX device as specified per CLI args.'''
    parser = argparse.ArgumentParser(
        description='Interact with specified SRX device as specified')
    parser.add_argument('--version', action='version', version=__version__)
    parser.add_argument('-d', '--datafile', help='specify YAML file to read router info from',
                        default=SRX_FILE)
    parser.add_argument('--prompt', action='store_true',
                        help='prompt for router info (do not try to read in from file)',
                        default=False)
    parser.add_argument('-v', '--verbose', action='store_true', help='display verbose output',
                        default=False)
    args = parser.parse_args()
    # Debugging
    #if args.verbose:
    #    print 'Args = {}'.format(args)

    # Initialize data structures
    mysrx = {}
    if not args.prompt:
        mysrx = yaml_input(args.datafile, args.verbose)
        # Debugging
        #if args.verbose:
        #    print 'mysrx = {}'.format(mysrx)
    else:
        if args.verbose:
            print 'Prompting specified - asking user for all connection details'
    check_input(mysrx, args.verbose)

    mysrx_conn = Device(host=mysrx['HOST'], user=mysrx['USER'], password=mysrx['PASSWORD'])
    if args.verbose:
        print 'Opening NETCONF connection to {}...'.format(mysrx['HOST'])
    mysrx_conn.open()
    # Set timeout - default of 30 seconds can be problematic, must set after open()
    mysrx_conn.timeout = TIMEOUT

    ethports = EthPortTable(mysrx_conn)
    if args.verbose:
        print 'Gathering EthPortTable info from {}...'.format(mysrx['HOST'])
    ethports.get()

    print 'Device Ethernet Port information for {}:'.format(mysrx['HOST'])
    for int_key in ethports.keys():
        print '{}:'.format(int_key)
        for int_subkey in ethports[int_key].keys():
            if int_subkey == 'oper':
                print '  \\Operational Status:   {}'.format(ethports[int_key][int_subkey])
            elif int_subkey == 'rx_packets':
                print '  \\Received Packets:     {}'.format(ethports[int_key][int_subkey])
            elif int_subkey == 'tx_packets':
                print '  \\Transmitted Packets:  {}'.format(ethports[int_key][int_subkey])
    mysrx_conn.close()
예제 #13
0
def main():
    password = getpass()
    device = Device(host = '184.105.247.76', user = '******', password = password)
    
    device.open()
    eth = EthPortTable(device)
    eth.get()
    
    for interface,v in eth.items():
        if interface == "fe-0/0/7":
            print "interface {}".format(interface)
            for field, value in v:
                if 'bytes' in field:
                    print "{} equals {}".format(field, value)
예제 #14
0
def main():
    """Using Juniper's pyez for get interface operations."""
    password = getpass()
    a_device = Device(host='184.105.247.76', user='******', password=password)
    a_device.open()

    eth = EthPortTable(a_device)
    eth.get()
    print
    for intf, v in eth.items():
        if intf == 'fe-0/0/7':
            print 'intf {}: '.format(intf)
            for field_name, field_value in v:
                if 'bytes' in field_name:
                    print "    {:<15} {:<30}".format(field_name, field_value)
    print
예제 #15
0
def main():
    '''
    Main function
    '''
    a_device = remote_conn(HOST, USER, PWD)
    if not a_device:
        sys.exit('Fix the above errors. Exiting...')

    ports = EthPortTable(a_device)
    ports.get()
    for port in ports.keys():
        print port
        port_items = dict(ports[port].items())
        print '   Oper: %s' % (port_items['oper'])
        print '   rx: %s' % (port_items['rx_packets'])
        print '   tx: %s' % (port_items['tx_packets'])
        print
예제 #16
0
def main():

    pwd = getpass()

    juniper = {
        "host": "50.76.53.27",
        "user": "******",
        "password": pwd
    }

    a_device = Device(**juniper)
    a_device.open()

    ports = EthPortTable(a_device)
    ports.get()

    for eth, stats in ports.items():
        stats = dict(stats)
        #print stats
        interface_status = stats['oper']
        packets_in = stats['rx_packets']
        packets_out = stats['tx_packets']
        print "Interface: %s Interface status: %s In Packets: %s Out Packets: %s" % (eth, interface_status, packets_in, packets_out)
예제 #17
0
def main():
    pwd = getpass()

    a_device = Device(host='184.105.247.76', user=USER, password=pwd)
    a_device.open()

    ports = EthPortTable(a_device)
    ports.get()

    print
    print "{:<20} {:<10} {:>20} {:>20}".format('interface', 'state',
                                               'RX packets', 'TX packets')
    for intfc, tuple_list in ports.items():
        for info, stat in tuple_list:
            if info == 'oper':
                oper = stat
            elif info == 'rx_packets':
                rx_packets = stat
            elif info == 'tx_packets':
                tx_packets = stat
        print "{:<20} {:<10} {:>20} {:>20}".format(intfc, oper, rx_packets,
                                                   tx_packets)

    print
예제 #18
0
def get_port_list(host, username, pwd, total_ports_open_lock,
                  device_dict_lock):
    count_up = 0
    connect_timeout = 10

    #global resources shared by all threads
    global total_ports_open
    global device_dict

    try:
        # Connect to devices in devices file using username and password provided above
        dev = Device(host=host.strip(),
                     user=username,
                     password=pwd,
                     port_no=22)
        dev.open(auto_probe=connect_timeout)
        dev.timeout = connect_timeout
        eths = EthPortTable(dev).get()

        # for every port on this device
        for port in eths:
            status = port.oper
            descrip = port.description

            # if the port is a wifi port don't add it
            if descrip not in ["WAPS"] and status in ["up"]:
                count_up += 1

#update our global variables safetly
        with total_ports_open_lock:
            total_ports_open += count_up

        with device_dict_lock:
            device_dict[host] = count_up

        dev.close()

    except ConnectAuthError:
        print "\nAuthentication error on: ", host
    except ConnectError as err:
        print("Cannot connect to device: ".format(err))
    except Exception, e:
        print "\nError ", e, "on host: ", host
예제 #19
0
def add_vlan_and_port(dev):
    from jnpr.junos.op.ethport import EthPortTable
    ports_dict = {}
    eths = EthPortTable(dev).get()
    for port in eths:
        ports_dict[port.name] = port.description

    uplinks = [
        k for k, v in ports_dict.items() if v != None and v.startswith('TRUNK')
    ]
    config_vars = {
        'uplinks': uplinks,
        'client_port': [parser.parse_args().port[0]],
        'interfaces': uplinks + [parser.parse_args().port[0]],
        'vlan': parser.parse_args().vlan[0],
        'trunk_bool': parser.parse_args().tag
    }

    config_file = "templates/junos-config-add-vlans.conf"
    cu = Config(dev, mode='private')
    cu.load(template_path=config_file, template_vars=config_vars, replace=True)
    cu.pdiff()
    apply_config(dev, cu)
예제 #20
0
    "password": getpass(),
}


def juniper_print(k, v):
    print
    print k
    print '-' * 20
    pprint(v)
    print '-' * 20


a_device = Device(**juniper_srx)
a_device.open()

eth_ports = EthPortTable(a_device)
eth_ports.get()
print '-' * 80
print "Ethernet Ports"
for k, v in eth_ports.items():
    juniper_print(k, v)
print '-' * 80
raw_input("Hit enter to continue: ")

arp = ArpTable(a_device)
arp.get()
print '-' * 80
print "ARP"
for k, v in arp.items():
    juniper_print(k, v)
print '-' * 80
예제 #21
0
from jnpr.junos import Device
from jnpr.junos.op.ethport import EthPortTable
from getpass import getpass
from pprint import pprint



pwd = getpass()
a_device = Device(host='50.242.94.227', user='******', password=pwd)
a_device.open()
pprint(a_device.facts)



ports = EthPortTable(a_device)
ports.get()
ports.keys()

ports.items()
ports.values()

ports['fe-0/0/1']
ports['fe-0/0/1'].items()
for k,v in ports['fe-0/0/1'].items():
	print k, v

ports['fe-0/0/1']['oper']
ports['fe-0/0/1']['macaddr']


#!/usr/bin/python

from jnpr.junos import Device
from jnpr.junos.op.ethport import EthPortTable
import time

if __name__ == '__main__':
    dev = Device(host='192.168.108.199', user='******', passwd='lab123')
    dev.open()
    intfs = EthPortTable(dev)
    intfs.get()
    for intf in intfs:
        print "Data: Name %s, Desc %s, Mac %s" % (intf.key, intf.description, intf.macaddr)
    time.sleep(2)
    dev.close() 
예제 #23
0
#!/usr/bin/python

from jnpr.junos import Device
from pprint import pprint
device1 = Device(host='10.1.2.3', user='******', password='******')
device1.open()
pprint(device1.facts)

from jnpr.junos.op.ethport import EthPortTable
ports = EthPortTable(device1)
ports = get()

for k, v in ports['fe-0/0/1'].items():
    print k, v
예제 #24
0
#!/usr/bin/env python
from __future__ import print_function
from jnpr.junos import Device
from jnpr.junos.op.ethport import EthPortTable
from getpass import getpass

juniper_srx = {
    "host": "184.105.247.76",
    "user": "******",
    "password": getpass(),
}

a_device = Device(**juniper_srx)
a_device.open()
eth_ports = EthPortTable(a_device)
eth_ports.get()
print(eth_ports.keys())
예제 #25
0
 def test_optable_view_get_astype_bool(self, mock_execute):
     mock_execute.side_effect = self._mock_manager
     et = EthPortTable(self.dev)
     et.get()
     v = et['ge-0/0/0']
     self.assertEqual(v['present'], True)
예제 #26
0
def assert_interfaces_up(conn, interface):
    with Device(**conn) as dev:
        eths = EthPortTable(dev)
        eths.get(interface)
        for eth in eths:
            assert (eth.oper == 'up' and eth.admin == 'up')
 def __get_ports(self):
     self.ports = EthPortTable(self.conn)
     self.ports.get()
#!/usr/bin/env python
# 2. For each of the SRX's interfaces, display: the operational state, 
# packets-in, and packets-out. You will probably want to use EthPortTable
# for this.

from jnpr.junos import Device
from jnpr.junos.op.ethport import EthPortTable
from pprint import pprint
from getpass import getpass

pwd = getpass()
a_device = Device(host='50.76.53.27', user='******', password=pwd)
a_device.open()     # Establich connection to Juniper SRX device

# Instantiagte an EthPortTable object
ports = EthPortTable(a_device)

# Retrieve data from ports
ports.get()

# Retrieve port numbers and recursively obtain other info from there   
for a_port in ports.keys():
    print ("Port: %s, Operating state: %s, Rx Packets: %s, Tx Packets: %s" 
           % (a_port,
              ports[a_port]['oper'],
              ports[a_port]['rx_packets'],
              ports[a_port]['tx_packets']))
# mm = tamtamnewclass
예제 #29
0
from jnpr.junos import Device
from jnpr.junos.op.ethport import EthPortTable
from getpass import getpass
from pprint import pprint
import warnings
warnings.filterwarnings(action='ignore', module='.*paramiko.*')

# import ipdb

a_device = Device(host="srx2.lasthop.io", user="******", password=getpass())
a_device.open()

# ipdb.set_trace()
ports = EthPortTable(a_device)
ports.get()

print(ports)
print(ports.keys())
# pprint(ports.values())
# pprint(ports.items())
예제 #30
0
from jnpr.junos import Device
# Do not worry if your IDE flags the next import up.
# It will work.
from jnpr.junos.op.ethport import EthPortTable

with Device(host='10.4.4.41', user='******',
            password='******') as dev:
    eths = EthPortTable(dev)
    eths.get()
    for port in eths:
        print("{}: {}".format(port.name, port.oper))
예제 #31
0
from jnpr.junos import Device
from jnpr.junos.op.ethport import EthPortTable
a_device = Device(host="184.105.247.76", user='******', password='******')
a_device.open()
a_device.timeout = 120
ports = EthPortTable(a_device)
ports.get()

for int in ports.keys():
    print '=========='
    print "Stats for interface {}".format(int)
    for k,v in ports[int].items():
        if k == 'rx_packets' or k == 'tx_packets':
            print k, v
    print '=========='

예제 #32
0
파일: ex2.py 프로젝트: patrebert/pynet_cert
#!/bin/env python
#pynet-sf-srx ansible_ssh_host=184.105.247.76 juniper_user=pyclass juniper_passwd=88newclass

import sys
from jnpr.junos import Device
from jnpr.junos.op.ethport import EthPortTable

def get_item(itemlist,key):
    for k,v in itemlist:
        if k==key:
            return v
    return None

a_device = Device(host='184.105.247.76', user='******', password='******')
a_device.open()
ports = EthPortTable(a_device)
jports=ports.get()
items=jports.items()
for key,itemlist in items:
    print key
    for k in ['oper','rx_packets','tx_packets']:
        print "  %s %s" %(k,get_item(itemlist,k))
예제 #33
0
#!/usr/bin/python

import sys
from getpass import getpass
from jnpr.junos import Device
from jnpr.junos.op.ethport import EthPortTable
from pprint import pprint

devlist = ['192.168.2.254']
username = raw_input('username: '******'password: '******'connecting to %s ... ' % hostname)
    #  sys.stdout.flush()

    dev = Device(host=hostname, user=username, password=passwd)
    dev.open()

    ints = EthPortTable(dev).get()
    for int in ints:
        print("%s,%s" % (int.key, int.oper))

    dev.close()
예제 #34
0
# EthPortTable을 이용한 ethernet interface 상태 확인

from jnpr.junos import Device
from jnpr.junos.op.ethport import EthPortTable
from lxml import etree
from pprint import pprint

with Device(host='172.27.14.72', user='******', passwd='jun2per') as dev:
    eth = EthPortTable(dev)
    eth_get = eth.get()

    #print(eth.keys())
    #pprint(eth.values())
    pprint(eth.items())

    for item in eth:
        print("{} : {}".format(item.name, item.oper))
예제 #35
0
device_ip = "192.168.229.185"
user_name = "test"
password = "******"

from jnpr.junos import Device
from jnpr.junos.op.ethport import EthPortTable
from time import sleep
from influxdb.influxdb08 import client
 
device = Device(host=device_ip, port=22, user=user_name, passwd=password)
device.open()
switch_name = device.facts['fqdn']
print 'Connected to', switch_name, '(', device.facts['model'], 'running', device.facts['version'], ')'
ports_table = EthPortTable(device)
 
db = client.InfluxDBClient('localhost', 8086, 'root', 'root', 'network')
print 'Connected to InfluxDB'
 
print 'Collecting metrics...'
columns = ['rx_packets', 'rx_bytes', 'tx_packets', 'tx_bytes']
while True:
  ports = ports_table.get()
  for port in ports:
    point = {'name': switch_name + '.' + port['name'],
             'columns': columns,
             'points': [[int(port['rx_packets']), int(port['rx_bytes']), int(port['tx_packets']), int(port['tx_bytes'])]]}
    db.write_points([point])
  sleep(1) 
예제 #36
0
 def test_optable_view_get_astype_bool(self, mock_execute):
     mock_execute.side_effect = self._mock_manager
     et = EthPortTable(self.dev)
     et.get()
     v = et['ge-0/0/0']
     self.assertEqual(v['present'], True)
예제 #37
0
from jnpr.junos import Device
from jnpr.junos.op.ethport import EthPortTable
from getpass import getpass
from pprint import pprint

srx1 = Device(host="srx1.lasthop.io", user="******", password=getpass())
srx1.open()

ports = EthPortTable(srx1)
ports.get()

print(ports)
pprint(ports.keys())
#pprint(ports.values())
#pprint(ports.items())
예제 #38
0
from jnpr.junos import Device
from jnpr.junos.op.ethport import EthPortTable
from getpass import getpass
from pprint import pprint
import ipdb

a_device = Device(host="srx2.lasthop.io", user="******", password=getpass())
a_device.open()

ipdb.set_trace()
ports = EthPortTable(a_device)
ports.get()

print(ports)
print(ports.keys())
pprint(ports.values())
pprint(ports.items())
예제 #39
0
 def __get_ports(self):
     self.ports = EthPortTable(self.conn)
     self.ports.get()
예제 #40
0
device_ip = "192.168.229.185"
user_name = "test"
password = "******"

from jnpr.junos import Device
from jnpr.junos.op.ethport import EthPortTable
from time import sleep
from influxdb.influxdb08 import client

device = Device(host=device_ip, port=22, user=user_name, passwd=password)
device.open()
switch_name = device.facts['fqdn']
print 'Connected to', switch_name, '(', device.facts[
    'model'], 'running', device.facts['version'], ')'
ports_table = EthPortTable(device)

db = client.InfluxDBClient('localhost', 8086, 'root', 'root', 'network')
print 'Connected to InfluxDB'

print 'Collecting metrics...'
columns = ['rx_packets', 'rx_bytes', 'tx_packets', 'tx_bytes']
while True:
    ports = ports_table.get()
    for port in ports:
        point = {
            'name':
            switch_name + '.' + port['name'],
            'columns':
            columns,
            'points': [[
                int(port['rx_packets']),
예제 #41
0
#### Getter operations
print "\nLLDP Get"
print '-' * 50
lldp = LLDPNeighborTable(a_device)
lldp.get()

for k, v in lldp.items():
    print k
    for entry in v:
        print entry

#### Getter operations
print "\nEth Port Get"
print '-' * 50
eth = EthPortTable(a_device)
eth.get()
pprint(eth.items())

#### Getter operations
print "\nRoute Table Get"
print '-' * 50
z_routes = RouteTable(a_device)
z_routes.get()
pprint(z_routes.items())

#### Config operations
print
print "Current static routes"
print '-' * 50
pprint(z_routes.keys())