1lfc2_python(3) Python Reference lfc2_python(3)
2
3
4
6 lfc2 - New python interface to the LFC client API
7 lfc2thr - Thread enabled version of Python interface to the LFC
8
10 import lfc2 as lfc
11
12 import lfc2thr as lfc
13 lfc.init()
14
15
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
29 lfc_aborttrans ( )
30
31 lfc_access ( string path, int amode ) -> bool access
32
33 lfc_accessr ( string sfn, int amode ) -> bool access
34
35 lfc_addreplica ( string guid, struct lfc_fileid *file_uniqueid, string
36 server, string sfn, char status, char f_type, string poolname, string
37 fs )
38
39 lfc_addreplicax ( string guid, struct lfc_fileid *file_uniqueid, string
40 server, string sfn, char status, char f_type, string poolname, string
41 fs, char r_type, string setname )
42
43 lfc_chdir ( string path )
44
45 lfc_chmod ( string path, mode_t mode )
46
47 lfc_chown ( string path, uid_t new_uid, gid_t new_gid )
48
49 lfc_client_setAuthorizationId ( uid_t uid, gid_t gid, string mech,
50 string id )
51
52 lfc_client_setVOMS_data ( string voname, stringlist vomsdata )
53
54 lfc_closedir ( lfc_DIR dirp )
55
56 lfc_creatg ( string path, string guid, mode_t mode )
57
58 lfc_delcomment ( string path )
59
60 lfc_delete ( string path )
61
62 lfc_delfilesbyguid ( ListOfString guids, int force ) -> ListOfInt
63 result
64
65 lfc_delfilesbyname ( ListOfString names, intforce ) -> ListOfInt
66 results
67
68 lfc_delfilesbypattern ( string path, string pattern, int force ) ->
69 ListOf struct lfc_filestatus results
70
71 lfc_delreplica ( string guid, struct lfc_fileid *file_uniqueid, string
72 sfn )
73
74 lfc_delreplicas ( ListOfString sfns, string se ) -> ListOfInt results
75
76 lfc_delreplicasbysfn ( ListOfString sfns, ListOfString guids ) ->
77 ListOfInt results
78
79 lfc_endsess ( )
80
81 lfc_endtrans ( )
82
83 lfc_getacl ( string path, ) -> ListOf struct lfc_acl acls
84
85 lfc_getcomment ( string path ) -> string comment
86
87 lfc_getcwd ( ) -> string dir
88
89 lfc_getifcevers ( ) -> string version
90
91 lfc_getlinks ( string path, string guid ) -> ListOf struct lfc_linkinfo
92 links
93
94 lfc_getreplica ( string path, string guid, string se ) -> ListOf struct
95 lfc_filereplica replicas
96
97 lfc_getreplicas ( ListOfString guids, string se ) -> ListOf struct
98 lfc_filereplicas replicas
99
100 lfc_getreplicasl ( ListOfString paths, string se ) -> ListOf struct
101 lfc_filereplicas replicas
102
103 lfc_getreplicass ( ListOfString paths, ) -> ListOf struct lfc_fil‐
104 ereplicas replicas
105
106 lfc_getreplicax ( string path, string guid, string se ) -> ListOf
107 struct lfc_filereplicax replicas
108
109 lfc_lchown ( string path, uid_t new_uid, gid_t new_gid )
110
111 lfc_listreplicax ( string poolname, string server, string fs, int
112 flags, lfc_list * listp ) -> struct lfc_filereplica replica
113
114 lfc_listrepset ( string setname, int flags, lfc_list *listp ) -> struct
115 lfc_filereplicax replica
116
117 lfc_lstat ( string path ) -> struct lfc_filestat statbuf
118
119 lfc_mkdir ( string path, mode_t mode )
120
121 lfc_mkdirg ( string path, string guid, mode_t mode )
122
123 lfc_modreplica ( string sfn, string setname, string poolname, string
124 server )
125
126 lfc_modreplicax ( string sfn, string setname, string poolname, string
127 server, string fs, char r_type )
128
129 lfc_opendir ( string path ) -> lfc_DIR dir
130
131 lfc_opendirg ( string path, string guid ) -> lfc_DIR dir
132
133 lfc_opendirxg ( string server, string path, string guid ) -> lfc_DIR
134 dir
135
136 lfc_ping ( string server ) -> string info
137
138 lfc_readdir ( lfc_DIR dirp ) -> struct dirent dirent
139
140 lfc_readdirc ( lfc_DIR dirp ) -> struct lfc_direncomm dirent
141
142 lfc_readdirg ( lfc_DIR dirp ) -> struct lfc_direnstatg dirent
143
144 lfc_readdirx ( lfc_DIR dirp ) -> struct lfc_direnstat dirent
145
146 lfc_readdirxc ( lfc_DIR dirp ) -> struct lfc_direnstatc dirent
147
148 lfc_readdirxp ( lfc_DIR dirp, string pattern, string se = None ) ->
149 struct lfc_direnrep dirent
150
151 lfc_readdirxr ( lfc_DIR dirp, string se = None ) -> struct lfc_direnrep
152 dirent
153
154 lfc_readlink ( string path ) -> string link
155
156 lfc_registerfiles ( ListOf struct lfc_filereg files ) -> ListOfInt
157 results
158
159 lfc_rename ( string oldpath, string newpath )
160
161 lfc_rewinddir ( lfc_DIR dirp )
162
163 lfc_rmdir ( string path )
164
165 lfc_setacl ( string path, ListOf struct lfc_acl acls )
166
167 lfc_setatime ( string path, struct lfc_fileid file_uniqueid )
168
169 lfc_setcomment ( string path, string comment )
170
171 lfc_setfsize ( string path, struct lfc_fileid file_uniqueid, long file‐
172 size )
173
174 lfc_setfsizec ( string path, struct lfc_fileid file_uniqueid, long
175 filesize, string csumtype, string csumvalue )
176
177 lfc_setfsizeg ( string guid, long filesize, string csumtype, string
178 csumvalue )
179
180 lfc_setptime ( string sfn, long ptime )
181
182 lfc_setratime ( string sfn )
183
184 lfc_setrltime ( string sfn, long ltime )
185
186 lfc_setrstatus ( string sfn, char status )
187
188 lfc_setrtype ( string sfn, char type )
189
190 lfc_startsess ( string server, string comment )
191
192 lfc_starttrans ( string server, string comment )
193
194 lfc_stat ( string path ) -> struct lfc_filestat statbuf
195
196 lfc_statg ( string path, string guid ) -> struct lfc_filestatg statbuf
197
198 lfc_statr ( string sfn) ) -> struct lfc_filestatg statbuf
199
200 lfc_symlink ( string target, string linkname )
201
202 lfc_umask ( mode_t cmask ) -> mode_t oldmask
203
204 lfc_undelete ( string path )
205
206 lfc_unlink ( string path )
207
208 lfc_utime ( string path, struct utimbuf times )
209
210 lfc_entergrpmap ( gid_t gid, string groupname )
211
212 lfc_enterusrmap ( uid_t uid, string username )
213
214 lfc_getgrpbygid ( gid_t gid ) -> string group
215
216 lfc_getgrpbygids ( ListOfgid_t gids ) -> ListOfString groups
217
218 lfc_getgrpbynam ( string groupname ) -> gid_t gid
219
220 lfc_getgrpmap ( ) -> ListOf struct lfc_groupinfo infos
221
222 lfc_getidmap ( string username, ListOfString vo_roles ) -> uid_t uid,
223 ListOf gid_t gids
224
225 lfc_getusrbynam ( string username ) -> uid_t uid
226
227 lfc_getusrbyuid ( uid_t uid ) -> string user
228
229 lfc_getusrmap ( ) -> ListOf struct lfc_userinfo userinfo
230
231 lfc_modifygrpmap ( gid_t gid, string newname )
232
233 lfc_modifyusrmap ( uid_t uid, string newname )
234
235 lfc_rmgrpmap ( gid_t gid, string groupname )
236
237 lfc_rmusrmap ( uid_t uid, string username )
238
239
241 Sometimes you need to specify a structure as an input argument (eg.
242 struct lfc_acl, struct lfc_list, etc.). For that purpose, the module
243 includes structure constructors, named exactly as the structure.
244
245 Thus, to create struct lfc_acl or struct lfc_list, you have to do the
246 following:
247
248 lfcacl = lfc.lfc_acl()
249 lfclist = lfc.lfc_list()
250
251 If you want to see how to use it in a real case, please have a look at
252 examples.
253
254
256 As you can see, no error code is returned. When an error occurs, an
257 exception is raised with a description of the error.
258
259
261 #!/usr/bin/python
262
263 import sys
264 import traceback
265 import lfc2 as lfc
266
267 """
268 # stat an existing entry in the LFC and print the GUID
269 """
270
271 name = "/grid/dteam/my.test"
272
273 try:
274 stat = lfc.lfc_statg(name,"")
275 except Exception:
276 traceback.print_exc()
277 sys.exit(1)
278
279 guid = stat.guid
280 print "The GUID for " + name + " is " + guid
281
282
284 #!/usr/bin/python
285
286 import sys
287 import traceback
288 import lfc2 as lfc
289
290 """
291 # setting and retrieving a comment on a file
292 """
293
294 file = "/grid/dteam/my.test"
295 comment = "MyComment"
296
297 try:
298 lfc.lfc_setcomment(file,comment)
299
300 comment = lfc.lfc_getcomment(file)
301 print "Read back comment " + comment
302 except Exception:
303 traceback.print_exc()
304 sys.exit(1)
305
306
308 #!/usr/bin/python
309
310 """
311 # Using the lfc_readdirxr method
312 """
313
314 import sys
315 import traceback
316 import lfc2 as lfc
317
318 name = "/grid/dteam/my.test"
319
320 try:
321 dir = lfc.lfc_opendir(name)
322
323 while 1:
324 entry = lfc.lfc_readdirxr(dir)
325 if entry == None:
326 break
327 print entry.d_name
328 for i in range(entry.nbreplicas):
329 print " ==> %s" % entry.rep[i].sfn
330
331 lfc.lfc_closedir(dir)
332 except TypeError, x:
333 print " ==> None"
334 except Exception:
335 traceback.print_exc()
336 sys.exit(1)
337
338
340 #!/usr/bin/python
341
342 import sys
343 import traceback
344 import lfc2 as lfc
345
346 """
347 # Using the lfc_getreplica method
348 """
349
350 file = "/grid/dteam/my.test"
351
352 try:
353 list = lfc.lfc_getreplica(file, "", "")
354 except Exception:
355 traceback.print_exc()
356 sys.exit(1)
357
358 for i in list:
359 print i.host
360 print i.sfn
361
362
364 #!/usr/bin/python
365
366 import sys
367 import traceback
368 import lfc2 as lfc
369
370 """
371 # Using the lfc_getacl and lfc_setacl methods to add a user ACL
372 """
373
374 file = "/grid/dteam/my.test"
375
376 try:
377 acls_list = lfc.lfc_getacl(file)
378 except Exception:
379 traceback.print_exc()
380 sys.exit(1)
381
382 for i in acls_list:
383 print i.a_type
384 print i.a_id
385 print i.a_perm
386
387 # When adding a first ACL for a given user, you also need to add the mask
388 # When adding the second user ACL, it is not necessary anymore
389
390 acl_user = lfc.lfc_acl()
391 acl_mask = lfc.lfc_acl()
392
393 acl_user.a_type = lfc.CNS_ACL_USER
394 acl_user.a_id = 18701 # user id
395 acl_user.a_perm = lfc.S_IROTH | lfc.S_IXOTH
396
397 acl_mask.a_type = lfc.CNS_ACL_MASK
398 acl_mask.a_id = 0 # no user id specified
399 acl_mask.a_perm = lfc.S_IROTH | lfc.S_IXOTH
400
401 acls_list.append(acl_user)
402 acls_list.append(acl_mask)
403
404 try:
405 lfc.lfc_setacl(file, acls_list)
406 except Exception:
407 traceback.print_exc()
408 sys.exit(1)
409
410
412 #!/usr/bin/python
413
414 import sys
415 import traceback
416 import lfc2 as lfc
417
418 """
419 # Using the lfc_getacl and lfc_setacl methods to remove a user ACL
420 """
421
422 file = "/grid/dteam/my.test"
423
424 try:
425 acls_list = lfc.lfc_getacl(file)
426 except Exception:
427 traceback.print_exc()
428 sys.exit(1)
429
430 for i in acls_list:
431 print i.a_type
432 print i.a_id
433 print i.a_perm
434
435 del acls_list[1] # delete a given user ACL from the list of ACLs
436
437 try:
438 lfc.lfc_setacl(file, acls_list)
439 except Exception:
440 traceback.print_exc()
441 sys.exit(1)
442
443
445 #!/usr/bin/env python
446 import lfc2thr as lfc
447 import os
448 from threading import Thread
449
450 class slave(Thread):
451
452 def __init__ (self):
453 Thread.__init__(self)
454
455 def run(self):
456 ....
457 result = lfc.lfc_getreplica("", guid, "")
458 ....
459 return
460
461 if __name__ == '__main__':
462
463 os.environ['LFC_HOST'] = 'my_lfc.cern.ch'
464
465 # Threaded library initialisation
466 lfc.init()
467
468 ....
469 # Start up of threads
470 for i in xrange(totalNumberOfSlaves):
471 slv = slave(i)
472 slv.start()
473
474 ....
475
476
478 #!/usr/bin/python
479
480 import sys
481 import traceback
482 import lfc2 as lfc
483
484 """
485 # Using the lfc_getusrmap method
486 """
487
488 try:
489 list = lfc.lfc_getusrmap()
490 except Exception:
491 traceback.print_exc()
492 sys.exit(1)
493
494 for i in list:
495 print i.userid + " " + i.username
496
497
499 #!/usr/bin/python
500
501 import sys
502 import traceback
503 import lfc2 as lfc
504
505 """
506 # Using the lfc_getgrpmap method
507 """
508
509 try:
510 list = lfc.lfc_getgrpmap()
511 except Exception:
512 traceback.print_exc()
513 sys.exit(1)
514
515 for i in list:
516 print i.gid + " " + i.groupname
517
518
520 #!/usr/bin/python
521
522 import sys
523 import traceback
524 import lfc2 as lfc
525
526 """
527 # Using the lfc_getidmap method
528 """
529
530 userdn = "user certificate DN"
531 vo_roles = ["dteam"]
532
533 try:
534 uid, gids = lfc.lfc_getidmap (userdn, vo_roles)
535 except Exception:
536 traceback.print_exc()
537 sys.exit(1)
538
539 print "uid=", uid
540 print "gids=", gids
541
542
544 LFC C interface man pages
545
546
547
548LFC $Date: 2010-12-14 08:31:05 +0100 (Tue, 14 Dec 2010)l$fc2_python(3)