Junos OS

Expand all | Collapse all

Junos - python : operation not permitted

  • 1.  Junos - python : operation not permitted

    Posted 10-31-2018 21:21

    I have reserved Standalone vMX in Juniper lab. I want to test running python code on Junos.

     

     

    When I am running command python or python or python --version or running simple hello python program then it is giving error "/usr/bin/python: Operation not permitted."

     

    PFA.

     

    Please help me to fix this issue.



  • 2.  RE: Junos - python : operation not permitted

     
    Posted 10-31-2018 22:40

    Hi

     

    Python interactive mode is not supported on-box on a Junos device. Instead you can run scripts from files. See e.g. Recipe 17 in "Day One: Junos PyEZ Cookbook" (you can download in for free from https://www.juniper.net/uk/en/training/jnbooks/day-one/automation-series/junos-pyez-cookbook/).

     

    If you want to use Python interactive mode with Junos/PyEZ, you  still can do it from remote server (Linux, etc.)

     



  • 3.  RE: Junos - python : operation not permitted

    Posted 11-01-2018 00:03

    I tried to run simple hellowolrd python program but it stil gives the same error operation not permitted



  • 4.  RE: Junos - python : operation not permitted

     
    Posted 11-01-2018 03:07

    Hi 

     

    I assume this may be due to inappropriate permissions for Python file. Generally it should be something like this, for device_info.py script:

    lab@vMX-1> file list /var/db/scripts/op/ detail | match device_info.py 
    -rw-r--r--  1 lab   wheel        309 Jul 19  2017 device_info.py

    I.e., write permissions must only be available for script owner. See the following URL for more details on permissions and running scripts: 

    https://www.juniper.net/documentation/en_US/junos/topics/reference/general/junos-script-automation-python-scripts-requirements-for-executing.html

     

    Then you will be able to run the script as follows

    lab@vMX-1> op device_info.py 
    Model: VMX
    Serial number: VMXXXXXXXX

    You also need to have the following configured

    lab@vMX-1# show system scripts 
    op {
        file device_info.py;
    }
    language python;

    The content of the example script is below

    lab@vMX-1> file show /var/db/scripts/op/device_info.py 
     
    from junos import Junos
    from junos import Junos_Context
    from jnpr.junos import Device   # PyEZ
    import jcs
     
    jdev = Device().open()
    inv = jdev.rpc.get_chassis_inventory()
     
    print "Model: %s" % inv.find('chassis/description').text
    print "Serial number: %s" % inv.find('chassis/serial-number').text
     
    jdev.close()

     

     



  • 5.  RE: Junos - python : operation not permitted

    Posted 12-31-2019 15:33

    Hello, i see that you are using a usernamed "lab" what privilages does this user has ? 



  • 6.  RE: Junos - python : operation not permitted

    Posted 12-31-2019 15:34

    did you run the tests with user root and if yes were the results same as seen with user lab ?