Python script triggered by UPM doesn't work properly
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
‎11-06-2015 12:22 PM
Hi everybody.
I use x480 with 16.1.2.
I have simple .py script like this.
import pexpect
import exsh
exsh.clicmd ('create log message "Starting NSCBackup!"')
for i in range(1,10):
print(i)
p = pexpect.spawn('/exos/bin/ssh -r 2 USERNAME@172.20.1.' + str(i))
idx = p.expect(['password', pexpect.EOF, pexpect.TIMEOUT])
p.sendline('SECRETPASS')
idx = p.expect(['sCore', pexpect.EOF, pexpect.TIMEOUT])
p.sendline('create log message "Not so cold backuper"')
idx = p.expect(['sCore', pexpect.EOF, pexpect.TIMEOUT])
p.sendline('save')
idx = p.expect(['(y/N)', pexpect.EOF, pexpect.TIMEOUT])
p.sendline('y')
idx = p.expect(['sCore', pexpect.EOF, pexpect.TIMEOUT])
p.sendline('scp2 vr "VR-Default" sCore' + str(i) + '.cfg USERNAME@172.20.1.10:sCore' + str(i) + '.cfg')
idx = p.expect(['password', pexpect.EOF, pexpect.TIMEOUT])
p.sendline('SECRETPASS')
p.sendline('exit')Not so beautiful, but it works!
So... I can run it with "load script NSCB.py". It works properly.
Then I created and scheduled UPM profile like this.
create upm profile NSCB
load script NSCB.py
.
create upm timer NSCBtimer
configure upm timer NSCBtimer profile NSCB
configure upm timer NSCBtimer at 11 5 2015 23 50 0 every 86400And I run it:
run upm profile "NSCB" I see some log messages, but script stucked.
11/06/2015 15:55:19.94 Starting NSCBackup!
11/06/2015 15:55:19.54 Launched profile NSCB for the event user-request
Any suggestions?
I use x480 with 16.1.2.
I have simple .py script like this.
import pexpect
import exsh
exsh.clicmd ('create log message "Starting NSCBackup!"')
for i in range(1,10):
print(i)
p = pexpect.spawn('/exos/bin/ssh -r 2 USERNAME@172.20.1.' + str(i))
idx = p.expect(['password', pexpect.EOF, pexpect.TIMEOUT])
p.sendline('SECRETPASS')
idx = p.expect(['sCore', pexpect.EOF, pexpect.TIMEOUT])
p.sendline('create log message "Not so cold backuper"')
idx = p.expect(['sCore', pexpect.EOF, pexpect.TIMEOUT])
p.sendline('save')
idx = p.expect(['(y/N)', pexpect.EOF, pexpect.TIMEOUT])
p.sendline('y')
idx = p.expect(['sCore', pexpect.EOF, pexpect.TIMEOUT])
p.sendline('scp2 vr "VR-Default" sCore' + str(i) + '.cfg USERNAME@172.20.1.10:sCore' + str(i) + '.cfg')
idx = p.expect(['password', pexpect.EOF, pexpect.TIMEOUT])
p.sendline('SECRETPASS')
p.sendline('exit')Not so beautiful, but it works!
So... I can run it with "load script NSCB.py". It works properly.
Then I created and scheduled UPM profile like this.
create upm profile NSCB
load script NSCB.py
.
create upm timer NSCBtimer
configure upm timer NSCBtimer profile NSCB
configure upm timer NSCBtimer at 11 5 2015 23 50 0 every 86400And I run it:
run upm profile "NSCB" I see some log messages, but script stucked.
11/06/2015 15:55:19.94 Starting NSCBackup!
11/06/2015 15:55:19.54
Any suggestions?
21 REPLIES 21
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
‎11-13-2015 09:10 AM
I'm running 16.1.2.14.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
‎11-13-2015 04:25 AM
Sorry for waiting... Something is going wrong.
I've created py script, but when I run it I have this.
Traceback (most recent call last):
File "/config/NSCB.py", line 2, in
import exos.api
File "/exos/tools/lib/python2.7/site-packages/exos/api/__init__.py", line 21, in
File "/exos/tools/lib/python2.7/site-packages/exos/api/ems.py", line 10, in
ImportError: No module named _exos_ext_ems
I've tried to import XOS api with "from exos import api" but...
Traceback (most recent call last):
File "/config/NSCB.py", line 2, in
from xos import api
ImportError: No module named xos
It's not clear for me... What am I doing wrong?
I've created py script, but when I run it I have this.
Traceback (most recent call last):
File "/config/NSCB.py", line 2, in
import exos.api
File "/exos/tools/lib/python2.7/site-packages/exos/api/__init__.py", line 21, in
File "/exos/tools/lib/python2.7/site-packages/exos/api/ems.py", line 10, in
ImportError: No module named _exos_ext_ems
I've tried to import XOS api with "from exos import api" but...
Traceback (most recent call last):
File "/config/NSCB.py", line 2, in
from xos import api
ImportError: No module named xos
It's not clear for me... What am I doing wrong?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
‎11-06-2015 07:17 PM
I was able to create a test.py application/process that uses pexpect with /exos/bin/ssh similarly to your script and I used a UPM profile and timer to restart it every 5 minutes. It worked.
Here is the UPM configuration:
## Module upm configuration.
#
create upm profile test
disable cli prompt
restart process test
.
create upm timer test
configure upm timer test profile test
configure upm timer test after 1 every 300
...
And here is the py file for the process and the command to create it. (I assumed that the ssh targets were sub-tended EXOS switches and so I sent the "disable cli prompting" command to avoid unnecessary pexpect lines in the process script.)
#vi test.py
import pexpectimport exos.api
def exosCmd(cmd):
reply = exos.api.exec_cli([str(cmd)], ignore_errors=True)
return str(reply)
def logMsg(m):
exosCmd('create log message "{0}"'.format(m))
logMsg("Starting NSCBackup!")
p = pexpect.spawn('/exos/bin/ssh -r 2 admin@10.0.0.202')
idx = p.expect(['password', pexpect.EOF, pexpect.TIMEOUT])
p.sendline('admin')
idx = p.expect(['x202', pexpect.EOF, pexpect.TIMEOUT])
p.sendline('create log message "test test test"')
idx = p.expect(['x202', pexpect.EOF, pexpect.TIMEOUT])
p.sendline('disable cli prompt')
idx = p.expect(['x202', pexpect.EOF, pexpect.TIMEOUT])
p.sendline('save')
idx = p.expect(['x202', pexpect.EOF, pexpect.TIMEOUT])
p.sendline('exit')
#^wq!
...
The process was started with this line that I issued before starting the UPM timer:
create process test py test start auto
...
Hope this helps.
Here is the UPM configuration:
## Module upm configuration.
#
create upm profile test
disable cli prompt
restart process test
.
create upm timer test
configure upm timer test profile test
configure upm timer test after 1 every 300
...
And here is the py file for the process and the command to create it. (I assumed that the ssh targets were sub-tended EXOS switches and so I sent the "disable cli prompting" command to avoid unnecessary pexpect lines in the process script.)
#vi test.py
import pexpectimport exos.api
def exosCmd(cmd):
reply = exos.api.exec_cli([str(cmd)], ignore_errors=True)
return str(reply)
def logMsg(m):
exosCmd('create log message "{0}"'.format(m))
logMsg("Starting NSCBackup!")
p = pexpect.spawn('/exos/bin/ssh -r 2 admin@10.0.0.202')
idx = p.expect(['password', pexpect.EOF, pexpect.TIMEOUT])
p.sendline('admin')
idx = p.expect(['x202', pexpect.EOF, pexpect.TIMEOUT])
p.sendline('create log message "test test test"')
idx = p.expect(['x202', pexpect.EOF, pexpect.TIMEOUT])
p.sendline('disable cli prompt')
idx = p.expect(['x202', pexpect.EOF, pexpect.TIMEOUT])
p.sendline('save')
idx = p.expect(['x202', pexpect.EOF, pexpect.TIMEOUT])
p.sendline('exit')
#^wq!
...
The process was started with this line that I issued before starting the UPM timer:
create process test py test start auto
...
Hope this helps.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
‎11-06-2015 07:17 PM
Thank you for advice! I'm going to create similar proccess and give you feedback as soon as possible.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
‎11-06-2015 05:14 PM
So it looks like the purpose of this is to have a core switch ssh into downstream connected switches and save their configurations periodically right?
I'll take your script and attempt to make it into a python EXOS application process instead. I'll then test having a UPM process restart the py process. I'll let you know how it works out.
Let me know if I've misinterpreted what you want to do.
Thanks.
I'll take your script and attempt to make it into a python EXOS application process instead. I'll then test having a UPM process restart the py process. I'll let you know how it works out.
Let me know if I've misinterpreted what you want to do.
Thanks.
