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