Skip to content

Commit

Permalink
Merge 268c449 into 23df9a7
Browse files Browse the repository at this point in the history
  • Loading branch information
dexteradeus committed Jun 20, 2018
2 parents 23df9a7 + 268c449 commit 2db3837
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ncclient/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def make_device_handler(device_params):
if device_params is None:
device_params = {}

handler = device_params.get('handler', None)
if handler:
return handler(device_params)

device_name = device_params.get("name", "default")
# Attempt to import device handler class. All device handlers are
# in a module called "ncclient.devices.<devicename>" and in a class named
Expand Down Expand Up @@ -98,6 +102,9 @@ def connect_ssh(*args, **kwds):
To invoke advanced vendor related operation add device_params =
{'name':'<vendor_alias>'} in connection paramerers. For the time,
'junos' and 'nexus' are supported for Juniper and Cisco Nexus respectively.
A custom device handler can be provided with device_params =
{'handler':<handler class>} in connection paramerers.
"""
# Extract device parameter dict, if it was passed into this function. Need to
# remove it from kwds, since the session.connect() doesn't like extra stuff in
Expand Down
8 changes: 8 additions & 0 deletions test/unit/test_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
from mock import patch, MagicMock
from ncclient import manager
from ncclient.devices.junos import JunosDeviceHandler


class TestManager(unittest.TestCase):
Expand Down Expand Up @@ -66,6 +67,13 @@ def test_make_device_handler(self):
device_handler.__class__.__name__,
"JunosDeviceHandler")

def test_make_device_handler_provided_handler(self):
device_handler = manager.make_device_handler(
{'handler': JunosDeviceHandler})
self.assertEqual(
device_handler.__class__.__name__,
"JunosDeviceHandler")

@patch('ncclient.operations.LockContext')
def test_manager_locked(self, mock_lock):
conn = manager.Manager(None, None, timeout=20)
Expand Down

0 comments on commit 2db3837

Please sign in to comment.