summaryrefslogtreecommitdiff
path: root/openstack_dashboard/dashboards/admin/networks
diff options
context:
space:
mode:
Diffstat (limited to 'openstack_dashboard/dashboards/admin/networks')
-rw-r--r--openstack_dashboard/dashboards/admin/networks/forms.py22
-rw-r--r--openstack_dashboard/dashboards/admin/networks/tests.py69
-rw-r--r--openstack_dashboard/dashboards/admin/networks/workflows.py2
3 files changed, 92 insertions, 1 deletions
diff --git a/openstack_dashboard/dashboards/admin/networks/forms.py b/openstack_dashboard/dashboards/admin/networks/forms.py
index ae5dbca..b95bff2 100644
--- a/openstack_dashboard/dashboards/admin/networks/forms.py
+++ b/openstack_dashboard/dashboards/admin/networks/forms.py
@@ -139,6 +139,12 @@ class CreateNetwork(forms.SelfHandlingForm):
139 }), 139 }),
140 initial=True, 140 initial=True,
141 required=False) 141 required=False)
142 az_hints = forms.MultipleChoiceField(
143 label=_("Availability Zone Hints"),
144 required=False,
145 help_text=_("Availability zones where the DHCP agents may be "
146 "scheduled. Leaving this unset is equivalent to "
147 "selecting all availability zones"))
142 148
143 @classmethod 149 @classmethod
144 def _instantiate(cls, request, *args, **kwargs): 150 def _instantiate(cls, request, *args, **kwargs):
@@ -237,6 +243,20 @@ class CreateNetwork(forms.SelfHandlingForm):
237 else: 243 else:
238 self.fields['network_type'].choices = network_type_choices 244 self.fields['network_type'].choices = network_type_choices
239 245
246 try:
247 if api.neutron.is_extension_supported(request,
248 'network_availability_zone'):
249 zones = api.neutron.list_availability_zones(
250 self.request, 'network', 'available')
251 self.fields['az_hints'].choices = [(zone['name'], zone['name'])
252 for zone in zones]
253 else:
254 del self.fields['az_hints']
255 except Exception:
256 msg = _('Failed to get availability zone list.')
257 messages.warning(request, msg)
258 del self.fields['az_hints']
259
240 def _hide_provider_network_type(self): 260 def _hide_provider_network_type(self):
241 self.fields['network_type'].widget = forms.HiddenInput() 261 self.fields['network_type'].widget = forms.HiddenInput()
242 self.fields['physical_network'].widget = forms.HiddenInput() 262 self.fields['physical_network'].widget = forms.HiddenInput()
@@ -261,6 +281,8 @@ class CreateNetwork(forms.SelfHandlingForm):
261 if network_type in self.nettypes_with_seg_id: 281 if network_type in self.nettypes_with_seg_id:
262 params['provider:segmentation_id'] = ( 282 params['provider:segmentation_id'] = (
263 data['segmentation_id']) 283 data['segmentation_id'])
284 if 'az_hints' in data and data['az_hints']:
285 params['availability_zone_hints'] = data['az_hints']
264 network = api.neutron.network_create(request, **params) 286 network = api.neutron.network_create(request, **params)
265 LOG.debug('Network %s was successfully created.', data['name']) 287 LOG.debug('Network %s was successfully created.', data['name'])
266 return network 288 return network
diff --git a/openstack_dashboard/dashboards/admin/networks/tests.py b/openstack_dashboard/dashboards/admin/networks/tests.py
index f3e4312..34f64af 100644
--- a/openstack_dashboard/dashboards/admin/networks/tests.py
+++ b/openstack_dashboard/dashboards/admin/networks/tests.py
@@ -464,6 +464,9 @@ class NetworkTests(test.BaseAdminViewTests):
464 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider').\ 464 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider').\
465 MultipleTimes().AndReturn(True) 465 MultipleTimes().AndReturn(True)
466 api.neutron.is_extension_supported(IsA(http.HttpRequest), 466 api.neutron.is_extension_supported(IsA(http.HttpRequest),
467 'network_availability_zone').\
468 MultipleTimes().AndReturn(False)
469 api.neutron.is_extension_supported(IsA(http.HttpRequest),
467 'subnet_allocation').\ 470 'subnet_allocation').\
468 MultipleTimes().AndReturn(True) 471 MultipleTimes().AndReturn(True)
469 api.neutron.subnetpool_list(IsA(http.HttpRequest)).\ 472 api.neutron.subnetpool_list(IsA(http.HttpRequest)).\
@@ -486,6 +489,57 @@ class NetworkTests(test.BaseAdminViewTests):
486 self.assertRedirectsNoFollow(res, INDEX_URL) 489 self.assertRedirectsNoFollow(res, INDEX_URL)
487 490
488 @test.create_stubs({api.neutron: ('network_create', 491 @test.create_stubs({api.neutron: ('network_create',
492 'is_extension_supported',
493 'list_availability_zones',
494 'subnetpool_list'),
495 api.keystone: ('tenant_list',)})
496 def test_network_create_post_with_az(self):
497 tenants = self.tenants.list()
498 tenant_id = self.tenants.first().id
499 network = self.networks.first()
500
501 api.keystone.tenant_list(IsA(http.HttpRequest))\
502 .AndReturn([tenants, False])
503 params = {'name': network.name,
504 'tenant_id': tenant_id,
505 'admin_state_up': network.admin_state_up,
506 'router:external': True,
507 'shared': True,
508 'provider:network_type': 'local',
509 'with_subnet': False,
510 'az_hints': ['nova']}
511 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider').\
512 MultipleTimes().AndReturn(True)
513 api.neutron.is_extension_supported(IsA(http.HttpRequest),
514 'network_availability_zone').\
515 MultipleTimes().AndReturn(True)
516 api.neutron.list_availability_zones(IsA(http.HttpRequest),
517 "network", "available")\
518 .AndReturn(self.neutron_availability_zones.list())
519 api.neutron.is_extension_supported(IsA(http.HttpRequest),
520 'subnet_allocation').\
521 MultipleTimes().AndReturn(True)
522 api.neutron.subnetpool_list(IsA(http.HttpRequest)).\
523 AndReturn(self.subnetpools.list())
524 api.neutron.network_create(IsA(http.HttpRequest), **params)\
525 .AndReturn(network)
526
527 self.mox.ReplayAll()
528
529 form_data = {'tenant_id': tenant_id,
530 'name': network.name,
531 'admin_state': network.admin_state_up,
532 'external': True,
533 'shared': True,
534 'network_type': 'local',
535 'availability_zone_hints': ['nova']}
536 url = reverse('horizon:admin:networks:create')
537 res = self.client.post(url, form_data)
538
539 self.assertNoFormErrors(res)
540 self.assertRedirectsNoFollow(res, INDEX_URL)
541
542 @test.create_stubs({api.neutron: ('network_create',
489 'subnet_create', 543 'subnet_create',
490 'is_extension_supported', 544 'is_extension_supported',
491 'subnetpool_list'), 545 'subnetpool_list'),
@@ -509,6 +563,9 @@ class NetworkTests(test.BaseAdminViewTests):
509 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider').\ 563 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider').\
510 MultipleTimes().AndReturn(True) 564 MultipleTimes().AndReturn(True)
511 api.neutron.is_extension_supported(IsA(http.HttpRequest), 565 api.neutron.is_extension_supported(IsA(http.HttpRequest),
566 'network_availability_zone').\
567 MultipleTimes().AndReturn(False)
568 api.neutron.is_extension_supported(IsA(http.HttpRequest),
512 'subnet_allocation').\ 569 'subnet_allocation').\
513 MultipleTimes().AndReturn(True) 570 MultipleTimes().AndReturn(True)
514 api.neutron.subnetpool_list(IsA(http.HttpRequest)).\ 571 api.neutron.subnetpool_list(IsA(http.HttpRequest)).\
@@ -552,6 +609,9 @@ class NetworkTests(test.BaseAdminViewTests):
552 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider').\ 609 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider').\
553 MultipleTimes().AndReturn(True) 610 MultipleTimes().AndReturn(True)
554 api.neutron.is_extension_supported(IsA(http.HttpRequest), 611 api.neutron.is_extension_supported(IsA(http.HttpRequest),
612 'network_availability_zone').\
613 MultipleTimes().AndReturn(False)
614 api.neutron.is_extension_supported(IsA(http.HttpRequest),
555 'subnet_allocation').\ 615 'subnet_allocation').\
556 MultipleTimes().AndReturn(True) 616 MultipleTimes().AndReturn(True)
557 api.neutron.subnetpool_list(IsA(http.HttpRequest)).\ 617 api.neutron.subnetpool_list(IsA(http.HttpRequest)).\
@@ -581,6 +641,9 @@ class NetworkTests(test.BaseAdminViewTests):
581 api.keystone.tenant_list( 641 api.keystone.tenant_list(
582 IsA(http.HttpRequest) 642 IsA(http.HttpRequest)
583 ).MultipleTimes().AndReturn([tenants, False]) 643 ).MultipleTimes().AndReturn([tenants, False])
644 api.neutron.is_extension_supported(IsA(http.HttpRequest),
645 'network_availability_zone').\
646 MultipleTimes().AndReturn(False)
584 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider')\ 647 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider')\
585 .MultipleTimes().AndReturn(True) 648 .MultipleTimes().AndReturn(True)
586 649
@@ -611,6 +674,9 @@ class NetworkTests(test.BaseAdminViewTests):
611 IsA(http.HttpRequest) 674 IsA(http.HttpRequest)
612 ).MultipleTimes().AndReturn([tenants, False]) 675 ).MultipleTimes().AndReturn([tenants, False])
613 676
677 api.neutron.is_extension_supported(IsA(http.HttpRequest),
678 'network_availability_zone').\
679 MultipleTimes().AndReturn(False)
614 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider').\ 680 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider').\
615 MultipleTimes().AndReturn(True) 681 MultipleTimes().AndReturn(True)
616 self.mox.ReplayAll() 682 self.mox.ReplayAll()
@@ -642,6 +708,9 @@ class NetworkTests(test.BaseAdminViewTests):
642 IsA(http.HttpRequest) 708 IsA(http.HttpRequest)
643 ).MultipleTimes().AndReturn([tenants, False]) 709 ).MultipleTimes().AndReturn([tenants, False])
644 710
711 api.neutron.is_extension_supported(IsA(http.HttpRequest),
712 'network_availability_zone').\
713 MultipleTimes().AndReturn(False)
645 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider')\ 714 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider')\
646 .MultipleTimes().AndReturn(True) 715 .MultipleTimes().AndReturn(True)
647 716
diff --git a/openstack_dashboard/dashboards/admin/networks/workflows.py b/openstack_dashboard/dashboards/admin/networks/workflows.py
index ff98b33..d8925ae 100644
--- a/openstack_dashboard/dashboards/admin/networks/workflows.py
+++ b/openstack_dashboard/dashboards/admin/networks/workflows.py
@@ -44,7 +44,7 @@ class CreateNetworkInfoAction(network_workflows.CreateNetworkInfoAction):
44 44
45class CreateNetworkInfo(network_workflows.CreateNetworkInfo): 45class CreateNetworkInfo(network_workflows.CreateNetworkInfo):
46 action_class = CreateNetworkInfoAction 46 action_class = CreateNetworkInfoAction
47 contributes = ("net_name", "admin_state", "with_subnet") 47 contributes = ("net_name", "admin_state", "with_subnet", "az_hints")
48 48
49 def __init__(self, workflow): 49 def __init__(self, workflow):
50 self.contributes = tuple(workflow.create_network_form.fields.keys()) 50 self.contributes = tuple(workflow.create_network_form.fields.keys())