rucio-clients 32.8.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of rucio-clients might be problematic. Click here for more details.

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