1dpm2_python(3) Python Reference dpm2_python(3)
2
3
4
6 dpm - Python interface to the DPM
7
8
10 import dpm2 as dpm
11
12
14 The dpm module permits you to access the DPM client interface from
15 python programs. The dpm module is a swig wrapping of the standard C
16 interface. For detailed descriptions of each function see the individ‐
17 ual man page of each function.
18
19
21 dpns_aborttrans ( )
22
23 dpns_access ( string path, int amode ) -> bool access
24
25 dpns_accessr ( string sfn, int amode ) -> bool access
26
27 dpns_addreplica ( string guid, struct dpns_fileid *file_uniqueid,
28 string server, string sfn, char status, char f_type, string poolname,
29 string fs )
30
31 dpns_addreplicax ( string guid, struct dpns_fileid *file_uniqueid,
32 string server, string sfn, char status, char f_type, string poolname,
33 string fs, char r_type, string setname )
34
35 dpns_chdir ( string path )
36
37 dpns_chmod ( string path, mode_t mode )
38
39 dpns_chown ( string path, uid_t new_uid, gid_t new_gid )
40
41 dpns_client_setAuthorizationId ( uid_t uid, gid_t gid, string mech,
42 string id )
43
44 dpns_client_setVOMS_data ( string voname, stringlist vomsdata )
45
46 dpns_closedir ( dpns_DIR dirp )
47
48 dpns_creat ( string path, mode_t mode )
49
50 dpns_delcomment ( string path )
51
52 dpns_delete ( string path )
53
54 dpns_delreplica ( string guid, struct dpns_fileid *file_uniqueid,
55 string sfn )
56
57 dpns_delreplicasbysfn ( ListOfString sfns, ListOfString guids ) ->
58 ListOfInt results
59
60 dpns_endsess ( )
61
62 dpns_endtrans ( )
63
64 dpns_getacl ( string path, ) -> ListOf struct dpns_acl acls
65
66 dpns_getcomment ( string path ) -> string comment
67
68 dpns_getcwd ( ) -> string dir
69
70 dpns_getifcevers ( ) -> string version
71
72 dpns_getlinks ( string path, string guid ) -> ListOf struct dpns_link‐
73 info links
74
75 dpns_getreplica ( string path, string guid, string se ) -> ListOf
76 struct dpns_filereplica replicas
77
78 dpns_getreplicax ( string path, string guid, string se ) -> ListOf
79 struct dpns_filereplicax replicas
80
81 dpns_lchown ( string path, uid_t new_uid, gid_t new_gid )
82
83 dpns_listreplicax ( string poolname, string server, string fs, int
84 flags, dpns_list * listp ) -> struct dpns_filereplica replica
85
86 dpns_listrepset ( string setname, int flags, dpns_list *listp ) ->
87 struct dpns_filereplicax replica
88
89 dpns_lstat ( string path ) -> struct dpns_filestat statbuf
90
91 dpns_mkdir ( string path, mode_t mode )
92
93 dpns_modreplica ( string sfn, string setname, string poolname, string
94 server )
95
96 dpns_modreplicax ( string sfn, string setname, string poolname, string
97 server, string fs, char r_type )
98
99 dpns_opendir ( string path ) -> dpns_DIR dir
100
101 dpns_opendirxg ( string server, string path, string guid ) -> dpns_DIR
102 dir
103
104 dpns_ping ( string server ) -> string info
105
106 dpns_readdir ( dpns_DIR dirp ) -> struct dirent dirent
107
108 dpns_readdirc ( dpns_DIR dirp ) -> struct dpns_direncomm dirent
109
110 dpns_readdirg ( dpns_DIR dirp ) -> struct dpns_direnstatg dirent
111
112 dpns_readdirx ( dpns_DIR dirp ) -> struct dpns_direnstat dirent
113
114 dpns_readdirxc ( dpns_DIR dirp ) -> struct dpns_direnstatc dirent
115
116 dpns_readdirxp ( dpns_DIR dirp, string pattern, string se = None ) ->
117 struct dpns_direnrep dirent
118
119 dpns_readdirxr ( dpns_DIR dirp, string se = None ) -> struct
120 dpns_direnrep dirent
121
122 dpns_readlink ( string path ) -> string link
123
124 dpns_rename ( string oldpath, string newpath )
125
126 dpns_rewinddir ( dpns_DIR dirp )
127
128 dpns_rmdir ( string path )
129
130 dpns_setacl ( string path, ListOf struct dpns_acl acls )
131
132 dpns_setatime ( string path, struct dpns_fileid file_uniqueid )
133
134 dpns_setcomment ( string path, string comment )
135
136 dpns_setfsize ( string path, struct dpns_fileid file_uniqueid, long
137 filesize )
138
139 dpns_setfsizec ( string path, struct dpns_fileid file_uniqueid, long
140 filesize, string csumtype, string csumvalue )
141
142 dpns_setptime ( string sfn, long ptime )
143
144 dpns_setratime ( string sfn )
145
146 dpns_setrltime ( string sfn, long ltime )
147
148 dpns_setrstatus ( string sfn, char status )
149
150 dpns_setrtype ( string sfn, char type )
151
152 dpns_startsess ( string server, string comment )
153
154 dpns_starttrans ( string server, string comment )
155
156 dpns_stat ( string path ) -> struct dpns_filestat statbuf
157
158 dpns_statg ( string path, string guid ) -> struct dpns_filestatg stat‐
159 buf
160
161 dpns_statr ( string sfn) ) -> struct dpns_filestatg statbuf
162
163 dpns_symlink ( string target, string linkname )
164
165 dpns_umask ( mode_t cmask ) -> mode_t oldmask
166
167 dpns_undelete ( string path )
168
169 dpns_unlink ( string path )
170
171 dpns_utime ( string path, struct utimbuf times )
172
173 dpns_entergrpmap ( gid_t gid, string groupname )
174
175 dpns_enterusrmap ( uid_t uid, string username )
176
177 dpns_getgrpbygid ( gid_t gid ) -> string group
178
179 dpns_getgrpbygids ( ListOfgid_t gids ) -> ListOfString groups
180
181 dpns_getgrpbynam ( string groupname ) -> gid_t gid
182
183 dpns_getgrpmap ( ) -> ListOf struct dpns_groupinfo infos
184
185 dpns_getusrbynam ( string username ) -> uid_t uid
186
187 dpns_getusrbyuid ( uid_t uid ) -> string user
188
189 dpns_getusrmap ( ) -> ListOf struct dpns_userinfo userinfo
190
191 dpns_modifygrpmap ( gid_t gid, string newname )
192
193 dpns_modifyusrmap ( uid_t uid, string newname )
194
195 dpns_rmgrpmap ( gid_t gid, string groupname )
196
197 dpns_rmusrmap ( uid_t uid, string username )
198
199 dpm_getpoolfs ( string poolname ) -> ListOf struct dpm_fs dpm_fs
200
201 dpm_getpools ( ) -> ListOf struct dpm_pool dpm_pools
202
203 dpm_getprotocols ( ) -> ListOfString protocols
204
205 dpm_getspacemd ( ListOfString s_tokens ) -> ListOf struct
206 dpm_space_metadata spacemd
207
208 dpm_getspacetoken ( string u_token ) -> ListOfString s_tokens
209
210 dpm_addfs ( string poolname, string server, string fs, int status )
211
212 dpm_addpool ( struct dpm_pool dpm_pool )
213
214 dpm_delreplica ( string pfn )
215
216 dpm_modifyfs ( string server, string fs, int status )
217
218 dpm_modifypool ( struct dpm_pool dpm_pool )
219
220 dpm_ping ( string host ) -> string info
221
222 dpm_releasespace ( string s_token, int force )
223
224 dpm_reservespace ( char s_type, string u_token, char ret_policy, char
225 ac_latency, long req_t_space, long req_g_space, long req_lifetime,
226 ListOfInt gids, string poolname ) -> char actual_s_type, long
227 actual_t_space, long actual_g_space, long actual_lifetime, string
228 s_token
229
230 dpm_rmfs ( string server, string fs )
231
232 dpm_rmpool ( string poolname )
233
234 dpm_updatespace ( string s_token, long req_t_space, long req_g_space,
235 long req_lifetime, ListOfInt gids ) -> long actual_t_space, long
236 actual_g_space, long actual_lifetime
237
238
240 Sometimes you need to specify a structure as an input argument (eg.
241 struct dpns_acl, struct dpns_list, struct dpm_pool, etc.). For that
242 purpose, the module includes structure constructors, named exactly as
243 the structure.
244
245 Thus, to create struct dpns_acl, struct dpns_list or struct dpmm_pool,
246 you have to do the following:
247
248 dpnsacl = dpm.dpns_acl()
249 dpnslist = dpm.dpns_list()
250 dpmpool = dpm.dpm_pool()
251
252 If you want to see how to use it in a real case, please have a look at
253 examples.
254
255
257 As you can see, no error code is returned. When an error occurs, an
258 exception is raised with a description of the error.
259
260
262 #!/usr/bin/python
263
264 """
265 # Using the dpns_readdirxr method
266 """
267
268 import sys
269 import traceback
270 import dpm2 as dpm
271
272 name = "/dpm/cern.ch/home/dteam/";
273
274 try:
275 dir = dpm.dpns_opendir(name)
276
277 while 1:
278 entry = dpm.dpns_readdirxr(dir)
279 if entry == None:
280 break
281 print entry.d_name
282 for i in range(entry.nbreplicas):
283 print " ==> %s" % entry.rep[i].sfn
284
285 dpm.dpns_closedir(dir)
286 except TypeError, x:
287 print " ==> None"
288 except Exception:
289 traceback.print_exc()
290 sys.exit(1)
291
292
294 #!/usr/bin/python
295
296 import sys
297 import traceback
298 import dpm2 as dpm
299
300 """
301 # Using the dpns_getreplica method
302 """
303
304 file = "/dpm/cern.ch/home/dteam/file.test"
305
306 try:
307 list = dpm.dpns_getreplica(file, "", "")
308 except Exception:
309 traceback.print_exc()
310 sys.exit(1)
311
312 for i in list:
313 print i.host
314 print i.sfn
315
316
318 #!/usr/bin/python
319
320 import sys
321 import traceback
322 import dpm2 as dpm
323
324 """
325 # Using the dpns_getacl and dpns_setacl methods to add a user ACL
326 """
327
328 file = "/dpm/cern.ch/home/dteam/file.test"
329
330 try:
331 acls_list = dpm.dpns_getacl(file)
332 except Exception:
333 traceback.print_exc()
334 sys.exit(1)
335
336 for i in acls_list:
337 print i.a_type
338 print i.a_id
339 print i.a_perm
340
341 # When adding a first ACL for a given user, you also need to add the mask
342 # When adding the second user ACL, it is not necessary anymore
343
344 acl_user = dpm.dpns_acl()
345 acl_mask = dpm.dpns_acl()
346
347 acl_user.a_type = lfc.CNS_ACL_USER
348 acl_user.a_id = 18701 # user id
349 acl_user.a_perm = 5
350
351 acl_mask.a_type = lfc.CNS_ACL_MASK
352 acl_mask.a_id = 0 # no user id specified
353 acl_mask.a_perm = 5
354
355 acls_list.append(acl_user)
356 acls_list.append(acl_mask)
357
358 try:
359 dpm.dpns_setacl(file, acls_list)
360 except Exception:
361 traceback.print_exc()
362 sys.exit(1)
363
364
366 #!/usr/bin/python
367
368 import sys
369 import traceback
370 import dpm2 as dpm
371
372 """
373 # Using the dpns_getacl and dpns_setacl methods to remove a user ACL
374 """
375
376 file = "/dpm/cern.ch/home/dteam/file.test"
377
378 try:
379 acls_list = dpm.dpns_getacl(file)
380 except Exception:
381 traceback.print_exc()
382 sys.exit(1)
383
384 for i in acls_list:
385 print i.a_type
386 print i.a_id
387 print i.a_perm
388
389 del acls_list[1] # delete a given user ACL from the list of ACLs
390
391 try:
392 dpm.dpns_setacl(file, acls_list)
393 except Exception:
394 traceback.print_exc()
395 sys.exit(1)
396
397
399 #!/usr/bin/python
400
401 import sys
402 import traceback
403 import dpm2 as dpm
404
405 """
406 # Using the dpns_getusrmap method
407 """
408
409 try:
410 list = dpm.dpns_getusrmap()
411 except Exception:
412 traceback.print_exc()
413 sys.exit(1)
414
415 for i in list:
416 print i.userid + " " + i.username
417
418
420 #!/usr/bin/python
421
422 import sys
423 import traceback
424 import dpm2 as dpm
425
426 """
427 # Using the dpns_getgrpmap method
428 """
429
430 try:
431 list = dpm.dpns_getgrpmap()
432 except Exception:
433 traceback.print_exc()
434 sys.exit(1)
435
436 for i in list:
437 print i.gid + " " + i.groupname
438
439
441 #!/usr/bin/python
442
443 import sys
444 import traceback
445 import dpm2 as dpm
446
447 """
448 # Using the dpm_addfs method
449 """
450
451 try:
452 dpm.dpm_addfs("mypool", "mydiskserver.domain.com", "/mountpoint", \
453 dpm.FS_READONLY)
454 except Exception:
455 traceback.print_exc()
456 sys.exit(1)
457
458
460 #!/usr/bin/python
461
462 import sys
463 import traceback
464 import dpm2 as dpm
465
466 """
467 # Using the dpm_modifyfs method
468 """
469
470 try:
471 dpm.dpm_modifyfs("mydiskserver.domain.com", "/mountpoint", \
472 dpm.FS_READONLY)
473 except Exception:
474 traceback.print_exc()
475 sys.exit(1)
476
477
479 #!/usr/bin/python
480
481 import sys
482 import traceback
483 import dpm2 as dpm
484
485 """
486 # Using the dpm_rmfs method
487 """
488
489 try:
490 dpm.dpm_rmfs("mypool", "mydiskserver.domain.com", "/mountpoint")
491 except Exception:
492 traceback.print_exc()
493 sys.exit(1)
494
495
497 #!/usr/bin/python
498
499 import sys
500 import traceback
501 import dpm2 as dpm
502
503 """
504 # Using the dpm_addpool method
505 """
506
507 dpmpool = dpm.dpm_pool()
508 dpmpool.poolname = "mypool"
509 dpmpool.defsize = 209715200
510 dpmpool.def_lifetime = 604800
511 dpmpool.defpintime = 604800
512 dpmpool.max_lifetime = 604800
513 dpmpool.max_pintime = 604800
514 dpmpool.nbgids = 1
515 dpmpool.gids = [0]
516 dpmpool.ret_policy = 'R'
517 dpmpool.s_type = 'D'
518
519 try:
520 dpm.dpm_addpool(dpmpool)
521 except Exception:
522 traceback.print_exc()
523 sys.exit(1)
524
525
527 #!/usr/bin/python
528
529 import sys
530 import traceback
531 import dpm2 as dpm
532
533 """
534 # Using the dpm_modifypool method
535 """
536
537 dpmpool = dpm.dpm_pool()
538 dpmpool.poolname = "mypool"
539 dpmpool.defsize = 209715200
540 dpmpool.def_lifetime = 604800
541 dpmpool.defpintime = 604800
542 dpmpool.max_lifetime = 604800
543 dpmpool.max_pintime = 604800
544 dpmpool.nbgids = 1
545 dpmpool.gids = [0]
546 dpmpool.ret_policy = 'R'
547 dpmpool.s_type = 'D'
548
549 try:
550 dpm.dpm_modifypool(dpmpool)
551 except Exception:
552 traceback.print_exc()
553 sys.exit(1)
554
555
557 #!/usr/bin/python
558
559 import sys
560 import traceback
561 import dpm2 as dpm
562
563 """
564 # Using the dpm_rmpool method
565 """
566
567 try:
568 dpm.dpm_rmpool("mypool")
569 except Exception:
570 traceback.print_exc()
571 sys.exit(1)
572
573
575 #!/usr/bin/python
576
577 import sys
578 import traceback
579 import dpm2 as dpm
580
581 """
582 # Using the dpm_getpoolfs method
583 """
584
585 try:
586 list = dpm.dpm_getpoolfs("mypool")
587 except Exception:
588 traceback.print_exc()
589 sys.exit(1)
590
591 print len(list)
592 for i in list:
593 print "POOL " + i.poolname + " SERVER " + i.server + " FS " + i.fs \
594 + " CAPACITY " + i.capacity + " FREE " + i.free
595
596
598 #!/usr/bin/python
599
600 import sys
601 import traceback
602 import dpm2 as dpm
603
604 """
605 # Using the dpm_getpools method
606 """
607
608 try:
609 list = dpm.dpm_getpools()
610 except Exception:
611 traceback.print_exc()
612 sys.exit(1)
613
614 print len(list)
615 for i in list:
616 print "POOL " + i.poolname + " CAPACITY " + i.capacity + " FREE " + i.free
617
618
620 #!/usr/bin/python
621
622 import sys
623 import traceback
624 import dpm2 as dpm
625
626 """
627 # Using the dpm_getprotocols method
628 """
629
630 try:
631 list = dpm.dpm_getprotocols()
632 except Exception:
633 traceback.print_exc()
634 sys.exit(1)
635
636 print len(list)
637 for i in list:
638 print i
639
640
642 #!/usr/bin/python
643
644 import sys
645 import traceback
646 import dpm2 as dpm
647
648 """
649 # Using the dpm_getspacemd method
650 """
651
652 try:
653 list = dpm.dpm_getspacemd(["myspacetoken"])
654 except Exception:
655 traceback.print_exc()
656 sys.exit(1)
657
658 print len(list)
659 for i in list:
660 print "TYPE " + i.s_type + " SPACETOKEN " i.s_token + " USERTOKEN " \
661 + i.u_token + " TOTAL " + i.t_space + " GUARANTUEED " + i.g_space \
662 + " UNUSED " + i.u_space + " POOL " + i.poolname
663
664
666 #!/usr/bin/python
667
668 import sys
669 import traceback
670 import dpm2 as dpm
671
672 """
673 # Using the dpm_getspacetoken method
674 """
675
676 try:
677 list = dpm.dpm_getspacetoken("myspacetokendesc")
678 except Exception:
679 traceback.print_exc()
680 sys.exit(1)
681
682 print len(list)
683 for i in list:
684 print i
685
686
688 #!/usr/bin/python
689
690 import sys
691 import traceback
692 import dpm2 as dpm
693
694 """
695 # Using the dpm_reservespace method
696 """
697
698 try:
699 actual_s_type,actual_t_space,actual_g_space,actual_lifetime,s_token = \
700 dpm.dpm_reservespace('D', "myspacetokendesc", 'R', 'O', 209715200, \
701 209715200, 2592000, 0, "mypoolname")
702 except Exception:
703 traceback.print_exc()
704 sys.exit(1)
705
706 print "TYPE " + actual_s_type + " TOTAL " + actual_t_space + " GUARANTEED " \
707 + actual_g_space + " LIFETIME " + actual_lifetime + " TOKEN " + s_token
708
709
711 #!/usr/bin/python
712
713 import sys
714 import traceback
715 import dpm2 as dpm
716
717 """
718 # Using the dpm_updatespace method
719 """
720
721 try:
722 actual_t_space,actual_g_space,actual_lifetime = \
723 dpm.dpm_updatespace("myspacetoken", 209715200, 209715200, 2592000)
724 except Exception:
725 traceback.print_exc()
726 sys.exit(1)
727
728 print " TOTAL " + actual_t_space + " GUARANTEED " + actual_g_space \
729 + " LIFETIME " + actual_lifetime
730
731
733 #!/usr/bin/python
734
735 import sys
736 import traceback
737 import dpm2 as dpm
738
739 """
740 # Using the dpm_releasespace method
741 """
742
743 try:
744 dpm.dpm_releasespace("myspacetoken", 0)
745 except Exception:
746 traceback.print_exc()
747 sys.exit(1)
748
749
751 #!/usr/bin/python
752
753 import sys
754 import traceback
755 import dpm2 as dpm
756
757 """
758 # Using the dpm_ping method
759 """
760
761 try:
762 info = dpm.dpm_ping("mydpmserver.domain.com")
763 except Exception:
764 traceback.print_exc()
765 sys.exit(1)
766
767 print info
768
769
771 DPM C interface man pages
772
773
774
775DPM $Date: 2010-12-14 08:31:05 +0100 (Tue, 14 Dec 2010)d$pm2_python(3)