partial integration with master branch 43/6343/2
authorlombardofr <lombardo@everyup.it>
Mon, 18 Jun 2018 17:35:59 +0000 (19:35 +0200)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Thu, 19 Jul 2018 12:11:04 +0000 (13:11 +0100)
Change-Id: I07e6266b021f038712d74a0af67a45e012753e34
Signed-off-by: lombardofr <lombardo@everyup.it>
instancehandler/template/instance_list.html
instancehandler/template/instance_list_ns.html
instancehandler/urls.py
instancehandler/views.py
lib/osm/osmclient/client.py
static/src/instancehandler/instance_list.js
template/login.html

index ff76215..9baae4c 100644 (file)
@@ -47,6 +47,8 @@
     {% include 'modal/instance_create.html' %}
     {% include 'modal/instance_show.html' %}
     {% include 'modal/instance_new_action.html' %}
+    {% include 'modal/instance_new_alarm.html' %}
+    {% include 'modal/instance_export_metric.html' %}
 {% endblock %}
 
 {% block resource_block %}
index 7743043..dd84d47 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>
+                                    <i class="fa fa-magic"></i> Exec NS Primitive</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>
+                                        <i class="fa fa-list"></i> Active operations</a></li>
+                                <li class="divider"></li>
+                                <li><a href="#"
+                                       onclick="javascript:newAlarmNs('{% url 'projects:instances:ns_create_alarm' instance_id=i|get:'_id' project_id=project_id type=type %}')">
+                                    <i class="far fa-bell"></i> New Alarm</a></li>
+                                <li><a href="#"
+                                       onclick="javascript:exportMetricNs('{% url 'projects:instances:ns_export_metric' instance_id=i|get:'_id' project_id=project_id type=type %}')">
+                                    <i class="far fa-chart-bar"></i> Export metric</a></li>
                                 <li class="divider"></li>
                                 <li>
                                     <a href="javascript:deleteNs('{% url 'projects:instances:delete' instance_id=i|get:'_id' project_id=project_id type=type %}', true)">
-                                        <i class="far fa-trash-alt" style="color:red" ></i>Force delete</a></li>
+                                        <i class="far fa-trash-alt" style="color:red" ></i> Force delete</a></li>
                             </ul>
 
 
index 9474f1e..054c3ba 100644 (file)
@@ -24,6 +24,8 @@ urlpatterns = [
     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-]+)/monitoring/alarm$', views.create_alarm, name='ns_create_alarm'),
+    url(r'^(?P<type>[ns|vnf]+)/(?P<instance_id>[0-9a-z-]+)/monitoring/metric$', views.export_metric, name='ns_export_metric'),
     url(r'^(?P<type>[ns|vnf]+)/(?P<instance_id>[0-9a-z-]+)', views.show, name='show'),
 
 ]
index c9808d6..d835de6 100644 (file)
@@ -123,6 +123,47 @@ def show(request, project_id=None, instance_id=None, type=None):
     print result
     return __response_handler(request, result)
 
+@login_required
+def export_metric(request, project_id=None, instance_id=None, type=None):
+
+    metric_data = request.POST.dict()
+
+    client = Client()
+    keys = ["collection_period",
+            "vnf_member_index",
+            "metric_name",
+            "correlation_id",
+            "vdu_name",
+            "collection_unit"]
+    metric_data = dict(filter(lambda i: i[0] in keys and len(i[1]) > 0, metric_data.items()))
+
+    response = client.ns_metric_export(instance_id, metric_data)
+
+    return __response_handler(request, {}, None, to_redirect=False,
+                              status=response.status_code)
+
+@login_required
+def create_alarm(request, project_id=None, instance_id=None, type=None):
+    metric_data = request.POST.dict()
+    print metric_data
+    client = Client()
+
+
+    keys = ["threshold_value",
+            "vnf_member_index",
+            "metric_name",
+            "vdu_name",
+            "alarm_name",
+            "correlation_id",
+            "statistic",
+            "operation",
+            "severity"]
+    metric_data = dict(filter(lambda i: i[0] in keys and len(i[1]) > 0, metric_data.items()))
+
+    result = client.ns_alarm_create(instance_id, metric_data)
+    return __response_handler(request, {}, None, to_redirect=False,
+                              status=result['status'] if 'status' in result else None)
+
 
 def __response_handler(request, data_res, url=None, to_redirect=None, *args, **kwargs):
     raw_content_types = request.META.get('HTTP_ACCEPT', '*/*').split(',')
@@ -132,3 +173,5 @@ def __response_handler(request, data_res, url=None, to_redirect=None, *args, **k
         return redirect(url, *args, **kwargs)
     else:
         return render(request, url, data_res)
+
+
index c8b2856..e9248ec 100644 (file)
@@ -14,7 +14,7 @@ log = logging.getLogger('helper.py')
 
 
 class Client(object):
-    def __init__(self, host=os.getenv('OSM_SERVER', "localhost"), so_port=9999, so_project='admin', **kwargs):
+    def __init__(self, host=os.getenv('OSM_SERVER', "localhost"), so_port=9999, so_project='admin', ro_host=None, ro_port=9090, **kwargs):
 
         self._user = 'admin'
         self._password = 'admin'
@@ -77,7 +77,6 @@ class Client(object):
                                   json=vim_data)
         return None
 
-
     def sdn_list(self):
         token = self.get_token()
         if token:
@@ -302,6 +301,33 @@ class Client(object):
             return self._send_get(_url, headers=headers)
         return None
 
+    def ns_alarm_create(self, id, alarm_payload):
+        token = self.get_token()
+        headers = {}
+        if token:
+            headers['Authorization'] = 'Bearer {}'.format(token)
+            headers['Content-Type'] = 'application/json'
+#            headers['accept'] = 'application/json'
+
+            _url = "{0}/test/message/alarm_request".format(self._base_path)
+            return self._send_post(_url, headers=headers, json=alarm_payload)
+        return None
+
+    def ns_metric_export(self, id, metric_payload):
+
+        token = self.get_token()
+        headers = {}
+        if token:
+            headers['Authorization'] = 'Bearer {}'.format(token)
+            headers['Content-Type'] = 'application/json'
+            #headers['accept'] = 'application/json'
+            print "DIO"
+            _url = "{0}/test/message/metric_request".format(self._base_path)
+            print _url
+            return self._send_post(_url, headers=headers, json=metric_payload)
+        return None
+
+
     def vnfd_list(self):
         token = self.get_token()
         if token:
@@ -416,7 +442,12 @@ class Client(object):
             log.exception(e)
             #print "Exception during send POST"
             return {'error': 'error during connection to agent'}
-        return Util.json_loads_byteified(r.text)
+        if 'accept' in kwargs['headers']:
+            accept = kwargs['headers']['accept']
+            if accept == 'application/json':
+                #print "json"
+                return Util.json_loads_byteified(r.text)
+        return r
 
     def _send_put(self, url, data=None, json=None, **kwargs):
         try:
index 47d4957..b4c0edc 100644 (file)
@@ -19,6 +19,17 @@ function performAction(url) {
     $('#modal_instance_new_action').modal('show');
 }
 
+function exportMetricNs(url) {
+    console.log(url)
+    $("#formExportMetricNS").attr("action", url);
+    $('#modal_instance_export_metric').modal('show');
+}
+
+function newAlarmNs(url) {
+    $("#formAlarmNS").attr("action", url);
+    $('#modal_instance_new_alarm').modal('show');
+}
+
 function deleteNs(url, force) {
     bootbox.confirm("Are you sure want to delete?", function (result) {
         if (result) {
@@ -141,4 +152,68 @@ $(document).ready(function () {
         });
     });
 
+    $("#formAlarmNS").submit(function (event) {
+        event.preventDefault(); //prevent default action
+        var post_url = $(this).attr("action"); //get form action url
+        var request_method = $(this).attr("method"); //get form GET/POST method
+        var form_data = new FormData(this); //Encode form elements for submission
+        console.log(post_url);
+        $.ajax({
+            url: post_url,
+            type: request_method,
+            data: form_data,
+            headers: {
+                "Accept": 'application/json'
+            },
+            contentType: false,
+            processData: false
+        }).done(function (response,textStatus, jqXHR) {
+            $('#modal_instance_new_action').modal('hide');
+            bootbox.alert({
+                    title: "Metric",
+                    message: "Alarm created."
+                });
+        }).fail(function(result){
+            var data  = result.responseJSON;
+            var title = "Error " + (data.code ? data.code: 'unknown');
+                var message = data.detail ? data.detail: 'No detail available.';
+                bootbox.alert({
+                    title: title,
+                    message: message
+                });
+        });
+    });
+
+    $("#formExportMetricNS").submit(function (event) {
+        event.preventDefault(); //prevent default action
+        var post_url = $(this).attr("action"); //get form action url
+        var request_method = $(this).attr("method"); //get form GET/POST method
+        var form_data = new FormData(this); //Encode form elements for submission
+        console.log(post_url);
+        $.ajax({
+            url: post_url,
+            type: request_method,
+            data: form_data,
+            headers: {
+                "Accept": 'application/json'
+            },
+            contentType: false,
+            processData: false
+        }).done(function (response,textStatus, jqXHR) {
+            $('#modal_instance_new_action').modal('hide');
+            bootbox.alert({
+                    title: "Metric",
+                    message: "Metric exported."
+                });
+        }).fail(function(result){
+            var data  = result.responseJSON;
+            var title = "Error " + (data.code ? data.code: 'unknown');
+                var message = data.detail ? data.detail: 'No detail available.';
+                bootbox.alert({
+                    title: title,
+                    message: message
+                });
+        });
+    });
+
 });
\ No newline at end of file
index 01019a4..2323200 100644 (file)
                 <input type="password" name="password" class="form-control" placeholder="Password">
                 <span class="glyphicon glyphicon-lock form-control-feedback"></span>
             </div>
-            <div class="form-group has-feedback">
-                <input name="project_id" class="form-control" placeholder="Project">
-                <span class="glyphicon glyphicon-lock form-control-feedback"></span>
-            </div>
             <div class="row">
                 <div class="col-xs-8">