mirror of
https://github.com/ansible/awx.git
synced 2026-01-15 20:00:43 -03:30
Implement tower ui view url on models
This commit is contained in:
parent
b88892be49
commit
75ef0dd395
@ -268,6 +268,7 @@ class ApiV1ConfigView(APIView):
|
||||
# If the license is valid, write it to disk.
|
||||
if license_data['valid_key']:
|
||||
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)
|
||||
# as appropriate, based on whether the license uses it.
|
||||
@ -3053,8 +3054,8 @@ class NotifierTest(GenericAPIView):
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
obj = self.get_object()
|
||||
notification = obj.generate_notification("Tower Notification Test {}".format(obj.id),
|
||||
{"body": "Ansible Tower Test Notification {}".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, tower_settings.TOWER_URL_BASE)})
|
||||
if not notification:
|
||||
return Response({}, status=status.HTTP_400_BAD_REQUEST)
|
||||
else:
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
import hmac
|
||||
import json
|
||||
import logging
|
||||
from urlparse import urljoin
|
||||
|
||||
# Django
|
||||
from django.conf import settings
|
||||
@ -139,6 +140,9 @@ class AdHocCommand(UnifiedJob):
|
||||
def get_absolute_url(self):
|
||||
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
|
||||
def task_auth_token(self):
|
||||
'''Return temporary auth token used for task requests via API.'''
|
||||
|
||||
@ -6,6 +6,7 @@ import datetime
|
||||
import logging
|
||||
import re
|
||||
import copy
|
||||
from urlparse import urljoin
|
||||
|
||||
# Django
|
||||
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.notifications import Notifier
|
||||
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']
|
||||
|
||||
@ -1249,6 +1251,9 @@ class InventoryUpdate(UnifiedJob, InventorySourceOptions):
|
||||
def get_absolute_url(self):
|
||||
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):
|
||||
if type(obj) == InventoryUpdate:
|
||||
if self.inventory_source.inventory == obj.inventory_source.inventory:
|
||||
|
||||
@ -6,6 +6,7 @@ import hmac
|
||||
import json
|
||||
import yaml
|
||||
import logging
|
||||
from urlparse import urljoin
|
||||
|
||||
# Django
|
||||
from django.conf import settings
|
||||
@ -380,6 +381,9 @@ class Job(UnifiedJob, JobOptions):
|
||||
def get_absolute_url(self):
|
||||
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
|
||||
def task_auth_token(self):
|
||||
'''Return temporary auth token used for task requests via API.'''
|
||||
@ -1096,6 +1100,9 @@ class SystemJob(UnifiedJob, SystemJobOptions):
|
||||
def get_absolute_url(self):
|
||||
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):
|
||||
return True
|
||||
|
||||
|
||||
@ -24,6 +24,7 @@ from awx.main.models.jobs import Job
|
||||
from awx.main.models.notifications import Notifier
|
||||
from awx.main.models.unified_jobs import * # noqa
|
||||
from awx.main.utils import update_scm_url
|
||||
from awx.main.conf import tower_settings
|
||||
|
||||
__all__ = ['Project', 'ProjectUpdate']
|
||||
|
||||
@ -389,6 +390,9 @@ class ProjectUpdate(UnifiedJob, ProjectOptions):
|
||||
def get_absolute_url(self):
|
||||
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):
|
||||
parent_instance = self._get_parent_instance()
|
||||
if parent_instance:
|
||||
|
||||
@ -484,6 +484,13 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
||||
else:
|
||||
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
|
||||
def _get_task_class(cls):
|
||||
raise NotImplementedError # Implement in subclasses.
|
||||
@ -734,7 +741,7 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
||||
def notification_data(self):
|
||||
return dict(id=self.id,
|
||||
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),
|
||||
started=self.started.isoformat(),
|
||||
finished=self.finished.isoformat(),
|
||||
|
||||
@ -228,11 +228,11 @@ def handle_work_success(self, result, task_actual):
|
||||
friendly_name = "AdHoc Command"
|
||||
else:
|
||||
return
|
||||
notification_subject = "{} #{} '{}' succeeded on Ansible Tower".format(friendly_name,
|
||||
task_actual['id'],
|
||||
instance_name)
|
||||
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)
|
||||
for n in notifiers.get('success', []) + notifiers.get('any', [])],
|
||||
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)
|
||||
instance.save()
|
||||
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_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
|
||||
send_notifications.delay([n.generate_notification(notification_subject, notification_body).id
|
||||
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_URL_BASE = "https://towerhost"
|
||||
|
||||
TOWER_SETTINGS_MANIFEST = {
|
||||
"SCHEDULE_MAX_JOBS": {
|
||||
"name": "Maximum Scheduled Jobs",
|
||||
@ -819,6 +821,13 @@ TOWER_SETTINGS_MANIFEST = {
|
||||
"type": "bool",
|
||||
"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": {
|
||||
"name": "Tower License",
|
||||
"description": "Controls what features and functionality is enabled in Tower.",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user