Scroll to navigation

dpm2_python(3) Python Reference dpm2_python(3)

NAME

dpm - Python interface to the DPM
 
 

SYNOPSIS

import dpm2 as dpm
 

DESCRIPTION

The dpm module permits you to access the DPM client interface from python programs. The dpm module is a swig wrapping of the standard C interface. For detailed descriptions of each function see the individual man page of each function.
 

FUNCTIONS

dpns_aborttrans ( )
 
dpns_access ( string path, int amode ) -> bool access
 
dpns_accessr ( string sfn, int amode ) -> bool access
 
dpns_addreplica ( string guid, struct dpns_fileid *file_uniqueid, string server, string sfn, char status, char f_type, string poolname, string fs )
 
dpns_addreplicax ( string guid, struct dpns_fileid *file_uniqueid, string server, string sfn, char status, char f_type, string poolname, string fs, char r_type, string setname )
 
dpns_chdir ( string path )
 
dpns_chmod ( string path, mode_t mode )
 
dpns_chown ( string path, uid_t new_uid, gid_t new_gid )
 
dpns_client_setAuthorizationId ( uid_t uid, gid_t gid, string mech, string id )
 
dpns_client_setVOMS_data ( string voname, stringlist vomsdata )
 
dpns_closedir ( dpns_DIR dirp )
 
dpns_creat ( string path, mode_t mode )
 
dpns_delcomment ( string path )
 
dpns_delete ( string path )
 
dpns_delreplica ( string guid, struct dpns_fileid *file_uniqueid, string sfn )
 
dpns_delreplicasbysfn ( ListOfString sfns, ListOfString guids ) -> ListOfInt results
 
dpns_endsess ( )
 
dpns_endtrans ( )
 
dpns_getacl ( string path, ) -> ListOf struct dpns_acl acls
 
dpns_getcomment ( string path ) -> string comment
 
dpns_getcwd ( ) -> string dir
 
dpns_getifcevers ( ) -> string version
 
dpns_getlinks ( string path, string guid ) -> ListOf struct dpns_linkinfo links
 
dpns_getreplica ( string path, string guid, string se ) -> ListOf struct dpns_filereplica replicas
 
dpns_getreplicax ( string path, string guid, string se ) -> ListOf struct dpns_filereplicax replicas
 
dpns_lchown ( string path, uid_t new_uid, gid_t new_gid )
 
dpns_listreplicax ( string poolname, string server, string fs, int flags, dpns_list * listp ) -> struct dpns_filereplica replica
 
dpns_listrepset ( string setname, int flags, dpns_list *listp ) -> struct dpns_filereplicax replica
 
dpns_lstat ( string path ) -> struct dpns_filestat statbuf
 
dpns_mkdir ( string path, mode_t mode )
 
dpns_modreplica ( string sfn, string setname, string poolname, string server )
 
dpns_modreplicax ( string sfn, string setname, string poolname, string server, string fs, char r_type )
 
dpns_opendir ( string path ) -> dpns_DIR dir
 
dpns_opendirxg ( string server, string path, string guid ) -> dpns_DIR dir
 
dpns_ping ( string server ) -> string info
 
dpns_readdir ( dpns_DIR dirp ) -> struct dirent dirent
 
dpns_readdirc ( dpns_DIR dirp ) -> struct dpns_direncomm dirent
 
dpns_readdirg ( dpns_DIR dirp ) -> struct dpns_direnstatg dirent
 
dpns_readdirx ( dpns_DIR dirp ) -> struct dpns_direnstat dirent
 
dpns_readdirxc ( dpns_DIR dirp ) -> struct dpns_direnstatc dirent
 
dpns_readdirxp ( dpns_DIR dirp, string pattern, string se = None ) -> struct dpns_direnrep dirent
 
dpns_readdirxr ( dpns_DIR dirp, string se = None ) -> struct dpns_direnrep dirent
 
dpns_readlink ( string path ) -> string link
 
dpns_rename ( string oldpath, string newpath )
 
dpns_rewinddir ( dpns_DIR dirp )
 
dpns_rmdir ( string path )
 
dpns_setacl ( string path, ListOf struct dpns_acl acls )
 
dpns_setatime ( string path, struct dpns_fileid file_uniqueid )
 
dpns_setcomment ( string path, string comment )
 
dpns_setfsize ( string path, struct dpns_fileid file_uniqueid, long filesize )
 
dpns_setfsizec ( string path, struct dpns_fileid file_uniqueid, long filesize, string csumtype, string csumvalue )
 
dpns_setptime ( string sfn, long ptime )
 
dpns_setratime ( string sfn )
 
dpns_setrltime ( string sfn, long ltime )
 
dpns_setrstatus ( string sfn, char status )
 
dpns_setrtype ( string sfn, char type )
 
dpns_startsess ( string server, string comment )
 
dpns_starttrans ( string server, string comment )
 
dpns_stat ( string path ) -> struct dpns_filestat statbuf
 
dpns_statg ( string path, string guid ) -> struct dpns_filestatg statbuf
 
dpns_statr ( string sfn) ) -> struct dpns_filestatg statbuf
 
dpns_symlink ( string target, string linkname )
 
dpns_umask ( mode_t cmask ) -> mode_t oldmask
 
dpns_undelete ( string path )
 
dpns_unlink ( string path )
 
dpns_utime ( string path, struct utimbuf times )
 
dpns_entergrpmap ( gid_t gid, string groupname )
 
dpns_enterusrmap ( uid_t uid, string username )
 
dpns_getgrpbygid ( gid_t gid ) -> string group
 
dpns_getgrpbygids ( ListOfgid_t gids ) -> ListOfString groups
 
dpns_getgrpbynam ( string groupname ) -> gid_t gid
 
dpns_getgrpmap ( ) -> ListOf struct dpns_groupinfo infos
 
dpns_getusrbynam ( string username ) -> uid_t uid
 
dpns_getusrbyuid ( uid_t uid ) -> string user
 
dpns_getusrmap ( ) -> ListOf struct dpns_userinfo userinfo
 
dpns_modifygrpmap ( gid_t gid, string newname )
 
dpns_modifyusrmap ( uid_t uid, string newname )
 
dpns_rmgrpmap ( gid_t gid, string groupname )
 
dpns_rmusrmap ( uid_t uid, string username )
 
dpm_getpoolfs ( string poolname ) -> ListOf struct dpm_fs dpm_fs
 
dpm_getpools ( ) -> ListOf struct dpm_pool dpm_pools
 
dpm_getprotocols ( ) -> ListOfString protocols
 
dpm_getspacemd ( ListOfString s_tokens ) -> ListOf struct dpm_space_metadata spacemd
 
dpm_getspacetoken ( string u_token ) -> ListOfString s_tokens
 
dpm_addfs ( string poolname, string server, string fs, int status )
 
dpm_addpool ( struct dpm_pool dpm_pool )
 
dpm_delreplica ( string pfn )
 
dpm_modifyfs ( string server, string fs, int status )
 
dpm_modifypool ( struct dpm_pool dpm_pool )
 
dpm_ping ( string host ) -> string info
 
dpm_releasespace ( string s_token, int force )
 
dpm_reservespace ( char s_type, string u_token, char ret_policy, char ac_latency, long req_t_space, long req_g_space, long req_lifetime, ListOfInt gids, string poolname ) -> char actual_s_type, long actual_t_space, long actual_g_space, long actual_lifetime, string s_token
 
dpm_rmfs ( string server, string fs )
 
dpm_rmpool ( string poolname )
 
dpm_updatespace ( string s_token, long req_t_space, long req_g_space, long req_lifetime, ListOfInt gids ) -> long actual_t_space, long actual_g_space, long actual_lifetime
 

STRUCTURES

Sometimes you need to specify a structure as an input argument (eg. struct dpns_acl, struct dpns_list, struct dpm_pool, etc.). For that purpose, the module includes structure constructors, named exactly as the structure.
 
Thus, to create struct dpns_acl, struct dpns_list or struct dpmm_pool, you have to do the following:
 
    dpnsacl = dpm.dpns_acl()
    dpnslist = dpm.dpns_list()
    dpmpool = dpm.dpm_pool()
 
If you want to see how to use it in a real case, please have a look at examples.
 

ERRORS

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

EXAMPLE

#!/usr/bin/python
""" # Using the dpns_readdirxr method """
import sys import traceback import dpm2 as dpm
name = "/dpm/cern.ch/home/dteam/";
try: dir = dpm.dpns_opendir(name)
while 1: entry = dpm.dpns_readdirxr(dir) if entry == None: break print entry.d_name for i in range(entry.nbreplicas): print " ==> %s" % entry.rep[i].sfn
dpm.dpns_closedir(dir) except TypeError, x: print " ==> None" except Exception: traceback.print_exc() sys.exit(1)

EXAMPLE

#!/usr/bin/python
import sys import traceback import dpm2 as dpm
""" # Using the dpns_getreplica method """
file = "/dpm/cern.ch/home/dteam/file.test"
try: list = dpm.dpns_getreplica(file, "", "") except Exception: traceback.print_exc() sys.exit(1)
for i in list: print i.host print i.sfn

EXAMPLE

#!/usr/bin/python
import sys import traceback import dpm2 as dpm
""" # Using the dpns_getacl and dpns_setacl methods to add a user ACL """
file = "/dpm/cern.ch/home/dteam/file.test"
try: acls_list = dpm.dpns_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 = dpm.dpns_acl() acl_mask = dpm.dpns_acl()
acl_user.a_type = lfc.CNS_ACL_USER acl_user.a_id = 18701 # user id acl_user.a_perm = 5
acl_mask.a_type = lfc.CNS_ACL_MASK acl_mask.a_id = 0 # no user id specified acl_mask.a_perm = 5
acls_list.append(acl_user) acls_list.append(acl_mask)
try: dpm.dpns_setacl(file, acls_list) except Exception: traceback.print_exc() sys.exit(1)

EXAMPLE

#!/usr/bin/python
import sys import traceback import dpm2 as dpm
""" # Using the dpns_getacl and dpns_setacl methods to remove a user ACL """
file = "/dpm/cern.ch/home/dteam/file.test"
try: acls_list = dpm.dpns_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: dpm.dpns_setacl(file, acls_list) except Exception: traceback.print_exc() sys.exit(1)

EXAMPLE

#!/usr/bin/python
import sys import traceback import dpm2 as dpm
""" # Using the dpns_getusrmap method """
try: list = dpm.dpns_getusrmap() except Exception: traceback.print_exc() sys.exit(1)
for i in list: print i.userid + " " + i.username

EXAMPLE

#!/usr/bin/python
import sys import traceback import dpm2 as dpm
""" # Using the dpns_getgrpmap method """
try: list = dpm.dpns_getgrpmap() except Exception: traceback.print_exc() sys.exit(1) for i in list: print i.gid + " " + i.groupname

EXAMPLE

#!/usr/bin/python
import sys import traceback import dpm2 as dpm
""" # Using the dpm_addfs method """
try: dpm.dpm_addfs("mypool", "mydiskserver.domain.com", "/mountpoint", \ dpm.FS_READONLY) except Exception: traceback.print_exc() sys.exit(1)

EXAMPLE

#!/usr/bin/python
import sys import traceback import dpm2 as dpm
""" # Using the dpm_modifyfs method """
try: dpm.dpm_modifyfs("mydiskserver.domain.com", "/mountpoint", \ dpm.FS_READONLY) except Exception: traceback.print_exc() sys.exit(1)

EXAMPLE

#!/usr/bin/python
import sys import traceback import dpm2 as dpm
""" # Using the dpm_rmfs method """
try: dpm.dpm_rmfs("mypool", "mydiskserver.domain.com", "/mountpoint") except Exception: traceback.print_exc() sys.exit(1)

EXAMPLE

#!/usr/bin/python
import sys import traceback import dpm2 as dpm
""" # Using the dpm_addpool method """
dpmpool = dpm.dpm_pool() dpmpool.poolname = "mypool" dpmpool.defsize = 209715200 dpmpool.def_lifetime = 604800 dpmpool.defpintime = 604800 dpmpool.max_lifetime = 604800 dpmpool.max_pintime = 604800 dpmpool.nbgids = 1 dpmpool.gids = [0] dpmpool.ret_policy = 'R' dpmpool.s_type = 'D'
try: dpm.dpm_addpool(dpmpool) except Exception: traceback.print_exc() sys.exit(1)

EXAMPLE

#!/usr/bin/python
import sys import traceback import dpm2 as dpm
""" # Using the dpm_modifypool method """
dpmpool = dpm.dpm_pool() dpmpool.poolname = "mypool" dpmpool.defsize = 209715200 dpmpool.def_lifetime = 604800 dpmpool.defpintime = 604800 dpmpool.max_lifetime = 604800 dpmpool.max_pintime = 604800 dpmpool.nbgids = 1 dpmpool.gids = [0] dpmpool.ret_policy = 'R' dpmpool.s_type = 'D'
try: dpm.dpm_modifypool(dpmpool) except Exception: traceback.print_exc() sys.exit(1)

EXAMPLE

#!/usr/bin/python
import sys import traceback import dpm2 as dpm
""" # Using the dpm_rmpool method """
try: dpm.dpm_rmpool("mypool") except Exception: traceback.print_exc() sys.exit(1)

EXAMPLE

#!/usr/bin/python
import sys import traceback import dpm2 as dpm
""" # Using the dpm_getpoolfs method """
try: list = dpm.dpm_getpoolfs("mypool") except Exception: traceback.print_exc() sys.exit(1)
print len(list) for i in list: print "POOL " + i.poolname + " SERVER " + i.server + " FS " + i.fs \ + " CAPACITY " + i.capacity + " FREE " + i.free

EXAMPLE

#!/usr/bin/python
import sys import traceback import dpm2 as dpm
""" # Using the dpm_getpools method """
try: list = dpm.dpm_getpools() except Exception: traceback.print_exc() sys.exit(1)
print len(list) for i in list: print "POOL " + i.poolname + " CAPACITY " + i.capacity + " FREE " + i.free

EXAMPLE

#!/usr/bin/python
import sys import traceback import dpm2 as dpm
""" # Using the dpm_getprotocols method """
try: list = dpm.dpm_getprotocols() except Exception: traceback.print_exc() sys.exit(1)
print len(list) for i in list: print i

EXAMPLE

#!/usr/bin/python
import sys import traceback import dpm2 as dpm
""" # Using the dpm_getspacemd method """
try: list = dpm.dpm_getspacemd(["myspacetoken"]) except Exception: traceback.print_exc() sys.exit(1)
print len(list) for i in list: print "TYPE " + i.s_type + " SPACETOKEN " i.s_token + " USERTOKEN " \ + i.u_token + " TOTAL " + i.t_space + " GUARANTUEED " + i.g_space \ + " UNUSED " + i.u_space + " POOL " + i.poolname

EXAMPLE

#!/usr/bin/python
import sys import traceback import dpm2 as dpm
""" # Using the dpm_getspacetoken method """
try: list = dpm.dpm_getspacetoken("myspacetokendesc") except Exception: traceback.print_exc() sys.exit(1)
print len(list) for i in list: print i

EXAMPLE

#!/usr/bin/python
import sys import traceback import dpm2 as dpm
""" # Using the dpm_reservespace method """
try: actual_s_type,actual_t_space,actual_g_space,actual_lifetime,s_token = \ dpm.dpm_reservespace('D', "myspacetokendesc", 'R', 'O', 209715200, \ 209715200, 2592000, 0, "mypoolname") except Exception: traceback.print_exc() sys.exit(1)
print "TYPE " + actual_s_type + " TOTAL " + actual_t_space + " GUARANTEED " \ + actual_g_space + " LIFETIME " + actual_lifetime + " TOKEN " + s_token

EXAMPLE

#!/usr/bin/python
import sys import traceback import dpm2 as dpm
""" # Using the dpm_updatespace method """
try: actual_t_space,actual_g_space,actual_lifetime = \ dpm.dpm_updatespace("myspacetoken", 209715200, 209715200, 2592000) except Exception: traceback.print_exc() sys.exit(1)
print " TOTAL " + actual_t_space + " GUARANTEED " + actual_g_space \ + " LIFETIME " + actual_lifetime

EXAMPLE

#!/usr/bin/python
import sys import traceback import dpm2 as dpm
""" # Using the dpm_releasespace method """
try: dpm.dpm_releasespace("myspacetoken", 0) except Exception: traceback.print_exc() sys.exit(1)

EXAMPLE

#!/usr/bin/python
import sys import traceback import dpm2 as dpm
""" # Using the dpm_ping method """
try: info = dpm.dpm_ping("mydpmserver.domain.com") except Exception: traceback.print_exc() sys.exit(1)
print info

SEE ALSO

DPM C interface man pages
$Date: 2010-12-14 08:31:05 +0100 (Tue, 14 Dec 2010) $ DPM