|
| 1 | + # Copyright 2016 Hewlett Packard Enterprise Development LP |
| 2 | + # |
| 3 | + # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | + # not use this file except in compliance with the License. You may obtain |
| 5 | + # a copy of the License at |
| 6 | + # |
| 7 | + # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + # |
| 9 | + # Unless required by applicable law or agreed to in writing, software |
| 10 | + # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | + # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | + # License for the specific language governing permissions and limitations |
| 13 | + # under the License. |
| 14 | + |
| 15 | +import sys |
| 16 | +from _redfishobject import RedfishObject |
| 17 | +from redfish.rest.v1 import ServerDownOrUnreachableError |
| 18 | + |
| 19 | +def ex54_expand_data(redfishobj, expand_url=None): |
| 20 | + sys.stdout.write("\nEXAMPLE 54: Expand Data Syntax\n") |
| 21 | + if redfishobj.typepath.defs.isgen9: |
| 22 | + sys.stderr.write("\nNOTE: Expand Syntax is not available on iLO 4 "\ |
| 23 | + "systems. \n") |
| 24 | + else: |
| 25 | + response = REDFISH_OBJ.redfish_get(expand_url) |
| 26 | + exp_response = REDFISH_OBJ.redfish_get(expand_url+'?$expand=.') |
| 27 | + sys.stdout.write('Standard response:\n') |
| 28 | + sys.stdout.write('\t'+str(response.dict)+'\n') |
| 29 | + sys.stdout.write('Expanded response:\n') |
| 30 | + sys.stdout.write('\t'+str(exp_response.dict)+'\n') |
| 31 | + |
| 32 | +if __name__ == "__main__": |
| 33 | + # When running on the server locally use the following commented values |
| 34 | + # iLO_https_url = "blobstore://." |
| 35 | + # iLO_account = "None" |
| 36 | + # iLO_password = "None" |
| 37 | + |
| 38 | + # When running remotely connect using the iLO secured (https://) address, |
| 39 | + # iLO account name, and password to send https requests |
| 40 | + # iLO_https_url acceptable examples: |
| 41 | + # "https://10.0.0.100" |
| 42 | + # "https://f250asha.americas.hpqcorp.net" |
| 43 | + iLO_https_url = "https://10.0.0.100" |
| 44 | + iLO_account = "admin" |
| 45 | + iLO_password = "password" |
| 46 | + |
| 47 | + # Create a REDFISH object |
| 48 | + try: |
| 49 | + REDFISH_OBJ = RedfishObject(iLO_https_url, iLO_account, iLO_password) |
| 50 | + except ServerDownOrUnreachableError as excp: |
| 51 | + sys.stderr.write("ERROR: server not reachable or doesn't support " \ |
| 52 | + "RedFish.\n") |
| 53 | + sys.exit() |
| 54 | + except Exception as excp: |
| 55 | + raise excp |
| 56 | + |
| 57 | + ex54_expand_data(REDFISH_OBJ, "/redfish/v1/systems/") |
| 58 | + REDFISH_OBJ.redfish_client.logout() |
0 commit comments