rucio-clients 32.8.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of rucio-clients might be problematic. Click here for more details.

Files changed (88) hide show
  1. rucio/__init__.py +18 -0
  2. rucio/alembicrevision.py +16 -0
  3. rucio/client/__init__.py +16 -0
  4. rucio/client/accountclient.py +413 -0
  5. rucio/client/accountlimitclient.py +155 -0
  6. rucio/client/baseclient.py +929 -0
  7. rucio/client/client.py +77 -0
  8. rucio/client/configclient.py +113 -0
  9. rucio/client/credentialclient.py +54 -0
  10. rucio/client/didclient.py +691 -0
  11. rucio/client/diracclient.py +48 -0
  12. rucio/client/downloadclient.py +1674 -0
  13. rucio/client/exportclient.py +44 -0
  14. rucio/client/fileclient.py +51 -0
  15. rucio/client/importclient.py +42 -0
  16. rucio/client/lifetimeclient.py +74 -0
  17. rucio/client/lockclient.py +99 -0
  18. rucio/client/metaclient.py +137 -0
  19. rucio/client/pingclient.py +45 -0
  20. rucio/client/replicaclient.py +444 -0
  21. rucio/client/requestclient.py +109 -0
  22. rucio/client/rseclient.py +664 -0
  23. rucio/client/ruleclient.py +287 -0
  24. rucio/client/scopeclient.py +88 -0
  25. rucio/client/subscriptionclient.py +161 -0
  26. rucio/client/touchclient.py +78 -0
  27. rucio/client/uploadclient.py +871 -0
  28. rucio/common/__init__.py +14 -0
  29. rucio/common/cache.py +74 -0
  30. rucio/common/config.py +796 -0
  31. rucio/common/constants.py +92 -0
  32. rucio/common/constraints.py +18 -0
  33. rucio/common/didtype.py +187 -0
  34. rucio/common/exception.py +1092 -0
  35. rucio/common/extra.py +37 -0
  36. rucio/common/logging.py +404 -0
  37. rucio/common/pcache.py +1387 -0
  38. rucio/common/policy.py +84 -0
  39. rucio/common/schema/__init__.py +143 -0
  40. rucio/common/schema/atlas.py +411 -0
  41. rucio/common/schema/belleii.py +406 -0
  42. rucio/common/schema/cms.py +478 -0
  43. rucio/common/schema/domatpc.py +399 -0
  44. rucio/common/schema/escape.py +424 -0
  45. rucio/common/schema/generic.py +431 -0
  46. rucio/common/schema/generic_multi_vo.py +410 -0
  47. rucio/common/schema/icecube.py +404 -0
  48. rucio/common/schema/lsst.py +423 -0
  49. rucio/common/stomp_utils.py +160 -0
  50. rucio/common/stopwatch.py +56 -0
  51. rucio/common/test_rucio_server.py +148 -0
  52. rucio/common/types.py +158 -0
  53. rucio/common/utils.py +1946 -0
  54. rucio/rse/__init__.py +97 -0
  55. rucio/rse/protocols/__init__.py +14 -0
  56. rucio/rse/protocols/cache.py +123 -0
  57. rucio/rse/protocols/dummy.py +112 -0
  58. rucio/rse/protocols/gfal.py +701 -0
  59. rucio/rse/protocols/globus.py +243 -0
  60. rucio/rse/protocols/gsiftp.py +93 -0
  61. rucio/rse/protocols/http_cache.py +83 -0
  62. rucio/rse/protocols/mock.py +124 -0
  63. rucio/rse/protocols/ngarc.py +210 -0
  64. rucio/rse/protocols/posix.py +251 -0
  65. rucio/rse/protocols/protocol.py +530 -0
  66. rucio/rse/protocols/rclone.py +365 -0
  67. rucio/rse/protocols/rfio.py +137 -0
  68. rucio/rse/protocols/srm.py +339 -0
  69. rucio/rse/protocols/ssh.py +414 -0
  70. rucio/rse/protocols/storm.py +207 -0
  71. rucio/rse/protocols/webdav.py +547 -0
  72. rucio/rse/protocols/xrootd.py +295 -0
  73. rucio/rse/rsemanager.py +752 -0
  74. rucio/vcsversion.py +11 -0
  75. rucio/version.py +46 -0
  76. rucio_clients-32.8.6.data/data/etc/rse-accounts.cfg.template +25 -0
  77. rucio_clients-32.8.6.data/data/etc/rucio.cfg.atlas.client.template +42 -0
  78. rucio_clients-32.8.6.data/data/etc/rucio.cfg.template +257 -0
  79. rucio_clients-32.8.6.data/data/requirements.txt +55 -0
  80. rucio_clients-32.8.6.data/data/rucio_client/merge_rucio_configs.py +147 -0
  81. rucio_clients-32.8.6.data/scripts/rucio +2540 -0
  82. rucio_clients-32.8.6.data/scripts/rucio-admin +2434 -0
  83. rucio_clients-32.8.6.dist-info/METADATA +50 -0
  84. rucio_clients-32.8.6.dist-info/RECORD +88 -0
  85. rucio_clients-32.8.6.dist-info/WHEEL +5 -0
  86. rucio_clients-32.8.6.dist-info/licenses/AUTHORS.rst +94 -0
  87. rucio_clients-32.8.6.dist-info/licenses/LICENSE +201 -0
  88. rucio_clients-32.8.6.dist-info/top_level.txt +1 -0
@@ -0,0 +1,664 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright European Organization for Nuclear Research (CERN) since 2012
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ from json import dumps, loads
17
+ from urllib.parse import quote
18
+
19
+ from requests.status_codes import codes
20
+
21
+ from rucio.client.baseclient import BaseClient
22
+ from rucio.client.baseclient import choice
23
+ from rucio.common.utils import build_url
24
+
25
+
26
+ class RSEClient(BaseClient):
27
+ """RSE client class for working with rucio RSEs"""
28
+
29
+ RSE_BASEURL = 'rses'
30
+
31
+ def get_rse(self, rse):
32
+ """
33
+ Returns details about the referred RSE.
34
+
35
+ :param rse: Name of the referred RSE
36
+
37
+ :returns: A dict containing all attributes of the referred RSE
38
+
39
+ :raises RSENotFound: if the referred RSE was not found in the database
40
+ """
41
+ path = '/'.join([self.RSE_BASEURL, rse])
42
+ url = build_url(choice(self.list_hosts), path=path)
43
+
44
+ r = self._send_request(url, type_='GET')
45
+ if r.status_code == codes.ok:
46
+ rse = loads(r.text)
47
+ return rse
48
+ else:
49
+ exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content)
50
+ raise exc_cls(exc_msg)
51
+
52
+ def add_rse(self, rse, **kwargs):
53
+ """
54
+ Sends the request to create a new RSE.
55
+
56
+ :param rse: the name of the rse.
57
+ :param deterministic: Boolean to know if the pfn is generated deterministically.
58
+ :param volatile: Boolean for RSE cache.
59
+ :param city: City for the RSE.
60
+ :param region_code: The region code for the RSE.
61
+ :param country_name: The country.
62
+ :param continent: The continent.
63
+ :param time_zone: Timezone.
64
+ :param staging_area: Staging area.
65
+ :param ISP: Internet service provider.
66
+ :param rse_type: RSE type.
67
+ :param latitude: Latitude coordinate of RSE.
68
+ :param longitude: Longitude coordinate of RSE.
69
+ :param ASN: Access service network.
70
+ :param availability: Availability.
71
+
72
+ :return: True if location was created successfully else False.
73
+ :raises Duplicate: if rse already exists.
74
+ """
75
+ path = 'rses/' + rse
76
+ url = build_url(choice(self.list_hosts), path=path)
77
+ r = self._send_request(url, type_='POST', data=dumps(kwargs))
78
+ if r.status_code == codes.created:
79
+ return True
80
+ exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content)
81
+ raise exc_cls(exc_msg)
82
+
83
+ def update_rse(self, rse, parameters):
84
+ """
85
+ Update RSE properties like availability or name.
86
+
87
+ :param rse: the name of the new rse.
88
+ :param parameters: A dictionnary with property (name, read, write, delete as keys).
89
+ """
90
+ path = 'rses/' + rse
91
+ url = build_url(choice(self.list_hosts), path=path)
92
+ r = self._send_request(url, type_='PUT', data=dumps(parameters))
93
+ if r.status_code == codes.created:
94
+ return True
95
+ exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content)
96
+ raise exc_cls(exc_msg)
97
+
98
+ def delete_rse(self, rse):
99
+ """
100
+ Sends the request to delete a rse.
101
+
102
+ :param rse: the name of the rse.
103
+ :return: True if location was created successfully else False.
104
+ """
105
+ path = 'rses/' + rse
106
+ url = build_url(choice(self.list_hosts), path=path)
107
+ r = self._send_request(url, type_='DEL')
108
+ if r.status_code == codes.ok:
109
+ return True
110
+ else:
111
+ exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content)
112
+ raise exc_cls(exc_msg)
113
+
114
+ def list_rses(self, rse_expression=None):
115
+ """
116
+ Sends the request to list all rucio locations(RSEs).
117
+
118
+ :rse_expression: RSE Expression to use as filter.
119
+ :return: a list containing the names of all rucio locations.
120
+ """
121
+ if rse_expression:
122
+ path = ['rses', "?expression=" + quote(rse_expression)]
123
+ path = '/'.join(path)
124
+ else:
125
+ path = 'rses/'
126
+ url = build_url(choice(self.list_hosts), path=path)
127
+ r = self._send_request(url, type_='GET')
128
+ if r.status_code == codes.ok:
129
+ return self._load_json_data(r)
130
+ else:
131
+ exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content)
132
+ raise exc_cls(exc_msg)
133
+
134
+ def add_rse_attribute(self, rse, key, value):
135
+ """
136
+ Sends the request to add a RSE attribute.
137
+
138
+ :param rse: the name of the rse.
139
+ :param key: the attribute key.
140
+ :param value: the attribute value.
141
+
142
+ :return: True if RSE attribute was created successfully else False.
143
+ :raises Duplicate: if RSE attribute already exists.
144
+ """
145
+ path = '/'.join([self.RSE_BASEURL, rse, 'attr', key])
146
+ url = build_url(choice(self.list_hosts), path=path)
147
+ data = dumps({'value': value})
148
+
149
+ r = self._send_request(url, type_='POST', data=data)
150
+ if r.status_code == codes.created:
151
+ return True
152
+ else:
153
+ exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content)
154
+ raise exc_cls(exc_msg)
155
+
156
+ def delete_rse_attribute(self, rse, key):
157
+ """
158
+ Sends the request to delete a RSE attribute.
159
+
160
+ :param rse: the RSE name.
161
+ :param key: the attribute key.
162
+
163
+ :return: True if RSE attribute was deleted successfully else False.
164
+ """
165
+ path = '/'.join([self.RSE_BASEURL, rse, 'attr', key])
166
+ url = build_url(choice(self.list_hosts), path=path)
167
+
168
+ r = self._send_request(url, type_='DEL')
169
+ if r.status_code == codes.ok:
170
+ return True
171
+ else:
172
+ exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content)
173
+ raise exc_cls(exc_msg)
174
+
175
+ def list_rse_attributes(self, rse):
176
+ """
177
+ Sends the request to get RSE attributes.
178
+
179
+ :param rse: The RSE name.
180
+
181
+ :return: A ``dict`` with the RSE attribute name/value pairs.
182
+ """
183
+ path = '/'.join([self.RSE_BASEURL, rse, 'attr/'])
184
+ url = build_url(choice(self.list_hosts), path=path)
185
+ r = self._send_request(url, type_='GET')
186
+ if r.status_code == codes.ok:
187
+ attributes = loads(r.text)
188
+ return attributes
189
+ else:
190
+ exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content)
191
+ raise exc_cls(exc_msg)
192
+
193
+ def add_protocol(self, rse, params):
194
+ """
195
+ Sends the request to create a new protocol for the given RSE.
196
+
197
+ :param rse: the name of the rse.
198
+ :param scheme: identifier of this protocol
199
+ :param params: Attributes of the protocol. Supported are:
200
+ hostname: hostname for this protocol (default = localhost)
201
+ port: port for this protocol (default = 0)
202
+ prefix: string used as a prfeix for this protocol when generating the PFN (default = None)
203
+ impl: qualified name of the implementation class for this protocol (mandatory)
204
+ read: integer representing the priority of this procotol for read operations (default = -1)
205
+ write: integer representing the priority of this procotol for write operations (default = -1)
206
+ delete: integer representing the priority of this procotol for delete operations (default = -1)
207
+ extended_attributes: miscellaneous protocol specific information e.g. spacetoken for SRM (default = None)
208
+
209
+ :return: True if protocol was created successfully else False.
210
+
211
+ :raises Duplicate: if protocol with same hostname, port and protocol identifier
212
+ already exists for the given RSE.
213
+ :raises RSENotFound: if the RSE doesn't exist.
214
+ :raises KeyNotFound: if params is missing manadtory attributes to create the
215
+ protocol.
216
+ :raises AccessDenied: if not authorized.
217
+ """
218
+ scheme = params['scheme']
219
+ path = '/'.join([self.RSE_BASEURL, rse, 'protocols', scheme])
220
+ url = build_url(choice(self.list_hosts), path=path)
221
+ r = self._send_request(url, type_='POST', data=dumps(params))
222
+ if r.status_code == codes.created:
223
+ return True
224
+ else:
225
+ exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content)
226
+ raise exc_cls(exc_msg)
227
+
228
+ def get_protocols(self, rse, protocol_domain='ALL', operation=None, default=False, scheme=None):
229
+ """
230
+ Returns protocol information. Parameter comibantions are:
231
+ (operation OR default) XOR protocol.
232
+
233
+ :param rse: the RSE name.
234
+ :param protocol_domain: The scope of the protocol. Supported are 'LAN', 'WAN', and 'ALL' (as default).
235
+ :param operation: The name of the requested operation (read, write, or delete).
236
+ If None, all operations are queried.
237
+ :param default: Indicates if only the default operations should be returned.
238
+ :param scheme: The identifier of the requested protocol.
239
+
240
+ :returns: A list with details about each matching protocol.
241
+
242
+ :raises RSENotFound: if the RSE doesn't exist.
243
+ :raises RSEProtocolNotSupported: if no matching protocol entry could be found.
244
+ :raises RSEOperationNotSupported: if no matching protocol entry for the requested
245
+ operation could be found.
246
+ """
247
+
248
+ path = None
249
+ params = {}
250
+ if scheme:
251
+ path = '/'.join([self.RSE_BASEURL, rse, 'protocols', scheme])
252
+ else:
253
+ path = '/'.join([self.RSE_BASEURL, rse, 'protocols'])
254
+ if operation:
255
+ params['operation'] = operation
256
+ if default:
257
+ params['default'] = default
258
+ params['protocol_domain'] = protocol_domain
259
+ url = build_url(choice(self.list_hosts), path=path, params=params)
260
+
261
+ r = self._send_request(url, type_='GET')
262
+ if r.status_code == codes.ok:
263
+ protocols = loads(r.text)
264
+ return protocols
265
+ else:
266
+ exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content)
267
+ raise exc_cls(exc_msg)
268
+
269
+ def lfns2pfns(self, rse, lfns, protocol_domain='ALL', operation=None, scheme=None):
270
+ """
271
+ Returns PFNs that should be used at a RSE, corresponding to requested LFNs.
272
+ The PFNs are generated for the RSE *regardless* of whether a replica exists for the LFN.
273
+
274
+ :param rse: the RSE name
275
+ :param lfns: A list of LFN strings to translate to PFNs.
276
+ :param protocol_domain: The scope of the protocol. Supported are 'LAN', 'WAN', and 'ALL' (as default).
277
+ :param operation: The name of the requested operation (read, write, or delete).
278
+ If None, all operations are queried.
279
+ :param scheme: The identifier of the requested protocol (gsiftp, https, davs, etc).
280
+
281
+ :returns: A dictionary of LFN / PFN pairs.
282
+ :raises RSENotFound: if the RSE doesn't exist.
283
+ :raises RSEProtocolNotSupported: if no matching protocol entry could be found.
284
+ :raises RSEOperationNotSupported: if no matching protocol entry for the requested
285
+ operation could be found.
286
+ """
287
+ path = '/'.join([self.RSE_BASEURL, rse, 'lfns2pfns'])
288
+ params = []
289
+ if scheme:
290
+ params.append(('scheme', scheme))
291
+ if protocol_domain != 'ALL':
292
+ params.append(('domain', protocol_domain))
293
+ if operation:
294
+ params.append(('operation', operation))
295
+ for lfn in lfns:
296
+ params.append(('lfn', lfn))
297
+
298
+ url = build_url(choice(self.list_hosts), path=path, params=params, doseq=True)
299
+
300
+ r = self._send_request(url, type_='GET')
301
+ if r.status_code == codes.ok:
302
+ pfns = loads(r.text)
303
+ return pfns
304
+ else:
305
+ exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content)
306
+ raise exc_cls(exc_msg)
307
+
308
+ def delete_protocols(self, rse, scheme, hostname=None, port=None):
309
+ """
310
+ Deletes matching protocols from RSE. Protocols using the same identifier can be
311
+ distinguished by hostname and port.
312
+
313
+ :param rse: the RSE name.
314
+ :param scheme: identifier of the protocol.
315
+ :param hostname: hostname of the protocol.
316
+ :param port: port of the protocol.
317
+
318
+ :returns: True if success.
319
+
320
+ :raises RSEProtocolNotSupported: if no matching protocol entry could be found.
321
+ :raises RSENotFound: if the RSE doesn't exist.
322
+ :raises AccessDenied: if not authorized.
323
+ """
324
+ path = [self.RSE_BASEURL, rse, 'protocols', scheme]
325
+ if hostname:
326
+ path.append(hostname)
327
+ if port:
328
+ path.append(str(port))
329
+
330
+ path = '/'.join(path)
331
+ url = build_url(choice(self.list_hosts), path=path)
332
+ r = self._send_request(url, type_='DEL')
333
+ if r.status_code == codes.ok:
334
+ return True
335
+ else:
336
+ exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content)
337
+ raise exc_cls(exc_msg)
338
+
339
+ def update_protocols(self, rse, scheme, data, hostname=None, port=None):
340
+ """
341
+ Updates matching protocols from RSE. Protocol using the same identifier can be
342
+ distinguished by hostname and port.
343
+
344
+ :param rse: the RSE name.
345
+ :param scheme: identifier of the protocol.
346
+ :param data: A dict providing the new values of the protocol attibutes.
347
+ Keys must match column names in database.
348
+ :param hostname: hostname of the protocol.
349
+ :param port: port of the protocol.
350
+
351
+ :returns: True if success.
352
+
353
+ :raises RSEProtocolNotSupported: if no matching protocol entry could be found.
354
+ :raises RSENotFound: if the RSE doesn't exist.
355
+ :raises KeyNotFound: if invalid data was provided for update.
356
+ :raises AccessDenied: if not authorized.
357
+ """
358
+ path = [self.RSE_BASEURL, rse, 'protocols', scheme]
359
+ if hostname:
360
+ path.append(hostname)
361
+ if port:
362
+ path.append(str(port))
363
+
364
+ path = '/'.join(path)
365
+ url = build_url(choice(self.list_hosts), path=path)
366
+ r = self._send_request(url, type_='PUT', data=dumps(data))
367
+ if r.status_code == codes.ok:
368
+ return True
369
+ else:
370
+ exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content)
371
+ raise exc_cls(exc_msg)
372
+
373
+ def swap_protocols(self, rse, domain, operation, scheme_a, scheme_b):
374
+ """
375
+ Swaps the priorities of the provided operation.
376
+
377
+ :param rse: the RSE name.
378
+ :param domain: the domain in which priorities should be swapped i.e. wan or lan.
379
+ :param operation: the operation that should be swapped i.e. read, write, or delete.
380
+ :param scheme_a: the scheme of one of the two protocols to be swapped, e.g. srm.
381
+ :param scheme_b: the scheme of the other of the two protocols to be swapped, e.g. http.
382
+
383
+ :returns: True if success.
384
+
385
+ :raises RSEProtocolNotSupported: if no matching protocol entry could be found.
386
+ :raises RSENotFound: if the RSE doesn't exist.
387
+ :raises KeyNotFound: if invalid data was provided for update.
388
+ :raises AccessDenied: if not authorized.
389
+ """
390
+ protocol_a = protocol_b = None
391
+ protocols = self.get_protocols(rse, domain, operation, False, scheme_a)['protocols']
392
+ for p in protocols:
393
+ if p['scheme'] == scheme_a:
394
+ protocol_a = p
395
+ if p['scheme'] == scheme_b:
396
+ protocol_b = p
397
+ if (protocol_a or protocol_b) is None:
398
+ return False
399
+ priority_a = protocol_a['domains'][domain][operation]
400
+ priority_b = protocol_b['domains'][domain][operation]
401
+ self.update_protocols(rse, protocol_a['scheme'], {'domains': {domain: {operation: priority_b}}}, protocol_a['hostname'], protocol_a['port'])
402
+ self.update_protocols(rse, protocol_b['scheme'], {'domains': {domain: {operation: priority_a}}}, protocol_b['hostname'], protocol_b['port'])
403
+ return True
404
+
405
+ def add_qos_policy(self, rse, qos_policy):
406
+ """
407
+ Add a QoS policy from an RSE.
408
+
409
+ :param rse_id: The id of the RSE.
410
+ :param qos_policy: The QoS policy to add.
411
+ :param session: The database session in use.
412
+
413
+ :raises Duplicate: If the QoS policy already exists.
414
+ :returns: True if successful, except otherwise.
415
+ """
416
+
417
+ path = [self.RSE_BASEURL, rse, 'qos_policy', qos_policy]
418
+ path = '/'.join(path)
419
+ url = build_url(choice(self.list_hosts), path=path)
420
+ r = self._send_request(url, type_='POST')
421
+ if r.status_code == codes.created:
422
+ return True
423
+ else:
424
+ exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content)
425
+ raise exc_cls(exc_msg)
426
+
427
+ def delete_qos_policy(self, rse, qos_policy):
428
+ """
429
+ Delete a QoS policy from an RSE.
430
+
431
+ :param rse_id: The id of the RSE.
432
+ :param qos_policy: The QoS policy to delete.
433
+ :param session: The database session in use.
434
+
435
+ :returns: True if successful, silent failure if QoS policy does not exist.
436
+ """
437
+
438
+ path = [self.RSE_BASEURL, rse, 'qos_policy', qos_policy]
439
+ path = '/'.join(path)
440
+ url = build_url(choice(self.list_hosts), path=path)
441
+ r = self._send_request(url, type_='DEL')
442
+ if r.status_code == codes.ok:
443
+ return True
444
+ else:
445
+ exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content)
446
+ raise exc_cls(exc_msg)
447
+
448
+ def list_qos_policies(self, rse):
449
+ """
450
+ List all QoS policies of an RSE.
451
+
452
+ :param rse_id: The id of the RSE.
453
+ :param session: The database session in use.
454
+
455
+ :returns: List containing all QoS policies.
456
+ """
457
+
458
+ path = [self.RSE_BASEURL, rse, 'qos_policy']
459
+ path = '/'.join(path)
460
+ url = build_url(choice(self.list_hosts), path=path)
461
+ r = self._send_request(url, type_='GET')
462
+ if r.status_code == codes.ok:
463
+ return loads(r.text)
464
+ else:
465
+ exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content)
466
+ raise exc_cls(exc_msg)
467
+
468
+ def set_rse_usage(self, rse, source, used, free, files=None):
469
+ """
470
+ Set RSE usage information.
471
+
472
+ :param rse: the RSE name.
473
+ :param source: the information source, e.g. srm.
474
+ :param used: the used space in bytes.
475
+ :param free: the free in bytes.
476
+ :param files: the number of files
477
+
478
+ :returns: True if successful, otherwise false.
479
+ """
480
+ path = [self.RSE_BASEURL, rse, 'usage']
481
+ path = '/'.join(path)
482
+ url = build_url(choice(self.list_hosts), path=path)
483
+ data = {'source': source, 'used': used, 'free': free, 'files': files}
484
+ r = self._send_request(url, type_='PUT', data=dumps(data))
485
+ if r.status_code == codes.ok:
486
+ return True
487
+ else:
488
+ exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content)
489
+ raise exc_cls(exc_msg)
490
+
491
+ def get_rse_usage(self, rse, filters=None):
492
+ """
493
+ Get RSE usage information.
494
+
495
+ :param rse: the RSE name.
496
+ :param filters: dictionary of attributes by which the results should be filtered
497
+
498
+ :returns: True if successful, otherwise false.
499
+ """
500
+ path = [self.RSE_BASEURL, rse, 'usage']
501
+ path = '/'.join(path)
502
+ url = build_url(choice(self.list_hosts), path=path)
503
+ r = self._send_request(url, type_='GET', params=filters)
504
+ if r.status_code == codes.ok:
505
+ return self._load_json_data(r)
506
+ else:
507
+ exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content)
508
+ raise exc_cls(exc_msg)
509
+
510
+ def list_rse_usage_history(self, rse, filters=None):
511
+ """
512
+ List RSE usage history information.
513
+
514
+ :param rse: The RSE name.
515
+ :param filters: dictionary of attributes by which the results should be filtered.
516
+
517
+ :returns: list of dictionnaries.
518
+ """
519
+ path = [self.RSE_BASEURL, rse, 'usage', 'history']
520
+ path = '/'.join(path)
521
+ url = build_url(choice(self.list_hosts), path=path)
522
+ r = self._send_request(url, type_='GET', params=filters)
523
+ if r.status_code == codes.ok:
524
+ return self._load_json_data(r)
525
+ else:
526
+ exc_cls, exc_msg = self._get_exception(headers=r.headers,
527
+ status_code=r.status_code,
528
+ data=r.content)
529
+ raise exc_cls(exc_msg)
530
+
531
+ def set_rse_limits(self, rse, name, value):
532
+ """
533
+ Set RSE limit information.
534
+
535
+ :param rse: The RSE name.
536
+ :param name: The name of the limit.
537
+ :param value: The feature value.
538
+
539
+ :returns: True if successful, otherwise false.
540
+ """
541
+ path = [self.RSE_BASEURL, rse, 'limits']
542
+ path = '/'.join(path)
543
+ url = build_url(choice(self.list_hosts), path=path)
544
+ r = self._send_request(url, type_='PUT', data=dumps({'name': name, 'value': value}))
545
+ if r.status_code == codes.ok:
546
+ return True
547
+ exc_cls, exc_msg = self._get_exception(headers=r.headers,
548
+ status_code=r.status_code,
549
+ data=r.content)
550
+ raise exc_cls(exc_msg)
551
+
552
+ def get_rse_limits(self, rse):
553
+ """
554
+ Get RSE limits.
555
+
556
+ :param rse: The RSE name.
557
+
558
+ :returns: True if successful, otherwise false.
559
+ """
560
+ path = [self.RSE_BASEURL, rse, 'limits']
561
+ path = '/'.join(path)
562
+ url = build_url(choice(self.list_hosts), path=path)
563
+ r = self._send_request(url, type_='GET')
564
+ if r.status_code == codes.ok:
565
+ return next(self._load_json_data(r))
566
+ exc_cls, exc_msg = self._get_exception(headers=r.headers,
567
+ status_code=r.status_code,
568
+ data=r.content)
569
+ raise exc_cls(exc_msg)
570
+
571
+ def delete_rse_limits(self, rse, name):
572
+ """
573
+ Delete RSE limit information.
574
+
575
+ :param rse: The RSE name.
576
+ :param name: The name of the limit.
577
+
578
+ :returns: True if successful, otherwise false.
579
+ """
580
+ path = [self.RSE_BASEURL, rse, 'limits']
581
+ path = '/'.join(path)
582
+ url = build_url(choice(self.list_hosts), path=path)
583
+ r = self._send_request(url, type_='DEL', data=dumps({'name': name}))
584
+ if r.status_code == codes.ok:
585
+ return True
586
+ exc_cls, exc_msg = self._get_exception(headers=r.headers,
587
+ status_code=r.status_code,
588
+ data=r.content)
589
+
590
+ return exc_cls(exc_msg)
591
+
592
+ def add_distance(self, source, destination, parameters):
593
+ """
594
+ Add a src-dest distance.
595
+
596
+ :param source: The source.
597
+ :param destination: The destination.
598
+ :param parameters: A dictionnary with property.
599
+ """
600
+ path = [self.RSE_BASEURL, source, 'distances', destination]
601
+ path = '/'.join(path)
602
+ url = build_url(choice(self.list_hosts), path=path)
603
+ r = self._send_request(url, type_='POST', data=dumps(parameters))
604
+ if r.status_code == codes.created:
605
+ return True
606
+ exc_cls, exc_msg = self._get_exception(headers=r.headers,
607
+ status_code=r.status_code,
608
+ data=r.content)
609
+ raise exc_cls(exc_msg)
610
+
611
+ def update_distance(self, source, destination, parameters):
612
+ """
613
+ Update distances with the given RSE ids.
614
+
615
+ :param source: The source.
616
+ :param destination: The destination.
617
+ :param parameters: A dictionnary with property.
618
+ """
619
+ path = [self.RSE_BASEURL, source, 'distances', destination]
620
+ path = '/'.join(path)
621
+ url = build_url(choice(self.list_hosts), path=path)
622
+ r = self._send_request(url, type_='PUT', data=dumps(parameters))
623
+ if r.status_code == codes.ok:
624
+ return True
625
+ exc_cls, exc_msg = self._get_exception(headers=r.headers,
626
+ status_code=r.status_code,
627
+ data=r.content)
628
+ raise exc_cls(exc_msg)
629
+
630
+ def get_distance(self, source, destination):
631
+ """
632
+ Get distances between rses.
633
+
634
+ :param source: The source RSE.
635
+ :param destination: The destination RSE.
636
+
637
+ :returns distance: List of dictionaries.
638
+ """
639
+ path = [self.RSE_BASEURL, source, 'distances', destination]
640
+ path = '/'.join(path)
641
+ url = build_url(choice(self.list_hosts), path=path)
642
+ r = self._send_request(url, type_='GET')
643
+ if r.status_code == codes.ok:
644
+ return next(self._load_json_data(r))
645
+ exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content)
646
+ raise exc_cls(exc_msg)
647
+
648
+ def delete_distance(self, source, destination):
649
+ """
650
+ Delete distances with the given RSE ids.
651
+
652
+ :param source: The source.
653
+ :param destination: The destination.
654
+ """
655
+ path = [self.RSE_BASEURL, source, 'distances', destination]
656
+ path = '/'.join(path)
657
+ url = build_url(choice(self.list_hosts), path=path)
658
+ r = self._send_request(url, type_='DEL')
659
+ if r.status_code == codes.ok:
660
+ return True
661
+ exc_cls, exc_msg = self._get_exception(headers=r.headers,
662
+ status_code=r.status_code,
663
+ data=r.content)
664
+ raise exc_cls(exc_msg)