cache a global hardware manager

This commit is contained in:
Russell Haering 2014-01-22 17:28:24 -08:00
parent e25f5dd4ce
commit 5ea4484a2c
2 changed files with 22 additions and 16 deletions

View File

@ -118,7 +118,7 @@ class TeethAgent(object):
self.api = api.TeethAgentAPIServer(self) self.api = api.TeethAgentAPIServer(self)
self.command_results = collections.OrderedDict() self.command_results = collections.OrderedDict()
self.heartbeater = TeethAgentHeartbeater(self) self.heartbeater = TeethAgentHeartbeater(self)
self.hardware = hardware.load_hardware_manager() self.hardware = hardware.get_manager()
self.command_lock = threading.Lock() self.command_lock = threading.Lock()
self.log = structlog.get_logger() self.log = structlog.get_logger()
self.started_at = None self.started_at = None
@ -235,7 +235,7 @@ def build_agent(api_url,
if not listen_host: if not listen_host:
listen_host = advertise_host listen_host = advertise_host
mac_addr = hardware.load_hardware_manager().get_primary_mac_address() mac_addr = hardware.get_manager().get_primary_mac_address()
api_client = overlord_agent_api.APIClient(api_url) api_client = overlord_agent_api.APIClient(api_url)
log.info('fetching agent configuration from API', log.info('fetching agent configuration from API',

View File

@ -59,7 +59,10 @@ def _compare_extensions(ext1, ext2):
return mgr1.evaluate_hardware_support() - mgr2.evaluate_hardware_support() return mgr1.evaluate_hardware_support() - mgr2.evaluate_hardware_support()
def load_hardware_manager(): def get_manager():
global _global_manager
if not _global_manager:
log = structlog.get_logger() log = structlog.get_logger()
extension_manager = stevedore.ExtensionManager( extension_manager = stevedore.ExtensionManager(
namespace='teeth_agent.hardware_managers', namespace='teeth_agent.hardware_managers',
@ -75,4 +78,7 @@ def load_hardware_manager():
log.info('selected hardware manager', log.info('selected hardware manager',
manager_name=preferred_extension.entry_point_target) manager_name=preferred_extension.entry_point_target)
return preferred_manager
_global_manager = preferred_manager
return _global_manager