Skip to content

pyntc.devices.jnpr_device

Module for using a Juniper junOS device.

pyntc.devices.jnpr_device.JunosDevice

Bases: BaseDevice

Juniper JunOS Device Implementation.

boot_options property

Get os version on device.

Returns:

Type Description
str

OS version on device.

connected property

Get connection status of device.

Returns:

Type Description
bool

True if connection is active. Otherwise, false.

fqdn property

Get fully qualified domain name.

Returns:

Type Description
str

Fully qualified domain name.

hostname property

Get device hostname.

Returns:

Type Description
str

Device hostname.

interfaces property

Get list of interfaces.

Returns:

Type Description
list

List of interfaces.

model property

Get device model.

Returns:

Type Description
str

Device model.

os_version property

Get OS version.

Returns:

Type Description
str

OS version.

running_config property

Get running configuration.

Returns:

Type Description
str

Running configuration.

serial_number property

Get serial number.

Returns:

Type Description
str

Serial number.

startup_config property

Get startup configuration.

Returns:

Type Description
str

Startup configuration.

uptime property

Get device uptime in seconds.

Returns:

Type Description
int

Device uptime in seconds.

uptime_string property

Get device uptime in format dd:hh:mm:ss.

Returns:

Type Description
str

Device uptime.

__init__(host, username, password, *args, **kwargs)

PyNTC device implementation for Juniper JunOS.

Parameters:

Name Type Description Default
host str

The address of the network device.

required
username str

The username to authenticate with the device.

required
password str

The password to authenticate with the device.

required
args tuple

Additional positional arguments to pass to the device.

()
kwargs dict

Additional keyword arguments to pass to the device.

{}

backup_running_config(filename)

Backup current running configuration.

Parameters:

Name Type Description Default
filename str

Name used for backup file.

required

check_file_exists(filename)

Check if a remote file exists by filename.

Parameters:

Name Type Description Default
filename str

The name of the file to check for on the remote device.

required

Returns:

Type Description
bool

True if the remote file exists, False if it doesn't.

checkpoint(filename)

Create checkpoint file.

Parameters:

Name Type Description Default
filename str

Name of checkpoint file.

required

close()

Close connection to device.

compare_file_checksum(checksum, filename, hashing_algorithm='md5')

Compare the checksum of a local file with a remote file.

Parameters:

Name Type Description Default
checksum str

The checksum of the file.

required
filename str

The name of the file to check for on the remote device.

required
hashing_algorithm str

The hashing algorithm to use. Valid values are 'md5', 'sha1', and 'sha256'. Defaults to 'md5'.

'md5'

Returns:

Type Description
bool

True if the checksums match, False otherwise.

config(commands, format_type='set')

Send configuration commands to a device.

Parameters:

Name Type Description Default
commands (str, list)

String with single command, or list with multiple commands.

required
format_type str

Format type for the command. Defaults to "set".

'set'

Raises:

Type Description
ConfigLoadError

Issue with loading the command.

CommandError

Issue with the command provided, if its a single command, passed in as a string.

CommandListError

Issue with a command in the list provided.

file_copy(src, dest=None, **kwargs)

Copy file to device via SCP.

Parameters:

Name Type Description Default
src str

Name of file to be transferred.

required
dest str

Path on device to save file. Defaults to None.

None
kwargs dict

Additional keyword arguments to pass to the file_copy command.

{}

Raises:

Type Description
FileTransferError

Raised when unable to verify file was transferred succesfully.

NotEnoughFreeSpaceError

When the target filesystem has fewer free bytes than src requires.

file_copy_remote_exists(src, dest=None, **kwargs)

Verify device already has existing file.

Parameters:

Name Type Description Default
src str

Source of local file.

required
dest str

Path of file on device. Defaults to None.

None
kwargs dict

Additional keyword arguments to pass to the file_copy command.

{}

Returns:

Type Description
bool

True if hashes of the file match. Otherwise, false.

get_remote_checksum(filename, hashing_algorithm='md5')

Get the checksum of a remote file.

Parameters:

Name Type Description Default
filename str

The name of the file to check for on the remote device.

required
hashing_algorithm str

The hashing algorithm to use. Valid values are those in JUNOS_SUPPORTED_HASHING_ALGORITHMS (md5, sha1, sha256). Defaults to md5.

'md5'

Returns:

Type Description
str

The checksum of the remote file or None if the file is not found.

Raises:

Type Description
ValueError

When hashing_algorithm is not one Junos implements.

install_os(image_name, checksum, reboot=True, hashing_algorithm='md5')

Install OS on device and reboot.

Parameters:

Name Type Description Default
image_name str

Name of image.

required
reboot bool

Whether to reboot the device after setting the boot options. Defaults to true.

True
checksum str

The checksum of the file.

required
hashing_algorithm str

The hashing algorithm to use. Valid values are 'md5', 'sha1', and 'sha256'. Defaults to 'md5'.

'md5'

open()

Open connection to device.

reboot(wait_for_reload=False, timeout=7200, confirm=None)

Reload the controller or controller pair.

Parameters:

Name Type Description Default
wait_for_reload bool

Whether the reboot method should wait for the device to come back up before returning. Defaults to False.

False
timeout int

Time in seconds to wait for the device to return after reboot. Defaults to 2 hours.

7200
confirm None

Not used. Deprecated since v0.17.0.

None
Example

device = JunosDevice(**connection_args) device.reboot()

remote_file_copy(src=None, dest=None, file_system=None, **kwargs)

Copy a file to a remote device.

Parameters:

Name Type Description Default
src FileCopyModel

The source file model.

None
dest str

The destination file path on the remote device.

None
file_system str

Mount point used for the pre-transfer free-space check. When None (the default), the probe uses _JUNOS_DEFAULT_FILE_SYSTEM (/var/tmp).

None
**kwargs Any

Accepted for parity with BaseDevice.remote_file_copy; other drivers may forward extra options.

{}

Raises:

Type Description
TypeError

If src is not an instance of FileCopyModel.

FileTransferError

If there is an error during file transfer or if the file cannot be verified after transfer.

NotEnoughFreeSpaceError

If src.file_size_bytes is set and the target mount point has fewer free bytes than src.file_size_bytes. When file_size is omitted from src the pre-transfer space check is skipped entirely.

rollback(filename)

Rollback to a specific configuration file.

Parameters:

Name Type Description Default
filename str

Filename to rollback device to.

required

save(filename=None)

Save current configuration to device.

If filename is provided, save current configuration to file.

Parameters:

Name Type Description Default
filename str

Filename to save current configuration. Defaults to None.

None

Returns:

Type Description
bool

True if new file created for save file. Otherwise, just returns if save is to default name.

set_boot_options(sys)

Set boot options.

Parameters:

Name Type Description Default
sys str

Name of image to set boot option to.

required

Raises:

Type Description
NotImplementedError

Method currently not implemented.

show(commands)

Send configuration commands to a device.

Parameters:

Name Type Description Default
commands (str, list)

String with single command, or list with multiple commands.

required

Raises:

Type Description
CommandError

Issue with the command provided.

CommandListError

Issue with a command in the list provided.

verify_file(checksum, filename, hashing_algorithm='md5')

Verify a file on the remote device by confirming the file exists and validate the checksum.

Parameters:

Name Type Description Default
checksum str

The checksum of the file.

required
filename str

The name of the file to check for on the remote device.

required
hashing_algorithm str

The hashing algorithm to use (default: "md5").

'md5'

Returns:

Type Description
bool

True if the file is verified successfully, False otherwise.