Skip to content

Commit

Permalink
Merge pull request #125 from DMTF/Release-Prep
Browse files Browse the repository at this point in the history
Cleanup prior to release
  • Loading branch information
mraineri authored Aug 14, 2023
2 parents c59b4d6 + 1e49fef commit c4707c3
Show file tree
Hide file tree
Showing 23 changed files with 237 additions and 273 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ required arguments:
optional arguments:
-h, --help show this help message and exit
--id, -i Construct sensor names using 'Id' values
--name, -n Construct sensor names using 'Name' values
--debug Creates debug file showing HTTP traces and exceptions
```

Expand Down
9 changes: 5 additions & 4 deletions redfish_utilities/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"""

from .messages import verify_response
from .messages import RedfishPasswordChangeRequiredError

class RedfishAccountCollectionNotFoundError( Exception ):
"""
Expand Down Expand Up @@ -146,7 +145,7 @@ def delete_user( context, user_name ):
verify_response( response )
return response

def modify_user( context, user_name, new_name = None, new_password = None, new_role = None, new_locked = None, new_enabled = None , user_uri = None):
def modify_user( context, user_name, new_name = None, new_password = None, new_role = None, new_locked = None, new_enabled = None, user_uri = None ):
"""
Modifies an existing user account
Expand All @@ -158,13 +157,14 @@ def modify_user( context, user_name, new_name = None, new_password = None, new_r
new_role: The new role of the user
new_locked: The new locked flag of the user
new_enabled: The new enabled flag of the user
user_uri: The URI of the user to modify
Returns:
The response of the PATCH
"""

# Get the current user info
user_uri, user_info = get_user( context, user_name , user_uri = user_uri)
user_uri, user_info = get_user( context, user_name , user_uri = user_uri )

# Build the payload for the new user
new_info = {}
Expand Down Expand Up @@ -216,6 +216,7 @@ def get_user( context, user_name, user_uri = None ):
Args:
context: The Redfish client object with an open session
user_name: The name of the user to find
user_uri: The URI of the user to get
Returns:
The URI for the user account
Expand All @@ -225,7 +226,7 @@ def get_user( context, user_name, user_uri = None ):
avail_users = []

if user_uri is not None:
account = context.get(user_uri)
account = context.get( user_uri )
if account.dict["UserName"] == user_name:
return user_uri, account

Expand Down
9 changes: 3 additions & 6 deletions redfish_utilities/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,16 @@ def verify_response( response ):
"""

if response.status >= 400:
messages_detail = get_messages_detail(response)
messages_detail = get_messages_detail( response )
exception_string = get_error_messages( messages_detail )
message_item = search_message(messages_detail, "Base", "PasswordChangeRequired")
message_item = search_message( messages_detail, "Base", "PasswordChangeRequired" )
if not message_item is None:
raise RedfishPasswordChangeRequiredError( "Operation failed: HTTP {}\n{}".format( response.status, exception_string ), message_item["MessageArgs"][0])
raise RedfishPasswordChangeRequiredError( "Operation failed: HTTP {}\n{}".format( response.status, exception_string ), message_item["MessageArgs"][0] )
else:
raise RedfishOperationFailedError( "Operation failed: HTTP {}\n{}".format( response.status, exception_string ) )

return

"""
for backend capability
"""
def print_error_payload( response ):
"""
Prints an error payload, which can also be used for action responses
Expand Down
44 changes: 31 additions & 13 deletions redfish_utilities/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,44 @@
# License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/Redfish-Tacklebox/blob/main/LICENSE.md

"""
some misc function implment in here
Miscellaneous
File : misc.py
Brief : some misc function implment in here
Brief : Miscellaneous functions with common script logic
"""

import sys
from redfish.rest.v1 import BadRequestError
def logout(redfish_obj, print_error = False):
if redfish_obj is not None:

def logout( context, ignore_error = False ):
"""
Performs a logout of the service and allows for exceptions to be ignored
Args:
context: The Redfish client object with an open session
ignore_error: Indicates if exceptions during logout are ignored
"""

if context is not None:
try:
redfish_obj.logout()
except BadRequestError as e:
pass
context.logout()
except Exception as e:
if print_error is True:
print(e)
if ignore_error:
pass
else:
raise
return

def print_password_change_required_and_logout(redfish_obj, args):
print("Password change required\n run rf_accounts.py -r {} -u {} -p <old password> --setpassword {} <new password> \nto set your password\n".format(args.rhost ,args.user, args.user))
logout(redfish_obj, print_error = True)
def print_password_change_required_and_logout( context, args ):
"""
Common help text when handling password change required conditions
Args:
context: The Redfish client object with an open session
args: The argparse object from the calling script
"""

print( "Password change required. To set a new password, run the following:" )
print( "rf_accounts.py -r {} -u {} -p <old password> --setpassword {} <new password>".format( args.rhost, args.user, args.user ) )
logout( context, ignore_error = True ) # Some services do not allow session logout in this condition
return
71 changes: 38 additions & 33 deletions redfish_utilities/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
Redfish service's Power and Thermal properties for sensor readings
"""

def get_sensors( context , use_id = False):
def get_sensors( context , use_id = False ):
"""
Walks a Redfish service for sensor information
Args:
context: The Redfish client object with an open session
use_id: Indicates whether to construct names from 'Id' property values
Returns:
A list containing all sensor readings
Expand All @@ -37,9 +38,8 @@ def get_sensors( context , use_id = False):
chassis = context.get( chassis_member["@odata.id"] )

chassis_name = "Chassis " + chassis.dict["Id"]
if use_id is False:
if "Name" in chassis.dict:
chassis_name = chassis.dict["Name"]
if use_id is False and "Name" in chassis.dict:
chassis_name = chassis.dict["Name"]

# Get the chassis status
chassis_instance = {
Expand Down Expand Up @@ -71,9 +71,8 @@ def get_sensors( context , use_id = False):
for power_supply_member in power_supplies.dict["Members"]:
power_supply = context.get( power_supply_member["@odata.id"] )
power_supply_name = "Power Supply " + power_supply.dict["Id"]
if use_id is False:
if "Name" in power_supply.dict:
power_supply_name = power_supply.dict["Name"]
if use_id is False and "Name" in power_supply.dict:
power_supply_name = power_supply.dict["Name"]
get_discrete_status( power_supply_name + " State", power_supply.dict, chassis_instance["Readings"] )
if "Metrics" in power_supply.dict:
metrics = context.get( power_supply.dict["Metrics"]["@odata.id"] )
Expand All @@ -95,9 +94,8 @@ def get_sensors( context , use_id = False):
for battery_member in batteries.dict["Members"]:
battery = context.get( battery_member["@odata.id"] )
battery_name = "Battery " + battery.dict["Id"]
if use_id is False:
if "Name" in battery.dict:
battery_name = battery.dict["Name"]
if use_id is False and "Name" in battery.dict:
battery_name = battery.dict["Name"]
get_discrete_status( battery_name + " State", battery.dict, chassis_instance["Readings"] )
get_excerpt_status( battery_name, "StateOfHealthPercent", "%", battery.dict, chassis_instance["Readings"])
if "Metrics" in battery.dict:
Expand All @@ -115,7 +113,10 @@ def get_sensors( context , use_id = False):
# Add information for each of the redundancy groups reported
if "PowerSupplyRedundancy" in power.dict:
for i, redundancy in enumerate( power.dict["PowerSupplyRedundancy"] ):
get_discrete_status( "Power Supply Redundancy " + str( i ), redundancy, chassis_instance["Readings"] )
redundancy_name = "Power Supply Redundancy " + str( i )
if use_id is False and "Name" in redundancy:
redundancy_name = redundancy["Name"]
get_discrete_status( redundancy_name, redundancy, chassis_instance["Readings"] )

# Get readings from the ThermalSubsystem resource if available
if "ThermalSubsystem" in chassis.dict:
Expand All @@ -136,16 +137,18 @@ def get_sensors( context , use_id = False):
for fan_member in fans.dict["Members"]:
fan = context.get( fan_member["@odata.id"] )
fan_name = "Fan " + fan.dict["Id"]
if use_id is False:
if "Name" in fan.dict:
fan_name = fan.dict["Name"]
if use_id is False and "Name" in fan.dict:
fan_name = fan.dict["Name"]
get_discrete_status( fan_name + " State", fan.dict, chassis_instance["Readings"] )
get_excerpt_status( fan_name, "SpeedPercent", "%", fan.dict, chassis_instance["Readings"])

# Add information for each of the redundancy groups reported
if "FanRedundancy" in thermal.dict:
for i, redundancy in enumerate( thermal.dict["FanRedundancy"] ):
get_discrete_status( "Fan Redundancy " + str( i ), redundancy, chassis_instance["Readings"] )
redundancy_name = "Fan Redundancy " + str( i )
if use_id is False and "Name" in redundancy:
redundancy_name = redundancy["Name"]
get_discrete_status( redundancy_name, redundancy, chassis_instance["Readings"] )

# Get all sensor readings if available
if "Sensors" in chassis.dict:
Expand All @@ -164,9 +167,8 @@ def get_sensors( context , use_id = False):
if "PowerSupplies" in power.dict:
for power_supply in power.dict["PowerSupplies"]:
power_supply_name = "Power Supply " + power_supply["MemberId"]
if use_id is False:
if "Name" in power_supply:
power_supply_name = power_supply["Name"]
if use_id is False and "Name" in power_supply:
power_supply_name = power_supply["Name"]
get_discrete_status( power_supply_name + " State", power_supply, chassis_instance["Readings"] )
get_analog_status_small( power_supply_name, "ReadingVolts", "V", power_supply, chassis_instance["Readings"] )
get_analog_status_small( power_supply_name, "LineInputVoltage", "V", power_supply, chassis_instance["Readings"] )
Expand All @@ -177,15 +179,17 @@ def get_sensors( context , use_id = False):
if "Voltages" in power.dict:
for voltage in power.dict["Voltages"]:
voltage_name = "Voltage " + voltage["MemberId"]
if use_id is False:
if "Name" in voltage:
voltage_name = voltage["Name"]
if use_id is False and "Name" in voltage:
voltage_name = voltage["Name"]
get_analog_status_full( voltage_name, voltage, chassis_instance["Readings"] )

# Add information for each of the redundancy groups reported
if "Redundancy" in power.dict:
for i, redundancy in enumerate( power.dict["Redundancy"] ):
get_discrete_status( "Power Supply Redundancy " + str( i ), redundancy, chassis_instance["Readings"] )
redundancy_name = "Power Supply Redundancy " + str( i )
if use_id is False and "Name" in redundancy:
redundancy_name = redundancy["Name"]
get_discrete_status( redundancy_name, redundancy, chassis_instance["Readings"] )

# Get readings from the Thermal resource if available
if "Thermal" in chassis.dict:
Expand All @@ -195,24 +199,25 @@ def get_sensors( context , use_id = False):
if "Temperatures" in thermal.dict:
for temperature in thermal.dict["Temperatures"]:
temperature_name = "Temperature " + temperature["MemberId"]
if use_id is False:
if "Name" in temperature:
temperature_name = temperature["Name"]
if use_id is False and "Name" in temperature:
temperature_name = temperature["Name"]
get_analog_status_full( temperature_name, temperature, chassis_instance["Readings"] )

# Add information for each of the fans reported
if "Fans" in thermal.dict:
for fan in thermal.dict["Fans"]:
fan_name = "Fan " + fan["MemberId"]
if use_id is False:
if "Name" in fan:
fan_name = fan["Name"]
if use_id is False and "Name" in fan:
fan_name = fan["Name"]
get_analog_status_full( fan_name, fan, chassis_instance["Readings"] )

# Add information for each of the redundancy groups reported
if "Redundancy" in thermal.dict:
for i, redundancy in enumerate( thermal.dict["Redundancy"] ):
get_discrete_status( "Fan Redundancy " + str( i ), redundancy, chassis_instance["Readings"] )
redundancy_name = "Fan Redundancy " + str( i )
if use_id is False and "Name" in redundancy:
redundancy_name = redundancy["Name"]
get_discrete_status( redundancy_name, redundancy, chassis_instance["Readings"] )

return sensor_list

Expand Down Expand Up @@ -375,13 +380,14 @@ def get_excerpt_status( name, field, units, object, readings ):
}
readings.append( reading )

def get_sensor_status( sensor, readings , use_id = False):
def get_sensor_status( sensor, readings , use_id = False ):
"""
Builds an analog reading from a sensor
Args:
sensor: The sensor
readings: The list of readings to update
use_id: Indicates whether to construct names from 'Id' property values
"""

state, health = get_status( sensor )
Expand All @@ -390,11 +396,10 @@ def get_sensor_status( sensor, readings , use_id = False):
if reading_val is None:
reading_val = state

name = sensor.get( "Name", None )

sensor_name = sensor.get( "Name", None )
name = "Sensor " + sensor["Id"]
if use_id is False and name is not None:
name = name
name = sensor_name

reading = {
"Name": name,
Expand Down
Loading

0 comments on commit c4707c3

Please sign in to comment.