blob: 025059b189009b6345f9d58290991c4fe4cbd5f9 [file] [log] [blame]
George Keishinge62d8b02018-11-29 12:01:56 -06001#!/usr/bin/env python
2
3r"""
George Keishing97c93942019-03-04 12:45:07 -06004See class prolog below for details.
George Keishinge62d8b02018-11-29 12:01:56 -06005"""
6
George Keishing97c93942019-03-04 12:45:07 -06007from redfish_plus import redfish_plus
George Keishing2296e8c2019-02-01 05:49:58 -06008from robot.libraries.BuiltIn import BuiltIn
George Keishinge62d8b02018-11-29 12:01:56 -06009
Michael Walsh5cc89192019-03-12 16:43:38 -050010import func_args as fa
11
George Keishinge62d8b02018-11-29 12:01:56 -060012
George Keishing97c93942019-03-04 12:45:07 -060013class bmc_redfish(redfish_plus):
George Keishinge62d8b02018-11-29 12:01:56 -060014 r"""
Michael Walsh5cc89192019-03-12 16:43:38 -050015 bmc_redfish is a child class of redfish_plus that is designed to provide
George Keishing97c93942019-03-04 12:45:07 -060016 benefits specifically for using redfish to communicate with an OpenBMC.
17
18 See the prologs of the methods below for details.
George Keishinge62d8b02018-11-29 12:01:56 -060019 """
George Keishinge62d8b02018-11-29 12:01:56 -060020
21 def login(self, *args, **kwargs):
22 r"""
George Keishing97c93942019-03-04 12:45:07 -060023 Assign BMC default values for username, password and auth arguments
24 and call parent class login method.
George Keishinge62d8b02018-11-29 12:01:56 -060025
26 Description of argument(s):
Michael Walsh5cc89192019-03-12 16:43:38 -050027 args See parent class method prolog for details.
28 kwargs See parent class method prolog for details.
George Keishinge62d8b02018-11-29 12:01:56 -060029 """
George Keishing4c394012019-02-01 06:03:02 -060030
George Keishing97c93942019-03-04 12:45:07 -060031 # Assign default values for username, password, auth where necessary.
Michael Walsh5cc89192019-03-12 16:43:38 -050032 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 Keishing4c394012019-02-01 06:03:02 -060037
George Keishing97c93942019-03-04 12:45:07 -060038 super(redfish_plus, self).login(username, password, auth,
39 *args, **kwargs)
Michael Walsh5cc89192019-03-12 16:43:38 -050040
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()