To remotely access a Junos OS device (physical or virtual), you must import the Device type:
You can obtain help from the Python shell using: help(Device).
To create a Device variable, you must provide at least the target hostname. You can optionally provide the username; if omitted, this will default to the $USER environment value. You can optionally provide a password; if omitted, this will assume that ssh-keys are active. The following code illustrates three ways to access the same device:
Once you've created the Device, you then open a connection:
If an error occurs in the process, an Exception is raised.
You can call-chain the Device create and connection open together:
The default timeout for an RPC to transaction is 30 seconds. You might need to change this value for long running requests. Specifically, if you perform a software upgrade you MUST change this value. You can read or write the timeout value as a Device property:
# read the value
# change the value to 10 minutes
You should explicitly close the Device connection when you are finished.