4

I have a requirement where, a python script running in a Juniper router shell needs to execute some commands in vty console of the FPC. I cannot use vty ­c because it may not work properly in all platforms. However, I can use vty fpc0 and then execute the command and exit from there.

Is there a way to execute vty command using PyEZ? If yes, please provide the syntax.

Ghost
  • 3,966
  • 1
  • 25
  • 36

2 Answers2

5

The StartShell class assumes the ability to make a new SSH connection to the target device using port 22. That might not always be a good assumption.

An alternative to using StartShell is to use the RPC equivalent to the request pfe execute command. Here's an example:

>>> resp = dev.rpc.request_pfe_execute(target='fpc0', command='show version')
>>> print resp.text

SENT: Ukern command: show version
GOT:
GOT:
GOT: Juniper Embedded Microkernel Version 15.1F4.15
GOT: Built by builder on 2015-12-23 18:11:49 UTC
GOT: Copyright (C) 1998-2015, Juniper Networks, Inc.
GOT: All rights reserved.
GOT:
GOT:
GOT: RMPC platform (1200Mhz QorIQ P2020 processor, 3584MB memory, 512KB flash)
GOT: Current time   : Sep  2 15:35:42.409859
GOT: Elapsed time   :      27+19:14:41
LOCAL: End of file
Stacy Smith
  • 106
  • 2
4

Using PyEZ StartShell utility we can do something like

from jnpr.junos.utils.start_shell import StartShell
from jnpr.junos import Device

dev = Device(host='xxxx', user='xxxx', password='xxxx')
dev.open()

with StartShell(dev) as ss:
    op = ss.run('vty fpc0', 'vty\)#')
    print op[1]
    op = ss.run('show version', 'vty\)#')
    print op[1]

dev.close()

or even

dev = Device(host='xxxx', user='xxxx', password='xxxx')
dev.open()

with StartShell(dev) as ss:
    op = sh.run('cprod -A fpc0 -c "show version"')
    print op[1]

dev.close()
Nitin Kr
  • 521
  • 2
  • 12