# Path: bgpvpn_dashboard/api/bgpvpn.py
# LOG = logging.getLogger(__name__)
# class Bgpvpn(neutron.NeutronAPIDictWrapper):
# class NetworkAssociation(neutron.NeutronAPIDictWrapper):
# class RouterAssociation(neutron.NeutronAPIDictWrapper):
# def bgpvpns_list(request, **kwargs):
# def bgpvpn_get(request, bgpvpn_id, **kwargs):
# def bgpvpn_create(request, **kwargs):
# def bgpvpn_update(request, bgpvpn_id, **kwargs):
# def bgpvpn_delete(request, bgpvpn_id):
# def network_association_get(request, bgpvpn_id, network_assoc_id, **kwargs):
# def network_association_list(request, bgpvpn_id, **kwargs):
# def network_association_create(request, bgpvpn_id, **kwargs):
# def network_association_delete(request, resource_id, bgpvpn_id):
# def router_association_get(request, bgpvpn_id, router_assoc_id, **kwargs):
# def router_association_list(request, bgpvpn_id, **kwargs):
# def router_association_create(request, bgpvpn_id, **kwargs):
# def router_association_update(request, bgpvpn_id, router_association_id,
#                               **kwargs):
# def router_association_delete(request, resource_id, bgpvpn_id):


import logging
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import forms
from horizon import workflows
from openstack_dashboard import api
from bgpvpn_dashboard.api import bgpvpn as bgpvpn_api

class RouterAssociation(workflows.Workflow):
    slug = "router_association"
    name = _("Associate a BGPVPN to a Router")
    finalize_button_name = _("Create")
    success_message = _('Router association with "%s" created.')
    failure_message = _('Unable to create a router association with "%s".')
    success_url = "horizon:project:bgpvpn:index"
    default_steps = (CreateRouterAssociationInfo,
                     AddRouterParametersInfo)
    wizard = True

    def format_status_message(self, message):
        name = self.context['name'] or self.context['bgpvpn_id']
        return message % name

    def handle(self, request, context):
        bgpvpn_id = context['bgpvpn_id']
        router_id = context["router_resource"]
        msg_error = _("Unable to associate router %s") % router_id
        try:
            router_association = bgpvpn_api.router_association_create(
                request, bgpvpn_id, router_id=router_id)
        except Exception:
            exceptions.handle(request, msg_error)
            return False
        if not context["with_parameters"]:
            return True
        asso_id = router_association['router_association']['id']
        try:

# Path: bgpvpn_dashboard/api/bgpvpn.py
# LOG = logging.getLogger(__name__)
# class Bgpvpn(neutron.NeutronAPIDictWrapper):
# class NetworkAssociation(neutron.NeutronAPIDictWrapper):
# class RouterAssociation(neutron.NeutronAPIDictWrapper):
# def bgpvpns_list(request, **kwargs):
# def bgpvpn_get(request, bgpvpn_id, **kwargs):
# def bgpvpn_create(request, **kwargs):
# def bgpvpn_update(request, bgpvpn_id, **kwargs):
# def bgpvpn_delete(request, bgpvpn_id):
# def network_association_get(request, bgpvpn_id, network_assoc_id, **kwargs):
# def network_association_list(request, bgpvpn_id, **kwargs):
# def network_association_create(request, bgpvpn_id, **kwargs):
# def network_association_delete(request, resource_id, bgpvpn_id):
# def router_association_get(request, bgpvpn_id, router_assoc_id, **kwargs):
# def router_association_list(request, bgpvpn_id, **kwargs):
# def router_association_create(request, bgpvpn_id, **kwargs):
# def router_association_update(request, bgpvpn_id, router_association_id,
#                               **kwargs):
# def router_association_delete(request, resource_id, bgpvpn_id):


# Path: bgpvpn_dashboard/dashboards/project/bgpvpn/workflows.py
import logging
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import forms
from horizon import workflows
from openstack_dashboard import api
from bgpvpn_dashboard.api import bgpvpn as bgpvpn_api


class RouterAssociation(workflows.Workflow):
    slug = "router_association"
    name = _("Associate a BGPVPN to a Router")
    finalize_button_name = _("Create")
    success_message = _('Router association with "%s" created.')
    failure_message = _('Unable to create a router association with "%s".')
    success_url = "horizon:project:bgpvpn:index"
    default_steps = (CreateRouterAssociationInfo,
                     AddRouterParametersInfo)
    wizard = True

    def format_status_message(self, message):
        name = self.context['name'] or self.context['bgpvpn_id']
        return message % name

    def handle(self, request, context):
        bgpvpn_id = context['bgpvpn_id']
        router_id = context["router_resource"]
        msg_error = _("Unable to associate router %s") % router_id
        try:
            router_association = bgpvpn_api.router_association_create(
                request, bgpvpn_id, router_id=router_id)
        except Exception:
            exceptions.handle(request, msg_error)
            return False
        if not context["with_parameters"]:
            return True
        asso_id = router_association['router_association']['id']
        try:

            bgpvpn_api.router_association_update(