forked from cms-PdmV/wmcontrol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wmpriority.py
executable file
·55 lines (49 loc) · 1.93 KB
/
wmpriority.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
#! /usr/bin/env python
import urllib
import httplib
import sys
import os
import optparse
import time
def changePriorityWorkflow(url, workflow, priority, cert, key, retry):
params = {workflow + ":status": "", workflow + ":priority": str(priority)}
headers = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"}
for i in range(retry):
stats, data = send_message(url, cert, key, params, headers)
if stats==200:
break
else:
data = "Unable to change priority of workflow {0}, status code: {1}".format(workflow, stats)
time.sleep(1)
print data
def send_message(url, cert, key, params, headers):
conn = httplib.HTTPSConnection(url, cert_file=cert, key_file=key)
encodedParams = urllib.urlencode(params)
conn.request("PUT", "/reqmgr/view/doAdmin", encodedParams, headers)
response = conn.getresponse()
status, data = response.status, response.read()
conn.close()
return status, data
def prepare_parser():
parser = optparse.OptionParser()
parser.add_option('-u', '--url', help='Base url to send request to', dest='url',
default='cmsweb.cern.ch')
parser.add_option('-c', '--cert', help='Cert file location', dest='cert',
default=os.getenv('X509_USER_PROXY'))
parser.add_option('-k', '--key', help='Key file location', dest='key',
default=os.getenv('X509_USER_PROXY'))
parser.add_option('-r', '--retry', help='Number of retries', dest='retry', default=2)
return parser
def main():
parser = prepare_parser()
options, args = parser.parse_args()
if len(args) < 2:
print "usage: wmpriority.py <workflowname> <priority> [options]"
sys.exit(1)
workflow = args[0]
priority = args[1]
changePriorityWorkflow( options.url, workflow, priority, options.cert, options.key, options.retry)
sys.exit(0)
if __name__ == "__main__":
main()