Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing vty commands in Juniper routers using PyEZ

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.

like image 230
Ghost Avatar asked Jan 05 '23 11:01

Ghost


1 Answers

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
like image 115
Stacy Smith Avatar answered Jan 13 '23 09:01

Stacy Smith