can't associate multiple ext-seg to an ext-group

Added support to associate multiple ext-segments
to external group while creation and also made
subnetID as optional field in ext-segment
creation.

Change-Id: I3cd591caede3a513e95c670235db47ed72249353
Closes-Bug: #1505416
(cherry picked from commit faa77b0218)
This commit is contained in:
sriharshabarkuru 2015-10-27 11:28:51 +05:30 committed by ank
parent f49fbeb021
commit 9dbadd9ab6
5 changed files with 41 additions and 29 deletions

View File

@ -90,12 +90,17 @@ def update_policy_target_attributes(request, pt):
setattr(pt, 'l2_policy_id', atag) setattr(pt, 'l2_policy_id', atag)
if hasattr(pt, 'external_segments'): if hasattr(pt, 'external_segments'):
exturl = "horizon:project:network_policy:external_connectivity_details" exturl = "horizon:project:network_policy:external_connectivity_details"
value = ["<ul>"]
li = lambda x: "<li><a href='" + \
reverse(exturl, kwargs={'external_connectivity_id': x.id}) + \
"'>" + x.name + "</a></li>"
for external_segment in pt.external_segments:
ext_policy = client.get_externalconnectivity(request, ext_policy = client.get_externalconnectivity(request,
pt.external_segments[0]) external_segment)
u = reverse(exturl, kwargs={'external_connectivity_id': ext_policy.id}) value.append(li(ext_policy))
exttag = mark_safe( value.append("</ul>")
"<a href='" + u + "'>" + ext_policy.name + "</a>") value = "".join(value)
setattr(pt, 'external_segments', exttag) setattr(pt, 'external_segments', mark_safe(value))
return pt return pt

View File

@ -412,8 +412,9 @@ class UpdateExternalConnectivityForm(forms.SelfHandlingForm):
msg = _("External Connectivity updated successfully!") msg = _("External Connectivity updated successfully!")
LOG.debug(msg) LOG.debug(msg)
return http.HttpResponseRedirect(url) return http.HttpResponseRedirect(url)
except Exception: except Exception as e:
msg = _("Failed to update External Connectivity") msg = _("Failed to update External Connectivity.%s") % \
(str(e))
LOG.error(msg) LOG.error(msg)
exceptions.handle(request, msg, redirect=shortcuts.redirect) exceptions.handle(request, msg, redirect=shortcuts.redirect)
@ -453,15 +454,17 @@ class CreateExternalConnectivityForm(forms.SelfHandlingForm):
net_list = api.neutron.network_list(request, **dic) net_list = api.neutron.network_list(request, **dic)
subnet_list = api.neutron.subnet_list(request) subnet_list = api.neutron.subnet_list(request)
net_id_list = [net.id for net in net_list] net_id_list = [net.id for net in net_list]
self.fields['subnet_id'].choices = [(subnet.id, subnet.name) self.fields['subnet_id'].choices = [('', 'Select')] + \
for subnet in subnet_list if subnet.network_id in net_id_list] [(subnet.id, subnet.name) for subnet in subnet_list
if subnet.network_id in net_id_list]
except Exception: except Exception:
msg = _("Failed to get Subnet ID list.") msg = _("Failed to get Subnet ID list.")
exceptions.handle(request, msg) exceptions.handle(request, msg)
def handle(self, request, context): def handle(self, request, context):
url = reverse("horizon:project:network_policy:index")
try: try:
if context['subnet_id'] == '':
del context['subnet_id']
if context['cidr'] == '': if context['cidr'] == '':
del context['cidr'] del context['cidr']
routes = context['external_routes'] routes = context['external_routes']
@ -473,11 +476,12 @@ class CreateExternalConnectivityForm(forms.SelfHandlingForm):
'nexthop': values[1]} 'nexthop': values[1]}
p.append(values) p.append(values)
context['external_routes'] = p context['external_routes'] = p
client.create_externalconnectivity( external_segment = client.create_externalconnectivity(
request, **context) request, **context)
msg = _("External Connectivity updatedsuccessfully!") msg = _('External Connectivity successfully created.')
LOG.debug(msg) LOG.debug(msg)
return http.HttpResponseRedirect(url) messages.success(request, msg)
return external_segment
except Exception as e: except Exception as e:
msg = str(e) msg = str(e)
LOG.error(msg) LOG.error(msg)

View File

@ -12,6 +12,7 @@
import re import re
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from horizon import exceptions from horizon import exceptions
@ -230,6 +231,12 @@ class CreateExternalConnectivityView(forms.ModalFormView):
CreateExternalConnectivityView, self).get_context_data(**kwargs) CreateExternalConnectivityView, self).get_context_data(**kwargs)
return context return context
def get_success_url(self):
return reverse('horizon:project:network_policy:index')
def get_object_id(self, external_segment):
return [external_segment.id]
class ExternalConnectivityDetailsView(tabs.TabView): class ExternalConnectivityDetailsView(tabs.TabView):
tab_group_class = (np_tabs.ExternalConnectivityDetailsTabs) tab_group_class = (np_tabs.ExternalConnectivityDetailsTabs)

View File

@ -145,9 +145,9 @@ class UpdateExternalPolicyTargetForm(forms.SelfHandlingForm):
label=_("Provided Policy Rule Set"), required=False) label=_("Provided Policy Rule Set"), required=False)
consumed_policy_rule_sets = forms.MultipleChoiceField( consumed_policy_rule_sets = forms.MultipleChoiceField(
label=_("Consumed Policy Rule Set"), required=False) label=_("Consumed Policy Rule Set"), required=False)
external_segments = forms.ChoiceField( external_segments = forms.MultipleChoiceField(
label=_("External Connectivity"), label=_("External Connectivity"), required=True,
help_text=_("Select external segment for Group.")) help_text=_("Select external segment(s) for Group."))
shared = forms.BooleanField(label=_("Shared"), required=False) shared = forms.BooleanField(label=_("Shared"), required=False)
failure_url = 'horizon:project:policytargets:index' failure_url = 'horizon:project:policytargets:index'
@ -183,10 +183,8 @@ class UpdateExternalPolicyTargetForm(forms.SelfHandlingForm):
consumed_init.append(item[0]) consumed_init.append(item[0])
self.fields['provided_policy_rule_sets'].initial = provided_init self.fields['provided_policy_rule_sets'].initial = provided_init
self.fields['consumed_policy_rule_sets'].initial = consumed_init self.fields['consumed_policy_rule_sets'].initial = consumed_init
for attr in ['name', 'description', 'shared']: for attr in ['name', 'description', 'shared', 'external_segments']:
self.fields[attr].initial = getattr(ext_policy_target, attr) self.fields[attr].initial = getattr(ext_policy_target, attr)
self.fields['external_segments'].initial = \
ext_policy_target.external_segments[0]
except Exception as e: except Exception as e:
msg = _('Unable to retrieve policy_rule_set details. %s') % ( msg = _('Unable to retrieve policy_rule_set details. %s') % (
str(e)) str(e))
@ -202,7 +200,6 @@ class UpdateExternalPolicyTargetForm(forms.SelfHandlingForm):
def handle(self, request, context): def handle(self, request, context):
ext_policy_target_id = self.initial['ext_policy_target_id'] ext_policy_target_id = self.initial['ext_policy_target_id']
name_or_id = context.get('name') or ext_policy_target_id name_or_id = context.get('name') or ext_policy_target_id
external_segment_list = []
try: try:
if 'provided_policy_rule_sets' in context: if 'provided_policy_rule_sets' in context:
if context.get('provided_policy_rule_sets'): if context.get('provided_policy_rule_sets'):
@ -218,9 +215,6 @@ class UpdateExternalPolicyTargetForm(forms.SelfHandlingForm):
for i in context['consumed_policy_rule_sets']]) for i in context['consumed_policy_rule_sets']])
else: else:
context['consumed_policy_rule_sets'] = None context['consumed_policy_rule_sets'] = None
if 'external_segments' in context:
external_segment_list.append(context['external_segments'])
context['external_segments'] = external_segment_list
if context.get('name'): if context.get('name'):
context['name'] = html.escape(context['name']) context['name'] = html.escape(context['name'])
if context.get('description'): if context.get('description'):

View File

@ -36,6 +36,8 @@ from gbpui import fields
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
POLICY_RULE_SET_URL = "horizon:project:application_policy:addpolicy_rule_set" POLICY_RULE_SET_URL = "horizon:project:application_policy:addpolicy_rule_set"
ADD_EXTERNAL_CONNECTIVITY = \
"horizon:project:network_policy:create_external_connectivity"
class SelectPolicyRuleSetAction(workflows.Action): class SelectPolicyRuleSetAction(workflows.Action):
@ -230,9 +232,11 @@ class AddPTG(workflows.Workflow):
class ExternalConnectivityAction(workflows.Action): class ExternalConnectivityAction(workflows.Action):
external_segments = forms.ChoiceField( external_segments = fields.DynamicMultiChoiceField(
label=_("External Connectivity"), label=_("External Connectivity"),
help_text=_("Select external segment for Group.")) required=True,
add_item_link=ADD_EXTERNAL_CONNECTIVITY,
help_text=_("Select external segment(s) for Group."))
class Meta(object): class Meta(object):
name = _("External Connectivity") name = _("External Connectivity")
@ -263,9 +267,7 @@ class ExternalConnectivityStep(workflows.Step):
contributes = ("external_segments",) contributes = ("external_segments",)
def contribute(self, data, context): def contribute(self, data, context):
ext_seg_list = [] context['external_segments'] = data.get('external_segments', [])
ext_seg_list.append(data['external_segments'])
context['external_segments'] = ext_seg_list
return context return context