Add booking communication reference implementation 27/26727/1
authormaxbr <maxbr@mi.fu-berlin.de>
Thu, 5 Jan 2017 11:38:00 +0000 (12:38 +0100)
committermaxbr <maxbr@mi.fu-berlin.de>
Thu, 5 Jan 2017 11:38:00 +0000 (12:38 +0100)
JIRA: PHAROS-265

This adds an implementation of a booking communication agent that
listens for booking notifications from the dashboard and updates the pod
status in the dashboard.

Change-Id: I1ea22390a46182a185df9c5e1771c9312d462092
Signed-off-by: maxbr <maxbr@mi.fu-berlin.de>
12 files changed:
tools/pharos-dashboard/__init__.py [new file with mode: 0644]
tools/pharos-dashboard/booking_communication_agent.py [new file with mode: 0644]
tools/pharos-dashboard/src/account/migrations/0001_initial.py
tools/pharos-dashboard/src/account/migrations/0002_auto_20161005_1201.py [deleted file]
tools/pharos-dashboard/src/booking/migrations/0001_initial.py
tools/pharos-dashboard/src/booking/migrations/0002_auto_20161005_1202.py [deleted file]
tools/pharos-dashboard/src/dashboard/admin.py
tools/pharos-dashboard/src/dashboard/migrations/0001_initial.py
tools/pharos-dashboard/src/dashboard/migrations/0002_auto_20161005_1202.py [deleted file]
tools/pharos-dashboard/src/dashboard/models.py
tools/pharos-dashboard/src/jenkins/migrations/0001_initial.py
tools/pharos-dashboard/src/templates/dashboard/resource_detail.html

diff --git a/tools/pharos-dashboard/__init__.py b/tools/pharos-dashboard/__init__.py
new file mode 100644 (file)
index 0000000..ce1acf3
--- /dev/null
@@ -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 (file)
index 0000000..c52e98b
--- /dev/null
@@ -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()
index 8db05cb..591f702 100644 (file)
@@ -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 (file)
index 33d2cc5..0000000
+++ /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),
-        ),
-    ]
index 1fbd59a..6932dae 100644 (file)
@@ -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 (file)
index 05684f0..0000000
+++ /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'),
-        ),
-    ]
index a1463a7..56ac169 100644 (file)
@@ -14,3 +14,4 @@ from dashboard.models import *
 
 admin.site.register(Resource)
 admin.site.register(Server)
+admin.site.register(ResourceStatus)
index ee054d3..aaf3945 100644 (file)
@@ -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,12 +26,26 @@ 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=[
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 (file)
index e47c3b1..0000000
+++ /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),
-        ),
-    ]
index ec6fec7..4f3ac95 100644 (file)
@@ -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)
index f44c89a..b1c7889 100644 (file)
@@ -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',
index e0b29bd..740dd25 100644 (file)
             </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">
             </div>
         </div>
     </div>
-</div>
\ No newline at end of file
+</div>