Skip to content

Commit

Permalink
Merge pull request #70 from DMTF/Power-State
Browse files Browse the repository at this point in the history
Added power state info to rf_power_reset.py
  • Loading branch information
mraineri authored Mar 4, 2022
2 parents 6ea9e7a + 03aa885 commit ee3ba9a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
6 changes: 4 additions & 2 deletions redfish_utilities/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions redfish_utilities/systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 7 additions & 2 deletions scripts/rf_power_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,14 +31,19 @@

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:
print( "Supported reset types: {}".format( ", ".join( param["AllowableValues"] ) ) )
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( "No power state information found")
else:
print( "Resetting the system..." )
response = redfish_utilities.system_reset( redfish_obj, args.system, args.type )
Expand Down

0 comments on commit ee3ba9a

Please sign in to comment.