1#!/usr/bin/env python 2 3r""" 4See class prolog below for details. 5""" 6 7from redfish_plus import redfish_plus 8from robot.libraries.BuiltIn import BuiltIn 9 10import func_args as fa 11 12 13class bmc_redfish(redfish_plus): 14 r""" 15 bmc_redfish is a child class of redfish_plus that is designed to provide 16 benefits specifically for using redfish to communicate with an OpenBMC. 17 18 See the prologs of the methods below for details. 19 """ 20 21 def login(self, *args, **kwargs): 22 r""" 23 Assign BMC default values for username, password and auth arguments 24 and call parent class login method. 25 26 Description of argument(s): 27 args See parent class method prolog for details. 28 kwargs See parent class method prolog for details. 29 """ 30 31 # Assign default values for username, password, auth where necessary. 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) 37 38 super(redfish_plus, self).login(username, password, auth, 39 *args, **kwargs) 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() 112