Skip to content

Instantly share code, notes, and snippets.

@clayg
Created January 8, 2016 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clayg/409b9ed47fa550cfc8ca to your computer and use it in GitHub Desktop.
Save clayg/409b9ed47fa550cfc8ca to your computer and use it in GitHub Desktop.
diff --git a/swift/common/ring/builder.py b/swift/common/ring/builder.py
index 742e020..5fe9b2c 100644
--- a/swift/common/ring/builder.py
+++ b/swift/common/ring/builder.py
@@ -334,18 +334,10 @@ class RingBuilder(object):
users may depend on it)
"""
if 'id' not in dev:
- dev['id'] = 0
- if self.devs:
- dev_id_found = False
- # look for existing slots that we can reuse
- for i in range(len(self.devs)):
- if self.devs[i] is None:
- dev['id'] = i
- dev_id_found = True
- break
- if not dev_id_found:
- # no slots available for reuse, grab a brand new one
- dev['id'] = len(self.devs)
+ try:
+ dev['id'] = self.devs.index(None)
+ except ValueError:
+ dev['id'] = len(self.devs)
if dev['id'] < len(self.devs) and self.devs[dev['id']] is not None:
raise exceptions.DuplicateDeviceError(
'Duplicate device id: %d' % dev['id'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment