def build_table_row(k: str, v: object) -> List[Any]: metric_override = v.metricOverride if v.metricOverride else "" if v.info.isUp: backoff_sec = int( (v.linkFlapBackOffMs if v.linkFlapBackOffMs else 0) / 1000 ) if backoff_sec == 0: state = "Up" elif not utils.is_color_output_supported(): state = backoff_sec else: state = click.style("Hold ({} s)".format(backoff_sec), fg="yellow") else: state = ( click.style("Down", fg="red") if utils.is_color_output_supported() else "Down" ) if v.isOverloaded: metric_override = ( click.style("Overloaded", fg="red") if utils.is_color_output_supported() else "Overloaded" ) addrs = [] for prefix in v.info.networks: addrStr = ipnetwork.sprint_addr(prefix.prefixAddress.addr) addrs.append(addrStr) row = [k, state, metric_override, addrs] return row
def _run( self, client: OpenrCtrl.Client, only_suppressed: bool, json: bool, *args, **kwargs, ) -> None: links = client.getInterfaces() if only_suppressed: links.interfaceDetails = { k: v for k, v in links.interfaceDetails.items() if v.linkFlapBackOffMs } if json: self.print_links_json(links) else: if utils.is_color_output_supported(): overload_color = "red" if links.isOverloaded else "green" overload_status = click.style( "{}".format("YES" if links.isOverloaded else "NO"), fg=overload_color, ) caption = "Node Overload: {}".format(overload_status) self.print_links_table(links.interfaceDetails, caption) else: caption = "Node Overload: {}".format( "YES" if links.isOverloaded else "NO") self.print_links_table(links.interfaceDetails, caption)
def print_db_diff( self, nodes_set_a: set, nodes_set_b: set, db_sources: List[str], db_type: str, json: bool, ) -> int: """Returns a status code, 0 = success, 1 = failure""" a_minus_b = sorted(nodes_set_a - nodes_set_b) b_minus_a = sorted(nodes_set_b - nodes_set_a) return_code = 0 if json: diffs_up = [] diffs_down = [] for node in a_minus_b: diffs_up.append(node) for node in b_minus_a: diffs_down.append(node) if diffs_up or diffs_down: diffs = { "db_type": db_type, "db_up": db_sources[0], "db_down": db_sources[1], "nodes_up": diffs_up, "nodes_down": diffs_down, } return_code = 1 utils.print_json(diffs) else: rows = [] for node in a_minus_b: rows.append([ "node {}'s {} db in {} but not in {}".format( node, db_type, *db_sources) ]) for node in b_minus_a: rows.append([ "node {}'s {} db in {} but not in {}".format( node, db_type, *reversed(db_sources)) ]) if rows: print(printing.render_vertical_table(rows)) return_code = 1 if return_code == 1: if utils.is_color_output_supported(): click.echo(click.style("FAIL", bg="red", fg="black")) else: click.echo("FAIL") print("{} table for {} and {} do not match".format( db_type, *db_sources)) else: if utils.is_color_output_supported(): click.echo(click.style("PASS", bg="green", fg="black")) else: click.echo("PASS") print("{} table for {} and {} match".format(db_type, *db_sources)) return return_code