rucio-clients 35.8.2__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.
Files changed (88) hide show
  1. rucio/__init__.py +17 -0
  2. rucio/alembicrevision.py +15 -0
  3. rucio/client/__init__.py +15 -0
  4. rucio/client/accountclient.py +433 -0
  5. rucio/client/accountlimitclient.py +183 -0
  6. rucio/client/baseclient.py +974 -0
  7. rucio/client/client.py +76 -0
  8. rucio/client/configclient.py +126 -0
  9. rucio/client/credentialclient.py +59 -0
  10. rucio/client/didclient.py +866 -0
  11. rucio/client/diracclient.py +56 -0
  12. rucio/client/downloadclient.py +1785 -0
  13. rucio/client/exportclient.py +44 -0
  14. rucio/client/fileclient.py +50 -0
  15. rucio/client/importclient.py +42 -0
  16. rucio/client/lifetimeclient.py +90 -0
  17. rucio/client/lockclient.py +109 -0
  18. rucio/client/metaconventionsclient.py +140 -0
  19. rucio/client/pingclient.py +44 -0
  20. rucio/client/replicaclient.py +454 -0
  21. rucio/client/requestclient.py +125 -0
  22. rucio/client/rseclient.py +746 -0
  23. rucio/client/ruleclient.py +294 -0
  24. rucio/client/scopeclient.py +90 -0
  25. rucio/client/subscriptionclient.py +173 -0
  26. rucio/client/touchclient.py +82 -0
  27. rucio/client/uploadclient.py +955 -0
  28. rucio/common/__init__.py +13 -0
  29. rucio/common/cache.py +74 -0
  30. rucio/common/config.py +801 -0
  31. rucio/common/constants.py +159 -0
  32. rucio/common/constraints.py +17 -0
  33. rucio/common/didtype.py +189 -0
  34. rucio/common/exception.py +1151 -0
  35. rucio/common/extra.py +36 -0
  36. rucio/common/logging.py +420 -0
  37. rucio/common/pcache.py +1408 -0
  38. rucio/common/plugins.py +153 -0
  39. rucio/common/policy.py +84 -0
  40. rucio/common/schema/__init__.py +150 -0
  41. rucio/common/schema/atlas.py +413 -0
  42. rucio/common/schema/belleii.py +408 -0
  43. rucio/common/schema/domatpc.py +401 -0
  44. rucio/common/schema/escape.py +426 -0
  45. rucio/common/schema/generic.py +433 -0
  46. rucio/common/schema/generic_multi_vo.py +412 -0
  47. rucio/common/schema/icecube.py +406 -0
  48. rucio/common/stomp_utils.py +159 -0
  49. rucio/common/stopwatch.py +55 -0
  50. rucio/common/test_rucio_server.py +148 -0
  51. rucio/common/types.py +403 -0
  52. rucio/common/utils.py +2238 -0
  53. rucio/rse/__init__.py +96 -0
  54. rucio/rse/protocols/__init__.py +13 -0
  55. rucio/rse/protocols/bittorrent.py +184 -0
  56. rucio/rse/protocols/cache.py +122 -0
  57. rucio/rse/protocols/dummy.py +111 -0
  58. rucio/rse/protocols/gfal.py +703 -0
  59. rucio/rse/protocols/globus.py +243 -0
  60. rucio/rse/protocols/gsiftp.py +92 -0
  61. rucio/rse/protocols/http_cache.py +82 -0
  62. rucio/rse/protocols/mock.py +123 -0
  63. rucio/rse/protocols/ngarc.py +209 -0
  64. rucio/rse/protocols/posix.py +250 -0
  65. rucio/rse/protocols/protocol.py +594 -0
  66. rucio/rse/protocols/rclone.py +364 -0
  67. rucio/rse/protocols/rfio.py +136 -0
  68. rucio/rse/protocols/srm.py +338 -0
  69. rucio/rse/protocols/ssh.py +413 -0
  70. rucio/rse/protocols/storm.py +206 -0
  71. rucio/rse/protocols/webdav.py +550 -0
  72. rucio/rse/protocols/xrootd.py +301 -0
  73. rucio/rse/rsemanager.py +764 -0
  74. rucio/vcsversion.py +11 -0
  75. rucio/version.py +38 -0
  76. rucio_clients-35.8.2.data/data/etc/rse-accounts.cfg.template +25 -0
  77. rucio_clients-35.8.2.data/data/etc/rucio.cfg.atlas.client.template +42 -0
  78. rucio_clients-35.8.2.data/data/etc/rucio.cfg.template +257 -0
  79. rucio_clients-35.8.2.data/data/requirements.client.txt +15 -0
  80. rucio_clients-35.8.2.data/data/rucio_client/merge_rucio_configs.py +144 -0
  81. rucio_clients-35.8.2.data/scripts/rucio +2542 -0
  82. rucio_clients-35.8.2.data/scripts/rucio-admin +2447 -0
  83. rucio_clients-35.8.2.dist-info/METADATA +50 -0
  84. rucio_clients-35.8.2.dist-info/RECORD +88 -0
  85. rucio_clients-35.8.2.dist-info/WHEEL +5 -0
  86. rucio_clients-35.8.2.dist-info/licenses/AUTHORS.rst +97 -0
  87. rucio_clients-35.8.2.dist-info/licenses/LICENSE +201 -0
  88. rucio_clients-35.8.2.dist-info/top_level.txt +1 -0
rucio/__init__.py ADDED
@@ -0,0 +1,17 @@
1
+ # Copyright European Organization for Nuclear Research (CERN) since 2012
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import gettext
16
+
17
+ gettext.install('rucio')
@@ -0,0 +1,15 @@
1
+ # Copyright European Organization for Nuclear Research (CERN) since 2012
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ ALEMBIC_REVISION = 'b0070f3695c8' # the current alembic head revision
@@ -0,0 +1,15 @@
1
+ # Copyright European Organization for Nuclear Research (CERN) since 2012
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from .client import Client # noqa: F401
@@ -0,0 +1,433 @@
1
+ # Copyright European Organization for Nuclear Research (CERN) since 2012
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from json import dumps
16
+ from typing import TYPE_CHECKING, Any, Optional
17
+ from urllib.parse import quote_plus
18
+
19
+ from requests.status_codes import codes
20
+
21
+ from rucio.client.baseclient import BaseClient, choice
22
+ from rucio.common.utils import build_url
23
+
24
+ if TYPE_CHECKING:
25
+ from collections.abc import Iterator
26
+
27
+
28
+ class AccountClient(BaseClient):
29
+
30
+ """Account client class for working with rucio accounts"""
31
+
32
+ ACCOUNTS_BASEURL = 'accounts'
33
+
34
+ def add_account(self, account: str, type_: str, email: str) -> bool:
35
+ """
36
+ Sends the request to create a new account.
37
+
38
+ :param account: the name of the account.
39
+ :param type_: The account type
40
+ :param email: The Email address associated with the account.
41
+
42
+ :return: True if account was created successfully else False.
43
+ :raises Duplicate: if account already exists.
44
+ """
45
+
46
+ data = dumps({'type': type_, 'email': email})
47
+ path = '/'.join([self.ACCOUNTS_BASEURL, account])
48
+ url = build_url(choice(self.list_hosts), path=path)
49
+
50
+ res = self._send_request(url, type_='POST', data=data)
51
+ if res.status_code == codes.created:
52
+ return True
53
+ exc_cls, exc_msg = self._get_exception(headers=res.headers, status_code=res.status_code, data=res.content)
54
+ raise exc_cls(exc_msg)
55
+
56
+ def delete_account(self, account: str) -> bool:
57
+ """
58
+ Sends the request to disable an account.
59
+
60
+ :param account: the name of the account.
61
+ :return: True is account was disabled successfully. False otherwise.
62
+ :raises AccountNotFound: if account doesn't exist.
63
+ """
64
+
65
+ path = '/'.join([self.ACCOUNTS_BASEURL, account])
66
+ url = build_url(choice(self.list_hosts), path=path)
67
+
68
+ res = self._send_request(url, type_='DEL')
69
+
70
+ if res.status_code == codes.ok:
71
+ return True
72
+ exc_cls, exc_msg = self._get_exception(headers=res.headers, status_code=res.status_code, data=res.content)
73
+ raise exc_cls(exc_msg)
74
+
75
+ def get_account(self, account: str) -> Optional[dict[str, Any]]:
76
+ """
77
+ Sends the request to get information about a given account.
78
+
79
+ :param account: the name of the account.
80
+ :return: a list of attributes for the account. None if failure.
81
+ :raises AccountNotFound: if account doesn't exist.
82
+ """
83
+
84
+ path = '/'.join([self.ACCOUNTS_BASEURL, account])
85
+ url = build_url(choice(self.list_hosts), path=path)
86
+
87
+ res = self._send_request(url)
88
+ if res.status_code == codes.ok:
89
+ acc = self._load_json_data(res)
90
+ return next(acc)
91
+ exc_cls, exc_msg = self._get_exception(headers=res.headers, status_code=res.status_code, data=res.content)
92
+ raise exc_cls(exc_msg)
93
+
94
+ def update_account(self, account: str, key: str, value: Any) -> bool:
95
+ """ Update a property of an account.
96
+
97
+ :param account: Name of the account.
98
+ :param key: Account property like status.
99
+ :param value: Property value.
100
+ """
101
+ data = dumps({key: value})
102
+ path = '/'.join([self.ACCOUNTS_BASEURL, account])
103
+ url = build_url(choice(self.list_hosts), path=path)
104
+
105
+ res = self._send_request(url, type_='PUT', data=data)
106
+
107
+ if res.status_code == codes.ok:
108
+ return True
109
+ else:
110
+ exc_cls, exc_msg = self._get_exception(headers=res.headers, status_code=res.status_code, data=res.content)
111
+ raise exc_cls(exc_msg)
112
+
113
+ def list_accounts(
114
+ self,
115
+ account_type: Optional[str] = None,
116
+ identity: Optional[str] = None,
117
+ filters: Optional[dict[str, Any]] = None
118
+ ) -> "Iterator[dict[str, Any]]":
119
+ """
120
+ Sends the request to list all rucio accounts.
121
+
122
+ :param type: The account type
123
+ :param identity: The identity key name. For example x509 DN, or a username.
124
+ :param filters: A dictionary key:account attribute to use for the filtering
125
+
126
+ :return: a list containing account info dictionary for all rucio accounts.
127
+ :raises AccountNotFound: if account doesn't exist.
128
+ """
129
+ path = '/'.join([self.ACCOUNTS_BASEURL])
130
+ url = build_url(choice(self.list_hosts), path=path)
131
+ params = {}
132
+ if account_type:
133
+ params['account_type'] = account_type
134
+ if identity:
135
+ params['identity'] = identity
136
+ if filters:
137
+ for key in filters:
138
+ params[key] = filters[key]
139
+
140
+ res = self._send_request(url, params=params)
141
+
142
+ if res.status_code == codes.ok:
143
+ accounts = self._load_json_data(res)
144
+ return accounts
145
+ else:
146
+ exc_cls, exc_msg = self._get_exception(headers=res.headers, status_code=res.status_code, data=res.content)
147
+ raise exc_cls(exc_msg)
148
+
149
+ def whoami(self) -> Optional[dict[str, Any]]:
150
+ """
151
+ Get information about account whose token is used
152
+
153
+ :return: a list of attributes for the account. None if failure.
154
+ :raises AccountNotFound: if account doesn't exist.
155
+ """
156
+ return self.get_account('whoami')
157
+
158
+ def add_identity(
159
+ self,
160
+ account: str,
161
+ identity: str,
162
+ authtype: str,
163
+ email: str,
164
+ default: bool = False,
165
+ password: Optional[str] = None
166
+ ) -> bool:
167
+ """
168
+ Adds a membership association between identity and account.
169
+
170
+ :param account: The account name.
171
+ :param identity: The identity key name. For example x509 DN, or a username.
172
+ :param authtype: The type of the authentication (x509, gss, userpass).
173
+ :param default: If True, the account should be used by default with the provided identity.
174
+ :param email: The Email address associated with the identity.
175
+ :param password: Password if authtype is userpass.
176
+ """
177
+
178
+ data = dumps({'identity': identity, 'authtype': authtype, 'default': default, 'email': email, 'password': password})
179
+ path = '/'.join([self.ACCOUNTS_BASEURL, account, 'identities'])
180
+
181
+ url = build_url(choice(self.list_hosts), path=path)
182
+
183
+ res = self._send_request(url, type_='POST', data=data)
184
+
185
+ if res.status_code == codes.created:
186
+ return True
187
+ else:
188
+ exc_cls, exc_msg = self._get_exception(headers=res.headers, status_code=res.status_code, data=res.content)
189
+ raise exc_cls(exc_msg)
190
+
191
+ def del_identity(
192
+ self,
193
+ account: str,
194
+ identity: str,
195
+ authtype: str
196
+ ) -> bool:
197
+ """
198
+ Delete an identity's membership association with an account.
199
+
200
+ :param account: The account name.
201
+ :param identity: The identity key name. For example x509 DN, or a username.
202
+ :param authtype: The type of the authentication (x509, gss, userpass).
203
+ :param default: If True, the account should be used by default with the provided identity.
204
+ """
205
+
206
+ data = dumps({'identity': identity, 'authtype': authtype})
207
+ path = '/'.join([self.ACCOUNTS_BASEURL, account, 'identities'])
208
+
209
+ url = build_url(choice(self.list_hosts), path=path)
210
+
211
+ res = self._send_request(url, type_='DEL', data=data)
212
+
213
+ if res.status_code == codes.ok:
214
+ return True
215
+ else:
216
+ exc_cls, exc_msg = self._get_exception(headers=res.headers, status_code=res.status_code, data=res.content)
217
+ raise exc_cls(exc_msg)
218
+
219
+ def list_identities(self, account: str) -> "Iterator[dict[str, Any]]":
220
+ """
221
+ List all identities on an account.
222
+
223
+ :param account: The account name.
224
+ """
225
+ path = '/'.join([self.ACCOUNTS_BASEURL, account, 'identities'])
226
+ url = build_url(choice(self.list_hosts), path=path)
227
+ res = self._send_request(url)
228
+ if res.status_code == codes.ok:
229
+ identities = self._load_json_data(res)
230
+ return identities
231
+ else:
232
+ exc_cls, exc_msg = self._get_exception(headers=res.headers, status_code=res.status_code, data=res.content)
233
+ raise exc_cls(exc_msg)
234
+
235
+ def list_account_rules(self, account: str) -> "Iterator[dict[str, Any]]":
236
+ """
237
+ List the associated rules of an account.
238
+
239
+ :param account: The account name.
240
+ """
241
+
242
+ path = '/'.join([self.ACCOUNTS_BASEURL, account, 'rules'])
243
+ url = build_url(choice(self.list_hosts), path=path)
244
+ res = self._send_request(url, type_='GET')
245
+ if res.status_code == codes.ok:
246
+ return self._load_json_data(res)
247
+ else:
248
+ exc_cls, exc_msg = self._get_exception(headers=res.headers, status_code=res.status_code, data=res.content)
249
+ raise exc_cls(exc_msg)
250
+
251
+ def get_account_limits(self, account: str, rse_expression: str, locality: str) -> dict[str, Any]:
252
+ """
253
+ Return the correct account limits for the given locality.
254
+
255
+ :param account: The account name.
256
+ :param rse_expression: Valid RSE expression
257
+ :param locality: The scope of the account limit. 'local' or 'global'.
258
+ """
259
+
260
+ if locality == 'local':
261
+ return self.get_local_account_limit(account, rse_expression)
262
+ elif locality == 'global':
263
+ return self.get_global_account_limit(account, rse_expression)
264
+ else:
265
+ from rucio.common.exception import UnsupportedOperation
266
+ raise UnsupportedOperation('The provided locality (%s) for the account limit was invalid' % locality)
267
+
268
+ def get_global_account_limit(self, account: str, rse_expression: str) -> dict[str, Any]:
269
+ """
270
+ List the account limit for the specific RSE expression.
271
+
272
+ :param account: The account name.
273
+ :param rse_expression: The rse expression.
274
+ """
275
+
276
+ path = '/'.join([self.ACCOUNTS_BASEURL, account, 'limits', 'global', quote_plus(rse_expression)])
277
+ url = build_url(choice(self.list_hosts), path=path)
278
+ res = self._send_request(url, type_='GET')
279
+ if res.status_code == codes.ok:
280
+ return next(self._load_json_data(res))
281
+ exc_cls, exc_msg = self._get_exception(headers=res.headers, status_code=res.status_code, data=res.content)
282
+ raise exc_cls(exc_msg)
283
+
284
+ def get_global_account_limits(self, account: str) -> dict[str, Any]:
285
+ """
286
+ List all RSE expression limits of this account.
287
+
288
+ :param account: The account name.
289
+ """
290
+
291
+ path = '/'.join([self.ACCOUNTS_BASEURL, account, 'limits', 'global'])
292
+ url = build_url(choice(self.list_hosts), path=path)
293
+ res = self._send_request(url, type_='GET')
294
+ if res.status_code == codes.ok:
295
+ return next(self._load_json_data(res))
296
+ exc_cls, exc_msg = self._get_exception(headers=res.headers, status_code=res.status_code, data=res.content)
297
+ raise exc_cls(exc_msg)
298
+
299
+ def get_local_account_limits(self, account: str) -> dict[str, Any]:
300
+ """
301
+ List the account rse limits of this account.
302
+
303
+ :param account: The account name.
304
+ """
305
+
306
+ path = '/'.join([self.ACCOUNTS_BASEURL, account, 'limits', 'local'])
307
+ url = build_url(choice(self.list_hosts), path=path)
308
+ res = self._send_request(url, type_='GET')
309
+ if res.status_code == codes.ok:
310
+ return next(self._load_json_data(res))
311
+ exc_cls, exc_msg = self._get_exception(headers=res.headers, status_code=res.status_code, data=res.content)
312
+ raise exc_cls(exc_msg)
313
+
314
+ def get_local_account_limit(self, account: str, rse: str) -> dict[str, Any]:
315
+ """
316
+ List the account rse limits of this account for the specific rse.
317
+
318
+ :param account: The account name.
319
+ :param rse: The rse name.
320
+ """
321
+
322
+ path = '/'.join([self.ACCOUNTS_BASEURL, account, 'limits', 'local', rse])
323
+ url = build_url(choice(self.list_hosts), path=path)
324
+ res = self._send_request(url, type_='GET')
325
+ if res.status_code == codes.ok:
326
+ return next(self._load_json_data(res))
327
+ exc_cls, exc_msg = self._get_exception(headers=res.headers, status_code=res.status_code, data=res.content)
328
+ raise exc_cls(exc_msg)
329
+
330
+ def get_local_account_usage(self, account: str, rse: Optional[str] = None) -> "Iterator[dict[str, Any]]":
331
+ """
332
+ List the account usage for one or all rses of this account.
333
+
334
+ :param account: The account name.
335
+ :param rse: The rse name.
336
+ """
337
+ if rse:
338
+ path = '/'.join([self.ACCOUNTS_BASEURL, account, 'usage', 'local', rse])
339
+ else:
340
+ path = '/'.join([self.ACCOUNTS_BASEURL, account, 'usage', 'local'])
341
+ url = build_url(choice(self.list_hosts), path=path)
342
+ res = self._send_request(url, type_='GET')
343
+ if res.status_code == codes.ok:
344
+ return self._load_json_data(res)
345
+ else:
346
+ exc_cls, exc_msg = self._get_exception(headers=res.headers, status_code=res.status_code, data=res.content)
347
+ raise exc_cls(exc_msg)
348
+
349
+ def get_global_account_usage(self, account: str, rse_expression: Optional[str] = None) -> "Iterator[dict[str, Any]]":
350
+ """
351
+ List the account usage for one or all RSE expressions of this account.
352
+
353
+ :param account: The account name.
354
+ :param rse_expression: The rse expression.
355
+ """
356
+ if rse_expression:
357
+ path = '/'.join([self.ACCOUNTS_BASEURL, account, 'usage', 'global', quote_plus(rse_expression)])
358
+ else:
359
+ path = '/'.join([self.ACCOUNTS_BASEURL, account, 'usage', 'global'])
360
+ url = build_url(choice(self.list_hosts), path=path)
361
+ res = self._send_request(url, type_='GET')
362
+ if res.status_code == codes.ok:
363
+ return self._load_json_data(res)
364
+ else:
365
+ exc_cls, exc_msg = self._get_exception(headers=res.headers, status_code=res.status_code, data=res.content)
366
+ raise exc_cls(exc_msg)
367
+
368
+ def get_account_usage_history(self, account: str, rse: str) -> dict[str, Any]:
369
+ """
370
+ List the account usage history of this account on rse.
371
+
372
+ :param account: The account name.
373
+ :param rse: The rse name.
374
+ """
375
+ path = '/'.join([self.ACCOUNTS_BASEURL, account, 'usage/history', rse])
376
+ url = build_url(choice(self.list_hosts), path=path)
377
+ res = self._send_request(url, type_='GET')
378
+ if res.status_code == codes.ok:
379
+ return next(self._load_json_data(res))
380
+ else:
381
+ exc_cls, exc_msg = self._get_exception(headers=res.headers, status_code=res.status_code, data=res.content)
382
+ raise exc_cls(exc_msg)
383
+
384
+ def list_account_attributes(self, account: str) -> "Iterator[dict[dict[str, Any], Any]]":
385
+ """
386
+ List the attributes for an account.
387
+
388
+ :param account: The account name.
389
+ """
390
+ path = '/'.join([self.ACCOUNTS_BASEURL, account, 'attr/'])
391
+ url = build_url(choice(self.list_hosts), path=path)
392
+ res = self._send_request(url, type_='GET')
393
+ if res.status_code == codes.ok:
394
+ return self._load_json_data(res)
395
+ else:
396
+ exc_cls, exc_msg = self._get_exception(headers=res.headers, status_code=res.status_code, data=res.content)
397
+ raise exc_cls(exc_msg)
398
+
399
+ def add_account_attribute(self, account: str, key: str, value: Any) -> bool:
400
+ """
401
+ Adds an attribute to an account.
402
+
403
+ :param account: The account name.
404
+ :param key: The attribute key.
405
+ :param value: The attribute value.
406
+ """
407
+
408
+ data = dumps({'key': key, 'value': value})
409
+ path = '/'.join([self.ACCOUNTS_BASEURL, account, 'attr', key])
410
+ url = build_url(choice(self.list_hosts), path=path)
411
+ res = self._send_request(url, type_='POST', data=data)
412
+ if res.status_code == codes.created:
413
+ return True
414
+ else:
415
+ exc_cls, exc_msg = self._get_exception(headers=res.headers, status_code=res.status_code, data=res.content)
416
+ raise exc_cls(exc_msg)
417
+
418
+ def delete_account_attribute(self, account: str, key: str) -> bool:
419
+ """
420
+ Delete an attribute for an account.
421
+
422
+ :param account: The account name.
423
+ :param key: The attribute key.
424
+ """
425
+
426
+ path = '/'.join([self.ACCOUNTS_BASEURL, account, 'attr', key])
427
+ url = build_url(choice(self.list_hosts), path=path)
428
+ res = self._send_request(url, type_='DEL', data=None)
429
+ if res.status_code == codes.ok:
430
+ return True
431
+ else:
432
+ exc_cls, exc_msg = self._get_exception(headers=res.headers, status_code=res.status_code, data=res.content)
433
+ raise exc_cls(exc_msg)
@@ -0,0 +1,183 @@
1
+ # Copyright European Organization for Nuclear Research (CERN) since 2012
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from json import dumps
16
+ from typing import Literal
17
+ from urllib.parse import quote_plus
18
+
19
+ from requests.status_codes import codes
20
+
21
+ from rucio.client.baseclient import BaseClient, choice
22
+ from rucio.common.utils import build_url
23
+
24
+
25
+ class AccountLimitClient(BaseClient):
26
+
27
+ """Account limit client class for working with account limits"""
28
+
29
+ ACCOUNTLIMIT_BASEURL = 'accountlimits'
30
+
31
+ def set_account_limit(
32
+ self,
33
+ account: str,
34
+ rse: str,
35
+ bytes_: int,
36
+ locality: Literal['local', 'global']
37
+ ) -> bool:
38
+ """
39
+ Sets an account limit for a given limit scope.
40
+
41
+ :param account: The name of the account.
42
+ :param rse: The rse name.
43
+ :param bytes_: An integer with the limit in bytes.
44
+ :param locality: The scope of the account limit. 'local' or 'global'.
45
+ :return: True if quota was created successfully else False.
46
+ """
47
+
48
+ if locality == 'local':
49
+ return self.set_local_account_limit(account, rse, bytes_)
50
+ elif locality == 'global':
51
+ return self.set_global_account_limit(account, rse, bytes_)
52
+ else:
53
+ from rucio.common.exception import UnsupportedOperation
54
+ raise UnsupportedOperation('The provided scope (%s) for the account limit was invalid' % locality)
55
+
56
+ def delete_account_limit(
57
+ self,
58
+ account: str,
59
+ rse: str,
60
+ locality: Literal['local', 'global']
61
+ ) -> bool:
62
+ """
63
+ Deletes an account limit for a given limit scope.
64
+
65
+ :param account: The name of the account.
66
+ :param rse: The rse name.
67
+ :param locality: The scope of the account limit. 'local' or 'global'.
68
+ :return: True if quota was created successfully else False.
69
+ """
70
+
71
+ if locality == 'local':
72
+ return self.delete_local_account_limit(account, rse)
73
+ elif locality == 'global':
74
+ return self.delete_global_account_limit(account, rse)
75
+ else:
76
+ from rucio.common.exception import UnsupportedOperation
77
+ raise UnsupportedOperation('The provided scope (%s) for the account limit was invalid' % locality)
78
+
79
+ def set_local_account_limit(
80
+ self,
81
+ account: str,
82
+ rse: str,
83
+ bytes_: int
84
+ ) -> bool:
85
+ """
86
+ Sends the request to set an account limit for an account.
87
+
88
+ :param account: The name of the account.
89
+ :param rse: The rse name.
90
+ :param bytes_: An integer with the limit in bytes.
91
+ :return: True if quota was created successfully else False.
92
+ """
93
+
94
+ data = dumps({'bytes': bytes_})
95
+ path = '/'.join([self.ACCOUNTLIMIT_BASEURL, 'local', account, rse])
96
+ url = build_url(choice(self.list_hosts), path=path)
97
+
98
+ r = self._send_request(url, type_='POST', data=data)
99
+
100
+ if r.status_code == codes.created:
101
+ return True
102
+ else:
103
+ exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content)
104
+ raise exc_cls(exc_msg)
105
+
106
+ def delete_local_account_limit(
107
+ self,
108
+ account: str,
109
+ rse: str
110
+ ) -> bool:
111
+ """
112
+ Sends the request to remove an account limit.
113
+
114
+ :param account: The name of the account.
115
+ :param rse: The rse name.
116
+
117
+ :return: True if quota was removed successfully. False otherwise.
118
+ :raises AccountNotFound: if account doesn't exist.
119
+ """
120
+
121
+ path = '/'.join([self.ACCOUNTLIMIT_BASEURL, 'local', account, rse])
122
+ url = build_url(choice(self.list_hosts), path=path)
123
+
124
+ r = self._send_request(url, type_='DEL')
125
+
126
+ if r.status_code == codes.ok:
127
+ return True
128
+ else:
129
+ exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content)
130
+ raise exc_cls(exc_msg)
131
+
132
+ def set_global_account_limit(
133
+ self,
134
+ account: str,
135
+ rse_expression: str,
136
+ bytes_: int
137
+ ) -> bool:
138
+ """
139
+ Sends the request to set a global account limit for an account.
140
+
141
+ :param account: The name of the account.
142
+ :param rse_expression: The rse expression.
143
+ :param bytes_: An integer with the limit in bytes.
144
+ :return: True if quota was created successfully else False.
145
+ """
146
+
147
+ data = dumps({'bytes': bytes_})
148
+ path = '/'.join([self.ACCOUNTLIMIT_BASEURL, 'global', account, quote_plus(rse_expression)])
149
+ url = build_url(choice(self.list_hosts), path=path)
150
+
151
+ r = self._send_request(url, type_='POST', data=data)
152
+
153
+ if r.status_code == codes.created:
154
+ return True
155
+ else:
156
+ exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content)
157
+ raise exc_cls(exc_msg)
158
+
159
+ def delete_global_account_limit(
160
+ self,
161
+ account: str,
162
+ rse_expression: str
163
+ ) -> bool:
164
+ """
165
+ Sends the request to remove a global account limit.
166
+
167
+ :param account: The name of the account.
168
+ :param rse_expression: The rse expression.
169
+
170
+ :return: True if quota was removed successfully. False otherwise.
171
+ :raises AccountNotFound: if account doesn't exist.
172
+ """
173
+
174
+ path = '/'.join([self.ACCOUNTLIMIT_BASEURL, 'global', account, quote_plus(rse_expression)])
175
+ url = build_url(choice(self.list_hosts), path=path)
176
+
177
+ r = self._send_request(url, type_='DEL')
178
+
179
+ if r.status_code == codes.ok:
180
+ return True
181
+ else:
182
+ exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content)
183
+ raise exc_cls(exc_msg)