mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 01:17:37 -02:30
Implement tower ui view url on models
This commit is contained in:
@@ -268,6 +268,7 @@ class ApiV1ConfigView(APIView):
|
|||||||
# If the license is valid, write it to disk.
|
# If the license is valid, write it to disk.
|
||||||
if license_data['valid_key']:
|
if license_data['valid_key']:
|
||||||
tower_settings.LICENSE = data_actual
|
tower_settings.LICENSE = data_actual
|
||||||
|
tower_settings.TOWER_URL_BASE = "{}://{}".format(request.scheme, request.get_host())
|
||||||
|
|
||||||
# Spawn a task to ensure that MongoDB is started (or stopped)
|
# Spawn a task to ensure that MongoDB is started (or stopped)
|
||||||
# as appropriate, based on whether the license uses it.
|
# as appropriate, based on whether the license uses it.
|
||||||
@@ -3053,8 +3054,8 @@ class NotifierTest(GenericAPIView):
|
|||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
obj = self.get_object()
|
obj = self.get_object()
|
||||||
notification = obj.generate_notification("Tower Notification Test {}".format(obj.id),
|
notification = obj.generate_notification("Tower Notification Test {} {}".format(obj.id, tower_settings.TOWER_URL_BASE),
|
||||||
{"body": "Ansible Tower Test Notification {}".format(obj.id)})
|
{"body": "Ansible Tower Test Notification {} {}".format(obj.id, tower_settings.TOWER_URL_BASE)})
|
||||||
if not notification:
|
if not notification:
|
||||||
return Response({}, status=status.HTTP_400_BAD_REQUEST)
|
return Response({}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
import hmac
|
import hmac
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
from urlparse import urljoin
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@@ -139,6 +140,9 @@ class AdHocCommand(UnifiedJob):
|
|||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse('api:ad_hoc_command_detail', args=(self.pk,))
|
return reverse('api:ad_hoc_command_detail', args=(self.pk,))
|
||||||
|
|
||||||
|
def get_ui_url(self):
|
||||||
|
return urljoin(tower_settings.TOWER_URL_BASE, "/#/ad_hoc_commands/{}".format(self.pk))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def task_auth_token(self):
|
def task_auth_token(self):
|
||||||
'''Return temporary auth token used for task requests via API.'''
|
'''Return temporary auth token used for task requests via API.'''
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import datetime
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import copy
|
import copy
|
||||||
|
from urlparse import urljoin
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@@ -25,6 +26,7 @@ from awx.main.models.jobs import Job
|
|||||||
from awx.main.models.unified_jobs import * # noqa
|
from awx.main.models.unified_jobs import * # noqa
|
||||||
from awx.main.models.notifications import Notifier
|
from awx.main.models.notifications import Notifier
|
||||||
from awx.main.utils import ignore_inventory_computed_fields, _inventory_updates
|
from awx.main.utils import ignore_inventory_computed_fields, _inventory_updates
|
||||||
|
from awx.main.conf import tower_settings
|
||||||
|
|
||||||
__all__ = ['Inventory', 'Host', 'Group', 'InventorySource', 'InventoryUpdate', 'CustomInventoryScript']
|
__all__ = ['Inventory', 'Host', 'Group', 'InventorySource', 'InventoryUpdate', 'CustomInventoryScript']
|
||||||
|
|
||||||
@@ -1249,6 +1251,9 @@ class InventoryUpdate(UnifiedJob, InventorySourceOptions):
|
|||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse('api:inventory_update_detail', args=(self.pk,))
|
return reverse('api:inventory_update_detail', args=(self.pk,))
|
||||||
|
|
||||||
|
def get_ui_url(self):
|
||||||
|
return urljoin(tower_settings.TOWER_URL_BASE, "/#/inventory_sync/{}".format(self.pk))
|
||||||
|
|
||||||
def is_blocked_by(self, obj):
|
def is_blocked_by(self, obj):
|
||||||
if type(obj) == InventoryUpdate:
|
if type(obj) == InventoryUpdate:
|
||||||
if self.inventory_source.inventory == obj.inventory_source.inventory:
|
if self.inventory_source.inventory == obj.inventory_source.inventory:
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import hmac
|
|||||||
import json
|
import json
|
||||||
import yaml
|
import yaml
|
||||||
import logging
|
import logging
|
||||||
|
from urlparse import urljoin
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@@ -380,6 +381,9 @@ class Job(UnifiedJob, JobOptions):
|
|||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse('api:job_detail', args=(self.pk,))
|
return reverse('api:job_detail', args=(self.pk,))
|
||||||
|
|
||||||
|
def get_ui_url(self):
|
||||||
|
return urljoin(tower_settings.TOWER_URL_BASE, "/#/jobs/{}".format(self.pk))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def task_auth_token(self):
|
def task_auth_token(self):
|
||||||
'''Return temporary auth token used for task requests via API.'''
|
'''Return temporary auth token used for task requests via API.'''
|
||||||
@@ -1096,6 +1100,9 @@ class SystemJob(UnifiedJob, SystemJobOptions):
|
|||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse('api:system_job_detail', args=(self.pk,))
|
return reverse('api:system_job_detail', args=(self.pk,))
|
||||||
|
|
||||||
|
def get_ui_url(self):
|
||||||
|
return urljoin(tower_settings.TOWER_URL_BASE, "/#/management_jobs/{}".format(self.pk))
|
||||||
|
|
||||||
def is_blocked_by(self, obj):
|
def is_blocked_by(self, obj):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ from awx.main.models.jobs import Job
|
|||||||
from awx.main.models.notifications import Notifier
|
from awx.main.models.notifications import Notifier
|
||||||
from awx.main.models.unified_jobs import * # noqa
|
from awx.main.models.unified_jobs import * # noqa
|
||||||
from awx.main.utils import update_scm_url
|
from awx.main.utils import update_scm_url
|
||||||
|
from awx.main.conf import tower_settings
|
||||||
|
|
||||||
__all__ = ['Project', 'ProjectUpdate']
|
__all__ = ['Project', 'ProjectUpdate']
|
||||||
|
|
||||||
@@ -389,6 +390,9 @@ class ProjectUpdate(UnifiedJob, ProjectOptions):
|
|||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse('api:project_update_detail', args=(self.pk,))
|
return reverse('api:project_update_detail', args=(self.pk,))
|
||||||
|
|
||||||
|
def get_ui_url(self):
|
||||||
|
return urlparse.urljoin(tower_settings.TOWER_URL_BASE, "/#/scm_update/{}".format(self.pk))
|
||||||
|
|
||||||
def _update_parent_instance(self):
|
def _update_parent_instance(self):
|
||||||
parent_instance = self._get_parent_instance()
|
parent_instance = self._get_parent_instance()
|
||||||
if parent_instance:
|
if parent_instance:
|
||||||
|
|||||||
@@ -484,6 +484,13 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
|||||||
else:
|
else:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
def get_ui_url(self):
|
||||||
|
real_instance = self.get_real_instance()
|
||||||
|
if real_instance != self:
|
||||||
|
return real_instance.get_ui_url()
|
||||||
|
else:
|
||||||
|
return ''
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _get_task_class(cls):
|
def _get_task_class(cls):
|
||||||
raise NotImplementedError # Implement in subclasses.
|
raise NotImplementedError # Implement in subclasses.
|
||||||
@@ -734,7 +741,7 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
|||||||
def notification_data(self):
|
def notification_data(self):
|
||||||
return dict(id=self.id,
|
return dict(id=self.id,
|
||||||
name=self.name,
|
name=self.name,
|
||||||
url=self.get_absolute_url(), #TODO: Need to replace with UI job view
|
url=self.get_ui_url(),
|
||||||
created_by=str(self.created_by),
|
created_by=str(self.created_by),
|
||||||
started=self.started.isoformat(),
|
started=self.started.isoformat(),
|
||||||
finished=self.finished.isoformat(),
|
finished=self.finished.isoformat(),
|
||||||
|
|||||||
@@ -228,11 +228,11 @@ def handle_work_success(self, result, task_actual):
|
|||||||
friendly_name = "AdHoc Command"
|
friendly_name = "AdHoc Command"
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
notification_subject = "{} #{} '{}' succeeded on Ansible Tower".format(friendly_name,
|
|
||||||
task_actual['id'],
|
|
||||||
instance_name)
|
|
||||||
notification_body = instance.notification_data()
|
notification_body = instance.notification_data()
|
||||||
notification_body['friendly_name'] = friendly_name
|
notification_subject = "{} #{} '{}' succeeded on Ansible Tower: {}".format(friendly_name,
|
||||||
|
task_actual['id'],
|
||||||
|
instance_name,
|
||||||
|
notification_body['url'])
|
||||||
send_notifications.delay([n.generate_notification(notification_subject, notification_body)
|
send_notifications.delay([n.generate_notification(notification_subject, notification_body)
|
||||||
for n in notifiers.get('success', []) + notifiers.get('any', [])],
|
for n in notifiers.get('success', []) + notifiers.get('any', [])],
|
||||||
job_id=task_actual['id'])
|
job_id=task_actual['id'])
|
||||||
@@ -284,10 +284,11 @@ def handle_work_error(self, task_id, subtasks=None):
|
|||||||
(first_task_type, first_task_name, first_task_id)
|
(first_task_type, first_task_name, first_task_id)
|
||||||
instance.save()
|
instance.save()
|
||||||
instance.socketio_emit_status("failed")
|
instance.socketio_emit_status("failed")
|
||||||
notification_subject = "{} #{} '{}' failed on Ansible Tower".format(first_task_friendly_name,
|
|
||||||
first_task_id,
|
|
||||||
first_task_name)
|
|
||||||
notification_body = first_task.notification_data()
|
notification_body = first_task.notification_data()
|
||||||
|
notification_subject = "{} #{} '{}' failed on Ansible Tower: {}".format(first_task_friendly_name,
|
||||||
|
first_task_id,
|
||||||
|
first_task_name,
|
||||||
|
notification_body['url'])
|
||||||
notification_body['friendly_name'] = first_task_friendly_name
|
notification_body['friendly_name'] = first_task_friendly_name
|
||||||
send_notifications.delay([n.generate_notification(notification_subject, notification_body).id
|
send_notifications.delay([n.generate_notification(notification_subject, notification_body).id
|
||||||
for n in notifiers.get('error', []) + notifiers.get('any', [])],
|
for n in notifiers.get('error', []) + notifiers.get('any', [])],
|
||||||
|
|||||||
@@ -685,6 +685,8 @@ ORG_ADMINS_CAN_SEE_ALL_USERS = True
|
|||||||
|
|
||||||
TOWER_ADMIN_ALERTS = True
|
TOWER_ADMIN_ALERTS = True
|
||||||
|
|
||||||
|
TOWER_URL_BASE = "https://towerhost"
|
||||||
|
|
||||||
TOWER_SETTINGS_MANIFEST = {
|
TOWER_SETTINGS_MANIFEST = {
|
||||||
"SCHEDULE_MAX_JOBS": {
|
"SCHEDULE_MAX_JOBS": {
|
||||||
"name": "Maximum Scheduled Jobs",
|
"name": "Maximum Scheduled Jobs",
|
||||||
@@ -819,6 +821,13 @@ TOWER_SETTINGS_MANIFEST = {
|
|||||||
"type": "bool",
|
"type": "bool",
|
||||||
"category": "system",
|
"category": "system",
|
||||||
},
|
},
|
||||||
|
"TOWER_URL_BASE": {
|
||||||
|
"name": "Base URL of the Tower host",
|
||||||
|
"description": "This is used by services like Notifications to render a valid url to the Tower host",
|
||||||
|
"default": TOWER_URL_BASE,
|
||||||
|
"type": "string",
|
||||||
|
"category": "system",
|
||||||
|
},
|
||||||
"LICENSE": {
|
"LICENSE": {
|
||||||
"name": "Tower License",
|
"name": "Tower License",
|
||||||
"description": "Controls what features and functionality is enabled in Tower.",
|
"description": "Controls what features and functionality is enabled in Tower.",
|
||||||
|
|||||||
Reference in New Issue
Block a user