diff --git a/neutron_fwaas_dashboard/api/fwaas_v2.py b/neutron_fwaas_dashboard/api/fwaas_v2.py index e5bc894..64576d6 100644 --- a/neutron_fwaas_dashboard/api/fwaas_v2.py +++ b/neutron_fwaas_dashboard/api/fwaas_v2.py @@ -22,41 +22,18 @@ neutronclient = neutron.neutronclient class Port(neutron.NeutronAPIDictWrapper): """Wrapper for neutron port.""" - def get_dict(self): - port_dict = self._apidict - port_dict['port_id'] = port_dict['id'] - return port_dict - class Rule(neutron.NeutronAPIDictWrapper): """Wrapper for neutron firewall rule.""" - def get_dict(self): - rule_dict = self._apidict - rule_dict['rule_id'] = rule_dict['id'] - return rule_dict - class Policy(neutron.NeutronAPIDictWrapper): """Wrapper for neutron firewall policy.""" - def get_dict(self): - policy_dict = self._apidict - policy_dict['policy_id'] = policy_dict['id'] - return policy_dict - class FirewallGroup(neutron.NeutronAPIDictWrapper): """Wrapper for neutron firewall group.""" - def __init__(self, apiresource): - super(FirewallGroup, self).__init__(apiresource) - - def get_dict(self): - firewallgroup_dict = self._apidict - firewallgroup_dict['firewallgroup_id'] = firewallgroup_dict['id'] - return firewallgroup_dict - def rule_create(request, **kwargs): """Create a firewall rule diff --git a/neutron_fwaas_dashboard/dashboards/project/firewalls_v2/forms.py b/neutron_fwaas_dashboard/dashboards/project/firewalls_v2/forms.py index 99768b8..c13cc71 100644 --- a/neutron_fwaas_dashboard/dashboards/project/firewalls_v2/forms.py +++ b/neutron_fwaas_dashboard/dashboards/project/firewalls_v2/forms.py @@ -86,7 +86,7 @@ class UpdateRule(forms.SelfHandlingForm): return body def handle(self, request, context): - rule_id = self.initial['rule_id'] + rule_id = self.initial['id'] name_or_id = context.get('name') or rule_id body = self._convert_req_body(_get_request_body(context, self.initial)) try: @@ -111,7 +111,7 @@ class UpdatePolicy(forms.SelfHandlingForm): failure_url = 'horizon:project:firewalls_v2:index' def handle(self, request, context): - policy_id = self.initial['policy_id'] + policy_id = self.initial['id'] name_or_id = context.get('name') or policy_id body = _get_request_body(context, self.initial) try: @@ -189,7 +189,7 @@ class UpdateFirewall(forms.SelfHandlingForm): return body def handle(self, request, context): - firewallgroup_id = self.initial['firewallgroup_id'] + firewallgroup_id = self.initial['id'] name_or_id = context.get('name') or firewallgroup_id body = self._convert_req_body(_get_request_body(context, self.initial)) try: @@ -228,7 +228,7 @@ class AddPort(forms.SelfHandlingForm): self.fields['port_id'].choices = current_choices def handle(self, request, context): - firewallgroup_id = self.initial['firewallgroup_id'] + firewallgroup_id = self.initial['id'] name_or_id = context.get('name') or firewallgroup_id body = _get_request_body(context, self.initial) add_port = context['port_id'] @@ -267,7 +267,7 @@ class RemovePort(forms.SelfHandlingForm): self.fields['port_id'].choices = current_choices def handle(self, request, context): - firewallgroup_id = self.initial['firewallgroup_id'] + firewallgroup_id = self.initial['id'] name_or_id = context.get('name') or firewallgroup_id body = _get_request_body(context, self.initial) remove_port = context['port_id'] @@ -325,7 +325,7 @@ class InsertRuleToPolicy(forms.SelfHandlingForm): self.fields['insert_after'].choices = [('', _('-'))] + current_choices def handle(self, request, context): - policy_id = self.initial['policy_id'] + policy_id = self.initial['id'] policy_name_or_id = self.initial['name'] or policy_id try: insert_rule_id = context['firewall_rule_id'] @@ -376,7 +376,7 @@ class RemoveRuleFromPolicy(forms.SelfHandlingForm): self.fields['firewall_rule_id'].choices = current_choices def handle(self, request, context): - policy_id = self.initial['policy_id'] + policy_id = self.initial['id'] policy_name_or_id = self.initial['name'] or policy_id try: remove_rule_id = context['firewall_rule_id'] diff --git a/neutron_fwaas_dashboard/dashboards/project/firewalls_v2/views.py b/neutron_fwaas_dashboard/dashboards/project/firewalls_v2/views.py index ee7fcf7..6177681 100644 --- a/neutron_fwaas_dashboard/dashboards/project/firewalls_v2/views.py +++ b/neutron_fwaas_dashboard/dashboards/project/firewalls_v2/views.py @@ -209,7 +209,7 @@ class UpdateRuleView(forms.ModalFormView): def get_initial(self): rule = self._get_object() - initial = rule.get_dict() + initial = rule.to_dict() protocol = initial['protocol'] initial['protocol'] = protocol.upper() if protocol else 'ANY' initial['action'] = initial['action'].upper() @@ -249,7 +249,7 @@ class UpdatePolicyView(forms.ModalFormView): def get_initial(self): policy = self._get_object() - initial = policy.get_dict() + initial = policy.to_dict() return initial @@ -287,7 +287,7 @@ class UpdateFirewallView(forms.ModalFormView): def get_initial(self): firewall = self._get_object() - initial = firewall.get_dict() + initial = firewall.to_dict() return initial @@ -325,7 +325,7 @@ class AddPortView(forms.ModalFormView): def get_initial(self): firewallgroup = self._get_object() - initial = firewallgroup.get_dict() + initial = firewallgroup.to_dict() return initial @@ -363,7 +363,7 @@ class RemovePortView(forms.ModalFormView): def get_initial(self): firewallgroup = self._get_object() - initial = firewallgroup.get_dict() + initial = firewallgroup.to_dict() return initial @@ -401,7 +401,7 @@ class InsertRuleToPolicyView(forms.ModalFormView): def get_initial(self): policy = self._get_object() - initial = policy.get_dict() + initial = policy.to_dict() initial['policy_id'] = initial['id'] return initial @@ -440,40 +440,6 @@ class RemoveRuleFromPolicyView(forms.ModalFormView): def get_initial(self): policy = self._get_object() - initial = policy.get_dict() + initial = policy.to_dict() initial['policy_id'] = initial['id'] return initial - - -class RouterCommonView(forms.ModalFormView): - form_id = "update_firewall_form" - context_object_name = 'firewall' - submit_label = _("Save Changes") - success_url = reverse_lazy("horizon:project:firewalls_v2:index") - - def get_context_data(self, **kwargs): - context = super(RouterCommonView, - self).get_context_data(**kwargs) - context["firewall_id"] = self.kwargs['firewall_id'] - args = (self.kwargs['firewall_id'],) - context['submit_url'] = reverse(self.submit_url, args=args) - obj = self._get_object() - if obj: - context['name'] = obj.name_or_id - return context - - @memoized.memoized_method - def _get_object(self, *args, **kwargs): - firewall_id = self.kwargs['firewall_id'] - try: - firewall = api_fwaas_v2.firewall_get(self.request, firewall_id) - return firewall - except Exception: - redirect = self.success_url - msg = _('Unable to retrieve firewall details.') - exceptions.handle(self.request, msg, redirect=redirect) - - def get_initial(self): - firewall = self._get_object() - initial = firewall.get_dict() - return initial