-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreate_fedmaps_DEV.py
executable file
·105 lines (90 loc) · 3.33 KB
/
create_fedmaps_DEV.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
try: import xml.etree.ElementTree as ET
except ImportError: from elementtree import ElementTree as ET
try: import json
except ImportError: import simplejson as json
import urllib2, httplib, sys
# global vars: prod, trans : we create these text files, see run.py
# cmsTopology : static text from dashboard team,
# sites : from BDII
# output : {"prod" : [...], "trans" : [...], "nowhere" : [...]}
output = {"prod" : [], "trans" : [], "nowhere" : []}
def getDataFromURL(url, header = {}):
request = urllib2.Request(url, headers=header)
urlObj = urllib2.urlopen(request)
data = urlObj.read()
return data
def getSites():
XML = getDataFromURL('http://dashb-cms-vo-feed.cern.ch/dashboard/request.py/cmssitemapbdii')
XML = ET.fromstring(XML)
sites = XML.findall('atp_site')
ret = {}
for site in sites:
groups = site.findall('group')
siteName = None
for i in groups:
if i.attrib['type'] == 'CMS_Site':
siteName = groups[1].attrib['name']
break
if not siteName:
continue
services = site.findall('service')
ret[siteName] = {}
ret[siteName]['hosts'] = []
ret[siteName]['name'] = site.attrib['name']
for service in services:
serviceName = service.attrib['hostname']
ret[siteName]['hosts'].append(serviceName)
return ret
def parseHN(data):
parsedHNs = []
for line in data.split('\n'):
if not len(line): continue
if ':' in line: line = line[:line.find(':')]
parsedHNs.append(line)
return parsedHNs
# try exception if we have a problem with URL.
try :
sites = getSites()
except Exception as e :
err={}
err["error"] = str(e)
print json.dumps(err)
sys.exit(1)
#import expection dictionary
with open('/root/FederationInfo/exceptions.json') as f: exc = f.read()
exc = json.loads(exc)
def exception(name):
ret = None
for i in exc.keys():
if i == name : return exc[i]['VOname']
return ret
def siteName2CMSSiteName(dom):
ret = None
for cmsSite in sites.keys():
ret = exception(dom)
if ret :
ret = str(ret)
return ret
if sites[cmsSite]['hosts'][0].find(dom) != -1: return cmsSite
return ret
if __name__ == "__main__":
# get domains
domains = {}
with open('/root/FederationInfo/in/prod_domain.txt') as f: domains['prod'] = parseHN(f.read())
with open('/root/FederationInfo/in/trans_domain.txt') as f: domains['trans'] = parseHN(f.read())
# find CMS site name of prod sites
for federation in ['prod', 'trans']:
for i in domains[federation]:
cmsSiteName = siteName2CMSSiteName(i)
#print cmsSiteName
if cmsSiteName and not cmsSiteName in output[federation]:
output[federation].append(cmsSiteName)
# special case for nowhere sites: if a site is not placed in both
# federations, move it into "nowhere" array
for cmsSite in sites.keys():
if not cmsSite in output['prod'] and not cmsSite in output['trans']:
output["nowhere"].append(cmsSite)
if cmsSite == "T1_FR_CCIN2P3" and cmsSite in output['prod'] :
output["prod"].append("T2_FR_CCIN2P3")
with open('/root/FederationInfo/out/federations.json', 'w') as f:
f.write(json.dumps(output, indent = 1))