def _run(self, client: OpenrCtrl.Client, json: bool) -> None: openr_version = client.getOpenrVersion() build_info = client.getBuildInfo() if json: if build_info.buildPackageName: info = utils.thrift_to_dict(build_info) print(utils.json_dumps(info)) version = utils.thrift_to_dict(openr_version) print(utils.json_dumps(version)) else: if build_info.buildPackageName: print("Build Information") print(" Built by: {}".format(build_info.buildUser)) print(" Built on: {}".format(build_info.buildTime)) print(" Built at: {}".format(build_info.buildHost)) print(" Build path: {}".format(build_info.buildPath)) print(" Package Name: {}".format(build_info.buildPackageName)) print(" Package Version: {}".format(build_info.buildPackageVersion)) print(" Package Release: {}".format(build_info.buildPackageRelease)) print(" Build Revision: {}".format(build_info.buildRevision)) print( " Build Upstream Revision: {}".format( build_info.buildUpstreamRevision ) ) print(" Build Platform: {}".format(build_info.buildPlatform)) print( " Build Rule: {} ({}, {}, {})".format( build_info.buildRule, build_info.buildType, build_info.buildTool, build_info.buildMode, ) ) rows = [] rows.append(["Open Source Version", ":", openr_version.version]) rows.append( [ "Lowest Supported Open Source Version", ":", openr_version.lowestSupportedVersion, ] ) print( printing.render_horizontal_table( rows, column_labels=[], tablefmt="plain" ) )
def run(self, json): info = self.client.get_build_info() if json: info = utils.thrift_to_dict(info) print(utils.json_dumps(info)) else: print('Build Information') print(' Built by: {}'.format(info.buildUser)) print(' Built on: {}'.format(info.buildTime)) print(' Built at: {}'.format(info.buildHost)) print(' Build path: {}'.format(info.buildPath)) print(' Package Name: {}'.format(info.buildPackageName)) print(' Package Version: {}'.format(info.buildPackageVersion)) print(' Package Release: {}'.format(info.buildPackageRelease)) print(' Build Revision: {}'.format(info.buildRevision)) print(' Build Upstream Revision: {}'.format( info.buildUpstreamRevision)) print(' Build Platform: {}'.format(info.buildPlatform)) print(' Build Rule: {} ({}, {}, {})'.format( info.buildRule, info.buildType, info.buildTool, info.buildMode, ))
def print_kvstore_values(self, resp, json_fmt): ''' print values from raw publication from KvStore :param resp kv_store_types.Publication: pub from kv store ''' # Export in json format if enabled if json_fmt: data = {} for k, v in resp.keyVals.items(): data[k] = utils.thrift_to_dict(v) print(utils.json_dumps(data)) return rows = [] for key, value in sorted(resp.keyVals.items(), key=lambda x: x[0]): val = self.deserialize_kvstore_publication(key, value) if not val: if all(isinstance(c, str) and c in string.printable for c in value.value): val = value.value else: val = hexdump.hexdump(value.value, 'return') ttl = 'INF' if value.ttl == Consts.CONST_TTL_INF else value.ttl rows.append(["key: {}\n version: {}\n originatorId: {}\n " "ttl: {}\n ttlVersion: {}\n value:\n {}" .format(key, value.version, value.originatorId, ttl, value.ttlVersion, val)]) caption = "Dump key-value pairs in KvStore" print(printing.render_vertical_table(rows, caption=caption))
def print_kvstore_keys( self, resp: Dict[str, kv_store_types.Publication], ttl: bool, json: bool ) -> None: """ print keys from raw publication from KvStore""" # Export in json format if enabled if json: all_kv = {} for _, kv in resp.items(): all_kv.update(kv.keyVals) # Force set value to None for value in all_kv.values(): value.value = None data = {} for k, v in all_kv.items(): data[k] = utils.thrift_to_dict(v) print(utils.json_dumps(data)) return rows = [] db_bytes = 0 num_keys = 0 for area in resp: keyVals = resp[area].keyVals num_keys += len(keyVals) area_str = "N/A" if area is None else area for key, value in sorted(keyVals.items(), key=lambda x: x[0]): # 32 bytes comes from version, ttlVersion, ttl and hash which are i64 kv_size = 32 + len(key) + len(value.originatorId) + len(value.value) db_bytes += kv_size hash_offset = "+" if value.hash > 0 else "" row = [ key, value.originatorId, value.version, f"{hash_offset}{value.hash:x}", printing.sprint_bytes(kv_size), area_str, ] if ttl: ttlStr = ( "Inf" if value.ttl == Consts.CONST_TTL_INF else str(datetime.timedelta(milliseconds=value.ttl)) ) row.append(f"{ttlStr} - {value.ttlVersion}") rows.append(row) db_bytes_str = printing.sprint_bytes(db_bytes) caption = f"KvStore Data - {num_keys} keys, {db_bytes_str}" column_labels = ["Key", "Originator", "Ver", "Hash", "Size", "Area"] if ttl: column_labels = column_labels + ["TTL - Ver"] print(printing.render_horizontal_table(rows, column_labels, caption))
def run(self, nodes, json, print_all): publication = self.client.dump_all_with_prefix( Consts.INTERFACE_DB_MARKER) intfs_map = utils.interface_dbs_to_dict(publication, nodes, self.iter_publication) if json: print(utils.json_dumps(intfs_map)) else: utils.print_interfaces_table(intfs_map, print_all)
def print_log_data(self, resp, json_opt): """ print the log data""" if json_opt: event_logs = [] for event_log in resp: event_logs.append(json.loads(event_log)) print(utils.json_dumps(event_logs)) else: for event_log in resp: self.print_log_sample(json.loads(event_log))
def print_kvstore_keys(self, resp, ttl, json_fmt): """ print keys from raw publication from KvStore :param resp kv_store_types.Publication: pub from kv store :param ttl bool: Show ttl value and version if True """ # Force set value to None for value in resp.keyVals.values(): value.value = None # Export in json format if enabled if json_fmt: data = {} for k, v in resp.keyVals.items(): data[k] = utils.thrift_to_dict(v) print(utils.json_dumps(data)) return rows = [] for key, value in sorted(resp.keyVals.items(), key=lambda x: x[0]): hash_offset = "+" if value.hash > 0 else "" if ttl: if value.ttl != Consts.CONST_TTL_INF: ttlStr = str(datetime.timedelta(milliseconds=value.ttl)) else: ttlStr = "Inf" rows.append( [ key, value.originatorId, value.version, "{}{:x}".format(hash_offset, value.hash), "{} - {}".format(ttlStr, value.ttlVersion), ] ) else: rows.append( [ key, value.originatorId, value.version, "{}{:x}".format(hash_offset, value.hash), ] ) caption = "Available keys in KvStore" column_labels = ["Key", "Originator", "Ver", "Hash"] if ttl: column_labels = column_labels + ["TTL - Ver"] print(printing.render_horizontal_table(rows, column_labels, caption))
def run(self, json): openr_version = self.client.get_openr_version() if json: version = utils.thrift_to_dict(openr_version) print(utils.json_dumps(version)) else: rows = [] rows.append(['Current Version', ':', openr_version.version]) rows.append(['Lowest Supported Version', ':', openr_version.lowestSupportedVersion]) print(printing.render_horizontal_table( rows, column_labels=[], tablefmt='plain'))
def print_log_data(self, resp, json_opt): """ print the log data""" if json_opt: data = {} data["eventLogs"] = [utils.thrift_to_dict(e) for e in resp] print(utils.json_dumps(data)) else: log_samples = [] for event_log in resp: log_samples.extend([json.loads(lg) for lg in event_log.samples]) for log_sample in log_samples: self.print_log_sample(log_sample)
def _run(self, client: OpenrCtrl.Client, json: bool) -> None: openr_version = client.getOpenrVersion() if json: version = utils.thrift_to_dict(openr_version) print(utils.json_dumps(version)) else: rows = [] rows.append(["Current Version", ":", openr_version.version]) rows.append( ["Lowest Supported Version", ":", openr_version.lowestSupportedVersion] ) print( printing.render_horizontal_table( rows, column_labels=[], tablefmt="plain" ) )
def print_log_data(self, resp, json_opt): ''' print the log data''' def update_func(json_obj, thrift_obj): json_obj['eventLogs'] = \ [utils.thrift_to_dict(e) for e in thrift_obj.eventLogs] if json_opt: data = utils.thrift_to_dict(resp, update_func) print(utils.json_dumps(data)) return log_samples = [] for event_log in resp.eventLogs: log_samples.extend([json.loads(lg) for lg in event_log.samples]) for log_sample in log_samples: print_log_sample(log_sample)
def get_openr_version_cmd(client, json): ''' Get OpenR version command ''' openr_version = client.get_openr_version() if json: version = utils.thrift_to_dict(openr_version) print(utils.json_dumps(version)) else: rows = [] columns = ['', '', ''] rows.append(['Current version', ':', openr_version.version]) rows.append([ 'Lowest supported version', ':', openr_version.lowestSupportedVersion ]) print(printing.render_horizontal_table(rows, columns, tablefmt='plain'))
def print_counters(self, resp, prefix, is_json): """ print the Kv Store counters """ host_id = utils.get_connected_node_name(self.host, self.lm_cmd_port) caption = "{}'s counters".format(host_id) rows = [] for key, counter in sorted(resp.counters.items()): if not key.startswith(prefix): continue rows.append([key, ":", counter.value]) if is_json: json_data = {k: v for k, _, v in rows} print(utils.json_dumps(json_data)) else: print( printing.render_horizontal_table(rows, caption=caption, tablefmt="plain")) print()
def print_counters(self, resp: Dict, prefix: str, json: bool) -> None: """ print the Kv Store counters """ host_id = utils.get_connected_node_name(self.cli_opts) caption = "{}'s counters".format(host_id) rows = [] for key, counter in sorted(resp.items()): if not key.startswith(prefix): continue rows.append([key, ":", counter]) if json: json_data = {k: v for k, _, v in rows} print(utils.json_dumps(json_data)) else: print( printing.render_horizontal_table( rows, caption=caption, tablefmt="plain" ) ) print()
def _run(self, client: OpenrCtrl.Client, json: bool) -> None: info = client.getBuildInfo() if json: info = utils.thrift_to_dict(info) print(utils.json_dumps(info)) else: print("Build Information") print(" Built by: {}".format(info.buildUser)) print(" Built on: {}".format(info.buildTime)) print(" Built at: {}".format(info.buildHost)) print(" Build path: {}".format(info.buildPath)) print(" Package Name: {}".format(info.buildPackageName)) print(" Package Version: {}".format(info.buildPackageVersion)) print(" Package Release: {}".format(info.buildPackageRelease)) print(" Build Revision: {}".format(info.buildRevision)) print(" Build Upstream Revision: {}".format(info.buildUpstreamRevision)) print(" Build Platform: {}".format(info.buildPlatform)) print( " Build Rule: {} ({}, {}, {})".format( info.buildRule, info.buildType, info.buildTool, info.buildMode ) )
def print_links_json(self, links): links_dict = {links.thisNodeName: self.links_to_dict(links)} print(utils.json_dumps(links_dict))
def topology_json_dump(self, adjs_map_items): adj_topo = {} for this_node_name, db in adjs_map_items: adj_topo[this_node_name] = db print(utils.json_dumps(adj_topo))