├── .flake8 ├── .gitignore ├── .isort.cfg ├── .project ├── .pydevproject ├── .settings └── org.eclipse.core.resources.prefs ├── AUTHORS.md ├── CHANGELOG.md ├── LICENSE ├── LICENSE.md ├── MANIFEST.in ├── Makefile ├── MakefileSDK.ps1 ├── README.rst ├── docs ├── API-Overview.rest ├── Advanced-Usage.rest ├── Client-Quick-Start.rest ├── Examples.rest ├── Frequently-Asked-Questions.rest ├── Installation-Guide.rest ├── Makefile ├── Monolith.rest ├── Quick-Start.rest ├── Reference.rest ├── System-Compatibility.rest ├── conf.py ├── iLO_4_REST_API_Data_Model.md ├── images │ ├── hpe_logo2.png │ └── iLO_sys1.jpg ├── index.rst ├── make.bat ├── redfish_quick.json └── themes │ └── sphinx_rtd_theme │ ├── __init__.py │ ├── breadcrumbs.html │ ├── footer.html │ ├── layout.html │ ├── layout_old.html │ ├── search.html │ ├── searchbox.html │ ├── static │ ├── css │ │ ├── badge_only.css │ │ ├── badge_only.css.map │ │ ├── theme.css │ │ └── theme.css.map │ ├── fonts │ │ ├── FontAwesome.otf │ │ ├── Inconsolata-Bold.ttf │ │ ├── Inconsolata-Regular.ttf │ │ ├── Lato-Bold.ttf │ │ ├── Lato-Regular.ttf │ │ ├── RobotoSlab-Bold.ttf │ │ ├── RobotoSlab-Regular.ttf │ │ ├── fontawesome-webfont.eot │ │ ├── fontawesome-webfont.svg │ │ ├── fontawesome-webfont.ttf │ │ └── fontawesome-webfont.woff │ └── js │ │ ├── modernizr.min.js │ │ └── theme.js │ ├── theme.conf │ └── versions.html ├── examples ├── Legacy_Rest │ ├── add_ilo_user_account.py │ ├── bios_revert_default.py │ ├── change_bios_setting.py │ ├── change_boot_order.py │ ├── change_temporary_boot_order.py │ ├── clear_ahs_data.py │ ├── clear_ilo_event_log.py │ ├── clear_iml.py │ ├── computer_details.py │ ├── configure_snmp.py │ ├── dump_eskm_event_log.py │ ├── dump_ilo_event_log.py │ ├── dump_ilo_nic.py │ ├── dump_iml.py │ ├── enable_secure_boot.py │ ├── find_ilo_mac_address.py │ ├── generate_csr.py │ ├── get_ESKM.py │ ├── get_EncryptionSettings.py │ ├── get_LogicalDrives.py │ ├── get_ahs_data.py │ ├── get_base_registry.py │ ├── get_csr.py │ ├── get_ilo_ip.py │ ├── get_ilo_nic.py │ ├── get_license_key.py │ ├── get_powermetrics_average.py │ ├── get_resource_directory.py │ ├── get_schema.py │ ├── import_ssl.py │ ├── modify_ilo_user_account.py │ ├── mount_virtual_media_iso.py │ ├── remove_ilo_account.py │ ├── reset_ESKM_eventlog.py │ ├── reset_ilo.py │ ├── reset_server.py │ ├── sessions.py │ ├── set_ESKM_PrimaryKeyServer.py │ ├── set_ESKM_username_password.py │ ├── set_Ilo_ntp_servers.py │ ├── set_active_ilo_nic.py │ ├── set_bios_dhcp.py │ ├── set_bios_iscsi.py │ ├── set_bios_password.py │ ├── set_bios_service.py │ ├── set_bios_uefi_shell_startup.py │ ├── set_bios_url_boot_file.py │ ├── set_ilo_timezone.py │ ├── set_license_key.py │ ├── set_server_asset_tag.py │ ├── set_uid_light.py │ ├── test_ESKM_connection.py │ └── update_ilo_firmware.py ├── Redfish │ ├── add_user_account.py │ ├── bios_revert_default.py │ ├── change_bios_setting.py │ ├── change_boot_order.py │ ├── change_temporary_boot_order.py │ ├── clear_ahs_data.py │ ├── clear_ilo_IEL_IML_log.py │ ├── computer_details.py │ ├── configure_snmp.py │ ├── configure_snmp_trap_source.py │ ├── eject_virtual_media_iso.py │ ├── enable_ntp_servers.py │ ├── enable_secure_boot.py │ ├── expand_data.py │ ├── find_ilo_mac_address.py │ ├── flash_firmware_by_uefi.py │ ├── generate_csr.py │ ├── get_ESKM.py │ ├── get_SmartArray_EncryptionSettings.py │ ├── get_ahs_data.py │ ├── get_base_registry.py │ ├── get_bios_setting.py │ ├── get_ilo_ip.py │ ├── get_ilo_nic.py │ ├── get_license_key.py │ ├── get_logical_drives.py │ ├── get_powermetrics_average.py │ ├── get_resource_directory.py │ ├── get_schema.py │ ├── ilorest_util.py │ ├── import_ssl.py │ ├── modify_user_account.py │ ├── mount_virtual_media_iso.py │ ├── quickstart_redfish.py │ ├── reboot_server.py │ ├── remove_account.py │ ├── reset_ESKM_eventlog.py │ ├── reset_ilo.py │ ├── reset_server.py │ ├── sessions.py │ ├── set_ESKM_PrimaryKeyServer.py │ ├── set_ESKM_username_password.py │ ├── set_active_ilo_nic.py │ ├── set_bios_iscsi.py │ ├── set_bios_password.py │ ├── set_ethernet_management_iface_static_ip.py │ ├── set_ilo_ntp_servers.py │ ├── set_ilo_timezone.py │ ├── set_license_key.py │ ├── set_server_asset_tag.py │ ├── set_snmp_alert.py │ ├── set_syslogserver.py │ ├── set_uid_light.py │ ├── software_firmware_inventory.py │ ├── test_ESKM_connection.py │ ├── update_ilo_firmware.py │ ├── upload_firmware_ilo_repository.py │ └── upload_firmware_ilo_repository_with_compsig.py ├── quickstart_legacy_rest.py └── quickstart_redfish.py ├── flake8.txt ├── makeandinstallzip.bat ├── pull_request_template.md ├── pylint.sh ├── requirements.txt ├── setup.cfg ├── setup.py ├── src └── redfish │ ├── __init__.py │ ├── hpilo │ ├── __init__.py │ ├── risblobstore2.py │ ├── rishpilo.py │ └── vnichpilo.py │ ├── rest │ ├── __init__.py │ ├── connections.py │ ├── containers.py │ └── v1.py │ └── ris │ ├── __init__.py │ ├── config.py │ ├── gen_compat.py │ ├── resp_handler.py │ ├── ris.py │ ├── ris_threaded.py │ ├── rmc.py │ ├── rmc_api.py │ ├── rmc_helper.py │ ├── sharedtypes.py │ ├── utils.py │ └── validation.py ├── test_build_drone.yml └── tox.ini /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 120 3 | extend-ignore = E203, E722, C901, E731 4 | exclude = 5 | .git, 6 | packaging, 7 | __pycache__, 8 | build, 9 | dist, 10 | docs 11 | max-complexity = 10 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | 5 | # C extensions 6 | *.so 7 | 8 | # Distribution / packaging 9 | .Python 10 | env/ 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | *.egg-info/ 23 | .installed.cfg 24 | *.egg 25 | 26 | # PyInstaller 27 | # Usually these files are written by a python script from a template 28 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 29 | *.manifest 30 | *.spec 31 | 32 | # Installer logs 33 | pip-log.txt 34 | pip-delete-this-directory.txt 35 | 36 | # Unit test / coverage reports 37 | htmlcov/ 38 | .tox/ 39 | .coverage 40 | .coverage.* 41 | .cache 42 | nosetests.xml 43 | coverage.xml 44 | 45 | # Translations 46 | *.mo 47 | *.pot 48 | 49 | # Django stuff: 50 | *.log 51 | 52 | # Sphinx documentation 53 | docs/_build/ 54 | 55 | # PyBuilder 56 | target/ 57 | -------------------------------------------------------------------------------- /.isort.cfg: -------------------------------------------------------------------------------- 1 | [settings] 2 | profile = black 3 | skip_glob=.gitignore,.dockerignore,packaging/*,build/*,dist/*,.git,tests/*,docs/* 4 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | redfish 4 | 5 | 6 | 7 | 8 | 9 | org.python.pydev.PyDevBuilder 10 | 11 | 12 | 13 | 14 | 15 | org.python.pydev.pythonNature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.pydevproject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | /${PROJECT_DIR_NAME}/src 5 | 6 | python 2.7 7 | Default 8 | 9 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/redfish/rest/v1.py=utf-8 3 | encoding//src/redfish/ris/__init__.py=utf-8 4 | encoding//src/redfish/ris/config.py=utf-8 5 | encoding//src/redfish/ris/ris.py=utf-8 6 | encoding//src/redfish/ris/rmc.py=utf-8 7 | encoding//src/redfish/ris/rmc_helper.py=utf-8 8 | encoding//src/redfish/ris/sharedtypes.py=utf-8 9 | -------------------------------------------------------------------------------- /AUTHORS.md: -------------------------------------------------------------------------------- 1 | # Original Contribution: 2 | 3 | * [Jack Garcia](//github.com/lumbajack) - HPE - Hewlett Packard Enterprise Restful API Group 4 | * [Matthew Kocurek](//github.com/Yergidy) - HPE - Hewlett Packard Enterprise Restful API Group 5 | * [Prithvi Subrahmanya](//github.com/PrithviBS) - HPE - Hewlett Packard Enterprise Restful API Group 6 | 7 | # Other Key Contributions: 8 | 9 | *For a list of people who have contributed to the codebase, see [GitHub's list of contributors](https://github.com/DMTF/python-redfish-library/contributors).* 10 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # Change Log 3 | 4 | ## [1.0.0] - 2017-01-12 5 | - Initial Public Release -- supports Redfish 1.0 features 6 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The Distributed Management Task Force (DMTF) grants rights under copyright in 2 | this software on the terms of the BSD 3-Clause License as set forth below; no 3 | other rights are granted by DMTF. This software might be subject to other rights 4 | (such as patent rights) of other parties. 5 | 6 | 7 | ### Copyrights. 8 | 9 | Copyright (c) 2016, Contributing Member(s) of Distributed Management Task Force, 10 | Inc.. All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this 16 | list of conditions and the following disclaimer. 17 | * Redistributions in binary form must reproduce the above copyright notice, this 18 | list of conditions and the following disclaimer in the documentation and/or 19 | other materials provided with the distribution. 20 | * Neither the name of the Distributed Management Task Force (DMTF) nor the names 21 | of its contributors may be used to endorse or promote products derived from this 22 | software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 28 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 31 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | ### Patents. 37 | 38 | This software may be subject to third party patent rights, including provisional 39 | patent rights ("patent rights"). DMTF makes no representations to users of the 40 | standard as to the existence of such rights, and is not responsible to 41 | recognize, disclose, or identify any or all such third party patent right, 42 | owners or claimants, nor for any incomplete or inaccurate identification or 43 | disclosure of such rights, owners or claimants. DMTF shall have no liability to 44 | any party, in any manner or circumstance, under any legal theory whatsoever, for 45 | failure to recognize, disclose, or identify any such third party patent rights, 46 | or for such party's reliance on the software or incorporation thereof in its 47 | product, protocols or testing procedures. DMTF shall have no liability to any 48 | party using such software, whether such use is foreseeable or not, nor to any 49 | patent owner or claimant, and shall have no liability or responsibility for 50 | costs or losses incurred if software is withdrawn or modified after publication, 51 | and shall be indemnified and held harmless by any party using the software from 52 | any and all claims of infringement by a patent owner for such use. 53 | 54 | DMTF Members that contributed to this software source code might have made 55 | patent licensing commitments in connection with their participation in the DMTF. 56 | For details, see http://dmtf.org/sites/default/files/patent-10-18-01.pdf and 57 | http://www.dmtf.org/about/policies/disclosures. -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.rst 2 | include LICENSE 3 | -------------------------------------------------------------------------------- /MakefileSDK.ps1: -------------------------------------------------------------------------------- 1 | $START_DIR = "$(get-location)" 2 | $product_version = $Env:MTX_PRODUCT_VERSION 3 | if (!"$product_version") { 4 | $product_version = "9.9.9.9" 5 | } 6 | 7 | $build_number = $Env:MTX_BUILD_NUMBER 8 | if (!"$build_number") { 9 | $build_number = "999" 10 | } 11 | 12 | $app = Get-WmiObject -Class Win32_Product | Where-Object { 13 | $_.Name -match "Python*" 14 | } 15 | $app.Uninstall() 16 | #Get-Package "*python*" | Uninstall-Package -Force -Confirm 17 | if ( $LastExitCode ) { exit 1 } 18 | #Restart-Computer -Force 19 | 20 | #Set-Location -Path $START_DIR 21 | #if( Test-Path $START_DIR\python39 ) { Remove-Item $START_DIR\python39 -Recurse -Force } 22 | #Set-Location -Path $START_DIR 23 | #New-Item -ItemType directory -Path .\python39 24 | Set-Location -Path "${START_DIR}\packaging\python3" 25 | #Start-Process -FilePath ./python-3.9.5-amd64.exe -ArgumentList "/quiet TargetDir=${START_DIR}\python39 InstallAllUsers=1 PrependPath=1 Include_test=0" -NoNewWindow -Wait 26 | & .\python-3.8.6-amd64.exe /quiet TargetDir=${START_DIR}\python39 InstallAllUsers=1 PrependPath=1 Include_test=0 Include_launcher=0 /log "%WINDIR%\Temp\Python39-Install.log" 27 | if ( $LastExitCode ) { exit 1 } 28 | Start-Sleep -Seconds 120 29 | Set-Location -Path "${START_DIR}" 30 | if (-Not (Test-Path "${START_DIR}\python39")) { 31 | Write-Host "Python Not Installed" 32 | exit 1 33 | } 34 | 35 | #New-Item -ItemType directory -Path .\lessmsi 36 | #& 7z x -y -olessmsi .\packaging\lessmsi\lessmsi-v1.3.zip 37 | #if ( $LastExitCode ) { exit 1 } 38 | 39 | #if( Test-Path $START_DIR\python-2.7.10.amd64 ) { Remove-Item $START_DIR\python-2.7.11.amd64 -Recurse -Force } 40 | #& $START_DIR\lessmsi\lessmsi x .\packaging\python\python-2.7.11.amd64.msi 41 | #if ( $LastExitCode ) { exit 1 } 42 | #$Env:PYTHONPATH="$START_DIR\src" 43 | #$PYTHON_AMD64 = "${START_DIR}\python-2.7.11.amd64\SourceDir\python.exe" 44 | 45 | # Create an exe from the python script 46 | $Env:PYTHONPATH="${START_DIR}\python39\Lib\site-packages" 47 | $PYTHON_AMD64 = "${START_DIR}\python39\python.exe" 48 | $PIP_AMD64 = "${START_DIR}\python39\Scripts\pip.exe" 49 | 50 | Set-Location -Path $START_DIR 51 | 52 | Function InstallPythonModuleZip($python, $name, $version) { 53 | Set-Location -Path "${START_DIR}" 54 | if( Test-Path .\${name} ) { Remove-Item .\${name} -Recurse -Force } 55 | New-Item -ItemType directory -Path "${START_DIR}\${name}" 56 | & 7z x -y "-o${name}" .\packaging\ext\${name}-${version}.zip 57 | Set-Location -Path "${START_DIR}\${name}\${name}-${version}" 58 | & $python setup.py install 59 | Set-Location -Path "${START_DIR}" 60 | } 61 | 62 | Function InstallPythonModule($python, $name, $version) { 63 | Set-Location -Path "${START_DIR}" 64 | if( Test-Path .\${name} ) { Remove-Item .\${name} -Recurse -Force } 65 | New-Item -ItemType directory -Path "${START_DIR}\${name}" 66 | & 7z x -y "-o${name}" .\packaging\ext\${name}-${version}.tar.gz 67 | & 7z x -y "-o${name}" "${START_DIR}\${name}\dist\${name}-${version}.tar" 68 | Set-Location -Path "${START_DIR}\${name}\${name}-${version}" 69 | & $python setup.py install 70 | Set-Location -Path "${START_DIR}" 71 | } 72 | 73 | InstallPythonModuleZip "$PYTHON_AMD64" "setuptools" "50.3.2" 74 | #InstallPythonModule "$PYTHON_AMD64" "setuptools" "2.2" 75 | 76 | Set-Location -Path ${START_DIR} 77 | & $PYTHON_AMD64 setup.py "sdist" "--formats=zip" 78 | Copy-Item ".\dist\*" "$Env:MTX_COLLECTION_PATH" 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /docs/Frequently-Asked-Questions.rest: -------------------------------------------------------------------------------- 1 | .. image:: /images/hpe_logo2.png 2 | :width: 150pt 3 | 4 | | 5 | 6 | .. toctree:: 7 | :maxdepth: 1 8 | 9 | 10 | Frequently Asked Questions 11 | ========================== 12 | 13 | Q1: What is the difference between REST and Redfish API? 14 | -------------------------------------------------------- 15 | 16 | Representational State Transfer(REST) is a web-based software architectural style consisting of a set of constraints that focus on a system's resource. The HPE REST library performs the basic HTTP operations GET, POST, PUT, PATCH and DELETE on resources using the HATEOS (Hypermedia as the Engine of Application) REST architecture. RESTful typically refers to web services implementing REST architecture. 17 | 18 | Redfish API uses a hypermedia data model OData(Open Data Protocol) v4 represented within a RESTful interface. OData is a specific implementation of REST architecture that allows resources identified using URIs and defined in an abstract data model. Since the Redfish implementation is based on OData v4, it requires the starting metadata OData header to be version 4. Redfish changes the linking between resources. Where the HPE Restful URIs places all link as "href" inside a "links" sub-object, Redfish changes "**href**" to "**@odata.id**", "**links**" sub-objects to "**Links**". For more information on iLO's implementation of Redfish, click `here `_. 19 | 20 | More information on Redfish can be found on the `DMTF Redfish Website `_. 21 | -------------------------------------------------------------------------------- /docs/Installation-Guide.rest: -------------------------------------------------------------------------------- 1 | .. image:: /images/hpe_logo2.png 2 | :width: 150pt 3 | 4 | | 5 | 6 | ================== 7 | Installation Guide 8 | ================== 9 | 10 | The python-ilorest-library supports **Python 2** (Up to 2.7.15, which is the EOL version) and **Python 3** (At present, 3.8). 11 | 12 | Pip install 13 | =========== 14 | 15 | Standard install 16 | ---------------- 17 | :: 18 | 19 | pip install python-ilorest-library 20 | 21 | With SOCKS proxy support 22 | ------------------------ 23 | 24 | Starting with **version 2.5.0** of the python-ilorest-library, you can include the SOCKS proxy add-on if you need that support. 25 | 26 | :: 27 | 28 | pip install python-ilorest-library[socks] 29 | 30 | Building from Source 31 | ==================== 32 | 33 | 34 | Checkout using SVN (Subversion) 35 | ------------------------------- 36 | 37 | Assuming that SVN is already installed in your system and it is already in the system path, run the following command from the directory where you want to copy the source. 38 | 39 | :: 40 | 41 | svn checkout https://github.hpe.com/intelligent-provisioning/python-redfish-library.git 42 | 43 | Clone using GIT 44 | --------------- 45 | 46 | Run the following command from the directory where you want to copy the source. 47 | 48 | :: 49 | 50 | git clone https://github.hpe.com/intelligent-provisioning/python-redfish-library.git 51 | 52 | Building Source 53 | --------------- 54 | 55 | After you have checked out the latest code, run the following commands: 56 | 57 | :: 58 | 59 | cd python-ilorest-library 60 | python setup.py sdist --formats=zip (this will produce a .zip file) 61 | cd dist 62 | pip install python-ilorest-library-x.x.x.zip[socks] 63 | 64 | A successful installation will display that python-ilorest-library-x.x.x and the dependencies have been successfully installed. 65 | 66 | Building From Source With SOCKS Proxy Support 67 | --------------------------------------------- 68 | 69 | :: 70 | 71 | cd python-ilorest-library 72 | python setup.py sdist --formats=zip (this will produce a .zip file) 73 | cd dist 74 | pip install python-ilorest-library-x.x.x.zip[socks] 75 | -------------------------------------------------------------------------------- /docs/Reference.rest: -------------------------------------------------------------------------------- 1 | ======================= 2 | Reference Documentation 3 | ======================= 4 | 5 | redfish.rest 6 | --------------- 7 | .. automodule:: redfish.rest 8 | 9 | redfish.rest.v1 10 | =============== 11 | .. automodule:: redfish.rest.v1 12 | :members: 13 | :show-inheritance: 14 | 15 | redfish.rest.connections 16 | ======================== 17 | .. automodule:: redfish.rest.connections 18 | :members: 19 | :show-inheritance: 20 | 21 | redfish.rest.containers 22 | ======================= 23 | .. automodule:: redfish.rest.containers 24 | :members: RestRequest, RestResponse 25 | :show-inheritance: 26 | 27 | redfish.ris 28 | --------------- 29 | .. automodule:: redfish.ris 30 | 31 | redfish.ris.gen_compat 32 | ====================== 33 | .. automodule:: redfish.ris.gen_compat 34 | :members: 35 | :show-inheritance: 36 | 37 | redfish.ris.ris 38 | =============== 39 | .. automodule:: redfish.ris.ris 40 | :members: 41 | :show-inheritance: 42 | 43 | redfish.ris.ris_threaded 44 | ======================== 45 | .. automodule:: redfish.ris.ris_threaded 46 | :members: 47 | :show-inheritance: 48 | 49 | redfish.ris.utils 50 | ================= 51 | .. automodule:: redfish.ris.utils 52 | :members: 53 | :show-inheritance: 54 | 55 | redfish.ris.rmc 56 | =============== 57 | .. automodule:: redfish.ris.rmc 58 | :members: 59 | :show-inheritance: 60 | 61 | redfish.ris.rmc_helper 62 | ====================== 63 | .. automodule:: redfish.ris.rmc_helper 64 | :members: 65 | :show-inheritance: 66 | 67 | redfish.ris.resp_handler 68 | ======================== 69 | .. automodule:: redfish.ris.resp_handler 70 | :members: 71 | :show-inheritance: 72 | 73 | redfish.ris.validation 74 | ======================== 75 | .. automodule:: redfish.ris.validation 76 | :members: 77 | :show-inheritance: -------------------------------------------------------------------------------- /docs/System-Compatibility.rest: -------------------------------------------------------------------------------- 1 | .. image:: /images/hpe_logo2.png 2 | :width: 150pt 3 | 4 | 5 | | 6 | 7 | .. toctree:: 8 | :maxdepth: 1 9 | 10 | ==================== 11 | System Compatibility 12 | ==================== 13 | 14 | Compatibility can be hard to maintain if you have many different systems with different firmware versions and system generations on each of them. 15 | `Gen_compat `_ tries to help alleviate the headaches associated with this. It can automatically detect 16 | what type of system you are using and provide useful string values of key property keys, paths, types, and booleans to check what the system type is. 17 | 18 | A compatibility class is automatically created as part of an RmcApp class. 19 | 20 | .. note:: While currently gen_compat only specifically supports HPE iLO systems, the `Definevalstenplus `_ class defines are mostly Redfish standard values. Gen_compat can also easily be extended to provide strings for any system type. 21 | 22 | Creating a Compatibility Class 23 | ============================== 24 | 25 | To create a compatibility class we first need to import the relevant module and create an empty class. 26 | 27 | >>> from redfish.ris.gen_compat import Typesandpathdefines 28 | >>> COMPAT_OBJ = Typesandpathdefines() 29 | 30 | Using a Compatibility Class 31 | =========================== 32 | 33 | Now if you try to read any defines you will find the values are all empty. We need to point the compatibility class 34 | to a system in order to detect its API type, iLO version, and generation if necessary. This is done with the `getgen` function. 35 | If any other connection requirements are needed they can also be added now. 36 | 37 | >>> COMPAT_OBJ.getgen(url=iLO_host, username=login_account, password=login_password) 38 | 39 | After running the `getgen` function, if no connection errors occurred, you should be able to see information on the system 40 | as well as a list of string defines you can use in place of direct strings. That way you guarantee no matter the system 41 | you will have the correct key, type, or path value. 42 | 43 | .. note:: The following example defines are from an iLO 5 system. 44 | 45 | >>> COMPAT_OBJ.ilogen 46 | 5 47 | >>> COMPAT_OBJ.defs.hrefstring 48 | '@odata.id' 49 | >>> COMPAT_OBJ.defs.collectionstring 50 | 'Members' 51 | >>> COMPAT_OBJ.defs.biostype 52 | 'Bios.' 53 | 54 | Here is the compatibility class in action on a RedfishClient. The following code would work the same for LegacyRest 55 | due to the use of the compatibility class instead of hard coding paths and keys. 56 | 57 | >>> REST_OBJ = RestClient(base_url=iLO_host, username=login_account, password=login_password) 58 | >>> resp = REST_OBJ.get(COMPAT_OBJ.defs.startpath) 59 | >>> resp.path 60 | '/redfish/v1/' 61 | >>> resp.obj.Chassis[COMPAT_OBJ.defs.hrefstring] 62 | u'/redfish/v1/Chassis/' 63 | 64 | Updating a Compatibility Class 65 | ============================== 66 | 67 | On some iLO 4 systems both Redfish and LegacyRest are available for use for backwards compatibility. The compatibility 68 | class will automatically assume LegacyRest in this instance. In order to use Redfish on these systems you will need to 69 | update the defines. 70 | 71 | First create a new object with the redfish flag added. 72 | 73 | >>> COMPAT_OBJ = Typesandpathdefines() 74 | >>> COMPAT_OBJ.getgen(url=iLO_host, username=login_account, password=login_password, isredfish=True) 75 | 76 | The initial isredfish flag will ensure we load redfish paths when performing the initial detection. We still need 77 | to call `updatedefinesflag` to update our defines to Redfish. 78 | 79 | >>> COMPAT_OBJ.defs.startpath 80 | '/rest/v1' 81 | >>> COMPAT_OBJ.updatedefinesflag(redfishflag=True) 82 | True 83 | >>> COMPAT_OBJ.defs.startpath 84 | '/redfish/v1/' 85 | 86 | .. note:: This will not do anything on Redfish only systems, so it is safe to use in all cases to ensure Redfish is used if that is desired. -------------------------------------------------------------------------------- /docs/iLO_4_REST_API_Data_Model.md: -------------------------------------------------------------------------------- 1 | # iLO 4 REST API Data Model 2 | The data model documentation can be found 3 | here. 4 | -------------------------------------------------------------------------------- /docs/images/hpe_logo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-ilorest-library/82d7ae4a9d9682c7e48e9e19e665bde79fa9d8bf/docs/images/hpe_logo2.png -------------------------------------------------------------------------------- /docs/images/iLO_sys1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-ilorest-library/82d7ae4a9d9682c7e48e9e19e665bde79fa9d8bf/docs/images/iLO_sys1.jpg -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. iLO RESTful API documentation master file, created by 2 | sphinx-quickstart on Fri Mar 11 11:34:15 2016. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | .. image:: /images/hpe_logo2.png 7 | :width: 150pt 8 | 9 | | 10 | | 11 | 12 | Python iLO Redfish Library 13 | ========================== 14 | 15 | The iLO Redfish Library is a python library built for interacting with systems that implement the **Redfish API**, which includes the HPE iLO RESTful API. 16 | The library is the platform on which the `RESTful Interface tool `_ was built on. 17 | 18 | The library can connect **remotely** to any BMC that implements a Redfish API via HTTPS or **locally** to an HPE server using the HPE CHIF interface and implements Redfish or Legacy Rest APIs. 19 | On top of this functionality, the library also offers remote and local support for the Legacy HPE iLO RESTful API that was the starting point for the DMTF Redfish standard. 20 | 21 | For more information on the HPE iLO RESTful API and Redfish see the `API overview `_. 22 | 23 | .. note:: HPE's Legacy Rest API is available starting in **iLO 4 2.00**. iLO 4 is Redfish conformant starting with **iLO 4 2.30**. In iLO 5 and above the iLO RESTful API is Redfish only. 24 | 25 | Documentation 26 | ------------- 27 | 28 | .. toctree:: 29 | :maxdepth: 1 30 | 31 | API-Overview 32 | Installation-Guide 33 | Client-Quick-Start 34 | Advanced-Usage 35 | Monolith 36 | System-Compatibility 37 | Examples 38 | Frequently-Asked-Questions 39 | Reference 40 | 41 | Get in touch with the team 42 | -------------------------- 43 | 44 | If you have further questions, please contact the team: 45 | 46 | * `Matthew Kocurek `_ 47 | * `Tony Wang `_ 48 | * `Grant O'Connor `_ 49 | * `Matthew Whiteside `_ 50 | 51 | Contributors 52 | ------------- 53 | 54 | Contributors are listed `here `_. 55 | 56 | -------------------------------------------------------------------------------- /docs/redfish_quick.json: -------------------------------------------------------------------------------- 1 | { 2 | "@odata.context": "/redfish/v1/$metadata#ComputerSystem.ComputerSystem", 3 | "@odata.etag": "W/\"E4BDA463\"", 4 | "@odata.id": "/redfish/v1/Systems/1", 5 | "@odata.type": "#ComputerSystem.v1_4_0.ComputerSystem", 6 | "Id": "1", 7 | "Actions": { 8 | "#ComputerSystem.Reset": { 9 | "ResetType@Redfish.AllowableValues": [ 10 | "On", 11 | "ForceOff", 12 | "ForceRestart", 13 | "Nmi", 14 | "PushPowerButton" 15 | ], 16 | "target": "/redfish/v1/Systems/1/Actions/ComputerSystem.Reset" 17 | } 18 | }, 19 | "AssetTag": "", 20 | "Bios": { 21 | "@odata.id": "/redfish/v1/systems/1/bios" 22 | } 23 | } -------------------------------------------------------------------------------- /docs/themes/sphinx_rtd_theme/__init__.py: -------------------------------------------------------------------------------- 1 | """Sphinx ReadTheDocs theme. 2 | 3 | From https://github.com/ryan-roemer/sphinx-bootstrap-theme. 4 | 5 | """ 6 | import os 7 | 8 | VERSION = (0, 1, 9) 9 | 10 | __version__ = ".".join(str(v) for v in VERSION) 11 | __version_full__ = __version__ 12 | 13 | 14 | def get_html_theme_path(): 15 | """Return list of HTML theme paths.""" 16 | cur_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) 17 | return cur_dir 18 | -------------------------------------------------------------------------------- /docs/themes/sphinx_rtd_theme/breadcrumbs.html: -------------------------------------------------------------------------------- 1 | {# Support for Sphinx 1.3+ page_source_suffix, but don't break old builds. #} 2 | 3 | {% if page_source_suffix %} 4 | {% set suffix = page_source_suffix %} 5 | {% else %} 6 | {% set suffix = source_suffix %} 7 | {% endif %} 8 | 9 |
10 |
    11 |
  • Docs »
  • 12 | {% for doc in parents %} 13 |
  • {{ doc.title }} »
  • 14 | {% endfor %} 15 |
  • {{ title }}
  • 16 |
  • 17 | {% if pagename != "search" %} 18 | {% if display_github %} 19 | Edit on GitHub 20 | {% elif display_bitbucket %} 21 | Edit on Bitbucket 22 | {% elif show_source and source_url_prefix %} 23 | 24 | {% elif show_source and has_source and sourcename %} 25 | 26 | {% endif %} 27 | {% endif %} 28 |
  • 29 |
30 |
31 |
32 | -------------------------------------------------------------------------------- /docs/themes/sphinx_rtd_theme/footer.html: -------------------------------------------------------------------------------- 1 |
2 | {% if next or prev %} 3 | 11 | {% endif %} 12 | 13 |
14 | 15 |
16 |

17 | {%- if show_copyright %} 18 | {%- if hasdoc('copyright') %} 19 | {% trans path=pathto('copyright'), copyright=copyright|e %}© Copyright, 2016 HPE .{% endtrans %} 20 | {%- else %} 21 | {% trans copyright=copyright|e %}© Copyright {{ copyright }}.{% endtrans %} 22 | {%- endif %} 23 | {%- endif %} 24 | 25 | {%- if build_id and build_url %} 26 | {% trans build_url=build_url, build_id=build_id %} 27 | 28 | Build 29 | {{ build_id }}. 30 | 31 | {% endtrans %} 32 | {%- elif commit %} 33 | {% trans commit=commit %} 34 | 35 | Revision {{ commit }}. 36 | 37 | {% endtrans %} 38 | {%- elif last_updated %} 39 | {% trans last_updated=last_updated|e %}Last updated on {{ last_updated }}.{% endtrans %} 40 | {%- endif %} 41 | 42 |

43 |
44 | 45 | {%- if show_sphinx %} 46 | {% trans %}{% endtrans %} 47 | {%- endif %} 48 | 49 | {%- block extrafooter %} {% endblock %} 50 | 51 |
52 | 53 | -------------------------------------------------------------------------------- /docs/themes/sphinx_rtd_theme/search.html: -------------------------------------------------------------------------------- 1 | {# 2 | basic/search.html 3 | ~~~~~~~~~~~~~~~~~ 4 | 5 | Template for the search page. 6 | 7 | :copyright: Copyright 2007-2013 by the Sphinx team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | #} 10 | {%- extends "layout.html" %} 11 | {% set title = _('Search') %} 12 | {% set script_files = script_files + ['_static/searchtools.js'] %} 13 | {% block footer %} 14 | 17 | {# this is used when loading the search index using $.ajax fails, 18 | such as on Chrome for documents on localhost #} 19 | 20 | {{ super() }} 21 | {% endblock %} 22 | {% block body %} 23 | 31 | 32 | {% if search_performed %} 33 |

{{ _('Search Results') }}

34 | {% if not search_results %} 35 |

{{ _('Your search did not match any documents. Please make sure that all words are spelled correctly and that you\'ve selected enough categories.') }}

36 | {% endif %} 37 | {% endif %} 38 |
39 | {% if search_results %} 40 |
    41 | {% for href, caption, context in search_results %} 42 |
  • 43 | {{ caption }} 44 |

    {{ context|e }}

    45 |
  • 46 | {% endfor %} 47 |
48 | {% endif %} 49 |
50 | {% endblock %} 51 | -------------------------------------------------------------------------------- /docs/themes/sphinx_rtd_theme/searchbox.html: -------------------------------------------------------------------------------- 1 | {%- if builder != 'singlehtml' %} 2 |
3 |
4 | 5 | 6 | 7 |
8 |
9 | {%- endif %} 10 | -------------------------------------------------------------------------------- /docs/themes/sphinx_rtd_theme/static/css/badge_only.css: -------------------------------------------------------------------------------- 1 | .fa:before{-webkit-font-smoothing:antialiased}.clearfix{*zoom:1}.clearfix:before,.clearfix:after{display:table;content:""}.clearfix:after{clear:both}@font-face{font-family:FontAwesome;font-weight:normal;font-style:normal;src:url("../font/fontawesome_webfont.eot");src:url("../font/fontawesome_webfont.eot?#iefix") format("embedded-opentype"),url("../font/fontawesome_webfont.woff") format("woff"),url("../font/fontawesome_webfont.ttf") format("truetype"),url("../font/fontawesome_webfont.svg#FontAwesome") format("svg")}.fa:before{display:inline-block;font-family:FontAwesome;font-style:normal;font-weight:normal;line-height:1;text-decoration:inherit}a .fa{display:inline-block;text-decoration:inherit}li .fa{display:inline-block}li .fa-large:before,li .fa-large:before{width:1.875em}ul.fas{list-style-type:none;margin-left:2em;text-indent:-0.8em}ul.fas li .fa{width:0.8em}ul.fas li .fa-large:before,ul.fas li .fa-large:before{vertical-align:baseline}.fa-book:before{content:""}.icon-book:before{content:""}.fa-caret-down:before{content:""}.icon-caret-down:before{content:""}.fa-caret-up:before{content:""}.icon-caret-up:before{content:""}.fa-caret-left:before{content:""}.icon-caret-left:before{content:""}.fa-caret-right:before{content:""}.icon-caret-right:before{content:""}.rst-versions{position:fixed;bottom:0;left:0;width:300px;color:#fcfcfc;background:#1f1d1d;border-top:solid 10px #343131;font-family:"Lato","proxima-nova","Helvetica Neue",Arial,sans-serif;z-index:400}.rst-versions a{color:#2980B9;text-decoration:none}.rst-versions .rst-badge-small{display:none}.rst-versions .rst-current-version{padding:12px;background-color:#272525;display:block;text-align:right;font-size:90%;cursor:pointer;color:#27AE60;*zoom:1}.rst-versions .rst-current-version:before,.rst-versions .rst-current-version:after{display:table;content:""}.rst-versions .rst-current-version:after{clear:both}.rst-versions .rst-current-version .fa{color:#fcfcfc}.rst-versions .rst-current-version .fa-book{float:left}.rst-versions .rst-current-version .icon-book{float:left}.rst-versions .rst-current-version.rst-out-of-date{background-color:#E74C3C;color:#fff}.rst-versions .rst-current-version.rst-active-old-version{background-color:#F1C40F;color:#000}.rst-versions.shift-up .rst-other-versions{display:block}.rst-versions .rst-other-versions{font-size:90%;padding:12px;color:gray;display:none}.rst-versions .rst-other-versions hr{display:block;height:1px;border:0;margin:20px 0;padding:0;border-top:solid 1px #413d3d}.rst-versions .rst-other-versions dd{display:inline-block;margin:0}.rst-versions .rst-other-versions dd a{display:inline-block;padding:6px;color:#fcfcfc}.rst-versions.rst-badge{width:auto;bottom:20px;right:20px;left:auto;border:none;max-width:300px}.rst-versions.rst-badge .icon-book{float:none}.rst-versions.rst-badge .fa-book{float:none}.rst-versions.rst-badge.shift-up .rst-current-version{text-align:right}.rst-versions.rst-badge.shift-up .rst-current-version .fa-book{float:left}.rst-versions.rst-badge.shift-up .rst-current-version .icon-book{float:left}.rst-versions.rst-badge .rst-current-version{width:auto;height:30px;line-height:30px;padding:0 6px;display:block;text-align:center}@media screen and (max-width: 768px){.rst-versions{width:85%;display:none}.rst-versions.shift{display:block}img{width:100%;height:auto}} 2 | /*# sourceMappingURL=badge_only.css.map */ 3 | -------------------------------------------------------------------------------- /docs/themes/sphinx_rtd_theme/static/css/badge_only.css.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "mappings": "CAyDA,SAAY,EACV,qBAAsB,EAAE,UAAW,EAqDrC,QAAS,EARP,IAAK,EAAE,AAAC,EACR,+BAAS,EAEP,MAAO,EAAE,IAAK,EACd,MAAO,EAAE,CAAE,EACb,cAAO,EACL,IAAK,EAAE,GAAI,EC1Gb,SAkBC,EAjBC,UAAW,ECFJ,UAAW,EDGlB,UAAW,EAHqC,KAAM,EAItD,SAAU,EAJsD,KAAM,EAapE,EAAG,EAAE,qCAAwB,EAC7B,EAAG,EAAE,0PAAyE,ECZpF,SAAU,EACR,MAAO,EAAE,WAAY,EACrB,UAAW,EAAE,UAAW,EACxB,SAAU,EAAE,KAAM,EAClB,UAAW,EAAE,KAAM,EACnB,UAAW,EAAE,AAAC,EACd,cAAe,EAAE,MAAO,EAG1B,IAAK,EACH,MAAO,EAAE,WAAY,EACrB,cAAe,EAAE,MAAO,EAIxB,KAAG,EACD,MAAO,EAAE,WAAY,EACvB,sCAAiB,EAGf,IAAK,EAAE,MAAY,EAEvB,KAAM,EACJ,cAAe,EAAE,GAAI,EACrB,UAAW,EAAE,EAAG,EAChB,UAAW,EAAE,KAAM,EAEjB,YAAG,EACD,IAAK,EAAE,IAAI,EACb,oDAAiB,EAGf,aAAc,EAAE,OAAQ,EAG9B,cAAe,EACb,MAAO,EAAE,EAAO,EAElB,gBAAiB,EACf,MAAO,EAAE,EAAO,EAElB,oBAAqB,EACnB,MAAO,EAAE,EAAO,EAElB,sBAAuB,EACrB,MAAO,EAAE,EAAO,EAElB,kBAAmB,EACjB,MAAO,EAAE,EAAO,EAElB,oBAAqB,EACnB,MAAO,EAAE,EAAO,EAElB,oBAAqB,EACnB,MAAO,EAAE,EAAO,EAElB,sBAAuB,EACrB,MAAO,EAAE,EAAO,EAElB,qBAAsB,EACpB,MAAO,EAAE,EAAO,EAElB,uBAAwB,EACtB,MAAO,EAAE,EAAO,ECnElB,YAAa,EACX,OAAQ,EAAE,IAAK,EACf,KAAM,EAAE,AAAC,EACT,GAAI,EAAE,AAAC,EACP,IAAK,EC6E+B,IAAK,ED5EzC,IAAK,EEoC+B,MAAyB,EFnC7D,SAAU,EAAE,MAAkC,EAC9C,SAAU,EAAE,iBAAiC,EAC7C,UAAW,EE+CyB,sDAAM,EF9C1C,MAAO,EC+E6B,EAAG,ED9EvC,cAAC,EACC,IAAK,EE+B6B,MAAK,EF9BvC,cAAe,EAAE,GAAI,EACvB,6BAAgB,EACd,MAAO,EAAE,GAAI,EACf,iCAAoB,EAClB,MAAO,EAAE,GAAqB,EAC9B,eAAgB,EAAE,MAAkC,EACpD,MAAO,EAAE,IAAK,EACd,SAAU,EAAE,IAAK,EACjB,QAAS,EAAE,EAAG,EACd,KAAM,EAAE,MAAO,EACf,IAAK,EEX6B,MAAM,EL4F1C,IAAK,EAAE,AAAC,EACR,iFAAS,EAEP,MAAO,EAAE,IAAK,EACd,MAAO,EAAE,CAAE,EACb,uCAAO,EACL,IAAK,EAAE,GAAI,EGrFX,qCAAG,EACD,IAAK,EEgB2B,MAAyB,EFf3D,0CAAQ,EACN,IAAK,EAAE,GAAI,EACb,4CAAU,EACR,IAAK,EAAE,GAAI,EACb,iDAAiB,EACf,eAAgB,ECQgB,MAAI,EDPpC,IAAK,EEI2B,GAAM,EFHxC,wDAAwB,EACtB,eAAgB,EEmBgB,MAAO,EFlBvC,IAAK,ECzB2B,GAAI,ED0BxC,yCAA8B,EAC5B,MAAO,EAAE,IAAK,EAChB,gCAAmB,EACjB,QAAS,EAAE,EAAG,EACd,MAAO,EAAE,GAAqB,EAC9B,IAAK,EEP6B,GAAY,EFQ9C,MAAO,EAAE,GAAI,EACb,mCAAE,EACA,MAAO,EAAE,IAAK,EACd,KAAM,EAAE,EAAG,EACX,KAAM,EAAE,AAAC,EACT,KAAM,EAAE,KAAM,EACd,MAAO,EAAE,AAAC,EACV,SAAU,EAAE,gBAA6C,EAC3D,mCAAE,EACA,MAAO,EAAE,WAAY,EACrB,KAAM,EAAE,AAAC,EACT,qCAAC,EACC,MAAO,EAAE,WAAY,EACrB,MAAO,EAAE,EAAqB,EAC9B,IAAK,EEfyB,MAAyB,EFgB7D,sBAAW,EACT,IAAK,EAAE,GAAI,EACX,KAAM,EAAE,GAAI,EACZ,IAAK,EAAE,GAAI,EACX,GAAI,EAAE,GAAI,EACV,KAAM,EAAE,GAAI,EACZ,QAAS,ECkByB,IAAK,EDjBvC,iCAAU,EACR,IAAK,EAAE,GAAI,EACb,+BAAQ,EACN,IAAK,EAAE,GAAI,EACb,oDAA+B,EAC7B,SAAU,EAAE,IAAK,EACjB,6DAAQ,EACN,IAAK,EAAE,GAAI,EACb,+DAAU,EACR,IAAK,EAAE,GAAI,EACf,2CAAoB,EAClB,IAAK,EAAE,GAAI,EACX,KAAM,EAAE,GAAI,EACZ,UAAW,EAAE,GAAI,EACjB,MAAO,EAAE,IAAuB,EAChC,MAAO,EAAE,IAAK,EACd,SAAU,EAAE,KAAM,EGhDpB,mCAAsB,EHmDxB,YAAa,EACX,IAAK,EAAE,EAAG,EACV,MAAO,EAAE,GAAI,EACb,kBAAO,EACL,MAAO,EAAE,IAAK,EAClB,EAAG,EACD,IAAK,EAAE,GAAI,EACX,KAAM,EAAE,GAAI", 4 | "sources": ["../../../bower_components/wyrm/sass/wyrm_core/_mixin.sass","../../../bower_components/bourbon/dist/css3/_font-face.scss","../../../sass/_theme_badge_fa.sass","../../../sass/_theme_badge.sass","../../../bower_components/wyrm/sass/wyrm_core/_wy_variables.sass","../../../sass/_theme_variables.sass","../../../bower_components/neat/app/assets/stylesheets/grid/_media.scss"], 5 | "names": [], 6 | "file": "badge_only.css" 7 | } 8 | -------------------------------------------------------------------------------- /docs/themes/sphinx_rtd_theme/static/fonts/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-ilorest-library/82d7ae4a9d9682c7e48e9e19e665bde79fa9d8bf/docs/themes/sphinx_rtd_theme/static/fonts/FontAwesome.otf -------------------------------------------------------------------------------- /docs/themes/sphinx_rtd_theme/static/fonts/Inconsolata-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-ilorest-library/82d7ae4a9d9682c7e48e9e19e665bde79fa9d8bf/docs/themes/sphinx_rtd_theme/static/fonts/Inconsolata-Bold.ttf -------------------------------------------------------------------------------- /docs/themes/sphinx_rtd_theme/static/fonts/Inconsolata-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-ilorest-library/82d7ae4a9d9682c7e48e9e19e665bde79fa9d8bf/docs/themes/sphinx_rtd_theme/static/fonts/Inconsolata-Regular.ttf -------------------------------------------------------------------------------- /docs/themes/sphinx_rtd_theme/static/fonts/Lato-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-ilorest-library/82d7ae4a9d9682c7e48e9e19e665bde79fa9d8bf/docs/themes/sphinx_rtd_theme/static/fonts/Lato-Bold.ttf -------------------------------------------------------------------------------- /docs/themes/sphinx_rtd_theme/static/fonts/Lato-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-ilorest-library/82d7ae4a9d9682c7e48e9e19e665bde79fa9d8bf/docs/themes/sphinx_rtd_theme/static/fonts/Lato-Regular.ttf -------------------------------------------------------------------------------- /docs/themes/sphinx_rtd_theme/static/fonts/RobotoSlab-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-ilorest-library/82d7ae4a9d9682c7e48e9e19e665bde79fa9d8bf/docs/themes/sphinx_rtd_theme/static/fonts/RobotoSlab-Bold.ttf -------------------------------------------------------------------------------- /docs/themes/sphinx_rtd_theme/static/fonts/RobotoSlab-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-ilorest-library/82d7ae4a9d9682c7e48e9e19e665bde79fa9d8bf/docs/themes/sphinx_rtd_theme/static/fonts/RobotoSlab-Regular.ttf -------------------------------------------------------------------------------- /docs/themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-ilorest-library/82d7ae4a9d9682c7e48e9e19e665bde79fa9d8bf/docs/themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /docs/themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-ilorest-library/82d7ae4a9d9682c7e48e9e19e665bde79fa9d8bf/docs/themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /docs/themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-ilorest-library/82d7ae4a9d9682c7e48e9e19e665bde79fa9d8bf/docs/themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /docs/themes/sphinx_rtd_theme/theme.conf: -------------------------------------------------------------------------------- 1 | [theme] 2 | inherit = basic 3 | stylesheet = css/theme.css 4 | 5 | [options] 6 | typekit_id = hiw1hhg 7 | analytics_id = 8 | sticky_navigation = False 9 | logo_only = 10 | collapse_navigation = False 11 | display_version = True 12 | -------------------------------------------------------------------------------- /docs/themes/sphinx_rtd_theme/versions.html: -------------------------------------------------------------------------------- 1 | {% if READTHEDOCS %} 2 | {# Add rst-badge after rst-versions for small badge style. #} 3 |
4 | 5 | Read the Docs 6 | v: {{ current_version }} 7 | 8 | 9 |
10 |
11 |
Versions
12 | {% for slug, url in versions %} 13 |
{{ slug }}
14 | {% endfor %} 15 |
16 |
17 |
Downloads
18 | {% for type, url in downloads %} 19 |
{{ type }}
20 | {% endfor %} 21 |
22 |
23 |
On Read the Docs
24 |
25 | Project Home 26 |
27 |
28 | Builds 29 |
30 |
31 |
32 | Free document hosting provided by Read the Docs. 33 | 34 |
35 |
36 | {% else %} 37 | {# Add rst-badge after rst-versions for small badge style. #} 38 |
39 | 40 | Other Versions 41 | 42 | 43 |
44 |
45 |
Versions
46 |
latest
47 |
3.0
48 |
49 | 50 |
51 |
52 | {% endif %} 53 | 54 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/add_ilo_user_account.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 | 16 | """ 17 | An example of adding a user account by iLO privileges 18 | """ 19 | 20 | 21 | import sys 22 | from redfish import LegacyRestClient 23 | from get_resource_directory import get_resource_directory 24 | 25 | def add_ilo_user_account(restobj, new_ilo_loginname, new_ilo_username, \ 26 | new_ilo_password, irc=False, cfg=False, \ 27 | virtual_media=False, usercfg=False, vpr=False): 28 | resource_instances = get_resource_directory(restobj) 29 | if resource_instances: 30 | #Get URI from resource directory 31 | for instance in resource_instances: 32 | if "Collection." in instance.Type: 33 | if instance.MemberType.startswith("ManagerAccount."): 34 | accounts_path = instance.href 35 | break 36 | 37 | body = {"UserName": new_ilo_loginname, "Password": new_ilo_password, "Oem": {}} 38 | body["Oem"]["Hp"] = {} 39 | body["Oem"]["Hp"]["LoginName"] = new_ilo_username 40 | body["Oem"]["Hp"]["Privileges"] = {} 41 | body["Oem"]["Hp"]["Privileges"]["RemoteConsolePriv"] = irc 42 | body["Oem"]["Hp"]["Privileges"]["iLOConfigPriv"] = cfg 43 | body["Oem"]["Hp"]["Privileges"]["VirtualMediaPriv"] = virtual_media 44 | body["Oem"]["Hp"]["Privileges"]["UserConfigPriv"] = usercfg 45 | body["Oem"]["Hp"]["Privileges"]["VirtualPowerAndResetPriv"] = vpr 46 | 47 | response = restobj.post(accounts_path, body) 48 | 49 | sys.stdout.write("%s" % response) 50 | 51 | if __name__ == "__main__": 52 | # When running on the server locally use the following commented values 53 | # SYSTEM_URL = None 54 | # LOGIN_ACCOUNT = None 55 | # LOGIN_PASSWORD = None 56 | 57 | # When running remotely connect using the iLO secured (https://) address, 58 | # iLO account name, and password to send https requests 59 | # SYSTEM_URL acceptable examples: 60 | # "https://10.0.0.100" 61 | # "https://ilo.hostname" 62 | SYSTEM_URL = "https://10.0.0.100" 63 | LOGIN_ACCOUNT = "admin" 64 | LOGIN_PASSWORD = "password" 65 | 66 | #Create a REST object 67 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 68 | REST_OBJ.login() 69 | sys.stdout.write("\nEXAMPLE 10: Create an iLO User Account\n") 70 | add_ilo_user_account(REST_OBJ, "name", "username", "password") 71 | REST_OBJ.logout() 72 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/bios_revert_default.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def bios_revert_default(restobj): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "HpBios." in instance.Type: 25 | if "PUT" in instance.HttpMethods: 26 | bios_path = instance.href 27 | break 28 | 29 | body = {"BaseConfig": "default"} 30 | response = restobj.put(bios_path, body) 31 | sys.stdout.write("%s" % response) 32 | 33 | if __name__ == "__main__": 34 | # When running on the server locally use the following commented values 35 | # SYSTEM_URL = None 36 | # LOGIN_ACCOUNT = None 37 | # LOGIN_PASSWORD = None 38 | 39 | # When running remotely connect using the iLO secured (https://) address, 40 | # iLO account name, and password to send https requests 41 | # SYSTEM_URL acceptable examples: 42 | # "https://10.0.0.100" 43 | # "https://ilo.hostname" 44 | SYSTEM_URL = "https://10.0.0.100" 45 | LOGIN_ACCOUNT = "admin" 46 | LOGIN_PASSWORD = "password" 47 | 48 | #Create a REST object 49 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 50 | REST_OBJ.login() 51 | sys.stdout.write("\nEXAMPLE 6: Revert BIOS settings to default\n") 52 | bios_revert_default(REST_OBJ) 53 | REST_OBJ.logout() 54 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/change_bios_setting.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def change_bios_setting(restobj, bios_property, property_value, bios_password=None): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "HpBios." in instance.Type: 25 | if "PUT" in instance.HttpMethods: 26 | bios_path = instance.href 27 | break 28 | 29 | body = {bios_property: property_value} 30 | 31 | #BIOS password is the password if secondary authentication is 32 | #required before entering RBSU screen Only required on Gen9 systems 33 | restobj.bios_password = bios_password 34 | 35 | response = restobj.patch(bios_path, body) 36 | sys.stdout.write("%s" % response) 37 | 38 | if __name__ == "__main__": 39 | # When running on the server locally use the following commented values 40 | # SYSTEM_URL = None 41 | # LOGIN_ACCOUNT = None 42 | # LOGIN_PASSWORD = None 43 | 44 | # When running remotely connect using the iLO secured (https://) address, 45 | # iLO account name, and password to send https requests 46 | # SYSTEM_URL acceptable examples: 47 | # "https://10.0.0.100" 48 | # "https://ilo.hostname" 49 | SYSTEM_URL = "https://10.0.0.100" 50 | LOGIN_ACCOUNT = "admin" 51 | LOGIN_PASSWORD = "password" 52 | 53 | #Create a REST object 54 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 55 | REST_OBJ.login() 56 | sys.stdout.write("\nEXAMPLE 3: Change a BIOS setting\n") 57 | change_bios_setting(REST_OBJ, "AdminName", "admin") 58 | REST_OBJ.logout() 59 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/change_boot_order.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def change_boot_order(restobj, bios_password=None): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "ServerBootSettings." in instance.Type: 25 | if "PATCH" in instance.HttpMethods: 26 | boot_settings_path = instance.href 27 | break 28 | response = restobj.get(boot_settings_path) 29 | bootorder = response.dict["PersistentBootConfigOrder"] 30 | 31 | #TODO: Need to change the persistent boot order here 32 | body = dict() 33 | body["PersistentBootConfigOrder"] = bootorder 34 | 35 | #BIOS password is the password if secondary authentication is 36 | #required before entering RBSU screen Only required on Gen9 systems 37 | restobj.bios_password = bios_password 38 | 39 | response = restobj.patch(boot_settings_path, body) 40 | sys.stdout.write("%s" % response) 41 | 42 | if __name__ == "__main__": 43 | # When running on the server locally use the following commented values 44 | # SYSTEM_URL = None 45 | # LOGIN_ACCOUNT = None 46 | # LOGIN_PASSWORD = None 47 | 48 | # When running remotely connect using the iLO secured (https://) address, 49 | # iLO account name, and password to send https requests 50 | # SYSTEM_URL acceptable examples: 51 | # "https://10.0.0.100" 52 | # "https://ilo.hostname" 53 | SYSTEM_URL = "https://10.0.0.100" 54 | LOGIN_ACCOUNT = "admin" 55 | LOGIN_PASSWORD = "password" 56 | 57 | #Create a REST object 58 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 59 | REST_OBJ.login() 60 | sys.stdout.write("\nEXAMPLE 7: Change Boot Order (UEFI)\n") 61 | change_boot_order(REST_OBJ) 62 | REST_OBJ.logout() 63 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/change_temporary_boot_order.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def change_temporary_boot_order(restobj, boottarget, bios_password=None): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "ComputerSystem." in instance.Type: 25 | system_path = instance.href 26 | break 27 | response = restobj.get(system_path) 28 | bootoptions = response.dict["Boot"] 29 | 30 | if boottarget not in bootoptions["BootSourceOverrideSupported"]: 31 | sys.stderr.write("ERROR: %s is not a supported boot option.\n" % boottarget) 32 | return 33 | 34 | body = dict() 35 | body["Boot"] = dict() 36 | body["Boot"]["BootSourceOverrideTarget"] = boottarget 37 | 38 | #BIOS password is the password if secondary authentication is 39 | #required before entering RBSU screen Only required on Gen9 systems 40 | restobj.bios_password = bios_password 41 | 42 | response = restobj.patch(system_path, body) 43 | sys.stdout.write("%s" % response) 44 | 45 | if __name__ == "__main__": 46 | # When running on the server locally use the following commented values 47 | # SYSTEM_URL = None 48 | # LOGIN_ACCOUNT = None 49 | # LOGIN_PASSWORD = None 50 | 51 | # When running remotely connect using the iLO secured (https://) address, 52 | # iLO account name, and password to send https requests 53 | # SYSTEM_URL acceptable examples: 54 | # "https://10.0.0.100" 55 | # "https://ilo.hostname" 56 | SYSTEM_URL = "https://10.0.0.100" 57 | LOGIN_ACCOUNT = "admin" 58 | LOGIN_PASSWORD = "password" 59 | 60 | #Create a REST object 61 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 62 | REST_OBJ.login() 63 | sys.stdout.write("\nEXAMPLE 8: Change temporary boot order (one time boot" \ 64 | " or temporary override)\n") 65 | change_temporary_boot_order(REST_OBJ, "Hdd") 66 | REST_OBJ.logout() 67 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/clear_ahs_data.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def clear_ahs_data(restobj): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "HpiLOActiveHealthSystem." in instance.Type: 25 | AHS_path = instance.href 26 | break 27 | 28 | body = {"Action": "ClearLog"} 29 | 30 | response = restobj.post(AHS_path, body) 31 | sys.stdout.write("%s" % response) 32 | 33 | if __name__ == "__main__": 34 | # When running on the server locally use the following commented values 35 | # SYSTEM_URL = None 36 | # LOGIN_ACCOUNT = None 37 | # LOGIN_PASSWORD = None 38 | 39 | # When running remotely connect using the iLO secured (https://) address, 40 | # iLO account name, and password to send https requests 41 | # SYSTEM_URL acceptable examples: 42 | # "https://10.0.0.100" 43 | # "https://ilo.hostname" 44 | SYSTEM_URL = "https://10.0.0.100" 45 | LOGIN_ACCOUNT = "admin" 46 | LOGIN_PASSWORD = "password" 47 | 48 | #Create a REST object 49 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 50 | REST_OBJ.login() 51 | sys.stdout.write("\nEXAMPLE 47: Clear AHS Data\n") 52 | clear_ahs_data(REST_OBJ) 53 | REST_OBJ.logout() 54 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/clear_ilo_event_log.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def clear_ilo_event_log(restobj): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "LogService." in instance.Type: 25 | if instance["href"].endswith("IEL"): 26 | IEL_path = instance.href 27 | break 28 | 29 | body = {"Action": "ClearLog"} 30 | response = restobj.post(IEL_path, body) 31 | sys.stdout.write("%s" % response) 32 | 33 | if __name__ == "__main__": 34 | # When running on the server locally use the following commented values 35 | # SYSTEM_URL = None 36 | # LOGIN_ACCOUNT = None 37 | # LOGIN_PASSWORD = None 38 | 39 | # When running remotely connect using the iLO secured (https://) address, 40 | # iLO account name, and password to send https requests 41 | # SYSTEM_URL acceptable examples: 42 | # "https://10.0.0.100" 43 | # "https://ilo.hostname" 44 | SYSTEM_URL = "https://10.0.0.100" 45 | LOGIN_ACCOUNT = "admin" 46 | LOGIN_PASSWORD = "password" 47 | 48 | #Create a REST object 49 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 50 | REST_OBJ.login() 51 | sys.stdout.write("\nEXAMPLE 25: Clear iLO Event Log\n") 52 | clear_ilo_event_log(REST_OBJ) 53 | REST_OBJ.logout() 54 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/clear_iml.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def clear_iml(restobj): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "LogService." in instance.Type: 25 | if instance["href"].endswith("IML"): 26 | IEL_path = instance.href 27 | break 28 | 29 | body = {"Action": "ClearLog"} 30 | response = restobj.post(instance["href"], body) 31 | sys.stdout.write("%s" % response) 32 | 33 | if __name__ == "__main__": 34 | # When running on the server locally use the following commented values 35 | # SYSTEM_URL = None 36 | # LOGIN_ACCOUNT = None 37 | # LOGIN_PASSWORD = None 38 | 39 | # When running remotely connect using the iLO secured (https://) address, 40 | # iLO account name, and password to send https requests 41 | # SYSTEM_URL acceptable examples: 42 | # "https://10.0.0.100" 43 | # "https://ilo.hostname" 44 | SYSTEM_URL = "https://10.0.0.100" 45 | LOGIN_ACCOUNT = "admin" 46 | LOGIN_PASSWORD = "password" 47 | 48 | #Create a REST object 49 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 50 | REST_OBJ.login() 51 | sys.stdout.write("\nEXAMPLE 24: Clear Integrated Management Log\n") 52 | clear_iml(REST_OBJ) 53 | REST_OBJ.logout() 54 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/configure_snmp.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def configure_snmp(restobj, snmp_mode, snmp_alerts): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "SnmpService." in instance.Type: 25 | snmp_path = instance.href 26 | break 27 | 28 | body = {"Mode": snmp_mode, "AlertsEnabled": snmp_alerts} 29 | response = restobj.patch(snmp_path, body) 30 | sys.stdout.write("%s" % response) 31 | 32 | if __name__ == "__main__": 33 | # When running on the server locally use the following commented values 34 | # SYSTEM_URL = None 35 | # LOGIN_ACCOUNT = None 36 | # LOGIN_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 | # SYSTEM_URL acceptable examples: 41 | # "https://10.0.0.100" 42 | # "https://ilo.hostname" 43 | SYSTEM_URL = "https://10.0.0.100" 44 | LOGIN_ACCOUNT = "admin" 45 | LOGIN_PASSWORD = "password" 46 | 47 | #Create a REST object 48 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 49 | REST_OBJ.login() 50 | sys.stdout.write("\nEXAMPLE 26: Configure iLO SNMP Settings\n") 51 | configure_snmp(REST_OBJ, "Agentless", False) 52 | REST_OBJ.logout() 53 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/dump_eskm_event_log.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def dump_eskm_event_log(restobj): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "HpESKM." in instance.Type: 25 | eskm_path = instance.href 26 | break 27 | 28 | response = restobj.get(eskm_path) 29 | for entry in response.dict["ESKMEvents"]: 30 | sys.stdout.write(entry["Timestamp"] + "\n" + entry["Event"] + "\n") 31 | sys.stdout.write("%s" % response) 32 | 33 | if __name__ == "__main__": 34 | # When running on the server locally use the following commented values 35 | # SYSTEM_URL = None 36 | # LOGIN_ACCOUNT = None 37 | # LOGIN_PASSWORD = None 38 | 39 | # When running remotely connect using the iLO secured (https://) address, 40 | # iLO account name, and password to send https requests 41 | # SYSTEM_URL acceptable examples: 42 | # "https://10.0.0.100" 43 | # "https://ilo.hostname" 44 | SYSTEM_URL = "https://10.0.0.100" 45 | LOGIN_ACCOUNT = "admin" 46 | LOGIN_PASSWORD = "password" 47 | 48 | # Create a REST object 49 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 50 | REST_OBJ.login() 51 | sys.stdout.write("\nEXAMPLE 41: Dump ESKM Event Log\n") 52 | dump_eskm_event_log(REST_OBJ) 53 | REST_OBJ.logout() 54 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/dump_ilo_event_log.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def dump_ilo_event_log(restobj): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "LogService." in instance.Type: 25 | if instance["href"].endswith("IEL"): 26 | IEL_path = instance.href 27 | break 28 | 29 | tmp = restobj.get(IEL_path) 30 | 31 | for entry in tmp.dict["links"]["Entries"]: 32 | response = restobj.get(entry["href"]) 33 | print_log_entries(response.dict["Items"]) 34 | 35 | while 'NextPage' in response.dict["links"]: 36 | response = restobj.get(entry["href"] + '?page=' + \ 37 | str(response.dict["links"]['NextPage']['page'])) 38 | print_log_entries(response.dict["Items"]) 39 | sys.stdout.write("%s" % response) 40 | 41 | def print_log_entries(log_entries): 42 | for log_entry in log_entries: 43 | sys.stdout.write(log_entry["Message"] + "\n") 44 | 45 | if __name__ == "__main__": 46 | # When running on the server locally use the following commented values 47 | # SYSTEM_URL = None 48 | # LOGIN_ACCOUNT = None 49 | # LOGIN_PASSWORD = None 50 | 51 | # When running remotely connect using the iLO secured (https://) address, 52 | # iLO account name, and password to send https requests 53 | # SYSTEM_URL acceptable examples: 54 | # "https://10.0.0.100" 55 | # "https://ilo.hostname" 56 | SYSTEM_URL = "https://10.0.0.100" 57 | LOGIN_ACCOUNT = "admin" 58 | LOGIN_PASSWORD = "password" 59 | 60 | #Create a REST object 61 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 62 | REST_OBJ.login() 63 | sys.stdout.write("\nEXAMPLE 23: Dump iLO Event Log\n") 64 | dump_ilo_event_log(REST_OBJ) 65 | REST_OBJ.logout() 66 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/dump_ilo_nic.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def dump_ilo_nic(restobj): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "Manager." in instance.Type: 25 | manager_path = instance.href 26 | break 27 | 28 | manager = restobj.get(manager_path) 29 | response = restobj.get(manager.dict["links"]["EthernetNICs"]["href"]) 30 | 31 | for nic in response.dict["Items"]: 32 | if nic["Status"]["State"] == "Enabled": 33 | sys.stdout.write("\t" + nic["Name"] + "\n") 34 | 35 | if "MacAddress" not in nic: 36 | sys.stderr.write("\tNo MacAddress information available (no" 37 | " 'MacAddress' property in NIC resource)\n") 38 | else: 39 | sys.stdout.write("\tMAC: " + str(nic["MacAddress"]) + "\n") 40 | 41 | sys.stdout.write("\tSpeed: " + str(nic["SpeedMbps"]) + "\n") 42 | sys.stdout.write("\tAutosense: " + str(nic["Autosense"]) + "\n") 43 | sys.stdout.write("\tFull Duplex: " + str(nic["FullDuplex"]) + "\n") 44 | if "FQDN" not in nic: 45 | sys.stderr.write("\tNo FQDN information available\n") 46 | else: 47 | sys.stdout.write("\tFQDN: " + str(nic["FQDN"]) + "\n") 48 | for addr in nic["IPv4Addresses"]: 49 | sys.stdout.write("\tIPv4 Address: " + addr["Address"] 50 | + " from " + addr["AddressOrigin"] + "\n") 51 | if "IPv6Addresses" not in nic: 52 | sys.stderr.write("\tIPv6Addresses information not "\ 53 | "available\n") 54 | else: 55 | for addr in nic["IPv6Addresses"]: 56 | sys.stdout.write("\tIPv6 Address: " + addr["Address"] 57 | + " from " + addr["AddressOrigin"] + "\n") 58 | sys.stdout.write("%s" % response) 59 | if __name__ == "__main__": 60 | # When running on the server locally use the following commented values 61 | # SYSTEM_URL = None 62 | # LOGIN_ACCOUNT = None 63 | # LOGIN_PASSWORD = None 64 | 65 | # When running remotely connect using the iLO secured (https://) address, 66 | # iLO account name, and password to send https requests 67 | # SYSTEM_URL acceptable examples: 68 | # "https://10.0.0.100" 69 | # "https://ilo.hostname" 70 | SYSTEM_URL = "https://10.0.0.100" 71 | LOGIN_ACCOUNT = "admin" 72 | LOGIN_PASSWORD = "password" 73 | 74 | #Create a REST object 75 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 76 | REST_OBJ.login() 77 | sys.stdout.write("\nEXAMPLE 13: Get iLO NIC state\n") 78 | dump_ilo_nic(REST_OBJ) 79 | REST_OBJ.logout() 80 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/dump_iml.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def dump_iml(restobj): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "LogService." in instance.Type: 25 | if instance["href"].endswith("IML"): 26 | IML_path = instance.href 27 | break 28 | 29 | tmp = restobj.get(IML_path) 30 | 31 | for entry in tmp.dict["links"]["Entries"]: 32 | response = restobj.get(entry["href"]) 33 | print_log_entries(response.dict["Items"]) 34 | 35 | while 'NextPage' in response.dict["links"]: 36 | response = restobj.get(entry["href"] + '?page=' + \ 37 | str(response.dict["links"]['NextPage']['page'])) 38 | print_log_entries(response.dict["Items"]) 39 | 40 | def print_log_entries(log_entries): 41 | for log_entry in log_entries: 42 | sys.stdout.write(log_entry["Severity"] + ": Class " + \ 43 | str(log_entry["Oem"]["Hp"]["Class"]) + \ 44 | " / Code " + str(log_entry["Oem"]["Hp"]["Code"]) + \ 45 | ":\t" + log_entry["Message"] + "\n") 46 | 47 | if __name__ == "__main__": 48 | # When running on the server locally use the following commented values 49 | # SYSTEM_URL = None 50 | # LOGIN_ACCOUNT = None 51 | # LOGIN_PASSWORD = None 52 | 53 | # When running remotely connect using the iLO secured (https://) address, 54 | # iLO account name, and password to send https requests 55 | # SYSTEM_URL acceptable examples: 56 | # "https://10.0.0.100" 57 | # "https://ilo.hostname" 58 | SYSTEM_URL = "https://10.0.0.100" 59 | LOGIN_ACCOUNT = "admin" 60 | LOGIN_PASSWORD = "password" 61 | 62 | #Create a REST object 63 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 64 | REST_OBJ.login() 65 | sys.stdout.write("\nEXAMPLE 22: Dump Integrated Management Log\n") 66 | dump_iml(REST_OBJ) 67 | REST_OBJ.logout() 68 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/enable_secure_boot.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def enable_secure_boot(restobj, secure_boot_enable, bios_password=None): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "HpSecureBoot." in instance.Type: 25 | secure_boot_path = instance.href 26 | break 27 | 28 | #BIOS password is the password if secondary authentication is 29 | #required before entering RBSU screen Only required on Gen9 systems 30 | restobj.bios_password = bios_password 31 | 32 | body = {"SecureBootEnable": secure_boot_enable} 33 | 34 | response = restobj.patch(secure_boot_path, body) 35 | sys.stdout.write("%s" % response) 36 | 37 | if __name__ == "__main__": 38 | # When running on the server locally use the following commented values 39 | # SYSTEM_URL = None 40 | # LOGIN_ACCOUNT = None 41 | # LOGIN_PASSWORD = None 42 | 43 | # When running remotely connect using the iLO secured (https://) address, 44 | # iLO account name, and password to send https requests 45 | # SYSTEM_URL acceptable examples: 46 | # "https://10.0.0.100" 47 | # "https://ilo.hostname" 48 | SYSTEM_URL = "https://10.0.0.100" 49 | LOGIN_ACCOUNT = "admin" 50 | LOGIN_PASSWORD = "password" 51 | 52 | #Create a REST object 53 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 54 | REST_OBJ.login() 55 | sys.stdout.write("\nEXAMPLE 5: Enable/Disable UEFI Secure Boot\n") 56 | enable_secure_boot(REST_OBJ, False) 57 | REST_OBJ.logout() 58 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/find_ilo_mac_address.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def find_ilo_mac_address(restobj): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "Manager." in instance.Type: 25 | manager_path = instance.href 26 | break 27 | 28 | tmp = restobj.get(manager_path) 29 | response = restobj.get(tmp.dict["links"]["EthernetNICs"]["href"]) 30 | 31 | for item in response.dict["Items"]: 32 | if "MacAddress" not in item: 33 | sys.stderr.write("\tNIC resource does not contain 'MacAddress' property\n") 34 | else: 35 | sys.stdout.write("\t" + item["Name"] + " = " + item["MacAddress"] + "\t(" + \ 36 | item["Status"]["State"] + ")\n") 37 | sys.stdout.write("%s" % response) 38 | if __name__ == "__main__": 39 | # When running on the server locally use the following commented values 40 | # SYSTEM_URL = None 41 | # LOGIN_ACCOUNT = None 42 | # LOGIN_PASSWORD = None 43 | 44 | # When running remotely connect using the iLO secured (https://) address, 45 | # iLO account name, and password to send https requests 46 | # SYSTEM_URL acceptable examples: 47 | # "https://10.0.0.100" 48 | # "https://ilo.hostname" 49 | SYSTEM_URL = "https://10.0.0.100" 50 | LOGIN_ACCOUNT = "admin" 51 | LOGIN_PASSWORD = "password" 52 | 53 | #Create a REST object 54 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 55 | sys.stdout.write("\nEXAMPLE 9: Find iLO's MAC Addresses\n") 56 | REST_OBJ.login() 57 | find_ilo_mac_address(REST_OBJ) 58 | REST_OBJ.logout() 59 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/generate_csr.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def generate_csr(restobj, csr_properties): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "HpHttpsCert." in instance.Type: 25 | https_path = instance.href 26 | break 27 | 28 | body = dict() 29 | body["Action"] = "GenerateCSR" 30 | body["City"] = csr_properties["City"] 31 | body["CommonName"] = csr_properties["CommonName"] 32 | body["Country"] = csr_properties["Country"] 33 | body["OrgName"] = csr_properties["OrgName"] 34 | body["OrgUnit"] = csr_properties["OrgUnit"] 35 | body["State"] = csr_properties["State"] 36 | response = restobj.post(https_path, body) 37 | sys.stdout.write("%s" % response) 38 | sys.stdout.write("Generating CSR, this may take a few minutes\n") 39 | 40 | if __name__ == "__main__": 41 | # When running on the server locally use the following commented values 42 | # SYSTEM_URL = None 43 | # LOGIN_ACCOUNT = None 44 | # LOGIN_PASSWORD = None 45 | 46 | # When running remotely connect using the iLO secured (https://) address, 47 | # iLO account name, and password to send https requests 48 | # SYSTEM_URL acceptable examples: 49 | # "https://10.0.0.100" 50 | # "https://ilo.hostname" 51 | SYSTEM_URL = "https://10.0.0.100" 52 | LOGIN_ACCOUNT = "admin" 53 | LOGIN_PASSWORD = "password" 54 | 55 | #Create a REST object 56 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 57 | REST_OBJ.login() 58 | sys.stdout.write("\nEXAMPLE 49: Generate CSR\n") 59 | generate_csr(REST_OBJ, {"City" : "City",\ 60 | "CommonName": "Common Name",\ 61 | "Country": "US",\ 62 | "OrgName": "Organization",\ 63 | "OrgUnit": "Unit",\ 64 | "State": "State"}) 65 | REST_OBJ.logout() 66 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/get_ESKM.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 | import json 17 | from redfish import LegacyRestClient 18 | from get_resource_directory import get_resource_directory 19 | 20 | def get_ESKM(restobj): 21 | resource_instances = get_resource_directory(restobj) 22 | if resource_instances: 23 | #Get URI from resource directory 24 | for instance in resource_instances: 25 | if "HpESKM." in instance.Type: 26 | eskm_path = instance.href 27 | break 28 | 29 | response = restobj.get(eskm_path) 30 | 31 | sys.stdout.write("\tPrimaryKeyServerAddress: " + 32 | json.dumps(response.dict["PrimaryKeyServerAddress"]) + "\n") 33 | sys.stdout.write("\tPrimaryKeyServerPort: " + 34 | json.dumps(response.dict["PrimaryKeyServerPort"]) + "\n") 35 | sys.stdout.write("\tSecondaryKeyServerAddress: " + 36 | json.dumps(response.dict["SecondaryKeyServerAddress"])\ 37 | + "\n") 38 | sys.stdout.write("\tSecondaryKeyServerPort: " + 39 | json.dumps(response.dict["SecondaryKeyServerPort"])\ 40 | + "\n") 41 | sys.stdout.write("\tType: " + json.dumps(response.dict["Type"]) + "\n") 42 | sys.stdout.write("\tKeyServerRedundancyReq: " + 43 | json.dumps(response.dict["KeyServerRedundancyReq"]) + "\n") 44 | 45 | sys.stdout.write("\tAccountGroup: " + json.dumps(response.dict["KeyManagerConfig"]\ 46 | ["AccountGroup"]) + "\n") 47 | sys.stdout.write("\tESKMLocalCACertificateName: " + 48 | json.dumps(response.dict["KeyManagerConfig"]\ 49 | ["ESKMLocalCACertificateName"]) + "\n") 50 | sys.stdout.write("\tImportedCertificateIssuer: " + 51 | json.dumps(response.dict["KeyManagerConfig"]\ 52 | ["ImportedCertificateIssuer"]) + "\n") 53 | 54 | sys.stdout.write("\tESKMEvents: " + json.dumps(response.dict["ESKMEvents"]) + "\n") 55 | 56 | tmp = response.dict["ESKMEvents"] 57 | for entry in tmp: 58 | sys.stdout.write("\tTimestamp : " + entry["Timestamp"] + "Event: " + 59 | json.dumps(entry["Event"]) + "\n") 60 | sys.stdout.write("%s" % response) 61 | 62 | if __name__ == "__main__": 63 | # When running on the server locally use the following commented values 64 | # SYSTEM_URL = None 65 | # LOGIN_ACCOUNT = None 66 | # LOGIN_PASSWORD = None 67 | 68 | # When running remotely connect using the iLO secured (https://) address, 69 | # iLO account name, and password to send https requests 70 | # SYSTEM_URL acceptable examples: 71 | # "https://10.0.0.100" 72 | # "https://ilo.hostname" 73 | SYSTEM_URL = "https://10.0.0.100" 74 | LOGIN_ACCOUNT = "admin" 75 | LOGIN_PASSWORD = "password" 76 | 77 | # Create a REST object 78 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 79 | REST_OBJ.login() 80 | sys.stdout.write("\nEXAMPLE 42: Get ESKM configuration\n") 81 | get_ESKM(REST_OBJ) 82 | REST_OBJ.logout() 83 | 84 | 85 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/get_EncryptionSettings.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def get_EncryptionSettings(restobj): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "Collection.1.0.0" in instance.Type: 25 | if "HpSmartStorageArrayController." in instance.MemberType: 26 | array_controllers = instance.href 27 | break 28 | 29 | types = ["Name", "Model", "SerialNumber", "EncryptionBootPasswordSet",\ 30 | "EncryptionCryptoOfficerPasswordSet",\ 31 | "EncryptionLocalKeyCacheEnabled", "EncryptionMixedVolumesEnabled",\ 32 | "EncryptionPhysicalDriveCount", "EncryptionRecoveryParamsSet",\ 33 | "EncryptionStandaloneModeEnabled", "EncryptionUserPasswordSet"] 34 | 35 | collection = restobj.get(array_controllers) 36 | for instance in collection.obj.links.Member: 37 | response = restobj.get(instance.href) 38 | 39 | for item in types: 40 | sys.stdout.write("\tID: " + str(response.dict["@odata.id"]) + "\n") 41 | if item in response.dict: 42 | sys.stdout.write("\t" + item + ": " + str(response.dict[item]) + "\n") 43 | else: 44 | sys.stderr.write("\t" + item + "is not " \ 45 | "available on HpSmartStorageArrayController resource\n") 46 | sys.stdout.write("%s" % response) 47 | if __name__ == "__main__": 48 | # When running on the server locally use the following commented values 49 | # SYSTEM_URL = None 50 | # LOGIN_ACCOUNT = None 51 | # LOGIN_PASSWORD = None 52 | 53 | # When running remotely connect using the iLO secured (https://) address, 54 | # iLO account name, and password to send https requests 55 | # SYSTEM_URL acceptable examples: 56 | # "https://10.0.0.100" 57 | # "https://ilo.hostname" 58 | SYSTEM_URL = "https://10.0.0.100" 59 | LOGIN_ACCOUNT = "admin" 60 | LOGIN_PASSWORD = "password" 61 | 62 | # Create a REST object 63 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 64 | REST_OBJ.login() 65 | sys.stdout.write("\nEXAMPLE 43: Dump EncryptionSettings\n") 66 | get_EncryptionSettings(REST_OBJ) 67 | REST_OBJ.logout() 68 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/get_LogicalDrives.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 | import json 17 | from redfish import LegacyRestClient 18 | from get_resource_directory import get_resource_directory 19 | 20 | def get_LogicalDrives(restobj): 21 | resource_instances = get_resource_directory(restobj) 22 | if resource_instances: 23 | #Get URI from resource directory 24 | for instance in resource_instances: 25 | if "Collection.1.0.0" in instance.Type: 26 | if "HpSmartStorageArrayController." in instance.MemberType: 27 | array_controllers = instance.href 28 | break 29 | collection = restobj.get(array_controllers) 30 | for instance in collection.obj.links.Member: 31 | controller = restobj.get(instance.href) 32 | sys.stdout.write("Location: %s\n" % controller.obj.Location) 33 | logicaldrivecollection = restobj.get(controller.obj.links.LogicalDrives.href) 34 | for logicaldrive in logicaldrivecollection.obj.links.Member: 35 | drive = restobj.get(logicaldrive.href) 36 | sys.stdout.write("\t%s\n" % json.dumps(drive.dict)) 37 | 38 | if __name__ == "__main__": 39 | # When running on the server locally use the following commented values 40 | # SYSTEM_URL = None 41 | # LOGIN_ACCOUNT = None 42 | # LOGIN_PASSWORD = None 43 | 44 | # When running remotely connect using the iLO secured (https://) address, 45 | # iLO account name, and password to send https requests 46 | # SYSTEM_URL acceptable examples: 47 | # "https://10.0.0.100" 48 | # "https://ilo.hostname" 49 | SYSTEM_URL = "https://10.0.0.100" 50 | LOGIN_ACCOUNT = "admin" 51 | LOGIN_PASSWORD = "password" 52 | 53 | # Create a REST object 54 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 55 | sys.stdout.write("\nEXAMPLE 44: Dump LogicalDrive details\n") 56 | REST_OBJ.login() 57 | get_LogicalDrives(REST_OBJ) 58 | REST_OBJ.logout() 59 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/get_ahs_data.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def get_ahs_data(restobj): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "HpiLOActiveHealthSystem." in instance.Type: 25 | AHS_path = instance.href 26 | break 27 | sys.stdout.write("Fetching AHS Data, this may take minutes to hours\n") 28 | response = restobj.get(AHS_path) 29 | ahslink = restobj.get(response.dict["links"]["AHSLocation"]["extref"]) 30 | 31 | with open("data.ahs", 'wb') as ahsoutput: 32 | ahsoutput.write(ahslink.ori) 33 | ahsoutput.close() 34 | sys.stdout.write("AHS Data saved successfully as data.ahs\n") 35 | 36 | if __name__ == "__main__": 37 | # When running on the server locally use the following commented values 38 | # SYSTEM_URL = None 39 | # LOGIN_ACCOUNT = None 40 | # LOGIN_PASSWORD = None 41 | 42 | # When running remotely connect using the iLO secured (https://) address, 43 | # iLO account name, and password to send https requests 44 | # SYSTEM_URL acceptable examples: 45 | # "https://10.0.0.100" 46 | # "https://ilo.hostname" 47 | SYSTEM_URL = "https://10.0.0.100" 48 | LOGIN_ACCOUNT = "admin" 49 | LOGIN_PASSWORD = "password" 50 | 51 | #Create a REST object 52 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 53 | REST_OBJ.login() 54 | sys.stdout.write("\nEXAMPLE 46: Get AHS Data\n") 55 | get_ahs_data(REST_OBJ) 56 | REST_OBJ.logout() 57 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/get_base_registry.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def get_base_registry(restobj): 20 | response = restobj.get("/rest/v1/Registries") 21 | messages = {} 22 | 23 | identifier = None 24 | 25 | for entry in response.dict["Items"]: 26 | if "Id" in entry: 27 | identifier = entry["Id"] 28 | else: 29 | identifier = entry["Schema"].split(".")[0] 30 | 31 | if identifier not in ["Base", "iLO"]: 32 | continue 33 | 34 | for location in entry["Location"]: 35 | reg_resp = restobj.get(location["Uri"]["extref"]) 36 | 37 | if reg_resp.status == 200: 38 | sys.stdout.write("\tFound " + identifier + " at " + \ 39 | location["Uri"]["extref"] + "\n") 40 | messages[identifier] = reg_resp.dict["Messages"] 41 | else: 42 | sys.stdout.write("\t" + identifier + " not found at "\ 43 | + location["Uri"]["extref"] + "\n") 44 | 45 | return messages 46 | 47 | if __name__ == "__main__": 48 | # When running on the server locally use the following commented values 49 | # SYSTEM_URL = None 50 | # LOGIN_ACCOUNT = None 51 | # LOGIN_PASSWORD = None 52 | 53 | # When running remotely connect using the iLO secured (https://) address, 54 | # iLO account name, and password to send https requests 55 | # SYSTEM_URL acceptable examples: 56 | # "https://10.0.0.100" 57 | # "https://ilo.hostname" 58 | SYSTEM_URL = "https://10.0.0.100" 59 | LOGIN_ACCOUNT = "admin" 60 | LOGIN_PASSWORD = "password" 61 | 62 | #Create a REST object 63 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 64 | REST_OBJ.login() 65 | sys.stdout.write("\nEXAMPLE 2: Find and return registry " + "\n") 66 | get_base_registry(REST_OBJ) 67 | REST_OBJ.logout() 68 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/get_csr.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def get_csr(restobj, filename): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "HpHttpsCert." in instance.Type: 25 | https_path = instance.href 26 | break 27 | 28 | response = restobj.get(https_path) 29 | try: 30 | csr_response = response.dict["CertificateSigningRequest"] 31 | with open(filename, 'wb') as csroutput: 32 | csroutput.write(csr_response) 33 | csroutput.close() 34 | 35 | sys.stdout.write("\tCSR Data saved successfully as "+ filename + "\n") 36 | except KeyError: 37 | sys.stdout.write("\tCSR cannot be accessed right now, please try again later") 38 | 39 | if __name__ == "__main__": 40 | # When running on the server locally use the following commented values 41 | # SYSTEM_URL = None 42 | # LOGIN_ACCOUNT = None 43 | # LOGIN_PASSWORD = None 44 | 45 | # When running remotely connect using the iLO secured (https://) address, 46 | # iLO account name, and password to send https requests 47 | # SYSTEM_URL acceptable examples: 48 | # "https://10.0.0.100" 49 | # "https://ilo.hostname" 50 | SYSTEM_URL = "https://10.0.0.100" 51 | LOGIN_ACCOUNT = "admin" 52 | LOGIN_PASSWORD = "password" 53 | 54 | #Create a REST object 55 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 56 | REST_OBJ.login() 57 | sys.stdout.write("\nEXAMPLE 50: Get CSR\n") 58 | get_csr(REST_OBJ, "csr.txt") 59 | REST_OBJ.logout() 60 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/get_ilo_ip.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def get_ilo_ip(restobj): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "Manager." in instance.Type: 25 | manager_path = instance.href 26 | break 27 | 28 | response = restobj.get(manager_path) 29 | ethernet_rsp = restobj.get(response.dict["links"]["EthernetNICs"]["href"]) 30 | for item in ethernet_rsp.dict["Items"]: 31 | if not item["IPv4Addresses"][0]["Address"] == "0.0.0.0": 32 | sys.stdout.write("\t" + item["IPv4Addresses"][0]["Address"] + "\n") 33 | sys.stdout.write("%s" % response) 34 | 35 | if __name__ == "__main__": 36 | # When running on the server locally use the following commented values 37 | # While this example can be run remotely, it is used locally to locate the 38 | # iLO IP address 39 | SYSTEM_URL = None 40 | LOGIN_ACCOUNT = None 41 | LOGIN_PASSWORD = None 42 | 43 | # When running remotely connect using the iLO secured (https://) address, 44 | # iLO account name, and password to send https requests 45 | # SYSTEM_URL acceptable examples: 46 | # "https://10.0.0.100" 47 | # "https://ilo.hostname" 48 | # SYSTEM_URL = "https://10.0.0.100" 49 | # LOGIN_ACCOUNT = "admin" 50 | # LOGIN_PASSWORD = "password" 51 | 52 | #Create a REST object 53 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 54 | REST_OBJ.login() 55 | sys.stdout.write("\nEXAMPLE 52: Get iLO IP locally\n") 56 | get_ilo_ip(REST_OBJ) 57 | REST_OBJ.logout() 58 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/get_ilo_nic.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 | import json 17 | from redfish import LegacyRestClient 18 | from get_resource_directory import get_resource_directory 19 | 20 | def get_ilo_nic(restobj, get_active): 21 | resource_instances = get_resource_directory(restobj) 22 | if resource_instances: 23 | #Get URI from resource directory 24 | for instance in resource_instances: 25 | if "Manager." in instance.Type: 26 | manager_path = instance.href 27 | break 28 | 29 | tmp = restobj.get(manager_path) 30 | response = restobj.get(tmp.dict["links"]["EthernetNICs"]["href"]) 31 | 32 | for nic in response.dict["Items"]: 33 | if get_active and nic["Status"]["State"] == "Enabled": 34 | sys.stdout.write("Active\t" + nic["links"]["self"]["href"] + \ 35 | ": " + json.dumps(nic) + "\n") 36 | elif get_active == False and nic["Status"]["State"] == "Disabled": 37 | sys.stdout.write("InActive\t" + nic["links"]["self"]["href"] + \ 38 | ": " + json.dumps(nic) + "\n") 39 | 40 | if __name__ == "__main__": 41 | # When running on the server locally use the following commented values 42 | # SYSTEM_URL = None 43 | # LOGIN_ACCOUNT = None 44 | # LOGIN_PASSWORD = None 45 | 46 | # When running remotely connect using the iLO secured (https://) address, 47 | # iLO account name, and password to send https requests 48 | # SYSTEM_URL acceptable examples: 49 | # "https://10.0.0.100" 50 | # "https://ilo.hostname" 51 | SYSTEM_URL = "https://10.0.0.100" 52 | LOGIN_ACCOUNT = "admin" 53 | LOGIN_PASSWORD = "password" 54 | 55 | #Create a REST object 56 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 57 | REST_OBJ.login() 58 | sys.stdout.write("\nEXAMPLE 20: Get iLO's NIC configuration\n") 59 | get_ilo_nic(REST_OBJ, True) 60 | REST_OBJ.logout() 61 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/get_license_key.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def get_license_key(restobj): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "HpiLOLicense." in instance.Type: 25 | manager_path = instance.href 26 | break 27 | license_result = dict() 28 | licenseproperties = ["License", "LicenseKey", "LicenseType"] 29 | 30 | response = restobj.get(instance["href"]) 31 | license_result["License"] = response.dict["License"] 32 | 33 | for licenseproperty in licenseproperties: 34 | sys.stdout.write("\t" + licenseproperty + ": " + \ 35 | str(response.dict[licenseproperty]) + "\n") 36 | sys.stdout.write("%s" % response) 37 | return (license_result) 38 | 39 | if __name__ == "__main__": 40 | # When running on the server locally use the following commented values 41 | # SYSTEM_URL = None 42 | # LOGIN_ACCOUNT = None 43 | # LOGIN_PASSWORD = None 44 | 45 | # When running remotely connect using the iLO secured (https://) address, 46 | # iLO account name, and password to send https requests 47 | # SYSTEM_URL acceptable examples: 48 | # "https://10.0.0.100" 49 | # "https://ilo.hostname" 50 | SYSTEM_URL = "https://10.0.0.100" 51 | LOGIN_ACCOUNT = "admin" 52 | LOGIN_PASSWORD = "password" 53 | 54 | # Create a REST object 55 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 56 | REST_OBJ.login() 57 | sys.stdout.write("\nEXAMPLE 45: Get iLO License Key\n") 58 | get_license_key(REST_OBJ) 59 | REST_OBJ.logout() 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/get_powermetrics_average.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def get_powermetrics_average(restobj): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "PowerMetrics." in instance.Type: 25 | power_path = instance.href 26 | break 27 | 28 | response = restobj.get(power_path) 29 | 30 | if "PowerMetrics" not in response.dict or \ 31 | "AverageConsumedWatts" not in response.dict["PowerMetrics"] or \ 32 | "IntervalInMin" not in response.dict["PowerMetrics"]: 33 | sys.stdout.write("\tPowerMetrics resource does not contain "\ 34 | "'AverageConsumedWatts' or 'IntervalInMin' property\n") 35 | else: 36 | sys.stdout.write("\t" + " AverageConsumedWatts = " + \ 37 | str(response.dict["PowerMetrics"]["AverageConsumedWatts"]) + \ 38 | " watts over a " + str(response.dict["PowerMetrics"]\ 39 | ["IntervalInMin"]) + " minute moving average\n") 40 | 41 | if __name__ == "__main__": 42 | # When running on the server locally use the following commented values 43 | # SYSTEM_URL = None 44 | # LOGIN_ACCOUNT = None 45 | # LOGIN_PASSWORD = None 46 | 47 | # When running remotely connect using the iLO secured (https://) address, 48 | # iLO account name, and password to send https requests 49 | # SYSTEM_URL acceptable examples: 50 | # "https://10.0.0.100" 51 | # "https://ilo.hostname" 52 | SYSTEM_URL = "https://10.0.0.100" 53 | LOGIN_ACCOUNT = "admin" 54 | LOGIN_PASSWORD = "password" 55 | 56 | #Create a REST object 57 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 58 | REST_OBJ.login() 59 | sys.stdout.write("\nEXAMPLE 30: Report PowerMetrics Average Watts\n") 60 | get_powermetrics_average(REST_OBJ) 61 | REST_OBJ.logout() 62 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/get_resource_directory.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | 18 | def get_resource_directory(restobj): 19 | response = restobj.get("/rest/v1/resourcedirectory") 20 | resources = [] 21 | 22 | if response.status == 200: 23 | resources = response.obj.Instances 24 | else: 25 | sys.stderr.write("\tResource directory missing at /rest/v1/resourcedirectory" + "\n") 26 | return resources 27 | 28 | if __name__ == "__main__": 29 | # When running on the server locally use the following commented values 30 | # SYSTEM_URL = None 31 | # LOGIN_ACCOUNT = None 32 | # LOGIN_PASSWORD = None 33 | 34 | # When running remotely connect using the iLO secured (https://) address, 35 | # iLO account name, and password to send https requests 36 | # SYSTEM_URL acceptable examples: 37 | # "https://10.0.0.100" 38 | # "https://ilo.hostname" 39 | SYSTEM_URL = "https://10.0.0.100" 40 | LOGIN_ACCOUNT = "admin" 41 | LOGIN_PASSWORD = "password" 42 | 43 | #Create a REST object 44 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 45 | REST_OBJ.login() 46 | sys.stdout.write("\nEXAMPLE 1: Find the resource directory " + "\n") 47 | resources = get_resource_directory(REST_OBJ) 48 | 49 | for resource in resources: 50 | try: 51 | sys.stdout.write("\t" + str(resource["@odata.type"]) + \ 52 | "\n\t\t" + str(resource["@odata.id"]) + "\n") 53 | except KeyError: 54 | pass 55 | 56 | REST_OBJ.logout() 57 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/get_schema.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def get_schema(restobj, schema_prefix): 20 | sys.stdout.write("\nEXAMPLE 27: Find and return schema " + \ 21 | schema_prefix + "\n") 22 | response = restobj.get("/rest/v1/Schemas") 23 | 24 | for schema in response.dict["Items"]: 25 | if schema["Schema"].startswith(schema_prefix): 26 | for location in schema["Location"]: 27 | extref_uri = location["Uri"]["extref"] 28 | response = restobj.get(extref_uri) 29 | if response.status == 200: 30 | sys.stdout.write("\tFound " + schema_prefix + " at " + extref_uri + "\n") 31 | return 32 | else: 33 | sys.stderr.write("\t" + schema_prefix + " not found at " + extref_uri + "\n") 34 | return 35 | 36 | sys.stderr.write("Registry " + schema_prefix + " not found.\n") 37 | 38 | if __name__ == "__main__": 39 | # When running on the server locally use the following commented values 40 | # SYSTEM_URL = None 41 | # LOGIN_ACCOUNT = None 42 | # LOGIN_PASSWORD = None 43 | 44 | # When running remotely connect using the iLO secured (https://) address, 45 | # iLO account name, and password to send https requests 46 | # SYSTEM_URL acceptable examples: 47 | # "https://10.0.0.100" 48 | # "https://ilo.hostname" 49 | SYSTEM_URL = "https://10.0.0.100" 50 | LOGIN_ACCOUNT = "admin" 51 | LOGIN_PASSWORD = "password" 52 | 53 | #Create a REST object 54 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 55 | REST_OBJ.login() 56 | get_schema(REST_OBJ, "ComputerSystem") 57 | REST_OBJ.logout() 58 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/import_ssl.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def import_ssl(restobj, filename): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "HpHttpsCert." in instance.Type: 25 | https_path = instance.href 26 | break 27 | 28 | with open(filename, 'r') as csr_data: 29 | ssl_cert = csr_data.read() 30 | csr_data.close() 31 | 32 | body = dict() 33 | body["Action"] = "ImportCertificate" 34 | body["Certificate"] = ssl_cert 35 | response = restobj.post(https_path, body) 36 | sys.stdout.write("%s" % response) 37 | 38 | if __name__ == "__main__": 39 | # When running on the server locally use the following commented values 40 | # SYSTEM_URL = None 41 | # LOGIN_ACCOUNT = None 42 | # LOGIN_PASSWORD = None 43 | 44 | # When running remotely connect using the iLO secured (https://) address, 45 | # iLO account name, and password to send https requests 46 | # SYSTEM_URL acceptable examples: 47 | # "https://10.0.0.100" 48 | # "https://ilo.hostname" 49 | SYSTEM_URL = "https://10.0.0.100" 50 | LOGIN_ACCOUNT = "admin" 51 | LOGIN_PASSWORD = "password" 52 | 53 | #Create a REST object 54 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 55 | REST_OBJ.login() 56 | sys.stdout.write("\nEXAMPLE 51: Import SSL Certificate\n") 57 | import_ssl(REST_OBJ, "ssl.txt") 58 | REST_OBJ.logout() 59 | 60 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/modify_ilo_user_account.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def modify_ilo_user_account(restobj, ilo_login_name_to_modify, \ 20 | new_ilo_loginname, new_ilo_username, new_ilo_password, \ 21 | irc=None, cfg=None, virtual_media=None, usercfg=None, vpr=None): 22 | resource_instances = get_resource_directory(restobj) 23 | if resource_instances: 24 | #Get URI from resource directory 25 | for instance in resource_instances: 26 | if "Collection." in instance.Type: 27 | if "ManagerAccount." in instance.MemberType: 28 | accounts_path = instance.href 29 | break 30 | accounts = restobj.get(accounts_path) 31 | for account in accounts.obj.Items: 32 | for account in accounts.dict["Items"]: 33 | if account["UserName"] == ilo_login_name_to_modify: 34 | body = {} 35 | body_oemhp = {} 36 | body_oemhp_privs = {} 37 | 38 | # if new loginname or password specified 39 | if new_ilo_password: 40 | body["Password"] = new_ilo_password 41 | if new_ilo_loginname: 42 | body["UserName"] = new_ilo_loginname 43 | 44 | # if different username specified 45 | if new_ilo_username: 46 | body_oemhp["LoginName"] = new_ilo_username 47 | 48 | # if different privileges were requested (None = no change) 49 | if irc != None: 50 | body_oemhp_privs["RemoteConsolePriv"] = irc 51 | if virtual_media != None: 52 | body_oemhp_privs["VirtualMediaPriv"] = virtual_media 53 | if cfg != None: 54 | body_oemhp_privs["iLOConfigPriv"] = cfg 55 | if usercfg != None: 56 | body_oemhp_privs["UserConfigPriv"] = usercfg 57 | if vpr != None: 58 | body_oemhp_privs["VirtualPowerAndResetPriv"] = vpr 59 | 60 | # component assembly 61 | if len(body_oemhp_privs): 62 | body_oemhp["Privileges"] = body_oemhp_privs 63 | if len(body_oemhp): 64 | body["Oem"] = {"Hp": body_oemhp} 65 | 66 | newrsp = restobj.patch(account["links"]["self"]["href"], body) 67 | sys.stdout.write("%s" % newrsp) 68 | return 69 | 70 | sys.stderr.write("Account not found\n") 71 | 72 | if __name__ == "__main__": 73 | # When running on the server locally use the following commented values 74 | # SYSTEM_URL = None 75 | # LOGIN_ACCOUNT = None 76 | # LOGIN_PASSWORD = None 77 | 78 | # When running remotely connect using the iLO secured (https://) address, 79 | # iLO account name, and password to send https requests 80 | # SYSTEM_URL acceptable examples: 81 | # "https://10.0.0.100" 82 | # "https://ilo.hostname" 83 | SYSTEM_URL = "https://10.0.0.100" 84 | LOGIN_ACCOUNT = "admin" 85 | LOGIN_PASSWORD = "password" 86 | 87 | #Create a REST object 88 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 89 | REST_OBJ.login() 90 | sys.stdout.write("\nEXAMPLE 11: Modify an iLO user account\n") 91 | modify_ilo_user_account(REST_OBJ, "name", "newname", "newusername", "newpassword") 92 | REST_OBJ.logout() 93 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/mount_virtual_media_iso.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def mount_virtual_media_iso(restobj, iso_url, boot_on_next_server_reset): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "Manager." in instance.Type: 25 | manager_path = instance.href 26 | break 27 | 28 | rsp = restobj.get(manager_path) 29 | rsp = restobj.get(rsp.dict["links"]["VirtualMedia"]["href"]) 30 | 31 | for vmlink in rsp.dict["links"]["Member"]: 32 | response = restobj.get(vmlink["href"]) 33 | 34 | if response.status == 200 and "DVD" in response.dict["MediaTypes"]: 35 | body = {"Image": iso_url} 36 | 37 | if (iso_url is not None and boot_on_next_server_reset is not None): 38 | body["Oem"] = {"Hp": {"BootOnNextServerReset": boot_on_next_server_reset}} 39 | 40 | response = restobj.patch(vmlink["href"], body) 41 | sys.stdout.write("%s" % response) 42 | 43 | if __name__ == "__main__": 44 | # When running on the server locally use the following commented values 45 | # SYSTEM_URL = None 46 | # LOGIN_ACCOUNT = None 47 | # LOGIN_PASSWORD = None 48 | 49 | # When running remotely connect using the iLO secured (https://) address, 50 | # iLO account name, and password to send https requests 51 | # SYSTEM_URL acceptable examples: 52 | # "https://10.0.0.100" 53 | # "https://ilo.hostname" 54 | SYSTEM_URL = "https://10.0.0.100" 55 | LOGIN_ACCOUNT = "admin" 56 | LOGIN_PASSWORD = "password" 57 | 58 | #Create a REST object 59 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 60 | REST_OBJ.login() 61 | sys.stdout.write("\nEXAMPLE 17: Mount iLO Virtual Media DVD ISO from URL\n") 62 | mount_virtual_media_iso(REST_OBJ, "http://10.0.0.100/test.iso", True) 63 | REST_OBJ.logout() 64 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/remove_ilo_account.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def remove_ilo_account(restobj, ilo_loginname_to_remove): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "Collection." in instance.Type: 25 | if "ManagerAccount." in instance.MemberType: 26 | accounts_path = instance.href 27 | break 28 | accounts = restobj.get(accounts_path) 29 | 30 | for account in accounts.dict["Items"]: 31 | if account["UserName"] == ilo_loginname_to_remove: 32 | newrsp = restobj.delete(account["links"]["self"]["href"]) 33 | sys.stdout.write("%s" % newrsp) 34 | return 35 | 36 | sys.stderr.write("Account not found\n") 37 | 38 | if __name__ == "__main__": 39 | # When running on the server locally use the following commented values 40 | # SYSTEM_URL = None 41 | # LOGIN_ACCOUNT = None 42 | # LOGIN_PASSWORD = None 43 | 44 | # When running remotely connect using the iLO secured (https://) address, 45 | # iLO account name, and password to send https requests 46 | # SYSTEM_URL acceptable examples: 47 | # "https://10.0.0.100" 48 | # "https://ilo.hostname" 49 | SYSTEM_URL = "https://10.0.0.100" 50 | LOGIN_ACCOUNT = "admin" 51 | LOGIN_PASSWORD = "password" 52 | 53 | #Create a REST object 54 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 55 | REST_OBJ.login() 56 | sys.stdout.write("\nEXAMPLE 12: Remove an iLO account\n") 57 | remove_ilo_account(REST_OBJ, "newname") 58 | REST_OBJ.logout() 59 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/reset_ESKM_eventlog.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def reset_ESKM_eventlog(restobj): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "HpESKM." in instance.Type: 25 | eskm_path = instance.href 26 | break 27 | 28 | body = dict() 29 | body["Action"] = "ClearESKMLog" 30 | 31 | response = restobj.post(eskm_path, body) 32 | sys.stdout.write("%s" % response) 33 | 34 | if __name__ == "__main__": 35 | # When running on the server locally use the following commented values 36 | # SYSTEM_URL = None 37 | # LOGIN_ACCOUNT = None 38 | # LOGIN_PASSWORD = None 39 | 40 | # When running remotely connect using the iLO secured (https://) address, 41 | # iLO account name, and password to send https requests 42 | # SYSTEM_URL acceptable examples: 43 | # "https://10.0.0.100" 44 | # "https://ilo.hostname" 45 | SYSTEM_URL = "https://10.0.0.100" 46 | LOGIN_ACCOUNT = "admin" 47 | LOGIN_PASSWORD = "password" 48 | 49 | # Create a REST object 50 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 51 | REST_OBJ.login() 52 | sys.stdout.write("\nEXAMPLE 40: Reset ESKM event logs\n") 53 | reset_ESKM_eventlog(REST_OBJ) 54 | REST_OBJ.logout() 55 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/reset_ilo.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def reset_ilo(restobj): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "Manager." in instance.Type: 25 | manager_path = instance.href 26 | break 27 | 28 | body = {"Action": "Reset"} 29 | response = restobj.post(manager_path, body) 30 | sys.stdout.write("%s" % response) 31 | 32 | if __name__ == "__main__": 33 | # When running on the server locally use the following commented values 34 | # SYSTEM_URL = None 35 | # LOGIN_ACCOUNT = None 36 | # LOGIN_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 | # SYSTEM_URL acceptable examples: 41 | # "https://10.0.0.100" 42 | # "https://ilo.hostname" 43 | SYSTEM_URL = "https://10.0.0.100" 44 | LOGIN_ACCOUNT = "admin" 45 | LOGIN_PASSWORD = "password" 46 | 47 | #Create a REST object 48 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 49 | REST_OBJ.login() 50 | sys.stdout.write("\nEXAMPLE 19: Reset iLO\n") 51 | reset_ilo(REST_OBJ) 52 | REST_OBJ.logout() 53 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/reset_server.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def reset_server(restobj): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "ComputerSystem." in instance.Type: 25 | system_path = instance.href 26 | break 27 | 28 | body = dict() 29 | body["Action"] = "Reset" 30 | body["ResetType"] = "ForceRestart" 31 | 32 | response = restobj.post(system_path, body) 33 | sys.stdout.write("%s" % response) 34 | 35 | if __name__ == "__main__": 36 | # When running on the server locally use the following commented values 37 | # SYSTEM_URL = None 38 | # LOGIN_ACCOUNT = None 39 | # LOGIN_PASSWORD = None 40 | 41 | # When running remotely connect using the iLO secured (https://) address, 42 | # iLO account name, and password to send https requests 43 | # SYSTEM_URL acceptable examples: 44 | # "https://10.0.0.100" 45 | # "https://ilo.hostname" 46 | SYSTEM_URL = "https://10.0.0.100" 47 | LOGIN_ACCOUNT = "admin" 48 | LOGIN_PASSWORD = "password" 49 | 50 | #Create a REST object 51 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 52 | REST_OBJ.login() 53 | sys.stdout.write("\nExample 4: Reset a server\n") 54 | reset_server(REST_OBJ) 55 | REST_OBJ.logout() 56 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/sessions.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 urllib3.util import parse_url 17 | from redfish import LegacyRestClient 18 | from get_resource_directory import get_resource_directory 19 | 20 | def sessions(restobj, login_account, login_password): 21 | new_session = {"UserName": login_account, "Password": login_password} 22 | response = restobj.post("/rest/v1/Sessions", new_session) 23 | sys.stdout.write("%s" % response) 24 | 25 | if response.status == 201: 26 | session_uri = response.getheader("location") 27 | session_uri = parse_url(session_uri) 28 | sys.stdout.write("\tSession " + session_uri.path + " created\n") 29 | 30 | x_auth_token = response.getheader("x-auth-token") 31 | sys.stdout.write("\tSession key " + x_auth_token + " created\n") 32 | 33 | # Delete the created session 34 | sessresp = restobj.delete(session_uri.path) 35 | sys.stdout.write("%s" % response) 36 | else: 37 | sys.stderr.write("ERROR: failed to create a session.\n") 38 | 39 | if __name__ == "__main__": 40 | # When running on the server locally use the following commented values 41 | # SYSTEM_URL = None 42 | # LOGIN_ACCOUNT = None 43 | # LOGIN_PASSWORD = None 44 | 45 | # When running remotely connect using the iLO secured (https://) address, 46 | # iLO account name, and password to send https requests 47 | # SYSTEM_URL acceptable examples: 48 | # "https://10.0.0.100" 49 | # "https://ilo.hostname" 50 | SYSTEM_URL = "https://10.0.0.100" 51 | LOGIN_ACCOUNT = "admin" 52 | LOGIN_PASSWORD = "password" 53 | 54 | #Create a REST object 55 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 56 | sys.stdout.write("\nEXAMPLE 14: Create/Use/Delete a user session\n") 57 | sessions(REST_OBJ, "admin", "admin123") 58 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/set_ESKM_PrimaryKeyServer.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def set_ESKM_PrimaryKeyServer(restobj, PrimaryKeyServerAddress, PrimaryKeyServerPort): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "HpESKM." in instance.Type: 25 | eskm_path = instance.href 26 | break 27 | 28 | body = dict() 29 | 30 | body["PrimaryKeyServerAddress"] = PrimaryKeyServerAddress 31 | body["PrimaryKeyServerPort"] = int(PrimaryKeyServerPort) 32 | 33 | response = restobj.patch(eskm_path, body) 34 | sys.stdout.write("%s" % response) 35 | 36 | if __name__ == "__main__": 37 | # When running on the server locally use the following commented values 38 | # SYSTEM_URL = None 39 | # LOGIN_ACCOUNT = None 40 | # LOGIN_PASSWORD = None 41 | 42 | # When running remotely connect using the iLO secured (https://) address, 43 | # iLO account name, and password to send https requests 44 | # SYSTEM_URL acceptable examples: 45 | # "https://10.0.0.100" 46 | # "https://ilo.hostname" 47 | SYSTEM_URL = "https://10.0.0.100" 48 | LOGIN_ACCOUNT = "admin" 49 | LOGIN_PASSWORD = "password" 50 | PrimaryKeyServerAddress = "10.0.0.100" 51 | PrimaryKeyServerPort = "9000" 52 | 53 | # Create a REST object 54 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 55 | REST_OBJ.login() 56 | sys.stdout.write("\nEXAMPLE 37: Set ESKM Primary Key Server\n") 57 | set_ESKM_PrimaryKeyServer(REST_OBJ, PrimaryKeyServerAddress, PrimaryKeyServerPort) 58 | REST_OBJ.logout() 59 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/set_ESKM_username_password.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def set_ESKM_username_password(restobj, username, password, accountgroup): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "HpESKM." in instance.Type: 25 | eskm_path = instance.href 26 | break 27 | 28 | body = dict() 29 | 30 | body["KeyManagerConfig"] = dict() 31 | body["KeyManagerConfig"]["LoginName"] = username 32 | body["KeyManagerConfig"]["Password"] = password 33 | body["KeyManagerConfig"]["AccountGroup"] = accountgroup 34 | body["KeyManagerConfig"]["ESKMLocalCACertificateName"] = "" 35 | 36 | response = restobj.patch(eskm_path, body) 37 | sys.stdout.write("%s" % response) 38 | 39 | if __name__ == "__main__": 40 | # When running on the server locally use the following commented values 41 | # SYSTEM_URL = None 42 | # LOGIN_ACCOUNT = None 43 | # LOGIN_PASSWORD = None 44 | 45 | # When running remotely connect using the iLO secured (https://) address, 46 | # iLO account name, and password to send https requests 47 | # SYSTEM_URL acceptable examples: 48 | # "https://10.0.0.100" 49 | # "https://ilo.hostname" 50 | SYSTEM_URL = "https://10.0.0.100" 51 | LOGIN_ACCOUNT = "admin" 52 | LOGIN_PASSWORD = "password" 53 | eskm_username = "admin" 54 | eskm_password = "password" 55 | eskm_accountgroup = "group" 56 | 57 | # Create a REST object 58 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 59 | REST_OBJ.login() 60 | sys.stdout.write("\nEXAMPLE 38: Set ESKM username, password\n") 61 | set_ESKM_username_password(REST_OBJ, eskm_username, eskm_password, eskm_accountgroup) 62 | REST_OBJ.logout() 63 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/set_Ilo_ntp_servers.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 | import json 17 | from redfish import LegacyRestClient 18 | from get_resource_directory import get_resource_directory 19 | 20 | def set_ilo_ntp_servers(restobj, ntp_servers): 21 | resource_instances = get_resource_directory(restobj) 22 | if resource_instances: 23 | #Get URI from resource directory 24 | for instance in resource_instances: 25 | if "HpiLODateTime." in instance.Type: 26 | datetime_path = instance.href 27 | break 28 | 29 | response = restobj.get(datetime_path) 30 | 31 | sys.stdout.write("\tCurrent iLO Date/Time Settings: " + 32 | json.dumps(response.dict["ConfigurationSettings"]) + "\n") 33 | sys.stdout.write("\tCurrent iLO NTP Servers: " + 34 | json.dumps(response.dict["NTPServers"]) + "\n") 35 | 36 | body = {"StaticNTPServers": ntp_servers} 37 | response = restobj.patch(datetime_path, body) 38 | sys.stdout.write("%s" % response) 39 | 40 | if __name__ == "__main__": 41 | # When running on the server locally use the following commented values 42 | # SYSTEM_URL = None 43 | # LOGIN_ACCOUNT = None 44 | # LOGIN_PASSWORD = None 45 | 46 | # When running remotely connect using the iLO secured (https://) address, 47 | # iLO account name, and password to send https requests 48 | # SYSTEM_URL acceptable examples: 49 | # "https://10.0.0.100" 50 | # "https://ilo.hostname" 51 | SYSTEM_URL = "https://10.0.0.100" 52 | LOGIN_ACCOUNT = "admin" 53 | LOGIN_PASSWORD = "password" 54 | 55 | #Create a REST object 56 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 57 | REST_OBJ.login() 58 | sys.stdout.write("\nEXAMPLE 29: Set iLO's NTP Servers\n") 59 | set_ilo_ntp_servers(REST_OBJ, ["192.168.0.1", "192.168.0.2"]) 60 | REST_OBJ.logout() 61 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/set_active_ilo_nic.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def set_active_ilo_nic(restobj, shared_nic): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "Manager." in instance.Type: 25 | manager_path = instance.href 26 | break 27 | selected_nic_uri = None 28 | 29 | tmp = restobj.get(instance["href"]) 30 | response = restobj.get(tmp.dict["links"]["EthernetNICs"]["href"]) 31 | 32 | for nic in response.dict["Items"]: 33 | try: 34 | if (nic["Oem"]["Hp"]["SupportsFlexibleLOM"] == True and shared_nic == True): 35 | selected_nic_uri = nic["links"]["self"]["href"] 36 | break 37 | except KeyError: 38 | pass 39 | 40 | try: 41 | if (nic["Oem"]["Hp"]["SupportsLOM"] == True and shared_nic == True): 42 | selected_nic_uri = nic["links"]["self"]["href"] 43 | break 44 | except KeyError: 45 | pass 46 | 47 | if not shared_nic: 48 | selected_nic_uri = nic["links"]["self"]["href"] 49 | break 50 | elif not selected_nic_uri: 51 | sys.stderr.write("\tShared NIC is not supported\n") 52 | break 53 | 54 | if selected_nic_uri: 55 | body = {"Oem": {"Hp": {"NICEnabled": True}}} 56 | response = restobj.patch(selected_nic_uri, body) 57 | sys.stdout.write("%s" % response) 58 | 59 | if __name__ == "__main__": 60 | # When running on the server locally use the following commented values 61 | # SYSTEM_URL = None 62 | # LOGIN_ACCOUNT = None 63 | # LOGIN_PASSWORD = None 64 | 65 | # When running remotely connect using the iLO secured (https://) address, 66 | # iLO account name, and password to send https requests 67 | # SYSTEM_URL acceptable examples: 68 | # "https://10.0.0.100" 69 | # "https://ilo.hostname" 70 | SYSTEM_URL = "https://10.0.0.100" 71 | LOGIN_ACCOUNT = "admin" 72 | LOGIN_PASSWORD = "password" 73 | 74 | #Create a REST object 75 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 76 | REST_OBJ.login() 77 | sys.stdout.write("\nEXAMPLE 21: Set the active iLO NIC\n") 78 | set_active_ilo_nic(REST_OBJ, False) 79 | REST_OBJ.logout() 80 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/set_bios_dhcp.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def set_bios_dhcp(restobj, bios_properties, bios_password=None): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "HpBios." in instance.Type: 25 | if "PUT" in instance.HttpMethods: 26 | bios_path = instance.href 27 | break 28 | 29 | #BIOS password is the password if secondary authentication is 30 | #required before entering RBSU screen Only required on Gen9 systems 31 | restobj.bios_password = bios_password 32 | 33 | response = restobj.patch(bios_path, bios_properties) 34 | sys.stdout.write("%s" % response) 35 | 36 | if __name__ == "__main__": 37 | # When running on the server locally use the following commented values 38 | # SYSTEM_URL = None 39 | # LOGIN_ACCOUNT = None 40 | # LOGIN_PASSWORD = None 41 | 42 | # When running remotely connect using the iLO secured (https://) address, 43 | # iLO account name, and password to send https requests 44 | # SYSTEM_URL acceptable examples: 45 | # "https://10.0.0.100" 46 | # "https://ilo.hostname" 47 | SYSTEM_URL = "https://10.0.0.100" 48 | LOGIN_ACCOUNT = "admin" 49 | LOGIN_PASSWORD = "password" 50 | 51 | #Create a REST object 52 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 53 | REST_OBJ.login() 54 | sys.stdout.write("\nEXAMPLE 32: Set DHCP\n") 55 | set_bios_dhcp(REST_OBJ, {'Ipv4Address':'192.168.0.1', \ 56 | 'Ipv4Gateway':'192.168.0.2', \ 57 | 'Ipv4PrimaryDNS':'192.168.0.3', \ 58 | 'Ipv4SecondaryDNS':'192.168.0.4', \ 59 | 'Ipv4SubnetMask':'192.168.0.5'}) 60 | REST_OBJ.logout() 61 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/set_bios_iscsi.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def set_bios_iscsi(restobj, bios_properties, bios_password=None): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "HpiSCSISoftwareInitiator." in instance.Type: 25 | if "PUT" in instance.HttpMethods: 26 | iscsi_path = instance.href 27 | break 28 | 29 | #BIOS password is the password if secondary authentication is 30 | #required before entering RBSU screen Only required on Gen9 systems 31 | restobj.bios_password = bios_password 32 | 33 | response = restobj.patch(iscsi_path, bios_properties) 34 | sys.stdout.write("%s" % response) 35 | 36 | if __name__ == "__main__": 37 | # When running on the server locally use the following commented values 38 | # SYSTEM_URL = None 39 | # LOGIN_ACCOUNT = None 40 | # LOGIN_PASSWORD = None 41 | 42 | # When running remotely connect using the iLO secured (https://) address, 43 | # iLO account name, and password to send https requests 44 | # SYSTEM_URL acceptable examples: 45 | # "https://10.0.0.100" 46 | # "https://ilo.hostname" 47 | SYSTEM_URL = "https://10.0.0.100" 48 | LOGIN_ACCOUNT = "admin" 49 | LOGIN_PASSWORD = "password" 50 | 51 | #Create a REST object 52 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 53 | REST_OBJ.login() 54 | sys.stdout.write("\nEXAMPLE 35: Set ISCSI Config\n") 55 | set_bios_iscsi(REST_OBJ, {"iSCSIBootAttemptInstance": 2, \ 56 | "iSCSIBootAttemptName": \ 57 | "Updated Attempt Name", \ 58 | "iSCSIConnectRetry": 5}) 59 | REST_OBJ.logout() 60 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/set_bios_password.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def set_bios_password(restobj, new_password, bios_password=None): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "HpBios." in instance.Type: 25 | if "PUT" in instance.HttpMethods: 26 | bios_path = instance.href 27 | break 28 | 29 | #BIOS password is the password if secondary authentication is 30 | #required before entering RBSU screen Only required on Gen9 systems 31 | restobj.bios_password = bios_password 32 | 33 | body = {"AdminPassword": new_password, \ 34 | "OldAdminPassword": bios_password} 35 | response = restobj.patch(bios_path, body) 36 | sys.stdout.write("%s" % response) 37 | 38 | if __name__ == "__main__": 39 | # When running on the server locally use the following commented values 40 | # SYSTEM_URL = None 41 | # LOGIN_ACCOUNT = None 42 | # LOGIN_PASSWORD = None 43 | 44 | # When running remotely connect using the iLO secured (https://) address, 45 | # iLO account name, and password to send https requests 46 | # SYSTEM_URL acceptable examples: 47 | # "https://10.0.0.100" 48 | # "https://ilo.hostname" 49 | SYSTEM_URL = "https://10.0.0.100" 50 | LOGIN_ACCOUNT = "admin" 51 | LOGIN_PASSWORD = "password" 52 | 53 | #Create a REST object 54 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 55 | REST_OBJ.login() 56 | sys.stdout.write("\nEXAMPLE 48: Set Bios Password\n") 57 | set_bios_password(REST_OBJ, "newpassword", "biospassword") 58 | REST_OBJ.logout() 59 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/set_bios_service.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def set_bios_service(restobj, bios_properties, bios_password=None): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "HpBios." in instance.Type: 25 | if "PUT" in instance.HttpMethods: 26 | bios_path = instance.href 27 | break 28 | 29 | #BIOS password is the password if secondary authentication is 30 | #required before entering RBSU screen Only required on Gen9 systems 31 | restobj.bios_password = bios_password 32 | 33 | response = restobj.patch(bios_path, bios_properties, bios_password) 34 | sys.stdout.write("%s" % response) 35 | 36 | if __name__ == "__main__": 37 | # When running on the server locally use the following commented values 38 | # SYSTEM_URL = None 39 | # LOGIN_ACCOUNT = None 40 | # LOGIN_PASSWORD = None 41 | 42 | # When running remotely connect using the iLO secured (https://) address, 43 | # iLO account name, and password to send https requests 44 | # SYSTEM_URL acceptable examples: 45 | # "https://10.0.0.100" 46 | # "https://ilo.hostname" 47 | SYSTEM_URL = "https://10.0.0.100" 48 | LOGIN_ACCOUNT = "admin" 49 | LOGIN_PASSWORD = "password" 50 | 51 | #Create a REST object 52 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 53 | REST_OBJ.login() 54 | sys.stdout.write("\nEXAMPLE 33: Set BIOS Service.\n") 55 | set_bios_service(REST_OBJ, {'ServiceName':'HPE', 'ServiceEmail':'me@hpe.com'}) 56 | REST_OBJ.logout() 57 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/set_bios_uefi_shell_startup.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def set_bios_uefi_shell_startup(restobj, uefienabled="Enabled", \ 20 | networkpath="", urlpath="", \ 21 | bios_password=None): 22 | resource_instances = get_resource_directory(restobj) 23 | if resource_instances: 24 | #Get URI from resource directory 25 | for instance in resource_instances: 26 | if "HpBios." in instance.Type: 27 | if "PUT" in instance.HttpMethods: 28 | bios_path = instance.href 29 | break 30 | 31 | #BIOS password is the password if secondary authentication is 32 | #required before entering RBSU screen Only required on Gen9 systems 33 | restobj.bios_password = bios_password 34 | body = dict() 35 | body["UefiShellStartup"] = uefienabled 36 | body["UefiShellStartupLocation"] = networkpath 37 | body["UefiShellStartupUrl"] = urlpath 38 | 39 | response = restobj.patch(bios_path, body) 40 | sys.stdout.write("%s" % response) 41 | 42 | if __name__ == "__main__": 43 | # When running on the server locally use the following commented values 44 | # SYSTEM_URL = None 45 | # LOGIN_ACCOUNT = None 46 | # LOGIN_PASSWORD = None 47 | 48 | # When running remotely connect using the iLO secured (https://) address, 49 | # iLO account name, and password to send https requests 50 | # SYSTEM_URL acceptable examples: 51 | # "https://10.0.0.100" 52 | # "https://ilo.hostname" 53 | SYSTEM_URL = "https://10.0.0.100" 54 | LOGIN_ACCOUNT = "admin" 55 | LOGIN_PASSWORD = "password" 56 | 57 | #Create a REST object 58 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 59 | REST_OBJ.login() 60 | set_bios_uefi_shell_startup(REST_OBJ, "Enabled", "10.0.0.0", "test.com") 61 | REST_OBJ.logout() 62 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/set_bios_url_boot_file.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def set_bios_url_boot_file(restobj, path='', bios_password=None): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "HpBios." in instance.Type: 25 | if "PUT" in instance.HttpMethods: 26 | bios_path = instance.href 27 | break 28 | 29 | #BIOS password is the password if secondary authentication is 30 | #required before entering RBSU screen Only required on Gen9 systems 31 | restobj.bios_password = bios_password 32 | 33 | body = {"UrlBootFile": path} 34 | response = restobj.patch(bios_path, body) 35 | sys.stdout.write("%s" % response) 36 | 37 | if __name__ == "__main__": 38 | # When running on the server locally use the following commented values 39 | # SYSTEM_URL = None 40 | # LOGIN_ACCOUNT = None 41 | # LOGIN_PASSWORD = None 42 | 43 | # When running remotely connect using the iLO secured (https://) address, 44 | # iLO account name, and password to send https requests 45 | # SYSTEM_URL acceptable examples: 46 | # "https://10.0.0.100" 47 | # "https://ilo.hostname" 48 | SYSTEM_URL = "https://10.0.0.100" 49 | LOGIN_ACCOUNT = "admin" 50 | LOGIN_PASSWORD = "password" 51 | 52 | #Create a REST object 53 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 54 | REST_OBJ.login() 55 | sys.stdout.write("\nEXAMPLE 36: Set BIOS url boot file\n") 56 | set_bios_url_boot_file(REST_OBJ, "http://test.test/test.efi") 57 | REST_OBJ.logout() 58 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/set_ilo_timezone.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def set_ilo_timezone(restobj, olson_timezone): 20 | sys.stdout.write("\tNOTE: This only works if iLO is NOT configured to " \ 21 | "take time settings from DHCP v4 or v6\n") 22 | resource_instances = get_resource_directory(restobj) 23 | if resource_instances: 24 | #Get URI from resource directory 25 | for instance in resource_instances: 26 | if "HpiLODateTime." in instance.Type: 27 | datetime_path = instance.href 28 | break 29 | 30 | response = restobj.get(datetime_path) 31 | 32 | for timezone in response.dict["TimeZoneList"]: 33 | if timezone["Name"].startswith(olson_timezone): 34 | body = {"TimeZone": {"Name": timezone["Name"]}} 35 | response = restobj.patch(datetime_path, body) 36 | sys.stdout.write("%s" % response) 37 | break 38 | 39 | if __name__ == "__main__": 40 | # When running on the server locally use the following commented values 41 | # SYSTEM_URL = None 42 | # LOGIN_ACCOUNT = None 43 | # LOGIN_PASSWORD = None 44 | 45 | # When running remotely connect using the iLO secured (https://) address, 46 | # iLO account name, and password to send https requests 47 | # SYSTEM_URL acceptable examples: 48 | # "https://10.0.0.100" 49 | # "https://ilo.hostname" 50 | SYSTEM_URL = "https://16.83.63.89" 51 | LOGIN_ACCOUNT = "admin" 52 | LOGIN_PASSWORD = "password" 53 | 54 | #Create a REST object 55 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 56 | REST_OBJ.login() 57 | sys.stdout.write("\nEXAMPLE 28: Set iLO's Timezone\n") 58 | set_ilo_timezone(REST_OBJ, "America/Chicago") 59 | REST_OBJ.logout() 60 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/set_license_key.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def set_license_key(restobj, iLO_Key): 20 | sys.stdout.write("\nEXAMPLE 31: Set iLO License Key\n") 21 | resource_instances = get_resource_directory(restobj) 22 | if resource_instances: 23 | #Get URI from resource directory 24 | for instance in resource_instances: 25 | if "Manager." in instance.Type: 26 | manager_path = instance.href 27 | break 28 | 29 | rsp = restobj.get(manager_path) 30 | 31 | body = dict() 32 | body["LicenseKey"] = iLO_Key 33 | response = restobj.post(rsp.dict["Oem"]["Hp"]["links"]["LicenseService"]["href"], body) 34 | sys.stdout.write("%s" % response) 35 | 36 | if __name__ == "__main__": 37 | # When running on the server locally use the following commented values 38 | # SYSTEM_URL = None 39 | # LOGIN_ACCOUNT = None 40 | # LOGIN_PASSWORD = None 41 | 42 | # When running remotely connect using the iLO secured (https://) address, 43 | # iLO account name, and password to send https requests 44 | # SYSTEM_URL acceptable examples: 45 | # "https://10.0.0.100" 46 | # "https://ilo.hostname" 47 | SYSTEM_URL = "https://10.0.0.100" 48 | LOGIN_ACCOUNT = "admin" 49 | LOGIN_PASSWORD = "password" 50 | 51 | #Create a REST object 52 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 53 | REST_OBJ.login() 54 | set_license_key(REST_OBJ, "test_iLO_Key") 55 | REST_OBJ.logout() 56 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/set_server_asset_tag.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def set_server_asset_tag(restobj, asset_tag): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "ComputerSystem." in instance.Type: 25 | system_path = instance.href 26 | break 27 | 28 | body = {"AssetTag": asset_tag} 29 | response = restobj.patch(system_path, body) 30 | sys.stdout.write("%s" % response) 31 | 32 | if __name__ == "__main__": 33 | # When running on the server locally use the following commented values 34 | # SYSTEM_URL = None 35 | # LOGIN_ACCOUNT = None 36 | # LOGIN_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 | # SYSTEM_URL acceptable examples: 41 | # "https://10.0.0.100" 42 | # "https://ilo.hostname" 43 | SYSTEM_URL = "https://10.0.0.100" 44 | LOGIN_ACCOUNT = "admin" 45 | LOGIN_PASSWORD = "password" 46 | 47 | #Create a REST object 48 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 49 | REST_OBJ.login() 50 | sys.stdout.write("\nEXAMPLE 18: Set Computer Asset Tag\n") 51 | set_server_asset_tag(REST_OBJ, "assettaghere") 52 | REST_OBJ.logout() 53 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/set_uid_light.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def set_uid_light(restobj, uid): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "ComputerSystem." in instance.Type: 25 | system_path = instance.href 26 | break 27 | 28 | body = dict() 29 | if uid: 30 | body["IndicatorLED"] = "Lit" 31 | else: 32 | body["IndicatorLED"] = "Off" 33 | 34 | response = restobj.patch(system_path, body) 35 | sys.stdout.write("%s" % response) 36 | 37 | if __name__ == "__main__": 38 | # When running on the server locally use the following commented values 39 | # SYSTEM_URL = None 40 | # LOGIN_ACCOUNT = None 41 | # LOGIN_PASSWORD = None 42 | 43 | # When running remotely connect using the iLO secured (https://) address, 44 | # iLO account name, and password to send https requests 45 | # SYSTEM_URL acceptable examples: 46 | # "https://10.0.0.100" 47 | # "https://ilo.hostname" 48 | SYSTEM_URL = "https://10.0.0.100" 49 | LOGIN_ACCOUNT = "admin" 50 | LOGIN_PASSWORD = "password" 51 | 52 | #Create a REST object 53 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 54 | REST_OBJ.login() 55 | sys.stdout.write("\nEXAMPLE 15: Set UID Light on or off\n") 56 | set_uid_light(REST_OBJ, True) 57 | REST_OBJ.logout() 58 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/test_ESKM_connection.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def test_ESKM_connection(restobj): 20 | sys.stdout.write("\nEXAMPLE 39: Test ESKM connection\n") 21 | resource_instances = get_resource_directory(restobj) 22 | if resource_instances: 23 | #Get URI from resource directory 24 | for instance in resource_instances: 25 | if "HpESKM." in instance.Type: 26 | eskm_path = instance.href 27 | break 28 | 29 | body = dict() 30 | body["Action"] = "TestESKMConnections" 31 | 32 | response = restobj.post(eskm_path, body) 33 | sys.stdout.write("%s" % response) 34 | 35 | if __name__ == "__main__": 36 | # When running on the server locally use the following commented values 37 | # SYSTEM_URL = None 38 | # LOGIN_ACCOUNT = None 39 | # LOGIN_PASSWORD = None 40 | 41 | # When running remotely connect using the iLO secured (https://) address, 42 | # iLO account name, and password to send https requests 43 | # SYSTEM_URL acceptable examples: 44 | # "https://10.0.0.100" 45 | # "https://ilo.hostname" 46 | SYSTEM_URL = "https://10.0.0.100" 47 | LOGIN_ACCOUNT = "admin" 48 | LOGIN_PASSWORD = "password" 49 | 50 | # Create a REST object 51 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 52 | REST_OBJ.login() 53 | test_ESKM_connection(REST_OBJ) 54 | REST_OBJ.logout() 55 | -------------------------------------------------------------------------------- /examples/Legacy_Rest/update_ilo_firmware.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 redfish import LegacyRestClient 17 | from get_resource_directory import get_resource_directory 18 | 19 | def update_ilo_firmware(restobj, fw_url=None, tpm_flag=False): 20 | resource_instances = get_resource_directory(restobj) 21 | if resource_instances: 22 | #Get URI from resource directory 23 | for instance in resource_instances: 24 | if "HpiLOFirmwareUpdate." in instance.Type: 25 | update_path = instance.href 26 | break 27 | body = dict() 28 | body["Action"] = "InstallFromURI" 29 | body["FirmwareURI"] = fw_url 30 | body["TPMOverrideFlag"] = tpm_flag 31 | response = restobj.post(update_path, body) 32 | sys.stdout.write("%s" % response) 33 | 34 | if __name__ == "__main__": 35 | # When running on the server locally use the following commented values 36 | # While this example can be run remotely, it is used locally to locate the 37 | # iLO IP address 38 | #SYSTEM_URL = None 39 | #LOGIN_ACCOUNT = None 40 | #LOGIN_PASSWORD = None 41 | 42 | # When running remotely connect using the iLO secured (https://) address, 43 | # iLO account name, and password to send https requests 44 | # SYSTEM_URL acceptable examples: 45 | # "https://10.0.0.100" 46 | # "https://ilo.hostname" 47 | SYSTEM_URL = "https://10.0.0.100" 48 | LOGIN_ACCOUNT = "admin" 49 | LOGIN_PASSWORD = "password" 50 | 51 | #Create a REST object 52 | REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD) 53 | REST_OBJ.login() 54 | sys.stdout.write("\nEXAMPLE 53: Update iLO Firmware\n") 55 | update_ilo_firmware(REST_OBJ, "http://test.com/ilo4_244.bin", False) 56 | REST_OBJ.logout() 57 | -------------------------------------------------------------------------------- /examples/Redfish/computer_details.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 | # -*- coding: utf-8 -*- 16 | """ 17 | An example of gathering the computer system details 18 | """ 19 | 20 | 21 | import sys 22 | import json 23 | from redfish import RedfishClient 24 | from redfish.rest.v1 import ServerDownOrUnreachableError 25 | 26 | from get_resource_directory import get_resource_directory 27 | 28 | def computer_details(_redfishobj): 29 | systems_members_uri = None 30 | systems_members_response = None 31 | 32 | resource_instances = get_resource_directory(_redfishobj) 33 | if DISABLE_RESOURCE_DIR or not resource_instances: 34 | #if we do not have a resource directory or want to force it's non use to find the 35 | #relevant URI 36 | systems_uri = _redfishobj.root.obj['Systems']['@odata.id'] 37 | systems_response = _redfishobj.get(systems_uri) 38 | systems_members_uri = next(iter(systems_response.obj['Members']))['@odata.id'] 39 | systems_members_response = _redfishobj.get(systems_members_uri) 40 | else: 41 | for instance in resource_instances: 42 | #Use Resource directory to find the relevant URI 43 | if '#ComputerSystem.' in instance['@odata.type']: 44 | systems_members_uri = instance['@odata.id'] 45 | systems_members_response = _redfishobj.get(systems_members_uri) 46 | 47 | print("\n\nPrinting computer system details:\n\n") 48 | print(json.dumps(systems_members_response.dict, indent=4, sort_keys=True)) 49 | 50 | if __name__ == "__main__": 51 | # When running on the server locally use the following commented values 52 | #SYSTEM_URL = None 53 | #LOGIN_ACCOUNT = None 54 | #LOGIN_PASSWORD = None 55 | 56 | # When running remotely connect using the secured (https://) address, 57 | # account name, and password to send https requests 58 | # SYSTEM_URL acceptable examples: 59 | # "https://10.0.0.100" 60 | # "https://ilo.hostname" 61 | SYSTEM_URL = "https://16.83.61.9" 62 | LOGIN_ACCOUNT = "Administrator" 63 | LOGIN_PASSWORD = "password" 64 | 65 | # flag to force disable resource directory. Resource directory and associated operations are 66 | # intended for HPE servers. 67 | DISABLE_RESOURCE_DIR = False 68 | 69 | try: 70 | # Create a Redfish client object 71 | REDFISHOBJ = RedfishClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, \ 72 | password=LOGIN_PASSWORD) 73 | # Login with the Redfish client 74 | REDFISHOBJ.login() 75 | except ServerDownOrUnreachableError as excp: 76 | sys.stderr.write("ERROR: server not reachable or does not support RedFish.\n") 77 | sys.exit() 78 | 79 | computer_details(REDFISHOBJ) 80 | REDFISHOBJ.logout() 81 | -------------------------------------------------------------------------------- /examples/Redfish/configure_snmp_trap_source.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import json 3 | from redfish import RedfishClient 4 | from redfish.rest.v1 import ServerDownOrUnreachableError 5 | 6 | 7 | def configure_snmp(_redfishobj): 8 | 9 | snmp_service_uri = None 10 | managers_uri = _redfishobj.root.obj['Managers']['@odata.id'] 11 | managers_response = _redfishobj.get(managers_uri) 12 | managers_members_uri = next(iter(managers_response.obj['Members']))['@odata.id'] 13 | managers_members_response = _redfishobj.get(managers_members_uri) 14 | # print(managers_members_response.obj['Oem']['Hpe']['Links']) 15 | # exit(0) 16 | snmp_service_uri = managers_members_response.obj.Oem.Hpe.Links['SNMPService']['@odata.id'] 17 | 18 | if snmp_service_uri: 19 | # resp = _redfishobj.get(snmp_service_uri) 20 | # print(json.dumps(resp.dict, indent=4, sort_keys=True)) 21 | # exit(0) 22 | # TrapSourceHostname : Manager or System 23 | body = {"TrapSourceHostname": "System"} 24 | resp = _redfishobj.patch(snmp_service_uri, body) 25 | 26 | if resp.status == 400: 27 | try: 28 | print(json.dumps(resp.obj['error']['@Message.ExtendedInfo'], indent=4, 29 | sort_keys=True)) 30 | except Exception as excp: 31 | sys.stderr.write("A response error occurred, unable to access iLO Extended " 32 | "Message Info...") 33 | elif resp.status != 200: 34 | sys.stderr.write("An http response of \'%s\' was returned.\n" % resp.status) 35 | else: 36 | print("Success!\n") 37 | # print(json.dumps(resp.dict, indent=4, sort_keys=True)) 38 | 39 | 40 | if __name__ == "__main__": 41 | 42 | if len(sys.argv) <= 3: 43 | sys.stderr.write("ERROR: We need 3 arguments. \nUsage: change-snmp.py " 44 | "ILOIPADDR ILOUSER ILOPASSWORD \n") 45 | sys.exit() 46 | 47 | SYSTEM_URL = "https://" + sys.argv[1] 48 | LOGIN_ACCOUNT = sys.argv[2] 49 | LOGIN_PASSWORD = sys.argv[3] 50 | 51 | try: 52 | REDFISHOBJ = RedfishClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, 53 | password=LOGIN_PASSWORD) 54 | REDFISHOBJ.login() 55 | except ServerDownOrUnreachableError as excp: 56 | sys.stderr.write("ERROR: server not reachable or does not support RedFish.\n") 57 | sys.exit() 58 | 59 | configure_snmp(REDFISHOBJ) 60 | REDFISHOBJ.logout() -------------------------------------------------------------------------------- /examples/Redfish/expand_data.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 | # -*- coding: utf-8 -*- 16 | """ 17 | An example of expanding data responses 18 | """ 19 | 20 | import sys 21 | import json 22 | from redfish import RedfishClient 23 | from redfish.rest.v1 import ServerDownOrUnreachableError 24 | 25 | def expand_data(_redfishobj, expand_url="/redfish/v1/"): 26 | 27 | response = _redfishobj.get(expand_url) 28 | exp_response = _redfishobj.get(expand_url+'?$expand=.') 29 | sys.stdout.write('Standard response:\n') 30 | sys.stdout.write('\t'+str(response.dict)+'\n') 31 | sys.stdout.write('Expanded response:\n') 32 | sys.stdout.write('\t'+str(exp_response.dict)+'\n') 33 | 34 | if __name__ == "__main__": 35 | # When running on the server locally use the following commented values 36 | #SYSTEM_URL = None 37 | #LOGIN_ACCOUNT = None 38 | #LOGIN_PASSWORD = None 39 | 40 | # When running remotely connect using the secured (https://) address, 41 | # account name, and password to send https requests 42 | # SYSTEM_URL acceptable examples: 43 | # "https://10.0.0.100" 44 | # "https://ilo.hostname" 45 | SYSTEM_URL = "https://10.0.0.100" 46 | LOGIN_ACCOUNT = "admin" 47 | LOGIN_PASSWORD = "password" 48 | 49 | #url to be expanded 50 | EXPAND_URL = "/redfish/v1/systems/" 51 | 52 | try: 53 | # Create a Redfish client object 54 | REDFISHOBJ = RedfishClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, \ 55 | password=LOGIN_PASSWORD) 56 | # Login with the Redfish client 57 | REDFISHOBJ.login() 58 | except ServerDownOrUnreachableError as excp: 59 | sys.stderr.write("ERROR: server not reachable or does not support RedFish.\n") 60 | sys.exit() 61 | 62 | expand_data(REDFISHOBJ, EXPAND_URL) 63 | REDFISHOBJ.logout() 64 | -------------------------------------------------------------------------------- /examples/Redfish/get_ESKM.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 | # -*- coding: utf-8 -*- 16 | """ 17 | An example of gathering ESKM data for HPE iLO systems 18 | """ 19 | 20 | import sys 21 | import json 22 | from redfish import RedfishClient 23 | from redfish.rest.v1 import ServerDownOrUnreachableError 24 | 25 | from get_resource_directory import get_resource_directory 26 | 27 | def get_ESKM(_redfishobj): 28 | 29 | security_service_eskm_uri = None 30 | 31 | resource_instances = get_resource_directory(_redfishobj) 32 | if DISABLE_RESOURCE_DIR or not resource_instances: 33 | #if we do not have a resource directory or want to force it's non use to find the 34 | #relevant URI 35 | managers_uri = _redfishobj.root.obj['Managers']['@odata.id'] 36 | managers_response = _redfishobj.get(managers_uri) 37 | managers_members_uri = next(iter(managers_response.obj['Members']))['@odata.id'] 38 | managers_members_response = _redfishobj.get(managers_members_uri) 39 | security_service_uri = managers_members_response.obj.Oem.Hpe.Links\ 40 | ['SecurityService']['@odata.id'] 41 | security_service_response = _redfishobj.get(security_service_uri) 42 | security_service_eskm_uri = security_service_response.obj.Links['ESKM']['@odata.id'] 43 | else: 44 | for instance in resource_instances: 45 | #Use Resource directory to find the relevant URI 46 | if '#HpeESKM.' in instance['@odata.type']: 47 | security_service_eskm_uri = instance['@odata.id'] 48 | break 49 | 50 | if security_service_eskm_uri: 51 | security_service_eskm_resp = _redfishobj.get(security_service_eskm_uri) 52 | print(json.dumps(security_service_eskm_resp.dict, indent=4, sort_keys=True)) 53 | 54 | if __name__ == "__main__": 55 | # When running on the server locally use the following commented values 56 | #SYSTEM_URL = None 57 | #LOGIN_ACCOUNT = None 58 | #LOGIN_PASSWORD = None 59 | 60 | # When running remotely connect using the secured (https://) address, 61 | # account name, and password to send https requests 62 | # SYSTEM_URL acceptable examples: 63 | # "https://10.0.0.100" 64 | # "https://ilo.hostname" 65 | SYSTEM_URL = "https://10.0.0.100" 66 | LOGIN_ACCOUNT = "admin" 67 | LOGIN_PASSWORD = "password" 68 | 69 | # flag to force disable resource directory. Resource directory and associated operations are 70 | # intended for HPE servers. 71 | DISABLE_RESOURCE_DIR = False 72 | 73 | try: 74 | # Create a Redfish client object 75 | REDFISHOBJ = RedfishClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, \ 76 | password=LOGIN_PASSWORD) 77 | # Login with the Redfish client 78 | REDFISHOBJ.login() 79 | except ServerDownOrUnreachableError as excp: 80 | sys.stderr.write("ERROR: server not reachable or does not support RedFish.\n") 81 | sys.exit() 82 | 83 | get_ESKM(REDFISHOBJ) 84 | REDFISHOBJ.logout() 85 | -------------------------------------------------------------------------------- /examples/Redfish/get_base_registry.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 | # -*- coding: utf-8 -*- 16 | """ 17 | An example of getting the base message registry 18 | """ 19 | 20 | import sys 21 | import json 22 | from redfish import RedfishClient 23 | from redfish.rest.v1 import ServerDownOrUnreachableError 24 | 25 | def get_base_registry(_redfishobj): 26 | 27 | registries_uri = _redfishobj.root.obj['Registries']['@odata.id'] 28 | 29 | if registries_uri: 30 | registries_members = _redfishobj.get(registries_uri).obj['Members'] 31 | for registry in registries_members: 32 | sys.stdout.write("Registry URI at '%s'\n" % registry['@odata.id']) 33 | 34 | if __name__ == "__main__": 35 | # When running on the server locally use the following commented values 36 | #SYSTEM_URL = None 37 | #LOGIN_ACCOUNT = None 38 | #LOGIN_PASSWORD = None 39 | 40 | # When running remotely connect using the secured (https://) address, 41 | # account name, and password to send https requests 42 | # SYSTEM_URL acceptable examples: 43 | # "https://10.0.0.100" 44 | # "https://ilo.hostname" 45 | SYSTEM_URL = "https://10.0.0.100" 46 | LOGIN_ACCOUNT = "admin" 47 | LOGIN_PASSWORD = "password" 48 | 49 | try: 50 | # Create a Redfish client object 51 | REDFISHOBJ = RedfishClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, \ 52 | password=LOGIN_PASSWORD) 53 | # Login with the Redfish client 54 | REDFISHOBJ.login() 55 | except ServerDownOrUnreachableError as excp: 56 | sys.stderr.write("ERROR: server not reachable or does not support RedFish.\n") 57 | sys.exit() 58 | 59 | get_base_registry(REDFISHOBJ) 60 | REDFISHOBJ.logout() 61 | -------------------------------------------------------------------------------- /examples/Redfish/get_powermetrics_average.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 | # -*- coding: utf-8 -*- 16 | """ 17 | An example of gathering the power metrics average on HPE iLO systems 18 | """ 19 | 20 | import sys 21 | import json 22 | from redfish import RedfishClient 23 | from redfish.rest.v1 import ServerDownOrUnreachableError 24 | 25 | #from get_resource_directory import get_resource_directory 26 | 27 | def get_powermetrics_average(_redfishobj): 28 | 29 | power_metrics_uri = None 30 | 31 | resource_instances = _redfishobj.get_resource_directory() 32 | if DISABLE_RESOURCE_DIR or not resource_instances: 33 | #if we do not have a resource directory or want to force it's non use to find the 34 | #relevant URI 35 | chassis_uri = _redfishobj.root.obj['Chassis']['@odata.id'] 36 | chassis_response = _redfishobj.get(chassis_uri) 37 | chassis_members_uri = next(iter(chassis_response.obj['Members']))['@odata.id'] 38 | chassis_members_response = _redfishobj.get(chassis_members_uri) 39 | power_metrics_uri = chassis_members_response.obj.Oem.Hpe['Power']['@odata.id'] 40 | else: 41 | for instance in resource_instances: 42 | #Use Resource directory to find the relevant URI 43 | if '#Power.' in instance['@odata.type']: 44 | power_metrics_uri = instance['@odata.id'] 45 | break 46 | 47 | if power_metrics_uri: 48 | power_metrics_data = _redfishobj.get(power_metrics_uri).obj.Oem.Hpe 49 | print("\n\nPower Data:\n\n") 50 | print(json.dumps(power_metrics_data, indent=4, sort_keys=True)) 51 | 52 | if __name__ == "__main__": 53 | # When running on the server locally use the following commented values 54 | #SYSTEM_URL = None 55 | #LOGIN_ACCOUNT = None 56 | #LOGIN_PASSWORD = None 57 | 58 | # When running remotely connect using the secured (https://) address, 59 | # account name, and password to send https requests 60 | # SYSTEM_URL acceptable examples: 61 | # "https://10.0.0.100" 62 | # "https://ilo.hostname" 63 | SYSTEM_URL = input("Enter iLO IP address: ") 64 | LOGIN_ACCOUNT = input("Enter Username: ") 65 | LOGIN_PASSWORD = input("Enter password: ") 66 | 67 | # flag to force disable resource directory. Resource directory and associated operations are 68 | # intended for HPE servers. 69 | DISABLE_RESOURCE_DIR = False 70 | 71 | try: 72 | # Create a Redfish client object 73 | REDFISHOBJ = RedfishClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, \ 74 | password=LOGIN_PASSWORD) 75 | # Login with the Redfish client 76 | REDFISHOBJ.login() 77 | except ServerDownOrUnreachableError as excp: 78 | sys.stderr.write("ERROR: server not reachable or does not support RedFish.\n") 79 | sys.exit() 80 | 81 | get_powermetrics_average(REDFISHOBJ) 82 | REDFISHOBJ.logout() 83 | -------------------------------------------------------------------------------- /examples/Redfish/get_resource_directory.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 | # -*- coding: utf-8 -*- 16 | """ 17 | An example of getting the ilo information like ilo generation, version and resource directory for HPE iLO systems 18 | """ 19 | 20 | import sys 21 | from redfish import RedfishClient 22 | from redfish.rest.v1 import ServerDownOrUnreachableError 23 | 24 | def get_resource_directory(redfishobj): 25 | 26 | try: 27 | resource_uri = redfishobj.root.obj.Oem.Hpe.Links.ResourceDirectory['@odata.id'] 28 | except KeyError: 29 | sys.stderr.write("Resource directory is only available on HPE servers.\n") 30 | return None 31 | 32 | response = redfishobj.get(resource_uri) 33 | resources = [] 34 | 35 | if response.status == 200: 36 | sys.stdout.write("\tFound resource directory at /redfish/v1/resourcedirectory" + "\n\n") 37 | resources = response.dict["Instances"] 38 | else: 39 | sys.stderr.write("\tResource directory missing at /redfish/v1/resourcedirectory" + "\n") 40 | 41 | return resources 42 | 43 | def get_gen(_redfishobj): 44 | rootresp = _redfishobj.root.obj 45 | #Default iLO 5 46 | ilogen = 5 47 | gencompany = next(iter(rootresp.get("Oem", {}).keys()), None) in ('Hpe', 'Hp') 48 | comp = 'Hp' if gencompany else None 49 | comp = 'Hpe' if rootresp.get("Oem", {}).get('Hpe', None) else comp 50 | if comp and next(iter(rootresp.get("Oem", {}).get(comp, {}).get("Manager", {}))).\ 51 | get('ManagerType', None): 52 | ilogen = next(iter(rootresp.get("Oem", {}).get(comp, {}).get("Manager", {})))\ 53 | .get("ManagerType") 54 | ilover = next(iter(rootresp.get("Oem", {}).get(comp, {}).get("Manager", {}))).\ 55 | get("ManagerFirmwareVersion") 56 | if ilogen.split(' ')[-1] == "CM": 57 | # Assume iLO 4 types in Moonshot 58 | ilogen = 4 59 | iloversion = None 60 | else: 61 | ilogen = ilogen.split(' ')[1] 62 | iloversion = float(ilogen.split(' ')[-1] + '.' + \ 63 | ''.join(ilover.split('.'))) 64 | return (ilogen, iloversion) 65 | -------------------------------------------------------------------------------- /examples/Redfish/get_schema.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 | # -*- coding: utf-8 -*- 16 | """ 17 | An example of obtaining system schema data 18 | """ 19 | 20 | import sys 21 | import json 22 | from redfish import RedfishClient 23 | from redfish.rest.v1 import ServerDownOrUnreachableError 24 | 25 | def get_schema(_redfishobj): 26 | schema_members_uris = [] 27 | schema_members_expanded = {} 28 | 29 | schema_uri = _redfishobj.root.obj['JsonSchemas']['@odata.id'] 30 | schema_response = _redfishobj.get(schema_uri) 31 | schema_members_uris = schema_response.obj['Members'] 32 | for member in schema_members_uris: 33 | data = _redfishobj.get(member['@odata.id']).dict 34 | instance_id = data['Location'].index(next(iter(data['Location']))) 35 | schema_uri = data['Location'][instance_id]['Uri'] 36 | schema = _redfishobj.get(schema_uri).dict 37 | #I am just replacing the URI link for the sub-schema with the actual schema. You will 38 | #see EVERYTHING 39 | _tmp = {schema_uri + ' ->': schema} 40 | data['Location'][instance_id]['Uri'] = _tmp 41 | schema_members_expanded[member['@odata.id']] = data 42 | 43 | print(json.dumps(schema_members_expanded, indent=4, sort_keys=True)) 44 | 45 | if __name__ == "__main__": 46 | # When running on the server locally use the following commented values 47 | #SYSTEM_URL = None 48 | #LOGIN_ACCOUNT = None 49 | #LOGIN_PASSWORD = None 50 | 51 | # When running remotely connect using the secured (https://) address, 52 | # account name, and password to send https requests 53 | # SYSTEM_URL acceptable examples: 54 | # "https://10.0.0.100" 55 | # "https://ilo.hostname" 56 | SYSTEM_URL = "https://10.0.0.100" 57 | LOGIN_ACCOUNT = "admin" 58 | LOGIN_PASSWORD = "password" 59 | 60 | try: 61 | # Create a Redfish client object 62 | REDFISHOBJ = RedfishClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, \ 63 | password=LOGIN_PASSWORD) 64 | # Login with the Redfish client 65 | REDFISHOBJ.login() 66 | except ServerDownOrUnreachableError as excp: 67 | sys.stderr.write("ERROR: server not reachable or does not support RedFish.\n") 68 | sys.exit() 69 | 70 | get_schema(REDFISHOBJ) 71 | REDFISHOBJ.logout() 72 | -------------------------------------------------------------------------------- /examples/Redfish/ilorest_util.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 | # -*- coding: utf-8 -*- 16 | """ 17 | An example of getting the ilo information like ilo generation, version and resource directory for HPE iLO systems 18 | """ 19 | 20 | import sys 21 | from redfish import RedfishClient 22 | from redfish.rest.v1 import ServerDownOrUnreachableError 23 | 24 | def get_resource_directory(redfishobj): 25 | 26 | try: 27 | resource_uri = redfishobj.root.obj.Oem.Hpe.Links.ResourceDirectory['@odata.id'] 28 | except KeyError: 29 | sys.stderr.write("Resource directory is only available on HPE servers.\n") 30 | return None 31 | 32 | response = redfishobj.get(resource_uri) 33 | resources = [] 34 | 35 | if response.status == 200: 36 | sys.stdout.write("\tFound resource directory at /redfish/v1/resourcedirectory" + "\n\n") 37 | resources = response.dict["Instances"] 38 | else: 39 | sys.stderr.write("\tResource directory missing at /redfish/v1/resourcedirectory" + "\n") 40 | 41 | return resources 42 | 43 | def get_gen(_redfishobj): 44 | rootresp = _redfishobj.root.obj 45 | #Default iLO 5 46 | ilogen = 5 47 | gencompany = next(iter(rootresp.get("Oem", {}).keys()), None) in ('Hpe', 'Hp') 48 | comp = 'Hp' if gencompany else None 49 | comp = 'Hpe' if rootresp.get("Oem", {}).get('Hpe', None) else comp 50 | if comp and next(iter(rootresp.get("Oem", {}).get(comp, {}).get("Manager", {}))).\ 51 | get('ManagerType', None): 52 | ilogen = next(iter(rootresp.get("Oem", {}).get(comp, {}).get("Manager", {})))\ 53 | .get("ManagerType") 54 | ilover = next(iter(rootresp.get("Oem", {}).get(comp, {}).get("Manager", {}))).\ 55 | get("ManagerFirmwareVersion") 56 | if ilogen.split(' ')[-1] == "CM": 57 | # Assume iLO 4 types in Moonshot 58 | ilogen = 4 59 | iloversion = None 60 | else: 61 | ilogen = ilogen.split(' ')[1] 62 | iloversion = float(ilogen.split(' ')[-1] + '.' + \ 63 | ''.join(ilover.split('.'))) 64 | return (ilogen, iloversion) 65 | -------------------------------------------------------------------------------- /examples/Redfish/quickstart_redfish.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import sys 3 | import redfish 4 | 5 | # When running on the server locally use the following commented values 6 | # iLO_host = "blobstore://." 7 | # LOGIN_ACCOUNT = "None" 8 | # LOGIN_PASSWORD = "None" 9 | 10 | # When running remotely connect using the iLO address, iLO account name, 11 | # and password to send https requests 12 | iLO_host = "https://10.0.0.100" 13 | login_account = "admin" 14 | login_password = "password" 15 | 16 | ## Create a REDFISH object 17 | REDFISH_OBJ = redfish.RedfishClient(base_url=iLO_host,username=login_account, \ 18 | password=login_password) 19 | 20 | # Login into the server and create a session 21 | REDFISH_OBJ.login() 22 | 23 | # Do a GET on a given path 24 | response = REDFISH_OBJ.get("/redfish/v1/systems/1") 25 | 26 | # Print out the response 27 | sys.stdout.write("%s\n" % response) 28 | 29 | # Logout of the current session 30 | REDFISH_OBJ.logout() -------------------------------------------------------------------------------- /examples/Redfish/sessions.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 | # -*- coding: utf-8 -*- 16 | """ 17 | An example of manually managing sessions with Redfish 18 | """ 19 | 20 | import sys 21 | import json 22 | from six.moves import urllib 23 | from redfish import RedfishClient 24 | from redfish.rest.v1 import ServerDownOrUnreachableError 25 | 26 | def sessions(_redfishobj, login_account, login_password): 27 | 28 | new_session = {"UserName": login_account, "Password": login_password} 29 | response = _redfishobj.post('/redfish/v1/Sessions', new_session) 30 | 31 | if response.status == 201: 32 | print("Success!\n") 33 | session_uri = response.getheader("location") 34 | session_uri = urllib.parse.urlparse(session_uri) 35 | sys.stdout.write("\tSession " + session_uri.path + " created.\n") 36 | x_auth_token = response.getheader("x-auth-token") 37 | sys.stdout.write("\tThis is the session X-Auth Token key " + x_auth_token + ".\n") 38 | print(json.dumps(response.dict, indent=4, sort_keys=True)) 39 | 40 | # Delete the created session 41 | sys.stdout.write("\tTerminating this session.\n") 42 | sessresp = _redfishobj.delete(session_uri.path) 43 | print(json.dumps(sessresp.dict, indent=4, sort_keys=True)) 44 | else: 45 | sys.stderr.write("ERROR: failed to create a session.\n") 46 | try: 47 | print(json.dumps(sessresp.obj['error']['@Message.ExtendedInfo'], indent=4, \ 48 | sort_keys=True)) 49 | except Exception as excp: 50 | sys.stderr.write("A response error occurred, unable to access iLO Extended" 51 | " Message Info...") 52 | 53 | if __name__ == "__main__": 54 | # When running on the server locally use the following commented values 55 | #SYSTEM_URL = None 56 | #LOGIN_ACCOUNT = None 57 | #LOGIN_PASSWORD = None 58 | 59 | # When running remotely connect using the secured (https://) address, 60 | # account name, and password to send https requests 61 | # SYSTEM_URL acceptable examples: 62 | # "https://10.0.0.100" 63 | # "https://ilo.hostname" 64 | SYSTEM_URL = "https://10.0.0.100" 65 | LOGIN_ACCOUNT = "admin" 66 | LOGIN_PASSWORD = "password" 67 | 68 | try: 69 | # Create a Redfish client object 70 | REDFISHOBJ = RedfishClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, \ 71 | password=LOGIN_PASSWORD) 72 | except ServerDownOrUnreachableError as excp: 73 | sys.stderr.write("ERROR: server not reachable or does not support RedFish.\n") 74 | sys.exit() 75 | 76 | sessions(REDFISHOBJ, LOGIN_ACCOUNT, LOGIN_PASSWORD) 77 | -------------------------------------------------------------------------------- /examples/quickstart_legacy_rest.py: -------------------------------------------------------------------------------- 1 | ### 2 | # Copyright 2020 Hewlett Packard Enterprise, Inc. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ### 16 | 17 | # -*- coding: utf-8 -*- 18 | """A quickstart example for LegacyRestClient""" 19 | 20 | import sys 21 | import redfish 22 | 23 | # When running on the server locally use the following commented values 24 | # HOST = "blobstore://." 25 | # LOGIN_ACCOUNT = "None" 26 | # LOGIN_PASSWORD = "None" 27 | 28 | # When running remotely connect using the iLO address, iLO account name, 29 | # and password to send https requests 30 | SYSTEM_URL = "https://10.0.0.100" 31 | LOGIN_ACCOUNT = "admin" 32 | LOGIN_PASSWORD = "password" 33 | 34 | # Create a REST object 35 | REST_OBJ = redfish.LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT,\ 36 | password=LOGIN_PASSWORD) 37 | 38 | # Login into the server and create a session 39 | REST_OBJ.login(auth="session") 40 | 41 | # Do a GET on a given path 42 | RESPONSE = REST_OBJ.get("/rest/v1/systems/1") 43 | 44 | # Print out the response 45 | sys.stdout.write("%s\n" % RESPONSE) 46 | 47 | # Logout of the current session 48 | REST_OBJ.logout() 49 | -------------------------------------------------------------------------------- /examples/quickstart_redfish.py: -------------------------------------------------------------------------------- 1 | ### 2 | # Copyright 2020 Hewlett Packard Enterprise, Inc. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ### 16 | 17 | # -*- coding: utf-8 -*- 18 | """A quickstart example for RedfishClient""" 19 | 20 | import sys 21 | import redfish 22 | 23 | # When running on the server locally use the following commented values 24 | # HOST = "blobstore://." 25 | # LOGIN_ACCOUNT = "None" 26 | # LOGIN_PASSWORD = "None" 27 | 28 | # When running remotely connect using the iLO address, iLO account name, 29 | # and password to send https requests 30 | SYSTEM_URL = "https://10.0.0.100" 31 | LOGIN_ACCOUNT = "admin" 32 | LOGIN_PASSWORD = "password" 33 | 34 | ## Create a REDFISH object 35 | REDFISH_OBJ = redfish.RedfishClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT,\ 36 | password=LOGIN_PASSWORD) 37 | 38 | # Login into the server and create a session 39 | REDFISH_OBJ.login() 40 | 41 | # Do a GET on a given path 42 | RESPONSE = REDFISH_OBJ.get("/redfish/v1/systems/1") 43 | 44 | # Print out the response 45 | sys.stdout.write("%s\n" % RESPONSE) 46 | 47 | # Logout of the current session 48 | REDFISH_OBJ.logout() 49 | -------------------------------------------------------------------------------- /flake8.txt: -------------------------------------------------------------------------------- 1 | .\src\redfish\ris\resp_handler.py:227:74: F821 undefined name 'key' 2 | -------------------------------------------------------------------------------- /makeandinstallzip.bat: -------------------------------------------------------------------------------- 1 | python3 -m pip install -r requirements.txt 2 | python3 setup.py sdist --formats=zip 3 | cd dist 4 | 5 | python3 -m pip install --upgrade python-ilorest-library-5.3.0.zip 6 | -------------------------------------------------------------------------------- /pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | -----Synopsis of Commits Above----- 4 | 5 | **Please fill out the following when submitting the PR** 6 | 7 | ## Status 8 | - [ ] READY 9 | - [ ] IN-DEVELOPMENT 10 | - [ ] ON-HOLD 11 | 12 | ## Additional High Level Description 13 | A few sentences describing the overall goals of the pull request's commits. 14 | - Include the issue number here if it fixes one. Example `#1` 15 | - Include the QUIX number here if it fixes one. 16 | 17 | ## Dependent PRs 18 | List any PRs that must be merged together. (Tool dependent PRs SHOULD NOT occur.) 19 | - If additional library PRs are to be referenced simply note the PR# 20 | 21 | ## Before Status can be set to READY I have completed the following: 22 | - [ ] Check if documentation updates 23 | - [ ] Check if example code updates 24 | - [ ] Pylint static analysis tests are passing above 9.0/10.0 25 | - [ ] Unit tests added for any new functions/features and passed. 26 | - [ ] Targeted/Custom Testing performed. Indicate the results in the description above or as additional comments. 27 | -------------------------------------------------------------------------------- /pylint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Running pylint and exporting to file" 3 | pylint -f parseable redfish | tee pylint.out 4 | echo "Pylint done!" 5 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | jsonpatch 2 | jsonpath_rw 3 | jsonpointer 4 | urllib3 5 | six 6 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description_file = README.rst 3 | [bdist_rpm] 4 | requires = jsonpatch >= 1.3 5 | jsonpath-rw >= 1.3.0 6 | jsonpointer >= 1.1 7 | urllib3 >= 1.23 8 | ilorest_chif >= 2.3.0 9 | [isort] 10 | profile = black 11 | [pycodestyle] 12 | ignore = E203 13 | max_line_length = 120 14 | [pylint] 15 | max-line-length = 120 16 | [flake8] 17 | max-line-length = 120 18 | extend-ignore = E203,E722,C901,E731,W605 19 | exclude = 20 | .git, 21 | packaging, 22 | __pycache__, 23 | src/redfish/__init__.py, 24 | src/redfish/hpilo/__init__.py, 25 | src/redfish/ris/__init__.py, 26 | src/redfish/rest/__init__.py, 27 | build, 28 | dist, 29 | docs, 30 | examples, 31 | tests 32 | max-complexity = 20 33 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import find_packages, setup 2 | 3 | extras = {} 4 | 5 | setup(name='python-ilorest-library', 6 | version='6.1.0.0', 7 | description='iLO Rest Python Library', 8 | author='Hewlett Packard Enterprise', 9 | author_email='rajeevalochana.kallur@hpe.com', 10 | extras_require=extras, 11 | classifiers=[ 12 | 'Development Status :: 5 - Production/Stable', 13 | 'License :: OSI Approved :: Apache Software License', 14 | 'Programming Language :: Python :: 3.8', 15 | 'Programming Language :: Python :: 3.9', 16 | 'Programming Language :: Python :: 3.10', 17 | 'Programming Language :: Python :: 3.11', 18 | 'Programming Language :: Python :: 3.12', 19 | 'Topic :: Communications' 20 | ], 21 | keywords='Hewlett Packard Enterprise', 22 | url='https://github.com/HewlettPackard/python-ilorest-library', 23 | packages=find_packages('src'), 24 | package_dir={'': 'src'}, 25 | install_requires=[ 26 | 'jsonpatch', 27 | 'jsonpath_rw', 28 | 'jsonpointer', 29 | 'urllib3', 30 | 'six' 31 | ]) 32 | -------------------------------------------------------------------------------- /src/redfish/__init__.py: -------------------------------------------------------------------------------- 1 | """ Redfish restful library """ 2 | 3 | __all__ = ["rest", "ris", "hpilo"] 4 | __version__ = "6.1.0.0" 5 | 6 | import logging 7 | 8 | from redfish.rest.v1 import AuthMethod, LegacyRestClient, RedfishClient 9 | 10 | 11 | def redfish_logger(file_name, log_format, log_level=logging.ERROR): 12 | """redfish logger""" 13 | formatter = logging.Formatter(log_format) 14 | fhdl = logging.FileHandler(file_name) 15 | fhdl.setFormatter(formatter) 16 | logger = logging.getLogger(__name__) 17 | logger.addHandler(fhdl) 18 | logger.setLevel(log_level) 19 | return logger 20 | -------------------------------------------------------------------------------- /src/redfish/hpilo/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Utilities to simplify communicating with iLO locally 3 | """ 4 | -------------------------------------------------------------------------------- /src/redfish/rest/__init__.py: -------------------------------------------------------------------------------- 1 | """ Base interface to simplify interaction with LegacyRest/Redfish data and Remote/Local 2 | connections.""" 3 | -------------------------------------------------------------------------------- /src/redfish/ris/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Expanded LegacyREST/Redfish interface for schema validation, database for responses, caching, 4 | and error registries. 5 | """ 6 | 7 | from .ris import ( 8 | RisInstanceNotFoundError, 9 | RisMonolith, 10 | RisMonolithMemberBase, 11 | RisMonolithMemberv100, 12 | SessionExpired, 13 | ) 14 | from .rmc import RmcApp 15 | from .rmc_helper import ( 16 | CurrentlyLoggedInError, 17 | IdTokenError, 18 | IloLicenseError, 19 | InstanceNotFoundError, 20 | InvalidSelectionError, 21 | NothingSelectedError, 22 | NothingSelectedFilterError, 23 | NothingSelectedSetError, 24 | RmcCacheManager, 25 | RmcFileCacheManager, 26 | ScepenabledError, 27 | UndefinedClientError, 28 | ValidationError, 29 | ValueChangedError, 30 | ) 31 | from .sharedtypes import JSONEncoder 32 | from .validation import RegistryValidationError, ValidationManager 33 | -------------------------------------------------------------------------------- /src/redfish/ris/rmc_api.py: -------------------------------------------------------------------------------- 1 | from rmc import RmcApp 2 | 3 | 4 | class Rmc_API(RmcApp): 5 | def __init__(self, Args=None): 6 | RmcApp.__init__(self, Args) 7 | 8 | def Api_login(self, url=None, username=None, password=None): 9 | self.login(base_url=url, username=username, password=password) 10 | 11 | 12 | # for testing 13 | if __name__ == "__main__": 14 | api = Rmc_API() 15 | api.do_stuff() 16 | -------------------------------------------------------------------------------- /src/redfish/ris/sharedtypes.py: -------------------------------------------------------------------------------- 1 | ### 2 | # Copyright 2020 Hewlett Packard Enterprise, Inc. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ### 16 | 17 | # -*- coding: utf-8 -*- 18 | """Shared types used in this library.""" 19 | 20 | # ---------Imports--------- 21 | 22 | import logging 23 | 24 | import jsonpatch 25 | 26 | from redfish.rest.containers import JSONEncoder 27 | 28 | # ---------End of imports--------- 29 | 30 | # ---------Debug logger--------- 31 | 32 | LOGGER = logging.getLogger(__name__) 33 | 34 | # ---------End of debug logger--------- 35 | 36 | 37 | class JSONEncoder(JSONEncoder): 38 | """Custom JSONEncoder that understands our types""" 39 | 40 | def default(self, obj): 41 | """Set defaults 42 | 43 | :param obj: json object. 44 | :type obj: str. 45 | 46 | """ 47 | if isinstance(obj, Dictable): 48 | return obj.to_dict() 49 | elif isinstance(obj, set): 50 | return list(obj) 51 | elif isinstance(obj, jsonpatch.JsonPatch): 52 | return obj.patch 53 | return super(JSONEncoder, self).default(obj) 54 | 55 | 56 | class Dictable(object): 57 | """A base class which adds the to_dict method used during json encoding""" 58 | 59 | def to_dict(self): 60 | """Overridable funciton""" 61 | raise RuntimeError("You must override this method in your derived class") 62 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | # tox (https://tox.readthedocs.io/) is a tool for running tests 2 | # in multiple virtualenvs. This configuration file will run the 3 | # test suite on all supported python versions. To use it, "pip install tox" 4 | # and then run "tox" from this directory. 5 | 6 | [tox] 7 | envlist = py27, pylint, py3 8 | skipsdist=True 9 | 10 | [testenv:py27] 11 | changedir = tests 12 | deps = 13 | pytest 14 | mock 15 | commands = pytest --junit-xml={toxinidir}/python2.xml 16 | 17 | [testenv:py3] 18 | changedir = tests 19 | deps = pytest 20 | commands = pytest --junit-xml={toxinidir}/python3.xml 21 | 22 | [testenv:pylint] 23 | deps = pylint==1.6.1 24 | commands = - bash {toxinidir}/pylint.sh 25 | 26 | [flake8] 27 | max-line-length = 120 28 | extend-ignore = E203 29 | --------------------------------------------------------------------------------