Skip to content
Snippets Groups Projects
Commit 124fdb97 authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Add link to AWX job url

parent a8c9a750
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,7 @@ This module implements the models used in the app. ...@@ -12,6 +12,7 @@ This module implements the models used in the app.
import ipaddress import ipaddress
import string import string
import qrcode import qrcode
import urllib.parse
import sqlalchemy as sa import sqlalchemy as sa
from enum import Enum from enum import Enum
from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.ext.declarative import declared_attr
...@@ -969,6 +970,15 @@ class Task(db.Model): ...@@ -969,6 +970,15 @@ class Task(db.Model):
user_id = db.Column(db.Integer, db.ForeignKey('user_account.id'), user_id = db.Column(db.Integer, db.ForeignKey('user_account.id'),
nullable=False, default=utils.fetch_current_user_id) nullable=False, default=utils.fetch_current_user_id)
@property
def awx_job_url(self):
if self.awx_job_id is None:
return None
return urllib.parse.urljoin(
current_app.config['AWX_URL'],
f'/#/jobs/{self.awx_job_id}'
)
def __str__(self): def __str__(self):
return str(self.id) return str(self.id)
...@@ -980,6 +990,7 @@ class Task(db.Model): ...@@ -980,6 +990,7 @@ class Task(db.Model):
'ended_at': utils.format_field(self.ended_at), 'ended_at': utils.format_field(self.ended_at),
'status': self.status.name, 'status': self.status.name,
'awx_job_id': self.awx_job_id, 'awx_job_id': self.awx_job_id,
'awx_job_url': self.awx_job_url,
'command': self.command, 'command': self.command,
'user': str(self.user), 'user': str(self.user),
} }
......
...@@ -68,6 +68,7 @@ MAC_OUI = '02:42:42' ...@@ -68,6 +68,7 @@ MAC_OUI = '02:42:42'
DOCUMENTATION_URL = 'http://ics-infrastructure.pages.esss.lu.se/csentry/index.html' DOCUMENTATION_URL = 'http://ics-infrastructure.pages.esss.lu.se/csentry/index.html'
CSENTRY_STAGING = False CSENTRY_STAGING = False
AWX_URL = 'https://torn.tn.esss.lu.se'
# AWX job templates # AWX job templates
AWX_CORE_SERVICES_UPDATE = 'ics-ans-core @ DHCP test' AWX_CORE_SERVICES_UPDATE = 'ics-ans-core @ DHCP test'
AWX_CREATE_VM = 'ics-ans-deploy-proxmox-vm' AWX_CREATE_VM = 'ics-ans-deploy-proxmox-vm'
......
...@@ -12,18 +12,32 @@ $(document).ready(function() { ...@@ -12,18 +12,32 @@ $(document).ready(function() {
"pageLength": 20, "pageLength": 20,
"lengthMenu": [[20, 50, 100, -1], [20, 50, 100, "All"]], "lengthMenu": [[20, 50, 100, -1], [20, 50, 100, "All"]],
"order": [[2, 'desc']], "order": [[2, 'desc']],
"columnDefs": [ "columns": [
{ { data: 'id',
"targets": [0], render: function(data, type, row) {
"render": function(data, type, row) {
// render funtion to create link to Task view page // render funtion to create link to Task view page
if ( data === null ) { if ( data === null ) {
return data; return data;
} }
var url = $SCRIPT_ROOT + "/task/tasks/view/" + data; var url = $SCRIPT_ROOT + "/task/tasks/view/" + data;
return '<a href="'+ url + '">' + data + '</a>'; return '<a href="' + url + '">' + data + '</a>';
} }
} },
{ data: 'name' },
{ data: 'created_at' },
{ data: 'ended_at' },
{ data: 'status' },
{ data: null,
render: function(data, type, row) {
// render link to AWX job
if ( row.awx_job_id === null ) {
return null;
}
return '<a href="' + row.awx_job_url + '">' + row.awx_job_id + '</a>';
}
},
{ data: 'command' },
{ data: 'user' },
] ]
}); });
......
...@@ -32,5 +32,5 @@ def view_task(id_): ...@@ -32,5 +32,5 @@ def view_task(id_):
@bp.route('/_retrieve_tasks') @bp.route('/_retrieve_tasks')
@login_required @login_required
def retrieve_tasks(): def retrieve_tasks():
data = [list(task.to_dict().values()) for task in current_user.get_tasks()] data = [task.to_dict() for task in current_user.get_tasks()]
return jsonify(data=data) return jsonify(data=data)
...@@ -23,7 +23,11 @@ ...@@ -23,7 +23,11 @@
<dt class="col-sm-3">Status</dt> <dt class="col-sm-3">Status</dt>
<dd class="col-sm-9">{{ task.status.name }}</dd> <dd class="col-sm-9">{{ task.status.name }}</dd>
<dt class="col-sm-3">AWX job</dt> <dt class="col-sm-3">AWX job</dt>
{% if task.awx_job_id %}
<dd class="col-sm-9"><a href="{{ task.awx_job_url }}">{{ task.awx_job_id }}</a></dd>
{% else %}
<dd class="col-sm-9">{{ task.awx_job_id }}</dd> <dd class="col-sm-9">{{ task.awx_job_id }}</dd>
{% endif %}
<dt class="col-sm-3">Command</dt> <dt class="col-sm-3">Command</dt>
<dd class="col-sm-9">{{ task.command }}</dd> <dd class="col-sm-9">{{ task.command }}</dd>
<dt class="col-sm-3">User</dt> <dt class="col-sm-3">User</dt>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment