diff --git a/lib/jnpr/junos/device.py b/lib/jnpr/junos/device.py index 37523ad15..27133661c 100644 --- a/lib/jnpr/junos/device.py +++ b/lib/jnpr/junos/device.py @@ -1217,6 +1217,10 @@ def __init__(self, *vargs, **kvargs): *OPTIONAL* To disable public key authentication. default is ``None``. + :param str bind_addr: + *OPTIONAL* To use (local) source IP address. + default is ``None``. + :param bool hostkey_verify: *OPTIONAL* To enable ssh_known hostkey verify default is ``False``. @@ -1239,6 +1243,7 @@ def __init__(self, *vargs, **kvargs): self._huge_tree = kvargs.get("huge_tree", False) self._conn_open_timeout = kvargs.get("conn_open_timeout", 30) self._look_for_keys = kvargs.get("look_for_keys", None) + self._bind_addr = kvargs.get("bind_addr", None) self._hostkey_verify = kvargs.get("hostkey_verify", False) if self._fact_style != "new": warnings.warn( @@ -1393,6 +1398,7 @@ def open(self, *vargs, **kvargs): allow_agent=allow_agent, look_for_keys=look_for_keys, ssh_config=self._sshconf_lkup(), + bind_addr=self._bind_addr, timeout=self._conn_open_timeout, device_params={ "name": "junos", diff --git a/tests/unit/test_device.py b/tests/unit/test_device.py index 42d16b559..1773ee706 100644 --- a/tests/unit/test_device.py +++ b/tests/unit/test_device.py @@ -463,6 +463,23 @@ def test_device_open(self, mock_connect, mock_execute): self.dev2.open() self.assertEqual(self.dev2.connected, True) + @patch("ncclient.manager.connect") + @patch("jnpr.junos.Device.execute") + def test_device_open_with_bind_addr(self, mock_connect, mock_execute): + with patch("jnpr.junos.utils.fs.FS.cat") as mock_cat: + mock_cat.return_value = """ + + domain jls.net + + """ + mock_connect.side_effect = self._mock_manager + mock_execute.side_effect = self._mock_manager + self.dev2 = Device( + host="2.2.2.2", user="test", password="password123", bind_addr="1.1.1.1" + ) + self.dev2.open() + self.assertEqual(self.dev2.connected, True) + @patch("ncclient.manager.connect") @patch("jnpr.junos.Device.execute") def test_device_open_with_look_for_keys_False(self, mock_connect, mock_execute): @@ -496,6 +513,7 @@ def test_device_open_with_look_for_keys_True(self, mock_connect, mock_execute): ) self.dev2.open() self.assertEqual(self.dev2.connected, True) + @patch("ncclient.manager.connect") @patch("jnpr.junos.Device.execute") def test_device_open_with_hostkey_verify_True(self, mock_connect, mock_execute): @@ -525,7 +543,10 @@ def test_device_open_with_hostkey_verify_False(self, mock_connect, mock_execute) mock_connect.side_effect = self._mock_manager mock_execute.side_effect = self._mock_manager self.dev2 = Device( - host="2.2.2.2", user="test", password="password123", hostkey_verify=False + host="2.2.2.2", + user="test", + password="password123", + hostkey_verify=False, ) self.dev2.open() self.assertEqual(self.dev2.connected, True)