Skip to content

Commit

Permalink
Merge pull request #4557 from zenoss/bugfix/ZEN-34895.6x
Browse files Browse the repository at this point in the history
Implement an API to retrieve a single device config.
  • Loading branch information
jpeacock-zenoss authored Sep 18, 2024
2 parents df381f6 + 0261736 commit 9178e94
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 171 deletions.
9 changes: 7 additions & 2 deletions Products/ZenCollector/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
##############################################################################

from .proxy import ConfigurationProxy
from .task import ConfigurationLoaderTask, DeviceConfigLoader
from .task import (
ConfigurationLoaderTask,
ManyDeviceConfigLoader,
SingleDeviceConfigLoader,
)

__all__ = (
"ConfigurationLoaderTask",
"ConfigurationProxy",
"DeviceConfigLoader",
"ManyDeviceConfigLoader",
"SingleDeviceConfigLoader",
)
46 changes: 34 additions & 12 deletions Products/ZenCollector/config/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#
##############################################################################

import itertools
import logging
import time

Expand Down Expand Up @@ -66,7 +65,39 @@ def _processThresholds(self, thresholds):
self._collector._configureThresholds(thresholds)


class DeviceConfigLoader(object):
class SingleDeviceConfigLoader(object):
"""Handles retrieving the config of a single device."""

def __init__(self, deviceid, collector, service, options, callback):
self._deviceId = deviceid
self._collector = collector
self._service = service
self._options = options
self._callback = callback

@property
def deviceIds(self):
return [self._deviceId]

@defer.inlineCallbacks
def __call__(self):
try:
ref = yield self._collector.getRemoteConfigCacheProxy()

log.debug("fetching device config for %s", self._deviceId)
# get options from prefs.options and send to remote
config = yield ref.callRemote(
"getDeviceConfig",
self._service,
self._deviceId,
options=self._options.__dict__,
)
yield self._callback(config)
except Exception:
log.exception("failed to retrieve device configs")


class ManyDeviceConfigLoader(object):
"""Handles retrieving devices from the ConfigCache service."""

def __init__(self, proxy, callback):
Expand All @@ -81,6 +112,7 @@ def deviceIds(self):

@defer.inlineCallbacks
def __call__(self):
log.debug("fetching device configs")
try:
next_time = time.time()
config_data = yield self._proxy.getConfigProxies(
Expand All @@ -104,16 +136,6 @@ def _processConfigs(self, config_data):
except Exception:
log.exception("failed to process device configs")

def _get_specified_config(self, new, updated):
return next(
(
cfg
for cfg in itertools.chain(new, updated)
if self._options.device == cfg.configId
),
None,
)

def _update_local_cache(self, new, updated, removed):
self._deviceIds.difference_update(removed)
self._deviceIds.update(cfg.id for cfg in new)
Loading

0 comments on commit 9178e94

Please sign in to comment.