rucio-clients 37.0.0rc1__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 (104) hide show
  1. rucio/__init__.py +17 -0
  2. rucio/alembicrevision.py +15 -0
  3. rucio/cli/__init__.py +14 -0
  4. rucio/cli/account.py +216 -0
  5. rucio/cli/bin_legacy/__init__.py +13 -0
  6. rucio/cli/bin_legacy/rucio.py +2825 -0
  7. rucio/cli/bin_legacy/rucio_admin.py +2500 -0
  8. rucio/cli/command.py +272 -0
  9. rucio/cli/config.py +72 -0
  10. rucio/cli/did.py +191 -0
  11. rucio/cli/download.py +128 -0
  12. rucio/cli/lifetime_exception.py +33 -0
  13. rucio/cli/replica.py +162 -0
  14. rucio/cli/rse.py +293 -0
  15. rucio/cli/rule.py +158 -0
  16. rucio/cli/scope.py +40 -0
  17. rucio/cli/subscription.py +73 -0
  18. rucio/cli/upload.py +60 -0
  19. rucio/cli/utils.py +226 -0
  20. rucio/client/__init__.py +15 -0
  21. rucio/client/accountclient.py +432 -0
  22. rucio/client/accountlimitclient.py +183 -0
  23. rucio/client/baseclient.py +983 -0
  24. rucio/client/client.py +120 -0
  25. rucio/client/configclient.py +126 -0
  26. rucio/client/credentialclient.py +59 -0
  27. rucio/client/didclient.py +868 -0
  28. rucio/client/diracclient.py +56 -0
  29. rucio/client/downloadclient.py +1783 -0
  30. rucio/client/exportclient.py +44 -0
  31. rucio/client/fileclient.py +50 -0
  32. rucio/client/importclient.py +42 -0
  33. rucio/client/lifetimeclient.py +90 -0
  34. rucio/client/lockclient.py +109 -0
  35. rucio/client/metaconventionsclient.py +140 -0
  36. rucio/client/pingclient.py +44 -0
  37. rucio/client/replicaclient.py +452 -0
  38. rucio/client/requestclient.py +125 -0
  39. rucio/client/richclient.py +317 -0
  40. rucio/client/rseclient.py +746 -0
  41. rucio/client/ruleclient.py +294 -0
  42. rucio/client/scopeclient.py +90 -0
  43. rucio/client/subscriptionclient.py +173 -0
  44. rucio/client/touchclient.py +82 -0
  45. rucio/client/uploadclient.py +969 -0
  46. rucio/common/__init__.py +13 -0
  47. rucio/common/bittorrent.py +234 -0
  48. rucio/common/cache.py +111 -0
  49. rucio/common/checksum.py +168 -0
  50. rucio/common/client.py +122 -0
  51. rucio/common/config.py +788 -0
  52. rucio/common/constants.py +217 -0
  53. rucio/common/constraints.py +17 -0
  54. rucio/common/didtype.py +237 -0
  55. rucio/common/exception.py +1208 -0
  56. rucio/common/extra.py +31 -0
  57. rucio/common/logging.py +420 -0
  58. rucio/common/pcache.py +1409 -0
  59. rucio/common/plugins.py +185 -0
  60. rucio/common/policy.py +93 -0
  61. rucio/common/schema/__init__.py +200 -0
  62. rucio/common/schema/generic.py +416 -0
  63. rucio/common/schema/generic_multi_vo.py +395 -0
  64. rucio/common/stomp_utils.py +423 -0
  65. rucio/common/stopwatch.py +55 -0
  66. rucio/common/test_rucio_server.py +154 -0
  67. rucio/common/types.py +483 -0
  68. rucio/common/utils.py +1688 -0
  69. rucio/rse/__init__.py +96 -0
  70. rucio/rse/protocols/__init__.py +13 -0
  71. rucio/rse/protocols/bittorrent.py +194 -0
  72. rucio/rse/protocols/cache.py +111 -0
  73. rucio/rse/protocols/dummy.py +100 -0
  74. rucio/rse/protocols/gfal.py +708 -0
  75. rucio/rse/protocols/globus.py +243 -0
  76. rucio/rse/protocols/http_cache.py +82 -0
  77. rucio/rse/protocols/mock.py +123 -0
  78. rucio/rse/protocols/ngarc.py +209 -0
  79. rucio/rse/protocols/posix.py +250 -0
  80. rucio/rse/protocols/protocol.py +361 -0
  81. rucio/rse/protocols/rclone.py +365 -0
  82. rucio/rse/protocols/rfio.py +145 -0
  83. rucio/rse/protocols/srm.py +338 -0
  84. rucio/rse/protocols/ssh.py +414 -0
  85. rucio/rse/protocols/storm.py +195 -0
  86. rucio/rse/protocols/webdav.py +594 -0
  87. rucio/rse/protocols/xrootd.py +302 -0
  88. rucio/rse/rsemanager.py +881 -0
  89. rucio/rse/translation.py +260 -0
  90. rucio/vcsversion.py +11 -0
  91. rucio/version.py +45 -0
  92. rucio_clients-37.0.0rc1.data/data/etc/rse-accounts.cfg.template +25 -0
  93. rucio_clients-37.0.0rc1.data/data/etc/rucio.cfg.atlas.client.template +43 -0
  94. rucio_clients-37.0.0rc1.data/data/etc/rucio.cfg.template +241 -0
  95. rucio_clients-37.0.0rc1.data/data/requirements.client.txt +19 -0
  96. rucio_clients-37.0.0rc1.data/data/rucio_client/merge_rucio_configs.py +144 -0
  97. rucio_clients-37.0.0rc1.data/scripts/rucio +133 -0
  98. rucio_clients-37.0.0rc1.data/scripts/rucio-admin +97 -0
  99. rucio_clients-37.0.0rc1.dist-info/METADATA +54 -0
  100. rucio_clients-37.0.0rc1.dist-info/RECORD +104 -0
  101. rucio_clients-37.0.0rc1.dist-info/WHEEL +5 -0
  102. rucio_clients-37.0.0rc1.dist-info/licenses/AUTHORS.rst +100 -0
  103. rucio_clients-37.0.0rc1.dist-info/licenses/LICENSE +201 -0
  104. rucio_clients-37.0.0rc1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,594 @@
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 logging
16
+ import os
17
+ import sys
18
+ from dataclasses import dataclass
19
+ from typing import Any, Optional
20
+ from urllib.parse import urlparse
21
+ from xml.etree import ElementTree
22
+
23
+ import requests
24
+ from requests.adapters import HTTPAdapter
25
+ from urllib3.poolmanager import PoolManager
26
+
27
+ from rucio.common import exception
28
+ from rucio.rse.protocols import protocol
29
+
30
+
31
+ class TLSHTTPAdapter(HTTPAdapter):
32
+ '''
33
+ Class to force the SSL protocol to latest TLS
34
+ '''
35
+ def init_poolmanager(self, connections, maxsize, block=False):
36
+ self.poolmanager = PoolManager(num_pools=connections,
37
+ maxsize=maxsize,
38
+ block=block,
39
+ cert_reqs="CERT_REQUIRED",
40
+ ca_cert_dir="/etc/grid-security/certificates")
41
+
42
+
43
+ class UploadInChunks:
44
+ '''
45
+ Class to upload by chunks.
46
+ '''
47
+
48
+ def __init__(self, filename, chunksize, progressbar=False):
49
+ self.__totalsize = os.path.getsize(filename)
50
+ self.__readsofar = 0
51
+ self.__filename = filename
52
+ self.__chunksize = chunksize
53
+ self.__progressbar = progressbar
54
+
55
+ def __iter__(self):
56
+ try:
57
+ with open(self.__filename, 'rb') as file_in:
58
+ while True:
59
+ data = file_in.read(self.__chunksize)
60
+ if not data:
61
+ if self.__progressbar:
62
+ sys.stdout.write("\n")
63
+ break
64
+ self.__readsofar += len(data)
65
+ if self.__progressbar:
66
+ percent = self.__readsofar * 100 / self.__totalsize
67
+ sys.stdout.write("\r{percent:3.0f}%".format(percent=percent))
68
+ yield data
69
+ except OSError as error:
70
+ raise exception.SourceNotFound(error)
71
+
72
+ def __len__(self):
73
+ return self.__totalsize
74
+
75
+
76
+ class IterableToFileAdapter:
77
+ '''
78
+ Class IterableToFileAdapter
79
+ '''
80
+ def __init__(self, iterable):
81
+ self.iterator = iter(iterable)
82
+ self.length = len(iterable)
83
+
84
+ def read(self, size=-1): # TBD: add buffer for `len(data) > size` case
85
+ nextvar = next(self.iterator, b'')
86
+ return nextvar
87
+
88
+ def __len__(self):
89
+ return self.length
90
+
91
+
92
+ @dataclass(frozen=True)
93
+ class _PropfindFile:
94
+ """Contains the properties of one file from a PROPFIND response."""
95
+
96
+ href: str
97
+ size: Optional[int]
98
+
99
+ @classmethod
100
+ def from_xml_node(cls, node: ElementTree.Element):
101
+ """Extract file properties from a `<{DAV:}response>` node."""
102
+
103
+ xml_href = node.find('./{DAV:}href')
104
+ if xml_href is None or xml_href.text is None:
105
+ raise ValueError('Response is missing mandatory field "href".')
106
+ else:
107
+ href = xml_href.text
108
+
109
+ xml_size = node.find('./{DAV:}propstat/{DAV:}prop/{DAV:}getcontentlength')
110
+ if xml_size is None or xml_size.text is None:
111
+ size = None
112
+ else:
113
+ size = int(xml_size.text)
114
+
115
+ return cls(href=href, size=size) # type: ignore
116
+
117
+
118
+ @dataclass(frozen=True)
119
+ class _PropfindResponse:
120
+ """Contains all the files from a PROPFIND response."""
121
+
122
+ files: tuple[_PropfindFile]
123
+
124
+ @classmethod
125
+ def parse(cls, document: str):
126
+ """Parses the XML document of a WebDAV PROPFIND response.
127
+
128
+ The PROPFIND response is described in RFC 4918.
129
+ This method expects the document root to be a node with tag `{DAV:}multistatus`.
130
+
131
+ :param document: XML document to parse.
132
+ :raises ValueError: if the XML document couldn't be parsed.
133
+ :returns: The parsed response.
134
+ """
135
+
136
+ try:
137
+ xml = ElementTree.fromstring(document) # noqa: S314
138
+ except ElementTree.ParseError as ex:
139
+ raise ValueError("Couldn't parse XML document") from ex
140
+
141
+ if xml.tag != '{DAV:}multistatus':
142
+ raise ValueError('Root element is not "{DAV:}multistatus".')
143
+
144
+ files = []
145
+ for xml_response in xml.findall('./{DAV:}response'):
146
+ files.append(_PropfindFile.from_xml_node(xml_response))
147
+
148
+ return cls(files=tuple(files)) # type: ignore
149
+
150
+
151
+ class Default(protocol.RSEProtocol):
152
+
153
+ """ Implementing access to RSEs using the webDAV protocol."""
154
+
155
+ def connect(self, credentials: Optional[dict[str, Any]] = None) -> None:
156
+ """ Establishes the actual connection to the referred RSE.
157
+
158
+ :param credentials: Provides information to establish a connection
159
+ to the referred storage system. For WebDAV connections these are
160
+ ca_cert, cert, auth_type, timeout
161
+
162
+ :raises RSEAccessDenied
163
+ """
164
+ credentials = credentials or {}
165
+ using_presigned_urls = self.rse['sign_url'] is not None
166
+ try:
167
+ parse_url = urlparse(self.path2pfn(''))
168
+ self.server = f'{parse_url.scheme}://{parse_url.netloc}'
169
+ except KeyError:
170
+ raise exception.RSEAccessDenied('No specified Server')
171
+
172
+ try:
173
+ self.ca_cert = credentials['ca_cert']
174
+ except KeyError:
175
+ self.ca_cert = None
176
+
177
+ try:
178
+ self.auth_type = credentials['auth_type']
179
+ except KeyError:
180
+ self.auth_type = 'cert'
181
+
182
+ if using_presigned_urls:
183
+ # Suppress all authentication, otherwise S3 servers will reject
184
+ # requests.
185
+ self.cert = None
186
+ self.auth_token = None
187
+ else:
188
+ try:
189
+ self.cert = credentials['cert']
190
+ except KeyError:
191
+ x509 = os.getenv('X509_USER_PROXY')
192
+ if not x509:
193
+ # Trying to get the proxy from the default location
194
+ proxy_path = '/tmp/x509up_u%s' % os.geteuid()
195
+ if os.path.isfile(proxy_path):
196
+ self.cert = (proxy_path, proxy_path)
197
+ elif self.auth_token:
198
+ # If no proxy is found, we set the cert to None and use the auth_token
199
+ self.cert = None
200
+ pass
201
+ else:
202
+ raise exception.RSEAccessDenied('X509_USER_PROXY is not set')
203
+ else:
204
+ self.cert = (x509, x509)
205
+
206
+ try:
207
+ self.timeout = credentials['timeout']
208
+ except KeyError:
209
+ self.timeout = 300
210
+ self.session = requests.Session()
211
+ self.session.mount('https://', TLSHTTPAdapter())
212
+ if self.auth_token:
213
+ self.session.headers.update({'Authorization': 'Bearer ' + self.auth_token})
214
+ # "ping" to see if the server is available
215
+ try:
216
+ test_url = self.path2pfn('')
217
+ res = self.session.request('HEAD', test_url, verify=False, timeout=self.timeout, cert=self.cert)
218
+ # REVISIT: this test checks some URL that doesn't correspond to
219
+ # any valid Rucio file. Although this works for normal WebDAV
220
+ # endpoints, it fails for endpoints using presigned URLs. As a
221
+ # work-around, accept 4xx status codes when using presigned URLs.
222
+ if res.status_code != 200 and not (using_presigned_urls and res.status_code < 500):
223
+ raise exception.ServiceUnavailable('Bad status code %s %s : %s' % (res.status_code, test_url, res.text))
224
+ except requests.exceptions.ConnectionError as error:
225
+ raise exception.ServiceUnavailable('Problem to connect %s : %s' % (test_url, error))
226
+ except requests.exceptions.ReadTimeout as error:
227
+ raise exception.ServiceUnavailable(error)
228
+
229
+ def close(self):
230
+ self.session.close()
231
+
232
+ def path2pfn(self, path):
233
+ """
234
+ Returns a fully qualified PFN for the file referred by path.
235
+
236
+ :param path: The path to the file.
237
+
238
+ :returns: Fully qualified PFN.
239
+
240
+ """
241
+ if not path.startswith('https'):
242
+ return '%s://%s:%s%s%s' % (self.attributes['scheme'], self.attributes['hostname'], str(self.attributes['port']), self.attributes['prefix'], path)
243
+ else:
244
+ return path
245
+
246
+ def exists(self, pfn):
247
+ """ Checks if the requested file is known by the referred RSE.
248
+
249
+ :param pfn: Physical file name
250
+
251
+ :returns: True if the file exists, False if it doesn't
252
+
253
+ :raise ServiceUnavailable, RSEAccessDenied
254
+ """
255
+ path = self.path2pfn(pfn)
256
+ try:
257
+ result = self.session.request('HEAD', path, verify=False, timeout=self.timeout, cert=self.cert)
258
+ if result.status_code == 200:
259
+ return True
260
+ elif result.status_code in [401, ]:
261
+ raise exception.RSEAccessDenied()
262
+ elif result.status_code in [404, ]:
263
+ return False
264
+ else:
265
+ # catchall exception
266
+ raise exception.RucioException(result.status_code, result.text)
267
+ except requests.exceptions.ConnectionError as error:
268
+ raise exception.ServiceUnavailable(error)
269
+
270
+ def get(self, pfn, dest='.', transfer_timeout=None):
271
+ """ Provides access to files stored inside connected the RSE.
272
+
273
+ :param pfn: Physical file name of requested file
274
+ :param dest: Name and path of the files when stored at the client
275
+ :param transfer_timeout: Transfer timeout (in seconds)
276
+
277
+ :raises DestinationNotAccessible, ServiceUnavailable, SourceNotFound, RSEAccessDenied
278
+ """
279
+ path = self.path2pfn(pfn)
280
+ chunksize = 1024
281
+ transfer_timeout = self.timeout if transfer_timeout is None else transfer_timeout
282
+
283
+ try:
284
+ result = self.session.get(path, verify=False, stream=True, timeout=transfer_timeout, cert=self.cert)
285
+ if result and result.status_code in [200, ]:
286
+ length = None
287
+ if 'content-length' in result.headers:
288
+ length = int(result.headers['content-length'])
289
+ with open(dest, 'wb') as file_out:
290
+ nchunk = 0
291
+ if not length:
292
+ print('Malformed HTTP response (missing content-length header).')
293
+ for chunk in result.iter_content(chunksize):
294
+ file_out.write(chunk)
295
+ if length:
296
+ nchunk += 1
297
+ elif result.status_code in [404, ]:
298
+ raise exception.SourceNotFound()
299
+ elif result.status_code in [401, 403]:
300
+ raise exception.RSEAccessDenied()
301
+ else:
302
+ # catchall exception
303
+ raise exception.RucioException(result.status_code, result.text)
304
+ except requests.exceptions.ConnectionError as error:
305
+ raise exception.ServiceUnavailable(error)
306
+ except requests.exceptions.ReadTimeout as error:
307
+ raise exception.ServiceUnavailable(error)
308
+
309
+ def put(self, source, target, source_dir=None, transfer_timeout=None, progressbar=False):
310
+ """ Allows to store files inside the referred RSE.
311
+
312
+ :param source: Physical file name
313
+ :param target: Name of the file on the storage system e.g. with prefixed scope
314
+ :param source_dir Path where the to be transferred files are stored in the local file system
315
+ :param transfer_timeout Transfer timeout (in seconds)
316
+
317
+ :raises DestinationNotAccessible, ServiceUnavailable, SourceNotFound, RSEAccessDenied
318
+ """
319
+ path = self.path2pfn(target)
320
+ full_name = source_dir + '/' + source if source_dir else source
321
+ directories = path.split('/')
322
+ # Try the upload without testing the existence of the destination directory
323
+ transfer_timeout = self.timeout if transfer_timeout is None else transfer_timeout
324
+
325
+ try:
326
+ if not os.path.exists(full_name):
327
+ raise exception.SourceNotFound()
328
+ it = UploadInChunks(full_name, 10000000, progressbar)
329
+ result = self.session.put(path, data=IterableToFileAdapter(it), verify=False, allow_redirects=True, timeout=transfer_timeout, cert=self.cert)
330
+ if result.status_code in [200, 201]:
331
+ return
332
+ if result.status_code in [409, ]:
333
+ raise exception.FileReplicaAlreadyExists()
334
+ else:
335
+ # Create the directories before issuing the PUT
336
+ for directory_level in reversed(list(range(1, 4))):
337
+ upper_directory = "/".join(directories[:-directory_level])
338
+ self.mkdir(upper_directory)
339
+ try:
340
+ if not os.path.exists(full_name):
341
+ raise exception.SourceNotFound()
342
+ it = UploadInChunks(full_name, 10000000, progressbar)
343
+ result = self.session.put(path, data=IterableToFileAdapter(it), verify=False, allow_redirects=True, timeout=transfer_timeout, cert=self.cert)
344
+ if result.status_code in [200, 201]:
345
+ return
346
+ if result.status_code in [409, ]:
347
+ raise exception.FileReplicaAlreadyExists()
348
+ elif result.status_code in [401, ]:
349
+ raise exception.RSEAccessDenied()
350
+ else:
351
+ # catchall exception
352
+ raise exception.RucioException(result.status_code, result.text)
353
+ except requests.exceptions.ConnectionError as error:
354
+ raise exception.ServiceUnavailable(error)
355
+ except OSError as error:
356
+ raise exception.SourceNotFound(error)
357
+ except requests.exceptions.ConnectionError as error:
358
+ raise exception.ServiceUnavailable(error)
359
+ except requests.exceptions.ReadTimeout as error:
360
+ raise exception.ServiceUnavailable(error)
361
+ except OSError as error:
362
+ raise exception.SourceNotFound(error)
363
+
364
+ def rename(self, pfn, new_pfn):
365
+ """ Allows to rename a file stored inside the connected RSE.
366
+
367
+ :param pfn: Current physical file name
368
+ :param new_pfn New physical file name
369
+
370
+ :raises DestinationNotAccessible, ServiceUnavailable, SourceNotFound, RSEAccessDenied
371
+ """
372
+ path = self.path2pfn(pfn)
373
+ new_path = self.path2pfn(new_pfn)
374
+ directories = new_path.split('/')
375
+
376
+ headers = {'Destination': new_path}
377
+ # Try the rename without testing the existence of the destination directory
378
+ try:
379
+ result = self.session.request('MOVE', path, verify=False, headers=headers, timeout=self.timeout, cert=self.cert)
380
+ if result.status_code == 201:
381
+ return
382
+ elif result.status_code in [404, ]:
383
+ raise exception.SourceNotFound()
384
+ else:
385
+ # Create the directories before issuing the MOVE
386
+ for directory_level in reversed(list(range(1, 4))):
387
+ upper_directory = "/".join(directories[:-directory_level])
388
+ self.mkdir(upper_directory)
389
+ try:
390
+ result = self.session.request('MOVE', path, verify=False, headers=headers, timeout=self.timeout, cert=self.cert)
391
+ if result.status_code == 201:
392
+ return
393
+ elif result.status_code in [404, ]:
394
+ raise exception.SourceNotFound()
395
+ elif result.status_code in [401, ]:
396
+ raise exception.RSEAccessDenied()
397
+ else:
398
+ # catchall exception
399
+ raise exception.RucioException(result.status_code, result.text)
400
+ except requests.exceptions.ConnectionError as error:
401
+ raise exception.ServiceUnavailable(error)
402
+ except requests.exceptions.ConnectionError as error:
403
+ raise exception.ServiceUnavailable(error)
404
+ except requests.exceptions.ReadTimeout as error:
405
+ raise exception.ServiceUnavailable(error)
406
+
407
+ def delete(self, pfn):
408
+ """ Deletes a file from the connected RSE.
409
+
410
+ :param pfn: Physical file name
411
+
412
+ :raises ServiceUnavailable, SourceNotFound, RSEAccessDenied, ResourceTemporaryUnavailable
413
+ """
414
+ path = self.path2pfn(pfn)
415
+ try:
416
+ result = self.session.delete(path, verify=False, timeout=self.timeout, cert=self.cert)
417
+ if result.status_code in [204, ]:
418
+ return
419
+ elif result.status_code in [404, ]:
420
+ raise exception.SourceNotFound()
421
+ elif result.status_code in [401, 403]:
422
+ raise exception.RSEAccessDenied()
423
+ elif result.status_code in [500, 503]:
424
+ raise exception.ResourceTemporaryUnavailable()
425
+ else:
426
+ # catchall exception
427
+ raise exception.RucioException(result.status_code, result.text)
428
+ except requests.exceptions.ConnectionError as error:
429
+ raise exception.ServiceUnavailable(error)
430
+ except requests.exceptions.ReadTimeout as error:
431
+ raise exception.ServiceUnavailable(error)
432
+
433
+ def mkdir(self, directory):
434
+ """ Internal method to create directories
435
+
436
+ :param directory: Name of the directory that needs to be created
437
+
438
+ :raises DestinationNotAccessible, ServiceUnavailable, SourceNotFound, RSEAccessDenied
439
+ """
440
+ path = self.path2pfn(directory)
441
+ try:
442
+ result = self.session.request('MKCOL', path, verify=False, timeout=self.timeout, cert=self.cert)
443
+ if result.status_code in [201, 405]: # Success or directory already exists
444
+ return
445
+ elif result.status_code in [404, ]:
446
+ raise exception.SourceNotFound()
447
+ elif result.status_code in [401, ]:
448
+ raise exception.RSEAccessDenied()
449
+ else:
450
+ # catchall exception
451
+ raise exception.RucioException(result.status_code, result.text)
452
+ except requests.exceptions.ConnectionError as error:
453
+ raise exception.ServiceUnavailable(error)
454
+ except requests.exceptions.ReadTimeout as error:
455
+ raise exception.ServiceUnavailable(error)
456
+
457
+ def ls(self, filename):
458
+ """ Internal method to list files/directories
459
+
460
+ :param filename: Name of the directory that needs to be created
461
+
462
+ :raises DestinationNotAccessible, ServiceUnavailable, SourceNotFound, RSEAccessDenied
463
+ """
464
+ path = self.path2pfn(filename)
465
+ headers = {'Depth': '1'}
466
+ self.exists(filename)
467
+ try:
468
+ result = self.session.request('PROPFIND', path, verify=False, headers=headers, timeout=self.timeout, cert=self.cert)
469
+ if result.status_code in [404, ]:
470
+ raise exception.SourceNotFound()
471
+ elif result.status_code in [401, ]:
472
+ raise exception.RSEAccessDenied()
473
+
474
+ try:
475
+ propfind = _PropfindResponse.parse(result.text)
476
+ except ValueError:
477
+ raise exception.ServiceUnavailable("Couldn't parse WebDAV response.")
478
+
479
+ list_files = [self.server + file.href for file in propfind.files if file.href is not None]
480
+
481
+ try:
482
+ list_files.remove(filename + '/')
483
+ except ValueError:
484
+ pass
485
+ try:
486
+ list_files.remove(filename)
487
+ except ValueError:
488
+ pass
489
+
490
+ return list_files
491
+ except requests.exceptions.ConnectionError as error:
492
+ raise exception.ServiceUnavailable(error)
493
+ except requests.exceptions.ReadTimeout as error:
494
+ raise exception.ServiceUnavailable(error)
495
+
496
+ def stat(self, path):
497
+ """
498
+ Returns the stats of a file.
499
+
500
+ :param path: path to file
501
+
502
+ :raises ServiceUnavailable: if some generic error occurred in the library.
503
+ :raises SourceNotFound: if the source file was not found on the referred storage.
504
+ :raises RSEAccessDenied: in case of permission issue.
505
+
506
+ :returns: a dict with filesize of the file provided in path as a key.
507
+ """
508
+ headers = {'Depth': '1'}
509
+ dict_ = {}
510
+ try:
511
+ result = self.session.request('PROPFIND', path, verify=False, headers=headers, timeout=self.timeout, cert=self.cert)
512
+ if result.status_code in [404, ]:
513
+ raise exception.SourceNotFound()
514
+ elif result.status_code in [401, ]:
515
+ raise exception.RSEAccessDenied()
516
+ if result.status_code in [400, ]:
517
+ raise exception.InvalidRequest()
518
+ except requests.exceptions.ConnectionError as error:
519
+ raise exception.ServiceUnavailable(error)
520
+ except requests.exceptions.ReadTimeout as error:
521
+ raise exception.ServiceUnavailable(error)
522
+
523
+ path_parts = self.parse_pfns(path)[path]
524
+ local_path = os.path.join(path_parts['prefix'], path_parts['path'][1:], path_parts['name'])
525
+
526
+ try:
527
+ propfind = _PropfindResponse.parse(result.text)
528
+ except ValueError:
529
+ raise exception.ServiceUnavailable("Couldn't parse WebDAV response.")
530
+
531
+ for file in propfind.files:
532
+ if file.href != str(local_path):
533
+ continue
534
+
535
+ if file.size is None:
536
+ continue
537
+
538
+ dict_['filesize'] = file.size
539
+ break
540
+ else:
541
+ raise exception.ServiceUnavailable("WebDAV response didn't include content length for requested path.")
542
+
543
+ return dict_
544
+
545
+ def get_space_usage(self):
546
+ """
547
+ Get RSE space usage information.
548
+
549
+ :returns: a list with dict containing 'totalsize' and 'unusedsize'
550
+
551
+ :raises ServiceUnavailable: if some generic error occurred in the library.
552
+ """
553
+ endpoint_basepath = self.path2pfn('')
554
+ headers = {'Depth': '0'}
555
+
556
+ try:
557
+ root = ElementTree.fromstring(self.session.request('PROPFIND', endpoint_basepath, verify=False, headers=headers, cert=self.session.cert).text) # noqa: S314
558
+ usedsize = root[0][1][0].find('{DAV:}quota-used-bytes').text
559
+ try:
560
+ unusedsize = root[0][1][0].find('{DAV:}quota-available-bytes').text
561
+ except Exception:
562
+ print('No free space given, return -999')
563
+ unusedsize = -999
564
+ totalsize = int(usedsize) + int(unusedsize)
565
+ return totalsize, unusedsize
566
+ except Exception as error:
567
+ raise exception.ServiceUnavailable(error)
568
+
569
+
570
+ class NoRename(Default):
571
+ """ Implementing access to RSEs using the WebDAV protocol but without
572
+ renaming files on upload/download. Necessary for some storage endpoints.
573
+ """
574
+
575
+ def __init__(self, protocol_attr, rse_settings, logger=logging.log):
576
+ """ Initializes the object with information about the referred RSE.
577
+
578
+ :param protocol_attr: Properties of the requested protocol.
579
+ :param rse_settings: The RSE settings.
580
+ :param logger: Optional decorated logger that can be passed from the calling daemons or servers.
581
+ """
582
+ super(NoRename, self).__init__(protocol_attr, rse_settings, logger=logger)
583
+ self.renaming = False
584
+ self.attributes.pop('determinism_type', None)
585
+
586
+ def rename(self, pfn, new_pfn):
587
+ """ Allows to rename a file stored inside the connected RSE.
588
+
589
+ :param pfn: Current physical file name
590
+ :param new_pfn New physical file name
591
+
592
+ :raises DestinationNotAccessible, ServiceUnavailable, SourceNotFound
593
+ """
594
+ raise NotImplementedError