0002-provisionning-grab-existing-roles-by-uuid-in-one-que.patch
hobo/provisionning/utils.py | ||
---|---|---|
109 | 109 |
def provision_role(cls, issuer, action, data, full=False): |
110 | 110 |
logger = logging.getLogger(__name__) |
111 | 111 |
uuids = set() |
112 |
roles_by_uuid = dict() |
|
113 | ||
114 |
if action == 'provision': |
|
115 |
# first pass to gather existing roles by uuid |
|
116 |
target_uuids = set() |
|
117 |
for o in data: |
|
118 |
assert 'uuid' in o |
|
119 |
target_uuids.add(o['uuid']) |
|
120 |
for role in Role.objects.filter(uuid__in=target_uuids): |
|
121 |
roles_by_uuid[role.uuid] = role |
|
122 | ||
112 | 123 |
for o in data: |
113 | 124 |
assert 'uuid' in o |
114 | 125 |
uuids.add(o['uuid']) |
... | ... | |
118 | 129 |
if len(role_name) > 70: |
119 | 130 |
role_name = role_name[:70] + '(...)' |
120 | 131 |
try: |
121 |
role = Role.objects.get(uuid=o['uuid'])
|
|
132 |
role = roles_by_uuid[o['uuid']]
|
|
122 | 133 |
created = False |
123 |
except Role.DoesNotExist:
|
|
134 |
except KeyError:
|
|
124 | 135 |
try: |
125 | 136 |
with atomic(): |
126 | 137 |
role, created = Role.objects.get_or_create( |
127 |
- |