Browse Source

Merge "Use BooleanField for admin_state_up form" into stable/ocata

Jenkins 1 year ago
parent
commit
3bc399f3ae

+ 7
- 9
openstack_dashboard/dashboards/admin/networks/forms.py View File

@@ -125,10 +125,9 @@ class CreateNetwork(forms.SelfHandlingForm):
125 125
             'class': 'switched',
126 126
             'data-switch-on': 'network_type',
127 127
         }))
128
-    admin_state = forms.ThemableChoiceField(
129
-        choices=[('True', _('UP')),
130
-                 ('False', _('DOWN'))],
131
-        label=_("Admin State"))
128
+    admin_state = forms.BooleanField(label=_("Enable Admin State"),
129
+                                     initial=True,
130
+                                     required=False)
132 131
     shared = forms.BooleanField(label=_("Shared"),
133 132
                                 initial=False, required=False)
134 133
     external = forms.BooleanField(label=_("External Network"),
@@ -246,7 +245,7 @@ class CreateNetwork(forms.SelfHandlingForm):
246 245
         try:
247 246
             params = {'name': data['name'],
248 247
                       'tenant_id': data['tenant_id'],
249
-                      'admin_state_up': (data['admin_state'] == 'True'),
248
+                      'admin_state_up': data['admin_state'],
250 249
                       'shared': data['shared'],
251 250
                       'router:external': data['external']}
252 251
             if api.neutron.is_port_profiles_supported():
@@ -312,9 +311,8 @@ class UpdateNetwork(forms.SelfHandlingForm):
312 311
     network_id = forms.CharField(label=_("ID"),
313 312
                                  widget=forms.TextInput(
314 313
                                      attrs={'readonly': 'readonly'}))
315
-    admin_state = forms.ThemableChoiceField(choices=[(True, _('UP')),
316
-                                                     (False, _('DOWN'))],
317
-                                            label=_("Admin State"))
314
+    admin_state = forms.BooleanField(label=_("Enable Admin State"),
315
+                                     required=False)
318 316
     shared = forms.BooleanField(label=_("Shared"), required=False)
319 317
     external = forms.BooleanField(label=_("External Network"), required=False)
320 318
     failure_url = 'horizon:admin:networks:index'
@@ -322,7 +320,7 @@ class UpdateNetwork(forms.SelfHandlingForm):
322 320
     def handle(self, request, data):
323 321
         try:
324 322
             params = {'name': data['name'],
325
-                      'admin_state_up': (data['admin_state'] == 'True'),
323
+                      'admin_state_up': data['admin_state'],
326 324
                       'shared': data['shared'],
327 325
                       'router:external': data['external']}
328 326
             network = api.neutron.network_update(request,

+ 1
- 2
openstack_dashboard/dashboards/admin/networks/ports/forms.py View File

@@ -158,7 +158,7 @@ class CreatePort(forms.SelfHandlingForm):
158 158
             params = {
159 159
                 'tenant_id': network.tenant_id,
160 160
                 'network_id': data['network_id'],
161
-                'admin_state_up': data['admin_state'] == 'True',
161
+                'admin_state_up': data['admin_state'],
162 162
                 'name': data['name'],
163 163
                 'device_id': data['device_id'],
164 164
                 'device_owner': data['device_owner'],
@@ -214,7 +214,6 @@ class UpdatePort(project_forms.UpdatePort):
214 214
         try:
215 215
             LOG.debug('params = %s' % data)
216 216
             extension_kwargs = {}
217
-            data['admin_state'] = (data['admin_state'] == 'True')
218 217
             if 'binding__vnic_type' in data:
219 218
                 extension_kwargs['binding__vnic_type'] = \
220 219
                     data['binding__vnic_type']

+ 2
- 4
openstack_dashboard/dashboards/project/firewalls/forms.py View File

@@ -134,9 +134,8 @@ class UpdateFirewall(forms.SelfHandlingForm):
134 134
                                   label=_("Description"),
135 135
                                   required=False)
136 136
     firewall_policy_id = forms.ThemableChoiceField(label=_("Policy"))
137
-    admin_state_up = forms.ThemableChoiceField(choices=[(True, _('UP')),
138
-                                                        (False, _('DOWN'))],
139
-                                               label=_("Admin State"))
137
+    admin_state_up = forms.BooleanField(label=_("Enable Admin State"),
138
+                                        required=False)
140 139
 
141 140
     failure_url = 'horizon:project:firewalls:index'
142 141
 
@@ -165,7 +164,6 @@ class UpdateFirewall(forms.SelfHandlingForm):
165 164
     def handle(self, request, context):
166 165
         firewall_id = self.initial['firewall_id']
167 166
         name_or_id = context.get('name') or firewall_id
168
-        context['admin_state_up'] = (context['admin_state_up'] == 'True')
169 167
         try:
170 168
             firewall = api.fwaas.firewall_update(request, firewall_id,
171 169
                                                  **context)

+ 3
- 8
openstack_dashboard/dashboards/project/firewalls/workflows.py View File

@@ -327,9 +327,9 @@ class AddFirewallAction(workflows.Action):
327 327
                                   label=_("Description"),
328 328
                                   required=False)
329 329
     firewall_policy_id = forms.ThemableChoiceField(label=_("Policy"))
330
-    admin_state_up = forms.ThemableChoiceField(choices=[(True, _('UP')),
331
-                                                        (False, _('DOWN'))],
332
-                                               label=_("Admin State"))
330
+    admin_state_up = forms.BooleanField(label=_("Enable Admin State"),
331
+                                        initial=True,
332
+                                        required=False)
333 333
 
334 334
     def __init__(self, request, *args, **kwargs):
335 335
         super(AddFirewallAction, self).__init__(request, *args, **kwargs)
@@ -364,11 +364,6 @@ class AddFirewallStep(workflows.Step):
364 364
     contributes = ("name", "firewall_policy_id", "description",
365 365
                    "admin_state_up")
366 366
 
367
-    def contribute(self, data, context):
368
-        context = super(AddFirewallStep, self).contribute(data, context)
369
-        context['admin_state_up'] = (context['admin_state_up'] == 'True')
370
-        return context
371
-
372 367
 
373 368
 class AddFirewall(workflows.Workflow):
374 369
     slug = "addfirewall"

+ 3
- 6
openstack_dashboard/dashboards/project/networks/forms.py View File

@@ -38,11 +38,8 @@ class UpdateNetwork(forms.SelfHandlingForm):
38 38
     network_id = forms.CharField(label=_("ID"),
39 39
                                  widget=forms.TextInput(
40 40
                                      attrs={'readonly': 'readonly'}))
41
-    admin_state = forms.ThemableChoiceField(
42
-        choices=[('True', _('UP')),
43
-                 ('False', _('DOWN'))],
44
-        required=False,
45
-        label=_("Admin State"))
41
+    admin_state = forms.BooleanField(label=_("Enable Admin State"),
42
+                                     required=False)
46 43
     shared = forms.BooleanField(label=_("Shared"), required=False)
47 44
     failure_url = 'horizon:project:networks:index'
48 45
 
@@ -54,7 +51,7 @@ class UpdateNetwork(forms.SelfHandlingForm):
54 51
 
55 52
     def handle(self, request, data):
56 53
         try:
57
-            params = {'admin_state_up': (data['admin_state'] == 'True'),
54
+            params = {'admin_state_up': data['admin_state'],
58 55
                       'name': data['name']}
59 56
             # Make sure we are not sending shared data when the user
60 57
             # doesnt'have admin rights because even if the user doesn't

+ 2
- 5
openstack_dashboard/dashboards/project/networks/ports/forms.py View File

@@ -38,10 +38,8 @@ class UpdatePort(forms.SelfHandlingForm):
38 38
     name = forms.CharField(max_length=255,
39 39
                            label=_("Name"),
40 40
                            required=False)
41
-    admin_state = forms.ThemableChoiceField(
42
-        choices=[('True', _('UP')),
43
-                 ('False', _('DOWN'))],
44
-        label=_("Admin State"))
41
+    admin_state = forms.BooleanField(label=_("Enable Admin State"),
42
+                                     required=False)
45 43
     failure_url = 'horizon:project:networks:detail'
46 44
 
47 45
     def __init__(self, request, *args, **kwargs):
@@ -81,7 +79,6 @@ class UpdatePort(forms.SelfHandlingForm):
81 79
             exceptions.handle(self.request, msg)
82 80
 
83 81
     def handle(self, request, data):
84
-        data['admin_state'] = (data['admin_state'] == 'True')
85 82
         try:
86 83
             LOG.debug('params = %s' % data)
87 84
             extension_kwargs = {}

+ 5
- 7
openstack_dashboard/dashboards/project/networks/workflows.py View File

@@ -45,13 +45,11 @@ class CreateNetworkInfoAction(workflows.Action):
45 45
                                                required=False,
46 46
                                                widget=widget)
47 47
 
48
-    admin_state = forms.ThemableChoiceField(
49
-        choices=[(True, _('UP')),
50
-                 (False, _('DOWN'))],
51
-        label=_("Admin State"),
48
+    admin_state = forms.BooleanField(
49
+        label=_("Enable Admin State"),
50
+        initial=True,
52 51
         required=False,
53
-        help_text=_("The state to start"
54
-                    " the network in."))
52
+        help_text=_("The state to start the network in."))
55 53
     shared = forms.BooleanField(label=_("Shared"), initial=False,
56 54
                                 required=False)
57 55
     with_subnet = forms.BooleanField(label=_("Create Subnet"),
@@ -493,7 +491,7 @@ class CreateNetwork(workflows.Workflow):
493 491
     def _create_network(self, request, data):
494 492
         try:
495 493
             params = {'name': data['net_name'],
496
-                      'admin_state_up': (data['admin_state'] == 'True'),
494
+                      'admin_state_up': data['admin_state'],
497 495
                       'shared': data['shared']}
498 496
             if api.neutron.is_port_profiles_supported():
499 497
                 params['net_profile_id'] = data['net_profile_id']

+ 6
- 8
openstack_dashboard/dashboards/project/routers/forms.py View File

@@ -34,10 +34,9 @@ LOG = logging.getLogger(__name__)
34 34
 class CreateForm(forms.SelfHandlingForm):
35 35
     name = forms.CharField(max_length=255, label=_("Router Name"),
36 36
                            required=False)
37
-    admin_state_up = forms.ThemableChoiceField(label=_("Admin State"),
38
-                                               choices=[(True, _('UP')),
39
-                                                        (False, _('DOWN'))],
40
-                                               required=False)
37
+    admin_state_up = forms.BooleanField(label=_("Enable Admin State"),
38
+                                        initial=True,
39
+                                        required=False)
41 40
     external_network = forms.ThemableChoiceField(label=_("External Network"),
42 41
                                                  required=False)
43 42
     mode = forms.ChoiceField(label=_("Router Type"))
@@ -116,9 +115,8 @@ class CreateForm(forms.SelfHandlingForm):
116 115
 
117 116
 class UpdateForm(forms.SelfHandlingForm):
118 117
     name = forms.CharField(label=_("Name"), required=False)
119
-    admin_state = forms.ThemableChoiceField(choices=[(True, _('UP')),
120
-                                                     (False, _('DOWN'))],
121
-                                            label=_("Admin State"))
118
+    admin_state = forms.BooleanField(label=_("Enable Admin State"),
119
+                                     required=False)
122 120
     router_id = forms.CharField(label=_("ID"),
123 121
                                 widget=forms.TextInput(
124 122
                                     attrs={'readonly': 'readonly'}))
@@ -155,7 +153,7 @@ class UpdateForm(forms.SelfHandlingForm):
155 153
 
156 154
     def handle(self, request, data):
157 155
         try:
158
-            params = {'admin_state_up': (data['admin_state'] == 'True'),
156
+            params = {'admin_state_up': data['admin_state'],
159 157
                       'name': data['name']}
160 158
             if self.dvr_allowed:
161 159
                 params['distributed'] = (data['mode'] == 'distributed')

+ 5
- 5
openstack_dashboard/dashboards/project/routers/tests.py View File

@@ -264,7 +264,7 @@ class RouterActionTests(RouterMixin, test.TestCase):
264 264
         api.neutron.network_list(IsA(http.HttpRequest))\
265 265
             .AndReturn(self.networks.list())
266 266
         params = {'name': router.name,
267
-                  'admin_state_up': str(router.admin_state_up)}
267
+                  'admin_state_up': router.admin_state_up}
268 268
         api.neutron.router_create(IsA(http.HttpRequest), **params)\
269 269
             .AndReturn(router)
270 270
 
@@ -291,7 +291,7 @@ class RouterActionTests(RouterMixin, test.TestCase):
291 291
         api.neutron.network_list(IsA(http.HttpRequest))\
292 292
             .AndReturn(self.networks.list())
293 293
         params = {'name': router.name,
294
-                  'admin_state_up': str(router.admin_state_up)}
294
+                  'admin_state_up': router.admin_state_up}
295 295
         api.neutron.router_create(IsA(http.HttpRequest), **params)\
296 296
             .AndReturn(router)
297 297
 
@@ -322,7 +322,7 @@ class RouterActionTests(RouterMixin, test.TestCase):
322 322
         param = {'name': router.name,
323 323
                  'distributed': True,
324 324
                  'ha': True,
325
-                 'admin_state_up': str(router.admin_state_up)}
325
+                 'admin_state_up': router.admin_state_up}
326 326
         api.neutron.router_create(IsA(http.HttpRequest), **param)\
327 327
             .AndReturn(router)
328 328
 
@@ -352,7 +352,7 @@ class RouterActionTests(RouterMixin, test.TestCase):
352 352
         api.neutron.network_list(IsA(http.HttpRequest))\
353 353
             .MultipleTimes().AndReturn(self.networks.list())
354 354
         params = {'name': router.name,
355
-                  'admin_state_up': str(router.admin_state_up)}
355
+                  'admin_state_up': router.admin_state_up}
356 356
         api.neutron.router_create(IsA(http.HttpRequest), **params)\
357 357
             .AndRaise(self.exceptions.neutron)
358 358
         self.mox.ReplayAll()
@@ -380,7 +380,7 @@ class RouterActionTests(RouterMixin, test.TestCase):
380 380
         api.neutron.network_list(IsA(http.HttpRequest))\
381 381
             .MultipleTimes().AndReturn(self.networks.list())
382 382
         params = {'name': router.name,
383
-                  'admin_state_up': str(router.admin_state_up)}
383
+                  'admin_state_up': router.admin_state_up}
384 384
         api.neutron.router_create(IsA(http.HttpRequest), **params)\
385 385
             .AndRaise(self.exceptions.neutron)
386 386
         self.mox.ReplayAll()

+ 4
- 10
openstack_dashboard/dashboards/project/vpn/forms.py View File

@@ -34,15 +34,12 @@ class UpdateVPNService(forms.SelfHandlingForm):
34 34
         widget=forms.TextInput(attrs={'readonly': 'readonly'}))
35 35
     description = forms.CharField(
36 36
         required=False, max_length=80, label=_("Description"))
37
-    admin_state_up = forms.ChoiceField(choices=[(True, _('UP')),
38
-                                                (False, _('DOWN'))],
39
-                                       label=_("Admin State"),
40
-                                       required=False)
37
+    admin_state_up = forms.BooleanField(label=_("Enable Admin State"),
38
+                                        required=False)
41 39
 
42 40
     failure_url = 'horizon:project:vpn:index'
43 41
 
44 42
     def handle(self, request, context):
45
-        context['admin_state_up'] = (context['admin_state_up'] == 'True')
46 43
         try:
47 44
             data = {'vpnservice': {'name': context['name'],
48 45
                                    'description': context['description'],
@@ -279,10 +276,8 @@ class UpdateIPSecSiteConnection(forms.SelfHandlingForm):
279 276
         required=False,
280 277
         choices=[('bi-directional', _('bi-directional')),
281 278
                  ('response-only', _('response-only'))])
282
-    admin_state_up = forms.ChoiceField(choices=[(True, _('UP')),
283
-                                                (False, _('DOWN'))],
284
-                                       label=_("Admin State"),
285
-                                       required=False)
279
+    admin_state_up = forms.BooleanField(label=_("Enable Admin State"),
280
+                                        required=False)
286 281
 
287 282
     failure_url = 'horizon:project:vpn:index'
288 283
 
@@ -297,7 +292,6 @@ class UpdateIPSecSiteConnection(forms.SelfHandlingForm):
297 292
         return cleaned_data
298 293
 
299 294
     def handle(self, request, context):
300
-        context['admin_state_up'] = (context['admin_state_up'] == 'True')
301 295
         try:
302 296
             data = {'ipsec_site_connection':
303 297
                     {'name': context['name'],

+ 2
- 2
openstack_dashboard/dashboards/project/vpn/templates/vpn/_add_vpn_service_help.html View File

@@ -3,5 +3,5 @@
3 3
 <p>{% trans "Create VPN service for current project." %}</p>
4 4
 <p>{% trans "The VPN service is attached to a router and references to a single subnet to push to a remote site." %}</p>
5 5
 <p>{% trans "Specify a name, description, router, and subnet for the VPN Service." %}</p>
6
-<p>{% trans "Admin State is UP (True) by default." %}</p>
7
-<p>{% trans "The router, subnet and admin state fields are required. All others are optional." %} </p>
6
+<p>{% trans "Admin State is enabled by default." %}</p>
7
+<p>{% trans "The router, subnet and admin state fields require to be enabled. All others are optional." %} </p>

+ 11
- 11
openstack_dashboard/dashboards/project/vpn/workflows.py View File

@@ -28,11 +28,11 @@ class AddVPNServiceAction(workflows.Action):
28 28
         max_length=80, label=_("Description"))
29 29
     router_id = forms.ChoiceField(label=_("Router"))
30 30
     subnet_id = forms.ChoiceField(label=_("Subnet"))
31
-    admin_state_up = forms.ChoiceField(
32
-        choices=[(True, _('UP')), (False, _('DOWN'))],
33
-        label=_("Admin State"),
34
-        help_text=_("The state of VPN service to start in. "
35
-                    "If DOWN (False) VPN service does not forward packets."),
31
+    admin_state_up = forms.BooleanField(
32
+        label=_("Enable Admin State"),
33
+        help_text=_("The state of VPN service to start in. If disabled "
34
+                    "(not checked), VPN service does not forward packets."),
35
+        initial=True,
36 36
         required=False)
37 37
 
38 38
     def __init__(self, request, *args, **kwargs):
@@ -426,13 +426,13 @@ class AddIPSecSiteConnectionOptionalAction(workflows.Action):
426 426
         required=False,
427 427
         help_text=_("Valid integer greater than the DPD interval"))
428 428
     initiator = forms.ChoiceField(label=_("Initiator state"), required=False)
429
-    admin_state_up = forms.ChoiceField(
430
-        choices=[(True, _('UP')), (False, _('DOWN'))],
431
-        label=_("Admin State"),
432
-        required=False,
429
+    admin_state_up = forms.BooleanField(
430
+        label=_("Enable Admin State"),
433 431
         help_text=_("The state of IPSec site connection to start in. "
434
-                    "If DOWN (False), IPSec site connection "
435
-                    "does not forward packets."))
432
+                    "If disabled (not checked), IPSec site connection "
433
+                    "does not forward packets."),
434
+        initial=True,
435
+        required=False)
436 436
 
437 437
     def __init__(self, request, *args, **kwargs):
438 438
         super(AddIPSecSiteConnectionOptionalAction, self).__init__(

Loading…
Cancel
Save