mirror of
https://github.com/ansible/awx.git
synced 2026-02-22 05:30:18 -03:30
Set JT.organization with value from its project
Remove validation requiring JT.organization
Undo some of the additional org definitions in tests
Revert some tests no longer needed for feature
exclude workflow approvals from unified organization field
revert awxkit changes for providing organization
Roll back additional JT creation permission requirement
Fix up more issues by persisting organization field when project is removed
Restrict project org editing, logging, and testing
Grant removed inventory org admin permissions in migration
Add special validate_unique for job templates
this deals with enforcing name-organization uniqueness
Add back in special message where config is unknown
when receiving 403 on job relaunch
Fix logical and performance bugs with data migration
within JT.inventory.organization make-permission-explicit migration
remove nested loops so we do .iterator() on JT queryset
in reverse migration, carefully remove execute role on JT
held by org admins of inventory organization,
as well as the execute_role holders
Use current state of Role model in logic, with 1 notable exception
that is used to filter on ancestors
the ancestor and descentent relationship in the migration model
is not reliable
output of this is saved as an integer list to avoid future
compatibility errors
make the parents rebuilding logic skip over irrelevant models
this is the largest performance gain for small resource numbers
119 lines
4.2 KiB
Python
119 lines
4.2 KiB
Python
import json
|
|
|
|
from awxkit.api.mixins import HasCreate, HasNotifications, HasSurvey, HasCopy, DSAdapter
|
|
from awxkit.api.pages import Organization, UnifiedJobTemplate
|
|
from awxkit.utils import filter_by_class, not_provided, update_payload, random_title, suppress, PseudoNamespace
|
|
from awxkit.api.resources import resources
|
|
import awxkit.exceptions as exc
|
|
|
|
from . import base
|
|
from . import page
|
|
|
|
|
|
class WorkflowJobTemplate(HasCopy, HasCreate, HasNotifications, HasSurvey, UnifiedJobTemplate):
|
|
|
|
optional_dependencies = [Organization]
|
|
|
|
def launch(self, payload={}):
|
|
"""Launch using related->launch endpoint."""
|
|
# get related->launch
|
|
launch_pg = self.get_related('launch')
|
|
|
|
# launch the workflow_job_template
|
|
result = launch_pg.post(payload)
|
|
|
|
# return job
|
|
jobs_pg = self.related.workflow_jobs.get(id=result.workflow_job)
|
|
if jobs_pg.count != 1:
|
|
msg = "workflow_job_template launched (id:{}) but job not found in response at {}/workflow_jobs/" % \
|
|
(result.json['workflow_job'], self.url)
|
|
raise exc.UnexpectedAWXState(msg)
|
|
return jobs_pg.results[0]
|
|
|
|
def payload(self, **kwargs):
|
|
payload = PseudoNamespace(name=kwargs.get('name') or 'WorkflowJobTemplate - {}'.format(random_title()),
|
|
description=kwargs.get('description') or random_title(10))
|
|
|
|
optional_fields = (
|
|
"allow_simultaneous",
|
|
"ask_variables_on_launch",
|
|
"ask_inventory_on_launch",
|
|
"ask_scm_branch_on_launch",
|
|
"ask_limit_on_launch",
|
|
"limit",
|
|
"scm_branch",
|
|
"survey_enabled",
|
|
"webhook_service",
|
|
"webhook_credential",
|
|
)
|
|
update_payload(payload, optional_fields, kwargs)
|
|
|
|
extra_vars = kwargs.get('extra_vars', not_provided)
|
|
if extra_vars != not_provided:
|
|
if isinstance(extra_vars, dict):
|
|
extra_vars = json.dumps(extra_vars)
|
|
payload.update(extra_vars=extra_vars)
|
|
|
|
if kwargs.get('organization'):
|
|
payload.organization = kwargs.get('organization').id
|
|
|
|
if kwargs.get('inventory'):
|
|
payload.inventory = kwargs.get('inventory').id
|
|
|
|
if kwargs.get('webhook_credential'):
|
|
webhook_cred = kwargs.get('webhook_credential')
|
|
if isinstance(webhook_cred, int):
|
|
payload.update(webhook_credential=int(webhook_cred))
|
|
elif hasattr(webhook_cred, 'id'):
|
|
payload.update(webhook_credential=webhook_cred.id)
|
|
else:
|
|
raise AttributeError("Webhook credential must either be integer of pkid or Credential object")
|
|
|
|
return payload
|
|
|
|
def create_payload(self, name='', description='', organization=None, **kwargs):
|
|
self.create_and_update_dependencies(*filter_by_class((organization, Organization)))
|
|
organization = self.ds.organization if organization else None
|
|
payload = self.payload(name=name, description=description, organization=organization, **kwargs)
|
|
payload.ds = DSAdapter(self.__class__.__name__, self._dependency_store)
|
|
return payload
|
|
|
|
def create(self, name='', description='', organization=None, **kwargs):
|
|
payload = self.create_payload(name=name, description=description, organization=organization, **kwargs)
|
|
return self.update_identity(WorkflowJobTemplates(self.connection).post(payload))
|
|
|
|
def add_label(self, label):
|
|
if isinstance(label, page.Page):
|
|
label = label.json
|
|
with suppress(exc.NoContent):
|
|
self.related.labels.post(label)
|
|
|
|
|
|
page.register_page([resources.workflow_job_template,
|
|
(resources.workflow_job_templates, 'post'),
|
|
(resources.workflow_job_template_copy, 'post')], WorkflowJobTemplate)
|
|
|
|
|
|
class WorkflowJobTemplates(page.PageList, WorkflowJobTemplate):
|
|
|
|
pass
|
|
|
|
|
|
page.register_page([resources.workflow_job_templates], WorkflowJobTemplates)
|
|
|
|
|
|
class WorkflowJobTemplateLaunch(base.Base):
|
|
|
|
pass
|
|
|
|
|
|
page.register_page(resources.workflow_job_template_launch, WorkflowJobTemplateLaunch)
|
|
|
|
|
|
class WorkflowJobTemplateCopy(base.Base):
|
|
|
|
pass
|
|
|
|
|
|
page.register_page([resources.workflow_job_template_copy], WorkflowJobTemplateCopy)
|