Commit 52c23bb7 authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

Automatic private networks subnet assignment in ui

Automatically choose a subnet that doesn't already exists in user's
private networks if 'Auto' subnet option is selected.
parent d9c69c11
......@@ -170,6 +170,10 @@ UI_NETWORK_AVAILABLE_NETWORK_TYPES = {'PRIVATE_FILTERED': 'mac-filtering'}
# network with dhcp enabled
UI_NETWORK_AVAILABLE_SUBNETS = ['10.0.0.0/24', '192.168.0.0/24']
# UI will use this setting to find an available network subnet if user requests
# automatic subnet selection.
UI_AUTOMATIC_NETWORK_RANGE_FORMAT = "192.168.%d.0/24"
# Whether to display already connected vm's to the network connect overlay
UI_NETWORK_ALLOW_DUPLICATE_VM_NICS = False
......
......@@ -314,6 +314,22 @@
return true;
},
get_next_available_subnet: function() {
var auto_tpl = synnefo.config.automatic_network_range_format;
if (!auto_tpl) {
return null
}
var index = 0;
var subnet = auto_tpl.format(index);
var networks = synnefo.storage.networks;
var check_existing = function(n) { return n.get('cidr') == subnet }
while (networks.filter(check_existing).length > 0 && index <= 255) {
index++;
subnet = auto_tpl.format(index);
}
return subnet;
},
create: function() {
this.create_button.addClass("in-progress");
......@@ -329,7 +345,7 @@
if (this.subnet_select.val() == "custom") {
subnet = this.subnet_custom.val();
} else if (this.subnet_select.val() == "auto") {
subnet = null;
subnet = this.get_next_available_subnet()
} else {
subnet = this.subnet_select.val();
}
......
......@@ -629,6 +629,7 @@
synnefo.config.group_public_networks = {{ group_public_networks }};
synnefo.config.grouped_public_network_name = {{ grouped_public_network_name|safe }};
synnefo.config.vm_hostname_format = {{ vm_hostname_format|safe }};
synnefo.config.automatic_network_range_format = {{ automatic_network_range_format|safe }};
synnefo.auth_client = new synnefo.auth.AstakosClient({
login_url: synnefo.config.login_redirect,
......
......@@ -138,6 +138,9 @@ NETWORK_STRICT_DESTROY = getattr(settings,
'UI_NETWORK_STRICT_DESTROY', False)
NETWORK_ALLOW_MULTIPLE_DESTROY = getattr(settings,
'UI_NETWORK_ALLOW_MULTIPLE_DESTROY', False)
AUTOMATIC_NETWORK_RANGE_FORMAT = getattr(settings,
'UI_AUTOMATIC_NETWORK_RANGE_FORMAT',
"192.168.%d.0/24").replace("%d", "{0}")
GROUP_PUBLIC_NETWORKS = getattr(settings, 'UI_GROUP_PUBLIC_NETWORKS', True)
GROUPED_PUBLIC_NETWORK_NAME = getattr(settings, 'UI_GROUPED_PUBLIC_NETWORK_NAME', 'Internet')
......@@ -199,6 +202,7 @@ def home(request):
'network_allow_duplicate_vm_nics': json.dumps(NETWORK_DUPLICATE_NICS),
'network_strict_destroy': json.dumps(NETWORK_STRICT_DESTROY),
'network_allow_multiple_destroy': json.dumps(NETWORK_ALLOW_MULTIPLE_DESTROY),
'automatic_network_range_format': json.dumps(AUTOMATIC_NETWORK_RANGE_FORMAT),
'grouped_public_network_name': json.dumps(GROUPED_PUBLIC_NETWORK_NAME),
'group_public_networks': json.dumps(GROUP_PUBLIC_NETWORKS),
'diagnostics_update_interval': json.dumps(DIAGNOSTICS_UPDATE_INTERVAL),
......
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