From 381d3c8d5fd35030393d7939cd9ab827ae3f407a Mon Sep 17 00:00:00 2001 From: Mircea Ulinic Date: Tue, 14 Apr 2020 14:27:10 +0100 Subject: [PATCH] Continue work from PR #749 on configure private --- docs/support/index.rst | 1 + napalm/junos/junos.py | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/support/index.rst b/docs/support/index.rst index 3bbb9cee8..5823ac171 100644 --- a/docs/support/index.rst +++ b/docs/support/index.rst @@ -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: ``''``). diff --git a/napalm/junos/junos.py b/napalm/junos/junos.py index 7c3e9e4b1..9aeb473a8 100644 --- a/napalm/junos/junos.py +++ b/napalm/junos/junos.py @@ -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 @@ -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( @@ -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() @@ -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,