Skip to content

Commit

Permalink
Add support for configure private in Junos (#1184)
Browse files Browse the repository at this point in the history
  • Loading branch information
omershtivi1 committed Apr 27, 2020
1 parent 7b704b5 commit a326111
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/support/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ ____________________________________
* :code:`auto_rollback_on_error` (ios) - Disable automatic rollback (certain versions of IOS support configure replace, but not rollback on error) (default: ``True``).
* :code:`config_lock` (iosxr, junos) - Lock the config during open() (default: ``False``).
* :code:`lock_disable` (junos) - Disable all configuration locking for management by an external system (default: ``False``).
* :code:`config_private` (junos) - Configure private, no DB locking (default: ``False``).
* :code:`canonical_int` (ios) - Convert operational interface's returned name to canonical name (fully expanded name) (default: ``False``).
* :code:`dest_file_system` (ios) - Destination file system for SCP transfers (default: ``flash:``).
* :code:`enable_password` (eos) - Password required to enter privileged exec (enable) (default: ``''``).
Expand Down
15 changes: 14 additions & 1 deletion napalm/junos/junos.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(self, hostname, username, password, timeout=60, optional_args=None)
* config_lock (True/False): lock configuration DB after the connection is established.
* lock_disable (True/False): force configuration lock to be disabled (for external lock
management).
* config_private (True/False): juniper configure private command, no DB locking
* port (int): custom port
* key_file (string): SSH key file path
* keepalive (int): Keepalive interval
Expand All @@ -92,6 +93,7 @@ def __init__(self, hostname, username, password, timeout=60, optional_args=None)
# Define locking method
self.lock_disable = optional_args.get("lock_disable", False)
self.session_config_lock = optional_args.get("config_lock", False)
self.config_private = optional_args.get("config_private", False)

# Junos driver specific options
self.junos_config_database = optional_args.get(
Expand Down Expand Up @@ -223,7 +225,11 @@ def _load_candidate(self, filename, config, overwrite):
with open(filename) as f:
configuration = f.read()

if not self.lock_disable and not self.session_config_lock:
if (
not self.lock_disable
and not self.session_config_lock
and not self.config_private
):
# if not locked during connection time, will try to lock
self._lock()

Expand All @@ -233,6 +239,13 @@ def _load_candidate(self, filename, config, overwrite):
if fmt == "xml":
configuration = etree.XML(configuration)

if self.config_private:
try:
self.device.rpc.open_configuration(private=True, normalize=True)
except RpcError as err:
if str(err) == "uncommitted changes will be discarded on exit":
pass

self.device.cu.load(
configuration,
format=fmt,
Expand Down

0 comments on commit a326111

Please sign in to comment.