mirror of
https://github.com/ansible/awx.git
synced 2026-03-16 16:37:30 -02:30
Initial (editable) pass of adding JT.organization
This is the old version of this feature from 2019 this allows setting the organization in the data sent to the API when creating a JT, and exposes the field in the UI as well Subsequent commit changes the field from editable to read-only, but as of this commit, the machinery is not hooked up to infer it from project
This commit is contained in:
@@ -7,7 +7,7 @@ from awxkit.utils import (
|
||||
suppress,
|
||||
update_payload,
|
||||
PseudoNamespace)
|
||||
from awxkit.api.pages import Credential, Inventory, Project, UnifiedJobTemplate
|
||||
from awxkit.api.pages import Credential, Inventory, Project, UnifiedJobTemplate, Organization
|
||||
from awxkit.api.mixins import HasCreate, HasInstanceGroups, HasNotifications, HasSurvey, HasCopy, DSAdapter
|
||||
from awxkit.api.resources import resources
|
||||
import awxkit.exceptions as exc
|
||||
@@ -23,7 +23,7 @@ class JobTemplate(
|
||||
HasSurvey,
|
||||
UnifiedJobTemplate):
|
||||
|
||||
optional_dependencies = [Inventory, Credential, Project]
|
||||
optional_dependencies = [Organization, Inventory, Credential, Project]
|
||||
|
||||
def launch(self, payload={}):
|
||||
"""Launch the job_template using related->launch endpoint."""
|
||||
@@ -129,6 +129,7 @@ class JobTemplate(
|
||||
playbook='ping.yml',
|
||||
credential=Credential,
|
||||
inventory=Inventory,
|
||||
organization=Organization,
|
||||
project=None,
|
||||
**kwargs):
|
||||
if not project:
|
||||
@@ -148,12 +149,18 @@ class JobTemplate(
|
||||
project = self.ds.project if project else None
|
||||
inventory = self.ds.inventory if inventory else None
|
||||
credential = self.ds.credential if credential else None
|
||||
# if the created project has an organization, and the parameters
|
||||
# specified no organization, then borrow the one from the project
|
||||
if hasattr(project.ds, 'organization') and organization is Organization:
|
||||
self.ds.organization = project.ds.organization
|
||||
organization = self.ds.organization
|
||||
|
||||
payload = self.payload(
|
||||
name=name,
|
||||
description=description,
|
||||
job_type=job_type,
|
||||
playbook=playbook,
|
||||
organization=organization,
|
||||
credential=credential,
|
||||
inventory=inventory,
|
||||
project=project,
|
||||
@@ -169,11 +176,12 @@ class JobTemplate(
|
||||
playbook='ping.yml',
|
||||
credential=Credential,
|
||||
inventory=Inventory,
|
||||
organization=Organization,
|
||||
project=None,
|
||||
**kwargs):
|
||||
payload, credential = self.create_payload(name=name, description=description, job_type=job_type,
|
||||
playbook=playbook, credential=credential, inventory=inventory,
|
||||
project=project, **kwargs)
|
||||
project=project, organization=organization, **kwargs)
|
||||
ret = self.update_identity(
|
||||
JobTemplates(
|
||||
self.connection).post(payload))
|
||||
|
||||
@@ -12,7 +12,7 @@ from . import page
|
||||
|
||||
class WorkflowJobTemplate(HasCopy, HasCreate, HasNotifications, HasSurvey, UnifiedJobTemplate):
|
||||
|
||||
optional_dependencies = [Organization]
|
||||
dependencies = [Organization]
|
||||
|
||||
def launch(self, payload={}):
|
||||
"""Launch using related->launch endpoint."""
|
||||
@@ -71,14 +71,14 @@ class WorkflowJobTemplate(HasCopy, HasCreate, HasNotifications, HasSurvey, Unifi
|
||||
|
||||
return payload
|
||||
|
||||
def create_payload(self, name='', description='', organization=None, **kwargs):
|
||||
def create_payload(self, name='', description='', organization=Organization, **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):
|
||||
def create(self, name='', description='', organization=Organization, **kwargs):
|
||||
payload = self.create_payload(name=name, description=description, organization=organization, **kwargs)
|
||||
return self.update_identity(WorkflowJobTemplates(self.connection).post(payload))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user