Prevent configuring fixed IP if building more than one member
Change-Id: Ib2be0fa8742d0d066ec1115bfbfb3209a7c2d1f3 Closes-Bug: #1582527
This commit is contained in:
parent
47d2a569aa
commit
0d1f36ac0b
|
@ -53,8 +53,8 @@
|
||||||
<input id="fixed_ip" type="text"/>
|
<input id="fixed_ip" type="text"/>
|
||||||
<input id="set_ip_button" type="button" value="Add"/>
|
<input id="set_ip_button" type="button" value="Add"/>
|
||||||
<input id="remove" type="button" value="Remove"/>
|
<input id="remove" type="button" value="Remove"/>
|
||||||
<p id="errors" style="color:red" ></p>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div id="errors" class="alert alert-message alert-danger" style="display:none"></div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -298,7 +298,7 @@ def check_ip_availability(request):
|
||||||
fixed_ip = request.GET.get('fixed_ip')
|
fixed_ip = request.GET.get('fixed_ip')
|
||||||
response = {'error': 'IP address is not within the allocated pool range'}
|
response = {'error': 'IP address is not within the allocated pool range'}
|
||||||
subnets = request.GET.get('subnets')
|
subnets = request.GET.get('subnets')
|
||||||
subnets = subnets.split(";")
|
subnets = subnets.split(":")
|
||||||
for subnet in subnets:
|
for subnet in subnets:
|
||||||
subnet_details = subnet.split(",")
|
subnet_details = subnet.split(",")
|
||||||
try:
|
try:
|
||||||
|
@ -306,7 +306,8 @@ def check_ip_availability(request):
|
||||||
if IPAddress(fixed_ip) >= IPAddress(subnet_details[1]) and \
|
if IPAddress(fixed_ip) >= IPAddress(subnet_details[1]) and \
|
||||||
IPAddress(fixed_ip) <= IPAddress(subnet_details[2]):
|
IPAddress(fixed_ip) <= IPAddress(subnet_details[2]):
|
||||||
fixed_ips = "ip_address=" + fixed_ip
|
fixed_ips = "ip_address=" + fixed_ip
|
||||||
ports = api.neutron.port_list(request, fixed_ips=fixed_ips)
|
ports = api.neutron.port_list(request,
|
||||||
|
tenant_id=request.user.tenant_id, fixed_ips=fixed_ips)
|
||||||
if ports:
|
if ports:
|
||||||
response = {"inuse": False,
|
response = {"inuse": False,
|
||||||
"error": "IP address already in use"}
|
"error": "IP address already in use"}
|
||||||
|
|
|
@ -415,7 +415,7 @@ class SetGroupAction(workflows.Action):
|
||||||
if subnet_dedails is None:
|
if subnet_dedails is None:
|
||||||
subnet_dedails = subnet['cidr']
|
subnet_dedails = subnet['cidr']
|
||||||
else:
|
else:
|
||||||
subnet_dedails = ";" + subnet['cidr']
|
subnet_dedails = subnet_dedails + ";" + subnet['cidr']
|
||||||
allocation_pools = subnet['allocation_pools']
|
allocation_pools = subnet['allocation_pools']
|
||||||
if allocation_pools:
|
if allocation_pools:
|
||||||
start = allocation_pools[0]['start']
|
start = allocation_pools[0]['start']
|
||||||
|
@ -430,7 +430,13 @@ class SetGroupAction(workflows.Action):
|
||||||
|
|
||||||
class Meta(object):
|
class Meta(object):
|
||||||
name = _("Groups")
|
name = _("Groups")
|
||||||
help_text = _("Select groups for launching the member instance in.")
|
|
||||||
|
def clean(self):
|
||||||
|
cleaned_data = super(SetGroupAction, self).clean()
|
||||||
|
if not cleaned_data.get("network", None):
|
||||||
|
raise forms.ValidationError(_(
|
||||||
|
'At least one group must be selected.'))
|
||||||
|
return cleaned_data
|
||||||
|
|
||||||
def populate_network_choices(self, request, context):
|
def populate_network_choices(self, request, context):
|
||||||
try:
|
try:
|
||||||
|
@ -446,7 +452,7 @@ class SetGroupAction(workflows.Action):
|
||||||
if subnet_dedails is None:
|
if subnet_dedails is None:
|
||||||
subnet_dedails = subnet['cidr']
|
subnet_dedails = subnet['cidr']
|
||||||
else:
|
else:
|
||||||
subnet_dedails = ";" + subnet['cidr']
|
subnet_dedails += ";" + subnet['cidr']
|
||||||
allocation_pools = subnet['allocation_pools']
|
allocation_pools = subnet['allocation_pools']
|
||||||
if allocation_pools:
|
if allocation_pools:
|
||||||
start = allocation_pools[0]['start']
|
start = allocation_pools[0]['start']
|
||||||
|
|
|
@ -59,9 +59,10 @@ member = {
|
||||||
$("ul#available_group li[name^='"+ ptg +"']").css("background-color", "");
|
$("ul#available_group li[name^='"+ ptg +"']").css("background-color", "");
|
||||||
$("#fixed_ip_div").hide()
|
$("#fixed_ip_div").hide()
|
||||||
}
|
}
|
||||||
|
member.control_max_instances()
|
||||||
};
|
};
|
||||||
var updateForm = function() {
|
var updateForm = function() {
|
||||||
var groupListId = $("#groupListId");
|
var groupListId = $("#groupListId .multiple-checkbox");
|
||||||
var lists = groupListId.find("li").attr('data-index',100);
|
var lists = groupListId.find("li").attr('data-index',100);
|
||||||
var active_groups = $("#selected_network > li").map(function(){
|
var active_groups = $("#selected_network > li").map(function(){
|
||||||
return $(this).attr("name");
|
return $(this).attr("name");
|
||||||
|
@ -83,7 +84,7 @@ member = {
|
||||||
};
|
};
|
||||||
|
|
||||||
$("#groupListSortContainer").show();
|
$("#groupListSortContainer").show();
|
||||||
$("#groupListIdContainer").hide();
|
$("#groupListId .form-group").hide()
|
||||||
self.init_group_list();
|
self.init_group_list();
|
||||||
// Make sure we don't duplicate the groups in the list
|
// Make sure we don't duplicate the groups in the list
|
||||||
available_group.empty();
|
available_group.empty();
|
||||||
|
@ -124,11 +125,25 @@ member = {
|
||||||
}
|
}
|
||||||
}).disableSelection();
|
}).disableSelection();
|
||||||
},
|
},
|
||||||
|
control_max_instances: function(){
|
||||||
|
$("#id_count").attr('readonly', false)
|
||||||
|
$("#id_network").each(function() {
|
||||||
|
$input = $(this).find('li input');
|
||||||
|
value = $input.val();
|
||||||
|
fields = value.split(":")
|
||||||
|
if ($input.is(":checked") && fields.length == 3){
|
||||||
|
// fixed ip is associated, dont allow Instance Count > 1
|
||||||
|
$("#id_count").attr('readonly', true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
allow_fixed_ip: function(selected_group){
|
allow_fixed_ip: function(selected_group){
|
||||||
|
if (member.allowed() == false)
|
||||||
|
return
|
||||||
fixed_ip = ""
|
fixed_ip = ""
|
||||||
$("#fixed_ip").val("")
|
$("#fixed_ip").val("")
|
||||||
$("#errors").text("")
|
$("#errors").hide().text("")
|
||||||
$("#fixed_ip_div").show()
|
$("#fixed_ip_div").show()
|
||||||
ptg = $(selected_group).attr('name')
|
ptg = $(selected_group).attr('name')
|
||||||
$(selected_group).siblings().css( "background-color", "");
|
$(selected_group).siblings().css( "background-color", "");
|
||||||
|
@ -152,12 +167,23 @@ member = {
|
||||||
if (values.length == 3)
|
if (values.length == 3)
|
||||||
$("#fixed_ip").val(values[2]);
|
$("#fixed_ip").val(values[2]);
|
||||||
},
|
},
|
||||||
|
allowed: function(){
|
||||||
|
if($("#id_count").val() > 1){
|
||||||
|
$("#errors").show().text("You cannot assign fixed IPs " +
|
||||||
|
"if more than one instance is requested.")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
},
|
||||||
associate_fixed_ip: function(){
|
associate_fixed_ip: function(){
|
||||||
|
if (member.allowed() == false)
|
||||||
|
return
|
||||||
ptg = $("#fixed_ip").attr("data-ptg")
|
ptg = $("#fixed_ip").attr("data-ptg")
|
||||||
subnet = $("#fixed_ip").attr("data-subnet")
|
subnet = $("#fixed_ip").attr("data-subnet")
|
||||||
|
subnet = subnet.replace(";", ":")
|
||||||
fixed_ip = $("#fixed_ip").val()
|
fixed_ip = $("#fixed_ip").val()
|
||||||
if (!fixed_ip || 0 === fixed_ip.length ){
|
if (!fixed_ip || 0 === fixed_ip.length ){
|
||||||
$("#errors").text("Enter valid IP address")
|
$("#errors").show().text("Enter valid IP address")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
@ -167,6 +193,7 @@ member = {
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
if(response.inuse){
|
if(response.inuse){
|
||||||
horizon.alert('success', "IP address '" + fixed_ip +"' is available.")
|
horizon.alert('success', "IP address '" + fixed_ip +"' is available.")
|
||||||
|
subnet = subnet.replace(":", ";")
|
||||||
value = ptg + ":" + subnet + ":" + fixed_ip
|
value = ptg + ":" + subnet + ":" + fixed_ip
|
||||||
selected_element = $(".multiple-checkbox #id_network li input[value^='"+ ptg +"']");
|
selected_element = $(".multiple-checkbox #id_network li input[value^='"+ ptg +"']");
|
||||||
selected_element.val(value)
|
selected_element.val(value)
|
||||||
|
@ -178,18 +205,21 @@ member = {
|
||||||
}
|
}
|
||||||
$("ul#selected_network li[name^='"+ ptg +"']").css("background-color", "");
|
$("ul#selected_network li[name^='"+ ptg +"']").css("background-color", "");
|
||||||
$("#fixed_ip_div").hide()
|
$("#fixed_ip_div").hide()
|
||||||
|
$("#errors").hide().text("")
|
||||||
|
member.control_max_instances()
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$("#errors").text(response.error)
|
$("#errors").show().text(response.error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function(response) {
|
error: function(response) {
|
||||||
$("#errors").text(response)
|
$("#errors").show().text(response)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
disassociate_fixed_ip: function(){
|
disassociate_fixed_ip: function(){
|
||||||
ptg = $("#fixed_ip").attr("data-ptg")
|
ptg = $("#fixed_ip").attr("data-ptg")
|
||||||
|
$("#errors").hide().text("")
|
||||||
subnet = $("#fixed_ip").attr("data-subnet")
|
subnet = $("#fixed_ip").attr("data-subnet")
|
||||||
value = ptg + ":" + subnet
|
value = ptg + ":" + subnet
|
||||||
selected_element = $(".multiple-checkbox #id_network li input[value^='"+ ptg +"']");
|
selected_element = $(".multiple-checkbox #id_network li input[value^='"+ ptg +"']");
|
||||||
|
@ -197,14 +227,16 @@ member = {
|
||||||
$("#selected_network li[name^='"+ ptg +"'] strong").text("")
|
$("#selected_network li[name^='"+ ptg +"'] strong").text("")
|
||||||
$("#fixed_ip_div").hide()
|
$("#fixed_ip_div").hide()
|
||||||
$("ul#selected_network li").css("background-color", "");
|
$("ul#selected_network li").css("background-color", "");
|
||||||
|
member.control_max_instances()
|
||||||
},
|
},
|
||||||
groups_init: function() {
|
groups_init: function() {
|
||||||
// Initialise the drag and drop group list
|
// Initialise the drag and drop group list
|
||||||
member.generate_grouplist_html();
|
member.generate_grouplist_html();
|
||||||
|
|
||||||
// allocate fixed ip
|
// allocate fixed ip
|
||||||
$(document).on('click', "ul#selected_network li", function(){
|
$(document).on('click', "ul#selected_network li", function(e){
|
||||||
member.allow_fixed_ip(this);
|
member.allow_fixed_ip(this);
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#set_ip_button").click(function(){
|
$("#set_ip_button").click(function(){
|
||||||
|
@ -214,5 +246,9 @@ member = {
|
||||||
$("#remove").click(function(){
|
$("#remove").click(function(){
|
||||||
member.disassociate_fixed_ip()
|
member.disassociate_fixed_ip()
|
||||||
});
|
});
|
||||||
|
help = $("label[for=id_count]").parent().find('span.help-icon')
|
||||||
|
title = help.attr("title")
|
||||||
|
title = title + " Fixed IP can be assigned only when Instance Count is 1"
|
||||||
|
help.attr("title", title)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue