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()