def handle(self, request, data):
        gw_vlan = None
        gw_port_id = self.initial.get('gw_port_id')
        try:
            vlan = data['vlan']
            assigned = data['assigned']
            type = data['type']
            subnet_id = data['subnet_id']
            port_id = data['port_id']

            gw_vlan = self.create_gw_vlan(request, gw_port_id, vlan,
                                          assigned, type, subnet_id,
                                          port_id)

            message = _('Gateway Vlan with vlan %s was successfully '
                        'created.') % vlan
            messages.success(request, message)
            return gw_vlan
        except Exception:
            if gw_vlan:
                neutron.nuage_gateway_vlan_delete(request, gw_vlan['id'])
            msg = _('Failed to create Gateway Vlan.')
            LOG.info(msg)
            args = [gw_port_id]
            redirect = reverse(self.failure_url, args=args)
            exceptions.handle(request, msg, redirect=redirect)
            return False
 def delete_gw_vlan(self, gw_vlan_id, request):
     gw_vlan = neutron.nuage_gateway_vlan_get(self.request, gw_vlan_id)
     try:
         vport = gw_vlan.get('vport')
         if vport:
             neutron.nuage_gateway_vport_delete(request, vport)
         neutron.nuage_gateway_vlan_delete(request, gw_vlan_id)
     except Exception:
         msg = _('Failed to delete Gateway Vlan %s')
         LOG.info(msg, gw_vlan_id)
         redirect = reverse("horizon:project:gateways:ports:detail",
                            args=[gw_vlan['gatewayport']])
         exceptions.handle(request, msg % gw_vlan_id, redirect=redirect)
 def delete(self, request, gw_vlan_id):
     gw_vlan = self.table.get_object_by_id(gw_vlan_id)
     try:
         vport = gw_vlan.get('vport')
         if vport:
             neutron.nuage_gateway_vport_delete(request, vport['id'])
         neutron.nuage_gateway_vlan_delete(request, gw_vlan_id)
     except Exception:
         msg = _('Failed to delete Gateway Vlan %s') % gw_vlan_id
         LOG.info(msg)
         redirect = reverse("horizon:project:gateways:ports:detail",
                            args=[gw_vlan['gatewayport']])
         exceptions.handle(request, msg, redirect=redirect)