Skip to content

Commit

Permalink
Merge pull request #392 from andrewmallory/multiVendor
Browse files Browse the repository at this point in the history
global variable fix
  • Loading branch information
einarnn committed May 24, 2020
2 parents 58fe706 + c190fb5 commit 54d50ec
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions ncclient/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@
operations to the :class:`Manager` API.
"""

VENDOR_OPERATIONS = {}


def make_device_handler(device_params):
"""
Expand Down Expand Up @@ -129,8 +127,6 @@ def connect_ssh(*args, **kwds):

device_handler = make_device_handler(device_params)
device_handler.add_additional_ssh_connect_params(kwds)
global VENDOR_OPERATIONS
VENDOR_OPERATIONS.update(device_handler.add_additional_operations())
session = transport.SSHSession(device_handler)
if "hostkey_verify" not in kwds or kwds["hostkey_verify"]:
session.load_known_hosts()
Expand All @@ -155,8 +151,6 @@ def connect_ioproc(*args, **kwds):

device_handler = make_device_handler(device_params)

global VENDOR_OPERATIONS
VENDOR_OPERATIONS.update(device_handler.add_additional_operations())
session = third_party_import.IOProc(device_handler)
session.connect()

Expand Down Expand Up @@ -207,6 +201,9 @@ def __init__(self, session, device_handler, timeout=30):
self._raise_mode = operations.RaiseMode.ALL
self._huge_tree = self.HUGE_TREE_DEFAULT
self._device_handler = device_handler
self._vendor_operations = {}
if device_handler:
self._vendor_operations.update(device_handler.add_additional_operations())

def __enter__(self):
return self
Expand Down Expand Up @@ -257,8 +254,8 @@ def session(self):
raise NotImplementedError

def __getattr__(self, method):
if method in VENDOR_OPERATIONS:
return functools.partial(self.execute, VENDOR_OPERATIONS[method])
if method in self._vendor_operations:
return functools.partial(self.execute, self._vendor_operations[method])
elif method in OPERATIONS:
return functools.partial(self.execute, OPERATIONS[method])
else:
Expand Down

0 comments on commit 54d50ec

Please sign in to comment.