Skip to content

Commit

Permalink
Make proper use of service_id
Browse files Browse the repository at this point in the history
Signed-off-by: Rick Elrod <[email protected]>
  • Loading branch information
relrod committed Aug 8, 2024
1 parent fb9bc88 commit 96399fa
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,20 @@ def sync_to_resource_server(instance, action, ansible_id=None):
body = ResourceRequestBody(
resource_type=resource_type.name,
ansible_id=ansible_id,
service_id=instance.resource.service_id,
resource_data=data,
)

try:
if action == "create":
client.create_resource(body)
response = client.create_resource(body)
json = response.json()
if isinstance(json, dict): # Mainly for tests... to avoid getting here with mock
instance.resource.service_id = json['service_id']
instance.resource.save()
elif action == "update":
client.update_resource(ansible_id, body)
elif action == "delete":
client.delete_resource(ansible_id)
except Exception as e:
logger.exception(f"Failed to sync {action} of resource {ansible_id} to resource server: {e}")
logger.exception(f"Failed to sync {action} of resource {instance} ({ansible_id}) to resource server: {e}")
raise ValidationError(_("Failed to sync resource to resource server")) from e

0 comments on commit 96399fa

Please sign in to comment.