operations list of a concrete NS 26/6126/1
authorlombardof <flombardo@cnit.it>
Thu, 10 May 2018 23:07:01 +0000 (01:07 +0200)
committerlombardof <flombardo@cnit.it>
Thu, 10 May 2018 23:07:01 +0000 (01:07 +0200)
Change-Id: I053371f6e769f4a965aaf99fdabde38b42485b31
Signed-off-by: lombardof <flombardo@cnit.it>
instancehandler/template/instance_list.html
instancehandler/template/instance_operations_list.html [new file with mode: 0644]
instancehandler/template/modal/operation_show.html [new file with mode: 0644]
instancehandler/urls.py
instancehandler/views.py
lib/osm/osmclient/client.py
sf_t3d/settings.py
sf_t3d/templatetags/datetag.py [new file with mode: 0644]
static/src/instancehandler/instance_create.js
static/src/instancehandler/instance_operations_list.js [new file with mode: 0644]

index 54ac016..b2485c2 100644 (file)
                                             <ul class="dropdown-menu">
                                                 <li><a href="#" onclick="javascript:performAction('{% url 'projects:instances:action' instance_id=i|get:'_id' project_id=project_id type=type %}')">
                                                     <i class="fa fa-magic"></i>Exec NS Primitive</a></li>
-                                                <li><a href="#"> <i class="fa fa-list"></i>Active operations</a></li>
+                                                <li><a href="{% url 'projects:instances:ns_operations' project_id=project_id type=type instance_id=i|get:'_id'%}"> <i class="fa fa-list"></i>Active operations</a></li>
                                             </ul>
 
 
diff --git a/instancehandler/template/instance_operations_list.html b/instancehandler/template/instance_operations_list.html
new file mode 100644 (file)
index 0000000..4115e0d
--- /dev/null
@@ -0,0 +1,123 @@
+{% extends "base.html" %}
+{% load get %}
+{% load date_tag %}
+{% load staticfiles %}
+
+
+
+{% block head_block %}
+    {{ block.super }}
+    <!-- Codemirror core CSS -->
+    <link rel="stylesheet" href="/static/bower_components/codemirror/lib/codemirror.css">
+    <link rel="stylesheet" href="/static/bower_components/codemirror/addon/fold/foldgutter.css" />
+    <link rel="stylesheet" href="/static/bower_components/codemirror/theme/neat.css">
+    <link rel="stylesheet" href="/static/bower_components/codemirror/addon/dialog/dialog.css">
+    <link rel="stylesheet" href="/static/bower_components/codemirror/addon/display/fullscreen.css">
+    <link rel="stylesheet" href="/static/bower_components/select2/dist/css/select2.min.css">
+{% endblock %}
+{% block title_header_big %}
+    {{ block.super }}
+{% endblock %}
+{% block left_sidebar %}
+    {% include 'osm/osm_project_left_sidebar.html' %}
+{% endblock %}
+
+
+{% block breadcrumb_body %}
+    {{ block.super }}
+    <li><a href="{% url 'projects:instances:list' project_id=project_id type=type %}">Instances</a></li>
+{% endblock %}
+
+{% block content_body %}
+    {{ block.super }}
+    {% include 'modal/instance_create.html' %}
+    {% csrf_token %}
+    <div class="row">
+        <div class="col-md-12">
+
+            <div class="box">
+                <div class="box-header with-border">
+                    <h3 class="box-title">Active operations</h3>
+
+                </div>
+                <div class="box-body">
+                    <table id="instances_table" class="table table-bordered table-striped">
+                        <thead>
+                        <tr>
+                            <th>Id</th>
+                            <th>Type</th>
+                            <th>Operation State</th>
+                            <th>Start Time</th>
+                            <th>Status Entered Time</th>
+                            <th>Actions</th>
+                        </tr>
+                        </thead>
+                        <tbody>
+                        {% for i in operations %}
+                            <tr>
+
+                                <td>{{ i|get:"_id" }}</td>
+                                <td>{{ i|get:"lcmOperationType" }}</td>
+
+                                {% if i|get:"operationState" == 'FAILED' %}
+                                    <td><span class="label label-danger">{{ i|get:"operationState"  }}</span> </td>
+                                {% elif i|get:"operationState" == 'PROCESSING' %}
+                                     <td><span class="label label-warning">{{ i|get:"operationState"  }}</span> </td>
+                                {% elif i|get:"operationState" == 'COMPLETED' %}
+                                     <td><span class="label label-success">{{ i|get:"operationState"  }}</span> </td>
+                                {% else  %}
+                                    <td>{{ i|get:"operationState"  }}</td>
+                                {% endif %}
+
+                                <td >{{ i.startTime|get_date }}</td>
+                                <td >{{ i.statusEnteredTime|get_date }}</td>
+                                <td>
+                                    <div class="btn-group">
+                                        <button type="button" class="btn btn-default"
+                                                onclick="javascript:showOperationDetails('{% url 'projects:instances:ns_operation' op_id=i|get:'_id' instance_id=i|get:'nsInstanceId' project_id=project_id type=type %}')"
+                                                data-toggle="tooltip" data-placement="top" data-container="body" title="More Info"><i
+                                                class="fa fa-info"></i>
+                                        </button>
+
+
+                                    </div>
+
+                                </td>
+
+
+                            </tr>
+                        {% endfor %}
+                        </tbody>
+                    </table>
+                </div>
+            </div>
+        </div>
+
+    </div>
+    {% include 'modal/operation_show.html' %}
+{% endblock %}
+
+{% block resource_block %}
+    {{ block.super }}
+    <!-- Utility JS -->
+    <script src="/static/bower_components/select2/dist/js/select2.js"></script>
+    <script src="/static/bower_components/codemirror/lib/codemirror.js"></script>
+    <script src="/static/bower_components/codemirror/addon/fold/foldcode.js"></script>
+    <script src="/static/bower_components/codemirror/addon/fold/foldgutter.js"></script>
+    <script src="/static/bower_components/codemirror/addon/fold/brace-fold.js"></script>
+    <script src="/static/bower_components/codemirror/mode/javascript/javascript.js"></script>
+    <script src="/static/bower_components/codemirror/addon/search/searchcursor.js"></script>
+    <script src="/static/bower_components/codemirror/addon/search/search.js"></script>
+    <script src="/static/bower_components/codemirror/addon/dialog/dialog.js"></script>
+    <script src="/static/bower_components/codemirror/addon/display/autorefresh.js"></script>
+    <script src="/static/bower_components/codemirror/addon/edit/matchbrackets.js"></script>
+    <script src="/static/bower_components/codemirror/addon/edit/closebrackets.js"></script>
+    <script src="/static/bower_components/codemirror/addon/display/fullscreen.js"></script>
+    <script src="/static/bower_components/codemirror/keymap/sublime.js"></script>
+    <script src="/static/src/instancehandler/instance_operations_list.js"></script>
+
+{% endblock %}
+
+{% block footer %}
+    {% include "footer.html" %}
+{% endblock %}
diff --git a/instancehandler/template/modal/operation_show.html b/instancehandler/template/modal/operation_show.html
new file mode 100644 (file)
index 0000000..3c378de
--- /dev/null
@@ -0,0 +1,23 @@
+<div class="modal" id="modal_show_operation" xmlns="http://www.w3.org/1999/html">
+    <div   class="modal-dialog">
+        <div class="modal-content">
+            <div class="modal-header">
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                    <span aria-hidden="true">×</span></button>
+                <h4 class="modal-title" >Instance details</h4>
+            </div>
+
+            <div class="modal-body" id="modal_show_operation_body" >
+                <textarea id="operation_view_json">
+                </textarea>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Cancel</button>
+
+            </div>
+
+        </div>
+        <!-- /.modal-content -->
+    </div>
+    <!-- /.modal-dialog -->
+</div>
index b6a9e33..9474f1e 100644 (file)
@@ -21,7 +21,9 @@ urlpatterns = [
     url(r'^(?P<type>[ns|vnf]+)/list/', views.list, name='list'),
     url(r'^create/', views.create, name='create'),
     url(r'^(?P<type>[ns|vnf]+)/(?P<instance_id>[0-9a-z-]+)/delete$', views.delete, name='delete'),
-    url(r'^(?P<type>[ns|vnf]+)/(?P<instance_id>[0-9a-z-]+)/action', views.action, name='action'),
+    url(r'^(?P<type>[ns|vnf]+)/(?P<instance_id>[0-9a-z-]+)/action$', views.action, name='action'),
+    url(r'^(?P<type>[ns|vnf]+)/(?P<instance_id>[0-9a-z-]+)/operation$', views.ns_operations, name='ns_operations'),
+    url(r'^(?P<type>[ns|vnf]+)/(?P<instance_id>[0-9a-z-]+)/operation/(?P<op_id>[0-9a-z-]+)', views.ns_operation, name='ns_operation'),
     url(r'^(?P<type>[ns|vnf]+)/(?P<instance_id>[0-9a-z-]+)', views.show, name='show'),
 
 ]
index 534579a..e193825 100644 (file)
@@ -68,6 +68,17 @@ def create(request, project_id=None):
     result = client.ns_create(ns_data)
     return __response_handler(request, result, 'projects:instances:list', to_redirect=True, type='ns', project_id=project_id)
 
+@login_required
+def ns_operations(request, project_id=None, instance_id=None, type=None):
+    client = Client()
+    result = client.ns_op_list(instance_id)
+    return __response_handler(request, {'operations': result, 'type': 'ns', 'project_id': project_id}, 'instance_operations_list.html')
+
+@login_required
+def ns_operation(request, op_id, project_id=None, instance_id=None, type=None):
+    client = Client()
+    result = client.ns_op(op_id)
+    return __response_handler(request, result)
 
 @login_required
 def action(request, project_id=None, instance_id=None, type=None):
index 48c9815..0d38955 100644 (file)
@@ -235,6 +235,30 @@ class Client(object):
                                    json=action_payload)
         return None
 
+    def ns_op_list(self, id):
+        token = self.get_token()
+        headers = {}
+        if token:
+            headers['Authorization'] = 'Bearer {}'.format(token)
+            headers['Content-Type'] = 'application/json'
+            headers['accept'] = 'application/json'
+
+            _url = "{0}/nslcm/v1/ns_lcm_op_occs/?nsInstanceId={1}".format(self._base_path, id)
+            return self._send_get(_url, headers=headers)
+        return None
+
+    def ns_op(self, id):
+        token = self.get_token()
+        headers = {}
+        if token:
+            headers['Authorization'] = 'Bearer {}'.format(token)
+            headers['Content-Type'] = 'application/json'
+            headers['accept'] = 'application/json'
+
+            _url = "{0}/nslcm/v1/ns_lcm_op_occs/{1}".format(self._base_path, id)
+            return self._send_get(_url, headers=headers)
+        return None
+
     def vnfd_list(self):
         token = self.get_token()
         if token:
index cfd7a3e..619f4a2 100644 (file)
@@ -92,7 +92,7 @@ TEMPLATES = [
             ],
             'libraries':{
                 'get': 'sf_t3d.templatetags.get',
-
+                'date_tag': 'sf_t3d.templatetags.datetag',
             }
         },
     },
diff --git a/sf_t3d/templatetags/datetag.py b/sf_t3d/templatetags/datetag.py
new file mode 100644 (file)
index 0000000..04a5917
--- /dev/null
@@ -0,0 +1,33 @@
+#
+#   Copyright 2018 CNIT - Consorzio Nazionale Interuniversitario per le Telecomunicazioni
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an  BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+
+from django import template
+import time
+register = template.Library()
+
+
+'''
+    Custom template filter handle timestamp
+'''
+
+
+# TODO add configurable date format
+@register.filter
+def get_date(timestamp):
+    if isinstance(timestamp, float):
+        return time.strftime("%d-%m-%Y %H:%M:%S", time.gmtime(timestamp))
+    return '-'
+
index 55fb512..b09aa5b 100644 (file)
@@ -20,6 +20,7 @@ function openModalCreateNS(args) {
     // load vim account list
     select2_groups = $('#vimAccountId').select2({
         placeholder: 'Select VIM',
+        width: '100%',
         ajax: {
             url: args.vim_list_url,
             dataType: 'json',
diff --git a/static/src/instancehandler/instance_operations_list.js b/static/src/instancehandler/instance_operations_list.js
new file mode 100644 (file)
index 0000000..705fce2
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+   Copyright 2018 CNIT - Consorzio Nazionale Interuniversitario per le Telecomunicazioni
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an  BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+*/
+
+
+function showOperationDetails(url_info) {
+    var dialog = bootbox.dialog({
+        message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
+        closeButton: true
+    });
+    $.ajax({
+        url: url_info,
+        type: 'GET',
+        dataType: "json",
+        contentType: "application/json;charset=utf-8",
+        success: function (result) {
+            editorJSON.setValue(JSON.stringify(result, null, "\t"));
+            editorJSON.setOption("autoRefresh", true);
+            dialog.modal('hide');
+            $('#modal_show_operation').modal('show');
+        },
+        error: function (result) {
+            dialog.modal('hide');
+            bootbox.alert("An error occurred while retrieving the information for the NS");
+        }
+    });
+}
+
+var editorJSON;
+
+$(document).ready(function () {
+    var json_editor_settings = {
+        mode: "javascript",
+        showCursorWhenSelecting: true,
+        autofocus: true,
+        lineNumbers: true,
+        lineWrapping: true,
+        foldGutter: true,
+        gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
+        autoCloseBrackets: true,
+        matchBrackets: true,
+        extraKeys: {
+            "F11": function (cm) {
+                cm.setOption("fullScreen", !cm.getOption("fullScreen"));
+            },
+            "Esc": function (cm) {
+                if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
+            },
+            "Ctrl-Q": function (cm) {
+                cm.foldCode(cm.getCursor());
+            }
+        },
+        theme: "neat",
+        keyMap: "sublime"
+    };
+    var myJsonTextArea = document.getElementById("operation_view_json");
+    editorJSON = CodeMirror(function (elt) {
+        myJsonTextArea.parentNode.replaceChild(elt, myJsonTextArea);
+    }, json_editor_settings);
+
+
+});
\ No newline at end of file