ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/osg_bdii.py
Revision: 1.2
Committed: Sun Apr 1 22:41:27 2007 UTC (18 years, 1 month ago) by gutsche
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_0_0_pre5, CRAB_1_5_3_pre3, configure, CRAB_2_0_0_pre4, CRAB_1_5_3_pre2, CRAB_1_5_3_pre1, CRAB_2_0_0_pre3, CRAB_1_5_2, CRAB_2_0_0_pre2, CRAB_2_0_0_pre1, CRAB_1_5_1, CRAB_1_5_1_pre4, CRAB_1_5_1_pre3, CRAB_1_5_1_pre2, CRAB_1_5_1_pre1, CRAB_1_5_0, CRAB_1_5_0_pre9
Changes since 1.1: +22 -9 lines
Log Message:
improvements in OSG usage of BDII

File Contents

# Content
1 #!/usr/bin/python
2 import re, popen2, sys
3 def unwraplines(wrapped_list):
4 r = re.compile('^ (.*)$')
5 unwrapped_list = []
6 for l in wrapped_list:
7 m = r.match(l)
8 if m:
9 unwrapped_list[-1] += m.groups()[0]
10 else:
11 unwrapped_list.append(l.rstrip())
12
13 return unwrapped_list
14
15
16 def runldapquery(filter, attribute, bdii):
17 # bdii = 'exp-bdii.cern.ch'
18 command = 'ldapsearch -xLLL -p 2170 -h '+bdii+' -b o=grid '
19 command += filter+' '+attribute
20
21 pout,pin,perr = popen2.popen3(command)
22
23 pout = pout.readlines()
24 p = perr.readlines()
25
26 pout = unwraplines(pout)
27 if (p):
28 for l in p: print l
29 raise RuntimeError('ldapsearch call failed')
30
31 return pout
32
33 def jm_from_se_bdii(se, bdii='exp-bdii.cern.ch'):
34 se = '\''+se+'\''
35 pout = runldapquery(''' '(GlueCESEBindGroupSEUniqueID='''+se+''')' ''',
36 'GlueCESEBindGroupCEUniqueID', bdii)
37
38 r = re.compile('^GlueCESEBindGroupCEUniqueID: (.*:.*/jobmanager-.*)-cms')
39 jm = []
40 for l in pout:
41 m = r.match(l)
42 if m:
43 item = m.groups()[0]
44 if (jm.count(item) == 0):
45 jm.append(m.groups()[0])
46
47 return jm
48
49
50 def cestate_from_se_bdii(se, bdii='exp-bdii.cern.ch' ):
51 status = []
52 jmlist = jm_from_se_bdii(se)
53
54 for jm in jmlist:
55 jm += "-cms"
56
57 pout = runldapquery(''' '(&(objectClass=GlueCEState)(GlueCEUniqueID='''+
58 jm+'''))' ''', 'GlueCEStateStatus', bdii)
59
60 r = re.compile('^GlueCEStateStatus: (.*)')
61 for l in pout:
62 m = r.match(l)
63 if m:
64 status.append(m.groups()[0])
65
66 return status
67
68 def cestate_from_ce_bdii(ce, bdii='exp-bdii.cern.ch'):
69 pout = runldapquery(''' '(&(objectClass=GlueCEState)(GlueCEInfoHostName='''+
70 ce+''')(GlueCEAccessControlBaseRule=VO:cms))' ''', 'GlueCEStateStatus', bdii)
71
72 status = ''
73 r = re.compile('^GlueCEStateStatus: (.*)')
74 for l in pout:
75 m = r.match(l)
76 if m:
77 status = m.groups()[0]
78
79 return status