Commit ac5e32b0 authored by Felipe Fonseca's avatar Felipe Fonseca
Browse files

Changed VLAN selection to lease creation

parent 0cec7f61
......@@ -199,16 +199,29 @@ class Reservation(object):
leases = []
for schedule in self.schedules:
lease = {
"name": str(uuid.uuid4()),
"valid_from": schedule['start'],
"valid_until": schedule['end'],
"policy": "best-effort",
"use_slice_components": True,
"account_attributes": {
"urn": self.slice['slice_urn']
},
}
if int(schedule['vlan']) == -1:
lease = {
"name": str(uuid.uuid4()),
"valid_from": schedule['start'],
"valid_until": schedule['end'],
"policy": "best-effort",
"use_slice_components": True,
"account_attributes": {
"urn": self.slice['slice_urn']
},
}
else:
lease = {
"name": str(uuid.uuid4()),
"valid_from": schedule['start'],
"valid_until": schedule['end'],
"vlan": schedule['vlan'],
"policy": "best-effort",
"use_slice_components": True,
"account_attributes": {
"urn": self.slice['slice_urn']
},
}
leases.append(lease)
return leases
......@@ -280,6 +280,48 @@ $(document).ready(function() {
}
});
function removeVlan(arr, vlan) {
return arr.filter(function(ele){
return ele != vlan;
});
}
function getAvailableVlansForSchedule(startDate, endDate) {
var allEvents = $('#calendar').fullCalendar('clientEvents');
var overlapEvnts = [];
$.grep(allEvents, function (v) {
var eventStart = parseInt((new Date(v.start)).getTime());
var eventEnd = parseInt((new Date(v.end)).getTime());
if((startDate >= eventStart && startDate <= eventEnd)
|| (endDate >= eventStart && endDate <= eventEnd)
|| (eventStart >= startDate && eventStart <= endDate)
|| (eventEnd >= startDate && eventEnd <= endDate))
{
overlapEvnts.push(v);
}
});
// Checks for resource reservation conflict...
var availableVlans = JSON.parse(JSON.stringify(window.vlans));
overlapEvnts.forEach(function(evnt) {
if (evnt.user_event === true) {
return;
}
if (evnt.resources == undefined) {
return;
}
evnt.resources.forEach(function(item) {
if (item.resource_type === 'vlan') {
availableVlans = removeVlan(availableVlans, item.name)
}
});
});
return availableVlans;
}
function addScheduleEvent(eventData) {
var calendar = window.calendar;
if(calendar.length > 0) {
......@@ -298,9 +340,14 @@ function update_schedules() {
$.each(myEvents, function(index, event) {
schedules.push({
"start": moment(event.start).format('YYYY-MM-DD HH:mm:ss Z'),
"end": moment(event.end).format('YYYY-MM-DD HH:mm:ss Z')
"end": moment(event.end).format('YYYY-MM-DD HH:mm:ss Z'),
"availableVlans": getAvailableVlansForSchedule(event.start, event.end),
"vlan": -1
});
});
updateNetworkTab(schedules);
schedules.sort((a, b) => (a["start"] > b["start"]) ? 1: -1);
window.selected_schedules = schedules
$("input[name=schedules]").val(JSON.stringify(schedules));
if (schedules.length > 0) {
......@@ -310,3 +357,32 @@ function update_schedules() {
}
}
}
function updateNetworkTab(schedules) {
if (schedules == undefined) {
return;
}
html = ''
$.each(schedules, function(index, schedule) {
availableVlans = ''
$.each(schedule["availableVlans"], function(index, vlan) {
availableVlans += `<option value="${vlan}">${vlan}</option>`
});
html += `<div class="row">
<div class="col-sm-12 vlan-container">
<label for="vlans">"Schedule ${index + 1}: VLAN ID"</label>
<select class="form-control" name="vlans" onchange="updateScheduleVlan(${index}, this.value)">
<option value="-1" disabled selected>"Select a vlan"</option>
${availableVlans}
</select>
</div>
</div>`
});
$('#schedule_vlans').html(html)
}
function updateScheduleVlan(index, value) {
window.selected_schedules[index]["vlan"] = value
$("input[name=schedules]").val(JSON.stringify(window.selected_schedules));
}
\ No newline at end of file
......@@ -31,6 +31,7 @@
window.available_cms = {{available_cms|safe}};
window.hypervisors = {{hypervisors|safe}};
window.server_time = {{ server_time|safe }};
window.vlans = {{vlans|safe}};
window.server_time = parseInt(window.server_time*1000);
window.server_offset = new Date().getTime() - window.server_time;
});
......@@ -50,6 +51,11 @@
</div>
<div class="panel-body">
<ul class="breadcrumb reservation-breadcrumb clean-background">
<li class="active" data-open-panel="schedule">{% trans "Schedule selection" %}</li>
<li data-open-panel="network">{% trans "Network Resources" %}</li>
<!-- <li data-open-panel="review_lease">{% trans "Review" %}</li> -->
</ul>
{% if form.errors or get_resources_error %}
<div class="alert alert-warning alert-dismissible" role="alert">
......@@ -62,14 +68,35 @@
{% endif %}
<input type="hidden" name="project_name" value="{{ project.project_name }}">
<div class="configuration-panel">
<div id="schedule">
<div id="calendar"></div>
<input type="hidden" name="schedules">
</div>
<div id="network">
<p>
<span class="small"> {% trans "If you do not wish to experiment with OpenFlow resources for a schedule, you do not need to select a VLAN." %}</span>
</p>
<div class="panel panel-box">
<div class="panel-heading panel-title">
<span class="glyphicon glyphicon-random"></span>
<span>{% trans "Vlan configuration" %}</span>
</div>
<div class="panel-body" id="schedule_vlans">
</div>
</div>
</div>
</div>
<div class="panel-footer">
<div class="row">
<div class="col-sm-12 text-right">
<div id="page-controls" class="col-sm-6">
<div class="btn-group">
<button type="button" class="btn btn-default" disabled="disabled" data-page-action="prev" onclick="updateNetworkTab()"></button>
<button type="button" class="btn btn-default" data-page-action="next" onclick="updateNetworkTab()"></button>
</div>
</div>
<div class="col-sm-6 text-right">
<button type="submit" class="btn btn-primary loading" disabled="disabled" id="create_reservation_btn" data-loading-text="<i class='fa fa-spinner fa-spin '></i> {% trans "Create reservation" %}">
{% trans "Create reservation" %}
</button>
......
......@@ -83,7 +83,7 @@
<ul class="breadcrumb reservation-breadcrumb clean-background">
<li class="active" data-open-panel="slice-data">{% trans "Slice description" %}</li>
<li data-open-panel="computational-resources">{% trans "Computational Resources" %}</li>
<li data-open-panel="network">{% trans "Network Resources" %}</li>
<!-- <li data-open-panel="network">{% trans "Network Resources" %}</li> -->
<li data-open-panel="review_reservation">{% trans "Review" %}</li>
</ul>
......@@ -318,7 +318,8 @@
<tbody id="node_summary">
</tbody>
</table>
<!--
<li>{% trans "OpenFlow resources" %}</li>
<table class="table dataTables_wrapper no-footer" id="network_summary_table">
<thead>
......@@ -329,6 +330,7 @@
<tbody id="network_summary">
</tbody>
</table>
-->
</ul>
</div>
</div>
......
......@@ -189,12 +189,14 @@ def create_reservation(request, slice_urn, slice):
context['leases'] = json.dumps(leases)
context['available_cms'] = json.dumps(available_cms)
context['hypervisors'] = json.dumps(hypervisors_capacity)
context['vlans'] = resource_manager.get_vlans(member_cred)
except Exception as exception:
logging.error(exception)
context['get_resources_error'] = True
context['leases'] = json.dumps([])
context['available_cms'] = json.dumps([])
context['hypervisors'] = json.dumps([])
context['vlans'] = json.dumps([])
context['server_time'] = time.time()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment