From 74ed51abc7bbaee0474367fe9be134d47394889c Mon Sep 17 00:00:00 2001 From: lombardof Date: Fri, 11 May 2018 01:07:01 +0200 Subject: [PATCH] operations list of a concrete NS Change-Id: I053371f6e769f4a965aaf99fdabde38b42485b31 Signed-off-by: lombardof --- instancehandler/template/instance_list.html | 2 +- .../template/instance_operations_list.html | 123 ++++++++++++++++++ .../template/modal/operation_show.html | 23 ++++ instancehandler/urls.py | 4 +- instancehandler/views.py | 11 ++ lib/osm/osmclient/client.py | 24 ++++ sf_t3d/settings.py | 2 +- sf_t3d/templatetags/datetag.py | 33 +++++ static/src/instancehandler/instance_create.js | 1 + .../instance_operations_list.js | 74 +++++++++++ 10 files changed, 294 insertions(+), 3 deletions(-) create mode 100644 instancehandler/template/instance_operations_list.html create mode 100644 instancehandler/template/modal/operation_show.html create mode 100644 sf_t3d/templatetags/datetag.py create mode 100644 static/src/instancehandler/instance_operations_list.js diff --git a/instancehandler/template/instance_list.html b/instancehandler/template/instance_list.html index 54ac016..b2485c2 100644 --- a/instancehandler/template/instance_list.html +++ b/instancehandler/template/instance_list.html @@ -109,7 +109,7 @@ diff --git a/instancehandler/template/instance_operations_list.html b/instancehandler/template/instance_operations_list.html new file mode 100644 index 0000000..4115e0d --- /dev/null +++ b/instancehandler/template/instance_operations_list.html @@ -0,0 +1,123 @@ +{% extends "base.html" %} +{% load get %} +{% load date_tag %} +{% load staticfiles %} + + + +{% block head_block %} + {{ block.super }} + + + + + + + +{% endblock %} +{% block title_header_big %} + {{ block.super }} +{% endblock %} +{% block left_sidebar %} + {% include 'osm/osm_project_left_sidebar.html' %} +{% endblock %} + + +{% block breadcrumb_body %} + {{ block.super }} +
  • Instances
  • +{% endblock %} + +{% block content_body %} + {{ block.super }} + {% include 'modal/instance_create.html' %} + {% csrf_token %} +
    +
    + +
    +
    +

    Active operations

    + +
    +
    + + + + + + + + + + + + + {% for i in operations %} + + + + + + {% if i|get:"operationState" == 'FAILED' %} + + {% elif i|get:"operationState" == 'PROCESSING' %} + + {% elif i|get:"operationState" == 'COMPLETED' %} + + {% else %} + + {% endif %} + + + + + + + + {% endfor %} + +
    IdTypeOperation StateStart TimeStatus Entered TimeActions
    {{ i|get:"_id" }}{{ i|get:"lcmOperationType" }}{{ i|get:"operationState" }} {{ i|get:"operationState" }} {{ i|get:"operationState" }} {{ i|get:"operationState" }}{{ i.startTime|get_date }}{{ i.statusEnteredTime|get_date }} +
    + + + +
    + +
    +
    +
    +
    + +
    + {% include 'modal/operation_show.html' %} +{% endblock %} + +{% block resource_block %} + {{ block.super }} + + + + + + + + + + + + + + + + + +{% 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 index 0000000..3c378de --- /dev/null +++ b/instancehandler/template/modal/operation_show.html @@ -0,0 +1,23 @@ + diff --git a/instancehandler/urls.py b/instancehandler/urls.py index b6a9e33..9474f1e 100644 --- a/instancehandler/urls.py +++ b/instancehandler/urls.py @@ -21,7 +21,9 @@ urlpatterns = [ url(r'^(?P[ns|vnf]+)/list/', views.list, name='list'), url(r'^create/', views.create, name='create'), url(r'^(?P[ns|vnf]+)/(?P[0-9a-z-]+)/delete$', views.delete, name='delete'), - url(r'^(?P[ns|vnf]+)/(?P[0-9a-z-]+)/action', views.action, name='action'), + url(r'^(?P[ns|vnf]+)/(?P[0-9a-z-]+)/action$', views.action, name='action'), + url(r'^(?P[ns|vnf]+)/(?P[0-9a-z-]+)/operation$', views.ns_operations, name='ns_operations'), + url(r'^(?P[ns|vnf]+)/(?P[0-9a-z-]+)/operation/(?P[0-9a-z-]+)', views.ns_operation, name='ns_operation'), url(r'^(?P[ns|vnf]+)/(?P[0-9a-z-]+)', views.show, name='show'), ] diff --git a/instancehandler/views.py b/instancehandler/views.py index 534579a..e193825 100644 --- a/instancehandler/views.py +++ b/instancehandler/views.py @@ -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): diff --git a/lib/osm/osmclient/client.py b/lib/osm/osmclient/client.py index 48c9815..0d38955 100644 --- a/lib/osm/osmclient/client.py +++ b/lib/osm/osmclient/client.py @@ -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: diff --git a/sf_t3d/settings.py b/sf_t3d/settings.py index cfd7a3e..619f4a2 100644 --- a/sf_t3d/settings.py +++ b/sf_t3d/settings.py @@ -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 index 0000000..04a5917 --- /dev/null +++ b/sf_t3d/templatetags/datetag.py @@ -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 '-' + diff --git a/static/src/instancehandler/instance_create.js b/static/src/instancehandler/instance_create.js index 55fb512..b09aa5b 100644 --- a/static/src/instancehandler/instance_create.js +++ b/static/src/instancehandler/instance_create.js @@ -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 index 0000000..705fce2 --- /dev/null +++ b/static/src/instancehandler/instance_operations_list.js @@ -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: '
    Loading...
    ', + 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 -- 2.25.1