
from openstack_dashboard.api import base
from openstack_dashboard.api import network
from openstack_dashboard.api import neutron
from openstack_dashboard.api import nova


def _nova_network_list(request):
    nets = nova.novaclient(request).networks.list()
    for net in nets:
        net.name_or_id = net.to_dict().get('label', net.to_dict().get('id'))
    return nets


def _nova_network_get(request, nova_net_id):
    net = nova.novaclient(request).networks.get(nova_net_id)
    net.name_or_id = net.to_dict().get('label', net.to_dict().get('id'))
    return net


class NetworkClient(network.NetworkClient):
    def __init__(self, request):
        super(NetworkClient, self).__init__(request)
        if base.is_service_enabled(request, 'network'):
            self.network_list = neutron.network_list
            self.network_get = neutron.network_get
        else:
            self.network_list = _nova_network_list
            self.network_get = _nova_network_get


def network_list(request):
    return NetworkClient(request).network_list(request)


def network_get(request, net_id):
    return NetworkClient(request).network_get(request, net_id)


from openstack_dashboard.api import neutron


def network_list(request):
    return neutron.network_list(request)


def network_get(request, net_id):
    return neutron.network_get(request, net_id)

Fix compatibility with latest horizon
Fix compatibility with latest horizon

Class "NetworkClient" from "openstack_dashboards.api.network" module
was removed from horizon repo. So, remove its usage and use neutron
directly.

Change-Id: Idcf51553f64fae2254c224d4c6ef4fbb94e6f279
Closes-Bug: #1691466

  
- from openstack_dashboard.api import base
- from openstack_dashboard.api import network
  from openstack_dashboard.api import neutron
- from openstack_dashboard.api import nova
- 
- 
- def _nova_network_list(request):
-     nets = nova.novaclient(request).networks.list()
-     for net in nets:
-         net.name_or_id = net.to_dict().get('label', net.to_dict().get('id'))
-     return nets
- 
- 
- def _nova_network_get(request, nova_net_id):
-     net = nova.novaclient(request).networks.get(nova_net_id)
-     net.name_or_id = net.to_dict().get('label', net.to_dict().get('id'))
-     return net
- 
- 
- class NetworkClient(network.NetworkClient):
-     def __init__(self, request):
-         super(NetworkClient, self).__init__(request)
-         if base.is_service_enabled(request, 'network'):
-             self.network_list = neutron.network_list
-             self.network_get = neutron.network_get
-         else:
-             self.network_list = _nova_network_list
-             self.network_get = _nova_network_get
  
  
  def network_list(request):
-     return NetworkClient(request).network_list(request)
+     return neutron.network_list(request)
  
  
  def network_get(request, net_id):
-     return NetworkClient(request).network_get(request, net_id)
+     return neutron.network_get(request, net_id)
  
Fix compatibility with latest horizon
## Code Before:

from openstack_dashboard.api import base
from openstack_dashboard.api import network
from openstack_dashboard.api import neutron
from openstack_dashboard.api import nova


def _nova_network_list(request):
    nets = nova.novaclient(request).networks.list()
    for net in nets:
        net.name_or_id = net.to_dict().get('label', net.to_dict().get('id'))
    return nets


def _nova_network_get(request, nova_net_id):
    net = nova.novaclient(request).networks.get(nova_net_id)
    net.name_or_id = net.to_dict().get('label', net.to_dict().get('id'))
    return net


class NetworkClient(network.NetworkClient):
    def __init__(self, request):
        super(NetworkClient, self).__init__(request)
        if base.is_service_enabled(request, 'network'):
            self.network_list = neutron.network_list
            self.network_get = neutron.network_get
        else:
            self.network_list = _nova_network_list
            self.network_get = _nova_network_get


def network_list(request):
    return NetworkClient(request).network_list(request)


def network_get(request, net_id):
    return NetworkClient(request).network_get(request, net_id)

## Instruction:
Fix compatibility with latest horizon
## Code After:

from openstack_dashboard.api import neutron


def network_list(request):
    return neutron.network_list(request)


def network_get(request, net_id):
    return neutron.network_get(request, net_id)
