Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continue work from PR #749 on configure private #1169

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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