Merge "Add fixed network mode for environments"
This commit is contained in:
commit
b82f13986d
@ -16,8 +16,11 @@
|
||||
import re
|
||||
import uuid
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from horizon import exceptions
|
||||
from neutronclient.common import exceptions as exc
|
||||
from openstack_dashboard.api import keystone
|
||||
from openstack_dashboard.api import neutron
|
||||
from oslo_log import log as logging
|
||||
|
||||
@ -35,6 +38,24 @@ NN_HELP = _("OpenStack Networking (Neutron) is not available in current "
|
||||
"environment. Custom Network Settings cannot be applied")
|
||||
|
||||
|
||||
def get_project_assigned_network(request):
|
||||
tenant_id = request.user.tenant_id
|
||||
|
||||
tenant = keystone.tenant_get(request, tenant_id)
|
||||
network_name = getattr(settings, 'FIXED_MURANO_NETWORK', 'murano_network')
|
||||
tenant_network_id = getattr(tenant, network_name, None)
|
||||
if not tenant_network_id:
|
||||
LOG.warning(("murano_network property is not "
|
||||
"defined for project '%s'") % tenant_id)
|
||||
return []
|
||||
|
||||
try:
|
||||
tenant_network = neutron.network_get(request, tenant_network_id)
|
||||
return [((tenant_network.id, None), tenant_network.name_or_id)]
|
||||
except exc.NeutronClientException:
|
||||
return []
|
||||
|
||||
|
||||
def get_available_networks(request, include_subnets=True,
|
||||
filter=None, murano_networks=None):
|
||||
if murano_networks:
|
||||
|
@ -13,6 +13,7 @@
|
||||
# under the License.
|
||||
import ast
|
||||
|
||||
from django.conf import settings
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from horizon import exceptions
|
||||
@ -39,14 +40,30 @@ class CreateEnvironmentForm(horizon_forms.SelfHandlingForm):
|
||||
|
||||
def __init__(self, request, *args, **kwargs):
|
||||
super(CreateEnvironmentForm, self).__init__(request, *args, **kwargs)
|
||||
net_choices = net.get_available_networks(request,
|
||||
murano_networks='translate')
|
||||
if net_choices is None: # NovaNetwork case
|
||||
net_choices = [((None, None), _('Unavailable'))]
|
||||
help_text = net.NN_HELP
|
||||
env_fixed_network = getattr(settings, 'USE_FIXED_NETWORK', False)
|
||||
if env_fixed_network:
|
||||
net_choices = net.get_project_assigned_network(request)
|
||||
help_text = None
|
||||
if not net_choices:
|
||||
msg = _("Default network is either not specified for "
|
||||
"this project, or specified incorrectly, "
|
||||
"please contact administrator.")
|
||||
messages.error(request, msg)
|
||||
raise exceptions.ConfigurationError(msg)
|
||||
else:
|
||||
self.fields['net_config'].required = False
|
||||
self.fields['net_config'].widget.attrs['readonly'] = True
|
||||
else:
|
||||
net_choices.insert(0, ((None, None), _('Create New')))
|
||||
help_text = net.NEUTRON_NET_HELP
|
||||
net_choices = net.get_available_networks(
|
||||
request,
|
||||
murano_networks='translate')
|
||||
|
||||
if net_choices is None: # NovaNetwork case
|
||||
net_choices = [((None, None), _('Unavailable'))]
|
||||
help_text = net.NN_HELP
|
||||
else:
|
||||
net_choices.insert(0, ((None, None), _('Create New')))
|
||||
help_text = net.NEUTRON_NET_HELP
|
||||
self.fields['net_config'].choices = net_choices
|
||||
self.fields['net_config'].help_text = help_text
|
||||
|
||||
|
@ -0,0 +1,18 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Introduce a fixed network mode for environments. Specifically,
|
||||
when this mode is activated, in the environment creation dialog
|
||||
user is no longer prompted for a network and instead a network
|
||||
previously assigned to the current project is used.
|
||||
|
||||
Network is assigned to project using project metadata key (custom) with network ID as the value.
|
||||
Specify this metadata key in Horizon config to be able to use it
|
||||
|
||||
This behavior is disabled by default and could be enabled by adding:
|
||||
|
||||
USE_FIXED_NETWORK = yes
|
||||
FIXED_MURANO_NETWORK = murano_network
|
||||
|
||||
to the Horizon configuration.
|
||||
|
Loading…
Reference in New Issue
Block a user