Skip to content

Commit

Permalink
Merge branch 'develop' into develop_fix_version_regression
Browse files Browse the repository at this point in the history
  • Loading branch information
mirceaulinic authored Sep 18, 2019
2 parents 510f472 + 74cce13 commit f4a6bf6
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions napalm/eos/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,26 @@ class EOSDriver(NetworkDriver):
)

def __init__(self, hostname, username, password, timeout=60, optional_args=None):
"""Constructor."""
"""
Initialize EOS Driver.
Optional args:
* lock_disable (True/False): force configuration lock to be disabled (for external lock
management).
* enable_password (True/False): Enable password for privilege elevation
* eos_autoComplete (True/False): Allow for shortening of cli commands
* transport (string): pyeapi transport, defaults to eos_transport if set
- socket
- http_local
- http
- https
- https_certs
(from: https://github.com/arista-eosplus/pyeapi/blob/develop/pyeapi/client.py#L115)
transport is the preferred method
* eos_transport (string): pyeapi transport, defaults to https
eos_transport for backwards compatibility
"""
self.device = None
self.hostname = hostname
self.username = username
Expand All @@ -101,6 +120,9 @@ def __init__(self, hostname, username, password, timeout=60, optional_args=None)
self._process_optional_args(optional_args or {})

def _process_optional_args(self, optional_args):
# Define locking method
self.lock_disable = optional_args.get("lock_disable", False)

self.enablepwd = optional_args.pop("enable_password", "")
self.eos_autoComplete = optional_args.pop("eos_autoComplete", None)
# eos_transport is there for backwards compatibility, transport is the preferred method
Expand All @@ -115,7 +137,7 @@ def _process_optional_args(self, optional_args):
init_args.pop(0) # Remove "self"
init_args.append("enforce_verification") # Not an arg for unknown reason

filter_args = ["host", "username", "password", "timeout"]
filter_args = ["host", "username", "password", "timeout", "lock_disable"]

self.eapi_kwargs = {
k: v
Expand Down Expand Up @@ -154,8 +176,6 @@ def is_alive(self):
return {"is_alive": True} # always true as eAPI is HTTP-based

def _lock(self):
if self.config_session is None:
self.config_session = "napalm_{}".format(datetime.now().microsecond)
sess = self.device.run_commands(["show configuration sessions"])[0]["sessions"]
if [
k
Expand Down Expand Up @@ -227,9 +247,10 @@ def _mode_comment_convert(commands):
return ret

def _load_config(self, filename=None, config=None, replace=True):
commands = []
if self.config_session is None:
self.config_session = "napalm_{}".format(datetime.now().microsecond)

self._lock()
commands = []
commands.append("configure session {}".format(self.config_session))
if replace:
commands.append("rollback clean-config")
Expand Down Expand Up @@ -293,6 +314,9 @@ def compare_config(self):

def commit_config(self, message=""):
"""Implementation of NAPALM method commit_config."""

if not self.lock_disable:
self._lock()
if message:
raise NotImplementedError(
"Commit message not implemented for this platform"
Expand Down

0 comments on commit f4a6bf6

Please sign in to comment.