mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 09:57:35 -02:30
Changes to get execution environments factories working (#8126)
This commit is contained in:
committed by
Shane McDonald
parent
b7209d1694
commit
9530c6ca50
@@ -1,11 +1,12 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from awxkit.api.mixins import HasCreate
|
from awxkit.api.mixins import DSAdapter, HasCreate
|
||||||
from awxkit.api.pages import (
|
from awxkit.api.pages import (
|
||||||
Credential,
|
Credential,
|
||||||
Organization,
|
Organization,
|
||||||
)
|
)
|
||||||
from awxkit.api.resources import resources
|
from awxkit.api.resources import resources
|
||||||
|
from awxkit.utils import random_title, PseudoNamespace
|
||||||
|
|
||||||
from . import base
|
from . import base
|
||||||
from . import page
|
from . import page
|
||||||
@@ -19,6 +20,29 @@ class ExecutionEnvironment(HasCreate, base.Base):
|
|||||||
dependencies = [Organization, Credential]
|
dependencies = [Organization, Credential]
|
||||||
NATURAL_KEY = ('organization', 'image')
|
NATURAL_KEY = ('organization', 'image')
|
||||||
|
|
||||||
|
# fields are image, organization, managed_by_tower, credential
|
||||||
|
def create(self, image='quay.io/ansible/ansible-runner:devel', credential=None, **kwargs):
|
||||||
|
# we do not want to make a credential by default
|
||||||
|
payload = self.create_payload(image=image, credential=credential, **kwargs)
|
||||||
|
ret = self.update_identity(ExecutionEnvironments(self.connection).post(payload))
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def create_payload(self, organization=Organization, **kwargs):
|
||||||
|
self.create_and_update_dependencies(organization)
|
||||||
|
payload = self.payload(organization=self.ds.organization, **kwargs)
|
||||||
|
payload.ds = DSAdapter(self.__class__.__name__, self._dependency_store)
|
||||||
|
return payload
|
||||||
|
|
||||||
|
def payload(self, image=None, organization=None, credential=None, **kwargs):
|
||||||
|
payload = PseudoNamespace(
|
||||||
|
image=image or random_title(10),
|
||||||
|
organization=organization.id if organization else None,
|
||||||
|
credential=credential.id if credential else None,
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
|
|
||||||
|
return payload
|
||||||
|
|
||||||
|
|
||||||
page.register_page([resources.execution_environment,
|
page.register_page([resources.execution_environment,
|
||||||
(resources.execution_environments, 'post'),
|
(resources.execution_environments, 'post'),
|
||||||
|
|||||||
@@ -101,18 +101,17 @@ class JobTemplate(
|
|||||||
|
|
||||||
if kwargs.get('project'):
|
if kwargs.get('project'):
|
||||||
payload.update(project=kwargs.get('project').id, playbook=playbook)
|
payload.update(project=kwargs.get('project').id, playbook=playbook)
|
||||||
if kwargs.get('inventory'):
|
|
||||||
payload.update(inventory=kwargs.get('inventory').id)
|
for fk_field in ('inventory', 'credential', 'webhook_credential', 'execution_environment'):
|
||||||
if kwargs.get('credential'):
|
rel_obj = kwargs.get(fk_field)
|
||||||
payload.update(credential=kwargs.get('credential').id)
|
if rel_obj is None:
|
||||||
if kwargs.get('webhook_credential'):
|
continue
|
||||||
webhook_cred = kwargs.get('webhook_credential')
|
elif isinstance(rel_obj, int):
|
||||||
if isinstance(webhook_cred, int):
|
payload.update(**{fk_field: int(rel_obj)})
|
||||||
payload.update(webhook_credential=int(webhook_cred))
|
elif hasattr(rel_obj, 'id'):
|
||||||
elif hasattr(webhook_cred, 'id'):
|
payload.update(**{fk_field: rel_obj.id})
|
||||||
payload.update(webhook_credential=webhook_cred.id)
|
|
||||||
else:
|
else:
|
||||||
raise AttributeError("Webhook credential must either be integer of pkid or Credential object")
|
raise AttributeError(f'Related field {fk_field} must be either integer of pkid or object')
|
||||||
|
|
||||||
return payload
|
return payload
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user