Greg Padgett has uploaded a new change for review. Change subject: client: API to retrieve local host score ......................................................................
client: API to retrieve local host score Add client API to retrieve score of local host. Part of a series of patches to enable maintenance mode for the HA hosts and engine VM. Change-Id: I49043a33e927393941e63a89e4e93519431f3695 Bug-Url: https://bugzilla.redhat.com/1015724 Signed-off-by: Greg Padgett <gpadg...@redhat.com> --- M ovirt_hosted_engine_ha/client/client.py 1 file changed, 28 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-ha refs/changes/28/20128/1 diff --git a/ovirt_hosted_engine_ha/client/client.py b/ovirt_hosted_engine_ha/client/client.py index 86e35eb..decfd15 100644 --- a/ovirt_hosted_engine_ha/client/client.py +++ b/ovirt_hosted_engine_ha/client/client.py @@ -19,7 +19,9 @@ import logging import os +import time +from ..agent import constants as agent_constants from ..env import config from ..env import constants from ..env import path @@ -85,3 +87,29 @@ else: output[host_id] = md return output + + def get_local_host_score(self): + if self._config is None: + self._config = config.Config() + + host_id = int(self._config.get(config.ENGINE, config.HOST_ID)) + broker = brokerlink.BrokerLink() + with broker.connection(): + stats = broker.get_stats_from_storage( + path.get_metadata_path(self._config), + constants.SERVICE_TYPE) + + score = 0 + if host_id in stats: + try: + md = metadata.parse_metadata_to_dict(host_id, stats[host_id]) + except MetadataError as e: + self._log.error(str(e)) + else: + # Only report a non-zero score if the local host has had a + # recent update. + if (md['host-ts'] + agent_constants.HOST_ALIVE_TIMEOUT_SECS + >= time.time()): + score = md['score'] + + return score -- To view, visit http://gerrit.ovirt.org/20128 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I49043a33e927393941e63a89e4e93519431f3695 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-hosted-engine-ha Gerrit-Branch: master Gerrit-Owner: Greg Padgett <gpadg...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches