---
name: "dpm2_python"
section: "3"
platform: "linux"
package: "python-dpm"
version: "1.10.0-2+b3"
release: "Debian 10 (Buster)"
platforms: ["linux"]
url: "https://new.carta.tech/dpm2_python"
---

# dpm2\_python(3)

Python interface to the DPM

## 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**
