elif type == 'vnf':
result = client.vnf_list()
- return __response_handler(request, {'instances': result, 'type': type, 'project_id': project_id}, 'instance_list.html')
+ result = {'instances': result, 'type': type, 'project_id': project_id}
+
+ return __response_handler(request, result, 'instance_list.html')
@login_required
json=vim_data)
return None
+
+ def sdn_list(self):
+ token = self.get_token()
+ if token:
+ self._headers['Authorization'] = 'Bearer {}'.format(token)
+ self._headers['accept'] = 'application/json'
+ _url = "{0}/admin/v1/sdns".format(self._base_path)
+ return self._send_get(_url, headers=self._headers)
+
+ def sdn_delete(self, id):
+ token = self.get_token()
+ if token:
+ self._headers['Authorization'] = 'Bearer {}'.format(token)
+ self._headers['accept'] = 'application/json'
+ _url = "{0}/admin/v1/sdns/{1}".format(self._base_path, id)
+ return self._send_delete(_url, headers=self._headers)
+ return None
+
+ def sdn_get(self, id):
+ token = self.get_token()
+ if token:
+ self._headers['Authorization'] = 'Bearer {}'.format(token)
+ self._headers['accept'] = 'application/json'
+ _url = "{0}/admin/v1/sdns/{1}".format(self._base_path, id)
+ return self._send_get(_url, headers=self._headers)
+ return None
+
+ def sdn_create(self, sdn_data):
+ token = self.get_token()
+ headers = {}
+ if token:
+ headers['Authorization'] = 'Bearer {}'.format(token)
+ headers['Content-Type'] = 'application/json'
+ headers['accept'] = 'application/json'
+
+ _url = "{0}/admin/v1/sdns".format(self._base_path)
+ return self._send_post(_url, headers=headers,
+ json=sdn_data)
+ return None
+
def nsd_list(self):
token = self.get_token()
if token:
<i class="fa fa-list fa-fw"></i><span>VNF Instances</span>
</a>
</li>
+ {% url "projects:sdns:list" project_id=project_id as sdn_list_url %}
+ <li {% if request.get_full_path == sdn_list_url %} class="active" {% endif %}>
+ <a href='{% url "projects:sdns:list" project_id=project_id %}'>
+ <i class="fa fa-list fa-fw"></i><span>SDN Controllers</span>
+ </a>
+ </li>
<li class="header">CONFIG</li>
{% url "vim:list" type='ns' as vim_list_url %}
<li {% if request.get_full_path == vim_list_url %} class="active" {% endif %}>
url(r'^list/', views.user_projects, name='projects_list'),
url(r'^new/', views.create_new_project, name='new_project'),
url(r'^(?P<project_id>\d+)/$', views.open_project, name='open_project'),
+ url(r'^(?P<project_id>\d+)/sdn/', include('sdnctrlhandler.urls', namespace='sdns'), name='sdns_base'),
url(r'^(?P<project_id>\d+)/instances/', include('instancehandler.urls', namespace='instances'), name='instances_base'),
url(r'^(?P<project_id>\d+)/delete$', views.delete_project, name='delete_project'),
url(r'^(?P<project_id>\d+)/graph(/$)', views.graph, name='graph_view'),
--- /dev/null
+from django.contrib import admin
+
+# Register your models here.
--- /dev/null
+from __future__ import unicode_literals
+
+from django.apps import AppConfig
+
+
+class SdnctrlhandlerConfig(AppConfig):
+ name = 'sdnctrlhandler'
--- /dev/null
+from __future__ import unicode_literals
+
+from django.db import models
+
+# Create your models here.
--- /dev/null
+<div class="modal" id="modal_show_sdn" 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">SDN Controller</h4>
+ </div>
+
+ <div class="modal-body" id="modal_show_sdn_body">
+ <div class="row">
+ <div class="col-lg-10">
+ <ul class="nav nav-stacked">
+ <li><a><b>ID:</b> <span id="_id" class="pull-right"></span></a></li>
+ </ul>
+ </div>
+ <div class="col-lg-7">
+ <ul class="nav nav-stacked">
+ <li><a><b>Operational State:</b><span id="operationalState" class="pull-right badge"></span></a></li>
+ <li><a><b> Name:</b><span id="name" class="pull-right"></span></a></li>
+ <li><a><b>Type:</b><span id="type" class="pull-right"></span></a></li>
+ <li><a><b>User:</b><span id="user" class="pull-right"></span></a></li>
+ <li><a><b>DPID:</b><span id="dpid" class="pull-right"></span></a></li>
+
+ </ul>
+ </div>
+ <div class="col-lg-5">
+ <ul class="nav nav-stacked">
+ <li><a><b>IP:</b><span id="ip" class="pull-right "></span></a></li>
+ <li><a><b>Port:</b><span id="port" class="pull-right "></span></a></li>
+ <li><a><b>Version:</b><span id="" class="pull-right "></span></a></li>
+ <li><a><b>Created:</b><span id="created" class="pull-right "></span></a></li>
+ <li><a><b>Modified:</b><span id="modified" class="pull-right "></span></a></li>
+ </ul>
+ </div>
+ <div class="col-lg-12">
+ <ul class="nav nav-stacked">
+ <li><a><b>Deployed:</b><span id="deployed" class="pull-right "></span></a></li>
+ </ul>
+ </div>
+ </div>
+ </div>
+ <div class="modal-footer">
+ <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
+ </div>
+ </div>
+ <!-- /.modal-content -->
+ </div>
+ <!-- /.modal-dialog -->
+</div>
\ No newline at end of file
--- /dev/null
+{% extends "base.html" %}
+{% load get %}
+{% 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 }}
+ <li><a href="{% url 'projects:sdns:list' project_id=project_id %}">SDN Controllers</a></li>
+{% endblock %}
+
+{% block content_body %}
+ {{ block.super }}
+
+ <div class="row">
+ <div class="col-md-12">
+ <form action='{% url 'projects:sdns:create' project_id=project_id%}' method="post">
+ {% csrf_token %}
+ <div class="box">
+ <div class="box-header with-border">
+ <h3 class="box-title">New SDN Controller</h3>
+ <div class="box-tools">
+
+ </div>
+ </div>
+ <div class="box-body">
+ <div class="row">
+ <div class="col-lg-6">
+ <div class="row">
+ <div class="form-group">
+ <label for="name" class="col-sm-3 control-label">Name*</label>
+ <div class="col-sm-6 input-group input-group-sm">
+ <input class="form-control" id="name" name="name" required>
+ </div>
+ </div>
+ </div>
+ <div class="row">
+ <div class="form-group">
+ <label for="sdn_type" class="col-sm-3 control-label">Type*</label>
+ <div class="col-sm-6 input-group input-group-sm">
+ <input class="form-control" id="sdn_type" name="type" required>
+ </div>
+ </div>
+ </div>
+ <div class="row">
+ <div class="form-group">
+ <label for="sdn_user" class="col-sm-3 control-label">Username*</label>
+ <div class="col-sm-6 input-group input-group-sm">
+ <input class="form-control" id="sdn_user" name="user" required>
+ </div>
+ </div>
+ </div>
+ <div class="row">
+ <div class="form-group">
+ <label for="sdn_password" class="col-sm-3 control-label">Password*</label>
+ <div class="col-sm-6 input-group input-group-sm">
+ <input type="password" class="form-control" id="password"
+ name="sdn_password" required>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div class="col-lg-6">
+ <div class="row">
+ <div class="form-group">
+ <label for="sdn_ip" class="col-sm-3 control-label">IP*</label>
+ <div class="col-sm-6 input-group input-group-sm">
+ <input class="form-control" id="sdn_ip" name="ip" required>
+ </div>
+ </div>
+ </div>
+ <div class="row">
+ <div class="form-group">
+ <label for="sdn_port" class="col-sm-3 control-label">Port*</label>
+ <div class="col-sm-6 input-group input-group-sm">
+ <input class="form-control" type="number" id="sdn_port" name="port" required>
+ </div>
+ </div>
+ </div>
+ <div class="row">
+ <div class="form-group">
+ <label for="sdn_dpid" class="col-sm-3 control-label">DPID*</label>
+ <div class="col-sm-6 input-group input-group-sm">
+ <input class="form-control" id="sdn_dpid" name="dpid" pattern="[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){7}" required>
+ </div>
+ </div>
+ </div>
+ <div class="row">
+ <div class="form-group">
+ <label for="sdn_version" class="col-sm-3 control-label">Version</label>
+ <div class="col-sm-6 input-group input-group-sm">
+ <input class="form-control" id="sdn_version" name="version">
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ </div>
+ <div class="box-footer">
+ <button onclick="location.href='{% url 'projects:sdns:list' project_id=project_id %}'" class="btn btn-default pull-left">Back to
+ SDN Controllers
+ </button>
+ <button class="btn btn-primary pull-right">Create</button>
+ </div>
+ </div>
+ </form>
+ </div>
+
+ </div>
+{% endblock %}
+
+{% block resource_block %}
+ {{ block.super }}
+ <!-- Utility JS -->
+
+ <script>
+ $(document).ready(function () {
+ });
+ </script>
+
+{% endblock %}
+
+{% block footer %}
+ {% include "footer.html" %}
+{% endblock %}
\ No newline at end of file
--- /dev/null
+{% extends "base.html" %}
+{% load get %}
+{% 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 }}
+ <li><a href="{% url 'projects:sdns:list' project_id=project_id %}">SDN Controllers</a></li>
+{% endblock %}
+
+{% block content_body %}
+ {{ block.super }}
+ {% include 'modal/sdn_details.html' %}
+ {% csrf_token %}
+ <div class="row">
+ <div class="col-md-12">
+
+ <div class="box">
+ <div class="box-header with-border">
+ <h3 class="box-title">Registered SDN Controllers</h3>
+ <div class="box-tools">
+ <a href='{% url "projects:sdns:create" project_id=project_id %}' class="btn btn-block btn-primary btn-sm"><i
+ class="fa fa-plus"></i><span> New SDN Controller</span></a>
+ </div>
+ </div>
+ <div class="box-body">
+ <table id="projects_table" class="table table-bordered table-striped">
+ <thead>
+ <tr>
+ <th>Id</th>
+ <th>Name</th>
+ <th>Type</th>
+ <th>Operational State</th>
+ <th>IP</th>
+ <th>Port</th>
+ <th>Actions</th>
+
+ </tr>
+ </thead>
+ <tbody>
+ {% for s in sdns %}
+ <tr>
+ <td>{{ s|get:"_id" }}</td>
+ <td>{{ s|get:"name" }}</td>
+ <td>{{ s|get:"type" }}</td>
+ <td>{{ s|get_sub:"_admin,operationalState"}}</td>
+ <td>{{ s|get:"ip" }}</td>
+ <td>{{ s|get:"port" }}</td>
+ <td>
+ <div class="btn-group">
+ <button type="button" class="btn btn-default"
+ onclick="javascript:showSDN('{{ project_id }}', '{{ s|get:"_id" }}')" data-toggle="tooltip" data-placement="top" data-container="body" title="Show Info"><i
+ class="fa fa-info"></i></button>
+ <button type="button" class="btn btn-default"
+ onclick="javascript:deleteSDN('{{ project_id }}', '{{ s|get:"_id" }}')" data-toggle="tooltip" data-placement="top" data-container="body" title="Delete"><i
+ class="fa fa-trash-o" ></i></button>
+ </div>
+ </td>
+
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ </div>
+ </div>
+ </div>
+
+ </div>
+{% endblock %}
+
+{% block resource_block %}
+ {{ block.super }}
+ <!-- moment JS -->
+ <script src="/static/bower_components/moment/moment.js"></script>
+
+ <script src="/static/src/sdnctrlhandler/sdn_list.js"></script>
+
+
+{% endblock %}
+
+{% block footer %}
+ {% include "footer.html" %}
+{% endblock %}
\ No newline at end of file
--- /dev/null
+from django.test import TestCase
+
+# Create your tests here.
--- /dev/null
+#
+# 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.conf.urls import url
+from sdnctrlhandler import views
+
+urlpatterns = [
+ url(r'^list$', views.list, name='list'),
+ url(r'^create$', views.create, name='create'),
+ url(r'^(?P<sdn_id>[0-9a-z-]+)/delete$', views.delete, name='delete'),
+ url(r'^(?P<sdn_id>[0-9a-z-]+)', views.show, name='show'),
+
+]
\ No newline at end of file
--- /dev/null
+#
+# 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.shortcuts import render, redirect
+from django.contrib.auth.decorators import login_required
+from django.http import JsonResponse
+from lib.osm.osmclient.client import Client
+import logging
+
+logging.basicConfig(level=logging.DEBUG)
+log = logging.getLogger('view.py')
+
+
+@login_required
+def list(request, project_id):
+ client = Client()
+ result = client.sdn_list()
+
+ result = {
+ 'project_id': project_id,
+ 'sdns': result
+ }
+ return __response_handler(request, result, 'sdn_list.html')
+
+
+@login_required
+def create(request, project_id):
+ result = {'project_id': project_id}
+ if request.method == 'GET':
+ return __response_handler(request, result, 'sdn_create.html')
+ else:
+ new_sdn_dict = request.POST.dict()
+ client = Client()
+ keys = ["name",
+ "type",
+ "version",
+ "dpid",
+ "ip",
+ "port",
+ "user",
+ "password"]
+ sdn_data = dict(filter(lambda i: i[0] in keys and len(i[1]) > 0, new_sdn_dict.items()))
+ sdn_data['port'] = int(sdn_data['port'])
+
+ result = client.sdn_create(sdn_data)
+
+ return __response_handler(request, result, 'projects:sdns:list', to_redirect=True, project_id=project_id)
+
+
+@login_required
+def delete(request, project_id, sdn_id=None):
+ try:
+ client = Client()
+ del_res = client.sdn_delete(sdn_id)
+ except Exception as e:
+ log.exception(e)
+ return __response_handler(request, {}, 'projects:sdns:list', to_redirect=True, project_id=project_id)
+
+
+@login_required
+def show(request, project_id, sdn_id=None):
+ client = Client()
+ datacenter = client.sdn_get(sdn_id)
+ return __response_handler(request, {
+ "sdn": datacenter
+ }, project_id=project_id)
+
+
+def __response_handler(request, data_res, url=None, to_redirect=None, *args, **kwargs):
+ raw_content_types = request.META.get('HTTP_ACCEPT', '*/*').split(',')
+ if 'application/json' in raw_content_types:
+ return JsonResponse(data_res)
+ elif to_redirect:
+ return redirect(url, *args, **kwargs)
+ else:
+ return render(request, url, data_res)
'sf_user',
'projecthandler',
'vimhandler',
- 'instancehandler'
+ 'instancehandler',
+ 'sdnctrlhandler'
]
MIDDLEWARE_CLASSES = [
os.path.join(BASE_DIR, 'projecthandler', 'template', 'project'),
os.path.join(BASE_DIR, 'vimhandler', 'template'),
os.path.join(BASE_DIR, 'instancehandler', 'template'),
+ os.path.join(BASE_DIR, 'sdnctrlhandler', 'template'),
],
'APP_DIRS': True,
'OPTIONS': {
url(r'^register', user_views.register_view, name='register_user'),
url(r'^projects/', include('projecthandler.urls.project', namespace='projects'), name='projects_base'),
url(r'^vims/', include('vimhandler.urls', namespace='vim'), name='vims_base'),
+ #url(r'^sdn/', include('sdnctrlhandler.urls', namespace='sdn'), name='sdns_base'),
url(r'^$', views.home, name='home'),
url(r'^home', views.home, name='home'),
--- /dev/null
+function deleteSDN(project_id, sdn_uuid) {
+ bootbox.confirm("Are you sure want to delete?", function (result) {
+ if (result) {
+ location.href = '/projects/' + project_id + '/sdn/' + sdn_uuid + '/delete'
+ }
+ })
+}
+
+function showSDN(project_id, sdn_uuid) {
+ 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 + '/sdn/' + sdn_uuid ,
+ //url: '/sdn/' + sdn_uuid,
+ type: 'GET',
+ dataType: "json",
+ contentType: "application/json;charset=utf-8",
+ success: function (result) {
+ //$('#modal_show_vim_body').empty();
+ var sdn = result.sdn;
+ if (sdn) {
+ $('#modal_show_sdn_body').find('span').text('-');
+ for (var k in sdn) {
+ $('#' + k).text(sdn[k])
+ }
+ if (sdn['_admin']) {
+ for (var i in sdn['_admin']) {
+ if (i === 'modified' || i === 'created') {
+ //$('#' + i).text(new Date(sdn['_admin'][i]* 1000).toUTCString());
+ $('#' + i).text(moment(sdn['_admin'][i] * 1000).format('DD/MM/YY hh:mm:ss'));
+ }
+ else if (i === 'deployed') {
+ $('#' + i).text(JSON.stringify(sdn['_admin'][i]))
+ }
+ else
+ $('#' + i).text(sdn['_admin'][i])
+ }
+ }
+ dialog.modal('hide');
+ $('#modal_show_sdn').modal('show');
+ }
+ else {
+ dialog.modal('hide');
+ bootbox.alert("An error occurred while retrieving the SDN controller info.");
+ }
+
+ },
+ error: function (result) {
+ dialog.modal('hide');
+ bootbox.alert("An error occurred while retrieving the SDN controller info.");
+ }
+ });
+
+}
\ No newline at end of file
#
from django.shortcuts import render, redirect
-from django.contrib.auth.decorators import login_required, permission_required
-from django.http import HttpResponse, JsonResponse
+from django.contrib.auth.decorators import login_required
+from django.http import JsonResponse
from lib.osm.osmclient.client import Client
import yaml
import logging
logging.basicConfig(level=logging.DEBUG)
-log = logging.getLogger('helper.py')
+log = logging.getLogger('view.py')
@login_required
def list(request):