1lfc_python(3)                  Python Reference                  lfc_python(3)
2
3
4

NAME

6       lfc - Python interface to the LFC
7       lfcthr - Thread enabled version of Python interface to the LFC
8

SYNOPSIS

10       import lfc
11
12       import lfcthr
13       lfcthr.init()
14
15

DESCRIPTION

17       The  lfc  module  permits  you  to access the LFC client interface from
18       python programs. The lfc module is a swig wrapping of  the  standard  C
19       interface.  For detailed descriptions of each function see the individ‐
20       ual man page of each function.
21
22       The lfcthr module is a version of  the  lfc  module  supporting  multi-
23       threaded  Python  clients. Its usage is similar to the usage of the lfc
24       module except the obligatory initialisation call lfcthr.init()  in  the
25       main program before threads are started.
26
27       There follows a series of examples of how to use selected functions and
28       how to retrieve the information returned by them: Examples are  finding
29       the GUID of an existing entry, listing the replicas of a given GUID and
30       setting and retrieving the comment associated with an entry.
31

EXAMPLE

33       #!/usr/bin/python
34
35       import sys
36       import lfc
37
38       """
39       # stat an existing entry in the LFC and print the GUID
40       """
41
42       name = "/grid/dteam/my.test"
43
44       stat = lfc.lfc_filestatg()
45       res = lfc.lfc_statg(name,"",stat)
46
47       if res == 0:
48          guid = stat.guid
49          print "The GUID for " + name + " is " + guid
50       else:
51          err_num = lfc.cvar.serrno
52          err_string = lfc.sstrerror(err_num)
53          print "There was an error while looking for " + name + ": Error " + str(err_num) \
54                 + " (" + err_string + ")"
55          sys.exit(1)
56

EXAMPLE

58       #!/usr/bin/python
59
60       import lfc
61
62       """
63       # list the replicas of a given entry, starting from the GUID
64       """
65
66       guid = "6a3164e0-a4d7-4abe-9f76-e3b8882735d1"
67
68       listp = lfc.lfc_list()
69       flag = lfc.CNS_LIST_BEGIN
70
71       print "Listing replicas for GUID " + guid
72
73       num_replicas=0
74
75       while(1):
76          res = lfc.lfc_listreplica("",guid,flag,listp)
77          flag = lfc.CNS_LIST_CONTINUE
78
79          if res == None:
80             break
81          else:
82             rep_name = res.sfn
83             print "Replica: " + rep_name
84             num_replicas = num_replicas + 1
85
86       lfc.lfc_listreplica("",guid,lfc.CNS_LIST_END,listp)
87       print "Found " + str(num_replicas) + " replica(s)"
88

EXAMPLE

90       #!/usr/bin/python
91
92       import sys
93       import lfc
94       import re
95
96       """
97       # setting and retrieving a comment on a file
98       """
99
100       file = "/grid/dteam/my.test"
101
102       comment = "MyComment"
103       res = lfc.lfc_setcomment(file,comment)
104
105       if res != 0:
106          err_num = lfc.cvar.serrno
107          err_string = lfc.sstrerror(err_num)
108          print "Problem while setting comment for " + file + ": Error " + str(err_num) \
109                 + " (" + err_string + ")"
110          sys.exit(1)
111
112       buffer=""
113       for i in range(0,lfc.CA_MAXCOMMENTLEN+1):
114         buffer=buffer + " "
115
116       res = lfc.lfc_getcomment(file,buffer)
117
118       if res != 0:
119          err_num = lfc.cvar.serrno
120          err_string = lfc.sstrerror(err_num)
121          print "Problem while reading the comment for " + file + ": Error " + str(err_num) \
122                 + " (" + err_string + ")"
123          sys.exit(1)
124
125       r = re.compile("(.*?) ", re.DOTALL)
126       comment = r.findall(buffer)[0]
127
128       print "Read back comment " + comment
129
130

EXAMPLE

132       #!/usr/bin/python
133
134       """
135       # Using the lfc_readdirxr method
136       """
137
138       import sys
139       import lfc
140
141       name = "/grid/dteam/my.test"
142
143       dir = lfc.lfc_opendirg(name,"")
144       if (dir == None) or (dir == 0):
145               err_num = lfc.cvar.serrno
146               err_string = lfc.sstrerror(err_num)
147               print "Error while looking for " + name + ": Error " + str(err_num) \
148                      + " (" + err_string + ")"
149               sys.exit(1)
150
151       while 1:
152               read_pt = lfc.lfc_readdirxr(dir,"")
153               if (read_pt == None) or (read_pt == 0):
154                       break
155               entry, list = read_pt
156               print entry.d_name
157               try:
158                       for i in range(len(list)):
159                               print " ==> %s" % list[i].sfn
160               except TypeError, x:
161                       print " ==> None"
162
163       lfc.lfc_closedir(dir)
164
165

EXAMPLE

167       #!/usr/bin/python
168
169       import lfc
170
171       """
172       # Using the lfc_getlinks method
173       """
174
175       result, list = lfc.lfc_getlinks("/grid/dteam/antotests/extratests/dir2/f105", "")
176       print result
177       print len(list)
178       if (result == 0):
179            for i in list:
180                 print i.path
181
182

EXAMPLE

184       #!/usr/bin/python
185
186       import lfc
187
188       """
189       # Using the lfc_getreplica method
190       """
191
192       result, list = lfc.lfc_getreplica("/grid/dteam/antotests/extratests/dir2/f105", "", "")
193       print result
194       print len(list)
195       if (result == 0):
196            for i in list:
197                 print i.host
198                 print i.sfn
199
200

EXAMPLE

202       #!/usr/bin/python
203
204       import lfc
205
206       """
207       # Using the lfc_getacl and lfc_setacl methods to add a user ACL
208       """
209
210       nentries, acls_list = lfc.lfc_getacl("/grid/dteam/tests_sophie3", lfc.CA_MAXACLENTRIES)
211
212       print nentries
213       print len(acls_list)
214
215       for i in acls_list:
216               print i.a_type
217               print i.a_id
218               print i.a_perm
219
220       # When adding a first ACL for a given user, you also need to add the mask
221       # When adding the second user ACL, it is not necessary anymore
222
223       acl_user = lfc.lfc_acl()
224       acl_mask = lfc.lfc_acl()
225
226       acl_user.a_type=2        # 2 corresponds to CNS_ACL_USER
227       acl_user.a_id=18701      # user id
228       acl_user.a_perm=5
229
230       acl_mask.a_type=5        # 5 corresponds to CNS_ACL_MASK
231       acl_mask.a_id=0               # no user id specified
232       acl_mask.a_perm=5
233
234       acls_list.append(acl_user)
235       acls_list.append(acl_mask)
236
237       res = lfc.lfc_setacl("/grid/dteam/tests_sophie3", acls_list)
238
239       if res == 0:
240               print "OK"
241       else:
242               err_num = lfc.cvar.serrno
243               err_string = lfc.sstrerror(err_num)
244               print "There was an error : Error " + str(err_num) + " (" + err_string + ")"
245               sys.exit(1)
246
247

EXAMPLE

249       #!/usr/bin/python
250
251       import lfc
252
253       """
254       # Using the lfc_getacl and lfc_setacl methods to remove a user ACL
255       """
256
257       nentries, acls_list = lfc.lfc_getacl("/grid/dteam/tests_sophie3", lfc.CA_MAXACLENTRIES)
258
259       # Note : you cannot remove the owner ACL (i.e. for CNS_ACL_USER_OBJ type) if ACLs
260       # ====== for other users exist. Ff all the other user ACLs are deleted, the owner
261       # ====== ACL is automatically removed.
262
263       for i in acls_list:
264               print i.a_type
265               print i.a_id
266               print i.a_perm
267
268       del acls_list[1]    # delete a given user ACL from the list of ACLs
269
270       res = lfc.lfc_setacl("/grid/dteam/tests_sophie3", acls_list)
271
272       if res == 0:
273               print "OK"
274       else:
275               err_num = lfc.cvar.serrno
276               err_string = lfc.sstrerror(err_num)
277               print "There was an error : Error " + str(err_num) + " (" + err_string + ")"
278               sys.exit(1)
279
280

EXAMPLE

282       #!/usr/bin/env python
283       import lfcthr
284       import os
285       from threading import Thread
286
287       class slave(Thread):
288
289          def __init__ (self):
290             Thread.__init__(self)
291
292          def run(self):
293               ....
294               result = lfcthr.lfc_getreplica("", guid, "")
295               ....
296               return
297
298       if __name__ == '__main__':
299
300           os.environ['LFC_HOST'] = 'my_lfc.cern.ch'
301
302           #     Threaded library initialisation
303           lfcthr.init()
304
305           ....
306           #     Start up of threads
307           for i in xrange(totalNumberOfSlaves):
308               slv = slave(i)
309               slv.start()
310
311           ....
312
313
314

EXAMPLE

316       #!/usr/bin/python
317
318       import lfc
319
320       """
321       # Using the lfc_getusrmap method
322       """
323
324       result, list = lfc.lfc_getusrmap()
325       print result
326       print len(list)
327       if (result == 0):
328            for i in list:
329                 print i.userid + " " + i.username
330
331

EXAMPLE

333       #!/usr/bin/python
334
335       import lfc
336
337       """
338       # Using the lfc_getgrpmap method
339       """
340
341       result, list = lfc.lfc_getgrpmap()
342       print result
343       print len(list)
344       if (result == 0):
345            for i in list:
346                 print i.gid + " " + i.groupname
347
348

KNOWN BUGS

350       The  current  interface  to   the   lfc_getcomment(3),   lfc_getcwd(3),
351       lfc_readlink(3),  lfc_seterrbuf(3)  requires  the passing of str object
352       which is modified to contain the result (in a  similar  way  to  the  C
353       functions,  which accept a buffer).  However this breaks the immutabil‐
354       ity of python str. This will be changed in the future.
355

SEE ALSO

357       LFC C interface man pages
358
359
360
361LFC          $Date: 2010-02-04 13:08:39 +0100 (Thu, 04 Feb 2010) $lfc_python(3)
Impressum