salt.modules.junos

Module to interact with Junos devices.

maturity:new
dependencies:junos-eznc, jxmlease

Note

Those who wish to use junos-eznc (PyEZ) version >= 2.1.0, must use the latest salt code from github until the next release.

Refer to junos for information on connecting to junos proxy.

salt.modules.junos.cli(command=None, format='text', **kwargs)

Executes the CLI commands and returns the output in specified format. (default is text) The ouput can also be stored in a file.

Usage:

salt 'device_name' junos.cli 'show system commit'

salt 'device_name' junos.cli 'show version' dev_timeout=40

salt 'device_name' junos.cli 'show system alarms' 'xml' dest=/home/user/cli_output.txt
Parameters:
  • Required --
    • command: The command that need to be executed on Junos CLI. (default = None)
  • Optional --
    • format: Format in which to get the CLI output. (text or xml, default = 'text')
    • kwargs: Keyworded arguments which can be provided like-
      • dev_timeout: Set NETCONF RPC timeout. Can be used for commands which take a while to execute. (default = 30 seconds)
      • dest: The destination file where the CLI output can be stored. (default = None)
salt.modules.junos.commit(**kwargs)

To commit the changes loaded in the candidate configuration.

Usage:

salt 'device_name' junos.commit comment='Commiting via saltstack' detail=True

salt 'device_name' junos.commit dev_timeout=60 confirm=10

salt 'device_name' junos.commit sync=True dev_timeout=90
Parameters:Optional --
  • kwargs: Keyworded arguments which can be provided like-
    • dev_timeout: Set NETCONF RPC timeout. Can be used for commands which take a while to execute. (default = 30 seconds)
    • comment: Provide a comment to the commit. (default = None)
    • confirm: Provide time in minutes for commit confirmation. If this option is specified, the commit will be rollbacked in the given time unless the commit is confirmed.
    • sync: On dual control plane systems, requests that the candidate configuration on one control plane be copied to the other control plane,checked for correct syntax, and committed on both Routing Engines. (default = False)
    • force_sync: On dual control plane systems, force the candidate configuration on one control plane to be copied to the other control plane.
    • full: When set to True requires all the daemons to check and evaluate the new configuration.
    • detail: When true return commit detail.
salt.modules.junos.commit_check()

Perform a commit check on the configuration.

Usage:

salt 'device_name' junos.commit_check
salt.modules.junos.diff(id=0)

Gives the difference between the candidate and the current configuration.

Usage:

salt 'device_name' junos.diff 3
Parameters:Optional --
  • id: The rollback id value [0-49]. (default = 0)
salt.modules.junos.facts()

Displays the facts gathered during the connection. These facts are also stored in Salt grains.

Usage:

salt 'device_name' junos.facts
salt.modules.junos.facts_refresh()

Reload the facts dictionary from the device. Usually only needed if, the device configuration is changed by some other actor. This function will also refresh the facts stored in the salt grains.

Usage:

salt 'device_name' junos.facts_refresh
salt.modules.junos.file_copy(src=None, dest=None)

Copies the file from the local device to the junos device.

Usage:

salt 'device_name' junos.file_copy /home/m2/info.txt info_copy.txt
Parameters:Required --
  • src: The sorce path where the file is kept.
  • dest: The destination path where the file will be copied.
salt.modules.junos.install_config(path=None, **kwargs)

Installs the given configuration file into the candidate configuration. Commits the changes if the commit checks or throws an error.

Usage:

salt 'device_name' junos.install_config 'salt://production/network/routers/config.set'

salt 'device_name' junos.install_config 'salt://templates/replace_config.conf' replace=True comment='Committed via SaltStack'

salt 'device_name' junos.install_config 'salt://my_new_configuration.conf' dev_timeout=300 diffs_file='/salt/confs/old_config.conf' overwrite=True

salt 'device_name' junos.install_config 'salt://syslog_template.conf' template_vars='{"syslog_host": "10.180.222.7"}'
Parameters:
  • Required --
    • path: Path where the configuration/template file is present. If the file has a '.conf' extension, the content is treated as text format. If the file has a '.xml' extension, the content is treated as XML format. If the file has a '*.set' extension, the content is treated as Junos OS 'set' commands.(default = None)
  • Optional --
    • kwargs: Keyworded arguments which can be provided like-
      • mode: The mode in which the configuration is locked. (Options: private, dynamic, batch, exclusive; default= exclusive)
      • dev_timeout: Set NETCONF RPC timeout. Can be used for commands which take a while to execute. (default = 30 seconds)
      • overwrite: Set to True if you want this file is to completely replace the configuration file. (default = False)
      • replace: Specify whether the configuration file uses "replace:" statements. Those statements under the 'replace' tag will only be changed. (default = False)
      • format: Determines the format of the contents.
      • update: Compare a complete loaded configuration against the candidate configuration. For each hierarchy level or configuration object that is different in the two configurations, the version in the loaded configuration replaces the version in the candidate configuration. When the configuration is later committed, only system processes that are affected by the changed configuration elements parse the new configuration. This action is supported from PyEZ 2.1 (default = False)
      • comment: Provide a comment to the commit. (default = None)
      • confirm: Provide time in minutes for commit confirmation. If this option is specified, the commit will be rollbacked in the given time unless the commit is confirmed.
      • diffs_file: Path to the file where the diff (difference in old configuration and the committed configuration) will be stored.(default = None) Note that the file will be stored on the proxy minion. To push the files to the master use the salt's following execution module: cp.push
      • template_vars: Variables to be passed into the template processing engine in addition to those present in __pillar__, __opts__, __grains__, etc. You may reference these variables in your template like so: {{ template_vars["var_name"] }}
salt.modules.junos.install_os(path=None, **kwargs)

Installs the given image on the device. After the installation is complete the device is rebooted, if reboot=True is given as a keyworded argument.

Usage:

salt 'device_name' junos.install_os 'salt://images/junos_image.tgz' reboot=True

salt 'device_name' junos.install_os 'salt://junos_16_1.tgz' dev_timeout=300
Parameters:
  • Required --
    • path: Path where the image file is present on the proxy minion.
  • Optional --
    • kwargs: keyworded arguments to be given such as dev_timeout, reboot etc
      • dev_timeout: Set NETCONF RPC timeout. Can be used to RPCs which take a while to execute. (default = 30 seconds)
      • reboot: Whether to reboot after installation (default = False)
      • no_copy: When True the software package will not be SCP’d to the device. (default = False)
salt.modules.junos.load(path=None, **kwargs)

Loads the configuration from the file provided onto the device.

Usage:

salt 'device_name' junos.load 'salt://production/network/routers/config.set'

salt 'device_name' junos.load 'salt://templates/replace_config.conf' replace=True

salt 'device_name' junos.load 'salt://my_new_configuration.conf' overwrite=True

salt 'device_name' junos.load 'salt://syslog_template.conf' template_vars='{"syslog_host": "10.180.222.7"}'
Parameters:
  • Required --
    • path: Path where the configuration/template file is present. If the file has a '.conf' extension, the content is treated as text format. If the file has a '.xml' extension, the content is treated as XML format. If the file has a '*.set' extension, the content is treated as Junos OS 'set' commands.(default = None)
  • Optional --
    • kwargs: Keyworded arguments which can be provided like-
      • overwrite: Set to True if you want this file is to completely replace the configuration file. (default = False)
      • replace: Specify whether the configuration file uses "replace:" statements. Those statements under the 'replace' tag will only be changed. (default = False)
      • format: Determines the format of the contents.
      • update: Compare a complete loaded configuration against the candidate configuration. For each hierarchy level or configuration object that is different in the two configurations, the version in the loaded configuration replaces the version in the candidate configuration. When the configuration is later committed, only system processes that are affected by the changed configuration elements parse the new configuration. This action is supported from PyEZ 2.1 (default = False)
      • template_vars: Variables to be passed into the template processing engine in addition to those present in __pillar__, __opts__, __grains__, etc. You may reference these variables in your template like so: {{ template_vars["var_name"] }}
salt.modules.junos.lock()

Attempts an exclusive lock on the candidate configuration. This is a non-blocking call.

Note

Any user who wishes to use lock, must necessarily unlock the configuration too. Ensure unlock is called in the same orchestration run in which the lock is called.

Usage:

salt 'device_name' junos.lock
salt.modules.junos.ping(dest_ip=None, **kwargs)

To send ping RPC to a device.

Usage:

salt 'device_name' junos.ping '8.8.8.8' count=5

salt 'device_name' junos.ping '8.8.8.8' ttl=1 rapid=True
Parameters:
  • Required --
    • dest_ip: The IP which is to be pinged. (default = None)
  • Optional --
    • kwargs: Keyworded arguments which can be provided like-
      • dev_timeout: Set NETCONF RPC timeout. Can be used for commands which take a while to execute. (default = 30 seconds)
      • rapid: Setting this to True executes ping at 100pps instead of 1pps. (default = False)
      • ttl: Maximum number of IP routers (IP hops) allowed between source and destination.
      • routing_instance: Name of the routing instance to use to send the ping.
      • interface: Interface used to send traffic out.
      • count: Number of packets to send. (default = 5)
salt.modules.junos.rollback(id=0, **kwargs)

To rollback the last committed configuration changes and commit the same.

Usage:

salt 'device_name' junos.rollback 10
Parameters:Optional --
  • id: The rollback id value [0-49]. (default = 0)
  • kwargs: Keyworded arguments which can be provided like-
    • dev_timeout: Set NETCONF RPC timeout. Can be used for commands which take a while to execute. (default = 30 seconds)
    • comment: Provide a comment to the commit. (default = None)
    • confirm: Provide time in minutes for commit confirmation. If this option is specified, the commit will be rollbacked in the given time unless the commit is confirmed.
    • diffs_file: Path to the file where any diffs will be written. (default = None)
salt.modules.junos.rpc(cmd=None, dest=None, format='xml', **kwargs)

This function executes the rpc provided as arguments on the junos device. The returned data can be stored in a file.

Usage:

salt 'device' junos.rpc 'get_config' '/var/log/config.txt' 'text' filter='<configuration><system/></configuration>'

salt 'device' junos.rpc 'get-interface-information' '/home/user/interface.xml' interface_name='lo0' terse=True

salt 'device' junos.rpc 'get-chassis-inventory'
Parameters:
  • Required --
    • cmd: The rpc to be executed. (default = None)
  • Optional --
    • dest: Destination file where the rpc ouput is stored. (default = None) Note that the file will be stored on the proxy minion. To push the files to the master use the salt's following execution module: cp.push
    • format: The format in which the rpc reply is received from the device. (default = xml)
    • kwargs: keyworded arguments taken by rpc call like-
      • dev_timeout: Set NETCONF RPC timeout. Can be used for commands which take a while to execute. (default= 30 seconds)
      • filter: Only to be used with 'get-config' rpc to get specific configuration.
      • terse: Amount of information you want.
      • interface_name: Name of the interface whose information you want.
salt.modules.junos.set_hostname(hostname=None, **kwargs)

To set the name of the device.

Usage:

salt 'device_name' junos.set_hostname salt-device
Parameters:
  • Required --
    • hostname: The name to be set. (default = None)
  • Optional --
    • kwargs: Keyworded arguments which can be provided like-
      • dev_timeout: Set NETCONF RPC timeout. Can be used for commands which take a while to execute. (default = 30 seconds)
      • comment: Provide a comment to the commit. (default = None)
      • confirm: Provide time in minutes for commit confirmation. If this option is specified, the commit will be rollbacked in the given time unless the commit is confirmed.
salt.modules.junos.shutdown(**kwargs)

Shut down (power off) or reboot a device running Junos OS. This includes all Routing Engines in a Virtual Chassis or a dual Routing Engine system.

Usage:

salt 'device_name' junos.shutdown reboot=True

salt 'device_name' junos.shutdown shutdown=True in_min=10

salt 'device_name' junos.shutdown shutdown=True
Parameters:Optional --
  • kwargs:
    • shutdown: Set this to true if you want to shutdown the machine. (default=False, this is a safety mechanism so that the user does not accidentally shutdown the junos device.)
    • reboot: Whether to reboot instead of shutdown. (default=False) Note that either one of the above arguments has to be specified (shutdown or reboot) for this function to work.
    • at: Date and time the reboot should take place. The string must match the junos cli reboot syntax (To be used only if reboot=True)
    • in_min: Specify delay in minutes for shutdown
salt.modules.junos.unlock()

Unlocks the candidate configuration.

Usage:

salt 'device_name' junos.unlock
salt.modules.junos.zeroize()

Resets the device to default factory settings

Usage:

salt 'device_name' junos.zeroize