Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added bind_addr parameter in Device() API #1340

Merged
merged 2 commits into from
Oct 21, 2024

Conversation

dineshbaburam91
Copy link
Collaborator

bind_addr is a (local) source IP address to use, must be reachable from the remote device.

(envname) root@masterhost:~# ping -I 1.1.1.4 x.x.x.x
PING x.x.x.x (x.x.x.x) from 1.1.1.4 : 56(84) bytes of data.
64 bytes from x.x.x.x: icmp_seq=1 ttl=64 time=27.3 ms
64 bytes from x.x.x.x: icmp_seq=2 ttl=64 time=1.20 ms
64 bytes from x.x.x.x: icmp_seq=3 ttl=64 time=1.33 ms


Testcase1: No Bind address configured


(envname) root@masterhost:~# cat sample.py 
from jnpr.junos import Device
from pprint import pprint
dev = Device(host=‘ng1r,’ user='root', password='Embe1mpls')
dev.open()
pprint (dev.facts['hostname'])
O/P:


(envname) root@masterhost:~# python3 sample.py
'ng1r'

Netstat o/p:


root@masterhost:~# netstat -a | grep 830
tcp 0 0 ng1h.englab.junip:53886 ng1r-fxp0.englab.ju:830 ESTABLISHED


Testcase2: When bind address configured as None

(envname) root@masterhost:~# cat sample.py 
from jnpr.junos import Device
from pprint import pprint
dev = Device(host=’ng1r’, bind_addr= None, user='root', password='Embe1mpls')
dev.open()
pprint (dev.facts['hostname'])

O/p:

(envname) root@masterhost:~# python3 sample.py
'ng1r'

Netstat o/p:

root@masterhost:~# netstat -a | grep 830
tcp 0 0 ng1h.englab.junip:45758 ng1r-fxp0.englab.ju:830 ESTABLISHED

Testcase3: When bind_address configured

(envname) root@masterhost:~# cat sample.py 
from jnpr.junos import Device
from pprint import pprint
dev = Device(host=‘ngn1r’, bind_addr= "1.1.1.4", user='root', password='Embe1mpls')
dev.open()
pprint (dev.facts['hostname'])
O/p:

(envname) root@masterhost:~# python3 sample.py
'ng1r'

Netstat o/p:

root@masterhost:~# netstat -a | grep 830
tcp 0 0 1.1.1.4:55351 ng1r-fxp0.englab.ju:830 ESTABLISHED

Unit-test



(envname) root@masterhost:~/dinesh/py-junos-eznc# nose2  tests.unit.test_device
............................................................................................................
----------------------------------------------------------------------
Ran 108 tests in 0.227s

OK

Copy link
Collaborator

@chidanandpujar chidanandpujar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@chidanandpujar chidanandpujar merged commit 4828e32 into Juniper:master Oct 21, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants