7.5 KiB
7.5 KiB
Using Sushy
To use sushy in a project:
Specifying an authentication type
There are three authentication objects. By default we use SessionOrBasicAuth. Authentication Modes: auth.SessionOrBasicAuth: Use session based authentication. If we are unable to create a session we will fallback to basic authentication. auth.BasicAuth: Use basic authentication only. auth.SessionAuth: Use session based authentication only.
import logging
import sushy
from sushy import auth
# Enable logging at DEBUG level
= logging.getLogger('sushy')
LOG
LOG.setLevel(logging.DEBUG)
LOG.addHandler(logging.StreamHandler())
= auth.BasicAuth(username='foo', password='bar')
basic_auth = auth.SessionAuth(username='foo', password='bar')
session_auth = auth.SessionOrBasicAuth(username='foo',
session_or_basic_auth ='bar')
password
= sushy.Sushy('http://localhost:8000/redfish/v1',
s =basic_auth)
auth
= sushy.Sushy('http://localhost:8000/redfish/v1',
s =session_auth)
auth
= sushy.Sushy('http://localhost:8000/redfish/v1',
s =session_or_basic_auth)
auth
# It is important to note that you can
# call sushy without supplying an
# authentication object. In that case we
# will use the SessionOrBasicAuth authentication
# object in an attempt to connect to all different
# types of redfish servers.
= sushy.Sushy('http://localhost:8000/redfish/v1',
s ='foo',
username='bar') password
Creating and using a sushy system object
import logging
import sushy
# Enable logging at DEBUG level
= logging.getLogger('sushy')
LOG
LOG.setLevel(logging.DEBUG)
LOG.addHandler(logging.StreamHandler())
= sushy.Sushy('http://localhost:8000/redfish/v1',
s ='foo', password='bar')
username
# Get the Redfish version
print(s.redfish_version)
# Instantiate a system object
= s.get_system('/redfish/v1/Systems/437XR1138R2')
sys_inst
# Using system collections
# Instantiate a SystemCollection object
= s.get_system_collection()
sys_col
# Print the ID of the systems available in the collection
print(sys_col.members_identities)
# Get a list of systems objects available in the collection
= sys_col.get_members()
sys_col_insts
# Instantiate a system object, same as getting it directly
# from the s.get_system()
= sys_col.get_member(sys_col.members_identities[0])
sys_inst
# Refresh the system collection object
#
# In order to reload a resource post its initialization it has to be marked
# as stale (i.e. invoking 'invalidate()') first and then 'refresh()' has to
# be called. This will only reload the resource w/o reloading/refreshing its
# sub-resources (lazy-refresh of sub-resources).
# Note that calling 'refresh()' only, i.e. w/o calling 'invalidate()' first,
# will be a no-op wrt resource reload in this case.
sys_col.invalidate()
sys_col.refresh()
# Using system actions
# Power the system ON
sys_inst.reset_system(sushy.RESET_ON)
# Get a list of allowed reset values
print(sys_inst.get_allowed_reset_system_values())
# Refresh the system object (with all its sub-resources)
#
# Alternatively, this is the other way of reloading a resource object:
# The resource can be reloaded w/o the need of marking it stale
# (i.e. not invoking 'invalidate()'). It is achieved when the "force"
# argument of 'refresh()' method is set to True. Do note that the
# sub-resources of the resource being reloaded will also get reloaded
# (greedy-refresh of sub-resources) when this mode is adopted.
=True)
sys_inst.refresh(force
# Get the current power state
print(sys_inst.power_state)
# Set the next boot device to boot once from PXE in UEFI mode
sys_inst.set_system_boot_source(sushy.BOOT_SOURCE_TARGET_PXE,=sushy.BOOT_SOURCE_ENABLED_ONCE,
enabled=sushy.BOOT_SOURCE_MODE_UEFI)
mode
# Get the current boot source information
print(sys_inst.boot)
# Get a list of allowed boot source target values
print(sys_inst.get_allowed_system_boot_source_values())
# Get the memory summary
print(sys_inst.memory_summary)
# Get the processor summary
print(sys_inst.processors.summary)
Creating and using a sushy manager object
import logging
import sushy
# Enable logging at DEBUG level
= logging.getLogger('sushy')
LOG
LOG.setLevel(logging.DEBUG)
LOG.addHandler(logging.StreamHandler())
= sushy.Sushy('http://localhost:8000/redfish/v1',
s ='foo', password='bar')
username
# Instantiate a manager object
= s.get_manager('BMC')
mgr_inst
# Get the manager name & description
print(mgr_inst.name)
print(mgr_inst.description)
# Using manager collections
# Instantiate a ManagerCollection object
= s.get_manager_collection()
mgr_col
# Print the ID of the managers available in the collection
print(mgr_col.members_identities)
# Get a list of manager objects available in the collection
= mgr_col.get_members()
mgr_insts
# Instantiate a manager object, same as getting it directly
# from the s.get_manager()
= mgr_col.get_member(mgr_col.members_identities[0])
mgr_inst
# Refresh the manager collection object
mgr_col.invalidate()
mgr_col.refresh()
# Using manager actions
# Get supported graphical console types
print(mgr_inst.get_supported_graphical_console_types())
# Get supported serial console types
print(mgr_inst.get_supported_serial_console_types())
# Get supported command shell types
print(mgr_inst.get_supported_command_shell_types())
# Get a list of allowed manager reset values
print(mgr_inst.get_allowed_reset_manager_values())
# Reset the manager
mgr_inst.reset_manager(sushy.RESET_MANAGER_FORCE_RESTART)
# Refresh the manager object (with all its sub-resources)
=True) mgr_inst.refresh(force
Creating and using a sushy session service object
import logging
import sushy
# Enable logging at DEBUG level
= logging.getLogger('sushy')
LOG
LOG.setLevel(logging.DEBUG)
LOG.addHandler(logging.StreamHandler())
= sushy.Sushy('http://localhost:8000/redfish/v1',
s ='foo', password='bar')
username
# Instantiate a SessionService object
= s.get_session_service()
sess_serv
# Get SessionCollection
= sess_serv.sessions
sess_col
# Print the ID of the sessions available in the collection
print(sess_col.members_identities)
# Get a list of systems objects available in the collection
= sess_col.get_members()
sess_col_insts
# Instantiate a session object, same as getting it directly
= sess_col.get_member(sess_col.members_identities[0])
sess_inst # Getting it directly
= s.get_session(sess_col.members_identities[0])
sess_inst
# Delete the session
sess_inst.delete()
# Create a new session
= sess_serv.create_session(
session_key, session_id ='foo', password='bar')
username
# Delete a session
0]) sess_serv.close_session(sess_col.members_identities[
If you do not have any real baremetal machine that supports the
Redfish protocol you can look at the contributing
page to learn how to run a Redfish
emulator.