Add fixed network mode for environments

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.

Change-Id: Ic464e1560cc89fdc7615d51e67beb0f50e11f24c
This commit is contained in:
Artem Tiumentcev 2017-07-11 12:45:04 +03:00
parent 8dd79ad101
commit 76cd701382
3 changed files with 63 additions and 7 deletions

View File

@ -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:

View File

@ -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,8 +40,24 @@ 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,
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 = 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

View File

@ -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.