ssh-key and config in NS create modal 90/6090/1
authorlombardof <flombardo@cnit.it>
Wed, 9 May 2018 08:46:49 +0000 (10:46 +0200)
committerlombardof <flombardo@cnit.it>
Wed, 9 May 2018 08:46:49 +0000 (10:46 +0200)
Change-Id: Id03b474f0b07d8819c9fefa346221a6c6fc61cc8
Signed-off-by: lombardof <flombardo@cnit.it>
instancehandler/template/instance_list.html
instancehandler/template/modal/instance_create.html
instancehandler/views.py
projecthandler/template/project/osm/descriptor/descriptorlist.html
projecthandler/template/project/osm/osm_project_descriptors.html
static/src/instancehandler/instance_create.js [new file with mode: 0644]
static/src/projecthandler/descriptorslist.js
static/src/vimhandler/vim_create.js [new file with mode: 0644]

index 1b0868d..54ac016 100644 (file)
@@ -12,6 +12,7 @@
     <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 }}
             <div class="box">
                 <div class="box-header with-border">
                     <h3 class="box-title">Instances</h3>
-                    <!--
+
                     <div class="box-tools">
-                        <a href="javascript:newVimModal()" class="btn btn-block btn-primary btn-sm"><i
-                                class="fa fa-plus"></i><span> New VIM</span></a>
+
+                        <button type="button" class="btn btn-default" data-container="body"
+                                data-toggle="tooltip" data-placement="top" title="Instantiate NS"
+                                onclick="javascript:openModalCreateNS({ 'project_id':'{{project_id}}','vim_list_url': '{% url "vim:list" %}'})" disabled>
+                            <i class="fa fa-paper-plane"></i> <span> New NS</span></button>
+
                     </div>
-                    -->
+
                 </div>
                 <div class="box-body">
                     <table id="instances_table" class="table table-bordered table-striped">
         </div>
 
     </div>
-{% include 'modal/instance_show.html' %}
-{% include 'modal/instance_new_action.html' %}
+    {% include 'modal/instance_create.html' %}
+    {% include 'modal/instance_show.html' %}
+    {% include 'modal/instance_new_action.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/display/fullscreen.js"></script>
     <script src="/static/bower_components/codemirror/keymap/sublime.js"></script>
     <script src="/static/src/instancehandler/instance_list.js"></script>
+    <script src="/static/src/instancehandler/instance_create.js"></script>
 
 {% endblock %}
 
index c40ecb2..ffbce47 100644 (file)
@@ -1,53 +1,69 @@
 <div class="modal" id="modal_new_instance" xmlns="http://www.w3.org/1999/html">
-    <div   class="modal-dialog">
+    <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" >New Instance</h4>
+                <h4 class="modal-title">New Instance</h4>
             </div>
-             <form id="formCreateNS" action='{% url "projects:instances:create"  project_id=project_id%}' class="form-horizontal"
-                      method="post" enctype="multipart/form-data">
-                     {% csrf_token %}
-            <div class="modal-body" id="modal_new_instance_body" >
-                <div class="form-group">
-                    <label for="nsName" class="col-sm-3 control-label">Name</label>
+            <form id="formCreateNS" action='{% url "projects:instances:create"  project_id=project_id %}'
+                  class="form-horizontal"
+                  method="post" enctype="multipart/form-data">
+                {% csrf_token %}
+                <div class="modal-body" id="modal_new_instance_body">
+                    <div class="form-group">
+                        <label for="nsName" class="col-sm-3 control-label">Name *</label>
                         <div class="col-sm-6">
                             <input class="form-control" id="nsName" name="nsName"
                                    placeholder="Ns name" required>
                         </div>
-                </div>
-                <div class="form-group">
-                    <label for="nsDescription" class="col-sm-3 control-label">Description</label>
+                    </div>
+                    <div class="form-group">
+                        <label for="nsDescription" class="col-sm-3 control-label">Description</label>
                         <div class="col-sm-6">
                             <input class="form-control" id="nsDescription" name="nsDescription"
-                                   placeholder="Description" >
+                                   placeholder="Description">
                         </div>
-                </div>
-                <div class="form-group">
-                    <label for="nsdId" class="col-sm-3 control-label">Nsd Id</label>
+                    </div>
+                    <div class="form-group">
+                        <label for="nsdId" class="col-sm-3 control-label">Nsd Id *</label>
                         <div class="col-sm-6">
                             <input class="form-control" id="nsdId" name="nsdId"
-                                   placeholder="Nsd Id" >
+                                   placeholder="Nsd Id">
                         </div>
-                </div>
-                <div class="form-group">
-                    <label for="vimAccountId" class="col-sm-3 control-label">Vim Account Id</label>
+                    </div>
+                    <div class="form-group">
+                        <label for="vimAccountId" class="col-sm-3 control-label">Vim Account Id *</label>
                         <div class="col-sm-6">
                             <select id="vimAccountId" class="js-example-basic form-control" name="vimAccountId">
                             </select>
                         </div>
-                </div>
-
-
+                    </div>
+                    <div class="form-group">
+                        <label for="ssh_key" class="col-sm-3 control-label">SSH Key </label>
+                        <div class="col-sm-6">
+                            <textarea class="form-control" id="ssh_key" name="ssh_key"
+                                      placeholder="Paste your key here..." rows="4"></textarea>
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label for="config" class="col-sm-3 control-label">Config </label>
+                        <div class="col-sm-6">
+                            <textarea class="form-control" id="config" name="config" placeholder="Yaml config"
+                                      rows="4"></textarea>
+                        </div>
+                    </div>
 
-            </div>
-            <div class="modal-footer">
-                <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Cancel</button>
-                <button class="btn btn-primary"  data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Creating..." id="create_new_instance">Create</button>
+                </div>
+                <div class="modal-footer">
+                    <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Cancel</button>
+                    <button class="btn btn-primary"
+                            data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Creating..."
+                            id="create_new_instance">Create
+                    </button>
 
-            </div>
-                 </form>
+                </div>
+            </form>
         </div>
         <!-- /.modal-content -->
     </div>
index 0c9a8a4..86d00d5 100644 (file)
@@ -15,9 +15,9 @@
 #
 
 from django.shortcuts import render, redirect
-from django.contrib.auth.decorators import login_required, permission_required
+from django.contrib.auth.decorators import login_required
 from django.http import HttpResponse, JsonResponse
-import json
+import yaml
 import logging
 from lib.osm.osmclient.client import Client
 
@@ -39,12 +39,29 @@ def create(request, project_id=None):
         "nsDescription": request.POST.get('nsDescription', ''),
         "nsdId": request.POST.get('nsdId', ''),
         "vimAccountId": request.POST.get('vimAccountId', ''),
-        # "ssh-authorized-key": [
-        #     {
-        #         request.POST.get('key-pair-ref', ''): request.POST.get('keyValue', '')
-        #     }
-        # ]
     }
+    if 'ssh_key' in request.POST:
+        ns_data["ssh-authorized-key"] = [request.POST.get('ssh_key')]
+
+    if 'config' in request.POST:
+        ns_config = yaml.load(request.POST.get('config'))
+        if "vim-network-name" in ns_config:
+            ns_config["vld"] = ns_config.pop("vim-network-name")
+        if "vld" in ns_config:
+            for vld in ns_config["vld"]:
+                if vld.get("vim-network-name"):
+                    if isinstance(vld["vim-network-name"], dict):
+                        vim_network_name_dict = {}
+                        for vim_account, vim_net in vld["vim-network-name"].items():
+                            vim_network_name_dict[ns_data["vimAccountId"]] = vim_net
+                        vld["vim-network-name"] = vim_network_name_dict
+            ns_data["vld"] = ns_config["vld"]
+        if "vnf" in ns_config:
+            for vnf in ns_config["vnf"]:
+                if vnf.get("vim_account"):
+                    vnf["vimAccountId"] = ns_data["vimAccountId"]
+
+            ns_data["vnf"] = ns_config["vnf"]
     print ns_data
     client = Client()
     result = client.ns_create(ns_data)
@@ -53,7 +70,7 @@ def create(request, project_id=None):
 
 @login_required
 def action(request, project_id=None, instance_id=None, type=None):
-    result = {}
+
     client = Client()
 
     # result = client.ns_action(instance_id, action_payload)
index 56ee44d..4e3e24b 100644 (file)
@@ -37,7 +37,7 @@
                     <td>
                         <div class="btn-group">
                             {% if descriptor_type == "nsd" %}
-                            <button type="button" class="btn btn-default" data-container="body" data-toggle="tooltip" data-placement="top" title="Instantiate NS" onclick="javascript:openModalCreateNS('{{project_id}}', '{{descriptor_type}}', '{{ k|get:"_id" }}')"><i class="fa fa-paper-plane"></i></button>
+                            <button type="button" class="btn btn-default" data-container="body" data-toggle="tooltip" data-placement="top" title="Instantiate NS" onclick="javascript:openModalCreateNS({ 'project_id':'{{project_id}}', 'descriptor_type': '{{descriptor_type}}', 'descriptor_id':'{{ k|get:"_id" }}','vim_list_url': '{% url "vim:list" %}'})"><i class="fa fa-paper-plane"></i></button>
                             {% endif %}
                             <button type="button" class="btn btn-default" data-container="body" data-toggle="tooltip" data-placement="top" title="Edit" onclick="javascript:openDescriptorView('{{project_id}}', '{{descriptor_type}}', '{{ k|get:"_id" }}')"><i class="fa fa-edit"></i></button>
                             <button type="button" class="btn btn-default" data-container="body" data-toggle="tooltip" data-placement="top" title="Show content" onclick="javascript:openPackageContentList('{{project_id}}', '{{descriptor_type}}', '{{ k|get:"_id" }}')"><i class="fa fa-folder-open"></i></button>
index 30ea76a..27872b2 100644 (file)
 {% block resource_block %}
        {{ block.super }}
     <script src="/static/bower_components/select2/dist/js/select2.js"></script>
-    <script>
-        function deletePackage(project_id, descriptor_type, package_id) {
-            bootbox.confirm("Are you sure want to delete?", function (result) {
-                if (result) {
-                    location.href = '/projects/' + project_id + '/descriptors/' + descriptor_type + '/' + package_id + '/delete'
-                }
-            })
-        }
+    <script src="/static/src/instancehandler/instance_create.js"></script>
+    
 
-        function openModalCreateNS(project_id, descriptor_type, descriptor_id) {
-            select2_groups = $('#vimAccountId').select2({
-                placeholder: 'Select VIM',
-                ajax: {
-                    url: '{% url "vim:list" %}',
-                    dataType: 'json',
-                    processResults: function (data) {
-                        vims = [];
-                        if (data['datacenters']){
-                            for(d in data['datacenters']){
-                            var datacenter = data['datacenters'][d];
-                            vims.push({id: datacenter['_id'], text: datacenter['name']})
-                        }
-                        }
-
-                        return {
-                            results: vims
-                        };
-                    }
-                }
-            });
-            $('#nsdId').val(descriptor_id);
-            $('#modal_new_instance').modal('show');
-        }
-
-        function openPackageContentList(project_id, type, pkg_id) {
-            var dialog = bootbox.dialog({
-                message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
-                closeButton: true
-            });
-            $.ajax({
-                url: '/projects/' + project_id + '/descriptors/' + type + '/' + pkg_id + '/action/get_package_files_list',
-                type: 'GET',
-                dataType: "json",
-                contentType: "application/json;charset=utf-8",
-                success: function (result) {
-                    //$('#modal_show_vim_body').empty();
-                    console.log(result)
-                    dialog.modal('hide');
-                    build_file_list("Files in " + pkg_id, result.files);
-                },
-                error: function (result) {
-                    dialog.modal('hide');
-                    bootbox.alert("An error occurred while retrieving the package content.");
-                }
-            });
-        }
-
-
-        function build_file_list(title, list) {
-            $('#files_list_tbody').find('tr:gt(0)').remove();
-            $('#files_list_tbody_title').text(title)
-            for (var i in list) {
-                var template = '<tr><td>-</td><td>' + list[i] + '</td><td><button type="button" class="btn btn-default" onclick="" disabled><i class="fa fa-folder-open"></i></button></td></tr>'
-                $('#files_list_tbody').append(template)
-            }
-            $('#modal_files_list').modal('show');
-        }
-    </script>
 {% endblock %}
 
 {% block footer %}
diff --git a/static/src/instancehandler/instance_create.js b/static/src/instancehandler/instance_create.js
new file mode 100644 (file)
index 0000000..55fb512
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+   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 openModalCreateNS(args) {
+
+    // load vim account list
+    select2_groups = $('#vimAccountId').select2({
+        placeholder: 'Select VIM',
+        ajax: {
+            url: args.vim_list_url,
+            dataType: 'json',
+            processResults: function (data) {
+                vims = [];
+                if (data['datacenters']) {
+                    for (d in data['datacenters']) {
+                        var datacenter = data['datacenters'][d];
+                        vims.push({id: datacenter['_id'], text: datacenter['name']})
+                    }
+                }
+
+                return {
+                    results: vims
+                };
+            }
+        }
+    });
+    /*
+    // load nsd list
+    select2_groups = $('#nsdId').select2({
+        placeholder: 'Select NSD',
+        ajax: {
+            url: args.nsd_list_url,
+            dataType: 'json',
+            processResults: function (data) {
+                nsd_list = [];
+                if (data['nsd_list']) {
+                    for (d in data['nsd_list']) {
+                        var nsd = data['nsd_list'][d];
+                        nsd_list.push({id: nsd['_id'], text: nsd['name']})
+                    }
+                }
+
+                return {
+                    results: nsd_list
+                };
+            }
+        }
+    });
+    */
+    $('#nsdId').val(args.descriptor_id);
+    $('#modal_new_instance').modal('show');
+}
\ No newline at end of file
index 4a5975a..5a803da 100644 (file)
@@ -1,69 +1,42 @@
-
-function startFromAgent(start) {
-
-
-    if (start == 'exist'){
-        $('#div_new_agent').hide();
-        $('#div_available_agent').show();
-    }
-    else if (start == 'new'){
-        $('#div_available_agent').hide();
-        $('#div_new_agent').show();
-    }
-
-    $('.required').prop('required', function(){
-        return  $(this).is(':visible');
-    });
-
-}
-/*
-function InvalidGitUrl(textbox) {
-    console.log('InvalidGitUrl', textbox,textbox.value == '' ,textbox.validity.typeMismatch)
-    if (textbox.value === '') {
-        textbox.setCustomValidity('Required git URL');
-    }
-    else if (textbox.validity.typeMismatch){
-        textbox.setCustomValidity('please enter a valid git URL');
-
-    }
-    else {
-        textbox.setCustomValidity('please enter a valid git URL');
-    }
-    return true;
-}
-*/
-function startFromRepo(start) {
-
-
-    if (start == 'exist'){
-        $('#div_new_repo').hide();
-        $('#div_available_repo').show();
-    }
-    else if (start == 'new'){
-        $('#div_available_repo').hide();
-        $('#div_new_repo').show();
-    }
-
-    $('.required').prop('required', function(){
-        return  $(this).is(':visible');
-    });
-
-}
-
-$(document).ready(function () {
-    $("#startButtonsSelect :input").change(function () {
-        console.log("select")
-        startFromAgent(this.value);
-    });
-    $("#push_start_buttons_select :input").change(function () {
-        console.log("select")
-        startFromRepo(this.value);
-    });
-
-    // Bind events
-    $("form").submit(function(e) {
-        console.log("on submit form")
-        $("#start_new_deployment").button('loading');
-    });
-
-});
\ No newline at end of file
+ function deletePackage(project_id, descriptor_type, package_id) {
+            bootbox.confirm("Are you sure want to delete?", function (result) {
+                if (result) {
+                    location.href = '/projects/' + project_id + '/descriptors/' + descriptor_type + '/' + package_id + '/delete'
+                }
+            })
+        }
+
+
+
+        function openPackageContentList(project_id, type, pkg_id) {
+            var dialog = bootbox.dialog({
+                message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
+                closeButton: true
+            });
+            $.ajax({
+                url: '/projects/' + project_id + '/descriptors/' + type + '/' + pkg_id + '/action/get_package_files_list',
+                type: 'GET',
+                dataType: "json",
+                contentType: "application/json;charset=utf-8",
+                success: function (result) {
+                    //$('#modal_show_vim_body').empty();
+                    dialog.modal('hide');
+                    build_file_list("Files in " + pkg_id, result.files);
+                },
+                error: function (result) {
+                    dialog.modal('hide');
+                    bootbox.alert("An error occurred while retrieving the package content.");
+                }
+            });
+        }
+
+
+        function build_file_list(title, list) {
+            $('#files_list_tbody').find('tr:gt(0)').remove();
+            $('#files_list_tbody_title').text(title)
+            for (var i in list) {
+                var template = '<tr><td>-</td><td>' + list[i] + '</td><td><button type="button" class="btn btn-default" onclick="" disabled><i class="fa fa-folder-open"></i></button></td></tr>'
+                $('#files_list_tbody').append(template)
+            }
+            $('#modal_files_list').modal('show');
+        }
\ No newline at end of file
diff --git a/static/src/vimhandler/vim_create.js b/static/src/vimhandler/vim_create.js
new file mode 100644 (file)
index 0000000..e69de29