@@ -118,9 +118,16 @@ async def _mutate_create_object_and_reconcile(
118
118
) -> Node :
119
119
address = await cls .mutate_create_object (data = data , db = db , branch = branch )
120
120
reconciler = IpamReconciler (db = db , branch = branch )
121
- reconciled_address = await reconciler .reconcile (
122
- ip_value = ip_address , namespace = namespace_id , node_uuid = address .get_id ()
123
- )
121
+
122
+ if lock_name := cls ._get_lock_name (namespace_id , branch ):
123
+ async with InfrahubMultiLock (lock_registry = lock .registry , locks = [lock_name ]):
124
+ reconciled_address = await reconciler .reconcile (
125
+ ip_value = ip_address , namespace = namespace_id , node_uuid = address .get_id ()
126
+ )
127
+ else :
128
+ reconciled_address = await reconciler .reconcile (
129
+ ip_value = ip_address , namespace = namespace_id , node_uuid = address .get_id ()
130
+ )
124
131
return reconciled_address
125
132
126
133
@classmethod
@@ -138,15 +145,9 @@ async def mutate_create(
138
145
namespace_id = await validate_namespace (db = db , branch = branch , data = data )
139
146
140
147
async with db .start_transaction () as dbt :
141
- if lock_name := cls ._get_lock_name (namespace_id , branch ):
142
- async with InfrahubMultiLock (lock_registry = lock .registry , locks = [lock_name ]):
143
- reconciled_address = await cls ._mutate_create_object_and_reconcile (
144
- data = data , branch = branch , db = dbt , ip_address = ip_address , namespace_id = namespace_id
145
- )
146
- else :
147
- reconciled_address = await cls ._mutate_create_object_and_reconcile (
148
- data = data , branch = branch , db = dbt , ip_address = ip_address , namespace_id = namespace_id
149
- )
148
+ reconciled_address = await cls ._mutate_create_object_and_reconcile (
149
+ data = data , branch = branch , db = dbt , ip_address = ip_address , namespace_id = namespace_id
150
+ )
150
151
result = await cls .mutate_create_to_graphql (info = info , db = dbt , obj = reconciled_address )
151
152
152
153
return reconciled_address , result
@@ -164,9 +165,15 @@ async def _mutate_update_object_and_reconcile(
164
165
address = await cls .mutate_update_object (db = db , info = info , data = data , branch = branch , obj = address )
165
166
reconciler = IpamReconciler (db = db , branch = branch )
166
167
ip_address = ipaddress .ip_interface (address .address .value )
167
- reconciled_address = await reconciler .reconcile (
168
- ip_value = ip_address , node_uuid = address .get_id (), namespace = namespace_id
169
- )
168
+ if lock_name := cls ._get_lock_name (namespace_id , branch ):
169
+ async with InfrahubMultiLock (lock_registry = lock .registry , locks = [lock_name ]):
170
+ reconciled_address = await reconciler .reconcile (
171
+ ip_value = ip_address , node_uuid = address .get_id (), namespace = namespace_id
172
+ )
173
+ else :
174
+ reconciled_address = await reconciler .reconcile (
175
+ ip_value = ip_address , node_uuid = address .get_id (), namespace = namespace_id
176
+ )
170
177
return reconciled_address
171
178
172
179
@classmethod
@@ -194,16 +201,9 @@ async def mutate_update(
194
201
namespace_id = await validate_namespace (db = db , branch = branch , data = data , existing_namespace_id = namespace .id )
195
202
196
203
async with db .start_transaction () as dbt :
197
- if lock_name := cls ._get_lock_name (namespace_id , branch ):
198
- async with InfrahubMultiLock (lock_registry = lock .registry , locks = [lock_name ]):
199
- reconciled_address = await cls ._mutate_update_object_and_reconcile (
200
- info = info , data = data , branch = branch , address = address , namespace_id = namespace_id , db = dbt
201
- )
202
- else :
203
- reconciled_address = await cls ._mutate_update_object_and_reconcile (
204
- info = info , data = data , branch = branch , address = address , namespace_id = namespace_id , db = dbt
205
- )
206
-
204
+ reconciled_address = await cls ._mutate_update_object_and_reconcile (
205
+ info = info , data = data , branch = branch , address = address , namespace_id = namespace_id , db = dbt
206
+ )
207
207
result = await cls .mutate_update_to_graphql (db = dbt , info = info , obj = reconciled_address )
208
208
209
209
return address , result
@@ -289,12 +289,9 @@ async def mutate_create(
289
289
namespace_id = await validate_namespace (db = db , branch = branch , data = data )
290
290
291
291
async with db .start_transaction () as dbt :
292
- lock_name = cls ._get_lock_name (namespace_id )
293
- async with InfrahubMultiLock (lock_registry = lock .registry , locks = [lock_name ]):
294
- reconciled_prefix = await cls ._mutate_create_object_and_reconcile (
295
- data = data , branch = branch , db = dbt , namespace_id = namespace_id
296
- )
297
-
292
+ reconciled_prefix = await cls ._mutate_create_object_and_reconcile (
293
+ data = data , branch = branch , db = dbt , namespace_id = namespace_id
294
+ )
298
295
result = await cls .mutate_create_to_graphql (info = info , db = dbt , obj = reconciled_prefix )
299
296
300
297
return reconciled_prefix , result
@@ -339,11 +336,9 @@ async def mutate_update(
339
336
namespace_id = await validate_namespace (db = db , branch = branch , data = data , existing_namespace_id = namespace .id )
340
337
341
338
async with db .start_transaction () as dbt :
342
- lock_name = cls ._get_lock_name (namespace_id )
343
- async with InfrahubMultiLock (lock_registry = lock .registry , locks = [lock_name ]):
344
- reconciled_prefix = await cls ._mutate_update_object_and_reconcile (
345
- info = info , data = data , prefix = prefix , db = dbt , namespace_id = namespace_id , branch = branch
346
- )
339
+ reconciled_prefix = await cls ._mutate_update_object_and_reconcile (
340
+ info = info , data = data , prefix = prefix , db = dbt , namespace_id = namespace_id , branch = branch
341
+ )
347
342
result = await cls .mutate_update_to_graphql (db = dbt , info = info , obj = reconciled_prefix )
348
343
349
344
return prefix , result
@@ -378,9 +373,15 @@ async def _reconcile_prefix(
378
373
) -> Node :
379
374
reconciler = IpamReconciler (db = db , branch = branch )
380
375
ip_network = ipaddress .ip_network (prefix .prefix .value )
381
- reconciled_prefix = await reconciler .reconcile (
382
- ip_value = ip_network , node_uuid = prefix .get_id (), namespace = namespace_id , is_delete = is_delete
383
- )
376
+ if lock_name := cls ._get_lock_name (namespace_id ):
377
+ async with InfrahubMultiLock (lock_registry = lock .registry , locks = [lock_name ]):
378
+ reconciled_prefix = await reconciler .reconcile (
379
+ ip_value = ip_network , node_uuid = prefix .get_id (), namespace = namespace_id , is_delete = is_delete
380
+ )
381
+ else :
382
+ reconciled_prefix = await reconciler .reconcile (
383
+ ip_value = ip_network , node_uuid = prefix .get_id (), namespace = namespace_id , is_delete = is_delete
384
+ )
384
385
return reconciled_prefix
385
386
386
387
@classmethod
@@ -404,11 +405,9 @@ async def mutate_delete(
404
405
namespace_id = namespace_rels [0 ].peer_id
405
406
406
407
async with graphql_context .db .start_transaction () as dbt :
407
- lock_name = cls ._get_lock_name (namespace_id )
408
- async with InfrahubMultiLock (lock_registry = lock .registry , locks = [lock_name ]):
409
- reconciled_prefix = await cls ._reconcile_prefix (
410
- branch = branch , db = dbt , prefix = prefix , namespace_id = namespace_id , is_delete = True
411
- )
408
+ reconciled_prefix = await cls ._reconcile_prefix (
409
+ branch = branch , db = dbt , prefix = prefix , namespace_id = namespace_id , is_delete = True
410
+ )
412
411
ok = True
413
412
414
413
return DeleteResult (node = reconciled_prefix , mutation = cls (ok = ok ))
0 commit comments