from django.utils.translation import ugettext_lazy as _  # noqa

from horizon import exceptions
from openstack_dashboard import api


def get_interfaces_data(self):
    try:
        router_id = self.kwargs['router_id']
        ports = api.neutron.port_list(self.request,
                                      router_id=router_id)
    except Exception:
        ports = []
        msg = _(
            'Port list can not be retrieved for router ID %s' %
            self.kwargs.get('router_id')
        )
        exceptions.handle(self.request, msg)
    for p in ports:
        p.set_id_as_name_if_empty()
    return ports

from django.utils.translation import ugettext_lazy as _  # noqa

from horizon import exceptions
from openstack_dashboard import api


def get_interfaces_data(self):
    try:
        router_id = self.kwargs['router_id']
        router = api.quantum.router_get(self.request, router_id)
        ports = [api.quantum.Port(p) for p in router.ports]
    except Exception:
        ports = []
        msg = _(
            'Port list can not be retrieved for router ID %s' %
            self.kwargs.get('router_id')
        )
        exceptions.handle(self.request, msg)
    for p in ports:
        p.set_id_as_name_if_empty()
    return ports

Fix router's interface listing view
Fix router's interface listing view

To get all the ports for a router Horizon uses port_list
filtering by the device_id value which in vanilla openstack
is the quantum router_id, but we use the akanda_id as value for
that field so  the listing doesn't work for us. Lets replace the
port_list call with router_get.

Change-Id: Ibaabb11b2afa97aa2445776842afbdd5c6c2563d
Signed-off-by: Rosario Di Somma <73b2fe5f91895aea2b4d0e8942a5edf9f18fa897@dreamhost.com>

  from django.utils.translation import ugettext_lazy as _  # noqa
  
  from horizon import exceptions
  from openstack_dashboard import api
  
  
  def get_interfaces_data(self):
      try:
          router_id = self.kwargs['router_id']
-         ports = api.neutron.port_list(self.request,
-                                       router_id=router_id)
+         router = api.quantum.router_get(self.request, router_id)
+         ports = [api.quantum.Port(p) for p in router.ports]
      except Exception:
          ports = []
          msg = _(
              'Port list can not be retrieved for router ID %s' %
              self.kwargs.get('router_id')
          )
          exceptions.handle(self.request, msg)
      for p in ports:
          p.set_id_as_name_if_empty()
      return ports
  
Fix router's interface listing view
## Code Before:
from django.utils.translation import ugettext_lazy as _  # noqa

from horizon import exceptions
from openstack_dashboard import api


def get_interfaces_data(self):
    try:
        router_id = self.kwargs['router_id']
        ports = api.neutron.port_list(self.request,
                                      router_id=router_id)
    except Exception:
        ports = []
        msg = _(
            'Port list can not be retrieved for router ID %s' %
            self.kwargs.get('router_id')
        )
        exceptions.handle(self.request, msg)
    for p in ports:
        p.set_id_as_name_if_empty()
    return ports

## Instruction:
Fix router's interface listing view
## Code After:
from django.utils.translation import ugettext_lazy as _  # noqa

from horizon import exceptions
from openstack_dashboard import api


def get_interfaces_data(self):
    try:
        router_id = self.kwargs['router_id']
        router = api.quantum.router_get(self.request, router_id)
        ports = [api.quantum.Port(p) for p in router.ports]
    except Exception:
        ports = []
        msg = _(
            'Port list can not be retrieved for router ID %s' %
            self.kwargs.get('router_id')
        )
        exceptions.handle(self.request, msg)
    for p in ports:
        p.set_id_as_name_if_empty()
    return ports
