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,339 @@
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 os
17
+ import re
18
+ import urllib.parse as urlparse
19
+ from subprocess import getstatusoutput
20
+
21
+ from rucio.common import exception
22
+ from rucio.common.utils import execute
23
+ from rucio.rse.protocols import protocol
24
+
25
+
26
+ class Default(protocol.RSEProtocol):
27
+ """ Implementing access to RSEs using the SRM protocol. """
28
+
29
+ def lfns2pfns(self, lfns):
30
+ """
31
+ Returns a fully qualified PFN for the file referred by path.
32
+
33
+ :param path: The path to the file.
34
+ :returns: Fully qualified PFN.
35
+ """
36
+
37
+ pfns = {}
38
+ prefix = self.attributes['prefix']
39
+ if self.attributes['extended_attributes'] is not None and\
40
+ 'web_service_path' in list(self.attributes['extended_attributes'].keys()):
41
+ web_service_path = self.attributes['extended_attributes']['web_service_path']
42
+ else:
43
+ web_service_path = ''
44
+
45
+ if not prefix.startswith('/'):
46
+ prefix = ''.join(['/', prefix])
47
+ if not prefix.endswith('/'):
48
+ prefix = ''.join([prefix, '/'])
49
+
50
+ hostname = self.attributes['hostname']
51
+ if '://' in hostname:
52
+ hostname = hostname.split("://")[1]
53
+
54
+ lfns = [lfns] if type(lfns) == dict else lfns
55
+ if not self.attributes['port']:
56
+ for lfn in lfns:
57
+ scope, name, path = lfn['scope'], lfn['name'], lfn.get('path')
58
+ if not path:
59
+ path = self._get_path(scope=scope, name=name)
60
+ if path.startswith('/'):
61
+ path = path[1:]
62
+ pfns['%s:%s' % (scope, name)] = ''.join([self.attributes['scheme'], '://',
63
+ hostname, web_service_path, prefix, path])
64
+ else:
65
+ for lfn in lfns:
66
+ scope, name, path = lfn['scope'], lfn['name'], lfn.get('path')
67
+ if not path:
68
+ path = self._get_path(scope=scope, name=name)
69
+ if path.startswith('/'):
70
+ path = path[1:]
71
+ pfns['%s:%s' % (scope, name)] = ''.join([self.attributes['scheme'], '://',
72
+ hostname, ':', str(self.attributes['port']),
73
+ web_service_path, prefix, path])
74
+
75
+ return pfns
76
+
77
+ def parse_pfns(self, pfns):
78
+ """
79
+ Splits the given PFN into the parts known by the protocol. During parsing the PFN is also checked for
80
+ validity on the given RSE with the given protocol.
81
+
82
+ :param pfn: a fully qualified PFN
83
+ :returns: a dict containing all known parts of the PFN for the protocol e.g. scheme, path, filename
84
+ :raises RSEFileNameNotSupported: if the provided PFN doesn't match with the protocol settings
85
+ """
86
+
87
+ ret = dict()
88
+ pfns = [pfns] if isinstance(pfns, str) else pfns
89
+ for pfn in pfns:
90
+ parsed = urlparse.urlparse(pfn)
91
+ if parsed.path.startswith('/srm/managerv2') or\
92
+ parsed.path.startswith('/srm/managerv1') or\
93
+ parsed.path.startswith('/srm/v2/server'):
94
+ scheme, hostname, port, service_path, path = re.findall(r"([^:]+)://([^:/]+):?(\d+)?([^:]+=)?([^:]+)", pfn)[0]
95
+ else:
96
+ scheme = parsed.scheme
97
+ hostname = parsed.netloc.partition(':')[0]
98
+ port = parsed.netloc.partition(':')[2]
99
+ path = parsed.path
100
+ service_path = ''
101
+
102
+ # force type conversion
103
+ try:
104
+ port = int(port)
105
+ except:
106
+ port = ''
107
+
108
+ if self.attributes['hostname'] != hostname and\
109
+ self.attributes['hostname'] != scheme + "://" + hostname:
110
+ raise exception.RSEFileNameNotSupported('Invalid hostname: provided \'%s\', expected \'%s\'' % (hostname,
111
+ self.attributes['hostname']))
112
+
113
+ if port != '' and str(self.attributes['port']) != str(port):
114
+ raise exception.RSEFileNameNotSupported('Invalid port: provided \'%s\', expected \'%s\'' % (port,
115
+ self.attributes['port']))
116
+ elif port == '':
117
+ port = self.attributes['port']
118
+
119
+ if not path.startswith(self.attributes['prefix']):
120
+ raise exception.RSEFileNameNotSupported('Invalid prefix: provided \'%s\', expected \'%s\'' % ('/'.join(path.split('/')[0:len(self.attributes['prefix'].split('/')) - 1]),
121
+ self.attributes['prefix'])) # len(...)-1 due to the leading '/
122
+
123
+ # Spliting path into prefix, path, filename
124
+ prefix = self.attributes['prefix']
125
+ path = path.partition(self.attributes['prefix'])[2]
126
+ name = path.split('/')[-1]
127
+ path = '/' + '/'.join(path.split('/')[:-1]) if not self.rse['staging_area'] else None
128
+
129
+ if path != '/' and path[:-1] != '/':
130
+ path += '/'
131
+
132
+ ret[pfn] = {'scheme': scheme, 'port': port, 'hostname': hostname,
133
+ 'path': path, 'name': name, 'prefix': prefix,
134
+ 'web_service_path': service_path}
135
+
136
+ return ret
137
+
138
+ def path2pfn(self, path):
139
+ """
140
+ Returns a fully qualified PFN for the file referred by path.
141
+
142
+ :param path: The path to the file.
143
+ :returns: Fully qualified PFN.
144
+ """
145
+
146
+ if path.startswith("srm://"):
147
+ return path
148
+
149
+ hostname = self.attributes['hostname']
150
+ if '://' in hostname:
151
+ hostname = hostname.split("://")[1]
152
+
153
+ if 'extended_attributes' in list(self.attributes.keys()) and\
154
+ self.attributes['extended_attributes'] is not None and\
155
+ 'web_service_path' in list(self.attributes['extended_attributes'].keys()):
156
+ web_service_path = self.attributes['extended_attributes']['web_service_path']
157
+ else:
158
+ web_service_path = ''
159
+
160
+ if not path.startswith('srm'):
161
+ if self.attributes['port'] > 0:
162
+ return ''.join([self.attributes['scheme'], '://', hostname, ':', str(self.attributes['port']), web_service_path, path])
163
+ else:
164
+ return ''.join([self.attributes['scheme'], '://', hostname, web_service_path, path])
165
+ else:
166
+ return path
167
+
168
+ def connect(self):
169
+ """
170
+ Establishes the actual connection to the referred RSE.
171
+ As a quick and dirty impelementation we just use this method to check if the lcg tools are available.
172
+ If we decide to use gfal, init should be done here.
173
+
174
+ :raises RSEAccessDenied: Cannot connect.
175
+ """
176
+
177
+ status, lcglscommand = getstatusoutput('which lcg-ls')
178
+ if status:
179
+ raise exception.RSEAccessDenied('Cannot find lcg tools')
180
+ endpoint_basepath = self.path2pfn(self.attributes['prefix'])
181
+ status, result = getstatusoutput('%s -vv $LCGVO -b --srm-timeout 60 -D srmv2 -l %s' % (lcglscommand, endpoint_basepath))
182
+ if status:
183
+ if result == '':
184
+ raise exception.RSEAccessDenied('Endpoint not reachable. lcg-ls failed with status code %s but no further details.' % (str(status)))
185
+ else:
186
+ raise exception.RSEAccessDenied('Endpoint not reachable : %s' % str(result))
187
+
188
+ def get(self, path, dest, transfer_timeout=None):
189
+ """
190
+ Provides access to files stored inside connected the RSE.
191
+
192
+ :param path: Physical file name of requested file
193
+ :param dest: Name and path of the files when stored at the client
194
+ :param transfer_timeout: Transfer timeout (in seconds)
195
+
196
+ :raises DestinationNotAccessible: if the destination storage was not accessible.
197
+ :raises ServiceUnavailable: if some generic error occured in the library.
198
+ :raises SourceNotFound: if the source file was not found on the referred storage.
199
+ """
200
+
201
+ timeout_option = ''
202
+ if transfer_timeout:
203
+ timeout_option = '--sendreceive-timeout %s' % transfer_timeout
204
+
205
+ try:
206
+ cmd = 'lcg-cp $LCGVO -v -b --srm-timeout 3600 %s -D srmv2 %s file:%s' % (timeout_option, path, dest)
207
+ status, out, err = execute(cmd)
208
+ if status:
209
+ if self.__parse_srm_error__("SRM_INVALID_PATH", out, err):
210
+ raise exception.SourceNotFound(err)
211
+ raise exception.RucioException(err)
212
+ except exception.SourceNotFound as error:
213
+ raise exception.SourceNotFound(str(error))
214
+ except Exception as error:
215
+ raise exception.ServiceUnavailable(error)
216
+
217
+ def put(self, source, target, source_dir, transfer_timeout=None):
218
+ """
219
+ Allows to store files inside the referred RSE.
220
+
221
+ :param source: path to the source file on the client file system
222
+ :param target: path to the destination file on the storage
223
+ :param source_dir: Path where the to be transferred files are stored in the local file system
224
+ :param transfer_timeout: Transfer timeout (in seconds)
225
+
226
+ :raises DestinationNotAccessible: if the destination storage was not accessible.
227
+ :raises ServiceUnavailable: if some generic error occured in the library.
228
+ :raises SourceNotFound: if the source file was not found on the referred storage.
229
+ """
230
+
231
+ source_url = '%s/%s' % (source_dir, source) if source_dir else source
232
+
233
+ if not os.path.exists(source_url):
234
+ raise exception.SourceNotFound()
235
+
236
+ space_token = ''
237
+ if self.attributes['extended_attributes'] is not None and 'space_token' in list(self.attributes['extended_attributes'].keys()):
238
+ space_token = '--dst %s' % self.attributes['extended_attributes']['space_token']
239
+
240
+ timeout_option = ''
241
+ if transfer_timeout:
242
+ timeout_option = '--sendreceive-timeout %s' % transfer_timeout
243
+
244
+ try:
245
+ cmd = 'lcg-cp $LCGVO -v -b --srm-timeout 3600 %s -D srmv2 %s file:%s %s' % (timeout_option, space_token, source_url, target)
246
+ status, out, err = execute(cmd)
247
+ if status:
248
+ raise exception.RucioException(err)
249
+ except Exception as error:
250
+ raise exception.ServiceUnavailable(error)
251
+
252
+ def delete(self, path):
253
+ """
254
+ Deletes a file from the connected RSE.
255
+
256
+ :param path: path to the to be deleted file
257
+ :raises ServiceUnavailable: if some generic error occured in the library.
258
+ :raises SourceNotFound: if the source file was not found on the referred storage.
259
+ """
260
+
261
+ pfns = [path] if isinstance(path, str) else path
262
+
263
+ try:
264
+ pfn_chunks = [pfns[i:i + 20] for i in range(0, len(pfns), 20)]
265
+ for pfn_chunk in pfn_chunks:
266
+ cmd = 'lcg-del $LCGVO -v -b -l --srm-timeout 600 -D srmv2'
267
+ for pfn in pfn_chunk:
268
+ cmd += ' ' + pfn
269
+ status, out, err = execute(cmd)
270
+ if status:
271
+ if self.__parse_srm_error__("SRM_INVALID_PATH", out, err):
272
+ raise exception.SourceNotFound(err)
273
+ raise exception.RucioException(err)
274
+ except exception.SourceNotFound as error:
275
+ raise exception.SourceNotFound(str(error))
276
+ except Exception as error:
277
+ raise exception.ServiceUnavailable(error)
278
+
279
+ def rename(self, path, new_path):
280
+ """
281
+ Allows to rename a file stored inside the connected RSE.
282
+
283
+ :param path: path to the current file on the storage
284
+ :param new_path: path to the new file on the storage
285
+ :raises DestinationNotAccessible: if the destination storage was not accessible.
286
+ :raises ServiceUnavailable: if some generic error occured in the library.
287
+ :raises SourceNotFound: if the source file was not found on the referred storage.
288
+ """
289
+
290
+ space_token = ''
291
+ if self.attributes['extended_attributes'] is not None and 'space_token' in list(self.attributes['extended_attributes'].keys()):
292
+ space_token = '--dst %s' % self.attributes['extended_attributes']['space_token']
293
+
294
+ try:
295
+ cmd = 'lcg-cp $LCGVO -v -b --srm-timeout 3600 -D srmv2 %s %s %s' % (space_token, path, new_path)
296
+ status, out, err = execute(cmd)
297
+ if status:
298
+ raise exception.RucioException(err)
299
+
300
+ cmd = 'lcg-del $LCGVO -v -b -l --srm-timeout 600 -D srmv2 %s' % (path)
301
+ status, out, err = execute(cmd)
302
+ if status:
303
+ raise exception.RucioException(err)
304
+ except Exception as error:
305
+ raise exception.ServiceUnavailable(error)
306
+
307
+ def exists(self, path):
308
+ """
309
+ Checks if the requested file is known by the referred RSE.
310
+
311
+ :param path: Physical file name
312
+ :returns: True if the file exists, False if it doesn't
313
+ :raises SourceNotFound: if the source file was not found on the referred storage.
314
+ """
315
+
316
+ try:
317
+ cmd = 'lcg-ls $LCGVO -v -b --srm-timeout 60 -D srmv2 %s' % (path)
318
+ status, out, err = execute(cmd)
319
+ if status:
320
+ return False
321
+ return True
322
+ except Exception as error:
323
+ raise exception.ServiceUnavailable(error)
324
+
325
+ def __parse_srm_error__(self, err_code, out, err):
326
+ """Parse the error message to return error code."""
327
+ if out is not None and len(out) > 0:
328
+ if out.count(err_code) > 0:
329
+ return True
330
+ if err is not None and len(err) > 0:
331
+ if err.count(err_code) > 0:
332
+ return True
333
+ return False
334
+
335
+ def close(self):
336
+ """
337
+ Closes the connection to RSE.
338
+ """
339
+ pass