forked from CMSCompOps/WmAgentScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setCascadeStatus.py
executable file
·47 lines (39 loc) · 1.51 KB
/
setCascadeStatus.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
#!/usr/bin/env python
#import json
import sys
import json
import reqMgrClient as reqmgr
import optparse
def setStatus(url, workflowname,newstatus):
print "Setting %s to %s" % (workflowname,newstatus)
if newstatus == 'closed-out':
return reqmgr.closeOutWorkflowCascade(url, workflowname)
elif newstatus == 'announced':
return reqmgr.announceWorkflowCascade(url, workflowname)
else:
print "cannot cascade to",newstatus
def getStatus(url, workflow):
conn = httplib.HTTPSConnection(url, cert_file = os.getenv('X509_USER_PROXY'), key_file = os.getenv('X509_USER_PROXY'))
r1=conn.request('GET','/reqmgr/reqMgr/request?requestName=' + workflow)
r2=conn.getresponse()
#data = r2.read()
s = json.loads(r2.read())
t = s['RequestStatus']
return t
def main():
parser = optparse.OptionParser()
parser.add_option('-u','--url',help='Which server to communicate with', default='cmsweb.cern.ch',choices=['cmsweb.cern.ch','cmsweb-testbed.cern.ch'])
parser.add_option('-w','--wf',help='Filelis of coma separated list of workflows')
parser.add_option('-s','--status',help='The new status', choices=['closed-out','announced'])
(options,args) = parser.parse_args()
wfs = []
try:
f = open(options.wf, 'r')
wfs.extend([l.strip('\n').strip(' ') for l in f])
f.close()
except:
wfs.extend(options.wf.split(','))
for wf in wfs:
r = setStatus(options.url, wf, options.status)
if __name__ == "__main__":
main()