1 |
xmzhang |
1.1 |
#!/usr/bin/python
|
2 |
|
|
import string, os
|
3 |
|
|
import xml.dom.minidom
|
4 |
|
|
from xml import xpath
|
5 |
|
|
|
6 |
|
|
def getChildValue(element, child):
|
7 |
|
|
child = element.getElementsByTagName(child)[0].firstChild
|
8 |
|
|
if child is not None:
|
9 |
|
|
return str(child.nodeValue)
|
10 |
|
|
return None
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
pid=os.getpid()
|
14 |
|
|
namesUrl= 'https://cmsweb.cern.ch/sitedb/sitedb/reports/showXMLReport/?reportid=naming_convention.ini'
|
15 |
|
|
|
16 |
|
|
fileN="/tmp/sitelist.%i" % pid
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
os.system('wget -q --no-check-certificate -O %s %s' % (fileN, namesUrl))
|
20 |
|
|
f=file(fileN,'r')
|
21 |
|
|
t= xml.dom.minidom.parse(f)
|
22 |
|
|
f.close()
|
23 |
|
|
|
24 |
|
|
Sites={}
|
25 |
|
|
for url in xpath.Evaluate('report/result/item', t):
|
26 |
|
|
samName=getChildValue(url, 'sam')
|
27 |
|
|
cmsName=getChildValue(url, 'cms')
|
28 |
|
|
numId=getChildValue(url, 'id')
|
29 |
|
|
if cmsName not in Sites.keys():
|
30 |
|
|
Sites[cmsName]=numId
|
31 |
|
|
|
32 |
|
|
sortedSites=Sites.keys()
|
33 |
|
|
sortedSites.sort()
|
34 |
|
|
|
35 |
|
|
pledgeBaseUrl="https://cmsweb.cern.ch/sitedb/sitedb/xml/index/Pledge?site="
|
36 |
|
|
for site in sortedSites:
|
37 |
|
|
id=Sites[site]
|
38 |
|
|
pledgeUrl= pledgeBaseUrl + id
|
39 |
|
|
pledgeBaseUrl="https://cmsweb.cern.ch/sitedb/sitedb/xml/index/Pledge?site="
|
40 |
|
|
curlcommand='curl -ks "'+pledgeUrl+'"'
|
41 |
|
|
SiteDBData='\n'.join(os.popen(curlcommand).readlines())
|
42 |
|
|
pledgeDataXML = xml.dom.minidom.parseString(SiteDBData)
|
43 |
|
|
pledgeDataElement = xpath.Evaluate('SiteDB', pledgeDataXML)[0]
|
44 |
|
|
disk = getChildValue (pledgeDataElement, 'disk_store_-_TB')
|
45 |
|
|
disk=int(float(disk))
|
46 |
|
|
tape = getChildValue (pledgeDataElement, 'tape_store_-_TB')
|
47 |
|
|
tape = int(float(tape))
|
48 |
|
|
slots = getChildValue (pledgeDataElement, 'job_slots_-_')
|
49 |
|
|
slots=int(float(slots))
|
50 |
|
|
print id, site, slots, disk, tape
|