
from neutron._i18n import _LW
from neutron.notifiers import nova as n_nova
from novaclient import exceptions as nova_exceptions
from oslo_log import log as logging

LOG = logging.getLogger(__name__)


class NovaClient(object):

    def __init__(self):
        self.nclient = n_nova.Notifier().nclient

    def get_server(self, server_id):
        try:
            return self.nclient.servers.get(server_id)
        except nova_exceptions.NotFound:
            LOG.warning(_LW("Nova returned NotFound for server: %s"),
                        server_id)
        except Exception as e:
            LOG.exception(e)


from neutron._i18n import _LW
from neutron.notifiers import nova as n_nova
from novaclient import exceptions as nova_exceptions
from oslo_log import log as logging


LOG = logging.getLogger(__name__)


client = None


def _get_client():
    global client
    if client is None:
        client = n_nova.Notifier().nclient
    return client


class NovaClient(object):

    def __init__(self):
        self.client = n_nova.Notifier().nclient

    def get_server(self, server_id):
        try:
            return self.client.servers.get(server_id)
        except nova_exceptions.NotFound:
            LOG.warning(_LW("Nova returned NotFound for server: %s"),
                        server_id)
        except Exception as e:
            LOG.exception(e)

Load Nova Client only once to avoid reconnecting
Load Nova Client only once to avoid reconnecting

  
  from neutron._i18n import _LW
  from neutron.notifiers import nova as n_nova
  from novaclient import exceptions as nova_exceptions
  from oslo_log import log as logging
  
+ 
  LOG = logging.getLogger(__name__)
+ 
+ 
+ client = None
+ 
+ 
+ def _get_client():
+     global client
+     if client is None:
+         client = n_nova.Notifier().nclient
+     return client
  
  
  class NovaClient(object):
  
      def __init__(self):
-         self.nclient = n_nova.Notifier().nclient
+         self.client = n_nova.Notifier().nclient
  
      def get_server(self, server_id):
          try:
-             return self.nclient.servers.get(server_id)
+             return self.client.servers.get(server_id)
          except nova_exceptions.NotFound:
              LOG.warning(_LW("Nova returned NotFound for server: %s"),
                          server_id)
          except Exception as e:
              LOG.exception(e)
  
Load Nova Client only once to avoid reconnecting
## Code Before:

from neutron._i18n import _LW
from neutron.notifiers import nova as n_nova
from novaclient import exceptions as nova_exceptions
from oslo_log import log as logging

LOG = logging.getLogger(__name__)


class NovaClient(object):

    def __init__(self):
        self.nclient = n_nova.Notifier().nclient

    def get_server(self, server_id):
        try:
            return self.nclient.servers.get(server_id)
        except nova_exceptions.NotFound:
            LOG.warning(_LW("Nova returned NotFound for server: %s"),
                        server_id)
        except Exception as e:
            LOG.exception(e)

## Instruction:
Load Nova Client only once to avoid reconnecting
## Code After:

from neutron._i18n import _LW
from neutron.notifiers import nova as n_nova
from novaclient import exceptions as nova_exceptions
from oslo_log import log as logging


LOG = logging.getLogger(__name__)


client = None


def _get_client():
    global client
    if client is None:
        client = n_nova.Notifier().nclient
    return client


class NovaClient(object):

    def __init__(self):
        self.client = n_nova.Notifier().nclient

    def get_server(self, server_id):
        try:
            return self.client.servers.get(server_id)
        except nova_exceptions.NotFound:
            LOG.warning(_LW("Nova returned NotFound for server: %s"),
                        server_id)
        except Exception as e:
            LOG.exception(e)
