diff options
12 files changed, 144 insertions, 97 deletions
diff --git a/tools/pharos-dashboard/__init__.py b/tools/pharos-dashboard/__init__.py new file mode 100644 index 00000000..ce1acf36 --- /dev/null +++ b/tools/pharos-dashboard/__init__.py @@ -0,0 +1,8 @@ +############################################################################## +# Copyright (c) 2016 Max Breitenfeldt and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +##############################################################################
\ No newline at end of file diff --git a/tools/pharos-dashboard/booking_communication_agent.py b/tools/pharos-dashboard/booking_communication_agent.py new file mode 100644 index 00000000..c52e98bd --- /dev/null +++ b/tools/pharos-dashboard/booking_communication_agent.py @@ -0,0 +1,42 @@ +from dashboard_notification.notification import Notification +from dashboard_api.api import DashboardAPI + +CONFIG = { + 'dashboard_ip': '127.0.0.1', + 'dashboard_url': 'http://127.0.0.1', + 'api_token': 'f33ff43c85ecb13f5d0632c05dbb0a7d85a5a8d1', + 'user': 'opnfv', + 'password': 'opnfvopnfv' +} + +api = DashboardAPI(CONFIG['dashboard_url'], api_token=CONFIG['api_token'], verbose=True) + + +def booking_start(message): + content = message.content + booking = api.get_booking(id=content['booking_id']) + + # do something here... + + # notify dashboard + api.post_resource_status(resource_id=booking['resource_id'], type='info', title='pod setup', + content='details') + + +def booking_end(message): + # do something here... + + # notify dashboard + api.post_resource_status(resource_id=message.content['resource_id'], type='info', + title='booking end', content='details') + + +def main(): + with Notification(CONFIG['dashboard_ip'], CONFIG['user'], CONFIG['password']) as notification: + notification.register(booking_start, 'Arm POD 2', 'booking_start') + notification.register(booking_end, 'Arm POD 2', 'booking_end') + notification.receive() # wait for notifications + + +if __name__ == "__main__": + main() diff --git a/tools/pharos-dashboard/src/account/migrations/0001_initial.py b/tools/pharos-dashboard/src/account/migrations/0001_initial.py index 8db05cb4..591f7024 100644 --- a/tools/pharos-dashboard/src/account/migrations/0001_initial.py +++ b/tools/pharos-dashboard/src/account/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.10 on 2016-09-23 11:36 +# Generated by Django 1.10 on 2016-11-03 13:33 from __future__ import unicode_literals import account.models @@ -27,6 +27,8 @@ class Migration(migrations.Migration): ('company', models.CharField(max_length=200)), ('oauth_token', models.CharField(max_length=1024)), ('oauth_secret', models.CharField(max_length=1024)), + ('jira_url', models.CharField(default='', max_length=100)), + ('full_name', models.CharField(default='', max_length=100)), ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), ], options={ diff --git a/tools/pharos-dashboard/src/account/migrations/0002_auto_20161005_1201.py b/tools/pharos-dashboard/src/account/migrations/0002_auto_20161005_1201.py deleted file mode 100644 index 33d2cc54..00000000 --- a/tools/pharos-dashboard/src/account/migrations/0002_auto_20161005_1201.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10 on 2016-10-05 12:01 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('account', '0001_initial'), - ] - - operations = [ - migrations.AddField( - model_name='userprofile', - name='full_name', - field=models.CharField(default='', max_length=100), - ), - migrations.AddField( - model_name='userprofile', - name='jira_url', - field=models.CharField(default='', max_length=100), - ), - ] diff --git a/tools/pharos-dashboard/src/booking/migrations/0001_initial.py b/tools/pharos-dashboard/src/booking/migrations/0001_initial.py index 1fbd59af..6932daea 100644 --- a/tools/pharos-dashboard/src/booking/migrations/0001_initial.py +++ b/tools/pharos-dashboard/src/booking/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.10 on 2016-09-23 11:36 +# Generated by Django 1.10 on 2016-11-03 13:33 from __future__ import unicode_literals from django.conf import settings @@ -12,8 +12,8 @@ class Migration(migrations.Migration): initial = True dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), ('dashboard', '0001_initial'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), ] operations = [ @@ -26,11 +26,43 @@ class Migration(migrations.Migration): ('jira_issue_id', models.IntegerField(null=True)), ('jira_issue_status', models.CharField(max_length=50)), ('purpose', models.CharField(max_length=300)), - ('resource', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='dashboard.Resource')), - ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), ], options={ 'db_table': 'booking', }, ), + migrations.CreateModel( + name='Installer', + fields=[ + ('id', models.AutoField(primary_key=True, serialize=False)), + ('name', models.CharField(max_length=30)), + ], + ), + migrations.CreateModel( + name='Scenario', + fields=[ + ('id', models.AutoField(primary_key=True, serialize=False)), + ('name', models.CharField(max_length=300)), + ], + ), + migrations.AddField( + model_name='booking', + name='installer', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='booking.Installer'), + ), + migrations.AddField( + model_name='booking', + name='resource', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='dashboard.Resource'), + ), + migrations.AddField( + model_name='booking', + name='scenario', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='booking.Scenario'), + ), + migrations.AddField( + model_name='booking', + name='user', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), + ), ] diff --git a/tools/pharos-dashboard/src/booking/migrations/0002_auto_20161005_1202.py b/tools/pharos-dashboard/src/booking/migrations/0002_auto_20161005_1202.py deleted file mode 100644 index 05684f0b..00000000 --- a/tools/pharos-dashboard/src/booking/migrations/0002_auto_20161005_1202.py +++ /dev/null @@ -1,40 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10 on 2016-10-05 12:02 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('booking', '0001_initial'), - ] - - operations = [ - migrations.CreateModel( - name='Installer', - fields=[ - ('id', models.AutoField(primary_key=True, serialize=False)), - ('name', models.CharField(max_length=30)), - ], - ), - migrations.CreateModel( - name='Scenario', - fields=[ - ('id', models.AutoField(primary_key=True, serialize=False)), - ('name', models.CharField(max_length=300)), - ], - ), - migrations.AddField( - model_name='booking', - name='installer', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='booking.Installer'), - ), - migrations.AddField( - model_name='booking', - name='scenario', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='booking.Scenario'), - ), - ] diff --git a/tools/pharos-dashboard/src/dashboard/admin.py b/tools/pharos-dashboard/src/dashboard/admin.py index a1463a7a..56ac1693 100644 --- a/tools/pharos-dashboard/src/dashboard/admin.py +++ b/tools/pharos-dashboard/src/dashboard/admin.py @@ -14,3 +14,4 @@ from dashboard.models import * admin.site.register(Resource) admin.site.register(Server) +admin.site.register(ResourceStatus) diff --git a/tools/pharos-dashboard/src/dashboard/migrations/0001_initial.py b/tools/pharos-dashboard/src/dashboard/migrations/0001_initial.py index ee054d37..aaf3945f 100644 --- a/tools/pharos-dashboard/src/dashboard/migrations/0001_initial.py +++ b/tools/pharos-dashboard/src/dashboard/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.10 on 2016-09-23 11:36 +# Generated by Django 1.10 on 2016-11-03 13:33 from __future__ import unicode_literals from django.conf import settings @@ -12,8 +12,8 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ('jenkins', '0001_initial'), migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('jenkins', '0001_initial'), ] operations = [ @@ -26,13 +26,27 @@ class Migration(migrations.Migration): ('url', models.CharField(blank=True, max_length=100, null=True)), ('owner', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='user_lab_owner', to=settings.AUTH_USER_MODEL)), ('slave', models.ForeignKey(null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='jenkins.JenkinsSlave')), - ('vpn_users', models.ManyToManyField(related_name='user_vpn_users', to=settings.AUTH_USER_MODEL)), + ('vpn_users', models.ManyToManyField(blank=True, related_name='user_vpn_users', to=settings.AUTH_USER_MODEL)), ], options={ 'db_table': 'resource', }, ), migrations.CreateModel( + name='ResourceStatus', + fields=[ + ('id', models.AutoField(primary_key=True, serialize=False)), + ('timestamp', models.DateTimeField(auto_now_add=True)), + ('type', models.CharField(max_length=20)), + ('title', models.CharField(max_length=50)), + ('content', models.CharField(max_length=5000)), + ('resource', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.Resource')), + ], + options={ + 'db_table': 'resource_status', + }, + ), + migrations.CreateModel( name='Server', fields=[ ('id', models.AutoField(primary_key=True, serialize=False)), diff --git a/tools/pharos-dashboard/src/dashboard/migrations/0002_auto_20161005_1202.py b/tools/pharos-dashboard/src/dashboard/migrations/0002_auto_20161005_1202.py deleted file mode 100644 index e47c3b13..00000000 --- a/tools/pharos-dashboard/src/dashboard/migrations/0002_auto_20161005_1202.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10 on 2016-10-05 12:02 -from __future__ import unicode_literals - -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('dashboard', '0001_initial'), - ] - - operations = [ - migrations.AlterField( - model_name='resource', - name='vpn_users', - field=models.ManyToManyField(blank=True, related_name='user_vpn_users', to=settings.AUTH_USER_MODEL), - ), - ] diff --git a/tools/pharos-dashboard/src/dashboard/models.py b/tools/pharos-dashboard/src/dashboard/models.py index ec6fec76..4f3ac95c 100644 --- a/tools/pharos-dashboard/src/dashboard/models.py +++ b/tools/pharos-dashboard/src/dashboard/models.py @@ -64,7 +64,6 @@ class Resource(models.Model): def __str__(self): return self.name - class Server(models.Model): id = models.AutoField(primary_key=True) resource = models.ForeignKey(Resource, on_delete=models.CASCADE) @@ -79,3 +78,17 @@ class Server(models.Model): def __str__(self): return self.name + +class ResourceStatus(models.Model): + id = models.AutoField(primary_key=True) + resource = models.ForeignKey(Resource, on_delete=models.CASCADE) + timestamp = models.DateTimeField(auto_now_add=True) + type = models.CharField(max_length=20) + title = models.CharField(max_length=50) + content = models.CharField(max_length=5000) + + class Meta: + db_table = 'resource_status' + + def __str__(self): + return self.resource.name + ': ' + self.title + ' ' + str(self.timestamp) diff --git a/tools/pharos-dashboard/src/jenkins/migrations/0001_initial.py b/tools/pharos-dashboard/src/jenkins/migrations/0001_initial.py index f44c89a0..b1c78897 100644 --- a/tools/pharos-dashboard/src/jenkins/migrations/0001_initial.py +++ b/tools/pharos-dashboard/src/jenkins/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.10 on 2016-09-23 11:36 +# Generated by Django 1.10 on 2016-11-03 13:33 from __future__ import unicode_literals from django.db import migrations, models @@ -30,6 +30,7 @@ class Migration(migrations.Migration): ('last_job_branch', models.CharField(default='', max_length=50)), ('last_job_installer', models.CharField(default='', max_length=50)), ('last_job_result', models.CharField(default='', max_length=30)), + ('active', models.BooleanField(default=False)), ], options={ 'db_table': 'jenkins_slave', diff --git a/tools/pharos-dashboard/src/templates/dashboard/resource_detail.html b/tools/pharos-dashboard/src/templates/dashboard/resource_detail.html index e0b29bd9..740dd259 100644 --- a/tools/pharos-dashboard/src/templates/dashboard/resource_detail.html +++ b/tools/pharos-dashboard/src/templates/dashboard/resource_detail.html @@ -26,6 +26,26 @@ </div> </div> </div> + + <div class="col-lg-9"> + <div class="panel panel-default"> + <div class="panel-heading"> + Status + </div> + <div class="panel-body"> + <div class="list-group pre-scrollable"> + {% for status in resource.resourcestatus_set.all %} + <a href="#" class="list-group-item"> + <i class="fa fa-info fa-fw"></i> {{ status.title }} + <span class="pull-right text-muted small"> + <em>{{ status.timestamp }}</em> + </span> + </a> + {% endfor %} + </div> + </div> + </div> + </div> <div class="col-lg-9"> <div class="panel panel-default"> <div class="panel-heading"> @@ -182,4 +202,4 @@ </div> </div> </div> -</div>
\ No newline at end of file +</div> |