forked from CMSCompOps/WmAgentScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
findCustodialLocation.py
61 lines (52 loc) · 1.95 KB
/
findCustodialLocation.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
#!/usr/bin/env python
import urllib2,urllib, httplib, sys, re, os, json, time, math, dbsTest, locale
import optparse, closeOutWorkflows
from xml.dom.minidom import getDOMImplementation
def getInputDataset(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()
request = json.read(r2.read())
if 'InputDataset' in request.keys():
return request['InputDataset']
else:
return "None"
def findCustodialLocation(url, dataset):
conn = httplib.HTTPSConnection(url, cert_file = os.getenv('X509_USER_PROXY'), key_file = os.getenv('X509_USER_PROXY'))
r1=conn.request("GET",'/phedex/datasvc/json/prod/blockreplicas?dataset='+dataset)
r2=conn.getresponse()
result = json.read(r2.read())
request=result['phedex']
if 'block' not in request.keys():
return "No Site"
if len(request['block'])==0:
return "No Site"
for replica in request['block'][0]['replica']:
if replica['custodial']=="y":
return replica['node']
return "No Custodial Site found"
def main():
url='cmsweb.cern.ch'
siteList=['CNAF', 'FNAL', 'IN2P3', 'PIC', 'KIT', 'ASGC', 'RAL']
parser = optparse.OptionParser()
parser.add_option('-d', '--dataset', help='Name of the dataset', dest='dataset')
parser.add_option('-r', '--request', help='Name of the request', dest='request')
(options,args) = parser.parse_args()
if not options.dataset and not options.request:
print "Must specify a request or a dataset"
sys.exit(0);
if options.dataset and options.request:
print "Must specify request or dataset not BOTH"
sys.exit(0);
dataset=""
if options.dataset:
dataset=options.dataset
if options.request:
dataset=getInputDataset(url, options.request)
if dataset=="None":
print "Request withouh input dataset"
site=findCustodialLocation(url,dataset)
print site
sys.exit(0);
if __name__ == "__main__":
main()