-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsapx.py
60 lines (56 loc) · 2.03 KB
/
sapx.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/opt/opsware/bin/python2
import os
import re
import string
import sys
import time
import optparse
import SALib
import sacliutil
import getpass
def main():
p = sacliutil.standardOptions("")
p.add_option('--id', help="Specify ID or APX name.")
p.add_option('--notification', action="store_true",help="Emails notification to the user.")
p.add_option('--ticketid', help="Ticket ID to assign the APX.")
p.add_option('--args', help="Arguments to pass to the APX.")
(options,arguments) = p.parse_args()
s = sacliutil.getSALib(options.username,options.password,options.authfile)
if options.debug:
s.setDebug(1)
if options.id:
action = ['run','list']
if arguments:
if re.match('[Rr]un',arguments[0]):
if options.args:
args = options.args
else:
args = ''
if options.ticketid:
ticketid = options.ticketid
else:
ticketid = None
jobid = s.startProgramAPX(options.id,args,options.notification,ticketid)
print "%s" % jobid
elif re.match('[Ll]ist',arguments[0]):
for i in s.getAPXRefs(options.id):
print "%s" % i
else:
p.print_help()
print "Please provide an action: %s" % sacliutil.getActionList(action)
else:
p.print_help()
print "Please provide an action: %s" % sacliutil.getActionList(action)
else:
p.print_help()
if __name__ == '__main__':
try:
main()
except (SALib.AuthenticationFailed):
print "sacli is exiting because it couldn't authenticate the user."
except (KeyboardInterrupt):
print "sacli is exiting because it received a Ctrl-C sequence from the keyboard."
except OSError,args:
print "OS had problems performing system call: %s" % args
except SALib.RegExInvalid,args:
print "Regular Expression is invalid the message was: %s" % args