0

I am trying to push config into multiple juniper devices. But as a test I enter into config mode and change config.

client1 = paramiko.SSHClient()

client1.set_missing_host_key_policy(paramiko.AutoAddPolicy())

client1.connect(IP, username=username, password=password)

configure = client1.invoke_shell()

configure.send('configure')

configure.send('set interfaces ge-0/0/10 description "test"')

configure.send('show | compare')

print configure.recv(1000)

client1.close()

I am expecting the output as below:

[edit interfaces ge-0/0/10]
-   description "Internet Simulation Interface connect to QFX ge-0/0/21";
+   description test;

But the actual output is this:

JUNOS 12.3X50-D35 built 2013-10-22 07:02:18 UTC


mij
  • 532
  • 6
  • 13
  • For the above query the answer import "SSHClientInteraction" from paramiko_expect. But now the issue is able to get into config mode but unable to send further commands – sivabala senna Dec 14 '17 at 01:55
  • This is the new code ********************* client1 = paramiko.SSHClient() client1.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client1.connect(IP, username=username, password=password) interact = SSHClientInteraction(client1, timeout=10, display=True) #interact.expect ('sivabalask@in.ibm.com@usrdrsf072ccpf0>') interact.send('configure') interact.expect ( interact.send('show | compare') cmd_output = interact.current_output_clean print cmd_output client1.close() ************** There is something else missing. – sivabala senna Dec 14 '17 at 01:56

4 Answers4

0

You are getting the first lines of the Juniper CLI, try coding a higher receiving bytes in :

print configure.recv(1000)

Try:

print configure.recv(4096)

Let me know.

סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
rllavona13
  • 11
  • 1
0

I recommend you using the Junos Eznc, library from juniper for junos devices. Junos-Eznc GitHub

rllavona13
  • 11
  • 1
0

Can you try the below mentioned snippet? Sometimes, you have the wait for few seconds to receive some bytes on your stdin.

configure.send('show | compare')

time.sleep(2)

print configure.recv(1000)
Ru Chern Chong
  • 3,692
  • 13
  • 33
  • 43
sri
  • 1
0

Can you put the'cli'before sending commands?

configure = client1.invoke_shell ()
configure.send ('cli') <--- Add
configure.send ('configure')

You are in shell mode a first when you connect to JUNOS by SSH..So you can move to operation mode by using cli.

(lab-network) bash-3.2$ ssh root@localhost -p 2201 
Password:
--- JUNOS 12.1X47-D15.4 built 2014-11-12 02:13:59 UTC
root@vsrx1% cli
root@vsrx1> configure 
Entering configuration mode

[edit]
root@vsrx1# 
sourjp
  • 1