# 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/router_associations/tables.py
# LOG = logging.getLogger(__name__)
# class DeleteRouterAssociation(tables.DeleteAction):
# class UpdateRouterAssociation(tables.LinkAction):
# class CreateRouterAssociation(tables.LinkAction):
# class IDColumn(tables.Column):
# class RouterColumn(tables.Column):
# class RouterAssociationsTable(tables.DataTable):
#     class Meta(object):
#     def action_present(count):
#     def action_past(count):
#     def delete(self, request, asso_id):
#     def get_link_url(self, asso):
#     def allowed(self, request, datum=None):
#     def get_link_url(self, datum=None):
#     def get_link_url(self, asso):
#     def get_raw_data(self, asso):
#     def get_object_display(self, asso):


from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import tabs
from horizon.utils import memoized
from openstack_dashboard import api
from bgpvpn_dashboard.api import bgpvpn as bgpvpn_api
from bgpvpn_dashboard.dashboards.project.bgpvpn.router_associations \
    import tables as router_tables

    @staticmethod
    def get_router_detail_url(router_id):
        return reverse('horizon:project:routers:detail', args=(router_id,))


class RouterAssociationsTab(tabs.TableTab):
    name = _("Router Associations")
    slug = "router_associations_tab"
    table_classes = (router_tables.RouterAssociationsTable,)
    template_name = ("horizon/common/_detail_table.html")
    preload = False

    def get_router_associations_data(self):
        try:
            bgpvpn_id = self.tab_group.kwargs['bgpvpn_id']
            router_associations = bgpvpn_api.router_association_list(
                self.request, bgpvpn_id)
            for router_asso in router_associations:
                router = api.neutron.router_get(self.request,
                                                router_asso.router_id)
                router_asso.router_name = router.name
        except Exception:
            router_associations = []
            msg = _('Router associations list can not be retrieved.')
            exceptions.handle(self.request, msg)
        return router_associations


class RouterAssociationDetailTabs(tabs.TabGroup):

# 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/router_associations/tables.py
# LOG = logging.getLogger(__name__)
# class DeleteRouterAssociation(tables.DeleteAction):
# class UpdateRouterAssociation(tables.LinkAction):
# class CreateRouterAssociation(tables.LinkAction):
# class IDColumn(tables.Column):
# class RouterColumn(tables.Column):
# class RouterAssociationsTable(tables.DataTable):
#     class Meta(object):
#     def action_present(count):
#     def action_past(count):
#     def delete(self, request, asso_id):
#     def get_link_url(self, asso):
#     def allowed(self, request, datum=None):
#     def get_link_url(self, datum=None):
#     def get_link_url(self, asso):
#     def get_raw_data(self, asso):
#     def get_object_display(self, asso):


# Path: bgpvpn_dashboard/dashboards/project/bgpvpn/router_associations/tabs.py
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import tabs
from horizon.utils import memoized
from openstack_dashboard import api
from bgpvpn_dashboard.api import bgpvpn as bgpvpn_api
from bgpvpn_dashboard.dashboards.project.bgpvpn.router_associations \
    import tables as router_tables


    @staticmethod
    def get_router_detail_url(router_id):
        return reverse('horizon:project:routers:detail', args=(router_id,))


class RouterAssociationsTab(tabs.TableTab):
    name = _("Router Associations")
    slug = "router_associations_tab"
    table_classes = (router_tables.RouterAssociationsTable,)
    template_name = ("horizon/common/_detail_table.html")
    preload = False

    def get_router_associations_data(self):
        try:
            bgpvpn_id = self.tab_group.kwargs['bgpvpn_id']
            router_associations = bgpvpn_api.router_association_list(
                self.request, bgpvpn_id)
            for router_asso in router_associations:
                router = api.neutron.router_get(self.request,
                                                router_asso.router_id)
                router_asso.router_name = router.name
        except Exception:
            router_associations = []
            msg = _('Router associations list can not be retrieved.')
            exceptions.handle(self.request, msg)
        return router_associations


class RouterAssociationDetailTabs(tabs.TabGroup):

    slug = "router_association_details"