mirror of
https://github.com/ansible/awx.git
synced 2026-02-17 19:20:05 -03:30
refactor payload construction for awxkit
This fixes container_group creation to allow passing "is_container_group" and "credential" to the "create" method on instance groups, and refactors other page objects to use a common utility function to eliminate copy-pasted code
This commit is contained in:
@@ -319,6 +319,23 @@ def update_payload(payload, fields, kwargs):
|
||||
return payload
|
||||
|
||||
|
||||
def set_payload_foreign_key_args(payload, fk_fields, kwargs):
|
||||
if isinstance(fk_fields, str):
|
||||
fk_fields = (fk_fields,)
|
||||
|
||||
for fk_field in fk_fields:
|
||||
rel_obj = kwargs.get(fk_field)
|
||||
if rel_obj is None:
|
||||
continue
|
||||
elif isinstance(rel_obj, int):
|
||||
payload.update(**{fk_field: int(rel_obj)})
|
||||
elif hasattr(rel_obj, 'id'):
|
||||
payload.update(**{fk_field: rel_obj.id})
|
||||
else:
|
||||
raise AttributeError(f'Related field {fk_field} must be either integer of pkid or object')
|
||||
return payload
|
||||
|
||||
|
||||
def to_str(obj):
|
||||
if isinstance(obj, bytes):
|
||||
return obj.decode('utf-8')
|
||||
|
||||
Reference in New Issue
Block a user