1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
|
.. _usage:
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.
.. code-block:: python
import logging
import sushy
from sushy import auth
# Enable logging at DEBUG level
LOG = logging.getLogger('sushy')
LOG.setLevel(logging.DEBUG)
LOG.addHandler(logging.StreamHandler())
basic_auth = auth.BasicAuth(username='foo', password='bar')
session_auth = auth.SessionAuth(username='foo', password='bar')
session_or_basic_auth = auth.SessionOrBasicAuth(username='foo',
password='bar')
s = sushy.Sushy('http://localhost:8000/redfish/v1',
auth=basic_auth)
s = sushy.Sushy('http://localhost:8000/redfish/v1',
auth=session_auth)
s = sushy.Sushy('http://localhost:8000/redfish/v1',
auth=session_or_basic_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.
s = sushy.Sushy('http://localhost:8000/redfish/v1',
username='foo',
password='bar')
----------------------------------------
Creating and using a sushy system object
----------------------------------------
.. code-block:: python
import logging
import sushy
# Enable logging at DEBUG level
LOG = logging.getLogger('sushy')
LOG.setLevel(logging.DEBUG)
LOG.addHandler(logging.StreamHandler())
s = sushy.Sushy('http://localhost:8000/redfish/v1',
username='foo', password='bar')
# Get the Redfish version
print(s.redfish_version)
# Instantiate a system object
sys_inst = s.get_system('/redfish/v1/Systems/437XR1138R2')
# Using system collections
# Instantiate a SystemCollection object
sys_col = s.get_system_collection()
# 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_insts = sys_col.get_members()
# Instantiate a system object, same as getting it directly
# from the s.get_system()
sys_inst = sys_col.get_member(sys_col.members_identities[0])
# Refresh the system collection object
#
# See below for more options on how to refresh resources.
sys_col.refresh()
# Using system actions
# Power the system ON
sys_inst.reset_system(sushy.ResetType.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)
sys_inst.refresh()
# Alternatively, you can only refresh the resource if it is stale by passing
# force=False:
sys_inst.refresh(force=False)
# A resource can be marked stale by calling invalidate. Note that its
# subresources won't be marked as stale, and thus they won't be refreshed by
# a call to refresh(force=False)
sys_inst.invalidate()
# 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.BootSource.PXE,
enabled=sushy.BootSourceOverrideEnabled.ONCE,
mode=sushy.BootSourceOverrideMode.UEFI)
# 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
-----------------------------------------
.. code-block:: python
import logging
import sushy
# Enable logging at DEBUG level
LOG = logging.getLogger('sushy')
LOG.setLevel(logging.DEBUG)
LOG.addHandler(logging.StreamHandler())
s = sushy.Sushy('http://localhost:8000/redfish/v1',
username='foo', password='bar')
# Instantiate a manager object
mgr_inst = s.get_manager('BMC')
# Get the manager name & description
print(mgr_inst.name)
print(mgr_inst.description)
# Using manager collections
# Instantiate a ManagerCollection object
mgr_col = s.get_manager_collection()
# 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_insts = mgr_col.get_members()
# Instantiate a manager object, same as getting it directly
# from the s.get_manager()
mgr_inst = mgr_col.get_member(mgr_col.members_identities[0])
# 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.ResetType.FORCE_RESTART)
# Refresh the manager object (with all its sub-resources)
mgr_inst.refresh(force=True)
# Using Virtual Media
# Instantiate a VirtualMediaCollection object
virtmedia_col = mgr_inst.virtual_media
# Print the ID of the VirtualMedia available in the collection
print(virtmedia_col.members_identities)
# Get a list of VirtualMedia objects available in the collection
virtmedia_insts = virtmedia_col.get_members()
# Instantiate a VirtualMedia object
virtmedia_inst = virtmedia_col.get_member(
virtmedia_col.members_identities[0])
# Print out some of the VirtualMedia properties
print(virtmedia_inst.name,
virtmedia_inst.media_types)
# Insert virtual media (invalidates virtmedia_inst contents)
virtmedia_inst.insert_media('https://www.dmtf.org/freeImages/Sardine.img')
# Refresh the resource to load actual contents
virtmedia_inst.refresh()
# Print out some of the VirtualMedia properties
print(virtmedia_inst.image,
virtmedia_inst.image_path,
virtmedia_inst.inserted,
virtmedia_inst.write_protected)
# ... Boot the system off the virtual media...
# Eject virtual media (invalidates virtmedia_inst contents)
virtmedia_inst.eject_media()
-----------------------------------------------
Creating and using a sushy client with Sessions
-----------------------------------------------
.. code-block:: python
import logging
import sushy
# Enable logging at DEBUG level
LOG = logging.getLogger('sushy')
LOG.setLevel(logging.DEBUG)
LOG.addHandler(logging.StreamHandler())
s = sushy.Sushy('http://localhost:8000/redfish/v1',
username='foo', password='bar')
# Get the ComputerSystem object (if there is only one), otherwise
# the identity must be provided as a path to the system.
system = s.get_system()
# A session is created automatically for you.
# Print the boot field in the ComputerSystem.
print(system.boot)
# Upon session timeout, Sushy recreates the session based upon
# provided credentials. If this fails, an exception is raised.
# Explicitly request a session_key and session_uri.
# This is not stored, but may be useful.
session_key, session_uri = s.create_session(username='foo',
password='bar')
# Retrieve the session
session = s.get_session(session_uri)
# Delete the session
session.delete()
--------------------
Using OEM extensions
--------------------
Before running this example, please make sure you have a Redfish BMC that
includes the OEM piece for a specific vendor, as well as the Sushy OEM
extension package installed in the system for the same vendor.
You can check the presence of the OEM extension within each Redfish
resource by specifying the vendor ID and search for them.
In the following example, we are looking up "Acme" vendor extension to Redfish
Manager resource.
.. code-block:: python
import sushy
root = sushy.Sushy('http://localhost:8000/redfish/v1')
# Instantiate a system object
system = root.get_system('/redfish/v1/Systems/437XR1138R2')
print('Working on system resource %s' % system.identity)
for manager in system.managers:
print('Using System manager %s' % manager.identity)
# Get a list of OEM extension names for the system manager
oem_vendors = manager.oem_vendors
print('Listing OEM extension name(s) for the System '
'manager %s' % manager.identity )
print(*oem_vendors, sep="\n")
try:
manager_oem = manager.get_oem_extension('Acme')
except sushy.exceptions.OEMExtensionNotFoundError:
print('ERROR: Acme OEM extension not found in '
'Manager %s' % manager.identity)
continue
print('%s is an OEM extension of Manager %s'
% (manager_oem.get_extension(), manager.identity))
# set boot device to a virtual media device image
manager_oem.set_virtual_boot_device(sushy.VirtualMediaType.CD,
manager=manager)
If you do not have any real baremetal machine that supports the Redfish
protocol you can look at the :ref:`contributing` page to learn how to
run a Redfish emulator.
For the OEM extension example, presently, both of the emulators
(static/dynamic) do not expose any OEM; as a result, users may need to add
manually some OEM resources to emulators' templates. It may be easier to
start with a static emulator.
|