1dpm_python(3) Python Reference
2dpm_python(3)
3
4
5
6[1mNAME[0m
7 dpm ‐ Python interface to the DPM
8
9[1mSYNOPSIS[0m
10 [1mimport dpm[0m
11
12
13[1mDESCRIPTION[0m
14 The dpm module permits you to access the DPM client
15interface from
16 python programs. The dpm module is a swig wrapping of the
17standard C
18 interface. For detailed descriptions of each function see
19the individ‐
20 ual man page of each function.
21
22 There follows a series of examples of how to use selected
23functions and
24 how to retrieve the information returned by them: Exam‐
25ples are listing
26 the replicas of a given entry, reading the content of a
27directory, get‐
28 ting and setting ACLs. etc.
29
30
31[1mEXAMPLE[0m
32 #!/usr/bin/python
33
34 """
35 # Using the dpns_readdirxr method
36 """
37
38 import sys
39 import dpm
40
41 name = "/dpm/cern.ch/home/dteam/";
42
43 dir = dpm.dpns_opendirg(name,"")
44 if (dir == None) or (dir == 0):
45 err_num = dpm.cvar.serrno
46 err_string = dpm.sstrerror(err_num)
47 print "Error while looking for " + name + ": Error
48" + str(err_num) + " (" + err_string + ")"
49 sys.exit(1)
50
51 while 1:
52 read_pt = dpm.dpns_readdirxr(dir,"")
53 if (read_pt == None) or (read_pt == 0):
54 break
55 entry, list = read_pt
56 print entry.d_name
57 try:
58 for i in range(len(list)):
59 print " ==> %s" % list[i].sfn
60 except TypeError, x:
61 print " ==> None"
62
63 dpm.dpns_closedir(dir)
64
65
66[1mEXAMPLE[0m
67 #!/usr/bin/python
68
69 import dpm
70
71 """
72 # Using the dpns_getlinks method
73 """
74
75 result, list = dpm.dp‐
76ns_getlinks("/dpm/cern.ch/home/dteam/file.test", "")
77 print result
78 print len(list)
79 if (result == 0):
80 for i in list:
81 print i.path
82
83
84[1mEXAMPLE[0m
85 #!/usr/bin/python
86
87 import dpm
88
89 """
90 # Using the dpns_getreplica method
91 """
92
93 result, list = dpm.dpns_getrepli‐
94ca("/dpm/cern.ch/home/dteam/file.test", "", "")
95 print result
96 print len(list)
97 if (result == 0):
98 for i in list:
99 print i.host
100 print i.sfn
101
102
103[1mEXAMPLE[0m
104 #!/usr/bin/python
105
106 import dpm
107
108 """
109 # Using the dpns_getacl and dpns_setacl methods to add a
110user ACL
111 """
112
113 nentries, acls_list = dpm.dpns_geta‐
114cl("/dpm/cern.ch/home/dteam/file.test",
115dpm.CA_MAXACLENTRIES)
116
117 print nentries
118 print len(acls_list)
119
120 for i in acls_list:
121 print i.a_type
122 print i.a_id
123 print i.a_perm
124
125 # When adding a first ACL for a given user, you also need
126to add the mask
127 # When adding the second user ACL, it is not necessary
128anymore
129
130 acl_user = dpm.dpns_acl()
131 acl_mask = dpm.dpns_acl()
132
133 acl_user.a_type=2 # 2 corresponds to CNS_ACL_USER
134 acl_user.a_id=18701 # user id
135 acl_user.a_perm=5
136
137 acl_mask.a_type=5 # 5 corresponds to CNS_ACL_MASK
138 acl_mask.a_id=0 # no user id specified
139 acl_mask.a_perm=5
140
141 acls_list.append(acl_user)
142 acls_list.append(acl_mask)
143
144 res = dpm.dpns_setacl("/dpm/cern.ch/home/dteam/file.test",
145acls_list)
146
147 if res == 0:
148 print "OK"
149 else:
150 err_num = dpm.cvar.serrno
151 err_string = dpm.sstrerror(err_num)
152 print "There was an error : Error " + str(err_num)
153+ " (" + err_string + ")"
154 sys.exit(1)
155
156
157[1mEXAMPLE[0m
158 #!/usr/bin/python
159
160 import dpm
161
162 """
163 # Using the dpns_getacl and dpns_setacl methods to remove
164a user ACL
165 """
166
167 nentries, acls_list = dpm.dpns_geta‐
168cl("/dpm/cern.ch/home/dteam/file.test",
169dpm.CA_MAXACLENTRIES)
170
171 # Note : you cannot remove the owner ACL (i.e. for
172CNS_ACL_USER_OBJ type) if
173 # ====== ACLs for other users exist. If all the other user
174ACLs are deleted,
175 # ====== the owner ACL is automatically removed.
176
177 for i in acls_list:
178 print i.a_type
179 print i.a_id
180 print i.a_perm
181
182 del acls_list[1] # delete a given user ACL from the
183list of ACLs
184
185 res = dpm.dpns_setacl("/dpm/cern.ch/home/dteam/file.test",
186acls_list)
187
188 if res == 0:
189 print "OK"
190 else:
191 err_num = dpm.cvar.serrno
192 err_string = dpm.sstrerror(err_num)
193 print "There was an error : Error " + str(err_num)
194+ " (" + err_string + ")"
195 sys.exit(1)
196
197
198[1mEXAMPLE[0m
199 #!/usr/bin/python
200
201 import dpm
202
203 """
204 # Using the dpns_getusrmap method
205 """
206
207 result, list = dpm.dpns_getusrmap()
208 print result
209 print len(list)
210 if (result == 0):
211 for i in list:
212 print i.userid + " " + i.username
213
214
215[1mEXAMPLE[0m
216 #!/usr/bin/python
217
218 import dpm
219
220 """
221 # Using the dpns_getgrpmap method
222 """
223
224 result, list = dpm.dpns_getgrpmap()
225 print result
226 print len(list)
227 if (result == 0):
228 for i in list:
229 print i.gid + " " + i.groupname
230
231
232[1mEXAMPLE[0m
233 #!/usr/bin/python
234
235 import dpm
236
237 """
238 # Using the dpm_addfs method
239 """
240
241 result = dpm.dpm_addfs("mypool", "mydiskserver.do‐
242main.com", "/mountpoint", dpm.FS_READONLY)
243 print result
244
245
246[1mEXAMPLE[0m
247 #!/usr/bin/python
248
249 import dpm
250
251 """
252 # Using the dpm_modifyfs method
253 """
254
255 result = dpm.dpm_modifyfs("mydiskserver.domain.com",
256"/mountpoint", dpm.FS_READONLY)
257 print result
258
259
260[1mEXAMPLE[0m
261 #!/usr/bin/python
262
263 import dpm
264
265 """
266 # Using the dpm_rmfs method
267 """
268
269 result = dpm.dpm_rmfs("mypool", "mydiskserver.domain.com",
270"/mountpoint")
271 print result
272
273
274[1mEXAMPLE[0m
275 #!/usr/bin/python
276
277 import dpm
278
279 """
280 # Using the dpm_addpool method
281 """
282
283 dpmpool = dpm.dpm_pool()
284 dpmpool.poolname = "mypool"
285 dpmpool.defsize = 209715200
286 dpmpool.def_lifetime = 604800
287 dpmpool.defpintime = 604800
288 dpmpool.max_lifetime = 604800
289 dpmpool.max_pintime = 604800
290 dpmpool.nbgids = 1
291 dpmpool.gids = [0]
292 dpmpool.ret_policy = ’R’
293 dpmpool.s_type = ’D’
294
295 result = dpm.dpm_addpool(dpmpool)
296 print result
297
298
299[1mEXAMPLE[0m
300 #!/usr/bin/python
301
302 import dpm
303
304 """
305 # Using the dpm_modifypool method
306 """
307
308 dpmpool = dpm.dpm_pool()
309 dpmpool.poolname = "mypool"
310 dpmpool.defsize = 209715200
311 dpmpool.def_lifetime = 604800
312 dpmpool.defpintime = 604800
313 dpmpool.max_lifetime = 604800
314 dpmpool.max_pintime = 604800
315 dpmpool.nbgids = 1
316 dpmpool.gids = [0]
317 dpmpool.ret_policy = ’R’
318 dpmpool.s_type = ’D’
319
320 result = dpm.dpm_modifypool(dpmpool)
321 print result
322
323
324[1mEXAMPLE[0m
325 #!/usr/bin/python
326
327 import dpm
328
329 """
330 # Using the dpm_rmpool method
331 """
332
333 result = dpm.dpm_rmpool("mypool")
334 print result
335
336
337[1mEXAMPLE[0m
338 #!/usr/bin/python
339
340 import dpm
341
342 """
343 # Using the dpm_getpoolfs method
344 """
345
346 result,list = dpm.dpm_getpoolfs("mypool")
347 print result
348 print len(list)
349 if (result == 0):
350 for i in list:
351 print "POOL " + i.poolname + " SERVER " +
352i.server + " FS " + i.fs + " CAPACITY " +
353i.capacity + " FREE " + i.free
354
355
356[1mEXAMPLE[0m
357 #!/usr/bin/python
358
359 import dpm
360
361 """
362 # Using the dpm_getpools method
363 """
364
365 result,list = dpm.dpm_getpools()
366 print result
367 print len(list)
368 if (result == 0):
369 for i in list:
370 print "POOL " + i.poolname + " CAPACITY " +
371i.capacity + " FREE " + i.free
372
373
374[1mEXAMPLE[0m
375 #!/usr/bin/python
376
377 import dpm
378
379 """
380 # Using the dpm_getprotocols method
381 """
382
383 result,list = dpm.dpm_getprotocols()
384 print result
385 print len(list)
386 if (result == 0):
387 for i in list:
388 print i
389
390
391[1mEXAMPLE[0m
392 #!/usr/bin/python
393
394 import dpm
395
396 """
397 # Using the dpm_getspacemd method
398 """
399
400 result, list = dpm.dpm_getspacemd(["myspacetoken"])
401 print result
402 print len(list)
403 if (result == 0):
404 for i in list:
405 print "TYPE " + i.s_type + " SPACETOKEN "
406i.s_token + " USERTOKEN " + i.u_token + "
407TOTAL " + i.t_space + " GUARANTUEED " + i.g_space
408+ " UNUSED " + i.u_space + " POOL " + i.poolname
409
410
411[1mEXAMPLE[0m
412 #!/usr/bin/python
413
414 import dpm
415
416 """
417 # Using the dpm_getspacetoken method
418 """
419
420 result, list = dpm.dpm_getspacetoken("myspacetokendesc")
421 print result
422 print len(list)
423 if (result == 0):
424 for i in list:
425 print i
426
427
428[1mEXAMPLE[0m
429 #!/usr/bin/python
430
431 import dpm
432
433 """
434 # Using the dpm_reservespace method
435 """
436
437 result,actual_s_type,actual_t_space,actual_g_space,actu‐
438al_lifetime,s_token = dpm.dpm_reservespace(’D’,
439"myspacetokendesc", ’R’, ’O’, 209715200,
440209715200, 2592000, 0, "mypoolname")
441 print result
442 if (result == 0):
443 print "TYPE " + actual_s_type + " TOTAL " + actu‐
444al_t_space + " GUARANTEED " + actual_g_space + "
445LIFETIME " + actual_lifetime + " TOKEN " + s_token
446
447
448[1mEXAMPLE[0m
449 #!/usr/bin/python
450
451 import dpm
452
453 """
454 # Using the dpm_updatespace method
455 """
456
457 result,actual_t_space,actual_g_space,actual_lifetime =
458dpm.dpm_updatespace("myspacetoken", 209715200, 209715200,
4592592000)
460 print result
461 if (result == 0):
462 print " TOTAL " + actual_t_space + " GUARANTEED " +
463actual_g_space + " LIFETIME " + actual_lifetime
464
465
466[1mEXAMPLE[0m
467 #!/usr/bin/python
468
469 import dpm
470
471 """
472 # Using the dpm_releasespace method
473 """
474
475 result = dpm.dpm_releasespace("myspacetoken", 0)
476 print result
477
478
479[1mEXAMPLE[0m
480 #!/usr/bin/python
481
482 import dpm
483
484 """
485 # Using the dpm_ping method
486 """
487
488 result,info = dpm.dpm_ping("mydpmserver.domain.com")
489 print result
490 if (result == 0):
491 print info
492
493
494[1mKNOWN BUGS[0m
495 The current interface to the [1mdp‐
496ns_getcwd(3)[22m, [1mdpns_readlink(3)[22m,
497 [1mdpns_seterrbuf(3) [22mrequires the passing of str ob‐
498ject which is modified
499 to contain the result (in a similar way to the C
500functions, which
501 accept a buffer). However this breaks the immutability of
502python str.
503 This will be changed in the future.
504
505
506[1mSEE ALSO[0m
507 [1mDPM C interface man pages[0m
508
509
510
511DPM $Date$
512dpm_python(3)
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528