Overview:
The DMTF / python-redfish-library (or redfish) is an open source provide python library for management engineer who can write a python programming to manage the hardware which support DMTF redfish interface.
Purpose:
This article introduces how to install the DMTF / python-redfish-library and some examples to run it on Windows 10.
Target Audience:
For those engineer(s) whom will use redfish to manage the hardware which support DMTF redfish interface and have python programming experience. As of version 3.0.0, Python2 is no longer supported. Please use Python3 is required if redfish>=3.0.0.
Pre-requirement:
1. Windows 10 with the latest security update.
2. Install the python3 on Windows 10. Please click How to install python3 and pip on Windows 10?
3. Option: if you prefer to run the redfishtool in a python virtualenv. Please click How to install VirtualEnv & Activate of python3 on Windows 10? This is not mandatory. Just for those whom want to isolate the environment with other python project(s).
Procedures:
In this article, we are using the python virtualenv to install redfish development library and run it. You can by pass the virtualenv portion if you do not want to do it in virtualenv).
Installation:
redfish version >=3.0.0 development library is based on Python 3 and the client system is required to have the Python framework installed before the tool can be installed and executed on the system.
There are couple ways to install redfish. In this article, here is the way to use pip installation.
Option: python virtualenv [venv]
In this article, we use redfish as [venv]
# Activate the virtualenv redfish
PS C:\Users\[username]> redfish\Scripts\activate
(redfish) PS C:\Users\[username]>
# Install redfish in virtualenv
(redfish) PS C:\Users\[username]> pip install redfish
Collecting redfish
Downloading redfish-3.0.1-py3-none-any.whl (39 kB)
Collecting jsonpointer
Downloading jsonpointer-2.1-py2.py3-none-any.whl (7.4 kB)
Collecting jsonpatch
Downloading jsonpatch-1.32-py2.py3-none-any.whl (12 kB)
Collecting jsonpath-rw
Downloading jsonpath-rw-1.4.0.tar.gz (13 kB)
Collecting ply
Downloading ply-3.11-py2.py3-none-any.whl (49 kB)
|████████████████████████████████| 49 kB 964 kB/s
Collecting decorator
Downloading decorator-5.0.9-py3-none-any.whl (8.9 kB)
Requirement already satisfied: six in c:\users\[username]\redfish\lib\site-packages (from jsonpath-rw->redfish) (1.16.0)
Building wheels for collected packages: jsonpath-rw
Building wheel for jsonpath-rw (setup.py) ... done
Created wheel for jsonpath-rw: filename=jsonpath_rw-1.4.0-py3-none-any.whl size=15144 sha256=8d72281a3757e3c2e81b15237d6bea1154c6910e733679b8e2342c2d09aebb78
Stored in directory: c:\users\[username]\appdata\local\pip\cache\wheels\04\56\46\9ae68fd2e2115ef977e84ce5b86440421eba7059b36eeea416
Successfully built jsonpath-rw
Installing collected packages: ply, jsonpointer, decorator, jsonpath-rw, jsonpatch, redfish
Successfully installed decorator-5.0.9 jsonpatch-1.32 jsonpath-rw-1.4.0 jsonpointer-2.1 ply-3.11 redfish-3.0.1
(redfish) PS C:\Users\[username]>
Test:
1. Test by Python 3 interactive mode
(redfish) PS C:\Users\[username]> python
Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import redfish
>>> REDFISH_OBJ = redfish.redfish_client(base_url='https://172.17.21.120', username='administrator', password='advantech', default_prefix='/redfish/v1')
>>> REDFISH_OBJ.login(auth="session")
>>> response = REDFISH_OBJ.get("/redfish/v1/Systems/0/EthernetInterfaces", None)
>>> sys.stdout.write("%s\n" % response)
200
OData-Version 4.0
X-Auth-Token b715fb67a4f934f5884706e2903506c3
Etag W/"acca4fbbc351364c"
WWW-Authenticate Basic realm="administrator"
Allow GET
Cache-Control no-cache
Access-Control-Allow-Origin *
Content-Type application/json
Strict-Transport-Security max-age=6307200; includeSubdomains;
X-Frame-Options DENY
Content-Security-Policy frame-ancestors 'none'
Content-Length 665
Date Sun, 11 Jul 2021 10:58:37 GMT
Server lighttpd
{
"@odata.type": "#EthernetInterfaceCollection.EthernetInterfaceCollection",
"@odata.context": "/redfish/v1/$metadata/EthernetInterfaceCollection.EthernetInterfaceCollection",
"@odata.id": "/redfish/v1/Systems/0/EthernetInterfaces",
"@odata.etag": "W/\"acca4fbbc351364c\"",
"Name": "Ethernet Interface Collection",
"Description": "System NICs",
"Members@odata.count": 4,
"Members": [{
"@odata.id": "/redfish/v1/Systems/0/EthernetInterfaces/0"
}, {
"@odata.id": "/redfish/v1/Systems/0/EthernetInterfaces/1"
}, {
"@odata.id": "/redfish/v1/Systems/0/EthernetInterfaces/2"
}, {
"@odata.id": "/redfish/v1/Systems/0/EthernetInterfaces/3"
}]
}
>>> REDFISH_OBJ.logout()
>>> quit()
(redfish) PS C:\Users\[username]>
2. Test via a .py file:
(redfish) PS C:\Users\[username]> cat .\redfish\quickstart.py
import sys
import redfish
login_host = "https://172.17.21.120"
login_account = "administrator"
login_password = "advantech"
## Create a REDFISH object
REDFISH_OBJ = redfish.redfish_client(base_url=login_host, username=login_account,
password=login_password, default_prefix='/redfish/v1')
# Login into the server and create a session
REDFISH_OBJ.login(auth="session")
# Do a GET on a given path
response = REDFISH_OBJ.get("/redfish/v1/Systems/0/EthernetInterfaces", None)
# Print out the response
sys.stdout.write("%s\n" % response)
# Logout of the current session
REDFISH_OBJ.logout()
(redfish) PS C:\Users\[username]> python .\redfish\quickstart.py
200
OData-Version 4.0
X-Auth-Token ecd5e3d33496b407013a6df07685979d
Etag W/"acca4fbbc351364c"
WWW-Authenticate Basic realm="administrator"
Allow GET
Cache-Control no-cache
Access-Control-Allow-Origin *
Content-Type application/json
Strict-Transport-Security max-age=6307200; includeSubdomains;
X-Frame-Options DENY
Content-Security-Policy frame-ancestors 'none'
Content-Length 665
Date Sun, 11 Jul 2021 11:12:11 GMT
Server lighttpd
{
"@odata.type": "#EthernetInterfaceCollection.EthernetInterfaceCollection",
"@odata.context": "/redfish/v1/$metadata/EthernetInterfaceCollection.EthernetInterfaceCollection",
"@odata.id": "/redfish/v1/Systems/0/EthernetInterfaces",
"@odata.etag": "W/\"acca4fbbc351364c\"",
"Name": "Ethernet Interface Collection",
"Description": "System NICs",
"Members@odata.count": 4,
"Members": [{
"@odata.id": "/redfish/v1/Systems/0/EthernetInterfaces/0"
}, {
"@odata.id": "/redfish/v1/Systems/0/EthernetInterfaces/1"
}, {
"@odata.id": "/redfish/v1/Systems/0/EthernetInterfaces/2"
}, {
"@odata.id": "/redfish/v1/Systems/0/EthernetInterfaces/3"
}]
}
(redfish) PS C:\Users\[username]>
For more detail about how to use redfishtool, please refer the the following official github site:
https://github.com/DMTF/python-redfish-library
--- End of this article ---
Comments
0 comments
Please sign in to leave a comment.