From bada90bc55bf3bd78bbfd0329bae8ae5736d73d8 Mon Sep 17 00:00:00 2001 From: SRBuilds Date: Fri, 28 Jun 2024 14:44:53 -0700 Subject: [PATCH] 24.3.3 released --- docs/source/conf.py | 4 +- docs/source/features/{24.3.rst => 24.03.rst} | 8 +++ docs/source/index.rst | 8 +-- examples/convert_example.py | 6 +- examples/filesystem_example.py | 1 + examples/get_all_router_and_vprn.py | 4 +- ...l_vprn_routes_with_nexthop_ipv4_address.py | 5 +- examples/get_inventory_remotely.py | 9 +-- examples/get_list_keys_usage.py | 7 +-- examples/make_connection.py | 7 +-- examples/make_connection_extended.py | 5 +- .../make_connection_extended_with_argv.py | 2 +- examples/set_list.py | 2 +- examples/set_user_example.py | 8 +-- examples/show_command_aliases.py | 31 +++++----- examples/show_event_summary.py | 12 ++-- examples/show_log_event_summary.py | 12 ++-- examples/show_port_counters.py | 18 +++--- examples/show_route_table_communities.py | 4 +- examples/show_route_table_nexthop.py | 6 +- examples/show_router_bgp_asn.py | 62 ++++++++++++------- examples/show_sdp_with_description.py | 4 +- examples/show_statistics_interval.py | 4 +- examples/show_system_commit.py | 7 +-- examples/show_system_summary.py | 43 +++++++------ examples/to_pysros.py | 6 +- examples/who.py | 34 ++++++++-- setup.py | 4 +- 28 files changed, 189 insertions(+), 134 deletions(-) rename docs/source/features/{24.3.rst => 24.03.rst} (69%) diff --git a/docs/source/conf.py b/docs/source/conf.py index 6a2479b..3819526 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -10,8 +10,8 @@ author = 'Nokia' # The full version, including alpha/beta/rc tags -version = '24.3.2' -release = '24.3.2' +version = '24.3.3' +release = '24.3.3' # -- General configuration --------------------------------------------------- diff --git a/docs/source/features/24.3.rst b/docs/source/features/24.03.rst similarity index 69% rename from docs/source/features/24.3.rst rename to docs/source/features/24.03.rst index f94c871..4a84101 100644 --- a/docs/source/features/24.3.rst +++ b/docs/source/features/24.03.rst @@ -1,6 +1,14 @@ Release 24.3 ************ +24.3.3 +###### + +* No additional features + +.. Reviewed by PLM 20240509 +.. Reviewed by TechComms 20210510 + 24.3.2 ###### diff --git a/docs/source/index.rst b/docs/source/index.rst index ece17e5..ebdc113 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -17,11 +17,11 @@ documentation will be updated accordingly. .. list-table:: :header-rows: 0 - * - pySROS release: 24.3.2 - * - Document Number: 3HE 20087 AAAB TQZZA + * - pySROS release: 24.3.3 + * - Document Number: 3HE 20087 AAAC TQZZA -.. Reviewed by PLM 20240403 -.. Reviewed by TechComms 20240403 +.. Reviewed by PLM 20240509 +.. Reviewed by TechComms 20240510 .. toctree:: :maxdepth: 2 diff --git a/examples/convert_example.py b/examples/convert_example.py index a6cef9a..a136bfd 100644 --- a/examples/convert_example.py +++ b/examples/convert_example.py @@ -12,12 +12,12 @@ # Import sys library import sys -# Import the connect method from the management pySROS sub-module -from pysros.management import connect - # Import the exceptions that are referenced so they can be caught on error. from pysros.exceptions import ModelProcessingError +# Import the connect method from the management pySROS sub-module +from pysros.management import connect + class Data: # pylint: disable=too-few-public-methods """Create an object containing the input data in the required format diff --git a/examples/filesystem_example.py b/examples/filesystem_example.py index 2ae5ce4..b8835e8 100644 --- a/examples/filesystem_example.py +++ b/examples/filesystem_example.py @@ -12,6 +12,7 @@ # pylint: disable=broad-except, eval-used, unspecified-encoding import sys + from pysros.management import connect, sros diff --git a/examples/get_all_router_and_vprn.py b/examples/get_all_router_and_vprn.py index ae17e82..ac547af 100755 --- a/examples/get_all_router_and_vprn.py +++ b/examples/get_all_router_and_vprn.py @@ -6,10 +6,10 @@ """Example to get all routers and VPRNs""" - import sys -from pysros.management import connect + from pysros.exceptions import ModelProcessingError +from pysros.management import connect from pysros.pprint import Table # pylint: disable=no-name-in-module credentials = { diff --git a/examples/get_all_vprn_routes_with_nexthop_ipv4_address.py b/examples/get_all_vprn_routes_with_nexthop_ipv4_address.py index 1f5e6c6..3d5b0ac 100755 --- a/examples/get_all_vprn_routes_with_nexthop_ipv4_address.py +++ b/examples/get_all_vprn_routes_with_nexthop_ipv4_address.py @@ -6,10 +6,11 @@ """Example to get all VPRN routes with a given next-hop IP address""" -import sys import ipaddress -from pysros.management import connect +import sys + from pysros.exceptions import ModelProcessingError +from pysros.management import connect from pysros.pprint import Table # pylint: disable=no-name-in-module credentials = { diff --git a/examples/get_inventory_remotely.py b/examples/get_inventory_remotely.py index 287302d..e8368cd 100755 --- a/examples/get_inventory_remotely.py +++ b/examples/get_inventory_remotely.py @@ -6,13 +6,14 @@ """Example to show obtaining a hardware inventory of multiple devices""" -# Import the required libraries -import sys import ipaddress import json -from pysros.management import connect, sros -from pysros.exceptions import ModelProcessingError +# Import the required libraries +import sys + +from pysros.exceptions import ModelProcessingError +from pysros.management import connect, sros # Global credentials dictionary for the purposes of this example. Global variables # discouraged in operational applications. diff --git a/examples/get_list_keys_usage.py b/examples/get_list_keys_usage.py index 4dc6e13..4b6e8e9 100755 --- a/examples/get_list_keys_usage.py +++ b/examples/get_list_keys_usage.py @@ -37,16 +37,13 @@ def get_connection(): # Else if the application is executed remotely else: # Import sys for returning specific exit codes - import sys # pylint: disable=import-outside-toplevel - # Import getpass to read the password import getpass # pylint: disable=import-outside-toplevel + import sys # pylint: disable=import-outside-toplevel # Import the exceptions so they can be caught on error # pylint: disable=import-outside-toplevel - from pysros.exceptions import ( - ModelProcessingError, - ) + from pysros.exceptions import ModelProcessingError # Make sure we have the right number of arguments, the host can # be an IP address or a hostname diff --git a/examples/make_connection.py b/examples/make_connection.py index 1453fb5..4f556fd 100755 --- a/examples/make_connection.py +++ b/examples/make_connection.py @@ -6,16 +6,15 @@ """Example to show how to make a connection and handle exceptions""" - # Import sys for returning specific exit codes import sys -# Import the connect method from the management pySROS sub-module -from pysros.management import connect - # Import the exceptions that are referenced so they can be caught on error. from pysros.exceptions import ModelProcessingError +# Import the connect method from the management pySROS sub-module +from pysros.management import connect + def get_connection(host=None, credentials=None): """Function definition to obtain a Connection object to a specific SR OS device diff --git a/examples/make_connection_extended.py b/examples/make_connection_extended.py index 0a60c3c..1098240 100755 --- a/examples/make_connection_extended.py +++ b/examples/make_connection_extended.py @@ -42,16 +42,15 @@ def get_connection(): # Else if the application is executed remotely else: # Import sys for returning specific exit codes - import sys - # Import getpass to read the password import getpass + import sys # Import the exceptions so they can be caught on error # fmt: off from pysros.exceptions import ModelProcessingError - # fmt: on + # fmt: on # Make sure we have the right number of arguments, the host can # be an IP address or a hostname if len(sys.argv) != 2: diff --git a/examples/make_connection_extended_with_argv.py b/examples/make_connection_extended_with_argv.py index b155996..6cbc645 100755 --- a/examples/make_connection_extended_with_argv.py +++ b/examples/make_connection_extended_with_argv.py @@ -42,8 +42,8 @@ def get_remote_connection(my_username, my_host, my_password): # Import the exceptions so they can be caught on error # fmt: off from pysros.exceptions import ModelProcessingError - # fmt: on + # fmt: on # The try statement and except statements allow an operation # attempt with specific error conditions handled gracefully try: diff --git a/examples/set_list.py b/examples/set_list.py index bce33dd..30ce0df 100755 --- a/examples/set_list.py +++ b/examples/set_list.py @@ -8,10 +8,10 @@ # Import the required libraries import sys -from pysros.management import connect # Import the exceptions so they can be caught on error. from pysros.exceptions import ModelProcessingError +from pysros.management import connect def get_connection(host=None, credentials=None): diff --git a/examples/set_user_example.py b/examples/set_user_example.py index e4ec05f..77d9d42 100755 --- a/examples/set_user_example.py +++ b/examples/set_user_example.py @@ -7,15 +7,15 @@ """Example to show how to set data""" +import random +import string + # Import the required libraries import sys -import string -import random -from pysros.management import connect # Import the exceptions so they can be caught on error. from pysros.exceptions import ModelProcessingError - +from pysros.management import connect # Global credentials dictionary for the purposes of this example. Global variables # discouraged in operational applications. diff --git a/examples/show_command_aliases.py b/examples/show_command_aliases.py index 75faf29..f1037d2 100755 --- a/examples/show_command_aliases.py +++ b/examples/show_command_aliases.py @@ -7,7 +7,7 @@ # pylint: disable=import-error, import-outside-toplevel, line-too-long, too-many-branches, too-many-locals, too-many-statements """ -Tested on: SR OS 23.10.R2 +Tested on: SR OS 24.3.R1 Show command aliaseses. @@ -58,8 +58,8 @@ def get_remote_connection(my_username, my_host, my_password): # Import the exceptions so they can be caught on error # fmt: off from pysros.exceptions import ModelProcessingError - # fmt: on + # fmt: on # The try statement and except statements allow an operation # attempt with specific error conditions handled gracefully try: @@ -99,11 +99,12 @@ def get_remote_connection(my_username, my_host, my_password): def show_command_aliases_output(connection_object): """Main function for the show_command_aliases command""" - bright_red = "\u001b[31;1m" - bright_green = "\u001b[32;1m" - bright_blue = "\u001b[34;1m" - bright_cyan = "\u001b[36;1m" - reset_color = "\u001b[0m" + bright_blue = "\033[1;34m" + bright_cyan = "\033[1;36m" + bright_green = "\033[1;32m" + bright_red = "\033[1;31m" + bright_yellow = "\033[1;33m" + reset_color = "\033[0m" # Get environment configuration data try: @@ -155,7 +156,7 @@ def show_command_aliases_output(connection_object): ): print( "Alias name : " - + bright_cyan + + bright_blue + alias_name + reset_color + " (" @@ -168,11 +169,11 @@ def show_command_aliases_output(connection_object): else: print( "Alias name : " - + bright_cyan + + bright_blue + alias_name + reset_color + " (" - + bright_red + + bright_yellow + "disabled" + reset_color, end="", @@ -246,7 +247,7 @@ def show_command_aliases_output(connection_object): if mount_point == "global": print( "Availability : " - + bright_blue + + bright_cyan + alias_name + reset_color + " (global)" @@ -254,7 +255,7 @@ def show_command_aliases_output(connection_object): else: print( "Availability : " - + bright_blue + + bright_cyan + mount_point.replace("/", "") + " " + alias_name @@ -264,7 +265,7 @@ def show_command_aliases_output(connection_object): if mount_point == "global": print( " : " - + bright_blue + + bright_cyan + alias_name + reset_color + " (global)" @@ -283,7 +284,7 @@ def show_command_aliases_output(connection_object): print("-" * 80) print( "Total aliases : " - + bright_cyan + + bright_blue + str(num_admin_up_aliases + num_admin_down_aliases) + reset_color + " (" @@ -291,7 +292,7 @@ def show_command_aliases_output(connection_object): + str(num_admin_up_aliases) + reset_color + " enabled, " - + bright_red + + bright_yellow + str(num_admin_down_aliases) + reset_color + " disabled, " diff --git a/examples/show_event_summary.py b/examples/show_event_summary.py index bd73416..9b2e820 100755 --- a/examples/show_event_summary.py +++ b/examples/show_event_summary.py @@ -32,9 +32,9 @@ """ +from pysros.exceptions import InternalError, InvalidPathError, SrosMgmtError from pysros.management import connect, sros -from pysros.pprint import Table -from pysros.exceptions import InvalidPathError, SrosMgmtError, InternalError +from pysros.pprint import Table # pylint: disable=no-name-in-module def get_connection(): @@ -56,16 +56,16 @@ def get_connection(): # Else if the application is executed remotely else: # Import sys for returning specific exit codes - import sys # pylint: disable=import-outside-toplevel - # Import getpass to read the password import getpass # pylint: disable=import-outside-toplevel + import sys # pylint: disable=import-outside-toplevel # Import the exceptions so they can be caught on error # fmt: off - from pysros.exceptions import ModelProcessingError # pylint: disable=import-error disable=import-outside-toplevel - # fmt: on + from pysros.exceptions import \ + ModelProcessingError # pylint: disable=import-error disable=import-outside-toplevel + # fmt: on # Make sure we have the right number of arguments, the host can # be an IP address or a hostname if len(sys.argv) != 2: diff --git a/examples/show_log_event_summary.py b/examples/show_log_event_summary.py index 888c047..42c5065 100755 --- a/examples/show_log_event_summary.py +++ b/examples/show_log_event_summary.py @@ -7,7 +7,7 @@ # pylint: disable=line-too-long """ -Tested on: SR OS 23.10.R2 +Tested on: SR OS 24.3.R1 Obtain a summary of the log event history on the node. @@ -32,9 +32,9 @@ """ +from pysros.exceptions import InternalError, InvalidPathError, SrosMgmtError from pysros.management import connect, sros from pysros.pprint import Table -from pysros.exceptions import InvalidPathError, SrosMgmtError, InternalError def get_connection(): @@ -56,16 +56,16 @@ def get_connection(): # Else if the application is executed remotely else: # Import sys for returning specific exit codes - import sys # pylint: disable=import-outside-toplevel - # Import getpass to read the password import getpass # pylint: disable=import-outside-toplevel + import sys # pylint: disable=import-outside-toplevel # Import the exceptions so they can be caught on error # fmt: off - from pysros.exceptions import ModelProcessingError # pylint: disable=import-error disable=import-outside-toplevel - # fmt: on + from pysros.exceptions import \ + ModelProcessingError # pylint: disable=import-error disable=import-outside-toplevel + # fmt: on # Make sure we have the right number of arguments, the host can # be an IP address or a hostname if len(sys.argv) != 2: diff --git a/examples/show_port_counters.py b/examples/show_port_counters.py index f8b7daf..8a01c3c 100755 --- a/examples/show_port_counters.py +++ b/examples/show_port_counters.py @@ -7,7 +7,7 @@ # pylint: disable=import-error, import-outside-toplevel, line-too-long, too-many-branches, too-many-locals, too-many-statements """ -Tested on: SR OS 23.10.R2 +Tested on: SR OS 24.3.R1 Show port counters. @@ -36,12 +36,12 @@ /configure system { management-interface cli md-cli environment command-alias alias "counters" mount-point "/show port" } """ -# Import sys for parsing arguments and returning specific exit codes -import sys - # Import datetime to get and display the date and time import datetime +# Import sys for parsing arguments and returning specific exit codes +import sys + # Import the connect and sros methods from the management pySROS submodule from pysros.management import connect, sros @@ -302,8 +302,8 @@ def get_remote_connection(my_username, my_host, my_password): # Import the exceptions so they can be caught on error # fmt: off from pysros.exceptions import ModelProcessingError - # fmt: on + # fmt: on # The try statement and except statements allow an operation # attempt with specific error conditions handled gracefully try: @@ -372,10 +372,10 @@ def print_row_with_spacing(spacer, column, name, value): def show_port_counters_output(connection_object, language): """Main function for the show_port_counters command""" - bright_green = "\u001b[32;1m" - bright_red = "\u001b[31;1m" - bright_yellow = "\u001b[33;1m" - reset_color = "\u001b[0m" + bright_green = "\033[1;32m" + bright_red = "\033[1;31m" + bright_yellow = "\033[1;33m" + reset_color = "\033[0m" # Define local language oper-state strings and colors oper_state_str = { diff --git a/examples/show_route_table_communities.py b/examples/show_route_table_communities.py index 74a673f..6899a37 100755 --- a/examples/show_route_table_communities.py +++ b/examples/show_route_table_communities.py @@ -8,11 +8,11 @@ import re import sys -from pysros.management import connect -from pysros.pprint import Table # pylint: disable=no-name-in-module # Import the exceptions so they can be caught on error. from pysros.exceptions import ModelProcessingError +from pysros.management import connect +from pysros.pprint import Table # pylint: disable=no-name-in-module credentials = { "host": "192.168.1.1", diff --git a/examples/show_route_table_nexthop.py b/examples/show_route_table_nexthop.py index 6259cf3..4c95002 100755 --- a/examples/show_route_table_nexthop.py +++ b/examples/show_route_table_nexthop.py @@ -6,13 +6,13 @@ """Example to show all bgp routes for a given next-hop""" -import sys import ipaddress -from pysros.management import connect -from pysros.pprint import Table # pylint: disable=no-name-in-module +import sys # Import the exceptions so they can be caught on error. from pysros.exceptions import ModelProcessingError +from pysros.management import connect +from pysros.pprint import Table # pylint: disable=no-name-in-module credentials = { "host": "192.168.1.1", diff --git a/examples/show_router_bgp_asn.py b/examples/show_router_bgp_asn.py index b5c2bb7..8c89637 100755 --- a/examples/show_router_bgp_asn.py +++ b/examples/show_router_bgp_asn.py @@ -7,7 +7,7 @@ # pylint: disable=import-error, import-outside-toplevel, line-too-long, too-many-branches, too-many-locals, too-many-statements """ -Tested on: SR OS 23.10.R2 +Tested on: SR OS 24.3.R1 Show all BGP peers for an ASN. @@ -32,12 +32,12 @@ /configure system { management-interface cli md-cli environment command-alias alias "asn" mount-point "/show router bgp" } """ -# Import sys for parsing arguments and returning specific exit codes -import sys - # Import datetime to get and display the date and time import datetime +# Import sys for parsing arguments and returning specific exit codes +import sys + # Import the connect and sros methods from the management pySROS submodule from pysros.management import connect, sros @@ -61,8 +61,8 @@ def get_remote_connection(my_username, my_host, my_password): # Import the exceptions so they can be caught on error # fmt: off from pysros.exceptions import ModelProcessingError - # fmt: on + # fmt: on # The try statement and except statements allow an operation # attempt with specific error conditions handled gracefully try: @@ -102,11 +102,15 @@ def get_remote_connection(my_username, my_host, my_password): def show_router_bgp_asn_output(connection_object, asn): """Main function for the show_router_bgp_asn command""" - bright_cyan = "\u001b[36;1m" - bright_green = "\u001b[32;1m" - bright_red = "\u001b[31;1m" - bright_yellow = "\u001b[33;1m" - reset_color = "\u001b[0m" + bright_cyan = "\033[1;36m" + bright_black = "\033[1;30m" + bright_blue = "\033[1;34m" + bright_green = "\033[1;32m" + bright_magenta = "\033[1;35m" + bright_red = "\033[1;31m" + bright_yellow = "\033[1;33m" + cyan = "\033[0;36m" + reset_color = "\033[0m" bgp_stats = None oper_name = connection_object.running.get( @@ -133,11 +137,11 @@ def show_router_bgp_asn_output(connection_object, asn): if "peer-as" not in bgp_config[neighbor]: # If not, try to get the peer-as from the neighbor's group try: - bgp_config[neighbor][ - "peer-as" - ] = connection_object.running.get( - "/nokia-conf:configure/router[router-name=Base]/bgp/group[group-name=%s]/peer-as" - % bgp_config[neighbor]["group"] + bgp_config[neighbor]["peer-as"] = ( + connection_object.running.get( + "/nokia-conf:configure/router[router-name=Base]/bgp/group[group-name=%s]/peer-as" + % bgp_config[neighbor]["group"] + ) ) except LookupError as lookup_error: print( @@ -196,14 +200,18 @@ def show_router_bgp_asn_output(connection_object, asn): ) print( " State|" - + bright_cyan + + bright_blue + "Rcv" + reset_color + "/" + bright_green + "Act" + reset_color - + "/Sent (Addr Family)" + + "/" + + bright_magenta + + "Sent" + + reset_color + + " (Addr Family)" ) print("{0:<13} {1:<13}/{2:<13}".format("", "Messages Sent", "Out Queue")) print("-" * 80) @@ -215,13 +223,21 @@ def show_router_bgp_asn_output(connection_object, asn): for neighbor in sorted(bgp_config): if asn == 0 or int(asn) == bgp_config[neighbor]["peer-as"].data: # Print line 1 + print(bright_cyan, end="") print( - "{0:<45} {1} ({2})".format( + "{0:<45}{1} {2}{3}{4} {5}({6}{7}{8}){9}".format( neighbor, + reset_color, + cyan, bgp_stats[neighbor]["statistics"]["last-established-time"], + reset_color, + bright_black, + cyan, bgp_stats[neighbor]["statistics"][ "established-transitions" ], + bright_black, + reset_color, ) ) @@ -284,13 +300,13 @@ def show_router_bgp_asn_output(connection_object, asn): end="", ) print( - bright_cyan + bright_blue + str( bgp_stats[neighbor]["statistics"]["family-prefix"][ family.lower() ]["received"] ) - + reset_color + + bright_black + "/" + bright_green + str( @@ -298,13 +314,15 @@ def show_router_bgp_asn_output(connection_object, asn): family.lower() ]["received"] ) - + reset_color + + bright_black + "/" + + bright_magenta + str( bgp_stats[neighbor]["statistics"]["family-prefix"][ family.lower() ]["sent"] ) + + reset_color + " (" + str(family) + ")" @@ -363,7 +381,7 @@ def show_router_bgp_asn_output(connection_object, asn): print("-" * 80) print( "Total neighbors : " - + bright_cyan + + bright_blue + str(num_up_neighbors + num_down_neighbors + num_disabled_neighbors) + reset_color + " (" diff --git a/examples/show_sdp_with_description.py b/examples/show_sdp_with_description.py index 85accde..cb3ea6c 100755 --- a/examples/show_sdp_with_description.py +++ b/examples/show_sdp_with_description.py @@ -8,11 +8,11 @@ # Import the required libraries for the application. import sys -from pysros.management import connect -from pysros.pprint import Table # pylint: disable=no-name-in-module # Import the exceptions so they can be caught on error. from pysros.exceptions import ModelProcessingError +from pysros.management import connect +from pysros.pprint import Table # pylint: disable=no-name-in-module # Global credentials dictionary for the purposes of this example. Global variables # discouraged in operational applications. diff --git a/examples/show_statistics_interval.py b/examples/show_statistics_interval.py index a92c20c..d9ec301 100755 --- a/examples/show_statistics_interval.py +++ b/examples/show_statistics_interval.py @@ -8,11 +8,11 @@ import sys import time -from pysros.management import connect, sros -from pysros.pprint import Table # pylint: disable=no-name-in-module # Import the exceptions so they can be caught on error. from pysros.exceptions import ModelProcessingError +from pysros.management import connect, sros +from pysros.pprint import Table # pylint: disable=no-name-in-module credentials = { "host": "192.168.1.1", diff --git a/examples/show_system_commit.py b/examples/show_system_commit.py index ccdcbc0..44dcd5b 100755 --- a/examples/show_system_commit.py +++ b/examples/show_system_commit.py @@ -7,7 +7,7 @@ # pylint: disable=import-error, import-outside-toplevel, line-too-long, too-many-branches, too-many-locals, too-many-statements """ -Tested on: SR OS 22.2.R1 +Tested on: SR OS 24.3.R1 Show the commit history in an alternate format. @@ -56,16 +56,15 @@ def get_connection(): # Else if the application is executed remotely else: # Import sys for returning specific exit codes - import sys - # Import getpass to read the password import getpass + import sys # Import the exceptions so they can be caught on error # fmt: off from pysros.exceptions import ModelProcessingError - # fmt: on + # fmt: on # Make sure we have the right number of arguments, the host can # be an IP address or a hostname if len(sys.argv) != 2: diff --git a/examples/show_system_summary.py b/examples/show_system_summary.py index 6de677c..8afe33f 100755 --- a/examples/show_system_summary.py +++ b/examples/show_system_summary.py @@ -7,7 +7,7 @@ # pylint: disable=import-error, import-outside-toplevel, line-too-long, too-many-branches, too-many-locals, too-many-statements """ -Tested on: SR OS 23.10.R2 +Tested on: SR OS 24.3.R1 Show system summary information. @@ -37,15 +37,17 @@ /configure system { management-interface cli md-cli environment command-alias alias "summary" mount-point "/show system" } """ -# Import sys for parsing arguments and returning specific exit codes -import sys - # Import datetime to get and display the date and time import datetime +# Import sys for parsing arguments and returning specific exit codes +import sys + # Import the connect and sros methods from the management pySROS submodule from pysros.management import connect, sros +# Import the Container and Leaf structures from the wrappers pySROS submodule +from pysros.wrappers import Container, Leaf # Define local language strings local_str = { @@ -154,8 +156,8 @@ def get_remote_connection(my_username, my_host, my_password): # Import the exceptions so they can be caught on error # fmt: off from pysros.exceptions import ModelProcessingError - # fmt: on + # fmt: on # The try statement and except statements allow an operation # attempt with specific error conditions handled gracefully try: @@ -196,18 +198,19 @@ def print_rows(input_data, column): """Print table rows in the specified format""" for k in sorted(input_data): - # Elements with no data are not displayed - if input_data[k].data: - # If the input data is a dict like from - # /nokia-state:state/system/alarms/active then recurse - if isinstance(input_data[k].data, dict): - print_rows(input_data[k].data, column) - else: - print( - "{0:<{width}} : {1}".format( - k, str(input_data[k].data), width=column - ) + # If the input data is a Leaf, and has data + # (elements with no data are not displayed) + if isinstance(input_data[k], Leaf) and input_data[k].data: + print( + "{0:<{width}} : {1}".format( + k, str(input_data[k].data), width=column ) + ) + # If the input data is a Container like from + # /nokia-state:state/system/alarms/active then recurse + elif isinstance(input_data[k], Container): + print_rows(input_data[k].data, column) + # Else the input data is not a Leaf or Container, so ignore it def set_column_width(input_data): @@ -248,10 +251,10 @@ def print_row_mixed_spacing(language, column, name, value): def show_system_summary_output(connection_object, language): """Main function for the show_system_summary command""" - bright_green = "\u001b[32;1m" - bright_red = "\u001b[31;1m" - bright_yellow = "\u001b[33;1m" - reset_color = "\u001b[0m" + bright_green = "\033[1;32m" + bright_red = "\033[1;31m" + bright_yellow = "\033[1;33m" + reset_color = "\033[0m" # Define local language oper-state strings and colors oper_state_str = { diff --git a/examples/to_pysros.py b/examples/to_pysros.py index f82c423..5b1f992 100644 --- a/examples/to_pysros.py +++ b/examples/to_pysros.py @@ -17,13 +17,15 @@ Execution on remote machine Not supported. """ + import builtins +import json # Required imports import sys -import json -from pysros.management import connect + from pysros.exceptions import ModelProcessingError +from pysros.management import connect def get_connection(): diff --git a/examples/who.py b/examples/who.py index ce760f7..a5fc584 100755 --- a/examples/who.py +++ b/examples/who.py @@ -7,7 +7,7 @@ # pylint: disable=import-error, import-outside-toplevel, line-too-long, too-many-branches, too-many-locals, too-many-statements """ -Tested on: SR OS 23.10.R2 +Tested on: SR OS 24.3.R1 Show who is logged on. @@ -54,8 +54,8 @@ def get_remote_connection(my_username, my_host, my_password): # Import the exceptions so they can be caught on error # fmt: off from pysros.exceptions import ModelProcessingError - # fmt: on + # fmt: on # The try statement and except statements allow an operation # attempt with specific error conditions handled gracefully try: @@ -150,6 +150,13 @@ def get_connection_with_argv(): def who_output(connection_object, arg): """Main function for the who command""" + bright_cyan = "\033[1;36m" + bright_dark_gray = "\033[1;30m" + cyan = "\033[0;36m" + reset_color = "\033[0m" + user_color = reset_color + separator_color = reset_color + # Get the users state users = connection_object.running.get("/nokia-state:state/users/session") @@ -163,11 +170,23 @@ def who_output(connection_object, arg): ): continue + # Set color on the active session + if str(users[session_id]["current-active-session"]) == "True": + user_color = bright_cyan + separator_color = bright_dark_gray + text_color = cyan + else: + user_color = reset_color + separator_color = reset_color + text_color = reset_color + # Print session info in who(1) format # GNU who displays "%-8s" for user, use same format + print(user_color, end="") print( - "{0:8.8} {1}/{2}\t{3}".format( + "{0:8.8} {1}{2}/{3}\t{4}".format( str(users[session_id]["user"]), + reset_color, str(users[session_id]["connection-type"]), str(session_id), str(users[session_id]["login-time"]), @@ -177,11 +196,18 @@ def who_output(connection_object, arg): if "connection-ip" in users[session_id]: print( - " (" + " " + + separator_color + + "(" + + text_color + str(users[session_id]["router-instance"]) + + separator_color + "/" + + text_color + str(users[session_id]["connection-ip"]) + + separator_color + ")" + + reset_color ) else: print() diff --git a/setup.py b/setup.py index 156854a..2f643db 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -# Copyright 2021 Nokia +# Copyright 2021-2024 Nokia from setuptools import setup @@ -7,7 +7,7 @@ setup( name='pysros', - version='24.3.2', + version='24.3.3', packages=['pysros'], url='https://www.nokia.com', license='Copyright 2021-2024 Nokia. License available in the LICENSE.md file.',