rucio-clients 35.7.0__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 +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.7.0.data/data/etc/rse-accounts.cfg.template +25 -0
  77. rucio_clients-35.7.0.data/data/etc/rucio.cfg.atlas.client.template +42 -0
  78. rucio_clients-35.7.0.data/data/etc/rucio.cfg.template +257 -0
  79. rucio_clients-35.7.0.data/data/requirements.client.txt +15 -0
  80. rucio_clients-35.7.0.data/data/rucio_client/merge_rucio_configs.py +144 -0
  81. rucio_clients-35.7.0.data/scripts/rucio +2542 -0
  82. rucio_clients-35.7.0.data/scripts/rucio-admin +2447 -0
  83. rucio_clients-35.7.0.dist-info/METADATA +50 -0
  84. rucio_clients-35.7.0.dist-info/RECORD +88 -0
  85. rucio_clients-35.7.0.dist-info/WHEEL +5 -0
  86. rucio_clients-35.7.0.dist-info/licenses/AUTHORS.rst +97 -0
  87. rucio_clients-35.7.0.dist-info/licenses/LICENSE +201 -0
  88. rucio_clients-35.7.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,2542 @@
1
+ #!python
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 argparse
17
+ import errno
18
+ import itertools
19
+ import logging
20
+ import math
21
+ import os
22
+ import signal
23
+ import subprocess
24
+ import sys
25
+ import time
26
+ import traceback
27
+ import unittest
28
+ import uuid
29
+ from configparser import NoOptionError, NoSectionError
30
+ from copy import deepcopy
31
+ from datetime import datetime
32
+ from functools import wraps
33
+ from typing import Optional
34
+
35
+ from tabulate import tabulate
36
+
37
+ # rucio module has the same name as this executable module, so this rule fails. pylint: disable=no-name-in-module
38
+ from rucio import version
39
+ from rucio.client import Client
40
+ from rucio.common.config import config_get, config_get_float
41
+ from rucio.common.constants import ReplicaState
42
+ from rucio.common.exception import (
43
+ AccessDenied,
44
+ CannotAuthenticate,
45
+ DataIdentifierAlreadyExists,
46
+ DataIdentifierNotFound,
47
+ DIDFilterSyntaxError,
48
+ DuplicateContent,
49
+ DuplicateCriteriaInDIDFilter,
50
+ DuplicateRule,
51
+ InputValidationError,
52
+ InvalidObject,
53
+ InvalidRSEExpression,
54
+ InvalidType,
55
+ MissingDependency,
56
+ RSENotFound,
57
+ RucioException,
58
+ RuleNotFound,
59
+ UnsupportedOperation,
60
+ )
61
+ from rucio.common.extra import import_extras
62
+ from rucio.common.test_rucio_server import TestRucioServer
63
+ from rucio.common.utils import Color, StoreAndDeprecateWarningAction, chunks, detect_client_location, extract_scope, parse_did_filter_from_string, parse_did_filter_from_string_fe, setup_logger, sizefmt
64
+
65
+ EXTRA_MODULES = import_extras(['argcomplete'])
66
+
67
+ if EXTRA_MODULES['argcomplete']:
68
+ import argcomplete # pylint: disable=E0401
69
+
70
+ SUCCESS = 0
71
+ FAILURE = 1
72
+
73
+ DEFAULT_SECURE_PORT = 443
74
+ DEFAULT_PORT = 80
75
+
76
+ logger = logging.log
77
+ gfal2_logger = logging.getLogger("gfal2")
78
+ tablefmt = 'psql'
79
+
80
+
81
+ def setup_gfal2_logger(logger):
82
+ logger.setLevel(logging.CRITICAL)
83
+ logger.addHandler(logging.StreamHandler())
84
+
85
+
86
+ setup_gfal2_logger(gfal2_logger)
87
+
88
+
89
+ def signal_handler(sig, frame):
90
+ logger.warning('You pressed Ctrl+C! Exiting gracefully')
91
+ child_processes = subprocess.Popen('ps -o pid --ppid %s --noheaders' % os.getpid(), shell=True, stdout=subprocess.PIPE)
92
+ child_processes = child_processes.stdout.read()
93
+ for pid in child_processes.split("\n")[:-1]:
94
+ try:
95
+ os.kill(int(pid), signal.SIGTERM)
96
+ except Exception:
97
+ print('Cannot kill child process')
98
+ sys.exit(1)
99
+
100
+
101
+ signal.signal(signal.SIGINT, signal_handler)
102
+
103
+
104
+ def get_scope(did, client):
105
+ try:
106
+ scope, name = extract_scope(did)
107
+ return scope, name
108
+ except TypeError:
109
+ scopes = client.list_scopes()
110
+ scope, name = extract_scope(did, scopes)
111
+ return scope, name
112
+ return None, did
113
+
114
+
115
+ def exception_handler(function):
116
+ @wraps(function)
117
+ def new_funct(*args, **kwargs):
118
+ try:
119
+ return function(*args, **kwargs)
120
+ except InvalidObject as error:
121
+ logger.error(error)
122
+ return error.error_code
123
+ except DataIdentifierNotFound as error:
124
+ logger.error(error)
125
+ logger.debug('This means that the Data IDentifier you provided is not known by Rucio.')
126
+ return error.error_code
127
+ except AccessDenied as error:
128
+ logger.error(error)
129
+ logger.debug('This error is a permission issue. You cannot run this command with your account.')
130
+ return error.error_code
131
+ except DataIdentifierAlreadyExists as error:
132
+ logger.error(error)
133
+ logger.debug('This means that the Data IDentifier you try to add is already registered in Rucio.')
134
+ return error.error_code
135
+ except RSENotFound as error:
136
+ logger.error(error)
137
+ logger.debug('This means that the Rucio Storage Element you provided is not known by Rucio.')
138
+ return error.error_code
139
+ except InvalidRSEExpression as error:
140
+ logger.error(error)
141
+ logger.debug('This means the RSE expression you provided is not syntactically correct.')
142
+ return error.error_code
143
+ except DuplicateContent as error:
144
+ logger.error(error)
145
+ logger.debug('This means that the DID you want to attach is already in the target DID.')
146
+ return error.error_code
147
+ except TypeError as error:
148
+ logger.error(error)
149
+ logger.debug('This means the parameter you passed has a wrong type.')
150
+ return FAILURE
151
+ except RuleNotFound as error:
152
+ logger.error(error)
153
+ logger.debug('This means the rule you specified does not exist.')
154
+ return error.error_code
155
+ except UnsupportedOperation as error:
156
+ logger.error(error)
157
+ logger.debug('This means you cannot change the status of the DID.')
158
+ return error.error_code
159
+ except MissingDependency as error:
160
+ logger.error(error)
161
+ logger.debug('This means one dependency is missing.')
162
+ return error.error_code
163
+ except KeyError as error:
164
+ if 'x-rucio-auth-token' in str(error):
165
+ used_account = None
166
+ try: # get the configured account from the configuration file
167
+ used_account = '%s (from rucio.cfg)' % config_get('client', 'account')
168
+ except:
169
+ pass
170
+ try: # are we overridden by the environment?
171
+ used_account = '%s (from RUCIO_ACCOUNT)' % os.environ['RUCIO_ACCOUNT']
172
+ except:
173
+ pass
174
+ logger.error('Specified account %s does not have an associated identity.' % used_account)
175
+ else:
176
+ logger.debug(traceback.format_exc())
177
+ contact = config_get('policy', 'support', raise_exception=False)
178
+ support = ('Please follow up with all relevant information at: ' + contact) if contact else ''
179
+ logger.error('\nThe object is missing this property: %s\n'
180
+ 'This should never happen. Please rerun the last command with the "-v" option to gather more information.\n'
181
+ '%s' % (str(error), support))
182
+ return FAILURE
183
+ except RucioException as error:
184
+ logger.error(error)
185
+ return error.error_code
186
+ except Exception as error:
187
+ if isinstance(error, IOError) and getattr(error, 'errno', None) == errno.EPIPE:
188
+ # Ignore Broken Pipe
189
+ # While in python3 we can directly catch 'BrokenPipeError', in python2 it doesn't exist.
190
+
191
+ # Python flushes standard streams on exit; redirect remaining output
192
+ # to devnull to avoid another BrokenPipeError at shutdown
193
+ devnull = os.open(os.devnull, os.O_WRONLY)
194
+ os.dup2(devnull, sys.stdout.fileno())
195
+ return SUCCESS
196
+ logger.debug(traceback.format_exc())
197
+ logger.error(error)
198
+ contact = config_get('policy', 'support', raise_exception=False)
199
+ support = ("If it's a problem concerning your experiment or if you're unsure what to do, please follow up at: %s\n" % contact) if contact else ''
200
+ contact = config_get('policy', 'support_rucio', default='https://github.com/rucio/rucio/issues')
201
+ support += "If you're sure there is a problem with Rucio itself, please follow up at: " + contact
202
+ logger.error('\nRucio exited with an unexpected/unknown error.\n'
203
+ 'Please rerun the last command with the "-v" option to gather more information.\n'
204
+ '%s' % support)
205
+ return FAILURE
206
+ return new_funct
207
+
208
+
209
+ def get_client(args):
210
+ """
211
+ Returns a new client object.
212
+ """
213
+ if not args.auth_strategy:
214
+ if 'RUCIO_AUTH_TYPE' in os.environ:
215
+ auth_type = os.environ['RUCIO_AUTH_TYPE'].lower()
216
+ else:
217
+ try:
218
+ auth_type = config_get('client', 'auth_type').lower()
219
+ except (NoOptionError, NoSectionError):
220
+ logger.error('Cannot get AUTH_TYPE')
221
+ sys.exit(FAILURE)
222
+ else:
223
+ auth_type = args.auth_strategy.lower()
224
+
225
+ if auth_type in ['userpass', 'saml'] and args.username is not None and args.password is not None:
226
+ creds = {'username': args.username, 'password': args.password}
227
+ elif auth_type == 'oidc':
228
+ if args.oidc_issuer:
229
+ args.oidc_issuer = args.oidc_issuer.lower()
230
+ creds = {'oidc_auto': args.oidc_auto,
231
+ 'oidc_scope': args.oidc_scope,
232
+ 'oidc_audience': args.oidc_audience,
233
+ 'oidc_polling': args.oidc_polling,
234
+ 'oidc_refresh_lifetime': args.oidc_refresh_lifetime,
235
+ 'oidc_issuer': args.oidc_issuer,
236
+ 'oidc_username': args.oidc_username,
237
+ 'oidc_password': args.oidc_password}
238
+ elif auth_type == "x509":
239
+ creds = {'client_cert': args.certificate, "client_key": args.client_key}
240
+ else:
241
+ creds = None
242
+
243
+ try:
244
+ client = Client(rucio_host=args.host, auth_host=args.auth_host,
245
+ account=args.account,
246
+ auth_type=auth_type, creds=creds,
247
+ ca_cert=args.ca_certificate, timeout=args.timeout,
248
+ user_agent=args.user_agent, vo=args.vo,
249
+ logger=logger)
250
+ except CannotAuthenticate as error:
251
+ logger.error(error)
252
+ if 'alert certificate expired' in str(error):
253
+ logger.error('The server certificate expired.')
254
+ elif auth_type.lower() == 'x509_proxy':
255
+ logger.error('Please verify that your proxy is still valid and renew it if needed.')
256
+ sys.exit(FAILURE)
257
+ return client
258
+
259
+
260
+ def __resolve_containers_to_datasets(scope, name, client):
261
+ """
262
+ Helper function to resolve a container into its dataset content.
263
+ """
264
+ datasets = []
265
+ for did in client.list_content(scope, name):
266
+ if did['type'] == 'DATASET':
267
+ datasets.append({'scope': did['scope'], 'name': did['name']})
268
+ elif did['type'] == 'CONTAINER':
269
+ datasets.extend(__resolve_containers_to_datasets(did['scope'], did['name'], client))
270
+ return datasets
271
+
272
+
273
+ @exception_handler
274
+ def ping(args):
275
+ """
276
+ Pings a Rucio server.
277
+ """
278
+ client = get_client(args)
279
+ server_info = client.ping()
280
+ if server_info:
281
+ print(server_info['version'])
282
+ return SUCCESS
283
+ logger.error('Ping failed')
284
+ return FAILURE
285
+
286
+
287
+ @exception_handler
288
+ def whoami_account(args):
289
+ """
290
+ %(prog)s show [options] <field1=value1 field2=value2 ...>
291
+
292
+ Show extended information of a given account
293
+ """
294
+ client = get_client(args)
295
+ info = client.whoami()
296
+ for k in info:
297
+ print(k.ljust(10) + ' : ' + str(info[k]))
298
+ return SUCCESS
299
+
300
+
301
+ @exception_handler
302
+ def list_dataset_replicas(args):
303
+ """
304
+ %(prog)s list [options] <field1=value1 field2=value2 ...>
305
+
306
+ List dataset replicas
307
+ """
308
+ client = get_client(args)
309
+ result = {}
310
+ datasets = []
311
+
312
+ def _append_to_datasets(scope, name):
313
+ filedid = {'scope': scope, 'name': name}
314
+ if filedid not in datasets:
315
+ datasets.append(filedid)
316
+
317
+ def _fetch_datasets_for_meta(meta):
318
+ """Internal function to fetch datasets and recurse into files."""
319
+ if meta['did_type'] != 'DATASET':
320
+ dids = client.scope_list(scope=meta['scope'], name=meta['name'], recursive=True)
321
+ for did in dids:
322
+ if did['type'] == 'FILE':
323
+ _append_to_datasets(did['parent']['scope'], did['parent']['name'])
324
+ else:
325
+ _append_to_datasets(meta['scope'], meta['name'])
326
+
327
+ def _append_result(dsn, replica):
328
+ if dsn not in result:
329
+ result[dsn] = {}
330
+ result[dsn][replica['rse']] = [replica['rse'], replica['available_length'], replica['length']]
331
+
332
+ if len(args.dids) == 1:
333
+ scope, name = get_scope(args.dids[0], client)
334
+ dmeta = client.get_metadata(scope, name)
335
+ _fetch_datasets_for_meta(meta=dmeta)
336
+ else:
337
+ extractdids = (get_scope(did, client) for did in args.dids)
338
+ splitdids = [{'scope': scope, 'name': name} for scope, name in extractdids]
339
+ for dmeta in client.get_metadata_bulk(dids=splitdids):
340
+ _fetch_datasets_for_meta(meta=dmeta)
341
+
342
+ if args.deep or len(datasets) < 2:
343
+ for did in datasets:
344
+ dsn = "%s:%s" % (did['scope'], did['name'])
345
+ for rep in client.list_dataset_replicas(scope=did['scope'], name=did['name'], deep=args.deep):
346
+ _append_result(dsn=dsn, replica=rep)
347
+ else:
348
+ for rep in client.list_dataset_replicas_bulk(dids=datasets):
349
+ dsn = "%s:%s" % (rep['scope'], rep['name'])
350
+ _append_result(dsn=dsn, replica=rep)
351
+
352
+ if args.csv:
353
+ for dsn in result:
354
+ for rse in list(result[dsn].values()):
355
+ print(rse[0], rse[1], rse[2], sep=',')
356
+ else:
357
+ for dsn in result:
358
+ print('\nDATASET: %s' % (dsn))
359
+ print(tabulate(list(result[dsn].values()), tablefmt=tablefmt, headers=['RSE', 'FOUND', 'TOTAL']))
360
+ return SUCCESS
361
+
362
+
363
+ @exception_handler
364
+ def list_file_replicas(args):
365
+ """
366
+ %(prog)s list [options] <field1=value1 field2=value2 ...>
367
+
368
+ List file replicas
369
+ """
370
+ if args.missing:
371
+ args.all_states = True
372
+ client = get_client(args)
373
+
374
+ protocols = None
375
+ if args.protocols:
376
+ protocols = args.protocols.split(',')
377
+
378
+ table = []
379
+ dids = []
380
+ if args.missing and not args.rses:
381
+ print('Cannot use --missing without specifying a RSE')
382
+ return FAILURE
383
+ if args.link and ':' not in args.link:
384
+ print('The substitution parameter must equal --link="/pfn/dir:/dst/dir"')
385
+ return FAILURE
386
+
387
+ for did in args.dids:
388
+ scope, name = get_scope(did, client)
389
+ client.get_metadata(scope=scope, name=name) # break with Exception before streaming replicas if DID does not exist
390
+ dids.append({'scope': scope, 'name': name})
391
+
392
+ replicas = client.list_replicas(dids, schemes=protocols,
393
+ ignore_availability=True,
394
+ all_states=args.all_states,
395
+ rse_expression=args.rses,
396
+ metalink=args.metalink,
397
+ client_location=detect_client_location(),
398
+ sort=args.sort, domain=args.domain,
399
+ resolve_archives=not args.no_resolve_archives)
400
+ rses = [rse["rse"] for rse in client.list_rses(rse_expression=args.rses)]
401
+
402
+ if args.metalink:
403
+ print(replicas[:-1]) # last character is newline, no need to print that
404
+ return SUCCESS
405
+
406
+ if args.missing:
407
+ for replica, rse in itertools.product(replicas, rses):
408
+ if 'states' in replica and rse in replica['states'] and replica['states'].get(rse) != 'AVAILABLE':
409
+ table.append([replica['scope'], replica['name'], "({0}) {1}".format(ReplicaState[replica['states'].get(rse)].value, rse)])
410
+ print(tabulate(table, tablefmt=tablefmt, headers=['SCOPE', 'NAME', '(STATE) RSE']))
411
+ elif args.link:
412
+ pfn_dir, dst_dir = args.link.split(':')
413
+ if args.rses:
414
+ for replica, rse in itertools.product(replicas, rses):
415
+ if replica['rses'].get(rse):
416
+ for pfn in replica['rses'][rse]:
417
+ os.symlink(dst_dir + pfn.rsplit(pfn_dir)[-1], replica['name'])
418
+ else:
419
+ for replica in replicas:
420
+ for rse in replica['rses']:
421
+ if replica['rses'][rse]:
422
+ for pfn in replica['rses'][rse]:
423
+ os.symlink(dst_dir + pfn.rsplit(pfn_dir)[-1], replica['name'])
424
+ elif args.pfns:
425
+ if args.rses:
426
+ for replica in replicas:
427
+ for pfn in replica['pfns']:
428
+ rse = replica['pfns'][pfn]['rse']
429
+ if replica['rses'].get(rse):
430
+ print(pfn)
431
+ else:
432
+ for replica in replicas:
433
+ for pfn in replica['pfns']:
434
+ rse = replica['pfns'][pfn]['rse']
435
+ if replica['rses'][rse]:
436
+ print(pfn)
437
+ else:
438
+ if args.all_states:
439
+ header = ['SCOPE', 'NAME', 'FILESIZE', 'ADLER32', '(STATE) RSE: REPLICA']
440
+ else:
441
+ header = ['SCOPE', 'NAME', 'FILESIZE', 'ADLER32', 'RSE: REPLICA']
442
+ for replica in replicas:
443
+ if 'bytes' in replica:
444
+ for pfn in replica['pfns']:
445
+ rse = replica['pfns'][pfn]['rse']
446
+ if args.all_states:
447
+ rse_string = '({2}) {0}: {1}'.format(rse, pfn, ReplicaState[replica['states'][rse]].value)
448
+ else:
449
+ rse_string = '{0}: {1}'.format(rse, pfn)
450
+ if args.rses:
451
+ for selected_rse in rses:
452
+ if rse == selected_rse:
453
+ table.append([replica['scope'], replica['name'], sizefmt(replica['bytes'], args.human), replica['adler32'], rse_string])
454
+ else:
455
+ table.append([replica['scope'], replica['name'], sizefmt(replica['bytes'], args.human), replica['adler32'], rse_string])
456
+ print(tabulate(table, tablefmt=tablefmt, headers=header, disable_numparse=True))
457
+ return SUCCESS
458
+
459
+
460
+ @exception_handler
461
+ def add_dataset(args):
462
+ """
463
+ %(prog)s add-dataset [options] <dsn>
464
+
465
+ Add a dataset identifier.
466
+ """
467
+ client = get_client(args)
468
+ scope, name = get_scope(args.did, client)
469
+ client.add_dataset(scope=scope, name=name, statuses={'monotonic': args.monotonic}, lifetime=args.lifetime)
470
+ print('Added %s:%s' % (scope, name))
471
+ return SUCCESS
472
+
473
+
474
+ @exception_handler
475
+ def add_container(args):
476
+ """
477
+ %(prog)s add-container [options] <dsn>
478
+
479
+ Add a container identifier.
480
+ """
481
+ client = get_client(args)
482
+ scope, name = get_scope(args.did, client)
483
+ client.add_container(scope=scope, name=name, statuses={'monotonic': args.monotonic}, lifetime=args.lifetime)
484
+ print('Added %s:%s' % (scope, name))
485
+ return SUCCESS
486
+
487
+
488
+ @exception_handler
489
+ def attach(args):
490
+ """
491
+ %(prog)s attach [options] <field1=value1 field2=value2 ...>
492
+
493
+ Attach a data identifier.
494
+ """
495
+ client = get_client(args)
496
+ scope, name = get_scope(args.todid, client)
497
+ dids = args.dids
498
+ limit = 499
499
+
500
+ if args.fromfile:
501
+ if len(dids) > 1:
502
+ logger.error("If --fromfile option is active, only one file is supported. The file should contain a list of dids, one per line.")
503
+ return FAILURE
504
+ try:
505
+ f = open(dids[0], 'r')
506
+ dids = [did.rstrip() for did in f.readlines()]
507
+ except OSError:
508
+ logger.error("Can't open file '" + dids[0] + "'.")
509
+ return FAILURE
510
+
511
+ dids = [{'scope': get_scope(did, client)[0], 'name': get_scope(did, client)[1]} for did in dids]
512
+ if len(dids) <= limit:
513
+ client.attach_dids(scope=scope, name=name, dids=dids)
514
+ else:
515
+ logger.warning("You are trying to attach too much DIDs. Therefore they will be chunked and attached in multiple commands.")
516
+ missing_dids = []
517
+ for i, chunk in enumerate(chunks(dids, limit)):
518
+ logger.info("Try to attach chunk {0}/{1}".format(i, int(math.ceil(float(len(dids)) / float(limit)))))
519
+ try:
520
+ client.attach_dids(scope=scope, name=name, dids=chunk)
521
+ except Exception:
522
+ content = [{'scope': did['scope'], 'name': did['name']} for did in client.list_content(scope=scope, name=name)]
523
+ missing_dids += [did for did in chunk if did not in content]
524
+
525
+ if missing_dids:
526
+ for chunk in chunks(missing_dids, limit):
527
+ client.attach_dids(scope=scope, name=name, dids=chunk)
528
+
529
+ print('DIDs successfully attached to %s:%s' % (scope, name))
530
+ return SUCCESS
531
+
532
+
533
+ @exception_handler
534
+ def detach(args):
535
+ """
536
+ %(prog)s detach [options] <field1=value1 field2=value2 ...>
537
+
538
+ Detach data identifier.
539
+ """
540
+ client = get_client(args)
541
+ scope, name = get_scope(args.fromdid, client)
542
+ dids = []
543
+ for did in args.dids:
544
+ cscope, cname = get_scope(did, client)
545
+ dids.append({'scope': cscope, 'name': cname})
546
+ client.detach_dids(scope=scope, name=name, dids=dids)
547
+ print('DIDs successfully detached from %s:%s' % (scope, name))
548
+ return SUCCESS
549
+
550
+
551
+ @exception_handler
552
+ def list_dids(args):
553
+ """
554
+ %(prog)s list-dids scope[:*|:name] [--filter 'value' | --recursive]
555
+
556
+ List the data identifiers for a given scope.
557
+ """
558
+ client = get_client(args)
559
+ filters = {}
560
+ type_ = 'collection'
561
+ table = []
562
+
563
+ try:
564
+ scope, name = get_scope(args.did[0], client)
565
+ if name == '':
566
+ name = '*'
567
+ except InvalidObject:
568
+ scope = args.did[0]
569
+ name = '*'
570
+
571
+ if scope not in client.list_scopes():
572
+ logger.error('Scope not found')
573
+ return FAILURE
574
+
575
+ if args.recursive and '*' in name:
576
+ logger.error('Option recursive cannot be used with wildcards')
577
+ return FAILURE
578
+ else:
579
+ if filters:
580
+ if ('name' in filters) and (name != '*'):
581
+ logger.error('Must have a wildcard in did name if filtering by name')
582
+ return FAILURE
583
+
584
+ try:
585
+ filters, type_ = parse_did_filter_from_string_fe(args.filter, name)
586
+ except InvalidType as error:
587
+ logger.error(error)
588
+ return FAILURE
589
+ except DuplicateCriteriaInDIDFilter as error:
590
+ logger.error(error)
591
+ return FAILURE
592
+ except DIDFilterSyntaxError as error:
593
+ logger.error(error)
594
+ return FAILURE
595
+ except ValueError as error:
596
+ logger.error(error)
597
+ return FAILURE
598
+ except Exception as e:
599
+ logger.error(e)
600
+ return FAILURE
601
+
602
+ for did in client.list_dids(scope, filters=filters, did_type=type_, long=True, recursive=args.recursive):
603
+ table.append(['%s:%s' % (did['scope'], did['name']), did['did_type']])
604
+
605
+ if args.short:
606
+ for did, _ in table:
607
+ print(did)
608
+ else:
609
+ print(tabulate(table, tablefmt=tablefmt, headers=['SCOPE:NAME', '[DID TYPE]']))
610
+
611
+ return SUCCESS
612
+
613
+
614
+ @exception_handler
615
+ def list_dids_extended(args):
616
+ """
617
+ %(prog)s list-dids-extended scope[:*|:name] [--filter 'key=value' | --recursive]
618
+
619
+ List the data identifiers for a given scope (DEPRECATED).
620
+ """
621
+ logger.error("This command has been deprecated. Please use list_dids instead.")
622
+ return FAILURE
623
+
624
+
625
+ @exception_handler
626
+ def list_scopes(args):
627
+ """
628
+ %(prog)s list-scopes <scope>
629
+
630
+ List scopes.
631
+ """
632
+ # For the moment..
633
+ client = get_client(args)
634
+ scopes = client.list_scopes()
635
+ for scope in scopes:
636
+ print(scope)
637
+ return SUCCESS
638
+
639
+
640
+ @exception_handler
641
+ def list_files(args):
642
+ """
643
+ %(prog)s list-files [options] <field1=value1 field2=value2 ...>
644
+
645
+ List data identifier contents.
646
+ """
647
+ client = get_client(args)
648
+ if args.csv:
649
+ for did in args.dids:
650
+ scope, name = get_scope(did, client)
651
+ for f in client.list_files(scope=scope, name=name):
652
+ guid = f['guid']
653
+ if guid:
654
+ guid = '%s-%s-%s-%s-%s' % (guid[0:8], guid[8:12], guid[12:16], guid[16:20], guid[20:32])
655
+ else:
656
+ guid = '(None)'
657
+ print('{}:{}'.format(f['scope'], f['name']), guid, f['adler32'], sizefmt(f['bytes'], args.human), f['events'], sep=',')
658
+ return SUCCESS
659
+ elif args.LOCALPATH:
660
+
661
+ print('''<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
662
+ <!DOCTYPE POOLFILECATALOG SYSTEM "InMemory">
663
+ <POOLFILECATALOG>''')
664
+
665
+ file_str = ''' <File ID="%s">
666
+ <physical>
667
+ <pfn filetype="ROOT_All" name="%s/%s"/>
668
+ </physical>
669
+ <logical>
670
+ <lfn name="%s"/>
671
+ </logical>
672
+ </File>'''
673
+
674
+ for did in args.dids:
675
+ scope, name = get_scope(did, client)
676
+ for f in client.list_files(scope=scope, name=name):
677
+ guid = f['guid']
678
+ if guid:
679
+ guid = '%s-%s-%s-%s-%s' % (guid[0:8], guid[8:12], guid[12:16], guid[16:20], guid[20:32])
680
+ else:
681
+ guid = '(None)'
682
+ print(file_str % (guid, args.LOCALPATH, f['name'], f['name']))
683
+
684
+ print('</POOLFILECATALOG>')
685
+ return SUCCESS
686
+ else:
687
+ table = []
688
+ for did in args.dids:
689
+ totfiles = 0
690
+ totsize = 0
691
+ totevents = 0
692
+ scope, name = get_scope(did, client)
693
+ for file in client.list_files(scope=scope, name=name):
694
+ totfiles += 1
695
+ totsize += int(file['bytes'])
696
+ if file['events']:
697
+ totevents += int(file.get('events', 0))
698
+ guid = file['guid']
699
+ if guid:
700
+ guid = '%s-%s-%s-%s-%s' % (guid[0:8], guid[8:12], guid[12:16], guid[16:20], guid[20:32])
701
+ else:
702
+ guid = '(None)'
703
+ table.append(['%s:%s' % (file['scope'], file['name']), guid, 'ad:%s' % file['adler32'], sizefmt(file['bytes'], args.human), file['events']])
704
+ print(tabulate(table, tablefmt=tablefmt, headers=['SCOPE:NAME', 'GUID', 'ADLER32', 'FILESIZE', 'EVENTS'], disable_numparse=True))
705
+ print('Total files : %s' % totfiles)
706
+ print('Total size : %s' % sizefmt(totsize, args.human))
707
+ if totevents:
708
+ print('Total events : %s' % totevents)
709
+ return SUCCESS
710
+
711
+
712
+ @exception_handler
713
+ def list_content(args):
714
+ """
715
+ %(prog)s list-content [options] <field1=value1 field2=value2 ...>
716
+
717
+ List data identifier contents.
718
+ """
719
+ client = get_client(args)
720
+ table = []
721
+ for did in args.dids:
722
+ scope, name = get_scope(did, client)
723
+ for content in client.list_content(scope=scope, name=name):
724
+ table.append(['%s:%s' % (content['scope'], content['name']), content['type'].upper()])
725
+ if args.short:
726
+ for did, dummy in table:
727
+ print(did)
728
+ else:
729
+ print(tabulate(table, tablefmt=tablefmt, headers=['SCOPE:NAME', '[DID TYPE]']))
730
+ return SUCCESS
731
+
732
+
733
+ @exception_handler
734
+ def list_content_history(args):
735
+ """
736
+ %(prog)s list-content-history [options] <field1=value1 field2=value2 ...>
737
+
738
+ List data identifier contents.
739
+ """
740
+ client = get_client(args)
741
+ table = []
742
+ for did in args.dids:
743
+ scope, name = get_scope(did, client)
744
+ for content in client.list_content_history(scope=scope, name=name):
745
+ table.append(['%s:%s' % (content['scope'], content['name']), content['type'].upper()])
746
+ print(tabulate(table, tablefmt=tablefmt, headers=['SCOPE:NAME', '[DID TYPE]']))
747
+ return SUCCESS
748
+
749
+
750
+ @exception_handler
751
+ def list_parent_dids(args):
752
+ """
753
+ %(prog)s list-parent-dids
754
+
755
+ List parent data identifier.
756
+ """
757
+ client = get_client(args)
758
+ if args.pfns:
759
+ dict_datasets = {}
760
+ for res in client.get_did_from_pfns(args.pfns):
761
+ for key in res:
762
+ if key not in dict_datasets:
763
+ dict_datasets[key] = []
764
+ for rule in client.list_associated_rules_for_file(res[key]['scope'], res[key]['name']):
765
+ if '%s:%s' % (rule['scope'], rule['name']) not in dict_datasets[key]:
766
+ dict_datasets[key].append('%s:%s' % (rule['scope'], rule['name']))
767
+ for pfn in dict_datasets:
768
+ print('PFN: ', pfn)
769
+ print('Parents: ', ','.join(dict_datasets[pfn]))
770
+ elif args.guids:
771
+ guids = []
772
+ for input_ in args.guids:
773
+ try:
774
+ uuid.UUID(input_)
775
+ except ValueError:
776
+ continue
777
+ dict_datasets = {}
778
+ for guid in guids:
779
+ for did in client.get_dataset_by_guid(guid):
780
+ if guid not in dict_datasets:
781
+ dict_datasets[guid] = []
782
+ for rule in client.list_associated_rules_for_file(did['scope'], did['name']):
783
+ if '%s:%s' % (rule['scope'], rule['name']) not in dict_datasets[guid]:
784
+ dict_datasets[guid].append('%s:%s' % (rule['scope'], rule['name']))
785
+ for guid in dict_datasets:
786
+ print('GUID: ', guid)
787
+ print('Parents : ', ','.join(dict_datasets[guid]))
788
+ elif args.did:
789
+ table = []
790
+ scope, name = get_scope(args.did, client)
791
+ for dataset in client.list_parent_dids(scope=scope, name=name):
792
+ table.append(['%s:%s' % (dataset['scope'], dataset['name']), dataset['type']])
793
+ print(tabulate(table, tablefmt=tablefmt, headers=['SCOPE:NAME', '[DID TYPE]']))
794
+ else:
795
+ print('At least one option has to be given. Use -h to list the options.')
796
+ return FAILURE
797
+ return SUCCESS
798
+
799
+
800
+ @exception_handler
801
+ def close(args):
802
+ """
803
+ %(prog)s close [options] <field1=value1 field2=value2 ...>
804
+
805
+ Close a dataset or container.
806
+ """
807
+ client = get_client(args)
808
+ for did in args.dids:
809
+ scope, name = get_scope(did, client)
810
+ client.set_status(scope=scope, name=name, open=False)
811
+ print(f'{scope}:{name} has been closed.')
812
+ return SUCCESS
813
+
814
+
815
+ @exception_handler
816
+ def reopen(args):
817
+ """
818
+ %(prog)s reopen [options] <field1=value1 field2=value2 ...>
819
+
820
+ Reopen a dataset or container (only for privileged users).
821
+ """
822
+ client = get_client(args)
823
+ for did in args.dids:
824
+ scope, name = get_scope(did, client)
825
+ client.set_status(scope=scope, name=name, open=True)
826
+ print(f'{scope}:{name} has been reopened.')
827
+ return SUCCESS
828
+
829
+
830
+ @exception_handler
831
+ def stat(args):
832
+ """
833
+ %(prog)s stat [options] <field1=value1 field2=value2 ...>
834
+
835
+ List attributes and statuses about data identifiers..
836
+ """
837
+ client = get_client(args)
838
+ for i, did in enumerate(args.dids):
839
+ if i > 0:
840
+ print('------')
841
+ scope, name = get_scope(did, client)
842
+ info = client.get_did(scope=scope, name=name, dynamic_depth='DATASET')
843
+ table = [(k + ':', str(v)) for (k, v) in sorted(info.items())]
844
+ print(tabulate(table, tablefmt='plain', disable_numparse=True))
845
+ return SUCCESS
846
+
847
+
848
+ def erase(args):
849
+ """
850
+ %(prog)s erase [options] <field1=value1 field2=value2 ...>
851
+
852
+ Delete data identifier.
853
+ """
854
+ client = get_client(args)
855
+ for did in args.dids:
856
+ if '*' in did:
857
+ logger.warning("This command doesn't support wildcards! Skipping DID: %s" % did)
858
+ continue
859
+ try:
860
+ scope, name = get_scope(did, client)
861
+ except RucioException as error:
862
+ logger.warning('DID is in wrong format: %s' % did)
863
+ logger.debug('Error: %s' % error)
864
+ continue
865
+
866
+ if args.undo:
867
+ try:
868
+ client.set_metadata(scope=scope, name=name, key='lifetime', value=None)
869
+ logger.info('Erase undo for DID: {0}:{1}'.format(scope, name))
870
+ except Exception:
871
+ logger.warning('Cannot undo erase operation on DID. DID not existent or grace period of 24 hours already expired.')
872
+ logger.warning(' DID: {0}:{1}'.format(scope, name))
873
+ else:
874
+ try:
875
+ # set lifetime to expire in 24 hours (value is in seconds).
876
+ client.set_metadata(scope=scope, name=name, key='lifetime', value=86400)
877
+ logger.info('CAUTION! erase operation is irreversible after 24 hours. To cancel this operation you can run the following command:')
878
+ print("rucio erase --undo {0}:{1}".format(scope, name))
879
+ except RucioException as error:
880
+ logger.warning('Failed to erase DID: %s' % did)
881
+ logger.debug('Error: %s' % error)
882
+ return SUCCESS
883
+
884
+
885
+ @exception_handler
886
+ def upload(args):
887
+ """
888
+ rucio upload [scope:datasetname] [folder/] [files1 file2 file3]
889
+ %(prog)s upload [options] <field1=value1 field2=value2 ...>
890
+
891
+ Upload files into Rucio
892
+ """
893
+ if args.lifetime and args.expiration_date:
894
+ logger.error("--lifetime and --expiration-date cannot be specified at the same time.")
895
+ return FAILURE
896
+ elif args.expiration_date:
897
+ expiration_date = datetime.strptime(args.expiration_date, "%Y-%m-%d-%H:%M:%S")
898
+ if expiration_date < datetime.utcnow():
899
+ logger.error("The specified expiration date should be in the future!")
900
+ return FAILURE
901
+ args.lifetime = (expiration_date - datetime.utcnow()).total_seconds()
902
+
903
+ dsscope = None
904
+ dsname = None
905
+ for arg in args.args:
906
+ did = arg.split(':')
907
+ if not dsscope and len(did) == 2:
908
+ dsscope = did[0]
909
+ dsname = did[1]
910
+ elif len(did) == 2:
911
+ logger.warning('Ignoring input {} because dataset DID is already set {}:{}'.format(arg, dsscope, dsname))
912
+
913
+ items = []
914
+ for arg in args.args:
915
+ if arg.count(':') > 0:
916
+ continue
917
+ if args.pfn:
918
+ if args.impl:
919
+ logger.warning('Ignoring --impl option because --pfn option given')
920
+ args.impl = None
921
+ items.append({'path': arg,
922
+ 'rse': args.rse,
923
+ 'did_scope': args.scope,
924
+ 'did_name': args.name,
925
+ 'impl': args.impl,
926
+ 'dataset_scope': dsscope,
927
+ 'dataset_name': dsname,
928
+ 'force_scheme': args.protocol,
929
+ 'pfn': args.pfn,
930
+ 'no_register': args.no_register,
931
+ 'lifetime': args.lifetime,
932
+ 'register_after_upload': args.register_after_upload,
933
+ 'transfer_timeout': args.transfer_timeout,
934
+ 'guid': args.guid,
935
+ 'recursive': args.recursive})
936
+
937
+ if len(items) < 1:
938
+ raise InputValidationError('No files could be extracted from the given arguments')
939
+
940
+ if len(items) > 1 and args.guid:
941
+ logger.error("A single GUID was specified on the command line, but there are multiple files to upload.")
942
+ logger.error("If GUID auto-detection is not used, only one file may be uploaded at a time")
943
+ raise InputValidationError('Invalid input argument composition')
944
+ if len(items) > 1 and args.name:
945
+ logger.error("A single LFN was specified on the command line, but there are multiple files to upload.")
946
+ logger.error("If LFN auto-detection is not used, only one file may be uploaded at a time")
947
+ raise InputValidationError('Invalid input argument composition')
948
+
949
+ if args.recursive and args.pfn:
950
+ logger.error("It is not possible to create the folder structure into collections with a non-deterministic way.")
951
+ logger.error("If PFN is specified, you cannot use --recursive")
952
+ raise InputValidationError('Invalid input argument composition')
953
+
954
+ client = get_client(args)
955
+ from rucio.client.uploadclient import UploadClient
956
+ upload_client = UploadClient(client, logger=logger)
957
+ summary_file_path = 'rucio_upload.json' if args.summary else None
958
+ upload_client.upload(items, summary_file_path)
959
+ return SUCCESS
960
+
961
+
962
+ @exception_handler
963
+ def download(args):
964
+ """
965
+ %(prog)s download [options] <field1=value1 field2=value2 ...>
966
+
967
+ Download files from Rucio using new threaded model and RSE expression support
968
+ """
969
+ # Input validation
970
+ if not args.dids and not args.filter and not args.metalink_file:
971
+ logger.error('At least one did is mandatory')
972
+ return FAILURE
973
+ elif not args.dids and args.filter and not args.scope:
974
+ logger.error('The argument scope is mandatory')
975
+ return FAILURE
976
+
977
+ if args.filter and args.metalink_file:
978
+ logger.error('Arguments filter and metalink cannot be used together.')
979
+ return FAILURE
980
+
981
+ if args.dids and args.metalink_file:
982
+ logger.error('Arguments dids and metalink cannot be used together.')
983
+ return FAILURE
984
+
985
+ if args.ignore_checksum and args.check_local_with_filesize_only:
986
+ logger.error('Arguments ignore-checksum and check-local-with-filesize-only cannot be used together.')
987
+ return FAILURE
988
+
989
+ trace_pattern = {}
990
+
991
+ if args.trace_appid:
992
+ trace_pattern['appid'] = args.trace_appid
993
+ if args.trace_dataset:
994
+ trace_pattern['dataset'] = args.trace_dataset
995
+ if args.trace_datasetscope:
996
+ trace_pattern['datasetScope'] = args.trace_datasetscope
997
+ if args.trace_eventtype:
998
+ trace_pattern['eventType'] = args.trace_eventtype
999
+ if args.trace_pq:
1000
+ trace_pattern['pq'] = args.trace_pq
1001
+ if args.trace_taskid:
1002
+ trace_pattern['taskid'] = args.trace_taskid
1003
+ if args.trace_usrdn:
1004
+ trace_pattern['usrdn'] = args.trace_usrdn
1005
+ deactivate_file_download_exceptions = args.deactivate_file_download_exceptions if args.deactivate_file_download_exceptions is not None else False
1006
+
1007
+ client = get_client(args)
1008
+ from rucio.client.downloadclient import DownloadClient
1009
+ download_client = DownloadClient(client=client, logger=logger, check_admin=args.allow_tape)
1010
+
1011
+ result = None
1012
+ item_defaults = {}
1013
+ item_defaults['rse'] = args.rses
1014
+ item_defaults['base_dir'] = args.dir
1015
+ item_defaults['no_subdir'] = args.no_subdir
1016
+ item_defaults['transfer_timeout'] = args.transfer_timeout
1017
+ item_defaults['no_resolve_archives'] = args.no_resolve_archives
1018
+ item_defaults['ignore_checksum'] = args.ignore_checksum
1019
+ item_defaults['check_local_with_filesize_only'] = args.check_local_with_filesize_only
1020
+ archive_did = args.archive_did
1021
+ if archive_did:
1022
+ logger.warning("Archives are treated transparently. --archive-did option is being obsoleted.") # TODO
1023
+
1024
+ # Get filters
1025
+ filters = {}
1026
+ type_ = 'all'
1027
+ if args.filter:
1028
+ try:
1029
+ filters, type_ = parse_did_filter_from_string(args.filter)
1030
+ if args.scope:
1031
+ filters['scope'] = args.scope
1032
+ except InvalidType as error:
1033
+ logger.error(error)
1034
+ return FAILURE
1035
+ except ValueError as error:
1036
+ logger.error(error)
1037
+ return FAILURE
1038
+ except Exception as error:
1039
+ logger.error(error)
1040
+ logger.error("Invalid Filter. Filter must be 'key=value', 'key>=value', 'key>value', 'key<=value', 'key<value'")
1041
+ return FAILURE
1042
+ item_defaults['filters'] = filters
1043
+
1044
+ if not args.pfn:
1045
+ item_defaults['impl'] = args.impl
1046
+ item_defaults['force_scheme'] = args.protocol
1047
+ item_defaults['nrandom'] = args.nrandom
1048
+ item_defaults['transfer_speed_timeout'] = args.transfer_speed_timeout \
1049
+ if args.transfer_speed_timeout is not None \
1050
+ else config_get_float('download', 'transfer_speed_timeout', False, 500)
1051
+ items = []
1052
+ if args.dids:
1053
+ for did in args.dids:
1054
+ item = {'did': did}
1055
+ item.update(item_defaults)
1056
+ items.append(item)
1057
+ else:
1058
+ items.append(item_defaults)
1059
+
1060
+ if args.aria:
1061
+ result = download_client.download_aria2c(items, trace_pattern, deactivate_file_download_exceptions=deactivate_file_download_exceptions, sort=args.sort)
1062
+ elif args.metalink_file:
1063
+ result = download_client.download_from_metalink_file(items[0], args.metalink_file, deactivate_file_download_exceptions=deactivate_file_download_exceptions)
1064
+ if args.sort:
1065
+ logger.warning('Ignoring --replica-selection option because --metalink option given')
1066
+ else:
1067
+ result = download_client.download_dids(items, args.ndownloader, trace_pattern, deactivate_file_download_exceptions=deactivate_file_download_exceptions, sort=args.sort)
1068
+ else:
1069
+ if args.aria:
1070
+ logger.warning('Ignoring --aria option because --pfn option given')
1071
+ if args.impl:
1072
+ logger.warning('Ignoring --impl option because --pfn option given')
1073
+ if args.protocol:
1074
+ logger.warning('Ignoring --protocol option because --pfn option given')
1075
+ if args.transfer_speed_timeout:
1076
+ logger.warning("Download with --pfn doesn't support --transfer-speed-timeout")
1077
+ num_dids = len(args.dids)
1078
+ did_str = args.dids[0]
1079
+ if num_dids > 1:
1080
+ logger.warning('Download with --pfn option only supports one DID but {} DIDs were given. Considering only first DID: {}'.format(num_dids, did_str))
1081
+ logger.debug(args.dids)
1082
+ item_defaults['pfn'] = args.pfn
1083
+ item_defaults['did'] = did_str
1084
+ if args.rses is None:
1085
+ logger.warning("No RSE was given, selecting one.")
1086
+ client = get_client(args)
1087
+ replicas = client.list_replicas(
1088
+ [{"scope": did_str.split(':')[0], "name": did_str.split(':')[-1]}],
1089
+ schemes=args.protocol,
1090
+ ignore_availability=False,
1091
+ client_location=detect_client_location(),
1092
+ resolve_archives=not args.no_resolve_archives
1093
+ )
1094
+
1095
+ download_rse = _get_rse_for_pfn(replicas, args.pfn)
1096
+ if download_rse is None:
1097
+ logger.error("Could not find RSE for pfn %s", args.pfn)
1098
+ return FAILURE
1099
+ else:
1100
+ item_defaults['rse'] = download_rse
1101
+
1102
+ result = download_client.download_pfns([item_defaults], 1, trace_pattern, deactivate_file_download_exceptions=deactivate_file_download_exceptions)
1103
+
1104
+ if not result:
1105
+ raise RucioException('Download API failed')
1106
+
1107
+ summary = {}
1108
+ for item in result:
1109
+ for did, did_stats in item.get('input_dids', {}).items():
1110
+ did_summary = summary.setdefault(did, {'length': did_stats.get('length'), 'DONE': 0, 'ALREADY_DONE': 0, '_total': 0})
1111
+ did_summary['_total'] += 1
1112
+ state = item['clientState'].upper()
1113
+ if state in did_summary:
1114
+ did_summary[state] += 1
1115
+
1116
+ print('----------------------------------')
1117
+ print('Download summary')
1118
+ if not len(summary):
1119
+ print('-' * 40)
1120
+ print('No DID matching the pattern')
1121
+
1122
+ for summary_key, did_summary in summary.items():
1123
+ print('-' * 40)
1124
+ print('DID %s' % summary_key)
1125
+ length = did_summary['length']
1126
+ ds_total = did_summary['_total']
1127
+ downloaded_files = did_summary['DONE']
1128
+ local_files = did_summary['ALREADY_DONE']
1129
+ not_downloaded_files = ds_total - downloaded_files - local_files
1130
+
1131
+ if length:
1132
+ print('{0:40} {1:6d}'.format('Total files (DID): ', length))
1133
+ print('{0:40} {1:6d}'.format('Total files (filtered): ', ds_total))
1134
+ else:
1135
+ print('{0:40} {1:6d}'.format('Total files: ', ds_total))
1136
+ print('{0:40} {1:6d}'.format('Downloaded files: ', downloaded_files))
1137
+ print('{0:40} {1:6d}'.format('Files already found locally: ', local_files))
1138
+ print('{0:40} {1:6d}'.format('Files that cannot be downloaded: ', not_downloaded_files))
1139
+
1140
+ return SUCCESS
1141
+
1142
+
1143
+ def _get_rse_for_pfn(replicas, pfn) -> Optional[str]:
1144
+ # Check each rse in the replica list for the pfn. If no pfn is found, returns None.
1145
+ # If it is found, stop the generator and return the item.
1146
+ for replica in replicas:
1147
+ try:
1148
+ download_rse = next(
1149
+ rse for rse in replica['rses']
1150
+ if pfn in replica['rses'][rse]
1151
+ )
1152
+ except StopIteration:
1153
+ continue
1154
+ else:
1155
+ return download_rse
1156
+
1157
+
1158
+ @exception_handler
1159
+ def get_metadata(args):
1160
+ """
1161
+ %(prog)s get_metadata [options] <field1=value1 field2=value2 ...>
1162
+
1163
+ Get data identifier metadata
1164
+ """
1165
+ client = get_client(args)
1166
+ if args.plugin:
1167
+ plugin = args.plugin
1168
+ else:
1169
+ plugin = config_get('client', 'metadata_default_plugin', default='DID_COLUMN')
1170
+
1171
+ for i, did in enumerate(args.dids):
1172
+ if i > 0:
1173
+ print('------')
1174
+ scope, name = get_scope(did, client)
1175
+ meta = client.get_metadata(scope=scope, name=name, plugin=plugin)
1176
+ table = [(k + ':', str(v)) for (k, v) in sorted(meta.items())]
1177
+ print(tabulate(table, tablefmt='plain', disable_numparse=True))
1178
+ return SUCCESS
1179
+
1180
+
1181
+ @exception_handler
1182
+ def set_metadata(args):
1183
+ """
1184
+ %(prog)s set_metadata [options] <field1=value1 field2=value2 ...>
1185
+
1186
+ Set data identifier metadata
1187
+ """
1188
+ client = get_client(args)
1189
+ value = args.value
1190
+ if args.key == 'lifetime':
1191
+ value = None if args.value.lower() == 'none' else float(args.value)
1192
+ scope, name = get_scope(args.did, client)
1193
+ client.set_metadata(scope=scope, name=name, key=args.key, value=value)
1194
+ return SUCCESS
1195
+
1196
+
1197
+ @exception_handler
1198
+ def delete_metadata(args):
1199
+ """
1200
+ %(prog)s set_metadata [options] <field1=value1 field2=value2 ...>
1201
+
1202
+ Delete data identifier metadata
1203
+ """
1204
+ client = get_client(args)
1205
+ scope, name = get_scope(args.did, client)
1206
+ client.delete_metadata(scope=scope, name=name, key=args.key)
1207
+ return SUCCESS
1208
+
1209
+
1210
+ @exception_handler
1211
+ def add_rule(args):
1212
+ """
1213
+ %(prog)s add-rule <did> <copies> <rse-expression> [options]
1214
+
1215
+ Add a rule to a did.
1216
+ """
1217
+ client = get_client(args)
1218
+ dids = []
1219
+ rule_ids = []
1220
+ for did in args.dids:
1221
+ scope, name = get_scope(did, client)
1222
+ dids.append({'scope': scope, 'name': name})
1223
+ try:
1224
+ rule_ids = client.add_replication_rule(dids=dids,
1225
+ copies=args.copies,
1226
+ rse_expression=args.rse_expression,
1227
+ weight=args.weight,
1228
+ lifetime=args.lifetime,
1229
+ grouping=args.grouping,
1230
+ account=args.rule_account,
1231
+ locked=args.locked,
1232
+ source_replica_expression=args.source_replica_expression,
1233
+ notify=args.notify,
1234
+ activity=args.activity,
1235
+ comment=args.comment,
1236
+ ask_approval=args.ask_approval,
1237
+ asynchronous=args.asynchronous,
1238
+ delay_injection=args.delay_injection)
1239
+ except DuplicateRule as error:
1240
+ if args.ignore_duplicate:
1241
+ for did in dids:
1242
+ try:
1243
+ rule_id = client.add_replication_rule(dids=[did],
1244
+ copies=args.copies,
1245
+ rse_expression=args.rse_expression,
1246
+ weight=args.weight,
1247
+ lifetime=args.lifetime,
1248
+ grouping=args.grouping,
1249
+ account=args.rule_account,
1250
+ locked=args.locked,
1251
+ source_replica_expression=args.source_replica_expression,
1252
+ notify=args.notify,
1253
+ activity=args.activity,
1254
+ comment=args.comment,
1255
+ ask_approval=args.ask_approval,
1256
+ asynchronous=args.asynchronous,
1257
+ delay_injection=args.delay_injection)
1258
+ rule_ids.extend(rule_id)
1259
+ except DuplicateRule:
1260
+ print('Duplicate rule for %s:%s found; Skipping.' % (did['scope'], did['name']))
1261
+ else:
1262
+ raise error
1263
+
1264
+ for rule in rule_ids:
1265
+ print(rule)
1266
+ return SUCCESS
1267
+
1268
+
1269
+ @exception_handler
1270
+ def delete_rule(args):
1271
+ """
1272
+ %(prog)s delete-rule [options] <ruleid>
1273
+
1274
+ Delete a rule.
1275
+ """
1276
+ client = get_client(args)
1277
+
1278
+ try:
1279
+ # Test if the rule_id is a real rule_id
1280
+ uuid.UUID(args.rule_id)
1281
+ client.delete_replication_rule(rule_id=args.rule_id, purge_replicas=args.purge_replicas)
1282
+ except ValueError:
1283
+ # Otherwise, trying to extract the scope, name from args.rule_id
1284
+ if not args.rses:
1285
+ logger.error('A RSE expression must be specified if you do not provide a rule_id but a DID')
1286
+ return FAILURE
1287
+ scope, name = get_scope(args.rule_id, client)
1288
+ rules = client.list_did_rules(scope=scope, name=name)
1289
+ if args.rule_account is None:
1290
+ account = client.account
1291
+ else:
1292
+ account = args.rule_account
1293
+ deletion_success = False
1294
+ for rule in rules:
1295
+ if args.delete_all:
1296
+ account_checked = True
1297
+ else:
1298
+ account_checked = rule['account'] == account
1299
+ if rule['rse_expression'] == args.rses and account_checked:
1300
+ client.delete_replication_rule(rule_id=rule['id'], purge_replicas=args.purge_replicas)
1301
+ deletion_success = True
1302
+ if not deletion_success:
1303
+ logger.error('No replication rule was deleted from the DID')
1304
+ return FAILURE
1305
+ return SUCCESS
1306
+
1307
+
1308
+ @exception_handler
1309
+ def update_rule(args):
1310
+ """
1311
+ %(prog)s update-rule [options] <ruleid>
1312
+
1313
+ Update a rule.
1314
+ """
1315
+ client = get_client(args)
1316
+ options = {}
1317
+ if args.lifetime:
1318
+ options['lifetime'] = None if args.lifetime.lower() == "none" else int(args.lifetime)
1319
+ if args.locked:
1320
+ if args.locked.title() == "True":
1321
+ options['locked'] = True
1322
+ elif args.locked.title() == "False":
1323
+ options['locked'] = False
1324
+ else:
1325
+ logger.error('Locked must be True or False')
1326
+ return FAILURE
1327
+ if args.comment:
1328
+ options['comment'] = args.comment
1329
+ if args.rule_account:
1330
+ options['account'] = args.rule_account
1331
+ if args.state_stuck:
1332
+ options['state'] = 'STUCK'
1333
+ if args.state_suspended:
1334
+ options['state'] = 'SUSPENDED'
1335
+ if args.rule_activity:
1336
+ options['activity'] = args.rule_activity
1337
+ if args.source_replica_expression:
1338
+ options['source_replica_expression'] = None if args.source_replica_expression.lower() == 'none' else args.source_replica_expression
1339
+ if args.cancel_requests:
1340
+ if 'state' not in options:
1341
+ logger.error('--stuck or --suspend must be specified when running --cancel-requests')
1342
+ return FAILURE
1343
+ options['cancel_requests'] = True
1344
+ if args.priority:
1345
+ options['priority'] = int(args.priority)
1346
+ if args.child_rule_id:
1347
+ if args.child_rule_id.lower() == 'none':
1348
+ options['child_rule_id'] = None
1349
+ else:
1350
+ options['child_rule_id'] = args.child_rule_id
1351
+ if args.boost_rule:
1352
+ options['boost_rule'] = args.boost_rule
1353
+ client.update_replication_rule(rule_id=args.rule_id, options=options)
1354
+ print('Updated Rule')
1355
+ return SUCCESS
1356
+
1357
+
1358
+ @exception_handler
1359
+ def move_rule(args):
1360
+ """
1361
+ %(prog)s move-rule [options] <ruleid> <rse_expression>
1362
+
1363
+ Update a rule.
1364
+ """
1365
+ client = get_client(args)
1366
+
1367
+ override = {}
1368
+ if args.activity:
1369
+ override['activity'] = args.activity
1370
+ if args.source_replica_expression:
1371
+ override['source_replica_expression'] = None if args.source_replica_expression.lower() == "none" else args.source_replica_expression
1372
+
1373
+ print(client.move_replication_rule(rule_id=args.rule_id,
1374
+ rse_expression=args.rse_expression,
1375
+ override=override))
1376
+ return SUCCESS
1377
+
1378
+
1379
+ @exception_handler
1380
+ def info_rule(args):
1381
+ """
1382
+ %(prog)s rule-info [options] <ruleid>
1383
+
1384
+ Retrieve information about a rule.
1385
+ """
1386
+ client = get_client(args)
1387
+ if args.examine:
1388
+ analysis = client.examine_replication_rule(rule_id=args.rule_id)
1389
+ print('Status of the replication rule: %s' % analysis['rule_error'])
1390
+ if analysis['transfers']:
1391
+ print('STUCK Requests:')
1392
+ for transfer in analysis['transfers']:
1393
+ print(' %s:%s' % (transfer['scope'], transfer['name']))
1394
+ print(' RSE: %s' % str(transfer['rse']))
1395
+ print(' Attempts: %s' % str(transfer['attempts']))
1396
+ print(' Last Retry: %s' % str(transfer['last_time']))
1397
+ print(' Last error: %s' % str(transfer['last_error']))
1398
+ print(' Last source: %s' % str(transfer['last_source']))
1399
+ print(' Available sources: %s' % ', '.join([source[0] for source in transfer['sources'] if source[1]]))
1400
+ print(' Blocklisted sources: %s' % ', '.join([source[0] for source in transfer['sources'] if not source[1]]))
1401
+ else:
1402
+ rule = client.get_replication_rule(rule_id=args.rule_id)
1403
+ print("Id: %s" % rule['id'])
1404
+ print("Account: %s" % rule['account'])
1405
+ print("Scope: %s" % rule['scope'])
1406
+ print("Name: %s" % rule['name'])
1407
+ print("RSE Expression: %s" % rule['rse_expression'])
1408
+ print("Copies: %s" % rule['copies'])
1409
+ print("State: %s" % rule['state'])
1410
+ print("Locks OK/REPLICATING/STUCK: %s/%s/%s" % (rule['locks_ok_cnt'], rule['locks_replicating_cnt'], rule['locks_stuck_cnt']))
1411
+ print("Grouping: %s" % rule['grouping'])
1412
+ print("Expires at: %s" % rule['expires_at'])
1413
+ print("Locked: %s" % rule['locked'])
1414
+ print("Weight: %s" % rule['weight'])
1415
+ print("Created at: %s" % rule['created_at'])
1416
+ print("Updated at: %s" % rule['updated_at'])
1417
+ print("Error: %s" % rule['error'])
1418
+ print("Subscription Id: %s" % rule['subscription_id'])
1419
+ print("Source replica expression: %s" % rule['source_replica_expression'])
1420
+ print("Activity: %s" % rule['activity'])
1421
+ print("Comment: %s" % rule['comments'])
1422
+ print("Ignore Quota: %s" % rule['ignore_account_limit'])
1423
+ print("Ignore Availability: %s" % rule['ignore_availability'])
1424
+ print("Purge replicas: %s" % rule['purge_replicas'])
1425
+ print("Notification: %s" % rule['notification'])
1426
+ print("End of life: %s" % rule['eol_at'])
1427
+ print("Child Rule Id: %s" % rule['child_rule_id'])
1428
+ return SUCCESS
1429
+
1430
+
1431
+ @exception_handler
1432
+ def list_rules(args):
1433
+ """
1434
+ %(prog)s list-rules ...
1435
+
1436
+ List rules.
1437
+ """
1438
+ client = get_client(args)
1439
+ if args.rule_id:
1440
+ rules = [client.get_replication_rule(args.rule_id)]
1441
+ elif args.file:
1442
+ scope, name = get_scope(args.file, client)
1443
+ rules = client.list_associated_rules_for_file(scope=scope, name=name)
1444
+ elif args.traverse:
1445
+ scope, name = get_scope(args.did, client)
1446
+ locks = client.get_dataset_locks(scope=scope, name=name)
1447
+ rules = []
1448
+ for rule_id in list(set([lock['rule_id'] for lock in locks])):
1449
+ rules.append(client.get_replication_rule(rule_id))
1450
+ elif args.did:
1451
+ scope, name = get_scope(args.did, client)
1452
+ meta = client.get_metadata(scope=scope, name=name)
1453
+ rules = client.list_did_rules(scope=scope, name=name)
1454
+ try:
1455
+ next(rules)
1456
+ rules = client.list_did_rules(scope=scope, name=name)
1457
+ except StopIteration:
1458
+ rules = []
1459
+ # looking for other rules
1460
+ if meta['did_type'] == 'CONTAINER':
1461
+ for dsn in client.list_content(scope, name):
1462
+ rules.extend(client.list_did_rules(scope=dsn['scope'], name=dsn['name']))
1463
+ if rules:
1464
+ print('No rules found, listing rules for content')
1465
+ if meta['did_type'] == 'DATASET':
1466
+ for container in client.list_parent_dids(scope, name):
1467
+ rules.extend(client.list_did_rules(scope=container['scope'], name=container['name']))
1468
+ if rules:
1469
+ print('No rules found, listing rules for parents')
1470
+ elif args.rule_account:
1471
+ rules = client.list_account_rules(account=args.rule_account)
1472
+ elif args.subscription:
1473
+ account = args.subscription[0]
1474
+ name = args.subscription[1]
1475
+ rules = client.list_subscription_rules(account=account, name=name)
1476
+ else:
1477
+ print('At least one option has to be given. Use -h to list the options.')
1478
+ return FAILURE
1479
+ if args.csv:
1480
+ for rule in rules:
1481
+ print(rule['id'],
1482
+ rule['account'],
1483
+ '%s:%s' % (rule['scope'], rule['name']),
1484
+ '%s[%d/%d/%d]' % (rule['state'], rule['locks_ok_cnt'], rule['locks_replicating_cnt'], rule['locks_stuck_cnt']),
1485
+ rule['rse_expression'],
1486
+ rule['copies'],
1487
+ sizefmt(rule['bytes'], args.human) if rule['bytes'] is not None else 'N/A',
1488
+ rule['expires_at'],
1489
+ rule['created_at'],
1490
+ sep=',')
1491
+ else:
1492
+ table = []
1493
+ for rule in rules:
1494
+ table.append([rule['id'],
1495
+ rule['account'],
1496
+ '%s:%s' % (rule['scope'], rule['name']),
1497
+ '%s[%d/%d/%d]' % (rule['state'], rule['locks_ok_cnt'], rule['locks_replicating_cnt'], rule['locks_stuck_cnt']),
1498
+ rule['rse_expression'],
1499
+ rule['copies'],
1500
+ sizefmt(rule['bytes'], args.human) if rule['bytes'] is not None else 'N/A',
1501
+ rule['expires_at'],
1502
+ rule['created_at']])
1503
+ print(tabulate(table, tablefmt='simple', headers=['ID', 'ACCOUNT', 'SCOPE:NAME', 'STATE[OK/REPL/STUCK]', 'RSE_EXPRESSION', 'COPIES', 'SIZE', 'EXPIRES (UTC)', 'CREATED (UTC)'], disable_numparse=True))
1504
+ return SUCCESS
1505
+
1506
+
1507
+ @exception_handler
1508
+ def list_rules_history(args):
1509
+ """
1510
+ %(prog)s list-rules_history ...
1511
+
1512
+ List replication rules history for a DID.
1513
+ """
1514
+ rule_dict = []
1515
+ client = get_client(args)
1516
+ scope, name = get_scope(args.did, client)
1517
+ for rule in client.list_replication_rule_full_history(scope, name):
1518
+ if rule['rule_id'] not in rule_dict:
1519
+ rule_dict.append(rule['rule_id'])
1520
+ print('-' * 40)
1521
+ print('Rule insertion')
1522
+ print('Account : %s' % rule['account'])
1523
+ print('RSE expression : %s' % (rule['rse_expression']))
1524
+ print('Time : %s' % (rule['created_at']))
1525
+ else:
1526
+ rule_dict.remove(rule['rule_id'])
1527
+ print('-' * 40)
1528
+ print('Rule deletion')
1529
+ print('Account : %s' % rule['account'])
1530
+ print('RSE expression : %s' % (rule['rse_expression']))
1531
+ print('Time : %s' % (rule['updated_at']))
1532
+ return SUCCESS
1533
+
1534
+
1535
+ @exception_handler
1536
+ def list_rses(args):
1537
+ """
1538
+ %(prog)s list-rses [options] <field1=value1 field2=value2 ...>
1539
+
1540
+ List rses.
1541
+
1542
+ """
1543
+ client = get_client(args)
1544
+
1545
+ rses = client.list_rses(args.rses)
1546
+ for rse in rses:
1547
+ print('%(rse)s' % rse)
1548
+ return SUCCESS
1549
+
1550
+
1551
+ @exception_handler
1552
+ def list_suspicious_replicas(args):
1553
+ """
1554
+ %(prog)s list-suspicious-replicas [options] <field1=value1 field2=value2 ...>
1555
+
1556
+ List replicas marked as suspicious.
1557
+
1558
+ """
1559
+ client = get_client(args)
1560
+ rse_expression = None
1561
+ younger_than = None
1562
+ nattempts = None
1563
+ if args.rse_expression:
1564
+ rse_expression = args.rse_expression
1565
+ if args.younger_than:
1566
+ younger_than = args.younger_than
1567
+ if args.nattempts:
1568
+ nattempts = args.nattempts
1569
+ # Generator is a list with one entry, which itself is a list of lists.
1570
+ replicas_gen = client.list_suspicious_replicas(rse_expression, younger_than, nattempts)
1571
+ for i in replicas_gen:
1572
+ replicas = i
1573
+ table = []
1574
+ for rep in replicas:
1575
+ table.append([rep['rse'], rep['scope'], rep['created_at'], rep['cnt'], rep['name']])
1576
+ print(tabulate(table, headers=(['RSE Expression:', 'Scope:', 'Created at:', 'Nattempts:', 'File Name:'])))
1577
+ return SUCCESS
1578
+
1579
+
1580
+ @exception_handler
1581
+ def list_rse_attributes(args):
1582
+ """
1583
+ %(prog)s list-rse-attributes [options] <field1=value1 field2=value2 ...>
1584
+
1585
+ List rses.
1586
+
1587
+ """
1588
+ client = get_client(args)
1589
+ attributes = client.list_rse_attributes(rse=args.rse)
1590
+ table = [(k + ':', str(v)) for (k, v) in sorted(attributes.items())] # columns have mixed datatypes
1591
+ print(tabulate(table, tablefmt='plain', disable_numparse=True)) # disabling number parsing
1592
+ return SUCCESS
1593
+
1594
+
1595
+ @exception_handler
1596
+ def list_rse_usage(args):
1597
+ """
1598
+ %(prog)s list-rse-usage [options] <rse>
1599
+
1600
+ Show the space usage of a given rse
1601
+
1602
+ """
1603
+ client = get_client(args)
1604
+ all_usages = client.get_rse_usage(rse=args.rse, filters={'per_account': args.show_accounts})
1605
+ select_usages = [u for u in all_usages if u['source'] not in ('srm', 'gsiftp', 'webdav')]
1606
+ print('USAGE:')
1607
+ for usage in select_usages:
1608
+ print('------')
1609
+ for elem in usage:
1610
+ if (elem in ['free', 'total'] and usage['source'] != 'storage' or elem == 'files' and usage['source'] != 'rucio'):
1611
+ continue
1612
+ elif elem in ['used', 'free', 'total']:
1613
+ print(' {0}: {1}'.format(elem, sizefmt(usage[elem], args.human)))
1614
+ elif elem == 'account_usages':
1615
+ account_usages_title = ' per account:'
1616
+ if not usage[elem]:
1617
+ account_usages_title += ' no usage'
1618
+ else:
1619
+ print(account_usages_title)
1620
+ print(' ------')
1621
+ col_width = max(len(str(entry[1])) for account in usage[elem] for entry in list(account.items())) + 16
1622
+ for account in usage[elem]:
1623
+ base_string = ' '
1624
+ used_string = 'used: {0}'.format(sizefmt(account['used'], args.human))
1625
+ account_string = 'account: {0}'.format(account['account'])
1626
+ percentage_string = 'percentage: {0}'.format(account['percentage'])
1627
+ print(base_string + account_string.ljust(col_width) + used_string.ljust(col_width) + percentage_string.ljust(col_width))
1628
+ print(' ------')
1629
+ else:
1630
+ print(' {0}: {1}'.format(elem, usage[elem]))
1631
+ print('------')
1632
+ return SUCCESS
1633
+
1634
+
1635
+ @exception_handler
1636
+ def list_account_limits(args):
1637
+ """
1638
+ %(prog)s list [options] <field1=value1 field2=value2 ...>
1639
+
1640
+ List account limits.
1641
+
1642
+ """
1643
+ client = get_client(args)
1644
+ table = []
1645
+ if args.rse:
1646
+ limits = client.get_local_account_limit(account=args.limit_account, rse=args.rse)
1647
+ else:
1648
+ limits = client.get_local_account_limits(account=args.limit_account)
1649
+ for limit in list(limits.items()):
1650
+ table.append([limit[0], sizefmt(limit[1], args.human)])
1651
+ table.sort()
1652
+ print(tabulate(table, tablefmt=tablefmt, headers=['RSE', 'LIMIT']))
1653
+
1654
+ table = []
1655
+ limits = client.get_global_account_limits(account=args.limit_account)
1656
+ for limit in list(limits.items()):
1657
+ if (args.rse and args.rse in limit[1]['resolved_rses']) or not args.rse:
1658
+ table.append([limit[0], sizefmt(limit[1]['limit'], args.human)])
1659
+ table.sort()
1660
+ print(tabulate(table, tablefmt=tablefmt, headers=['RSE EXPRESSION', 'LIMIT']))
1661
+
1662
+ return SUCCESS
1663
+
1664
+
1665
+ @exception_handler
1666
+ def list_account_usage(args):
1667
+ """
1668
+ %(prog)s list [options] <field1=value1 field2=value2 ...>
1669
+
1670
+ List account usage.
1671
+
1672
+ """
1673
+ client = get_client(args)
1674
+ table = []
1675
+ if args.rse:
1676
+ usage = client.get_local_account_usage(account=args.usage_account, rse=args.rse)
1677
+ else:
1678
+ usage = client.get_local_account_usage(account=args.usage_account)
1679
+ for item in usage:
1680
+ remaining = 0 if float(item['bytes_remaining']) < 0 else float(item['bytes_remaining'])
1681
+ table.append([item['rse'], sizefmt(item['bytes'], args.human), sizefmt(item['bytes_limit'], args.human), sizefmt(remaining, args.human)])
1682
+ table.sort()
1683
+ print(tabulate(table, tablefmt=tablefmt, headers=['RSE', 'USAGE', 'LIMIT', 'QUOTA LEFT']))
1684
+
1685
+ table = []
1686
+ usage = client.get_global_account_usage(account=args.usage_account)
1687
+ for item in usage:
1688
+ if (args.rse and args.rse in item['rse_expression']) or not args.rse:
1689
+ remaining = 0 if float(item['bytes_remaining']) < 0 else float(item['bytes_remaining'])
1690
+ table.append([item['rse_expression'], sizefmt(item['bytes'], args.human), sizefmt(item['bytes_limit'], args.human), sizefmt(remaining, args.human)])
1691
+ table.sort()
1692
+ print(tabulate(table, tablefmt=tablefmt, headers=['RSE EXPRESSION', 'USAGE', 'LIMIT', 'QUOTA LEFT']))
1693
+
1694
+ return SUCCESS
1695
+
1696
+
1697
+ @exception_handler
1698
+ def list_datasets_rse(args):
1699
+ """
1700
+ %(prog)s list [options] <field1=value1 field2=value2 ...>
1701
+
1702
+ List the datasets in a site.
1703
+
1704
+ """
1705
+ client = get_client(args)
1706
+ if args.long:
1707
+ table = []
1708
+ for dsn in client.list_datasets_per_rse(args.rse):
1709
+ table.append(['%s:%s' % (dsn['scope'], dsn['name']), '%s/%s' % (str(dsn['available_length']), str(dsn['length'])), '%s/%s' % (str(dsn['available_bytes']), str(dsn['bytes']))])
1710
+ table.sort()
1711
+ print(tabulate(table, tablefmt=tablefmt, headers=['DID', 'LOCAL FILES/TOTAL FILES', 'LOCAL BYTES/TOTAL BYTES']))
1712
+ else:
1713
+ dsns = list(set(['%s:%s' % (dsn['scope'], dsn['name']) for dsn in client.list_datasets_per_rse(args.rse)]))
1714
+ dsns.sort()
1715
+ print("SCOPE:NAME")
1716
+ print('----------')
1717
+ for dsn in dsns:
1718
+ print(dsn)
1719
+ return SUCCESS
1720
+
1721
+
1722
+ @exception_handler
1723
+ def add_lifetime_exception(args):
1724
+ """
1725
+ %(prog)s add_lifetime_exception [options] <field1=value1 field2=value2 ...>
1726
+
1727
+ Declare a lifetime model exception.
1728
+
1729
+ """
1730
+ client = get_client(args)
1731
+ if not args.reason:
1732
+ logger.error('reason for the extension is mandatory')
1733
+ return FAILURE
1734
+ reason = args.reason
1735
+ if not args.expiration:
1736
+ logger.error('expiration is mandatory')
1737
+ return FAILURE
1738
+ try:
1739
+ expiration = datetime.strptime(args.expiration, "%Y-%m-%d")
1740
+ except Exception as err:
1741
+ logger.error(err)
1742
+ return FAILURE
1743
+
1744
+ if not args.inputfile:
1745
+ logger.error('inputfile is mandatory')
1746
+ return FAILURE
1747
+ with open(args.inputfile) as infile:
1748
+ dids = list(set(line.strip() for line in infile))
1749
+
1750
+ dids_list = []
1751
+ containers = []
1752
+ datasets = []
1753
+ error_types = ['Total DIDs',
1754
+ 'DID not submitted because it is a file',
1755
+ 'DID that are containers and were resolved',
1756
+ 'DID not submitted because it is not part of the lifetime campaign',
1757
+ 'DID successfully submitted including the one from containers resolved']
1758
+ for did in dids:
1759
+ scope, name = get_scope(did, client)
1760
+ dids_list.append({'scope': scope, 'name': name})
1761
+ summary = {0: len(dids_list), 1: 0, 2: 0, 3: 0, 4: 0}
1762
+ chunk_limit = 500 # Server should be able to accept 1000
1763
+ dids_list_copy = deepcopy(dids_list)
1764
+ for chunk in chunks(dids_list_copy, chunk_limit):
1765
+ for meta in client.get_metadata_bulk(chunk):
1766
+ scope, name = meta['scope'], meta['name']
1767
+ dids_list.remove({'scope': scope, 'name': name})
1768
+ if meta['did_type'] == 'FILE':
1769
+ logger.warning('%s:%s is a file. Will be ignored' % (scope, name))
1770
+ summary[1] += 1
1771
+ elif meta['did_type'] == 'CONTAINER':
1772
+ logger.warning('%s:%s is a container. It needs to be resolved' % (scope, name))
1773
+ containers.append({'scope': scope, 'name': name})
1774
+ summary[2] += 1
1775
+ elif not meta['eol_at']:
1776
+ logger.warning('%s:%s is not affected by the lifetime model' % (scope, name))
1777
+ summary[3] += 1
1778
+ else:
1779
+ logger.info('%s:%s will be declared' % (scope, name))
1780
+ datasets.append({'scope': scope, 'name': name})
1781
+ summary[4] += 1
1782
+
1783
+ for did in dids_list:
1784
+ scope = did['scope']
1785
+ name = did['name']
1786
+ logger.warning('%s:%s does not exist' % (scope, name))
1787
+
1788
+ if containers:
1789
+ logger.warning('One or more DIDs are containers. They will be resolved into a list of datasets to request exception. Full list below')
1790
+ for container in containers:
1791
+ logger.info('Resolving %s:%s into datasets :' % (container['scope'], container['name']))
1792
+ list_datasets = __resolve_containers_to_datasets(container['scope'], container['name'], client)
1793
+ for chunk in chunks(list_datasets, chunk_limit):
1794
+ for meta in client.get_metadata_bulk(chunk):
1795
+ scope, name = meta['scope'], meta['name']
1796
+ logger.debug('%s:%s' % (scope, name))
1797
+ if not meta['eol_at']:
1798
+ logger.warning('%s:%s is not affected by the lifetime model' % (scope, name))
1799
+ summary[3] += 1
1800
+ else:
1801
+ logger.info('%s:%s will be declared' % (scope, name))
1802
+ datasets.append({'scope': scope, 'name': name})
1803
+
1804
+ if not datasets:
1805
+ logger.error('Nothing to submit')
1806
+ return SUCCESS
1807
+ try:
1808
+ client.add_exception(dids=datasets, account=client.account, pattern='', comments=reason, expires_at=expiration)
1809
+ except UnsupportedOperation as err:
1810
+ logger.error(err)
1811
+ return FAILURE
1812
+ except Exception:
1813
+ logger.error('Failure to submit exception. Please retry')
1814
+ logger.debug(traceback.format_exc())
1815
+ return FAILURE
1816
+
1817
+ logger.info('Exception successfully submitted. Summary below')
1818
+ for cnt, error in enumerate(error_types):
1819
+ print('{0:100} {1:6d}'.format(error, summary[cnt]))
1820
+ return SUCCESS
1821
+
1822
+
1823
+ def test_server(args):
1824
+ """"
1825
+ %(prog)s test-server [options] <field1=value1 field2=value2 ...>
1826
+ Test the client against a server.
1827
+ """
1828
+ suite = unittest.TestLoader().loadTestsFromTestCase(TestRucioServer)
1829
+ unittest.TextTestRunner(verbosity=2).run(suite)
1830
+ return SUCCESS
1831
+
1832
+
1833
+ def touch(args):
1834
+ """
1835
+ %(prog)s touch [options] <did1 did2 ...>
1836
+ """
1837
+
1838
+ client = get_client(args)
1839
+
1840
+ for did in args.dids:
1841
+ scope, name = get_scope(did, client)
1842
+ client.touch(scope, name, args.rse)
1843
+
1844
+
1845
+ def rse_completer(prefix, parsed_args, **kwargs):
1846
+ """
1847
+ Completes the argument with a list of RSEs
1848
+ """
1849
+ client = get_client(parsed_args)
1850
+ return ["%(rse)s" % rse for rse in client.list_rses()]
1851
+
1852
+
1853
+ def get_parser():
1854
+ """
1855
+ Returns the argparse parser.
1856
+ """
1857
+ oparser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]), add_help=True)
1858
+ subparsers = oparser.add_subparsers()
1859
+
1860
+ # Main arguments
1861
+ oparser.add_argument('--version', action='version', version='%(prog)s ' + version.version_string())
1862
+ oparser.add_argument('--config', dest="config", help="The Rucio configuration file to use.")
1863
+ oparser.add_argument('--verbose', '-v', default=False, action='store_true', help="Print more verbose output.")
1864
+ oparser.add_argument('-H', '--host', dest="host", metavar="ADDRESS", help="The Rucio API host.")
1865
+ oparser.add_argument('--auth-host', dest="auth_host", metavar="ADDRESS", help="The Rucio Authentication host.")
1866
+ oparser.add_argument('-a', '--account', dest="account", metavar="ACCOUNT", help="Rucio account to use.")
1867
+ oparser.add_argument('-S', '--auth-strategy', dest="auth_strategy", default=None, help="Authentication strategy (userpass, x509...)")
1868
+ oparser.add_argument('-T', '--timeout', dest="timeout", type=float, default=None, help="Set all timeout values to seconds.")
1869
+ oparser.add_argument('--robot', '-R', dest="human", default=True, action='store_false', help="All output in bytes and without the units. This output format is preferred by parsers and scripts.")
1870
+ oparser.add_argument('--user-agent', '-U', dest="user_agent", default='rucio-clients', action='store', help="Rucio User Agent")
1871
+ oparser.add_argument('--vo', dest="vo", metavar="VO", default=None, help="VO to authenticate at. Only used in multi-VO mode.")
1872
+
1873
+ # Options for the userpass or OIDC auth_strategy
1874
+ oparser.add_argument('-u', '--user', dest='username', default=None, help='username')
1875
+ oparser.add_argument('-pwd', '--password', dest='password', default=None, help='password')
1876
+ # Options for defining remaining OIDC parameters
1877
+ oparser.add_argument('--oidc-user', dest='oidc_username', default=None, help='OIDC username')
1878
+ oparser.add_argument('--oidc-password', dest='oidc_password', default=None, help='OIDC password')
1879
+ oparser.add_argument('--oidc-scope', dest='oidc_scope', default='openid profile', help='Defines which (OIDC) information user will share with Rucio. '
1880
+ + 'Rucio requires at least -sc="openid profile". To request refresh token for Rucio, scope must include "openid offline_access" and ' # NOQA: W503
1881
+ + 'there must be no active access token saved on the side of the currently used Rucio Client.') # NOQA: W503
1882
+ oparser.add_argument('--oidc-audience', dest='oidc_audience', default=None, help='Defines which audience are tokens requested for.')
1883
+ oparser.add_argument('--oidc-auto', dest='oidc_auto', default=False, action='store_true', help='If not specified, username and password credentials are not required and users will be given a URL '
1884
+ + 'to use in their browser. If specified, the users explicitly trust Rucio with their IdP credentials.') # NOQA: W503
1885
+ oparser.add_argument('--oidc-polling', dest='oidc_polling', default=False, action='store_true', help='If not specified, user will be asked to enter a code returned by the browser to the command line. '
1886
+ + 'If --polling is set, Rucio Client should get the token without any further interaction of the user. This option is active only if --auto is *not* specified.') # NOQA: W503
1887
+ oparser.add_argument('--oidc-refresh-lifetime', dest='oidc_refresh_lifetime', default=None, help='Max lifetime in hours for this an access token will be refreshed by asynchronous Rucio daemon. '
1888
+ + 'If not specified, refresh will be stopped after 4 days. This option is effective only if --oidc-scope includes offline_access scope for a refresh token to be granted to Rucio.') # NOQA: W503
1889
+ oparser.add_argument('--oidc-issuer', dest='oidc_issuer', default=None,
1890
+ help='Defines which Identity Provider is going to be used. The issuer string must correspond '
1891
+ + 'to the keys configured in the /etc/idpsecrets.json auth server configuration file.') # NOQA: W503
1892
+
1893
+ # Options for the x509 auth_strategy
1894
+ oparser.add_argument('--certificate', dest='certificate', default=None, help='Client certificate file for x509 Authentication.')
1895
+ oparser.add_argument('--client_key', dest='client_key', default=None, help='Client key for x509 Authentication.')
1896
+ oparser.add_argument('--ca-certificate', dest='ca_certificate', default=None, help='CA certificate to verify peer against (SSL).')
1897
+
1898
+ # Ping command
1899
+ ping_parser = subparsers.add_parser('ping', formatter_class=argparse.RawDescriptionHelpFormatter, help='Ping Rucio server.',
1900
+ epilog='Usage example\n'
1901
+ '"""""""""""""\n'
1902
+ '\n'
1903
+ 'To ping the server::\n'
1904
+ '\n'
1905
+ ' $ rucio ping\n'
1906
+ ' 1.14.8\n'
1907
+ '\n'
1908
+ 'The returned value is the version of Rucio installed on the server.'
1909
+ '\n')
1910
+ ping_parser.set_defaults(function=ping)
1911
+
1912
+ # The whoami command
1913
+ whoami_parser = subparsers.add_parser('whoami', help='Get information about account whose token is used.', formatter_class=argparse.RawDescriptionHelpFormatter,
1914
+ epilog='''Usage example
1915
+ """""""""""""
1916
+ ::
1917
+
1918
+ $ rucio whoami
1919
+ jdoe
1920
+
1921
+ The returned value is the account currently used.
1922
+ ''')
1923
+
1924
+ whoami_parser.set_defaults(function=whoami_account)
1925
+
1926
+ # The list-file-replicas command
1927
+ list_file_replicas_parser = subparsers.add_parser('list-file-replicas', help='List the replicas of a DID and its PFNs.', description='This method allows to list all the replicas of a given Data IDentifier (DID). \
1928
+ The only mandatory parameter is the DID which can be a container/dataset/files. By default all the files replicas in state available are returned.', formatter_class=argparse.RawDescriptionHelpFormatter,
1929
+ epilog='''Usage example
1930
+ ^^^^^^^^^^^^^
1931
+
1932
+ To list the file replicas for a given dataset::
1933
+
1934
+ $ rucio list-file-replicas user.jdoe:user.jdoe.test.data.1234.1
1935
+ +-----------+---------------------------------+------------+-----------+-----------------------------------------------------------------------------------+
1936
+ | SCOPE | NAME | FILESIZE | ADLER32 | RSE: REPLICA |
1937
+ |-----------+---------------------------------+------------+-----------+-----------------------------------------------------------------------------------|
1938
+ | user.jdoe | user.jdoe.test.data.1234.file.1 | 94.835 MB | 5d000974 | SITE1_DISK: srm://blahblih/path/to/file/user.jdoe/user.jdoe.test.data.1234.file.1 |
1939
+ | user.jdoe | user.jdoe.test.data.1234.file.1 | 94.835 MB | 5d000974 | SITE2_DISK: file://another/path/to/file/user.jdoe/user.jdoe.test.data.1234.file.1 |
1940
+ | user.jdoe | user.jdoe.test.data.1234.file.2 | 82.173 MB | 01e56f23 | SITE2_DISK: file://another/path/to/file/user.jdoe/user.jdoe.test.data.1234.file.2 |
1941
+ +-----------+---------------------------------+------------+-----------+-----------------------------------------------------------------------------------+
1942
+
1943
+ To list the missing replica of a dataset of a given RSE-expression::
1944
+
1945
+ $ rucio list-file-replicas --rses SITE1_DISK user.jdoe:user.jdoe.test.data.1234.1
1946
+ +-----------+---------------------------------+------------+-----------+-----------------------------------------------------------------------------------+
1947
+ | SCOPE | NAME | FILESIZE | ADLER32 | RSE: REPLICA |
1948
+ |-----------+---------------------------------+------------+-----------+-----------------------------------------------------------------------------------|
1949
+ | user.jdoe | user.jdoe.test.data.1234.file.1 | 94.835 MB | 5d000974 | SITE1_DISK: srm://blahblih/path/to/file/user.jdoe/user.jdoe.test.data.1234.file.1 |
1950
+ +-----------+---------------------------------+------------+-----------+-----------------------------------------------------------------------------------+
1951
+ ''')
1952
+ list_file_replicas_parser.set_defaults(function=list_file_replicas)
1953
+ list_file_replicas_parser.add_argument('--protocols', dest='protocols', action='store', help='List of comma separated protocols. (i.e. https, root, srm).', required=False)
1954
+ list_file_replicas_parser.add_argument('--all-states', dest='all_states', action='store_true', default=False, help='To select all replicas (including unavailable ones).\
1955
+ Also gets information about the current state of a DID in each RSE.\
1956
+ Legend: ' + ', '.join(["{0} = {1}".format(state.value, state.name) for state in ReplicaState]), required=False)
1957
+ list_file_replicas_parser.add_argument(dest='dids', nargs='+', action='store', help='List of space separated data identifiers.')
1958
+ list_file_replicas_parser.add_argument('--pfns', default=False, action='store_true', help='Show only the PFNs.', required=False)
1959
+ list_file_replicas_parser.add_argument('--domain', default=None, action='store', help='Force the networking domain. Available options: wan, lan, all.', required=False)
1960
+ list_file_replicas_parser.add_argument('--link', dest='link', default=None, action='store', help='Symlink PFNs with directory substitution.\
1961
+ For example: rucio list-file-replicas --rse RSE_TEST --link /eos/:/eos/ scope:datasetname', required=False)
1962
+ list_file_replicas_parser.add_argument('--missing', dest='missing', default=False, action='store_true', help='To list missing replicas at a RSE-Expression. Must be used with --rses option', required=False)
1963
+ list_file_replicas_parser.add_argument('--metalink', dest='metalink', default=False, action='store_true', help='Output available replicas as metalink.', required=False)
1964
+ list_file_replicas_parser.add_argument('--no-resolve-archives', dest='no_resolve_archives', default=False, action='store_true', help='Do not resolve archives which may contain the files.', required=False)
1965
+ list_file_replicas_parser.add_argument('--sort', dest='sort', default=None, action='store', help='Replica sort algorithm. Available options: geoip (default), random', required=False)
1966
+ list_file_replicas_parser.add_argument('--rses', dest='rses', default=None, action='store', help='The RSE filter expression. A comprehensive help about RSE expressions\
1967
+ can be found in ' + Color.BOLD + 'https://rucio.cern.ch/documentation/started/concepts/rse_expressions' + Color.END)
1968
+
1969
+ # The list-dataset-replicas command
1970
+ list_dataset_replicas_parser = subparsers.add_parser('list-dataset-replicas', help='List the dataset replicas.',
1971
+ formatter_class=argparse.RawDescriptionHelpFormatter,
1972
+ epilog='''Usage example
1973
+ """""""""""""
1974
+ ::
1975
+
1976
+ $ rucio list-dataset-replicas user.jdoe:user.jdoe.test.data.1234.1
1977
+
1978
+ DATASET: user.jdoe:user.jdoe.test.data.1234.1
1979
+ +------------+---------+---------+
1980
+ | RSE | FOUND | TOTAL |
1981
+ |------------+---------+---------|
1982
+ | SITE1_DISK | 1 | 2 |
1983
+ | SITE2_DISK | 2 | 2 |
1984
+ +------------+---------+---------+
1985
+ ''')
1986
+ list_dataset_replicas_parser.set_defaults(function=list_dataset_replicas)
1987
+ list_dataset_replicas_parser.add_argument(dest='dids', action='store', nargs='+', help='The name of the DID to search.')
1988
+ list_dataset_replicas_parser.add_argument('--deep', action='store_true', help='Make a deep check.')
1989
+ list_dataset_replicas_parser.add_argument('--csv', dest='csv', action='store_true', default=False, help='Comma Separated Value output.',)
1990
+
1991
+ # The add-dataset command
1992
+ add_dataset_parser = subparsers.add_parser('add-dataset', help='Add a dataset to Rucio Catalog.',
1993
+ formatter_class=argparse.RawDescriptionHelpFormatter, epilog='''Usage example
1994
+ """""""""""""
1995
+ ::
1996
+
1997
+ $ rucio add-dataset user.jdoe:user.jdoe.test.data.1234.1
1998
+ Added user.jdoe:user.jdoe.test.data.1234.1
1999
+
2000
+ ''')
2001
+
2002
+ add_dataset_parser.set_defaults(function=add_dataset)
2003
+ add_dataset_parser.add_argument('--monotonic', action='store_true', help='Monotonic status to True.')
2004
+ add_dataset_parser.add_argument(dest='did', action='store', help='The name of the dataset to add.')
2005
+ add_dataset_parser.add_argument('--lifetime', dest='lifetime', action='store', type=int, help='Lifetime in seconds.')
2006
+
2007
+ # The add-container command
2008
+ add_container_parser = subparsers.add_parser('add-container', help='Add a container to Rucio Catalog.',
2009
+ formatter_class=argparse.RawDescriptionHelpFormatter, epilog='''Usage example
2010
+ """""""""""""
2011
+ ::
2012
+
2013
+ $ rucio add-container user.jdoe:user.jdoe.test.cont.1234.1
2014
+ Added user.jdoe:user.jdoe.test.cont.1234.1
2015
+
2016
+ ''')
2017
+
2018
+ add_container_parser.set_defaults(function=add_container)
2019
+ add_container_parser.add_argument('--monotonic', action='store_true', help='Monotonic status to True.')
2020
+ add_container_parser.add_argument(dest='did', action='store', help='The name of the container to add.')
2021
+ add_container_parser.add_argument('--lifetime', dest='lifetime', action='store', type=int, help='Lifetime in seconds.')
2022
+
2023
+ # The attach command
2024
+ attach_parser = subparsers.add_parser('attach', help='Attach a list of DIDs to a parent DID.',
2025
+ description='Attach a list of Data IDentifiers (file, dataset or container) to an other Data IDentifier (dataset or container).',
2026
+ formatter_class=argparse.RawDescriptionHelpFormatter, epilog='''Usage example
2027
+ """""""""""""
2028
+ ::
2029
+
2030
+ $ rucio attach user.jdoe:user.jdoe.test.cont.1234.1 user.jdoe:user.jdoe.test.data.1234.1
2031
+ DIDs successfully attached to user.jdoe:user.jdoe.test.cont.1234.1
2032
+
2033
+ ''')
2034
+
2035
+ attach_parser.set_defaults(function=attach)
2036
+ attach_parser.add_argument(dest='todid', action='store', help='Destination Data IDentifier (either dataset or container).')
2037
+ attach_parser.add_argument('-f', '--from-file', dest='fromfile', action='store_true', default=False, help='Attach the DIDs contained in a file. The file should contain one did per line.')
2038
+ attach_parser.add_argument(dest='dids', nargs='+', action='store', help='List of space separated data identifiers (or a file containing one did per line, if -f is present).')
2039
+
2040
+ # The detach command
2041
+ detach_parser = subparsers.add_parser('detach', help='Detach a list of DIDs from a parent DID.',
2042
+ description='Detach a list of Data Identifiers (file, dataset or container) from an other Data Identifier (dataset or container).',
2043
+ formatter_class=argparse.RawDescriptionHelpFormatter, epilog='''Usage example
2044
+ """""""""""""
2045
+ ::
2046
+
2047
+ $ rucio detach user.jdoe:user.jdoe.test.cont.1234.1 user.jdoe:user.jdoe.test.data.1234.1
2048
+ DIDs successfully detached from user.jdoe:user.jdoe.test.cont.1234.1
2049
+
2050
+ ''')
2051
+
2052
+ detach_parser.set_defaults(function=detach)
2053
+ detach_parser.add_argument(dest='fromdid', action='store', help='Target Data IDentifier (must be a dataset or container).')
2054
+ detach_parser.add_argument(dest='dids', nargs='+', action='store', help='List of space separated data identifiers.')
2055
+
2056
+ # The list command
2057
+ ls_parser = subparsers.add_parser('ls', help='List the data identifiers matching some metadata (synonym for list-dids).', description='List the Data IDentifiers matching certain pattern. \
2058
+ Only the collections (i.e. dataset or container) are returned by default. With the filter option, you can specify a list of metadata that the Data IDentifier should match.',
2059
+ formatter_class=argparse.RawDescriptionHelpFormatter, epilog='''Usage example
2060
+ """""""""""""
2061
+ You can query the DIDs matching a certain pattern. It always requires to specify the scope in which you want to search::
2062
+
2063
+ $ rucio ls user.jdoe:*
2064
+ +-------------------------------------------+--------------+
2065
+ | SCOPE:NAME | [DID TYPE] |
2066
+ |-------------------------------------------+--------------|
2067
+ | user.jdoe:user.jdoe.test.container.1234.1 | CONTAINER |
2068
+ | user.jdoe:user.jdoe.test.container.1234.2 | CONTAINER |
2069
+ | user.jdoe:user.jdoe.test.cont.1234.2 | CONTAINER |
2070
+ | user.jdoe:user.jdoe.test.dataset.1 | DATASET |
2071
+ | user.jdoe:user.jdoe.test.dataset.2 | DATASET |
2072
+ | user.jdoe:user.jdoe.test.data.1234.1 | DATASET |
2073
+ | user.jdoe:test.file.1 | FILE |
2074
+ | user.jdoe:test.file.2 | FILE |
2075
+ | user.jdoe:test.file.3 | FILE |
2076
+ +-------------------------------------------+--------------+
2077
+
2078
+ You can filter by key/value, e.g.::
2079
+
2080
+ $ rucio ls --filter type=CONTAINER
2081
+ +-------------------------------------------+--------------+
2082
+ | SCOPE:NAME | [DID TYPE] |
2083
+ |-------------------------------------------+--------------|
2084
+ | user.jdoe:user.jdoe.test.container.1234.1 | CONTAINER |
2085
+ | user.jdoe:user.jdoe.test.container.1234.2 | CONTAINER |
2086
+ | user.jdoe:user.jdoe.test.cont.1234.2 | CONTAINER |
2087
+ +-------------------------------------------+--------------+
2088
+ ''')
2089
+
2090
+ ls_parser.set_defaults(function=list_dids)
2091
+ ls_parser.add_argument('-r', '--recursive', dest='recursive', action='store_true', default=False, help='List data identifiers recursively.')
2092
+ ls_parser.add_argument('--filter', dest='filter', action='store', help='Filter arguments in form `key=value,another_key=next_value`. Valid keys are name, type.')
2093
+ ls_parser.add_argument('--short', dest='short', action='store_true', help='Just dump the list of DIDs.')
2094
+ ls_parser.add_argument(dest='did', nargs=1, action='store', default=None, help='Data IDentifier pattern.')
2095
+
2096
+ list_parser = subparsers.add_parser('list-dids',
2097
+ help='List the data identifiers matching some metadata (synonym for ls).',
2098
+ description='''List the Data IDentifiers matching certain pattern.
2099
+ Only the collections (i.e. dataset or container) are returned by default.
2100
+ With the filter option, you can specify a list of metadata that the Data IDentifier should match.
2101
+ Please use the filter option `--filter type=all` to find all types of Data IDentifiers.''',
2102
+ formatter_class=argparse.RawDescriptionHelpFormatter, epilog='''Usage example
2103
+ """""""""""""
2104
+
2105
+ You can query the DIDs matching a certain pattern. It always requires to specify the scope in which you want to search::
2106
+
2107
+ $ rucio list-dids --filter 'type=all' user.jdoe:*
2108
+ +-------------------------------------------+--------------+
2109
+ | SCOPE:NAME | [DID TYPE] |
2110
+ |-------------------------------------------+--------------|
2111
+ | user.jdoe:user.jdoe.test.container.1234.1 | CONTAINER |
2112
+ | user.jdoe:user.jdoe.test.container.1234.2 | CONTAINER |
2113
+ | user.jdoe:user.jdoe.test.cont.1234.2 | CONTAINER |
2114
+ | user.jdoe:user.jdoe.test.dataset.1 | DATASET |
2115
+ | user.jdoe:user.jdoe.test.dataset.2 | DATASET |
2116
+ | user.jdoe:user.jdoe.test.data.1234.1 | DATASET |
2117
+ | user.jdoe:test.file.1 | FILE |
2118
+ | user.jdoe:test.file.2 | FILE |
2119
+ | user.jdoe:test.file.3 | FILE |
2120
+ +-------------------------------------------+--------------+
2121
+
2122
+ You can filter by key/value, e.g.::
2123
+
2124
+ $ rucio list-dids --filter 'type=CONTAINER'
2125
+ +-------------------------------------------+--------------+
2126
+ | SCOPE:NAME | [DID TYPE] |
2127
+ |-------------------------------------------+--------------|
2128
+ | user.jdoe:user.jdoe.test.container.1234.1 | CONTAINER |
2129
+ | user.jdoe:user.jdoe.test.container.1234.2 | CONTAINER |
2130
+ | user.jdoe:user.jdoe.test.cont.1234.2 | CONTAINER |
2131
+ +-------------------------------------------+--------------+''')
2132
+
2133
+ list_parser.set_defaults(function=list_dids)
2134
+ list_parser.add_argument('--recursive', dest='recursive', action='store_true', default=False, help='List data identifiers recursively.')
2135
+ list_parser.add_argument('--filter', dest='filter', action='store', help='Single or logically combined filtering expression(s) either in the form <key><operator><value> or <value1><operator1><key><operator2><value2> (compound inequality). Keys are equivalent to columns in the DID table. Operators must belong to the set of (<=, >=, ==, !=, >, <). The following conventions for combining expressions are used: ";" represents the logical OR operator; "," represents the logical AND operator.') # noqa: E501
2136
+ list_parser.add_argument('--short', dest='short', action='store_true', help='Just dump the list of DIDs.')
2137
+ list_parser.add_argument(dest='did', nargs=1, action='store', default=None, help='Data IDentifier pattern')
2138
+
2139
+ # The extended version of list_dids that goes through the plugin mechanism
2140
+ list_extended_parser = subparsers.add_parser('list-dids-extended',
2141
+ help='List the data identifiers matching some metadata (extended version to include metadata from various resources).',
2142
+ description='''List the Data IDentifiers matching certain pattern.
2143
+ Only the collections (i.e. dataset or container) are returned by default.
2144
+ With the filter option, you can specify a list of metadata that the Data IDentifier should match.
2145
+ Please use the filter option `--filter type=all` to find all types of Data IDentifiers.''',
2146
+ formatter_class=argparse.RawDescriptionHelpFormatter, epilog='''Usage example
2147
+ """""""""""""
2148
+
2149
+ You can query the DIDs matching a certain pattern. It always requires to specify the scope in which you want to search::
2150
+
2151
+ $ rucio list-dids --filter 'type=all' user.jdoe:*
2152
+ +-------------------------------------------+--------------+
2153
+ | SCOPE:NAME | [DID TYPE] |
2154
+ |-------------------------------------------+--------------|
2155
+ | user.jdoe:user.jdoe.test.container.1234.1 | CONTAINER |
2156
+ | user.jdoe:user.jdoe.test.container.1234.2 | CONTAINER |
2157
+ | user.jdoe:user.jdoe.test.cont.1234.2 | CONTAINER |
2158
+ | user.jdoe:user.jdoe.test.dataset.1 | DATASET |
2159
+ | user.jdoe:user.jdoe.test.dataset.2 | DATASET |
2160
+ | user.jdoe:user.jdoe.test.data.1234.1 | DATASET |
2161
+ | user.jdoe:test.file.1 | FILE |
2162
+ | user.jdoe:test.file.2 | FILE |
2163
+ | user.jdoe:test.file.3 | FILE |
2164
+ +-------------------------------------------+--------------+
2165
+
2166
+ You can filter by key/value, e.g.::
2167
+
2168
+ $ rucio list-dids --filter 'type=CONTAINER'
2169
+ +-------------------------------------------+--------------+
2170
+ | SCOPE:NAME | [DID TYPE] |
2171
+ |-------------------------------------------+--------------|
2172
+ | user.jdoe:user.jdoe.test.container.1234.1 | CONTAINER |
2173
+ | user.jdoe:user.jdoe.test.container.1234.2 | CONTAINER |
2174
+ | user.jdoe:user.jdoe.test.cont.1234.2 | CONTAINER |
2175
+ +-------------------------------------------+--------------+''')
2176
+
2177
+ list_extended_parser.set_defaults(function=list_dids_extended)
2178
+
2179
+ # The list parent-dids command
2180
+ list_parent_parser = subparsers.add_parser('list-parent-dids', help='List parent DIDs for a given DID', description='List all parents Data IDentifier that contains the target Data IDentifier.',
2181
+ formatter_class=argparse.RawDescriptionHelpFormatter, epilog='''Usage example
2182
+ """""""""""""
2183
+ ::
2184
+
2185
+ $ rucio list-parent-dids user.jdoe:user.jdoe.test.data.1234.1
2186
+ +--------------------------------------+--------------+
2187
+ | SCOPE:NAME | [DID TYPE] |
2188
+ |--------------------------------------+--------------|
2189
+ | user.jdoe:user.jdoe.test.cont.1234.2 | CONTAINER |
2190
+ +--------------------------------------+--------------+
2191
+
2192
+ ''')
2193
+ list_parent_parser.set_defaults(function=list_parent_dids)
2194
+ list_parent_parser.add_argument(dest='did', action='store', nargs='?', default=None, help='Data identifier.')
2195
+ list_parent_parser.add_argument('--pfn', dest='pfns', action='store', nargs='+', help='List parent dids for these pfns.')
2196
+ list_parent_parser.add_argument('--guid', dest='guids', action='store', nargs='+', help='List parent dids for these guids.')
2197
+
2198
+ # argparse 2.7 does not allow aliases for commands, thus the list-parent-datasets is a copy&paste from list-parent-dids
2199
+ list_parent_datasets_parser = subparsers.add_parser('list-parent-datasets', help='List parent DIDs for a given DID', description='List all parents Data IDentifier that contains the target Data IDentifier.',
2200
+ formatter_class=argparse.RawDescriptionHelpFormatter, epilog='''Usage example
2201
+ """""""""""""
2202
+ ::
2203
+
2204
+ $ rucio list-parent-datasets user.jdoe:user.jdoe.test.data.1234.1
2205
+ +--------------------------------------+--------------+
2206
+ | SCOPE:NAME | [DID TYPE] |
2207
+ |--------------------------------------+--------------|
2208
+ | user.jdoe:user.jdoe.test.cont.1234.2 | CONTAINER |
2209
+ +--------------------------------------+--------------+
2210
+
2211
+ ''')
2212
+
2213
+ list_parent_datasets_parser.set_defaults(function=list_parent_dids)
2214
+ list_parent_datasets_parser.add_argument(dest='did', action='store', nargs='?', default=None, help='Data identifier.')
2215
+ list_parent_datasets_parser.add_argument('--pfn', dest='pfns', action='store', nargs='+', help='List parent dids for these pfns.')
2216
+ list_parent_datasets_parser.add_argument('--guid', dest='guids', action='store', nargs='+', help='List parent dids for these guids.')
2217
+
2218
+ # The list-scopes command
2219
+ scope_list_parser = subparsers.add_parser('list-scopes', help='List all available scopes.',
2220
+ formatter_class=argparse.RawDescriptionHelpFormatter, epilog='''Usage example
2221
+ """""""""""""
2222
+ ::
2223
+
2224
+ $ rucio list-scopes
2225
+ mc
2226
+ data
2227
+ user.jdoe
2228
+ user.janedoe
2229
+
2230
+ ''')
2231
+
2232
+ scope_list_parser.set_defaults(function=list_scopes)
2233
+
2234
+ # The close command
2235
+ close_parser = subparsers.add_parser('close', help='Close a dataset or container.')
2236
+ close_parser.set_defaults(function=close)
2237
+ close_parser.add_argument(dest='dids', nargs='+', action='store', help='List of space separated data identifiers.')
2238
+
2239
+ # The reopen command
2240
+ reopen_parser = subparsers.add_parser('reopen', help='Reopen a dataset or container (only for privileged users).')
2241
+ reopen_parser.set_defaults(function=reopen)
2242
+ reopen_parser.add_argument(dest='dids', nargs='+', action='store', help='List of space separated data identifiers.')
2243
+
2244
+ # The stat command
2245
+ stat_parser = subparsers.add_parser('stat', help='List attributes and statuses about data identifiers.')
2246
+ stat_parser.set_defaults(function=stat)
2247
+ stat_parser.add_argument(dest='dids', nargs='+', action='store', help='List of space separated data identifiers.')
2248
+
2249
+ # The erase command
2250
+ erase_parser = subparsers.add_parser('erase', help='Delete a data identifier.', description='This command sets the lifetime of the DID in order to expire in the next 24 hours.\
2251
+ After this time, the dataset is eligible for deletion. The deletion is not reversible after 24 hours grace time period expired.')
2252
+ erase_parser.set_defaults(function=erase)
2253
+ erase_parser.add_argument('--undo', dest='undo', action='store_true', default=False, help='Undo erase DIDs. Only works if has been less than 24 hours since erase operation.')
2254
+ erase_parser.add_argument(dest='dids', nargs='+', action='store', help='List of space separated data identifiers.')
2255
+
2256
+ # The list_files command
2257
+ list_files_parser = subparsers.add_parser('list-files', help='List DID contents', description='List all the files in a Data IDentifier. The DID can be a container, dataset or a file.\
2258
+ What is returned is a list of files in the DID with : <scope>:<name>\t<guid>\t<checksum>\t<filesize>')
2259
+ list_files_parser.set_defaults(function=list_files)
2260
+ list_files_parser.add_argument('--csv', dest='csv', action='store_true', default=False, help='Comma Separated Value output. This output format is preferred for easy parsing and scripting.')
2261
+ list_files_parser.add_argument('--pfc', dest='LOCALPATH', action='store', default=False, help='Outputs the list of files in the dataset with the LOCALPATH prepended as a PoolFileCatalog')
2262
+ list_files_parser.add_argument(dest='dids', nargs='+', action='store', help='List of space separated data identifiers.')
2263
+
2264
+ # The list_content command
2265
+ list_content_parser = subparsers.add_parser('list-content', help='List the content of a collection.')
2266
+ list_content_parser.set_defaults(function=list_content)
2267
+ list_content_parser.add_argument(dest='dids', nargs='+', action='store', help='List of space separated data identifiers.')
2268
+ list_content_parser.add_argument('--short', dest='short', action='store_true', help='Just dump the list of DIDs.')
2269
+
2270
+ # The list_content_history command
2271
+ list_content_history_parser = subparsers.add_parser('list-content-history', help='List the content history of a collection.')
2272
+ list_content_history_parser.set_defaults(function=list_content_history)
2273
+ list_content_history_parser.add_argument(dest='dids', nargs='+', action='store', help='List of space separated data identifiers.')
2274
+
2275
+ # The upload subparser
2276
+ upload_parser = subparsers.add_parser('upload', help='Upload method.')
2277
+ upload_parser.set_defaults(function=upload)
2278
+ upload_parser.add_argument('--rse', dest='rse', action='store', help='Rucio Storage Element (RSE) name.', required=True).completer = rse_completer
2279
+ upload_parser.add_argument('--lifetime', type=int, action='store', help='Lifetime of the rule in seconds.')
2280
+ upload_parser.add_argument('--expiration-date', action='store', help='The date when the rule expires in UTC, format: <year>-<month>-<day>-<hour>:<minute>:<second>. E.g. 2022-10-20-20:00:00')
2281
+ upload_parser.add_argument('--scope', dest='scope', action='store', help='Scope name.')
2282
+ upload_parser.add_argument('--impl', dest='impl', action='store', help='Transfer protocol implementation to use (e.g: xrootd, gfal.NoRename, webdav, ssh.Rsync, rclone).')
2283
+ # The --no-register option is hidden. This is pilot ONLY. Users should not use this. Will lead to unregistered data on storage!
2284
+ upload_parser.add_argument('--no-register', dest='no_register', action='store_true', default=False, help=argparse.SUPPRESS)
2285
+ upload_parser.add_argument('--register-after-upload', dest='register_after_upload', action='store_true', default=False, help='Register the file only after successful upload.')
2286
+ upload_parser.add_argument('--summary', dest='summary', action='store_true', default=False, help='Create rucio_upload.json summary file')
2287
+ upload_parser.add_argument('--guid', dest='guid', action='store', help='Manually specify the GUID for the file.')
2288
+ upload_parser.add_argument('--protocol', action='store', help='Force the protocol to use')
2289
+ upload_parser.add_argument('--pfn', dest='pfn', action='store', help='Specify the exact PFN for the upload.')
2290
+ upload_parser.add_argument('--name', dest='name', action='store', help='Specify the exact LFN for the upload.')
2291
+ upload_parser.add_argument('--transfer-timeout', dest='transfer_timeout', type=float, action='store', default=config_get_float('upload', 'transfer_timeout', False, 360), help='Transfer timeout (in seconds).')
2292
+ upload_parser.add_argument(dest='args', action='store', nargs='+', help='files and datasets.')
2293
+ upload_parser.add_argument('--recursive', dest='recursive', action='store_true', default=False, help='Convert recursively the folder structure into collections')
2294
+
2295
+ # The download and get subparser
2296
+ get_parser = subparsers.add_parser('get', help='Download method (synonym for download)')
2297
+ download_parser = subparsers.add_parser('download', help='Download method (synonym for get)')
2298
+ for selected_parser in [get_parser, download_parser]:
2299
+ selected_parser.set_defaults(function=download)
2300
+ selected_parser.add_argument('--dir', dest='dir', default='.', action='store', help='The directory to store the downloaded file.')
2301
+ selected_parser.add_argument(dest='dids', nargs='*', action='store', help='List of space separated data identifiers.')
2302
+ selected_parser.add_argument('--allow-tape', action='store_true', default=False, help="Also consider tape endpoints as source of the download.")
2303
+ selected_parser.add_argument('--rses', action='store', help='RSE Expression to specify allowed sources')
2304
+ selected_parser.add_argument('--impl', dest='impl', action='store', help='Transfer protocol implementation to use (e.g: xrootd, gfal.NoRename, webdav, ssh.Rsync, rclone).')
2305
+ selected_parser.add_argument('--protocol', action='store', help='Force the protocol to use.')
2306
+ selected_parser.add_argument('--nrandom', type=int, action='store', help='Download N random files from the DID.')
2307
+ selected_parser.add_argument('--ndownloader', type=int, default=3, action='store', help='Choose the number of parallel processes for download.')
2308
+ selected_parser.add_argument('--no-subdir', action='store_true', default=False, help="Don't create a subdirectory for the scope of the files.")
2309
+ selected_parser.add_argument('--pfn', dest='pfn', action='store', help="Specify the exact PFN for the download.")
2310
+ selected_parser.add_argument('--archive-did', action='store', dest='archive_did', help="Download from archive is transparent. This option is obsolete.")
2311
+ selected_parser.add_argument('--no-resolve-archives', action='store_true', default=False, help="If set archives will not be considered for download.")
2312
+ selected_parser.add_argument('--ignore-checksum', action='store_true', default=False, help="Don't validate checksum for downloaded files.")
2313
+ selected_parser.add_argument('--check-local-with-filesize-only', action='store_true', default=False, help="Don't use checksum verification for already downloaded files, use filesize instead.")
2314
+ selected_parser.add_argument('--transfer-timeout', dest='transfer_timeout', type=float, action='store', default=config_get_float('download', 'transfer_timeout', False, None), help='Transfer timeout (in seconds). Default: computed dynamically from --transfer-speed-timeout. If set to any value >= 0, --transfer-speed-timeout is ignored.') # NOQA: E501
2315
+ selected_parser.add_argument('--transfer-speed-timeout', dest='transfer_speed_timeout', type=float, action='store', default=None, help='Minimum allowed average transfer speed (in KBps). Default: 500. Used to dynamically compute the timeout if --transfer-timeout not set. Is not supported for --pfn.') # NOQA: E501
2316
+ selected_parser.add_argument('--aria', action='store_true', default=False, help="Use aria2c utility if possible. (EXPERIMENTAL)")
2317
+ selected_parser.add_argument('--trace_appid', '--trace-appid', new_option_string='--trace-appid', dest='trace_appid', action=StoreAndDeprecateWarningAction, default=os.environ.get('RUCIO_TRACE_APPID', None), help=argparse.SUPPRESS)
2318
+ selected_parser.add_argument('--trace_dataset', '--trace-dataset', new_option_string='--trace-dataset', dest='trace_dataset', action=StoreAndDeprecateWarningAction, default=os.environ.get('RUCIO_TRACE_DATASET', None), help=argparse.SUPPRESS)
2319
+ selected_parser.add_argument('--trace_datasetscope', '--trace-datasetscope', new_option_string='--trace-datasetscope', dest='trace_datasetscope', action=StoreAndDeprecateWarningAction, default=os.environ.get('RUCIO_TRACE_DATASETSCOPE', None), help=argparse.SUPPRESS) # NOQA: E501
2320
+ selected_parser.add_argument('--trace_eventtype', '--trace-eventtype', new_option_string='--trace-eventtype', dest='trace_eventtype', action=StoreAndDeprecateWarningAction, default=os.environ.get('RUCIO_TRACE_EVENTTYPE', None), help=argparse.SUPPRESS) # NOQA: E501
2321
+ selected_parser.add_argument('--trace_pq', '--trace-pq', new_option_string='--trace-pq', dest='trace_pq', action=StoreAndDeprecateWarningAction, default=os.environ.get('RUCIO_TRACE_PQ', None), help=argparse.SUPPRESS)
2322
+ selected_parser.add_argument('--trace_taskid', '--trace-taskid', new_option_string='--trace-taskid', dest='trace_taskid', action=StoreAndDeprecateWarningAction, default=os.environ.get('RUCIO_TRACE_TASKID', None), help=argparse.SUPPRESS)
2323
+ selected_parser.add_argument('--trace_usrdn', '--trace-usrdn', new_option_string='--trace-usrdn', dest='trace_usrdn', action=StoreAndDeprecateWarningAction, default=os.environ.get('RUCIO_TRACE_USRDN', None), help=argparse.SUPPRESS)
2324
+ selected_parser.add_argument('--filter', dest='filter', action='store', help='Filter files by key-value pairs like guid=2e2232aafac8324db452070304f8d745.')
2325
+ selected_parser.add_argument('--scope', dest='scope', action='store', help='Scope if you are using the filter option and no full DID.')
2326
+ selected_parser.add_argument('--metalink', dest='metalink_file', action='store', help='Path to a metalink file.')
2327
+ selected_parser.add_argument('--deactivate-file-download-exceptions', dest='deactivate_file_download_exceptions', action='store_true', help='Does not raise NoFilesDownloaded, NotAllFilesDownloaded or incorrect number of output queue files Exception.') # NOQA: E501
2328
+ selected_parser.add_argument('--replica-selection', dest='sort', action='store', help='Select the best replica using a replica sorting algorithm provided by replica sorter (e.g., random, geoip).')
2329
+
2330
+ # The get-metadata subparser
2331
+ get_metadata_parser = subparsers.add_parser('get-metadata', help='Get metadata for DIDs.')
2332
+ get_metadata_parser.set_defaults(function=get_metadata)
2333
+ get_metadata_parser.add_argument(dest='dids', nargs='+', action='store', help='List of space separated data identifiers.')
2334
+ get_metadata_parser.add_argument('--plugin', dest='plugin', action='store', help='Filter down to metadata from specific metadata plugin', required=False)
2335
+
2336
+ # The set-metadata subparser
2337
+ set_metadata_parser = subparsers.add_parser('set-metadata', help='set-metadata method')
2338
+ set_metadata_parser.set_defaults(function=set_metadata)
2339
+ set_metadata_parser.add_argument('--did', dest='did', action='store', help='Data identifier whose metadata will be set', required=True)
2340
+ set_metadata_parser.add_argument('--key', dest='key', action='store', help='Attribute key', required=True)
2341
+ set_metadata_parser.add_argument('--value', dest='value', action='store', help='Attribute value', required=True)
2342
+
2343
+ # delete-did-meta subparser
2344
+ delete_metadata_parser = subparsers.add_parser('delete-metadata', help='delete metadata')
2345
+ delete_metadata_parser.set_defaults(function=delete_metadata)
2346
+ delete_metadata_parser.add_argument('--did', dest='did', action='store', help='Data identifier to delete', required=True)
2347
+ delete_metadata_parser.add_argument('--key', dest='key', action='store', help='Attribute key', required=True)
2348
+
2349
+ # The list-rse-usage subparser
2350
+ list_rse_usage_parser = subparsers.add_parser('list-rse-usage', help='Shows the total/free/used space for a given RSE. This values can differ for different RSE source.')
2351
+ list_rse_usage_parser.set_defaults(function=list_rse_usage)
2352
+ list_rse_usage_parser.add_argument(dest='rse', action='store', help='Rucio Storage Element (RSE) name.').completer = rse_completer
2353
+ list_rse_usage_parser.add_argument('--history', dest='history', default=False, action='store', help='List RSE usage history. [Unimplemented]')
2354
+ list_rse_usage_parser.add_argument('--show-accounts', dest='show_accounts', action='store_true', default=False, help='List accounts usages of RSE')
2355
+
2356
+ # The list-account-usage subparser
2357
+ list_account_usage_parser = subparsers.add_parser('list-account-usage', help='Shows the space used, the quota limit and the quota left for an account for every RSE where the user have quota.')
2358
+ list_account_usage_parser.set_defaults(function=list_account_usage)
2359
+ list_account_usage_parser.add_argument(dest='usage_account', action='store', help='Account name.')
2360
+ list_account_usage_parser.add_argument('--rse', action='store', help='Show usage for only for this RSE.')
2361
+
2362
+ # The list-account-limits subparser
2363
+ list_account_limits_parser = subparsers.add_parser('list-account-limits', help='List quota limits for an account in every RSEs.')
2364
+ list_account_limits_parser.set_defaults(function=list_account_limits)
2365
+ list_account_limits_parser.add_argument('limit_account', action='store', help='The account name.')
2366
+ list_account_limits_parser.add_argument('--rse', dest='rse', action='store', help='If this option is given, the results are restricted to only this RSE.').completer = rse_completer
2367
+
2368
+ # Add replication rule subparser
2369
+ add_rule_parser = subparsers.add_parser('add-rule', help='Add replication rule.')
2370
+ add_rule_parser.set_defaults(function=add_rule)
2371
+ add_rule_parser.add_argument(dest='dids', action='store', nargs='+', help='DID(s) to apply the rule to')
2372
+ add_rule_parser.add_argument(dest='copies', action='store', type=int, help='Number of copies')
2373
+ add_rule_parser.add_argument(dest='rse_expression', action='store', help='RSE Expression')
2374
+ add_rule_parser.add_argument('--weight', dest='weight', action='store', help='RSE Weight')
2375
+ add_rule_parser.add_argument('--lifetime', dest='lifetime', action='store', type=int, help='Rule lifetime (in seconds)')
2376
+ add_rule_parser.add_argument('--grouping', dest='grouping', action='store', choices=['DATASET', 'ALL', 'NONE'], help='Rule grouping')
2377
+ add_rule_parser.add_argument('--locked', dest='locked', action='store_true', help='Rule locking')
2378
+ add_rule_parser.add_argument('--source-replica-expression', dest='source_replica_expression', action='store', help='RSE Expression for RSEs to be considered for source replicas')
2379
+ add_rule_parser.add_argument('--notify', dest='notify', action='store', help='Notification strategy : Y (Yes), N (No), C (Close)')
2380
+ add_rule_parser.add_argument('--activity', dest='activity', action='store', help='Activity to be used (e.g. User, Data Consolidation)')
2381
+ add_rule_parser.add_argument('--comment', dest='comment', action='store', help='Comment about the replication rule')
2382
+ add_rule_parser.add_argument('--ask-approval', dest='ask_approval', action='store_true', help='Ask for rule approval')
2383
+ add_rule_parser.add_argument('--asynchronous', dest='asynchronous', action='store_true', help='Create rule asynchronously')
2384
+ add_rule_parser.add_argument('--delay-injection', dest='delay_injection', action='store', type=int, help='Delay (in seconds) to wait before starting applying the rule. This option implies --asynchronous.')
2385
+ add_rule_parser.add_argument('--account', dest='rule_account', action='store', help='The account owning the rule')
2386
+ add_rule_parser.add_argument('--skip-duplicates', dest='ignore_duplicate', action='store_true', help='Skip duplicate rules')
2387
+
2388
+ # Delete replication rule subparser
2389
+ delete_rule_parser = subparsers.add_parser('delete-rule', help='Delete replication rule.')
2390
+ delete_rule_parser.set_defaults(function=delete_rule)
2391
+ delete_rule_parser.add_argument(dest='rule_id', action='store', help='Rule id or DID. If DID, the RSE expression is mandatory.')
2392
+ delete_rule_parser.add_argument('--purge-replicas', dest='purge_replicas', action='store_true', help='Purge rule replicas')
2393
+ delete_rule_parser.add_argument('--all', dest='delete_all', action='store_true', default=False, help='Delete all the rules, even the ones that are not owned by the account')
2394
+ delete_rule_parser.add_argument('--rses', dest='rses', action='store', help='The RSE expression. Must be specified if a DID is provided.')
2395
+ delete_rule_parser.add_argument('--account', dest='rule_account', action='store', help='The account of the rule that must be deleted')
2396
+
2397
+ # Info replication rule subparser
2398
+ info_rule_parser = subparsers.add_parser('rule-info', help='Retrieve information about a rule.')
2399
+ info_rule_parser.set_defaults(function=info_rule)
2400
+ info_rule_parser.add_argument(dest='rule_id', action='store', help='The rule ID')
2401
+ info_rule_parser.add_argument('--examine', dest='examine', action='store_true', help='Detailed analysis of transfer errors')
2402
+
2403
+ # The list_rules command
2404
+ list_rules_parser = subparsers.add_parser('list-rules', help='List replication rules.', formatter_class=argparse.RawDescriptionHelpFormatter, epilog='''Usage example
2405
+ """""""""""""
2406
+
2407
+ You can list the rules for a particular DID::
2408
+
2409
+ $ rucio list-rules user.jdoe:user.jdoe.test.container.1234.1
2410
+ ID ACCOUNT SCOPE:NAME STATE[OK/REPL/STUCK] RSE_EXPRESSION COPIES EXPIRES (UTC)
2411
+ -------------------------------- --------- ----------------------------------------- ---------------------- ------------------ -------- -------------------
2412
+ a12e5664555a4f12b3cc6991db5accf9 jdoe user.jdoe:user.jdoe.test.container.1234.1 OK[3/0/0] tier=1&disk=1 1 2018-02-09 03:57:46
2413
+ b0fcde2acbdb489b874c3c4537595adc janedoe user.jdoe:user.jdoe.test.container.1234.1 REPLICATING[4/1/1] tier=1&tape=1 2
2414
+ 4a6bd85c13384bd6836fbc06e8b316d7 mc user.jdoe:user.jdoe.test.container.1234.1 OK[3/0/0] tier=1&tape=1 2
2415
+
2416
+ You can filter by account::
2417
+
2418
+ $ rucio list-rules --account jdoe
2419
+ ID ACCOUNT SCOPE:NAME STATE[OK/REPL/STUCK] RSE_EXPRESSION COPIES EXPIRES (UTC)
2420
+ -------------------------------- --------- ----------------------------------------- ---------------------- ------------------ -------- -------------------
2421
+ a12e5664555a4f12b3cc6991db5accf9 jdoe user.jdoe:user.jdoe.test.container.1234.1 OK[3/0/0] tier=1&disk=1 1 2018-02-09 03:57:46
2422
+ 08537b2176843d92e05317938a89d148 jdoe user.jdoe:user.jdoe.test.data.1234.1 OK[2/0/0] SITE2_DISK 1
2423
+
2424
+ ''')
2425
+
2426
+ list_rules_parser.set_defaults(function=list_rules)
2427
+ list_rules_parser.add_argument(dest='did', action='store', nargs='?', default=None, help='List by did')
2428
+ list_rules_parser.add_argument('--id', dest='rule_id', action='store', help='List by rule id')
2429
+ list_rules_parser.add_argument('--traverse', dest='traverse', action='store_true', help='Traverse the did tree and search for rules affecting this did')
2430
+ list_rules_parser.add_argument('--csv', dest='csv', action='store_true', default=False, help='Comma Separated Value output')
2431
+ list_rules_parser.add_argument('--file', dest='file', action='store', help='List associated rules of an affected file')
2432
+ list_rules_parser.add_argument('--account', dest='rule_account', action='store', help='List by account')
2433
+ list_rules_parser.add_argument('--subscription', dest='subscription', action='store', help='List by account and subscription name', metavar=('ACCOUNT', 'SUBSCRIPTION'), nargs=2)
2434
+
2435
+ # The list_rules_history command
2436
+ list_rules_history_parser = subparsers.add_parser('list-rules-history', help='List replication rules history for a DID.')
2437
+ list_rules_history_parser.set_defaults(function=list_rules_history)
2438
+ list_rules_history_parser.add_argument(dest='did', action='store', help='The Data IDentifier.')
2439
+
2440
+ # The update_rule command
2441
+ update_rule_parser = subparsers.add_parser('update-rule', help='Update replication rule.')
2442
+ update_rule_parser.set_defaults(function=update_rule)
2443
+ update_rule_parser.add_argument(dest='rule_id', action='store', help='Rule id')
2444
+ update_rule_parser.add_argument('--lifetime', dest='lifetime', action='store', help='Lifetime in seconds.')
2445
+ update_rule_parser.add_argument('--locked', dest='locked', action='store', help='Locked (True/False).')
2446
+ update_rule_parser.add_argument('--account', dest='rule_account', action='store', help='Account to change.')
2447
+ update_rule_parser.add_argument('--stuck', dest='state_stuck', action='store_true', help='Set state to STUCK.')
2448
+ update_rule_parser.add_argument('--suspend', dest='state_suspended', action='store_true', help='Set state to SUSPENDED.')
2449
+ update_rule_parser.add_argument('--activity', dest='rule_activity', action='store', help='Activity of the rule.')
2450
+ update_rule_parser.add_argument('--source-replica-expression', dest='source_replica_expression', action='store', help='Source replica expression of the rule.')
2451
+ update_rule_parser.add_argument('--comment', dest='comment', action='store', help="Update comment for the rule")
2452
+ update_rule_parser.add_argument('--cancel-requests', dest='cancel_requests', action='store_true', help='Cancel requests when setting rules to stuck.')
2453
+ update_rule_parser.add_argument('--priority', dest='priority', action='store', help='Priority of the requests of the rule.')
2454
+ update_rule_parser.add_argument('--child-rule-id', dest='child_rule_id', action='store', help='Child rule id of the rule. Use "None" to remove an existing parent/child relationship.')
2455
+ update_rule_parser.add_argument('--boost-rule', dest='boost_rule', action='store_true', help='Quickens the transition of a rule from STUCK to REPLICATING.')
2456
+
2457
+ # The move_rule command
2458
+ move_rule_parser = subparsers.add_parser('move-rule', help='Move a replication rule to another RSE.')
2459
+ move_rule_parser.set_defaults(function=move_rule)
2460
+ move_rule_parser.add_argument(dest='rule_id', action='store', help='Rule id')
2461
+ move_rule_parser.add_argument(dest='rse_expression', action='store', help='RSE expression of new rule')
2462
+ move_rule_parser.add_argument('--activity', dest='activity', action='store', help='Update activity for moved rule.')
2463
+ move_rule_parser.add_argument('--source-replica-expression', dest='source_replica_expression', action='store', help='Update source-replica-expression for moved rule. Use "None" to remove the old value.')
2464
+
2465
+ # The list-rses command
2466
+ list_rses_parser = subparsers.add_parser('list-rses', help='Show the list of all the registered Rucio Storage Elements (RSEs).')
2467
+ list_rses_parser.set_defaults(function=list_rses)
2468
+ list_rses_parser.add_argument('--rses', dest='rses', action='store', help='The RSE filter expression. A comprehensive help about RSE expressions \
2469
+ can be found in ' + Color.BOLD + 'https://rucio.cern.ch/documentation/started/concepts/rse_expressions' + Color.END)
2470
+
2471
+ # The list-suspicious-replicas command
2472
+ list_suspicious_replicas_parser = subparsers.add_parser('list-suspicious-replicas', help='Show the list of all replicas marked "suspicious".')
2473
+ list_suspicious_replicas_parser.set_defaults(function=list_suspicious_replicas)
2474
+ list_suspicious_replicas_parser.add_argument('--expression', dest='rse_expression', action='store', help='The RSE filter expression. A comprehensive help about RSE expressions \
2475
+ can be found in ' + Color.BOLD + 'https://rucio.cern.ch/documentation/started/concepts/rse_expressions' + Color.END)
2476
+ list_suspicious_replicas_parser.add_argument('--younger_than', '--younger-than', new_option_string='--younger-than', dest='younger_than', action=StoreAndDeprecateWarningAction, help='List files that have been marked suspicious since the date "younger_than", e.g. 2021-11-29T00:00:00.') # NOQA: E501
2477
+ list_suspicious_replicas_parser.add_argument('--nattempts', dest='nattempts', action='store', help='Minimum number of failed attempts to access a suspicious file.')
2478
+
2479
+ # The list-rses-attributes command
2480
+ list_rse_attributes_parser = subparsers.add_parser('list-rse-attributes', help='List the attributes of an RSE.', description='This command is useful to create RSE filter expressions.')
2481
+ list_rse_attributes_parser.set_defaults(function=list_rse_attributes)
2482
+ list_rse_attributes_parser.add_argument(dest='rse', action='store', help='The RSE name').completer = rse_completer
2483
+
2484
+ # The list-datasets-rse command
2485
+ list_datasets_rse_parser = subparsers.add_parser('list-datasets-rse', help='List all the datasets at a RSE', description='This method allows to list all the datasets on a given Rucio Storage Element.\
2486
+ ' + Color.BOLD + 'Warning: ' + Color.END + 'This command can take a long time depending on the number of datasets in the RSE.')
2487
+ list_datasets_rse_parser.set_defaults(function=list_datasets_rse)
2488
+ list_datasets_rse_parser.add_argument(dest='rse', action='store', default=None, help='The RSE name').completer = rse_completer
2489
+ list_datasets_rse_parser.add_argument('--long', dest='long', action='store_true', default=False, help='The long option')
2490
+
2491
+ # The test-server command
2492
+ test_server_parser = subparsers.add_parser('test-server', help='Test Server', description='Run a bunch of tests against the Rucio Servers.')
2493
+ test_server_parser.set_defaults(function=test_server)
2494
+
2495
+ # The get-metadata subparser
2496
+ touch_parser = subparsers.add_parser('touch', help='Touch one or more DIDs and set the last accessed date to the current date')
2497
+ touch_parser.set_defaults(function=touch)
2498
+ touch_parser.add_argument(dest='dids', nargs='+', action='store', help='List of space separated data identifiers.')
2499
+ touch_parser.add_argument('--rse', dest='rse', action='store', help="The RSE of the DIDs that are touched.").completer = rse_completer
2500
+
2501
+ # The add-lifetime-exception command
2502
+ add_lifetime_exception_parser = subparsers.add_parser('add-lifetime-exception', help='Add an exception to the lifetime model.',
2503
+ formatter_class=argparse.RawDescriptionHelpFormatter, epilog='''Usage example
2504
+ """""""""""""
2505
+ ::
2506
+
2507
+ $ rucio add-lifetime-exception --inputfile myfile.txt --reason "Needed for my analysis" --expiration 2015-10-30
2508
+
2509
+ ''')
2510
+
2511
+ add_lifetime_exception_parser.set_defaults(function=add_lifetime_exception)
2512
+ add_lifetime_exception_parser.add_argument('--inputfile', action='store', help='File where the list of datasets requested to be extended are located.', required=True)
2513
+ add_lifetime_exception_parser.add_argument('--reason', action='store', help='The reason for the extension.', required=True)
2514
+ add_lifetime_exception_parser.add_argument('--expiration', action='store', help='The expiration date format YYYY-MM-DD', required=True)
2515
+
2516
+ return oparser
2517
+
2518
+
2519
+ if __name__ == '__main__':
2520
+ arguments = sys.argv[1:]
2521
+ # set the configuration before anything else, if the config parameter is present
2522
+ for argi in range(len(arguments)):
2523
+ if arguments[argi] == '--config' and (argi + 1) < len(arguments):
2524
+ os.environ['RUCIO_CONFIG'] = arguments[argi + 1]
2525
+
2526
+ oparser = get_parser()
2527
+ if EXTRA_MODULES['argcomplete']:
2528
+ argcomplete.autocomplete(oparser)
2529
+
2530
+ if len(sys.argv) == 1:
2531
+ oparser.print_help()
2532
+ sys.exit(FAILURE)
2533
+
2534
+ args = oparser.parse_args(arguments)
2535
+
2536
+ logger = setup_logger(module_name=__name__, logger_name='user', verbose=args.verbose)
2537
+ start_time = time.time()
2538
+ result = args.function(args)
2539
+ end_time = time.time()
2540
+ if args.verbose:
2541
+ print("Completed in %-0.4f sec." % (end_time - start_time))
2542
+ sys.exit(result)