From 482bde945db2cb7712d0c86185afaf526fef1281 Mon Sep 17 00:00:00 2001 From: Mike Raineri Date: Fri, 4 Mar 2022 12:40:41 -0500 Subject: [PATCH 1/4] Added power state info to rf_power_reset.py Signed-off-by: Mike Raineri --- scripts/rf_power_reset.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/rf_power_reset.py b/scripts/rf_power_reset.py index 3dec39e..7156620 100644 --- a/scripts/rf_power_reset.py +++ b/scripts/rf_power_reset.py @@ -32,6 +32,7 @@ try: if args.info: reset_uri, reset_parameters = redfish_utilities.get_system_reset_info( redfish_obj, args.system ) + system_info = redfish_utilities.get_system( redfish_obj, args.system ) printed_reset_types = False for param in reset_parameters: if param["Name"] == "ResetType" and "AllowableValues" in param: @@ -39,6 +40,10 @@ printed_reset_types = True if not printed_reset_types: print( "No reset information found" ) + if "PowerState" in system_info.dict: + print( "Current power state: {}".format( system_info.dict["PowerState"] ) ) + else: + print( "Not power state information found") else: print( "Resetting the system..." ) response = redfish_utilities.system_reset( redfish_obj, args.system, args.type ) From 5bc570341bf3fa5d107c028a2dd22f03fb3e4b5b Mon Sep 17 00:00:00 2001 From: Mike Raineri Date: Fri, 4 Mar 2022 12:42:29 -0500 Subject: [PATCH 2/4] Updating descriptions for new info Signed-off-by: Mike Raineri --- README.md | 3 ++- scripts/rf_power_reset.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4716992..bb7646a 100644 --- a/README.md +++ b/README.md @@ -179,7 +179,8 @@ optional arguments: --system SYSTEM, -s SYSTEM The ID of the system to reset --type {On,ForceOff,GracefulShutdown,GracefulRestart,ForceRestart,Nmi,ForceOn,PushPowerButton,PowerCycle}, -t {On,ForceOff,GracefulShutdown,GracefulRestart,ForceRestart,Nmi,ForceOn,PushPowerButton,PowerCycle} - --info, -info Indicates if reset information should be reported + --info, -info Indicates if reset and power information should be + reported ``` Example: `rf_power_reset.py -u root -p root -r https://192.168.1.100 -t GracefulRestart` diff --git a/scripts/rf_power_reset.py b/scripts/rf_power_reset.py index 7156620..87140a8 100644 --- a/scripts/rf_power_reset.py +++ b/scripts/rf_power_reset.py @@ -22,7 +22,7 @@ argget.add_argument( "--rhost", "-r", type = str, required = True, help = "The address of the Redfish service (with scheme)" ) argget.add_argument( "--system", "-s", type = str, help = "The ID of the system to reset" ) argget.add_argument( "--type", "-t", type = str, help = "The type of power/reset operation to perform", choices = redfish_utilities.reset_types ) -argget.add_argument( "--info", "-info", action = "store_true", help = "Indicates if reset information should be reported" ) +argget.add_argument( "--info", "-info", action = "store_true", help = "Indicates if reset and power information should be reported" ) args = argget.parse_args() # Set up the Redfish object From 026dc77ff7e5841f5c6e460ba7f33def3023d712 Mon Sep 17 00:00:00 2001 From: Mike Raineri Date: Fri, 4 Mar 2022 14:12:47 -0500 Subject: [PATCH 3/4] Text typo correction Signed-off-by: Mike Raineri --- scripts/rf_power_reset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/rf_power_reset.py b/scripts/rf_power_reset.py index 87140a8..6760d02 100644 --- a/scripts/rf_power_reset.py +++ b/scripts/rf_power_reset.py @@ -43,7 +43,7 @@ if "PowerState" in system_info.dict: print( "Current power state: {}".format( system_info.dict["PowerState"] ) ) else: - print( "Not power state information found") + print( "No power state information found") else: print( "Resetting the system..." ) response = redfish_utilities.system_reset( redfish_obj, args.system, args.type ) From 03aa8858c2a84b9072fe26fbb97cfa1af2b70dcc Mon Sep 17 00:00:00 2001 From: Mike Raineri Date: Fri, 4 Mar 2022 14:19:00 -0500 Subject: [PATCH 4/4] Added optimization to collect and print reset action info with power info in a single request Signed-off-by: Mike Raineri --- redfish_utilities/managers.py | 6 ++++-- redfish_utilities/systems.py | 6 ++++-- scripts/rf_power_reset.py | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/redfish_utilities/managers.py b/redfish_utilities/managers.py index 7bea540..10ed981 100644 --- a/redfish_utilities/managers.py +++ b/redfish_utilities/managers.py @@ -118,20 +118,22 @@ def print_manager( manager ): print( manager_line_format.format( property, prop_val ) ) print( "" ) -def get_manager_reset_info( context, manager_id = None ): +def get_manager_reset_info( context, manager_id = None, manager = None ): """ Finds a manager matching the given ID and returns its reset info Args: context: The Redfish client object with an open session manager_id: The manager to locate; if None, perform on the only manager + manager: Existing manager resource to inspect for reset info Returns: The URI of the Reset action A list of parameter requirements from the Action Info """ - manager = get_manager( context, manager_id ) + if manager is None: + manager = get_manager( context, manager_id ) # Check that there is a Reset action if "Actions" not in manager.dict: diff --git a/redfish_utilities/systems.py b/redfish_utilities/systems.py index 20101ba..13f1733 100644 --- a/redfish_utilities/systems.py +++ b/redfish_utilities/systems.py @@ -217,20 +217,22 @@ def print_system_boot( boot ): print( "" ) -def get_system_reset_info( context, system_id = None ): +def get_system_reset_info( context, system_id = None, system = None ): """ Finds a system matching the given ID and returns its reset info Args: context: The Redfish client object with an open session system_id: The system to locate; if None, perform on the only system + system: Existing system resource to inspect for reset info Returns: The URI of the Reset action A list of parameter requirements from the Action Info """ - system = get_system( context, system_id ) + if system is None: + system = get_system( context, system_id ) # Check that there is a Reset action if "Actions" not in system.dict: diff --git a/scripts/rf_power_reset.py b/scripts/rf_power_reset.py index 6760d02..fc78bf8 100644 --- a/scripts/rf_power_reset.py +++ b/scripts/rf_power_reset.py @@ -31,8 +31,8 @@ try: if args.info: - reset_uri, reset_parameters = redfish_utilities.get_system_reset_info( redfish_obj, args.system ) system_info = redfish_utilities.get_system( redfish_obj, args.system ) + reset_uri, reset_parameters = redfish_utilities.get_system_reset_info( redfish_obj, args.system, system_info ) printed_reset_types = False for param in reset_parameters: if param["Name"] == "ResetType" and "AllowableValues" in param: