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