This repository has been archived by the owner on Sep 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
wmpriority.py
executable file
·64 lines (54 loc) · 2.01 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
56
57
58
59
60
61
62
63
64
#! /usr/bin/env python
from __future__ import print_function
try:
import httplib
except ImportError:
import http.client as httplib
import sys
import os
import optparse
import time
import json
def change_priority(url, workflow, priority, cert, key, retry):
data = {'RequestPriority': priority}
headers = {'Content-type': 'application/json',
'Accept': 'application/json'}
for _ in range(retry):
conn = httplib.HTTPSConnection(url, cert_file=cert, key_file=key)
conn.request('PUT', '/reqmgr2/data/request/%s' % workflow, json.dumps(data), headers)
response = conn.getresponse()
status, res = response.status, response.read()
conn.close()
if status == 200:
return json.loads(res).get('result', [])[0].get(workflow, '').lower() == 'ok'
print('Status: %s, response: %s' % (status, res))
time.sleep(1)
return False
def main():
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=1)
options, args = parser.parse_args()
if len(args) < 2:
print('usage: wmpriority.py <workflowname> <priority> [options]')
sys.exit(1)
workflow = args[0]
priority = int(args[1])
res = change_priority(options.url, workflow, priority, options.cert, options.key, options.retry)
print('%s: %s' % (workflow, res))
if __name__ == "__main__":
main()