Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Schulman committed Dec 30, 2013
1 parent fa19521 commit c76ee7b
Showing 1 changed file with 3 additions and 27 deletions.
30 changes: 3 additions & 27 deletions examples/connect.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,12 @@
import sys
from pprint import pprint as pp
import jnpr.junos as junos

# if len(sys.argv) < 3:
# # argv[1] = user-name
# # argv[2] = host-name
# print "you must provide a Junos user and target hostname"
# sys.exit(1)

def sshconf_find(host):
import os, paramiko

# going to use paramiko SSHConfig to retrieve the port parameters for a given
# host. Doing this because I tend to use jumphosts to get to devices behind
# firewalls/etc. This is a pretty useful technique to illustrate:
config_file = os.path.join(os.getenv('HOME'),'.ssh/config')
ssh_config = paramiko.SSHConfig()
ssh_config.parse(open(config_file,'r'))
return ssh_config.lookup( host )
from os import getenv

def connect(host, user, password=None):
from getpass import getpass

got_lkup = sshconf_find( host )
from getpass import getpass
if password is None: password = getpass('password: ')

login = dict(
host=got_lkup['hostname'],
port=got_lkup.get('port',830),
user=user, password=password
)
return junos.Device(**login).open()
return junos.Device(host, user=user, password=password).open()

if len(sys.argv) > 1:
dev = connect(sys.argv[2], sys.argv[1])
Expand Down

0 comments on commit c76ee7b

Please sign in to comment.