Automation

Expand all | Collapse all

PyEz Inline Table View not returning any data from VirtualBox JunOS image

Jump to Best Answer
  • 1.  PyEz Inline Table View not returning any data from VirtualBox JunOS image

    Posted 08-05-2018 09:50

    Hi,

    I'm using VirtualBox on Windows 10 and am running the following image: Juniper JunOS Olive12.1R1.9 Virtualbox image.ova. I'm also using Python 3.6.3 with PyEz installed through pip. I have two scripts one for getting box health (CPU, memory, temprature etc.) and the other for getting network interface based I/O bytes and other traffic attributes. The problem is both the scripts exit with "Process finished with exit code 0" with returning any thing. Well the network script only prints the MTU size even though there are other values I'm trying to print. I'm copy/pasting my code and the outputs here. Any and all help would be appreciated. If this is not the right place for asking this question I apologize and will rectify the problem if asked.

     

    BTW if I try to execute the RPCs from the tables in JunOS directly I get error: Unrecognized command (chassis-control)

     

     

    #netstats.py
    from jnpr.junos import Device
    from jnpr.junos.factory.factory_loader import FactoryLoader
    import yaml

    yaml_data = """
    ---
    EthPortTable:
    rpc: get-interface-information
    args:
    media: True
    interface_name: '[afgxe]m*'
    args_key: interface_name
    item: physical-interface
    view: EthPortView
    EthPortView:
    groups:
    mac_stats: ethernet-mac-statistics
    flags: if-device-flags
    fields:
    oper: oper-status
    admin: admin-status
    description: description
    mtu: { mtu : int }
    link_mode: link-mode
    macaddr: current-physical-address
    fields_mac_stats:
    rx_bytes: input-bytes
    rx_packets: input-packets
    tx_bytes: output-bytes
    tx_packets: output-packets
    fields_flags:
    running: { ifdf-running: flag }
    present: { ifdf-present: flag }
    """

    dev = Device(host='192.168.56.20', user='root', password='njamal99', gather_facts=False)
    dev.open()

    globals().update(FactoryLoader().load(yaml.load(yaml_data)))
    hostmetrics = EthPortTable(dev)
    hostmetrics.get()
    for hostmetric in hostmetrics:
    print('status: ', hostmetric.oper)
    print('admin: ', hostmetric.admin)
    print('rx_bytes:', hostmetric.rx_bytes)
    print('rx_packets:', hostmetric.rx_packets)
    print('tx_packets:', hostmetric.tx_packets)
    print('mtu:', hostmetric.mtu)

    dev.close()

     

    Output from netstats.py:

    status: up
    admin: up
    rx_bytes: None
    rx_packets: None
    tx_packets: None
    mtu: 1514

    Process finished with exit code 0

    #hoststats.py
    from jnpr.junos import Device
    from jnpr.junos.factory.factory_loader import FactoryLoader
    import yaml

    yaml_data="""
    ---
    REStats:
    rpc: get-route-engine-information
    key: mastership-state
    item: route-engine
    view: REStatsView

    REStatsView:
    fields:
    status: status
    used: cpu-idle
    cpu-user : cpu-user
    cpu-background: cpu-background
    cpu-interrupt: cpu-interrupt
    cpu-system: cpu-system
    cpu-load_average: load-average-five
    temperature : temperature/@celsius
    memory: memory-buffer-utilization
    """

    dev = Device(host='192.168.56.20', user='root', password='njamal99', gather_facts=False)
    dev.open()

    globals().update(FactoryLoader().load(yaml.load(yaml_data)))
    hostmetrics = REStats(dev)
    hostmetrics.get()
    for hostmetric in hostmetrics:
    print('status: ', hostmetric.status)
    print('cpu_used: ', hostmetric.used)
    print('cpu-user:', hostmetric.cpu-user)
    print('cpu-background:', hostmetric.cpu-background)
    print('cpu-system:', hostmetric.cpu-system)
    print(hostmetrics)

    dev.close()

     

     

    Output from hoststats.py:

    Process finished with exit code 0

     

    Many thanks,

     

    Tahir-PyEz


    #PyEzVirtualBoxJunOSTableViews


  • 2.  RE: PyEz Inline Table View not returning any data from VirtualBox JunOS image

     
    Posted 08-05-2018 15:12

    Hi,

     

    It is possible that the rpc that you are trying to use does not exist in 12.x. 

     

    So if you do;

     

    show chassis routing-engine | display xml
    show chassis routing-engine | display xml rpc
    show interfaces media | display xml
    show interfaces media | display xml rpc
    

    Attach the XML outputs here so that we can see the responses. If the XML schema has changed then the curent table views that you are using may not support junos 12.x

     

    Tim



  • 3.  RE: PyEz Inline Table View not returning any data from VirtualBox JunOS image

    Posted 08-07-2018 05:30
      |   view attached

    Hi Tim, thanks very much for replying. Here is the output:

    https://www.dropbox.com/s/80bk9k81nap7a8r/JunOS%20Output%20A.docx?dl=0

    Please let me know if you have trouble looking at it. It was not possible to copy paste out of the running VM. Next time I'll remember to map a folder from my host machine 🙂 

    Again, your help is much appreciated!

    Attachment(s)

    docx
    JunOS Output A.docx   120 K 1 version


  • 4.  RE: PyEz Inline Table View not returning any data from VirtualBox JunOS image

    Posted 08-07-2018 07:28

    Hi Tim,

     

    I had another idea. Since I'm using PyEz are there any built-in operational PyEZ based tables and views for network interface stats and host health metrics like cpu, memory, temperature, disk i/o etc.?

     I just executed an example from the PyEz manual PDF page 140. It resulted in an empty array. I only have em0 defined could that be the issue that I have basically a simple JunOS vm with only em0 and nothing else?

     

    #Example from the PyEz Manual

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

    dev = Device(host='192.168.56.20', user='root', password='njamal99', gather_facts=False)
    dev.open()

    eths = EthPortTable(dev).get()
    for port in eths:
    print("{}: {}".format(port.name, port.oper))

    #print (eths.values())
    print(eths.items())
    dev.close()

    #########################

    Output:

    []

    Process finished with exit code 0

     

    I should see something similar to this instead:

    [('ge-0/3/0', [('oper', 'down'), ('rx_packets', '0'), ('macaddr',
    '00:00:5E:00:53:01'), ('description', None), ('rx_bytes', '0'), ('admin', 'up'),
    ('mtu', 1514), ('running', True), ('link_mode', None), ('tx_bytes', '0'),
    ('tx_packets', '0'), ('present', True)])]

     

    Many thanks,

     

    Tahir



  • 5.  RE: PyEz Inline Table View not returning any data from VirtualBox JunOS image
    Best Answer

     
    Posted 08-08-2018 18:42

    Hi,

     

    The Olive does not have a routing engine attached so that is why you are unable to get any output.

     

    For the interface output it looks correct and you are getting the values from the interface. Have you exited the python script or just finished it with dev.close()?

     

    You should look at running a vSRX as the Olive has limited functionality and an older XML schema.

     

    Tim



  • 6.  RE: PyEz Inline Table View not returning any data from VirtualBox JunOS image

    Posted 08-14-2018 12:55

    Hi Tim,

    Sorry for the radio silence. I'm working on a couple of projects and am not the best multi-tasker:) My friend you are 100% correct. vSRX does have a routing engine and I was able to get a good response using the rpc: get-route-engine-information (while executing my hoststats.py):

    master [('status', 'OK'), ('used', '79'), ('cpu-user', '10'), ('cpu-background', '0'), ('cpu-interrupt', '0'), ('cpu-system', '11'), ('cpu-load_average', '0.52'), ('temperature', None), ('memory', '10')]

     

    Now if I could just get the rpc: get-interface-information to work that would be awesome. BTW I had to use the AWS version of the vSRX. Do you think there is a virtualbox image that I can use to keep it on the free side?

     

    Many thanks and KUDOS!!!!