# 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.

class salt.modules.junos.HandleFileCopy(path, **kwargs)

  To figure out proper path either from proxy local file system or proxy cache or on master. If required, then only copy from master to proxy

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

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

  command (required)

    The command to execute on the Junos CLI

  formattext

    Format in which to get the CLI output (either `text` or `xml`)

  dev_timeout30

    The NETCONF RPC timeout (in seconds)

  dest

    Destination file where the RPC output is stored. Note that the file will be stored on the proxy minion. To push the files to the master use `cp.push`.

  CLI Examples:

      salt 'device_name' junos.cli 'show system commit'
      salt 'device_name' junos.cli 'show system alarms' format=xml dest=/home/user/cli_output.txt

salt.modules.junos.commit(**kwargs)

  To commit the changes loaded in the candidate configuration.

  dev_timeout30

    The NETCONF RPC timeout (in seconds)

  comment

    Provide a comment for the commit

  confirm

    Provide time in minutes for commit confirmation. If this option is specified, the commit will be rolled back in the specified amount of time unless the commit is confirmed.

  syncFalse

    When `True`, 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.

  force_syncFalse

    When `True`, on dual control plane systems, force the candidate configuration on one control plane to be copied to the other control plane.

  full

    When `True`, requires all the daemons to check and evaluate the new configuration.

  detail

    When `True`, return commit detail

  CLI Examples:

      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

salt.modules.junos.commit_check()

  Perform a commit check on the configuration

  CLI Example:

      salt 'device_name' junos.commit_check

salt.modules.junos.diff(**kwargs)

  Returns the difference between the candidate and the current configuration

  id0

    The rollback ID value (0-49)

  d_id0

    The rollback ID value (0-49)

  CLI Example:

      salt 'device_name' junos.diff d_id=3

  NOTE: Because of historical reasons and the internals of the Salt state compiler, there are three possible sources of the rollback ID--the positional argument, and the id and d_id kwargs. The precedence of the arguments are id (positional), id (kwarg), d_id (kwarg). In other words, if all three are passed, only the positional argument will be used. A warning is logged if more than one is passed.

salt.modules.junos.dir_copy(source, dest, force=False, **kwargs)

  Copy a directory and recursively its contents from source to dest.

  Note

  This function only works on the Juniper native minion

  Parameters:

  source : Directory to use as the source

  dest : Directory in which to place the source and its contents.

  force : This function will not copy identical files unless force is True

  Added in version 3003.

  CLI Example:

      salt 'device_name' junos.dir_copy /etc/salt/pki re1:/

  This will take the pki directory, its absolute path and copy it and its contents to routing engine 1 root directory. The result will be re1:/etc/salt/pki/<files and dirs in /etc/salt/pki.

salt.modules.junos.facts()

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

  CLI Example:

      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.

  CLI Example:

      salt 'device_name' junos.facts_refresh

salt.modules.junos.file_compare(file1, file2, **kwargs)

  Compare two files and return a dictionary indicating if they are different.

  Dictionary includes success key. If False, one or more files do not exist or some other error occurred.

  Under the hood, this uses the junos CLI command file compare files ...

  Note

  This function only works on Juniper native minions

  Added in version 3003.

  CLI Example:

      salt junos-router junos.file_compare /var/tmp/backup1/cmt.script /var/tmp/backup2/cmt.script

      junos-router:
          identical:
              False
          success:
              True

salt.modules.junos.file_copy(src, dest)

  Copies the file from the local device to the junos device

  Note

  This function does not work on Juniper native minions

  src

    The source path where the file is kept.

  dest

    The destination path on the where the file will be copied

  Added in version 3001.

  CLI Example:

      salt 'device_name' junos.file_copy /home/m2/info.txt info_copy.txt

salt.modules.junos.fsentry_exists(dir, **kwargs)

  Returns a dictionary indicating if dir refers to a file or a non-file (generally a directory) in the file system, or if there is no file by that name.

  Note

  This function only works on Juniper native minions

  Added in version 3003.

  CLI Example:

      salt junos-router junos.fsentry_exists /var/log

      junos-router:
          is_dir:
              True
          exists:
              True

salt.modules.junos.get_table(table, table_file, path=None, target=None, key=None, key_items=None, filters=None, table_args=None)

  Added in version 3001.

  Retrieve data from a Junos device using Tables/Views

  table (required)

    Name of PyEZ Table

  table_file (required)

    YAML file that has the table specified in table parameter

  path:

    Path of location of the YAML file. defaults to op directory in jnpr.junos.op

  target:

    if command need to run on FPC, can specify fpc target

  key:

    To overwrite key provided in YAML

  key_items:

    To select only given key items

  filters:

    To select only filter for the dictionary from columns

  table_args:

    key/value pair which should render Jinja template command or are passed as args to rpc call in op table

  CLI Example:

      salt 'device_name' junos.get_table RouteTable routes.yml
      salt 'device_name' junos.get_table EthPortTable ethport.yml table_args='{"interface_name": "ge-3/2/2"}'
      salt 'device_name' junos.get_table EthPortTable ethport.yml salt://tables

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.

  path (required)

    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.

  modeexclusive

    The mode in which the configuration is locked. Can be one of `private`, `dynamic`, `batch`, `exclusive`, `ephemeral`

  dev_timeout30

    Set NETCONF RPC timeout. Can be used for commands which take a while to execute.

  overwriteFalse

    Set to `True` if you want this file is to completely replace the configuration file. Sets action to override

    Note

    This option cannot be used if format is "set".

  replaceFalse

    Specify whether the configuration file uses `replace:` statements. If `True`, only those statements under the `replace` tag will be changed.

  mergeFalse

    If set to `True` will set the load-config action to merge. the default load-config action is 'replace' for xml/json/text config

  format

    Determines the format of the contents

  updateFalse

    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.

  comment

    Provide a comment for the commit

  confirm

    Provide time in minutes for commit confirmation. If this option is specified, the commit will be rolled back in the specified amount of 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. Note that the file will be stored on the proxy minion. To push the files to the master use:

    > py:func:cp.push <salt.modules.cp.push>.

  template_vars

    Variables to be passed into the template processing engine in addition to those present in pillar, the minion configuration, grains, etc. You may reference these variables in your template like so:

        {{ template_vars["var_name"] }}

  CLI Examples:

      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"}'

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.

  path (required)

    Path where the image file is present on the proxy minion

  remote_path/var/tmp

    If the value of path is a file path on the local (Salt host's) filesystem, then the image is copied from the local filesystem to the :remote_path: directory on the target Junos device. The default is `/var/tmp`. If the value of :path: or is a URL, then the value of :remote_path: is unused.

  dev_timeout1800

    The NETCONF RPC timeout (in seconds). This argument was added since most of the time the "package add" RPC takes a significant amount of time. So this :timeout: value will be used in the context of the SW installation process. Defaults to 30 minutes (30*60=1800 seconds)

  timeout1800

    Alias to dev_timeout for backward compatibility

  rebootFalse

    Whether to reboot after installation

  no_copyFalse

    If `True` the software package will not be SCP’d to the device

  bool validate:

    When `True` this method will perform a config validation against the new image

  bool issu: False

    When `True` allows unified in-service software upgrade (ISSU) feature enables you to upgrade between two different Junos OS releases with no disruption on the control plane and with minimal disruption of traffic.

  bool nssu: False

    When `True` allows nonstop software upgrade (NSSU) enables you to upgrade the software running on a Juniper Networks EX Series Virtual Chassis or a Juniper Networks EX Series Ethernet Switch with redundant Routing Engines with a single command and minimal disruption to network traffic.

  bool all_re: True

    When True (default), executes the software install on all Routing Engines of the Junos device. When False, execute the software install only on the current Routing Engine.

    Added in version 3001.

  Note

  Any additional keyword arguments specified are passed down to PyEZ sw.install() as is. Please refer to below URl for PyEZ sw.install() documentation: https://pyez.readthedocs.io/en/latest/jnpr.junos.utils.html#jnpr.junos.utils.sw.SW.install

  CLI Examples:

      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

salt.modules.junos.load(path=None, **kwargs)

  Loads the configuration from the file provided onto the device.

  path (required)

    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.

  overwriteFalse

    Set to `True` if you want this file is to completely replace the configuration file. Sets action to override

    Note

    This option cannot be used if format is "set".

  replaceFalse

    Specify whether the configuration file uses `replace:` statements. If `True`, only those statements under the `replace` tag will be changed.

  mergeFalse

    If set to `True` will set the load-config action to merge. the default load-config action is 'replace' for xml/json/text config

  updateFalse

    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.

  format

    Determines the format of the contents

  template_vars

    Variables to be passed into the template processing engine in addition to those present in pillar, the minion configuration, grains, etc. You may reference these variables in your template like so:

        {{ template_vars["var_name"] }}

  CLI Examples:

      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"}'

salt.modules.junos.lock()

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

  Note

  When locking, it is important to remember to call `junos.unlock` once finished. If locking during orchestration, remember to include a step in the orchestration job to unlock.

  CLI Example:

      salt 'device_name' junos.lock

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

  Send a ping RPC to a device

  dest_ip

    The IP of the device to ping

  dev_timeout30

    The NETCONF RPC timeout (in seconds)

  rapidFalse

    When `True`, executes ping at 100pps instead of 1pps

  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

  count5

    Number of packets to send

  CLI Examples:

      salt 'device_name' junos.ping '8.8.8.8' count=5
      salt 'device_name' junos.ping '8.8.8.8' ttl=1 rapid=True

salt.modules.junos.rollback(**kwargs)

  Roll back the last committed configuration changes and commit

  id0

    The rollback ID value (0-49)

  d_id0

    The rollback ID value (0-49)

  dev_timeout30

    The NETCONF RPC timeout (in seconds)

  comment

    Provide a comment for the commit

  confirm

    Provide time in minutes for commit confirmation. If this option is specified, the commit will be rolled back in the specified amount of 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. Note that the file will be stored on the proxy minion. To push the files to the master use `cp.push`.

  CLI Example:

      salt 'device_name' junos.rollback 10

  NOTE: Because of historical reasons and the internals of the Salt state compiler, there are three possible sources of the rollback ID--the positional argument, and the id and d_id kwargs. The precedence of the arguments are id (positional), id (kwarg), d_id (kwarg). In other words, if all three are passed, only the positional argument will be used. A warning is logged if more than one is passed.

salt.modules.junos.routing_engine(**kwargs)

  Returns a dictionary containing the routing engines on the device and their status (Master, Disabled, Backup).

  Under the hood parses the result of show chassis routing-engine

  Added in version 3003.

  CLI Example:

      salt junos-router junos.routing_engine

      junos-router:
          backup:
            - re1:
          master:
            re0:
          success:
            True

  Returns success: False if the device does not appear to have multiple routing engines.

salt.modules.junos.rpc(cmd=None, dest=None, **kwargs)

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

  cmd

    The RPC to be executed

  dest

    Destination file where the RPC output is stored. Note that the file will be stored on the proxy minion. To push the files to the master use `cp.push`.

  formatxml

    The format in which the RPC reply is received from the device

  dev_timeout30

    The NETCONF RPC timeout (in seconds)

  filter

    Used with the `get-config` RPC to get specific configuration

  terseFalse

    Amount of information you want

  interface_name

    Name of the interface to query

  CLI Example:

      salt 'device' junos.rpc get_config dest=/var/log/config.txt format=text filter='<configuration><system/></configuration>'
      salt 'device' junos.rpc get-interface-information dest=/home/user/interface.xml interface_name='lo0' terse=True
      salt 'device' junos.rpc get-chassis-inventory

salt.modules.junos.rpc_file_list(path, **kwargs)

  Use the Junos RPC interface to get a list of files and return them as a structure dictionary.

  Added in version 3003.

  CLI Example:

      salt junos-router junos.rpc_file_list /var/local/salt/etc

      junos-router:
          files:
              directory:
                  directory-name:
                      /var/local/salt/etc
                  file-information:
                      |_
                        file-directory:
                            file-name:
                                pki
                      |_
                        file-name:
                            proxy
                      |_
                        file-directory:
                            file-name:
                                proxy.d
              total-file-blocks:
                  10
              total-files:
                  1
      success:
          True

salt.modules.junos.set_hostname(hostname=None, **kwargs)

  Set the device's hostname

  hostname

    The name to be set

  comment

    Provide a comment to the commit

  dev_timeout30

    The NETCONF RPC timeout (in seconds)

  confirm

    Provide time in minutes for commit confirmation. If this option is specified, the commit will be rolled back in the specified amount of time unless the commit is confirmed.

  CLI Example:

      salt 'device_name' junos.set_hostname salt-device

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.

  > Note

  > One of `shutdown` or `reboot` must be set to `True` or no action will be taken.

  shutdownFalse

    Set this to `True` if you want to shutdown the machine. This is a safety mechanism so that the user does not accidentally shutdown the junos device.

  rebootFalse

    If `True`, reboot instead of shutting down

  at

    Used when rebooting, to specify the date and time the reboot should take place. The value of this option must match the JunOS CLI reboot syntax.

  in_min

    Used when shutting down. Specify the delay (in minutes) before the device will be shut down.

  CLI Examples:

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

salt.modules.junos.unlock()

  Unlocks the candidate configuration.

  CLI Example:

      salt 'device_name' junos.unlock

salt.modules.junos.zeroize()

  Resets the device to default factory settings

  Note

  In case of non-root user, proxy_reconnect will not be able to re-connect to the device as zeroize will delete the local user's configuration. For more details on zeroize functionality, please refer https://www.juniper.net/documentation/en_US/junos/topics/reference/command-summary/request-system-zeroize.html

  CLI Example:

      salt 'device_name' junos.zeroize