lfc2_python man page

lfc2_python(3) Python Reference lfc2_python(3)

[1mNAME[0m
lfc2 - New python interface to the LFC client API
lfc2thr - Thread enabled version of Python interface to the LFC

[1mSYNOPSIS[0m
[1mimport lfc2 as lfc[0m

[1mimport lfc2thr as lfc[0m
[1mlfc.init()[0m

[1mDESCRIPTION[0m
The lfc module permits you to access the LFC client interface from
python programs. The lfc module is a swig wrapping of the standard C
interface. For detailed descriptions of each function see the individ-
ual man page of each function.

The lfcthr module is a version of the lfc module supporting multi-
threaded Python clients. Its usage is similar to the usage of the lfc
module except the obligatory initialisation call lfcthr.init() in the
main program before threads are started.

[1mFUNCTIONS[0m
[1mlfc_aborttrans ( )[0m

[1mlfc_access ( string [4m[22mpath[24m[1m, int [4m[22mamode[24m [1m) -> bool [4m[22maccess[0m

[1mlfc_accessr ( string [4m[22msfn[24m[1m, int [4m[22mamode[24m [1m) -> bool [4m[22maccess[0m

[1mlfc_addreplica ( string [4m[22mguid[24m[1m, struct lfc_fileid *[4m[22mfile_uniqueid[24m[1m, string[0m
[4mserver[24m[1m, string [4m[22msfn[24m[1m, char [4m[22mstatus[24m[1m, char [4m[22mf_type[24m[1m, string [4m[22mpoolname[24m[1m, string[0m
[4mfs[24m [1m)[0m

[1mlfc_addreplicax ( string [4m[22mguid[24m[1m, struct lfc_fileid *[4m[22mfile_uniqueid[24m[1m, string[0m
[4mserver[24m[1m, string [4m[22msfn[24m[1m, char [4m[22mstatus[24m[1m, char [4m[22mf_type[24m[1m, string [4m[22mpoolname[24m[1m, string[0m
[4mfs[24m[1m, char [4m[22mr_type[24m[1m, string [4m[22msetname[24m [1m)[0m

[1mlfc_chdir ( string [4m[22mpath[24m [1m)[0m

[1mlfc_chmod ( string [4m[22mpath[24m[1m, mode_t [4m[22mmode[24m [1m)[0m

[1mlfc_chown ( string [4m[22mpath[24m[1m, uid_t [4m[22mnew_uid[24m[1m, gid_t [4m[22mnew_gid[24m [1m)[0m

[1mlfc_client_setAuthorizationId ( uid_t [4m[22muid[24m[1m, gid_t [4m[22mgid[24m[1m, string [4m[22mmech[24m[1m,[0m
[1mstring [4m[22mid[24m [1m)[0m

[1mlfc_client_setVOMS_data ( string [4m[22mvoname[24m[1m, stringlist [4m[22mvomsdata[24m [1m)[0m

[1mlfc_closedir ( lfc_DIR [4m[22mdirp[24m [1m)[0m

[1mlfc_creatg ( string [4m[22mpath[24m[1m, string [4m[22mguid[24m[1m, mode_t [4m[22mmode[24m [1m)[0m

[1mlfc_delcomment ( string [4m[22mpath[24m [1m)[0m

[1mlfc_delete ( string [4m[22mpath[24m [1m)[0m

[1mlfc_delfilesbyguid ( ListOfString [4m[22mguids[24m[1m, int [4m[22mforce[24m [1m) -> ListOfInt[0m
[4mresult[0m

[1mlfc_delfilesbyname ( ListOfString [4m[22mnames[24m[1m, int[4m[22mforce[24m [1m) -> ListOfInt[0m
[4mresults[0m

[1mlfc_delfilesbypattern ( string [4m[22mpath[24m[1m, string [4m[22mpattern[24m[1m, int [4m[22mforce[24m [1m) ->[0m
[1mListOf struct lfc_filestatus [4m[22mresults[0m

[1mlfc_delreplica ( string [4m[22mguid[24m[1m, struct lfc_fileid *[4m[22mfile_uniqueid[24m[1m, string[0m
[4msfn[24m [1m)[0m

[1mlfc_delreplicas ( ListOfString [4m[22msfns[24m[1m, string [4m[22mse[24m [1m) -> ListOfInt [4m[22mresults[0m

[1mlfc_delreplicasbysfn ( ListOfString [4m[22msfns[24m[1m, ListOfString [4m[22mguids[24m [1m) ->[0m
[1mListOfInt [4m[22mresults[0m

[1mlfc_endsess ( )[0m

[1mlfc_endtrans ( )[0m

[1mlfc_getacl ( string [4m[22mpath[24m[1m, ) -> ListOf struct lfc_acl [4m[22macls[0m

[1mlfc_getcomment ( string [4m[22mpath[24m [1m) -> string [4m[22mcomment[0m

[1mlfc_getcwd ( ) -> string [4m[22mdir[0m

[1mlfc_getifcevers ( ) -> string [4m[22mversion[0m

[1mlfc_getlinks ( string [4m[22mpath[24m[1m, string [4m[22mguid[24m [1m) -> ListOf struct lfc_linkinfo[0m
[4mlinks[0m

[1mlfc_getreplica ( string [4m[22mpath[24m[1m, string [4m[22mguid[24m[1m, string [4m[22mse[24m [1m) -> ListOf struct[0m
[1mlfc_filereplica [4m[22mreplicas[0m

[1mlfc_getreplicas ( ListOfString [4m[22mguids[24m[1m, string [4m[22mse[24m [1m) -> ListOf struct[0m
[1mlfc_filereplicas [4m[22mreplicas[0m

[1mlfc_getreplicasl ( ListOfString [4m[22mpaths[24m[1m, string [4m[22mse[24m [1m) -> ListOf struct[0m
[1mlfc_filereplicas [4m[22mreplicas[0m

[1mlfc_getreplicass ( ListOfString [4m[22mpaths[24m[1m, ) -> ListOf struct lfc_fil-[0m
[1mereplicas [4m[22mreplicas[0m

[1mlfc_getreplicax ( string [4m[22mpath[24m[1m, string [4m[22mguid[24m[1m, string [4m[22mse[24m [1m) -> ListOf[0m
[1mstruct lfc_filereplicax [4m[22mreplicas[0m

[1mlfc_lchown ( string [4m[22mpath[24m[1m, uid_t [4m[22mnew_uid[24m[1m, gid_t [4m[22mnew_gid[24m [1m)[0m

[1mlfc_listreplicax ( string [4m[22mpoolname[24m[1m, string [4m[22mserver[24m[1m, string [4m[22mfs[24m[1m, int[0m
[4mflags[24m[1m, lfc_list * listp ) -> struct lfc_filereplica [4m[22mreplica[0m

[1mlfc_listrepset ( string [4m[22msetname[24m[1m, int [4m[22mflags[24m[1m, lfc_list *[4m[22mlistp[24m [1m) -> struct[0m
[1mlfc_filereplicax [4m[22mreplica[0m

[1mlfc_lstat ( string [4m[22mpath[24m [1m) -> struct lfc_filestat [4m[22mstatbuf[0m

[1mlfc_mkdir ( string [4m[22mpath[24m[1m, mode_t [4m[22mmode[24m [1m)[0m

[1mlfc_mkdirg ( string [4m[22mpath[24m[1m, string [4m[22mguid[24m[1m, mode_t [4m[22mmode[24m [1m)[0m

[1mlfc_modreplica ( string [4m[22msfn[24m[1m, string [4m[22msetname[24m[1m, string [4m[22mpoolname[24m[1m, string[0m
[4mserver[24m [1m)[0m

[1mlfc_modreplicax ( string [4m[22msfn[24m[1m, string [4m[22msetname[24m[1m, string [4m[22mpoolname[24m[1m, string[0m
[4mserver[24m[1m, string [4m[22mfs[24m[1m, char [4m[22mr_type[24m [1m)[0m

[1mlfc_opendir ( string [4m[22mpath[24m [1m) -> lfc_DIR [4m[22mdir[0m

[1mlfc_opendirg ( string [4m[22mpath[24m[1m, string [4m[22mguid[24m [1m) -> lfc_DIR [4m[22mdir[0m

[1mlfc_opendirxg ( string [4m[22mserver[24m[1m, string [4m[22mpath[24m[1m, string [4m[22mguid[24m [1m) -> lfc_DIR[0m
[4mdir[0m

[1mlfc_ping ( string [4m[22mserver[24m [1m) -> string [4m[22minfo[0m

[1mlfc_readdir ( lfc_DIR [4m[22mdirp[24m [1m) -> struct dirent [4m[22mdirent[0m

[1mlfc_readdirc ( lfc_DIR [4m[22mdirp[24m [1m) -> struct lfc_direncomm [4m[22mdirent[0m

[1mlfc_readdirg ( lfc_DIR [4m[22mdirp[24m [1m) -> struct lfc_direnstatg [4m[22mdirent[0m

[1mlfc_readdirx ( lfc_DIR [4m[22mdirp[24m [1m) -> struct lfc_direnstat [4m[22mdirent[0m

[1mlfc_readdirxc ( lfc_DIR [4m[22mdirp[24m [1m) -> struct lfc_direnstatc [4m[22mdirent[0m

[1mlfc_readdirxp ( lfc_DIR [4m[22mdirp[24m[1m, string [4m[22mpattern[24m[1m, string [4m[22mse[24m [1m= None ) ->[0m
[1mstruct lfc_direnrep [4m[22mdirent[0m

[1mlfc_readdirxr ( lfc_DIR [4m[22mdirp[24m[1m, string [4m[22mse[24m [1m= None ) -> struct lfc_direnrep[0m
[4mdirent[0m

[1mlfc_readlink ( string [4m[22mpath[24m [1m) -> string [4m[22mlink[0m

[1mlfc_registerfiles ( ListOf struct lfc_filereg [4m[22mfiles[24m [1m) -> ListOfInt[0m
[4mresults[0m

[1mlfc_rename ( string [4m[22moldpath[24m[1m, string [4m[22mnewpath[24m [1m)[0m

[1mlfc_rewinddir ( lfc_DIR [4m[22mdirp[24m [1m)[0m

[1mlfc_rmdir ( string [4m[22mpath[24m [1m)[0m

[1mlfc_setacl ( string [4m[22mpath[24m[1m, ListOf struct lfc_acl [4m[22macls[24m [1m)[0m

[1mlfc_setatime ( string [4m[22mpath[24m[1m, struct lfc_fileid [4m[22mfile_uniqueid[24m [1m)[0m

[1mlfc_setcomment ( string [4m[22mpath[24m[1m, string [4m[22mcomment[24m [1m)[0m

[1mlfc_setfsize ( string [4m[22mpath[24m[1m, struct lfc_fileid [4m[22mfile_uniqueid[24m[1m, long [4m[22mfile-[0m
[4msize[24m [1m)[0m

[1mlfc_setfsizec ( string [4m[22mpath[24m[1m, struct lfc_fileid [4m[22mfile_uniqueid[24m[1m, long[0m
[4mfilesize[24m[1m, string [4m[22mcsumtype[24m[1m, string [4m[22mcsumvalue[24m [1m)[0m

[1mlfc_setfsizeg ( string [4m[22mguid[24m[1m, long [4m[22mfilesize[24m[1m, string [4m[22mcsumtype[24m[1m, string[0m
[4mcsumvalue[24m [1m)[0m

[1mlfc_setptime ( string [4m[22msfn[24m[1m, long [4m[22mptime[24m [1m)[0m

[1mlfc_setratime ( string [4m[22msfn[24m [1m)[0m

[1mlfc_setrltime ( string [4m[22msfn[24m[1m, long [4m[22mltime[24m [1m)[0m

[1mlfc_setrstatus ( string [4m[22msfn[24m[1m, char [4m[22mstatus[24m [1m)[0m

[1mlfc_setrtype ( string [4m[22msfn[24m[1m, char [4m[22mtype[24m [1m)[0m

[1mlfc_startsess ( string [4m[22mserver[24m[1m, string [4m[22mcomment[24m [1m)[0m

[1mlfc_starttrans ( string [4m[22mserver[24m[1m, string [4m[22mcomment[24m [1m)[0m

[1mlfc_stat ( string [4m[22mpath[24m [1m) -> struct lfc_filestat [4m[22mstatbuf[0m

[1mlfc_statg ( string [4m[22mpath[24m[1m, string [4m[22mguid[24m [1m) -> struct lfc_filestatg [4m[22mstatbuf[0m

[1mlfc_statr ( string [4m[22msfn)[24m [1m) -> struct lfc_filestatg [4m[22mstatbuf[0m

[1mlfc_symlink ( string [4m[22mtarget[24m[1m, string [4m[22mlinkname[24m [1m)[0m

[1mlfc_umask ( mode_t [4m[22mcmask[24m [1m) -> mode_t [4m[22moldmask[0m

[1mlfc_undelete ( string [4m[22mpath[24m [1m)[0m

[1mlfc_unlink ( string [4m[22mpath[24m [1m)[0m

[1mlfc_utime ( string [4m[22mpath[24m[1m, struct utimbuf [4m[22mtimes[24m [1m)[0m

[1mlfc_entergrpmap ( gid_t [4m[22mgid[24m[1m, string [4m[22mgroupname[24m [1m)[0m

[1mlfc_enterusrmap ( uid_t [4m[22muid[24m[1m, string [4m[22musername[24m [1m)[0m

[1mlfc_getgrpbygid ( gid_t [4m[22mgid[24m [1m) -> string [4m[22mgroup[0m

[1mlfc_getgrpbygids ( ListOfgid_t [4m[22mgids[24m [1m) -> ListOfString [4m[22mgroups[0m

[1mlfc_getgrpbynam ( string [4m[22mgroupname[24m [1m) -> gid_t [4m[22mgid[0m

[1mlfc_getgrpmap ( ) -> ListOf struct lfc_groupinfo [4m[22minfos[0m

[1mlfc_getidmap ( string [4m[22musername[24m[1m, ListOfString [4m[22mvo_roles[24m [1m) -> uid_t [4m[22muid[24m[1m,[0m
[1mListOf gid_t [4m[22mgids[0m

[1mlfc_getusrbynam ( string [4m[22musername[24m [1m) -> uid_t [4m[22muid[0m

[1mlfc_getusrbyuid ( uid_t [4m[22muid[24m [1m) -> string [4m[22muser[0m

[1mlfc_getusrmap ( ) -> ListOf struct lfc_userinfo [4m[22muserinfo[0m

[1mlfc_modifygrpmap ( gid_t [4m[22mgid[24m[1m, string [4m[22mnewname[24m [1m)[0m

[1mlfc_modifyusrmap ( uid_t [4m[22muid[24m[1m, string [4m[22mnewname[24m [1m)[0m

[1mlfc_rmgrpmap ( gid_t [4m[22mgid[24m[1m, string [4m[22mgroupname[24m [1m)[0m

[1mlfc_rmusrmap ( uid_t [4m[22muid[24m[1m, string [4m[22musername[24m [1m)[0m

[1mSTRUCTURES[0m
Sometimes you need to specify a structure as an input argument (eg.
[4mstruct[24m [4mlfc_acl[24m, [4mstruct[24m [4mlfc_list[24m, etc.). For that purpose, the module
includes structure constructors, named exactly as the structure.

Thus, to create [4mstruct[24m [4mlfc_acl[24m or [4mstruct[24m [4mlfc_list[24m, you have to do the
following:

lfcacl = lfc.lfc_acl()
lfclist = lfc.lfc_list()

If you want to see how to use it in a real case, please have a look at
examples.

[1mERRORS[0m
As you can see, no error code is returned. When an error occurs, an
exception is raised with a description of the error.

[1mEXAMPLE[0m
#!/usr/bin/python

import sys
import traceback
import lfc2 as lfc

"""
# stat an existing entry in the LFC and print the GUID
"""

name = "/grid/dteam/my.test"

try:
stat = lfc.lfc_statg(name,"")
except Exception:
traceback.print_exc()
sys.exit(1)

guid = stat.guid
print "The GUID for " + name + " is " + guid

[1mEXAMPLE[0m
#!/usr/bin/python

import sys
import traceback
import lfc2 as lfc

"""
# setting and retrieving a comment on a file
"""

file = "/grid/dteam/my.test"
comment = "MyComment"

try:
lfc.lfc_setcomment(file,comment)

comment = lfc.lfc_getcomment(file)
print "Read back comment " + comment
except Exception:
traceback.print_exc()
sys.exit(1)

[1mEXAMPLE[0m
#!/usr/bin/python

"""
# Using the lfc_readdirxr method
"""

import sys
import traceback
import lfc2 as lfc

name = "/grid/dteam/my.test"

try:
dir = lfc.lfc_opendir(name)

while 1:
entry = lfc.lfc_readdirxr(dir)
if entry == None:
break
print entry.d_name
for i in range(entry.nbreplicas):
print " ==> %s" % entry.rep[i].sfn

lfc.lfc_closedir(dir)
except TypeError, x:
print " ==> None"
except Exception:
traceback.print_exc()
sys.exit(1)

[1mEXAMPLE[0m
#!/usr/bin/python

import sys
import traceback
import lfc2 as lfc

"""
# Using the lfc_getreplica method
"""

file = "/grid/dteam/my.test"

try:
list = lfc.lfc_getreplica(file, "", "")
except Exception:
traceback.print_exc()
sys.exit(1)

for i in list:
print i.host
print i.sfn

[1mEXAMPLE[0m
#!/usr/bin/python

import sys
import traceback
import lfc2 as lfc

"""
# Using the lfc_getacl and lfc_setacl methods to add a user ACL
"""

file = "/grid/dteam/my.test"

try:
acls_list = lfc.lfc_getacl(file)
except Exception:
traceback.print_exc()
sys.exit(1)

for i in acls_list:
print i.a_type
print i.a_id
print i.a_perm

# When adding a first ACL for a given user, you also need to add the mask
# When adding the second user ACL, it is not necessary anymore

acl_user = lfc.lfc_acl()
acl_mask = lfc.lfc_acl()

acl_user.a_type = lfc.CNS_ACL_USER
acl_user.a_id = 18701 # user id
acl_user.a_perm = lfc.S_IROTH | lfc.S_IXOTH

acl_mask.a_type = lfc.CNS_ACL_MASK
acl_mask.a_id = 0 # no user id specified
acl_mask.a_perm = lfc.S_IROTH | lfc.S_IXOTH

acls_list.append(acl_user)
acls_list.append(acl_mask)

try:
lfc.lfc_setacl(file, acls_list)
except Exception:
traceback.print_exc()
sys.exit(1)

[1mEXAMPLE[0m
#!/usr/bin/python

import sys
import traceback
import lfc2 as lfc

"""
# Using the lfc_getacl and lfc_setacl methods to remove a user ACL
"""

file = "/grid/dteam/my.test"

try:
acls_list = lfc.lfc_getacl(file)
except Exception:
traceback.print_exc()
sys.exit(1)

for i in acls_list:
print i.a_type
print i.a_id
print i.a_perm

del acls_list[1] # delete a given user ACL from the list of ACLs

try:
lfc.lfc_setacl(file, acls_list)
except Exception:
traceback.print_exc()
sys.exit(1)

[1mEXAMPLE[0m
#!/usr/bin/env python
import lfc2thr as lfc
import os
from threading import Thread

class slave(Thread):

def __init__ (self):
Thread.__init__(self)

def run(self):
....
result = lfc.lfc_getreplica("", guid, "")
....
return

if __name__ == '__main__':

os.environ['LFC_HOST'] = 'my_lfc.cern.ch'

# Threaded library initialisation
lfc.init()

....
# Start up of threads
for i in xrange(totalNumberOfSlaves):
slv = slave(i)
slv.start()

....

[1mEXAMPLE[0m
#!/usr/bin/python

import sys
import traceback
import lfc2 as lfc

"""
# Using the lfc_getusrmap method
"""

try:
list = lfc.lfc_getusrmap()
except Exception:
traceback.print_exc()
sys.exit(1)

for i in list:
print i.userid + " " + i.username

[1mEXAMPLE[0m
#!/usr/bin/python

import sys
import traceback
import lfc2 as lfc

"""
# Using the lfc_getgrpmap method
"""

try:
list = lfc.lfc_getgrpmap()
except Exception:
traceback.print_exc()
sys.exit(1)

for i in list:
print i.gid + " " + i.groupname

[1mEXAMPLE[0m
#!/usr/bin/python

import sys
import traceback
import lfc2 as lfc

"""
# Using the lfc_getidmap method
"""

userdn = "user certificate DN"
vo_roles = ["dteam"]

try:
uid, gids = lfc.lfc_getidmap (userdn, vo_roles)
except Exception:
traceback.print_exc()
sys.exit(1)

print "uid=", uid
print "gids=", gids

[1mSEE ALSO[0m
[1mLFC C interface man pages[0m

LFC $Date: 2010-12-14 08:31:05 +0100 (Tue, 14 Dec 2010)l$fc2_python(3)

Info