1lfc2_python(3) Python Reference
2lfc2_python(3)
3
4
5
6[1mNAME[0m
7 lfc2 ‐ New python interface to the LFC client API
8 lfc2thr ‐ Thread enabled version of Python interface to
9the LFC
10
11[1mSYNOPSIS[0m
12 [1mimport lfc2 as lfc[0m
13
14 [1mimport lfc2thr as lfc[0m
15 [1mlfc.init()[0m
16
17
18[1mDESCRIPTION[0m
19 The lfc module permits you to access the LFC client
20interface from
21 python programs. The lfc module is a swig wrapping of the
22standard C
23 interface. For detailed descriptions of each function see
24the individ‐
25 ual man page of each function.
26
27 The lfcthr module is a version of the lfc module sup‐
28porting multi‐
29 threaded Python clients. Its usage is similar to the us‐
30age of the lfc
31 module except the obligatory initialisation call lfc‐
32thr.init() in the
33 main program before threads are started.
34
35
36[1mFUNCTIONS[0m
37 [1mlfc_aborttrans ( )[0m
38
39 [1mlfc_access ( string [4m[22mpath[24m[1m, int
40[4m[22mamode[24m [1m) ‐> bool [4m[22maccess[0m
41
42 [1mlfc_accessr ( string [4m[22msfn[24m[1m, int
43[4m[22mamode[24m [1m) ‐> bool [4m[22maccess[0m
44
45 [1mlfc_addreplica ( string [4m[22mguid[24m[1m, struct
46lfc_fileid *[4m[22mfile_uniqueid[24m[1m, string[0m
47 [4mserver[24m[1m, string [4m[22msfn[24m[1m, char
48[4m[22mstatus[24m[1m, char [4m[22mf_type[24m[1m, string
49[4m[22mpoolname[24m[1m, string[0m
50 [4mfs[24m [1m)[0m
51
52 [1mlfc_addreplicax ( string [4m[22mguid[24m[1m, struct
53lfc_fileid *[4m[22mfile_uniqueid[24m[1m, string[0m
54 [4mserver[24m[1m, string [4m[22msfn[24m[1m, char
55[4m[22mstatus[24m[1m, char [4m[22mf_type[24m[1m, string
56[4m[22mpoolname[24m[1m, string[0m
57 [4mfs[24m[1m, char [4m[22mr_type[24m[1m, string
58[4m[22msetname[24m [1m)[0m
59
60 [1mlfc_chdir ( string [4m[22mpath[24m [1m)[0m
61
62 [1mlfc_chmod ( string [4m[22mpath[24m[1m, mode_t
63[4m[22mmode[24m [1m)[0m
64
65 [1mlfc_chown ( string [4m[22mpath[24m[1m, uid_t
66[4m[22mnew_uid[24m[1m, gid_t [4m[22mnew_gid[24m [1m)[0m
67
68 [1mlfc_client_setAuthorizationId ( uid_t
69[4m[22muid[24m[1m, gid_t [4m[22mgid[24m[1m, string
70[4m[22mmech[24m[1m,[0m
71 [1mstring [4m[22mid[24m [1m)[0m
72
73 [1mlfc_client_setVOMS_data ( string [4m[22mvoname[24m[1m,
74stringlist [4m[22mvomsdata[24m [1m)[0m
75
76 [1mlfc_closedir ( lfc_DIR [4m[22mdirp[24m [1m)[0m
77
78 [1mlfc_creatg ( string [4m[22mpath[24m[1m, string
79[4m[22mguid[24m[1m, mode_t [4m[22mmode[24m [1m)[0m
80
81 [1mlfc_delcomment ( string [4m[22mpath[24m [1m)[0m
82
83 [1mlfc_delete ( string [4m[22mpath[24m [1m)[0m
84
85 [1mlfc_delfilesbyguid ( ListOfString [4m[22mguids[24m[1m,
86int [4m[22mforce[24m [1m) ‐> ListOfInt[0m
87 [4mresult[0m
88
89 [1mlfc_delfilesbyname ( ListOfString
90[4m[22mnames[24m[1m, int[4m[22mforce[24m [1m) ‐> ListOfInt[0m
91 [4mresults[0m
92
93 [1mlfc_delfilesbypattern ( string [4m[22mpath[24m[1m,
94string [4m[22mpattern[24m[1m, int [4m[22mforce[24m [1m) ‐>[0m
95 [1mListOf struct lfc_filestatus [4m[22mresults[0m
96
97 [1mlfc_delreplica ( string [4m[22mguid[24m[1m, struct
98lfc_fileid *[4m[22mfile_uniqueid[24m[1m, string[0m
99 [4msfn[24m [1m)[0m
100
101 [1mlfc_delreplicas ( ListOfString [4m[22msfns[24m[1m,
102string [4m[22mse[24m [1m) ‐> ListOfInt [4m[22mresults[0m
103
104 [1mlfc_delreplicasbysfn ( ListOfString
105[4m[22msfns[24m[1m, ListOfString [4m[22mguids[24m [1m) ‐>[0m
106 [1mListOfInt [4m[22mresults[0m
107
108 [1mlfc_endsess ( )[0m
109
110 [1mlfc_endtrans ( )[0m
111
112 [1mlfc_getacl ( string [4m[22mpath[24m[1m, ) ‐> ListOf
113struct lfc_acl [4m[22macls[0m
114
115 [1mlfc_getcomment ( string [4m[22mpath[24m [1m) ‐> string
116[4m[22mcomment[0m
117
118 [1mlfc_getcwd ( ) ‐> string [4m[22mdir[0m
119
120 [1mlfc_getifcevers ( ) ‐> string [4m[22mversion[0m
121
122 [1mlfc_getlinks ( string [4m[22mpath[24m[1m, string
123[4m[22mguid[24m [1m) ‐> ListOf struct lfc_linkinfo[0m
124 [4mlinks[0m
125
126 [1mlfc_getreplica ( string [4m[22mpath[24m[1m, string
127[4m[22mguid[24m[1m, string [4m[22mse[24m [1m) ‐> ListOf struct[0m
128 [1mlfc_filereplica [4m[22mreplicas[0m
129
130 [1mlfc_getreplicas ( ListOfString [4m[22mguids[24m[1m,
131string [4m[22mse[24m [1m) ‐> ListOf struct[0m
132 [1mlfc_filereplicas [4m[22mreplicas[0m
133
134 [1mlfc_getreplicasl ( ListOfString [4m[22mpaths[24m[1m,
135string [4m[22mse[24m [1m) ‐> ListOf struct[0m
136 [1mlfc_filereplicas [4m[22mreplicas[0m
137
138 [1mlfc_getreplicass ( ListOfString [4m[22mpaths[24m[1m,
139) ‐> ListOf struct lfc_fil‐[0m
140 [1mereplicas [4m[22mreplicas[0m
141
142 [1mlfc_getreplicax ( string [4m[22mpath[24m[1m, string
143[4m[22mguid[24m[1m, string [4m[22mse[24m [1m) ‐> ListOf[0m
144 [1mstruct lfc_filereplicax [4m[22mreplicas[0m
145
146 [1mlfc_lchown ( string [4m[22mpath[24m[1m, uid_t
147[4m[22mnew_uid[24m[1m, gid_t [4m[22mnew_gid[24m [1m)[0m
148
149 [1mlfc_listreplicax ( string [4m[22mpoolname[24m[1m,
150string [4m[22mserver[24m[1m, string [4m[22mfs[24m[1m, int[0m
151 [4mflags[24m[1m, lfc_list * listp ) ‐> struct lfc_fil‐
152ereplica [4m[22mreplica[0m
153
154 [1mlfc_listrepset ( string [4m[22msetname[24m[1m, int
155[4m[22mflags[24m[1m, lfc_list *[4m[22mlistp[24m [1m) ‐> struct[0m
156 [1mlfc_filereplicax [4m[22mreplica[0m
157
158 [1mlfc_lstat ( string [4m[22mpath[24m [1m) ‐> struct
159lfc_filestat [4m[22mstatbuf[0m
160
161 [1mlfc_mkdir ( string [4m[22mpath[24m[1m, mode_t
162[4m[22mmode[24m [1m)[0m
163
164 [1mlfc_mkdirg ( string [4m[22mpath[24m[1m, string
165[4m[22mguid[24m[1m, mode_t [4m[22mmode[24m [1m)[0m
166
167 [1mlfc_modreplica ( string [4m[22msfn[24m[1m, string
168[4m[22msetname[24m[1m, string [4m[22mpoolname[24m[1m, string[0m
169 [4mserver[24m [1m)[0m
170
171 [1mlfc_modreplicax ( string [4m[22msfn[24m[1m, string
172[4m[22msetname[24m[1m, string [4m[22mpoolname[24m[1m, string[0m
173 [4mserver[24m[1m, string [4m[22mfs[24m[1m, char
174[4m[22mr_type[24m [1m)[0m
175
176 [1mlfc_opendir ( string [4m[22mpath[24m [1m) ‐> lfc_DIR
177[4m[22mdir[0m
178
179 [1mlfc_opendirg ( string [4m[22mpath[24m[1m, string
180[4m[22mguid[24m [1m) ‐> lfc_DIR [4m[22mdir[0m
181
182 [1mlfc_opendirxg ( string [4m[22mserver[24m[1m, string
183[4m[22mpath[24m[1m, string [4m[22mguid[24m [1m) ‐> lfc_DIR[0m
184 [4mdir[0m
185
186 [1mlfc_ping ( string [4m[22mserver[24m [1m) ‐> string
187[4m[22minfo[0m
188
189 [1mlfc_readdir ( lfc_DIR [4m[22mdirp[24m [1m) ‐> struct
190dirent [4m[22mdirent[0m
191
192 [1mlfc_readdirc ( lfc_DIR [4m[22mdirp[24m [1m) ‐> struct
193lfc_direncomm [4m[22mdirent[0m
194
195 [1mlfc_readdirg ( lfc_DIR [4m[22mdirp[24m [1m) ‐> struct
196lfc_direnstatg [4m[22mdirent[0m
197
198 [1mlfc_readdirx ( lfc_DIR [4m[22mdirp[24m [1m) ‐> struct
199lfc_direnstat [4m[22mdirent[0m
200
201 [1mlfc_readdirxc ( lfc_DIR [4m[22mdirp[24m [1m) ‐> struct
202lfc_direnstatc [4m[22mdirent[0m
203
204 [1mlfc_readdirxp ( lfc_DIR [4m[22mdirp[24m[1m, string
205[4m[22mpattern[24m[1m, string [4m[22mse[24m [1m= None ) ‐>[0m
206 [1mstruct lfc_direnrep [4m[22mdirent[0m
207
208 [1mlfc_readdirxr ( lfc_DIR [4m[22mdirp[24m[1m, string
209[4m[22mse[24m [1m= None ) ‐> struct lfc_direnrep[0m
210 [4mdirent[0m
211
212 [1mlfc_readlink ( string [4m[22mpath[24m [1m) ‐> string
213[4m[22mlink[0m
214
215 [1mlfc_registerfiles ( ListOf struct lfc_filereg
216[4m[22mfiles[24m [1m) ‐> ListOfInt[0m
217 [4mresults[0m
218
219 [1mlfc_rename ( string [4m[22moldpath[24m[1m, string
220[4m[22mnewpath[24m [1m)[0m
221
222 [1mlfc_rewinddir ( lfc_DIR [4m[22mdirp[24m [1m)[0m
223
224 [1mlfc_rmdir ( string [4m[22mpath[24m [1m)[0m
225
226 [1mlfc_setacl ( string [4m[22mpath[24m[1m, ListOf struct
227lfc_acl [4m[22macls[24m [1m)[0m
228
229 [1mlfc_setatime ( string [4m[22mpath[24m[1m, struct
230lfc_fileid [4m[22mfile_uniqueid[24m [1m)[0m
231
232 [1mlfc_setcomment ( string [4m[22mpath[24m[1m, string
233[4m[22mcomment[24m [1m)[0m
234
235 [1mlfc_setfsize ( string [4m[22mpath[24m[1m, struct
236lfc_fileid [4m[22mfile_uniqueid[24m[1m, long [4m[22mfile‐[0m
237 [4msize[24m [1m)[0m
238
239 [1mlfc_setfsizec ( string [4m[22mpath[24m[1m, struct
240lfc_fileid [4m[22mfile_uniqueid[24m[1m, long[0m
241 [4mfilesize[24m[1m, string [4m[22mcsumtype[24m[1m, string
242[4m[22mcsumvalue[24m [1m)[0m
243
244 [1mlfc_setfsizeg ( string [4m[22mguid[24m[1m, long
245[4m[22mfilesize[24m[1m, string [4m[22mcsumtype[24m[1m, string[0m
246 [4mcsumvalue[24m [1m)[0m
247
248 [1mlfc_setptime ( string [4m[22msfn[24m[1m, long [4m[22mp‐
249time[24m [1m)[0m
250
251 [1mlfc_setratime ( string [4m[22msfn[24m [1m)[0m
252
253 [1mlfc_setrltime ( string [4m[22msfn[24m[1m, long
254[4m[22mltime[24m [1m)[0m
255
256 [1mlfc_setrstatus ( string [4m[22msfn[24m[1m, char
257[4m[22mstatus[24m [1m)[0m
258
259 [1mlfc_setrtype ( string [4m[22msfn[24m[1m, char
260[4m[22mtype[24m [1m)[0m
261
262 [1mlfc_startsess ( string [4m[22mserver[24m[1m, string
263[4m[22mcomment[24m [1m)[0m
264
265 [1mlfc_starttrans ( string [4m[22mserver[24m[1m, string
266[4m[22mcomment[24m [1m)[0m
267
268 [1mlfc_stat ( string [4m[22mpath[24m [1m) ‐> struct
269lfc_filestat [4m[22mstatbuf[0m
270
271 [1mlfc_statg ( string [4m[22mpath[24m[1m, string
272[4m[22mguid[24m [1m) ‐> struct lfc_filestatg [4m[22mstatbuf[0m
273
274 [1mlfc_statr ( string [4m[22msfn)[24m [1m) ‐> struct
275lfc_filestatg [4m[22mstatbuf[0m
276
277 [1mlfc_symlink ( string [4m[22mtarget[24m[1m, string
278[4m[22mlinkname[24m [1m)[0m
279
280 [1mlfc_umask ( mode_t [4m[22mcmask[24m [1m) ‐> mode_t
281[4m[22moldmask[0m
282
283 [1mlfc_undelete ( string [4m[22mpath[24m [1m)[0m
284
285 [1mlfc_unlink ( string [4m[22mpath[24m [1m)[0m
286
287 [1mlfc_utime ( string [4m[22mpath[24m[1m, struct utimbuf
288[4m[22mtimes[24m [1m)[0m
289
290 [1mlfc_entergrpmap ( gid_t [4m[22mgid[24m[1m, string
291[4m[22mgroupname[24m [1m)[0m
292
293 [1mlfc_enterusrmap ( uid_t [4m[22muid[24m[1m, string
294[4m[22musername[24m [1m)[0m
295
296 [1mlfc_getgrpbygid ( gid_t [4m[22mgid[24m [1m) ‐> string
297[4m[22mgroup[0m
298
299 [1mlfc_getgrpbygids ( ListOfgid_t [4m[22mgids[24m [1m) ‐>
300ListOfString [4m[22mgroups[0m
301
302 [1mlfc_getgrpbynam ( string [4m[22mgroupname[24m [1m) ‐>
303gid_t [4m[22mgid[0m
304
305 [1mlfc_getgrpmap ( ) ‐> ListOf struct lfc_groupinfo
306[4m[22minfos[0m
307
308 [1mlfc_getidmap ( string [4m[22musername[24m[1m, ListOf‐
309String [4m[22mvo_roles[24m [1m) ‐> uid_t [4m[22muid[24m[1m,[0m
310 [1mListOf gid_t [4m[22mgids[0m
311
312 [1mlfc_getusrbynam ( string [4m[22musername[24m [1m) ‐>
313uid_t [4m[22muid[0m
314
315 [1mlfc_getusrbyuid ( uid_t [4m[22muid[24m [1m) ‐> string
316[4m[22muser[0m
317
318 [1mlfc_getusrmap ( ) ‐> ListOf struct lfc_userinfo
319[4m[22muserinfo[0m
320
321 [1mlfc_modifygrpmap ( gid_t [4m[22mgid[24m[1m, string
322[4m[22mnewname[24m [1m)[0m
323
324 [1mlfc_modifyusrmap ( uid_t [4m[22muid[24m[1m, string
325[4m[22mnewname[24m [1m)[0m
326
327 [1mlfc_rmgrpmap ( gid_t [4m[22mgid[24m[1m, string
328[4m[22mgroupname[24m [1m)[0m
329
330 [1mlfc_rmusrmap ( uid_t [4m[22muid[24m[1m, string
331[4m[22musername[24m [1m)[0m
332
333
334[1mSTRUCTURES[0m
335 Sometimes you need to specify a structure as an input
336argument (eg.
337 [4mstruct[24m [4mlfc_acl[24m, [4mstruct[24m
338[4mlfc_list[24m, etc.). For that purpose, the module
339 includes structure constructors, named exactly as the
340structure.
341
342 Thus, to create [4mstruct[24m [4mlfc_acl[24m or
343[4mstruct[24m [4mlfc_list[24m, you have to do the
344 following:
345
346 lfcacl = lfc.lfc_acl()
347 lfclist = lfc.lfc_list()
348
349 If you want to see how to use it in a real case, please
350have a look at
351 examples.
352
353
354[1mERRORS[0m
355 As you can see, no error code is returned. When an er‐
356ror occurs, an
357 exception is raised with a description of the error.
358
359
360[1mEXAMPLE[0m
361 #!/usr/bin/python
362
363 import sys
364 import traceback
365 import lfc2 as lfc
366
367 """
368 # stat an existing entry in the LFC and print the GUID
369 """
370
371 name = "/grid/dteam/my.test"
372
373 try:
374 stat = lfc.lfc_statg(name,"")
375 except Exception:
376 traceback.print_exc()
377 sys.exit(1)
378
379 guid = stat.guid
380 print "The GUID for " + name + " is " + guid
381
382
383[1mEXAMPLE[0m
384 #!/usr/bin/python
385
386 import sys
387 import traceback
388 import lfc2 as lfc
389
390 """
391 # setting and retrieving a comment on a file
392 """
393
394 file = "/grid/dteam/my.test"
395 comment = "MyComment"
396
397 try:
398 lfc.lfc_setcomment(file,comment)
399
400 comment = lfc.lfc_getcomment(file)
401 print "Read back comment " + comment
402 except Exception:
403 traceback.print_exc()
404 sys.exit(1)
405
406
407[1mEXAMPLE[0m
408 #!/usr/bin/python
409
410 """
411 # Using the lfc_readdirxr method
412 """
413
414 import sys
415 import traceback
416 import lfc2 as lfc
417
418 name = "/grid/dteam/my.test"
419
420 try:
421 dir = lfc.lfc_opendir(name)
422
423 while 1:
424 entry = lfc.lfc_readdirxr(dir)
425 if entry == None:
426 break
427 print entry.d_name
428 for i in range(entry.nbreplicas):
429 print " ==> %s" % entry.rep[i].sfn
430
431 lfc.lfc_closedir(dir)
432 except TypeError, x:
433 print " ==> None"
434 except Exception:
435 traceback.print_exc()
436 sys.exit(1)
437
438
439[1mEXAMPLE[0m
440 #!/usr/bin/python
441
442 import sys
443 import traceback
444 import lfc2 as lfc
445
446 """
447 # Using the lfc_getreplica method
448 """
449
450 file = "/grid/dteam/my.test"
451
452 try:
453 list = lfc.lfc_getreplica(file, "", "")
454 except Exception:
455 traceback.print_exc()
456 sys.exit(1)
457
458 for i in list:
459 print i.host
460 print i.sfn
461
462
463[1mEXAMPLE[0m
464 #!/usr/bin/python
465
466 import sys
467 import traceback
468 import lfc2 as lfc
469
470 """
471 # Using the lfc_getacl and lfc_setacl methods to add a us‐
472er ACL
473 """
474
475 file = "/grid/dteam/my.test"
476
477 try:
478 acls_list = lfc.lfc_getacl(file)
479 except Exception:
480 traceback.print_exc()
481 sys.exit(1)
482
483 for i in acls_list:
484 print i.a_type
485 print i.a_id
486 print i.a_perm
487
488 # When adding a first ACL for a given user, you also need
489to add the mask
490 # When adding the second user ACL, it is not necessary
491anymore
492
493 acl_user = lfc.lfc_acl()
494 acl_mask = lfc.lfc_acl()
495
496 acl_user.a_type = lfc.CNS_ACL_USER
497 acl_user.a_id = 18701 # user id
498 acl_user.a_perm = lfc.S_IROTH | lfc.S_IXOTH
499
500 acl_mask.a_type = lfc.CNS_ACL_MASK
501 acl_mask.a_id = 0 # no user id specified
502 acl_mask.a_perm = lfc.S_IROTH | lfc.S_IXOTH
503
504 acls_list.append(acl_user)
505 acls_list.append(acl_mask)
506
507 try:
508 lfc.lfc_setacl(file, acls_list)
509 except Exception:
510 traceback.print_exc()
511 sys.exit(1)
512
513
514[1mEXAMPLE[0m
515 #!/usr/bin/python
516
517 import sys
518 import traceback
519 import lfc2 as lfc
520
521 """
522 # Using the lfc_getacl and lfc_setacl methods to remove a
523user ACL
524 """
525
526 file = "/grid/dteam/my.test"
527
528 try:
529 acls_list = lfc.lfc_getacl(file)
530 except Exception:
531 traceback.print_exc()
532 sys.exit(1)
533
534 for i in acls_list:
535 print i.a_type
536 print i.a_id
537 print i.a_perm
538
539 del acls_list[1] # delete a given user ACL from the
540list of ACLs
541
542 try:
543 lfc.lfc_setacl(file, acls_list)
544 except Exception:
545 traceback.print_exc()
546 sys.exit(1)
547
548
549[1mEXAMPLE[0m
550 #!/usr/bin/env python
551 import lfc2thr as lfc
552 import os
553 from threading import Thread
554
555 class slave(Thread):
556
557 def __init__ (self):
558 Thread.__init__(self)
559
560 def run(self):
561 ....
562 result = lfc.lfc_getreplica("", guid, "")
563 ....
564 return
565
566 if __name__ == ’__main__’:
567
568 os.environ[’LFC_HOST’] = ’my_lfc.cern.ch’
569
570 # Threaded library initialisation
571 lfc.init()
572
573 ....
574 # Start up of threads
575 for i in xrange(totalNumberOfSlaves):
576 slv = slave(i)
577 slv.start()
578
579 ....
580
581
582[1mEXAMPLE[0m
583 #!/usr/bin/python
584
585 import sys
586 import traceback
587 import lfc2 as lfc
588
589 """
590 # Using the lfc_getusrmap method
591 """
592
593 try:
594 list = lfc.lfc_getusrmap()
595 except Exception:
596 traceback.print_exc()
597 sys.exit(1)
598
599 for i in list:
600 print i.userid + " " + i.username
601
602
603[1mEXAMPLE[0m
604 #!/usr/bin/python
605
606 import sys
607 import traceback
608 import lfc2 as lfc
609
610 """
611 # Using the lfc_getgrpmap method
612 """
613
614 try:
615 list = lfc.lfc_getgrpmap()
616 except Exception:
617 traceback.print_exc()
618 sys.exit(1)
619
620 for i in list:
621 print i.gid + " " + i.groupname
622
623
624[1mEXAMPLE[0m
625 #!/usr/bin/python
626
627 import sys
628 import traceback
629 import lfc2 as lfc
630
631 """
632 # Using the lfc_getidmap method
633 """
634
635 userdn = "user certificate DN"
636 vo_roles = ["dteam"]
637
638 try:
639 uid, gids = lfc.lfc_getidmap (userdn, vo_roles)
640 except Exception:
641 traceback.print_exc()
642 sys.exit(1)
643
644 print "uid=", uid
645 print "gids=", gids
646
647
648[1mSEE ALSO[0m
649 [1mLFC C interface man pages[0m
650
651
652
653LFC $Date$
654lfc2_python(3)
655
656
657
658
659
660