From: maxbr Date: Mon, 12 Sep 2016 09:18:10 +0000 (+0200) Subject: Add info to the resource view X-Git-Tag: 6.0.0~136 X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=commitdiff_plain;h=167ed9ae59ded96d526b421c932b41554465f9eb;p=pharos.git Add info to the resource view JIRA: PHAROS-266 This adds a panel containing lab owner contact information, jenkins utilization timerange options and a table containing vpn users of a pod to the resource view. Change-Id: If991c74d3c93cd08f622771acc048ab998e16c48 Signed-off-by: maxbr --- diff --git a/tools/pharos-dashboard/booking/models.py b/tools/pharos-dashboard/booking/models.py index 4be8ccab..e772fb5b 100644 --- a/tools/pharos-dashboard/booking/models.py +++ b/tools/pharos-dashboard/booking/models.py @@ -1,10 +1,10 @@ from django.contrib.auth.models import User from django.db import models from jira import JIRA +from jira import JIRAError from dashboard.models import Resource -from pharos_dashboard import settings - +from django.conf import settings class Booking(models.Model): id = models.AutoField(primary_key=True) @@ -13,6 +13,7 @@ class Booking(models.Model): start = models.DateTimeField() end = models.DateTimeField() jira_issue_id = models.IntegerField(null=True) + jira_issue_status = models.CharField(max_length=50) purpose = models.CharField(max_length=300, blank=False) @@ -20,9 +21,13 @@ class Booking(models.Model): db_table = 'booking' def get_jira_issue(self): - jira = JIRA(server=settings.JIRA_URL, basic_auth=(settings.JIRA_USER_NAME, settings.JIRA_USER_PASSWORD)) - issue = jira.issue(self.jira_issue_id) - return issue + try: + jira = JIRA(server=settings.JIRA_URL, + basic_auth=(settings.JIRA_USER_NAME, settings.JIRA_USER_PASSWORD)) + issue = jira.issue(self.jira_issue_id) + return issue + except JIRAError: + return None def authorization_test(self): """ diff --git a/tools/pharos-dashboard/booking/urls.py b/tools/pharos-dashboard/booking/urls.py index f6429daa..bdcd52d4 100644 --- a/tools/pharos-dashboard/booking/urls.py +++ b/tools/pharos-dashboard/booking/urls.py @@ -21,6 +21,7 @@ urlpatterns = [ url(r'^(?P[0-9]+)/$', BookingFormView.as_view(), name='create'), url(r'^(?P[0-9]+)/bookings_json/$', ResourceBookingsJSON.as_view(), name='bookings_json'), + url(r'^detail/$', BookingView.as_view(), name='detail_prefix'), url(r'^detail/(?P[0-9]+)/$', BookingView.as_view(), name='detail'), ] diff --git a/tools/pharos-dashboard/booking/views.py b/tools/pharos-dashboard/booking/views.py index fde8d816..d0b2aefe 100644 --- a/tools/pharos-dashboard/booking/views.py +++ b/tools/pharos-dashboard/booking/views.py @@ -1,9 +1,13 @@ +from datetime import timedelta + +from django.conf import settings from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin from django.http import JsonResponse from django.shortcuts import get_object_or_404 from django.shortcuts import redirect from django.urls import reverse +from django.utils import timezone from django.views import View from django.views.generic import FormView from django.views.generic import TemplateView @@ -67,7 +71,8 @@ class BookingFormView(LoginRequiredMixin, FormView): messages.add_message(self.request, messages.ERROR, err) return super(BookingFormView, self).form_invalid(form) try: - create_jira_ticket(user, booking) + if settings.CREATE_JIRA_TICKET: + create_jira_ticket(user, booking) except JIRAError: messages.add_message(self.request, messages.ERROR, 'Failed to create Jira Ticket. ' 'Please check your Jira ' @@ -93,5 +98,6 @@ class BookingView(TemplateView): class ResourceBookingsJSON(View): def get(self, request, *args, **kwargs): resource = get_object_or_404(Resource, id=self.kwargs['resource_id']) - bookings = resource.booking_set.get_queryset().values('id', 'start', 'end', 'purpose') - return JsonResponse({'bookings': list(bookings)}) + bookings = resource.booking_set.get_queryset().values('id', 'start', 'end', 'purpose', + 'jira_issue_status') + return JsonResponse({'bookings': list(bookings)}) \ No newline at end of file diff --git a/tools/pharos-dashboard/dashboard/views.py b/tools/pharos-dashboard/dashboard/views.py index c34a7a57..0eddc130 100644 --- a/tools/pharos-dashboard/dashboard/views.py +++ b/tools/pharos-dashboard/dashboard/views.py @@ -1,7 +1,9 @@ from datetime import timedelta +from django.http import JsonResponse from django.shortcuts import get_object_or_404 from django.utils import timezone +from django.views import View from django.views.generic import TemplateView from booking.models import Booking @@ -104,3 +106,28 @@ class BookingUtilizationJSON(View): }, ] return JsonResponse({'data': utilization}) + + +class JenkinsUtilizationJSON(View): + def get(self, request, *args, **kwargs): + resource = get_object_or_404(Resource, id=kwargs['resource_id']) + weeks = int(kwargs['weeks']) + utilization = resource.slave.get_utilization(timedelta(weeks=weeks)) + utilization = [ + { + 'label': 'Offline', + 'data': utilization['offline'], + 'color': '#d9534f' + }, + { + 'label': 'Online', + 'data': utilization['online'], + 'color': '#5cb85c' + }, + { + 'label': 'Idle', + 'data': utilization['idle'], + 'color': '#5bc0de' + }, + ] + return JsonResponse({'data': utilization}) diff --git a/tools/pharos-dashboard/templates/dashboard/resource_detail.html b/tools/pharos-dashboard/templates/dashboard/resource_detail.html index 904fecd4..6067e1ea 100644 --- a/tools/pharos-dashboard/templates/dashboard/resource_detail.html +++ b/tools/pharos-dashboard/templates/dashboard/resource_detail.html @@ -1,12 +1,27 @@ +{% load jenkins_filters %} +
- Utilization + Jenkins Utilization +
+
+ +
+
-
+
@@ -78,19 +93,92 @@
- - \ No newline at end of file +
+
+
+
+ Contact +
+
+

+ Lab Owner: + {{ resource.owner.username }} +

+

+ Email: +

+

+ + Booking + + + OPNFV Wiki + +

+
+
+
+
+
+
+ Jenkins Status +
+
+

+ Slave Name: + {{ resource.slave.name }} +

+

+ Status: + {{ resource.slave.status }} +

+

+ Last Job: + + {{ resource.slave.last_job_name }} + +

+
+
+
+
+
+
+ VPN Users +
+
+
+ + + + + + + + + + {% for user in resource.vpn_users.all %} + + + + + + {% endfor %} +
UserEmailCompany
+ {{ user.username }} + + {{ user.email }} + + {{ user.userprofile.company }} +
+ +
+
+
+
+
\ No newline at end of file