Re: Cannot connect to device: ConnectUnknownHostError('hostname.spglab.juniper.net' )

410 views
Skip to first unread message

Rick Sherman

unread,
Mar 5, 2015, 10:17:24 AM3/5/15
to junos-p...@googlegroups.com
Hi Karthik,

The issue is readline() includes a '\n' at the end of the string:

You need to strip that off or read the file with read().splitlines() and iterate the resulting list.

-Rick


On Wednesday, March 4, 2015 at 6:26:26 PM UTC-6, karthik kumar wrote:

Hi All,

I am not sure if am doing something different, it would be great if someone  can suggest some ideas/solution. I am facing some issues when passing argument from file, its getting passed correctly but am not able to connect to the device,Not sure if am missing something.  

However  am not seeing the issue when am  giving directly giving the host name into the script either as a single value or as an array[without using file].  Thanks


[regress@kvmsrv12 ~]$ python test4.py device.txt

'vsrx66.spglab.juniper.net'

Cannot connect to device: ConnectUnknownHostError('vsrx66.spglab.juniper.net')

[regress@kvmsrv12 ~]$ vim test4.py 

from jnpr.junos import Device

from jnpr.junos.exception import *

from jnpr.junos.utils.sw import SW

import sys

import urllib

file=open(sys.argv[1], 'r')

line=file.readline()

#line='vsrx66.spglab.juniper.net';

print line

dev = Device(host=line, user="root", passwd="Embe1mpls")

try:

    dev.open()

except Exception as err:

    sys.stderr.write('Cannot connect to device: {0}\n'.format(err))

    sys.exit(1)

print dev.facts

dev.close()



[regress@kvmsrv12 ~]$ ping vsrx66.spglab.juniper.net

PING vsrx66-ge-000.spglab.juniper.net (10.157.78.2) 56(84) bytes of data.

64 bytes from 10.157.78.2: icmp_seq=1 ttl=64 time=3.77 ms

64 bytes from 10.157.78.2: icmp_seq=2 ttl=64 time=1.77 ms

^C

--- vsrx66-ge-000.spglab.juniper.net ping statistics ---

2 packets transmitted, 2 received, 0% packet loss, time 1478ms

rtt min/avg/max/mdev = 1.770/2.770/3.771/1.001 ms

[regress@kvmsrv12 ~]$ nslookup vsrxx6.spglab.juniper.net

^C

[regress@kvmsrv12 ~]$ nslookup vsrx66.spglab.juniper.net

Server: 10.155.191.252

Address: 10.155.191.252#53


vsrx66.spglab.juniper.net  canonical name = vsrx66-ge-000.spglab.juniper.net.

Name: vsrx66-ge-000.spglab.juniper.net

Address: 10.157.78.2

[regress@kvmsrv12 ~]$ 

karthik kumar

unread,
Mar 5, 2015, 9:03:11 PM3/5/15
to junos-p...@googlegroups.com
Great Thanks Rick.


Regards,
Karthik
Reply all
Reply to author
Forward
Message has been deleted
0 new messages