Browse Source

Prevent configuring fixed IP if building more than one member

Change-Id: Ib2be0fa8742d0d066ec1115bfbfb3209a7c2d1f3
Closes-Bug: #1582527
tags/5.0.0
ank 3 years ago
parent
commit
0d1f36ac0b

+ 1
- 1
gbpui/panels/policytargets/templates/policytargets/_update_groups.html View File

@@ -53,8 +53,8 @@
53 53
               <input id="fixed_ip" type="text"/>
54 54
               <input id="set_ip_button" type="button" value="Add"/>
55 55
               <input id="remove" type="button" value="Remove"/>
56
-              <p id="errors" style="color:red" ></p>
57 56
             </div>
57
+            <div id="errors" class="alert alert-message alert-danger" style="display:none"></div>
58 58
       </td>
59 59
     </tr>
60 60
   </tbody>

+ 3
- 2
gbpui/panels/policytargets/views.py View File

@@ -298,7 +298,7 @@ def check_ip_availability(request):
298 298
     fixed_ip = request.GET.get('fixed_ip')
299 299
     response = {'error': 'IP address is not within the allocated pool range'}
300 300
     subnets = request.GET.get('subnets')
301
-    subnets = subnets.split(";")
301
+    subnets = subnets.split(":")
302 302
     for subnet in subnets:
303 303
         subnet_details = subnet.split(",")
304 304
         try:
@@ -306,7 +306,8 @@ def check_ip_availability(request):
306 306
                 if IPAddress(fixed_ip) >= IPAddress(subnet_details[1]) and \
307 307
                         IPAddress(fixed_ip) <= IPAddress(subnet_details[2]):
308 308
                     fixed_ips = "ip_address=" + fixed_ip
309
-                    ports = api.neutron.port_list(request, fixed_ips=fixed_ips)
309
+                    ports = api.neutron.port_list(request,
310
+                        tenant_id=request.user.tenant_id, fixed_ips=fixed_ips)
310 311
                     if ports:
311 312
                         response = {"inuse": False,
312 313
                                     "error": "IP address already in use"}

+ 9
- 3
gbpui/panels/policytargets/workflows.py View File

@@ -415,7 +415,7 @@ class SetGroupAction(workflows.Action):
415 415
                 if subnet_dedails is None:
416 416
                     subnet_dedails = subnet['cidr']
417 417
                 else:
418
-                    subnet_dedails = ";" + subnet['cidr']
418
+                    subnet_dedails = subnet_dedails + ";" + subnet['cidr']
419 419
                 allocation_pools = subnet['allocation_pools']
420 420
                 if allocation_pools:
421 421
                     start = allocation_pools[0]['start']
@@ -430,7 +430,13 @@ class SetGroupAction(workflows.Action):
430 430
 
431 431
     class Meta(object):
432 432
         name = _("Groups")
433
-        help_text = _("Select groups for launching the member instance in.")
433
+
434
+    def clean(self):
435
+        cleaned_data = super(SetGroupAction, self).clean()
436
+        if not cleaned_data.get("network", None):
437
+            raise forms.ValidationError(_(
438
+                'At least one group must be selected.'))
439
+        return cleaned_data
434 440
 
435 441
     def populate_network_choices(self, request, context):
436 442
         try:
@@ -446,7 +452,7 @@ class SetGroupAction(workflows.Action):
446 452
                         if subnet_dedails is None:
447 453
                             subnet_dedails = subnet['cidr']
448 454
                         else:
449
-                            subnet_dedails = ";" + subnet['cidr']
455
+                            subnet_dedails += ";" + subnet['cidr']
450 456
                         allocation_pools = subnet['allocation_pools']
451 457
                         if allocation_pools:
452 458
                             start = allocation_pools[0]['start']

+ 45
- 9
gbpui/static/dashboard/js/member.js View File

@@ -59,9 +59,10 @@ member = {
59 59
          $("ul#available_group li[name^='"+ ptg +"']").css("background-color", "");
60 60
          $("#fixed_ip_div").hide()
61 61
        }
62
+       member.control_max_instances()
62 63
     };
63 64
     var updateForm = function() {
64
-      var groupListId = $("#groupListId");
65
+      var groupListId = $("#groupListId .multiple-checkbox");
65 66
       var lists = groupListId.find("li").attr('data-index',100);
66 67
       var active_groups = $("#selected_network > li").map(function(){
67 68
         return $(this).attr("name");
@@ -83,7 +84,7 @@ member = {
83 84
     };
84 85
 
85 86
     $("#groupListSortContainer").show();
86
-    $("#groupListIdContainer").hide();
87
+    $("#groupListId .form-group").hide()
87 88
     self.init_group_list();
88 89
     // Make sure we don't duplicate the groups in the list
89 90
     available_group.empty();
@@ -124,11 +125,25 @@ member = {
124 125
       }
125 126
     }).disableSelection();
126 127
   },
127
-
128
+  control_max_instances: function(){
129
+      $("#id_count").attr('readonly', false)
130
+      $("#id_network").each(function() {
131
+         $input = $(this).find('li input');
132
+         value = $input.val();
133
+         fields = value.split(":")
134
+         if ($input.is(":checked") && fields.length == 3){
135
+          // fixed ip is associated, dont allow Instance Count > 1
136
+          $("#id_count").attr('readonly', true)
137
+          return
138
+         }
139
+      });
140
+  },
128 141
   allow_fixed_ip: function(selected_group){
142
+      if (member.allowed() == false)
143
+        return
129 144
       fixed_ip = ""
130 145
       $("#fixed_ip").val("")
131
-      $("#errors").text("")
146
+      $("#errors").hide().text("")
132 147
       $("#fixed_ip_div").show()
133 148
       ptg = $(selected_group).attr('name')
134 149
       $(selected_group).siblings().css( "background-color", "");
@@ -152,12 +167,23 @@ member = {
152 167
       if (values.length == 3)
153 168
         $("#fixed_ip").val(values[2]);
154 169
   },
170
+  allowed: function(){
171
+      if($("#id_count").val() > 1){
172
+        $("#errors").show().text("You cannot assign fixed IPs " +
173
+          "if more than one instance is requested.")
174
+        return false
175
+      }
176
+      return true
177
+  },
155 178
   associate_fixed_ip: function(){
179
+      if (member.allowed() == false)
180
+        return
156 181
       ptg = $("#fixed_ip").attr("data-ptg")
157 182
       subnet = $("#fixed_ip").attr("data-subnet")
183
+      subnet = subnet.replace(";", ":")
158 184
       fixed_ip = $("#fixed_ip").val()
159 185
       if (!fixed_ip || 0 === fixed_ip.length ){
160
-        $("#errors").text("Enter valid IP address")
186
+        $("#errors").show().text("Enter valid IP address")
161 187
         return
162 188
       }
163 189
       $.ajax({
@@ -167,6 +193,7 @@ member = {
167 193
         success: function(response) {
168 194
           if(response.inuse){
169 195
             horizon.alert('success', "IP address '" + fixed_ip +"' is available.")
196
+            subnet = subnet.replace(":", ";")
170 197
             value = ptg + ":" + subnet + ":" + fixed_ip
171 198
             selected_element = $(".multiple-checkbox #id_network li input[value^='"+ ptg +"']");
172 199
             selected_element.val(value)
@@ -178,18 +205,21 @@ member = {
178 205
             }
179 206
             $("ul#selected_network li[name^='"+ ptg +"']").css("background-color", "");
180 207
             $("#fixed_ip_div").hide()
208
+            $("#errors").hide().text("")
209
+            member.control_max_instances()
181 210
           }
182 211
           else{
183
-            $("#errors").text(response.error)
212
+            $("#errors").show().text(response.error)
184 213
           }
185 214
         },
186 215
         error: function(response) {
187
-          $("#errors").text(response)
216
+          $("#errors").show().text(response)
188 217
         }
189 218
       });
190 219
   },
191 220
   disassociate_fixed_ip: function(){
192 221
     ptg = $("#fixed_ip").attr("data-ptg")
222
+    $("#errors").hide().text("")
193 223
     subnet = $("#fixed_ip").attr("data-subnet")
194 224
     value = ptg + ":" + subnet
195 225
     selected_element = $(".multiple-checkbox #id_network li input[value^='"+ ptg +"']");
@@ -197,14 +227,16 @@ member = {
197 227
     $("#selected_network li[name^='"+ ptg +"'] strong").text("")
198 228
     $("#fixed_ip_div").hide()
199 229
     $("ul#selected_network li").css("background-color", "");
230
+    member.control_max_instances()
200 231
   },
201 232
   groups_init: function() {
202 233
     // Initialise the drag and drop group list
203 234
     member.generate_grouplist_html();
204
-
205 235
     // allocate fixed ip
206
-    $(document).on('click', "ul#selected_network li", function(){
236
+    $(document).on('click', "ul#selected_network li", function(e){
207 237
       member.allow_fixed_ip(this);
238
+      e.preventDefault();
239
+      e.stopPropagation();
208 240
     });
209 241
 
210 242
     $("#set_ip_button").click(function(){
@@ -214,5 +246,9 @@ member = {
214 246
     $("#remove").click(function(){
215 247
       member.disassociate_fixed_ip()
216 248
     });
249
+    help = $("label[for=id_count]").parent().find('span.help-icon')
250
+    title = help.attr("title")
251
+    title = title + " Fixed IP can be assigned only when Instance Count is 1"
252
+    help.attr("title", title)
217 253
   }
218 254
 };

Loading…
Cancel
Save