Skip to content

Commit

Permalink
Refactor processing of EOS optional_args (#901) (#902)
Browse files Browse the repository at this point in the history
Process optional_args in a way that supports arbitrary underlying
arguments in the connection class used.
  • Loading branch information
bewing authored and ktbyers committed Jan 8, 2019
1 parent cf69482 commit 168f456
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions napalm/eos/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,44 +95,44 @@ def __init__(self, hostname, username, password, timeout=60, optional_args=None)
self.config_session = None
self.locked = False

if optional_args is None:
optional_args = {}
self.platform = "eos"
self.profile = [self.platform]

self._process_optional_args(optional_args or {})

def _process_optional_args(self, optional_args):
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
self.transport = optional_args.get(
transport = optional_args.get(
"transport", optional_args.get("eos_transport", "https")
)

if self.transport == "https":
self.port = optional_args.get("port", 443)
elif self.transport == "http":
self.port = optional_args.get("port", 80)

self.enablepwd = optional_args.get("enable_password", "")

self.platform = "eos"
self.profile = [self.platform]

self.eos_autoComplete = optional_args.get("eos_autoComplete", None)
try:
self.transport_class = pyeapi.client.TRANSPORTS[transport]
except KeyError:
raise ConnectionException("Unknown transport: {}".format(self.transport))
init_args = py23_compat.argspec(self.transport_class.__init__)[0]
init_args.pop(0) # Remove "self"
init_args.append("enforce_verification") # Not an arg for unknown reason

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

self.eapi_kwargs = {
k: v
for k, v in optional_args.items()
if k in init_args and k not in filter_args
}

def open(self):
"""Implementation of NAPALM method open."""
try:
if self.transport in ("http", "https"):
connection = pyeapi.client.connect(
transport=self.transport,
host=self.hostname,
username=self.username,
password=self.password,
port=self.port,
timeout=self.timeout,
)
elif self.transport == "socket":
connection = pyeapi.client.connect(transport=self.transport)
else:
raise ConnectionException(
"Unknown transport: {}".format(self.transport)
)
connection = self.transport_class(
host=self.hostname,
username=self.username,
password=self.password,
timeout=self.timeout,
**self.eapi_kwargs
)

if self.device is None:
self.device = pyeapi.client.Node(connection, enablepwd=self.enablepwd)
Expand Down

0 comments on commit 168f456

Please sign in to comment.