forked from CMSCompOps/WmAgentScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pledged.py
executable file
·42 lines (36 loc) · 1.09 KB
/
pledged.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
#!/usr/bin/env python
import urllib2, urllib
from xml.dom import minidom
def loadnamingconvention():
sitelist = {}
url = 'https://cmsweb.cern.ch/sitedb/reports/showXMLReport/?reportid=naming_convention.ini'
naming = minidom.parse(urllib.urlopen(url))
for node in naming.getElementsByTagName('item'):
# the http call doesn't work with T3*
tname = node.getElementsByTagName('cms')[0].firstChild.data
if "T2_" in tname or ( "T1_" in tname and "_Disk" not in tname):
if tname != "T2_CH_CAF" and tname != 'T1_CH_CERN':
sitelist[node.getElementsByTagName('id')[0].firstChild.data] = tname
return sitelist
def getslots(index):
url = 'https://cmsweb.cern.ch/sitedb/json/index/Pledge?site=%s' % index
data = urllib2.urlopen(url)
s = data.read()
try:
res = eval(s)
return int(res['0']['job_slots - #'])
except:
return 0
def allpledged():
sitelist = {}
pledged = {}
sites = loadnamingconvention()
for (k,v) in sites.items():
slots = getslots(k)
if slots > 0:
#if 1:
pledged[v] = slots
return pledged
p = allpledged()
for (k,v) in sorted(p.iteritems()):
print "%s %s" % (k,v)