George Keishing | e62d8b0 | 2018-11-29 12:01:56 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | r""" |
George Keishing | 97c9394 | 2019-03-04 12:45:07 -0600 | [diff] [blame] | 4 | See class prolog below for details. |
George Keishing | e62d8b0 | 2018-11-29 12:01:56 -0600 | [diff] [blame] | 5 | """ |
| 6 | |
George Keishing | 97c9394 | 2019-03-04 12:45:07 -0600 | [diff] [blame] | 7 | from redfish_plus import redfish_plus |
George Keishing | 2296e8c | 2019-02-01 05:49:58 -0600 | [diff] [blame] | 8 | from robot.libraries.BuiltIn import BuiltIn |
George Keishing | e62d8b0 | 2018-11-29 12:01:56 -0600 | [diff] [blame] | 9 | |
Michael Walsh | 5cc8919 | 2019-03-12 16:43:38 -0500 | [diff] [blame] | 10 | import func_args as fa |
| 11 | |
George Keishing | e62d8b0 | 2018-11-29 12:01:56 -0600 | [diff] [blame] | 12 | |
George Keishing | 97c9394 | 2019-03-04 12:45:07 -0600 | [diff] [blame] | 13 | class bmc_redfish(redfish_plus): |
George Keishing | e62d8b0 | 2018-11-29 12:01:56 -0600 | [diff] [blame] | 14 | r""" |
Michael Walsh | 5cc8919 | 2019-03-12 16:43:38 -0500 | [diff] [blame] | 15 | bmc_redfish is a child class of redfish_plus that is designed to provide |
George Keishing | 97c9394 | 2019-03-04 12:45:07 -0600 | [diff] [blame] | 16 | benefits specifically for using redfish to communicate with an OpenBMC. |
| 17 | |
| 18 | See the prologs of the methods below for details. |
George Keishing | e62d8b0 | 2018-11-29 12:01:56 -0600 | [diff] [blame] | 19 | """ |
George Keishing | e62d8b0 | 2018-11-29 12:01:56 -0600 | [diff] [blame] | 20 | |
| 21 | def login(self, *args, **kwargs): |
| 22 | r""" |
George Keishing | 97c9394 | 2019-03-04 12:45:07 -0600 | [diff] [blame] | 23 | Assign BMC default values for username, password and auth arguments |
| 24 | and call parent class login method. |
George Keishing | e62d8b0 | 2018-11-29 12:01:56 -0600 | [diff] [blame] | 25 | |
| 26 | Description of argument(s): |
Michael Walsh | 5cc8919 | 2019-03-12 16:43:38 -0500 | [diff] [blame] | 27 | args See parent class method prolog for details. |
| 28 | kwargs See parent class method prolog for details. |
George Keishing | e62d8b0 | 2018-11-29 12:01:56 -0600 | [diff] [blame] | 29 | """ |
George Keishing | 4c39401 | 2019-02-01 06:03:02 -0600 | [diff] [blame] | 30 | |
George Keishing | 97c9394 | 2019-03-04 12:45:07 -0600 | [diff] [blame] | 31 | # Assign default values for username, password, auth where necessary. |
Michael Walsh | 5cc8919 | 2019-03-12 16:43:38 -0500 | [diff] [blame] | 32 | openbmc_username = BuiltIn().get_variable_value("${OPENBMC_USERNAME}") |
| 33 | openbmc_password = BuiltIn().get_variable_value("${OPENBMC_PASSWORD}") |
| 34 | username, args, kwargs = fa.pop_arg(openbmc_username, *args, **kwargs) |
| 35 | password, args, kwargs = fa.pop_arg(openbmc_password, *args, **kwargs) |
| 36 | auth, args, kwargs = fa.pop_arg('session', *args, **kwargs) |
George Keishing | 4c39401 | 2019-02-01 06:03:02 -0600 | [diff] [blame] | 37 | |
George Keishing | 97c9394 | 2019-03-04 12:45:07 -0600 | [diff] [blame] | 38 | super(redfish_plus, self).login(username, password, auth, |
| 39 | *args, **kwargs) |
Michael Walsh | 5cc8919 | 2019-03-12 16:43:38 -0500 | [diff] [blame] | 40 | |
| 41 | def get_properties(self, *args, **kwargs): |
| 42 | r""" |
| 43 | Return dictionary of attributes for a given path. |
| 44 | |
| 45 | The difference between calling this function and calling get() |
| 46 | directly is that this function returns ONLY the dictionary portion of |
| 47 | the response object. |
| 48 | |
| 49 | Example robot code: |
| 50 | |
| 51 | ${properties}= Get Properties /redfish/v1/Systems/system/ |
| 52 | Rprint Vars 1 properties |
| 53 | |
| 54 | Output: |
| 55 | |
| 56 | properties: |
| 57 | [PowerState]: Off |
| 58 | [Processors]: |
| 59 | [@odata.id]: /redfish/v1/Systems/system/Processors |
| 60 | [SerialNumber]: 1234567 |
| 61 | ... |
| 62 | |
| 63 | Description of argument(s): |
| 64 | args See parent class get() prolog for details. |
| 65 | kwargs See parent class get() prolog for details. |
| 66 | """ |
| 67 | |
| 68 | resp = self.get(*args, **kwargs) |
| 69 | return resp.dict if hasattr(resp, 'dict') else {} |
| 70 | |
| 71 | def get_attribute(self, path, attribute, default=None, *args, **kwargs): |
| 72 | r""" |
| 73 | Get and return the named attribute from the properties for a given |
| 74 | path. |
| 75 | |
| 76 | This method has the following advantages over calling get_properties |
| 77 | directly: |
| 78 | - The caller can specify a default value to be returned if the |
| 79 | attribute does not exist. |
| 80 | |
| 81 | Example robot code: |
| 82 | |
| 83 | ${attribute}= Get Attribute /redfish/v1/AccountService |
| 84 | ... MaxPasswordLength default=600 |
| 85 | Rprint Vars attribute |
| 86 | |
| 87 | Output: |
| 88 | |
| 89 | attribute: 31 |
| 90 | |
| 91 | Description of argument(s): |
| 92 | path The path (e.g. |
| 93 | "/redfish/v1/AccountService"). |
| 94 | attribute The name of the attribute to be retrieved |
| 95 | (e.g. "MaxPasswordLength"). |
| 96 | default The default value to be returned if the |
| 97 | attribute does not exist (e.g. ""). |
| 98 | args See parent class get() prolog for details. |
| 99 | kwargs See parent class get() prolog for details. |
| 100 | """ |
| 101 | |
| 102 | return self.get_properties(path, *args, **kwargs).get(attribute, |
| 103 | default) |
| 104 | |
| 105 | def get_session_info(self): |
| 106 | r""" |
| 107 | Get and return session info as a tuple consisting of session_key and |
| 108 | session_location. |
| 109 | """ |
| 110 | |
| 111 | return self.get_session_key(), self.get_session_location() |