Greg Padgett has uploaded a new change for review. Change subject: client, broker: method to read agent metadata without broker ......................................................................
client, broker: method to read agent metadata without broker Provide a method usable by the ha setup application which will read and parse the ha metadata from the domain without requiring the ha broker. The initial planned use for this is to have setup verify host_id uniqueness during setup before starting the ha daemons. Change-Id: I51612715eee18a488e7d1f7942f0891e35b1fc62 Signed-off-by: Greg Padgett <[email protected]> --- M ovirt_hosted_engine_ha/broker/storage_broker.py M ovirt_hosted_engine_ha/client/client.py 2 files changed, 42 insertions(+), 7 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-ha refs/changes/40/19140/1 diff --git a/ovirt_hosted_engine_ha/broker/storage_broker.py b/ovirt_hosted_engine_ha/broker/storage_broker.py index 5a94f80..f0a05df 100644 --- a/ovirt_hosted_engine_ha/broker/storage_broker.py +++ b/ovirt_hosted_engine_ha/broker/storage_broker.py @@ -36,11 +36,28 @@ def get_all_stats_for_service_type(self, storage_dir, service_type): """ Reads all files in storage_dir for the given service_type, returning a - space-delimited list of "<hostname>=<hex data>" for each host. + space-delimited list of "<host_id>=<hex data>" for each host. + """ + d = self.get_raw_stats_for_service_type(storage_dir, service_type) + str_list = [] + for host_id in sorted(d.items()): + hex_data = base64.b16encode(d.pop(host_id)) + self._log.debug("Read for host id %d: %s", + host_id, hex_data) + str_list.append("{0}={1}".format(host_id, hex_data)) + return str_list + + def get_raw_stats_for_service_type(self, storage_dir, service_type): + """ + Reads all files in storage_dir for the given service_type, returning a + dict of "host_id: data" for each host + + Note: this method is called from the client as well as from + self.get_all_stats_for_service_type(). """ self._log.info("Getting stats for service %s from %s", service_type, storage_dir) - str_list = [] + d = {} with self._storage_access_lock: path = os.path.join(storage_dir, self._get_filename(service_type)) f = None @@ -55,10 +72,7 @@ if host_id > constants.MAX_HOST_ID_SCAN: break if data and data[0] != '\0': - hex_data = base64.b16encode(data) - self._log.debug("Read for host id %d: %s", - host_id, hex_data) - str_list.append("{0}={1}".format(host_id, hex_data)) + d[host_id] = data host_id += 1 except IOError as e: self._log.error("Failed to read metadata from %s", @@ -69,7 +83,7 @@ if f: f.close() - return " ".join(str_list) + return d def put_stats(self, storage_dir, service_type, host_id, data): """ diff --git a/ovirt_hosted_engine_ha/client/client.py b/ovirt_hosted_engine_ha/client/client.py index 46e830f..e5933f3 100644 --- a/ovirt_hosted_engine_ha/client/client.py +++ b/ovirt_hosted_engine_ha/client/client.py @@ -61,3 +61,24 @@ else: output[md['host-id']] = md return output + + def get_all_host_stats_direct(self, dom_path, service_type): + """ + Connects to HA broker, reads stats for all hosts, and returns + them in a dictionary as {host_id: = {key: value, ...}} + """ + from ..broker import storage_broker + + sb = storage_broker.StorageBroker() + stats = sb.get_raw_stats_for_service_type(dom_path, service_type) + + output = {} + for host_str, data in stats.iteritems(): + try: + md = metadata.parse_metadata_to_dict(host_str, data) + except MetadataError as e: + self._log.error(str(e)) + continue + else: + output[md['host-id']] = md + return output -- To view, visit http://gerrit.ovirt.org/19140 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I51612715eee18a488e7d1f7942f0891e35b1fc62 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-hosted-engine-ha Gerrit-Branch: master Gerrit-Owner: Greg Padgett <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
