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."
Please help me to fix this issue.
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.)
I tried to run simple hellowolrd python program but it stil gives the same error operation not permitted
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:
Then you will be able to run the script as follows
lab@vMX-1> op device_info.py
Serial number: VMXXXXXXXX
You also need to have the following configured
lab@vMX-1# show system scripts
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
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
Hello, i see that you are using a usernamed "lab" what privilages does this user has ?
did you run the tests with user root and if yes were the results same as seen with user lab ?