swift 2.32.0__py2.py3-none-any.whl → 2.34.0__py2.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.
Files changed (127) hide show
  1. swift/account/auditor.py +11 -0
  2. swift/account/reaper.py +11 -1
  3. swift/account/replicator.py +22 -0
  4. swift/account/server.py +13 -12
  5. swift-2.32.0.data/scripts/swift-account-audit → swift/cli/account_audit.py +6 -2
  6. swift-2.32.0.data/scripts/swift-config → swift/cli/config.py +1 -1
  7. swift-2.32.0.data/scripts/swift-dispersion-populate → swift/cli/dispersion_populate.py +6 -2
  8. swift-2.32.0.data/scripts/swift-drive-audit → swift/cli/drive_audit.py +12 -3
  9. swift-2.32.0.data/scripts/swift-get-nodes → swift/cli/get_nodes.py +6 -2
  10. swift/cli/info.py +131 -3
  11. swift-2.32.0.data/scripts/swift-oldies → swift/cli/oldies.py +6 -3
  12. swift-2.32.0.data/scripts/swift-orphans → swift/cli/orphans.py +7 -2
  13. swift-2.32.0.data/scripts/swift-recon-cron → swift/cli/recon_cron.py +9 -18
  14. swift-2.32.0.data/scripts/swift-reconciler-enqueue → swift/cli/reconciler_enqueue.py +2 -3
  15. swift/cli/relinker.py +1 -1
  16. swift/cli/reload.py +141 -0
  17. swift/cli/ringbuilder.py +24 -0
  18. swift/common/daemon.py +12 -2
  19. swift/common/db.py +14 -9
  20. swift/common/db_auditor.py +2 -2
  21. swift/common/db_replicator.py +6 -0
  22. swift/common/exceptions.py +12 -0
  23. swift/common/http_protocol.py +76 -3
  24. swift/common/manager.py +120 -5
  25. swift/common/memcached.py +24 -25
  26. swift/common/middleware/account_quotas.py +144 -43
  27. swift/common/middleware/backend_ratelimit.py +166 -24
  28. swift/common/middleware/catch_errors.py +1 -3
  29. swift/common/middleware/cname_lookup.py +3 -5
  30. swift/common/middleware/container_sync.py +6 -10
  31. swift/common/middleware/crypto/crypto_utils.py +4 -5
  32. swift/common/middleware/crypto/decrypter.py +4 -5
  33. swift/common/middleware/crypto/kms_keymaster.py +2 -1
  34. swift/common/middleware/proxy_logging.py +57 -43
  35. swift/common/middleware/ratelimit.py +6 -7
  36. swift/common/middleware/recon.py +6 -7
  37. swift/common/middleware/s3api/acl_handlers.py +10 -1
  38. swift/common/middleware/s3api/controllers/__init__.py +3 -0
  39. swift/common/middleware/s3api/controllers/acl.py +3 -2
  40. swift/common/middleware/s3api/controllers/logging.py +2 -2
  41. swift/common/middleware/s3api/controllers/multi_upload.py +31 -15
  42. swift/common/middleware/s3api/controllers/obj.py +20 -1
  43. swift/common/middleware/s3api/controllers/object_lock.py +44 -0
  44. swift/common/middleware/s3api/s3api.py +6 -0
  45. swift/common/middleware/s3api/s3request.py +190 -74
  46. swift/common/middleware/s3api/s3response.py +48 -8
  47. swift/common/middleware/s3api/s3token.py +2 -2
  48. swift/common/middleware/s3api/utils.py +2 -1
  49. swift/common/middleware/slo.py +508 -310
  50. swift/common/middleware/staticweb.py +45 -14
  51. swift/common/middleware/tempauth.py +6 -4
  52. swift/common/middleware/tempurl.py +134 -93
  53. swift/common/middleware/x_profile/exceptions.py +1 -4
  54. swift/common/middleware/x_profile/html_viewer.py +9 -10
  55. swift/common/middleware/x_profile/profile_model.py +1 -2
  56. swift/common/middleware/xprofile.py +1 -2
  57. swift/common/request_helpers.py +101 -8
  58. swift/common/statsd_client.py +207 -0
  59. swift/common/storage_policy.py +1 -1
  60. swift/common/swob.py +5 -2
  61. swift/common/utils/__init__.py +331 -1774
  62. swift/common/utils/base.py +138 -0
  63. swift/common/utils/config.py +443 -0
  64. swift/common/utils/logs.py +999 -0
  65. swift/common/utils/timestamp.py +23 -2
  66. swift/common/wsgi.py +19 -3
  67. swift/container/auditor.py +11 -0
  68. swift/container/backend.py +136 -31
  69. swift/container/reconciler.py +11 -2
  70. swift/container/replicator.py +64 -7
  71. swift/container/server.py +276 -146
  72. swift/container/sharder.py +86 -42
  73. swift/container/sync.py +11 -1
  74. swift/container/updater.py +12 -2
  75. swift/obj/auditor.py +20 -3
  76. swift/obj/diskfile.py +63 -25
  77. swift/obj/expirer.py +154 -47
  78. swift/obj/mem_diskfile.py +2 -1
  79. swift/obj/mem_server.py +1 -0
  80. swift/obj/reconstructor.py +28 -4
  81. swift/obj/replicator.py +63 -24
  82. swift/obj/server.py +76 -59
  83. swift/obj/updater.py +12 -2
  84. swift/obj/watchers/dark_data.py +72 -34
  85. swift/proxy/controllers/account.py +3 -2
  86. swift/proxy/controllers/base.py +254 -148
  87. swift/proxy/controllers/container.py +274 -289
  88. swift/proxy/controllers/obj.py +120 -166
  89. swift/proxy/server.py +17 -13
  90. {swift-2.32.0.dist-info → swift-2.34.0.dist-info}/AUTHORS +14 -4
  91. {swift-2.32.0.dist-info → swift-2.34.0.dist-info}/METADATA +9 -7
  92. {swift-2.32.0.dist-info → swift-2.34.0.dist-info}/RECORD +97 -120
  93. {swift-2.32.0.dist-info → swift-2.34.0.dist-info}/entry_points.txt +39 -0
  94. swift-2.34.0.dist-info/pbr.json +1 -0
  95. swift-2.32.0.data/scripts/swift-account-auditor +0 -23
  96. swift-2.32.0.data/scripts/swift-account-info +0 -52
  97. swift-2.32.0.data/scripts/swift-account-reaper +0 -23
  98. swift-2.32.0.data/scripts/swift-account-replicator +0 -34
  99. swift-2.32.0.data/scripts/swift-account-server +0 -23
  100. swift-2.32.0.data/scripts/swift-container-auditor +0 -23
  101. swift-2.32.0.data/scripts/swift-container-info +0 -56
  102. swift-2.32.0.data/scripts/swift-container-reconciler +0 -21
  103. swift-2.32.0.data/scripts/swift-container-replicator +0 -34
  104. swift-2.32.0.data/scripts/swift-container-server +0 -23
  105. swift-2.32.0.data/scripts/swift-container-sharder +0 -37
  106. swift-2.32.0.data/scripts/swift-container-sync +0 -23
  107. swift-2.32.0.data/scripts/swift-container-updater +0 -23
  108. swift-2.32.0.data/scripts/swift-dispersion-report +0 -24
  109. swift-2.32.0.data/scripts/swift-form-signature +0 -20
  110. swift-2.32.0.data/scripts/swift-init +0 -119
  111. swift-2.32.0.data/scripts/swift-object-auditor +0 -29
  112. swift-2.32.0.data/scripts/swift-object-expirer +0 -33
  113. swift-2.32.0.data/scripts/swift-object-info +0 -60
  114. swift-2.32.0.data/scripts/swift-object-reconstructor +0 -33
  115. swift-2.32.0.data/scripts/swift-object-relinker +0 -23
  116. swift-2.32.0.data/scripts/swift-object-replicator +0 -37
  117. swift-2.32.0.data/scripts/swift-object-server +0 -27
  118. swift-2.32.0.data/scripts/swift-object-updater +0 -23
  119. swift-2.32.0.data/scripts/swift-proxy-server +0 -23
  120. swift-2.32.0.data/scripts/swift-recon +0 -24
  121. swift-2.32.0.data/scripts/swift-ring-builder +0 -37
  122. swift-2.32.0.data/scripts/swift-ring-builder-analyzer +0 -22
  123. swift-2.32.0.data/scripts/swift-ring-composer +0 -22
  124. swift-2.32.0.dist-info/pbr.json +0 -1
  125. {swift-2.32.0.dist-info → swift-2.34.0.dist-info}/LICENSE +0 -0
  126. {swift-2.32.0.dist-info → swift-2.34.0.dist-info}/WHEEL +0 -0
  127. {swift-2.32.0.dist-info → swift-2.34.0.dist-info}/top_level.txt +0 -0
swift/account/auditor.py CHANGED
@@ -16,7 +16,9 @@
16
16
 
17
17
  from swift.account.backend import AccountBroker
18
18
  from swift.common.exceptions import InvalidAccountInfo
19
+ from swift.common.daemon import run_daemon
19
20
  from swift.common.db_auditor import DatabaseAuditor
21
+ from swift.common.utils import parse_options
20
22
 
21
23
 
22
24
  class AccountAuditor(DatabaseAuditor):
@@ -45,3 +47,12 @@ class AccountAuditor(DatabaseAuditor):
45
47
  'does not match the sum of %(key)s across policies (%(sum)s)'
46
48
  % {'key': key, 'account': info.get('account'),
47
49
  'total': info[key], 'sum': policy_totals[key]})
50
+
51
+
52
+ def main():
53
+ conf_file, options = parse_options(once=True)
54
+ run_daemon(AccountAuditor, conf_file, **options)
55
+
56
+
57
+ if __name__ == '__main__':
58
+ main()
swift/account/reaper.py CHANGED
@@ -27,6 +27,7 @@ import six
27
27
  import swift.common.db
28
28
  from swift.account.backend import AccountBroker, DATADIR
29
29
  from swift.common.constraints import check_drive
30
+ from swift.common.daemon import run_daemon
30
31
  from swift.common.direct_client import direct_delete_container, \
31
32
  direct_delete_object, direct_get_container
32
33
  from swift.common.exceptions import ClientException
@@ -34,7 +35,7 @@ from swift.common.request_helpers import USE_REPLICATION_NETWORK_HEADER
34
35
  from swift.common.ring import Ring
35
36
  from swift.common.ring.utils import is_local_device
36
37
  from swift.common.utils import get_logger, whataremyips, config_true_value, \
37
- Timestamp, md5, node_to_string
38
+ Timestamp, md5, node_to_string, parse_options
38
39
  from swift.common.daemon import Daemon
39
40
  from swift.common.storage_policy import POLICIES, PolicyError
40
41
 
@@ -525,3 +526,12 @@ class AccountReaper(Daemon):
525
526
  else:
526
527
  self.stats_objects_possibly_remaining += 1
527
528
  self.logger.increment('objects_possibly_remaining')
529
+
530
+
531
+ def main():
532
+ conf_file, options = parse_options(once=True)
533
+ run_daemon(AccountReaper, conf_file, **options)
534
+
535
+
536
+ if __name__ == '__main__':
537
+ main()
@@ -13,8 +13,12 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
+ import optparse
17
+
16
18
  from swift.account.backend import AccountBroker, DATADIR
17
19
  from swift.common import db_replicator
20
+ from swift.common.daemon import run_daemon
21
+ from swift.common.utils import parse_options
18
22
 
19
23
 
20
24
  class AccountReplicator(db_replicator.Replicator):
@@ -22,3 +26,21 @@ class AccountReplicator(db_replicator.Replicator):
22
26
  brokerclass = AccountBroker
23
27
  datadir = DATADIR
24
28
  default_port = 6202
29
+
30
+
31
+ def main():
32
+ parser = optparse.OptionParser("%prog CONFIG [options]")
33
+ parser.add_option('-d', '--devices',
34
+ help=('Replicate only given devices. '
35
+ 'Comma-separated list. '
36
+ 'Only has effect if --once is used.'))
37
+ parser.add_option('-p', '--partitions',
38
+ help=('Replicate only given partitions. '
39
+ 'Comma-separated list. '
40
+ 'Only has effect if --once is used.'))
41
+ conf_file, options = parse_options(parser=parser, once=True)
42
+ run_daemon(AccountReplicator, conf_file, **options)
43
+
44
+
45
+ if __name__ == '__main__':
46
+ main()
swift/account/server.py CHANGED
@@ -15,6 +15,7 @@
15
15
 
16
16
  import json
17
17
  import os
18
+ import sys
18
19
  import time
19
20
  import traceback
20
21
 
@@ -30,7 +31,7 @@ from swift.common.request_helpers import get_param, \
30
31
  from swift.common.utils import get_logger, hash_path, public, \
31
32
  Timestamp, storage_directory, config_true_value, \
32
33
  timing_stats, replication, get_log_line, \
33
- config_fallocate_value, fs_has_free_space
34
+ config_fallocate_value, fs_has_free_space, parse_options
34
35
  from swift.common.constraints import valid_timestamp, check_utf8, \
35
36
  check_drive, AUTO_CREATE_ACCOUNT_PREFIX
36
37
  from swift.common import constraints
@@ -43,6 +44,7 @@ from swift.common.swob import HTTPAccepted, HTTPBadRequest, \
43
44
  HTTPPreconditionFailed, HTTPConflict, Request, \
44
45
  HTTPInsufficientStorage, HTTPException, wsgi_to_str
45
46
  from swift.common.request_helpers import is_sys_or_user_meta
47
+ from swift.common.wsgi import run_wsgi
46
48
 
47
49
 
48
50
  def get_account_name_and_placement(req):
@@ -85,17 +87,7 @@ class AccountController(BaseStorageServer):
85
87
  self.replicator_rpc = ReplicatorRpc(self.root, DATADIR, AccountBroker,
86
88
  self.mount_check,
87
89
  logger=self.logger)
88
- if conf.get('auto_create_account_prefix'):
89
- self.logger.warning('Option auto_create_account_prefix is '
90
- 'deprecated. Configure '
91
- 'auto_create_account_prefix under the '
92
- 'swift-constraints section of '
93
- 'swift.conf. This option will '
94
- 'be ignored in a future release.')
95
- self.auto_create_account_prefix = \
96
- conf['auto_create_account_prefix']
97
- else:
98
- self.auto_create_account_prefix = AUTO_CREATE_ACCOUNT_PREFIX
90
+ self.auto_create_account_prefix = AUTO_CREATE_ACCOUNT_PREFIX
99
91
 
100
92
  swift.common.db.DB_PREALLOCATION = \
101
93
  config_true_value(conf.get('db_preallocation', 'f'))
@@ -349,3 +341,12 @@ def app_factory(global_conf, **local_conf):
349
341
  conf = global_conf.copy()
350
342
  conf.update(local_conf)
351
343
  return AccountController(conf)
344
+
345
+
346
+ def main():
347
+ conf_file, options = parse_options(test_config=True)
348
+ sys.exit(run_wsgi(conf_file, 'account-server', **options))
349
+
350
+
351
+ if __name__ == '__main__':
352
+ main()
@@ -1,4 +1,4 @@
1
- #!python
1
+ #!/usr/bin/env python
2
2
  # Copyright (c) 2010-2012 OpenStack Foundation
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -359,7 +359,7 @@ class Auditor(object):
359
359
  _print_stat("MD5 Mismatch", self.object_checksum_mismatch)
360
360
 
361
361
 
362
- if __name__ == '__main__':
362
+ def main():
363
363
  try:
364
364
  optlist, args = getopt.getopt(sys.argv[1:], 'c:r:e:d')
365
365
  except getopt.GetoptError as err:
@@ -384,3 +384,7 @@ if __name__ == '__main__':
384
384
  auditor.audit(*split_path(path, 1, 3, True))
385
385
  auditor.wait()
386
386
  auditor.print_stats()
387
+
388
+
389
+ if __name__ == '__main__':
390
+ main()
@@ -1,4 +1,4 @@
1
- #!python
1
+ #!/usr/bin/env python
2
2
  # Licensed under the Apache License, Version 2.0 (the "License");
3
3
  # you may not use this file except in compliance with the License.
4
4
  # You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- #!python
1
+ #!/usr/bin/env python
2
2
  # Copyright (c) 2010-2012 OpenStack Foundation
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -81,7 +81,7 @@ def report(success):
81
81
  stdout.flush()
82
82
 
83
83
 
84
- if __name__ == '__main__':
84
+ def main():
85
85
  global begun, created, item_type, next_report, need_to_create, retries_done
86
86
  patcher.monkey_patch()
87
87
  try:
@@ -281,3 +281,7 @@ Usage: %%prog [options] [conf_file]
281
281
  print('\r\x1B[KTotal object coverage is now %.2f%%.' %
282
282
  ((float(obj_coverage) / object_ring.partition_count * 100)))
283
283
  stdout.flush()
284
+
285
+
286
+ if __name__ == '__main__':
287
+ main()
@@ -1,4 +1,4 @@
1
- #!python
1
+ #!/usr/bin/env python
2
2
  # Copyright (c) 2010-2012 OpenStack Foundation
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -147,7 +147,12 @@ def get_errors(error_re, log_file_pattern, minutes, logger,
147
147
  log_time = datetime.datetime.strptime(
148
148
  log_time_string, '%Y %b %d %H:%M:%S')
149
149
  except ValueError:
150
- continue
150
+ # Some versions use ISO timestamps instead
151
+ try:
152
+ log_time = datetime.datetime.strptime(
153
+ line[0:19], '%Y-%m-%dT%H:%M:%S')
154
+ except ValueError:
155
+ continue
151
156
  if log_time > end_time:
152
157
  for err in error_re:
153
158
  for device in err.findall(line):
@@ -174,7 +179,7 @@ def comment_fstab(mount_point):
174
179
  os.rename('/etc/fstab.new', '/etc/fstab')
175
180
 
176
181
 
177
- if __name__ == '__main__':
182
+ def main():
178
183
  c = ConfigParser()
179
184
  try:
180
185
  conf_path = sys.argv[1]
@@ -257,3 +262,7 @@ if __name__ == '__main__':
257
262
  elif os.path.isdir("/run/systemd/system"):
258
263
  logger.debug("fstab updated, calling systemctl daemon-reload")
259
264
  subprocess.call(["/usr/bin/systemctl", "daemon-reload"])
265
+
266
+
267
+ if __name__ == '__main__':
268
+ main()
@@ -1,4 +1,4 @@
1
- #!python
1
+ #!/usr/bin/env python
2
2
  # Copyright (c) 2010-2012 OpenStack Foundation
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,7 +25,7 @@ from swift.cli.info import (parse_get_node_args, print_item_locations,
25
25
  InfoSystemExit)
26
26
 
27
27
 
28
- if __name__ == '__main__':
28
+ def main():
29
29
 
30
30
  usage = '''
31
31
  Shows the nodes responsible for the item specified.
@@ -74,3 +74,7 @@ if __name__ == '__main__':
74
74
  print_item_locations(ring, ring_name, *args, **vars(options))
75
75
  except InfoSystemExit:
76
76
  sys.exit(1)
77
+
78
+
79
+ if __name__ == '__main__':
80
+ main()
swift/cli/info.py CHANGED
@@ -10,15 +10,21 @@
10
10
  # License for the specific language governing permissions and limitations
11
11
  # under the License.
12
12
 
13
+
13
14
  from __future__ import print_function
15
+ import codecs
14
16
  import itertools
15
17
  import json
18
+ from optparse import OptionParser
16
19
  import os
17
20
  import sqlite3
21
+ import sys
18
22
  from collections import defaultdict
19
23
 
24
+ import six
20
25
  from six.moves import urllib
21
26
 
27
+ from swift.common.exceptions import LockTimeout
22
28
  from swift.common.utils import hash_path, storage_directory, \
23
29
  Timestamp, is_valid_ipv6
24
30
  from swift.common.ring import Ring
@@ -29,10 +35,10 @@ from swift.account.backend import AccountBroker, DATADIR as ABDATADIR
29
35
  from swift.container.backend import ContainerBroker, DATADIR as CBDATADIR
30
36
  from swift.obj.diskfile import get_data_dir, read_metadata, DATADIR_BASE, \
31
37
  extract_policy
32
- from swift.common.storage_policy import POLICIES
38
+ from swift.common.storage_policy import POLICIES, reload_storage_policies
33
39
  from swift.common.swob import wsgi_to_str
34
40
  from swift.common.middleware.crypto.crypto_utils import load_crypto_meta
35
- from swift.common.utils import md5
41
+ from swift.common.utils import md5, set_swift_dir
36
42
 
37
43
 
38
44
  class InfoSystemExit(Exception):
@@ -198,6 +204,28 @@ def print_ring_locations(ring, datadir, account, container=None, obj=None,
198
204
  'real value is set in the config file on each storage node.')
199
205
 
200
206
 
207
+ def get_max_len_sync_item(syncs, item, title):
208
+ def map_func(element):
209
+ return str(element[item])
210
+ return max(list(map(len, map(map_func, syncs))) + [len(title)])
211
+
212
+
213
+ def print_db_syncs(incoming, syncs):
214
+ max_sync_point_len = get_max_len_sync_item(syncs, 'sync_point',
215
+ "Sync Point")
216
+ max_remote_len = get_max_len_sync_item(syncs, 'remote_id', "Remote ID")
217
+ print('%s Syncs:' % ('Incoming' if incoming else 'Outgoing'))
218
+ print(' %s\t%s\t%s' % ("Sync Point".ljust(max_sync_point_len),
219
+ "Remote ID".ljust(max_remote_len),
220
+ "Updated At"))
221
+ for sync in syncs:
222
+ print(' %s\t%s\t%s (%s)' % (
223
+ str(sync['sync_point']).ljust(max_sync_point_len),
224
+ sync['remote_id'].ljust(max_remote_len),
225
+ Timestamp(sync['updated_at']).isoformat,
226
+ sync['updated_at']))
227
+
228
+
201
229
  def print_db_info_metadata(db_type, info, metadata, drop_prefixes=False,
202
230
  verbose=False):
203
231
  """
@@ -439,7 +467,7 @@ def print_obj_metadata(metadata, drop_prefixes=False):
439
467
 
440
468
 
441
469
  def print_info(db_type, db_file, swift_dir='/etc/swift', stale_reads_ok=False,
442
- drop_prefixes=False, verbose=False):
470
+ drop_prefixes=False, verbose=False, sync=False):
443
471
  if db_type not in ('account', 'container'):
444
472
  print("Unrecognized DB type: internal error")
445
473
  raise InfoSystemExit()
@@ -473,6 +501,11 @@ def print_info(db_type, db_file, swift_dir='/etc/swift', stale_reads_ok=False,
473
501
  info['shard_ranges'] = sranges
474
502
  print_db_info_metadata(
475
503
  db_type, info, broker.metadata, drop_prefixes, verbose)
504
+ if sync:
505
+ # Print incoming / outgoing sync tables.
506
+ for incoming in (True, False):
507
+ print_db_syncs(incoming, broker.get_syncs(incoming,
508
+ include_timestamp=True))
476
509
  try:
477
510
  ring = Ring(swift_dir, ring_name=db_type)
478
511
  except Exception:
@@ -686,3 +719,98 @@ def print_item_locations(ring, ring_name=None, account=None, container=None,
686
719
  print('Object \t%s\n\n' % urllib.parse.quote(obj))
687
720
  print_ring_locations(ring, loc, account, container, obj, part, all_nodes,
688
721
  policy_index=policy_index)
722
+
723
+
724
+ def obj_main():
725
+ if not six.PY2:
726
+ # Make stdout able to write escaped bytes
727
+ sys.stdout = codecs.getwriter("utf-8")(
728
+ sys.stdout.detach(), errors='surrogateescape')
729
+
730
+ parser = OptionParser('%prog [options] OBJECT_FILE')
731
+ parser.add_option(
732
+ '-n', '--no-check-etag', default=True,
733
+ action="store_false", dest="check_etag",
734
+ help="Don't verify file contents against stored etag")
735
+ parser.add_option(
736
+ '-d', '--swift-dir', default='/etc/swift', dest='swift_dir',
737
+ help="Pass location of swift directory")
738
+ parser.add_option(
739
+ '--drop-prefixes', default=False, action="store_true",
740
+ help="When outputting metadata, drop the per-section common prefixes")
741
+ parser.add_option(
742
+ '-P', '--policy-name', dest='policy_name',
743
+ help="Specify storage policy name")
744
+
745
+ options, args = parser.parse_args()
746
+
747
+ if len(args) != 1:
748
+ sys.exit(parser.print_help())
749
+
750
+ if set_swift_dir(options.swift_dir):
751
+ reload_storage_policies()
752
+
753
+ try:
754
+ print_obj(*args, **vars(options))
755
+ except InfoSystemExit:
756
+ sys.exit(1)
757
+
758
+
759
+ def run_print_info(db_type, args, opts):
760
+ try:
761
+ print_info(db_type, *args, **opts)
762
+ except InfoSystemExit:
763
+ sys.exit(1)
764
+ except (sqlite3.OperationalError, LockTimeout) as e:
765
+ if not opts.get('stale_reads_ok'):
766
+ opts['stale_reads_ok'] = True
767
+ print('Warning: Possibly Stale Data')
768
+ run_print_info(db_type, args, opts)
769
+ sys.exit(2)
770
+ else:
771
+ print('%s info failed: %s' % (db_type.title(), e))
772
+ sys.exit(1)
773
+
774
+
775
+ def container_main():
776
+ parser = OptionParser('%prog [options] CONTAINER_DB_FILE')
777
+ parser.add_option(
778
+ '-d', '--swift-dir', default='/etc/swift',
779
+ help="Pass location of swift directory")
780
+ parser.add_option(
781
+ '--drop-prefixes', default=False, action="store_true",
782
+ help="When outputting metadata, drop the per-section common prefixes")
783
+ parser.add_option(
784
+ '-v', '--verbose', default=False, action="store_true",
785
+ help="Show all shard ranges. By default, only the number of shard "
786
+ "ranges is displayed if there are many shards.")
787
+ parser.add_option(
788
+ '--sync', '-s', default=False, action="store_true",
789
+ help="Output the contents of the incoming/outging sync tables")
790
+
791
+ options, args = parser.parse_args()
792
+
793
+ if len(args) != 1:
794
+ sys.exit(parser.print_help())
795
+
796
+ run_print_info('container', args, vars(options))
797
+
798
+
799
+ def account_main():
800
+ parser = OptionParser('%prog [options] ACCOUNT_DB_FILE')
801
+ parser.add_option(
802
+ '-d', '--swift-dir', default='/etc/swift',
803
+ help="Pass location of swift directory")
804
+ parser.add_option(
805
+ '--drop-prefixes', default=False, action="store_true",
806
+ help="When outputting metadata, drop the per-section common prefixes")
807
+ parser.add_option(
808
+ '--sync', '-s', default=False, action="store_true",
809
+ help="Output the contents of the incoming/outging sync tables")
810
+
811
+ options, args = parser.parse_args()
812
+
813
+ if len(args) != 1:
814
+ sys.exit(parser.print_help())
815
+
816
+ run_print_info('account', args, vars(options))
@@ -1,4 +1,4 @@
1
- #!python
1
+ #!/usr/bin/env python
2
2
  # Licensed under the Apache License, Version 2.0 (the "License");
3
3
  # you may not use this file except in compliance with the License.
4
4
  # You may obtain a copy of the License at
@@ -12,13 +12,12 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- from __future__ import print_function
16
15
  import optparse
17
16
  import subprocess
18
17
  import sys
19
18
 
20
19
 
21
- if __name__ == '__main__':
20
+ def main():
22
21
  parser = optparse.OptionParser(usage='''%prog [options]
23
22
 
24
23
  Lists old Swift processes.
@@ -88,3 +87,7 @@ Lists old Swift processes.
88
87
  for hours, pid, args in listing:
89
88
  print('%*s %*s %s' % (hours_len, hours, pid_len,
90
89
  pid, args[:args_len]))
90
+
91
+
92
+ if __name__ == '__main__':
93
+ main()
@@ -1,4 +1,4 @@
1
- #!python
1
+ #!/usr/bin/env python
2
2
  # Licensed under the Apache License, Version 2.0 (the "License");
3
3
  # you may not use this file except in compliance with the License.
4
4
  # You may obtain a copy of the License at
@@ -22,7 +22,8 @@ import sys
22
22
 
23
23
  from swift.common.manager import RUN_DIR
24
24
 
25
- if __name__ == '__main__':
25
+
26
+ def main():
26
27
  parser = optparse.OptionParser(usage='''%prog [options]
27
28
 
28
29
  Lists and optionally kills orphaned Swift processes. This is done by scanning
@@ -130,3 +131,7 @@ Example (sends SIGTERM to all orphaned Swift processes older than two hours):
130
131
  for hours, pid, args in listing:
131
132
  os.kill(int(pid), signum)
132
133
  print('Done.')
134
+
135
+
136
+ if __name__ == '__main__':
137
+ main()
@@ -1,4 +1,3 @@
1
- #!python
2
1
  # Licensed under the Apache License, Version 2.0 (the "License");
3
2
  # you may not use this file except in compliance with the License.
4
3
  # You may obtain a copy of the License at
@@ -12,10 +11,6 @@
12
11
  # See the License for the specific language governing permissions and
13
12
  # limitations under the License.
14
13
 
15
- """
16
- swift-recon-cron.py
17
- """
18
-
19
14
  import os
20
15
  import sys
21
16
  import time
@@ -23,18 +18,18 @@ import time
23
18
  from eventlet import Timeout
24
19
 
25
20
  from swift.common.utils import get_logger, dump_recon_cache, readconf, \
26
- lock_path
21
+ lock_path, listdir
27
22
  from swift.common.recon import RECON_OBJECT_FILE, DEFAULT_RECON_CACHE_PATH
28
23
  from swift.obj.diskfile import ASYNCDIR_BASE
29
24
 
30
25
 
31
- def get_async_count(device_dir, logger):
26
+ def get_async_count(device_dir):
32
27
  async_count = 0
33
- for i in os.listdir(device_dir):
28
+ for i in listdir(device_dir):
34
29
  device = os.path.join(device_dir, i)
35
30
  if not os.path.isdir(device):
36
31
  continue
37
- for asyncdir in os.listdir(device):
32
+ for asyncdir in listdir(device):
38
33
  # skip stuff like "accounts", "containers", etc.
39
34
  if not (asyncdir == ASYNCDIR_BASE or
40
35
  asyncdir.startswith(ASYNCDIR_BASE + '-')):
@@ -42,10 +37,10 @@ def get_async_count(device_dir, logger):
42
37
  async_pending = os.path.join(device, asyncdir)
43
38
 
44
39
  if os.path.isdir(async_pending):
45
- for entry in os.listdir(async_pending):
40
+ for entry in listdir(async_pending):
46
41
  if os.path.isdir(os.path.join(async_pending, entry)):
47
42
  async_hdir = os.path.join(async_pending, entry)
48
- async_count += len(os.listdir(async_hdir))
43
+ async_count += len(listdir(async_hdir))
49
44
  return async_count
50
45
 
51
46
 
@@ -55,7 +50,7 @@ def main():
55
50
  except Exception:
56
51
  print("Usage: %s CONF_FILE" % sys.argv[0].split('/')[-1])
57
52
  print("ex: swift-recon-cron /etc/swift/object-server.conf")
58
- sys.exit(1)
53
+ return 1
59
54
  conf = readconf(conf_path, 'filter:recon')
60
55
  device_dir = conf.get('devices', '/srv/node')
61
56
  recon_cache_path = conf.get('recon_cache_path', DEFAULT_RECON_CACHE_PATH)
@@ -66,7 +61,7 @@ def main():
66
61
  logger = get_logger(conf, log_route='recon-cron')
67
62
  try:
68
63
  with lock_path(lock_dir):
69
- asyncs = get_async_count(device_dir, logger)
64
+ asyncs = get_async_count(device_dir)
70
65
  dump_recon_cache({
71
66
  'async_pending': asyncs,
72
67
  'async_pending_last': time.time(),
@@ -75,8 +70,4 @@ def main():
75
70
  msg = 'Exception during recon-cron while accessing devices'
76
71
  logger.exception(msg)
77
72
  print('%s: %s' % (msg, err))
78
- sys.exit(1)
79
-
80
-
81
- if __name__ == '__main__':
82
- main()
73
+ return 1
@@ -1,4 +1,4 @@
1
- #!python
1
+ #!/usr/bin/env python
2
2
  # Licensed under the Apache License, Version 2.0 (the "License");
3
3
  # you may not use this file except in compliance with the License.
4
4
  # You may obtain a copy of the License at
@@ -11,12 +11,10 @@
11
11
  # implied.
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
- from __future__ import print_function
15
14
  import sys
16
15
  from optparse import OptionParser
17
16
 
18
17
  import eventlet.debug
19
- eventlet.debug.hub_exceptions(True)
20
18
 
21
19
  from swift.common.ring import Ring
22
20
  from swift.common.utils import split_path
@@ -50,6 +48,7 @@ parser.add_option('-f', '--force', action='store_true',
50
48
 
51
49
 
52
50
  def main():
51
+ eventlet.debug.hub_exceptions(True)
53
52
  options, args = parser.parse_args()
54
53
  try:
55
54
  policy_index, path, timestamp = args
swift/cli/relinker.py CHANGED
@@ -743,7 +743,7 @@ def auto_or_int(value):
743
743
  return config_auto_int_value(value, default='auto')
744
744
 
745
745
 
746
- def main(args):
746
+ def main(args=None):
747
747
  parser = argparse.ArgumentParser(
748
748
  description='Relink and cleanup objects to increase partition power')
749
749
  parser.add_argument('action', choices=['relink', 'cleanup'])