redfish-python-sdk 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. redfish_python_sdk-1.0.0/LICENSE +29 -0
  2. redfish_python_sdk-1.0.0/PKG-INFO +164 -0
  3. redfish_python_sdk-1.0.0/README.md +99 -0
  4. redfish_python_sdk-1.0.0/pyproject.toml +80 -0
  5. redfish_python_sdk-1.0.0/redfish_python_sdk.egg-info/PKG-INFO +164 -0
  6. redfish_python_sdk-1.0.0/redfish_python_sdk.egg-info/SOURCES.txt +68 -0
  7. redfish_python_sdk-1.0.0/redfish_python_sdk.egg-info/dependency_links.txt +1 -0
  8. redfish_python_sdk-1.0.0/redfish_python_sdk.egg-info/requires.txt +7 -0
  9. redfish_python_sdk-1.0.0/redfish_python_sdk.egg-info/top_level.txt +1 -0
  10. redfish_python_sdk-1.0.0/redfish_sdk/__init__.py +63 -0
  11. redfish_python_sdk-1.0.0/redfish_sdk/client.py +1894 -0
  12. redfish_python_sdk-1.0.0/redfish_sdk/exceptions.py +56 -0
  13. redfish_python_sdk-1.0.0/redfish_sdk/http_client.py +452 -0
  14. redfish_python_sdk-1.0.0/redfish_sdk/managers/__init__.py +21 -0
  15. redfish_python_sdk-1.0.0/redfish_sdk/managers/_log_helpers.py +144 -0
  16. redfish_python_sdk-1.0.0/redfish_sdk/managers/account.py +96 -0
  17. redfish_python_sdk-1.0.0/redfish_sdk/managers/chassis.py +327 -0
  18. redfish_python_sdk-1.0.0/redfish_sdk/managers/event.py +264 -0
  19. redfish_python_sdk-1.0.0/redfish_sdk/managers/managers.py +120 -0
  20. redfish_python_sdk-1.0.0/redfish_sdk/managers/registries.py +48 -0
  21. redfish_python_sdk-1.0.0/redfish_sdk/managers/session.py +130 -0
  22. redfish_python_sdk-1.0.0/redfish_sdk/managers/systems.py +630 -0
  23. redfish_python_sdk-1.0.0/redfish_sdk/managers/task.py +89 -0
  24. redfish_python_sdk-1.0.0/redfish_sdk/managers/update.py +99 -0
  25. redfish_python_sdk-1.0.0/redfish_sdk/managers/update_strategies/__init__.py +51 -0
  26. redfish_python_sdk-1.0.0/redfish_sdk/managers/update_strategies/base.py +101 -0
  27. redfish_python_sdk-1.0.0/redfish_sdk/managers/update_strategies/h3c.py +140 -0
  28. redfish_python_sdk-1.0.0/redfish_sdk/managers/update_strategies/inspur.py +89 -0
  29. redfish_python_sdk-1.0.0/redfish_sdk/managers/update_strategies/lenovo.py +59 -0
  30. redfish_python_sdk-1.0.0/redfish_sdk/managers/update_strategies/nettrix.py +56 -0
  31. redfish_python_sdk-1.0.0/redfish_sdk/managers/update_strategies/registry.py +72 -0
  32. redfish_python_sdk-1.0.0/redfish_sdk/managers/update_strategies/vendor_detect.py +111 -0
  33. redfish_python_sdk-1.0.0/redfish_sdk/managers/update_strategies/xfusion.py +60 -0
  34. redfish_python_sdk-1.0.0/redfish_sdk/managers/update_strategies/zte.py +68 -0
  35. redfish_python_sdk-1.0.0/redfish_sdk/models/__init__.py +55 -0
  36. redfish_python_sdk-1.0.0/redfish_sdk/models/account.py +60 -0
  37. redfish_python_sdk-1.0.0/redfish_sdk/models/chassis.py +86 -0
  38. redfish_python_sdk-1.0.0/redfish_sdk/models/check.py +231 -0
  39. redfish_python_sdk-1.0.0/redfish_sdk/models/common.py +102 -0
  40. redfish_python_sdk-1.0.0/redfish_sdk/models/drive.py +53 -0
  41. redfish_python_sdk-1.0.0/redfish_sdk/models/event.py +64 -0
  42. redfish_python_sdk-1.0.0/redfish_sdk/models/fru.py +59 -0
  43. redfish_python_sdk-1.0.0/redfish_sdk/models/gpu.py +33 -0
  44. redfish_python_sdk-1.0.0/redfish_sdk/models/logs.py +56 -0
  45. redfish_python_sdk-1.0.0/redfish_sdk/models/managers.py +153 -0
  46. redfish_python_sdk-1.0.0/redfish_sdk/models/memory.py +50 -0
  47. redfish_python_sdk-1.0.0/redfish_sdk/models/network_adapter.py +76 -0
  48. redfish_python_sdk-1.0.0/redfish_sdk/models/oem.py +173 -0
  49. redfish_python_sdk-1.0.0/redfish_sdk/models/pcie_device.py +89 -0
  50. redfish_python_sdk-1.0.0/redfish_sdk/models/power.py +92 -0
  51. redfish_python_sdk-1.0.0/redfish_sdk/models/processor.py +50 -0
  52. redfish_python_sdk-1.0.0/redfish_sdk/models/registry.py +34 -0
  53. redfish_python_sdk-1.0.0/redfish_sdk/models/resource_key.py +70 -0
  54. redfish_python_sdk-1.0.0/redfish_sdk/models/root.py +50 -0
  55. redfish_python_sdk-1.0.0/redfish_sdk/models/session.py +42 -0
  56. redfish_python_sdk-1.0.0/redfish_sdk/models/storage.py +77 -0
  57. redfish_python_sdk-1.0.0/redfish_sdk/models/systems.py +194 -0
  58. redfish_python_sdk-1.0.0/redfish_sdk/models/task.py +54 -0
  59. redfish_python_sdk-1.0.0/redfish_sdk/models/thermal.py +111 -0
  60. redfish_python_sdk-1.0.0/redfish_sdk/models/update.py +55 -0
  61. redfish_python_sdk-1.0.0/setup.cfg +4 -0
  62. redfish_python_sdk-1.0.0/tests/test_client_mock.py +201 -0
  63. redfish_python_sdk-1.0.0/tests/test_log_entries_mock.py +416 -0
  64. redfish_python_sdk-1.0.0/tests/test_models.py +223 -0
  65. redfish_python_sdk-1.0.0/tests/test_models_mock.py +1462 -0
  66. redfish_python_sdk-1.0.0/tests/test_offline_json.py +347 -0
  67. redfish_python_sdk-1.0.0/tests/test_real_bmc.py +222 -0
  68. redfish_python_sdk-1.0.0/tests/test_sdk_mock.py +1650 -0
  69. redfish_python_sdk-1.0.0/tests/test_update_strategies.py +536 -0
  70. redfish_python_sdk-1.0.0/tests/test_v1_1_apis_mock.py +920 -0
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2025-present, Xingyin Information Technology Co., Ltd.
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,164 @@
1
+ Metadata-Version: 2.4
2
+ Name: redfish-python-sdk
3
+ Version: 1.0.0
4
+ Summary: A Python SDK for interacting with Redfish-compliant BMC endpoints
5
+ Author: RedNote Infrastructure
6
+ License: BSD 3-Clause License
7
+
8
+ Copyright (c) 2025-present, Xingyin Information Technology Co., Ltd.
9
+ All rights reserved.
10
+
11
+ Redistribution and use in source and binary forms, with or without
12
+ modification, are permitted provided that the following conditions are met:
13
+
14
+ 1. Redistributions of source code must retain the above copyright notice, this
15
+ list of conditions and the following disclaimer.
16
+
17
+ 2. Redistributions in binary form must reproduce the above copyright notice,
18
+ this list of conditions and the following disclaimer in the documentation
19
+ and/or other materials provided with the distribution.
20
+
21
+ 3. Neither the name of the copyright holder nor the names of its
22
+ contributors may be used to endorse or promote products derived from
23
+ this software without specific prior written permission.
24
+
25
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
+
36
+ Project-URL: Homepage, https://github.com/rednote-infra/redfish-python-sdk
37
+ Project-URL: Repository, https://github.com/rednote-infra/redfish-python-sdk
38
+ Project-URL: Issues, https://github.com/rednote-infra/redfish-python-sdk/issues
39
+ Project-URL: Changelog, https://github.com/rednote-infra/redfish-python-sdk/blob/main/CHANGELOG.md
40
+ Keywords: redfish,bmc,ipmi,server,oob
41
+ Classifier: Development Status :: 4 - Beta
42
+ Classifier: Intended Audience :: System Administrators
43
+ Classifier: Intended Audience :: Developers
44
+ Classifier: License :: OSI Approved :: BSD License
45
+ Classifier: Programming Language :: Python :: 3
46
+ Classifier: Programming Language :: Python :: 3.9
47
+ Classifier: Programming Language :: Python :: 3.10
48
+ Classifier: Programming Language :: Python :: 3.11
49
+ Classifier: Programming Language :: Python :: 3.12
50
+ Classifier: Programming Language :: Python :: 3.13
51
+ Classifier: Topic :: System :: Hardware
52
+ Classifier: Topic :: System :: Networking
53
+ Classifier: Topic :: System :: Systems Administration
54
+ Classifier: Typing :: Typed
55
+ Requires-Python: >=3.9
56
+ Description-Content-Type: text/markdown
57
+ License-File: LICENSE
58
+ Requires-Dist: requests>=2.31.0
59
+ Requires-Dist: pydantic>=2.5.0
60
+ Requires-Dist: urllib3>=2.0.0
61
+ Provides-Extra: dev
62
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
63
+ Requires-Dist: ruff>=0.4.0; extra == "dev"
64
+ Dynamic: license-file
65
+
66
+ # Redfish Python SDK
67
+
68
+ [English](README.md) | [中文](README_zh.md)
69
+
70
+ > A lightweight Python SDK for managing server BMCs (Baseboard Management Controllers) via the [DMTF Redfish](https://www.dmtf.org/standards/redfish) protocol. Covers system inventory, hardware inspection, power control, boot management, event subscriptions, and more.
71
+
72
+ ## Features
73
+
74
+ - **Comprehensive hardware queries** — CPU, memory, drives, GPU, NIC, PCIe, PSU, fans — one line of code each
75
+ - **Power & boot management** — power on/off, restart, PXE/HDD/BIOS boot source switching
76
+ - **Multi-vendor compatible** — auto-adapts to OEM extensions from Huawei, xFusion, Lenovo, HPE, Dell, and others
77
+ - **Pydantic v2 models** — all return values are strongly-typed objects with full IDE autocompletion
78
+ - **Context manager** — `with` statement support for automatic connection cleanup
79
+ - **Minimal dependencies** — only `requests`, `pydantic`, and `urllib3`
80
+
81
+ ## Requirements
82
+
83
+ - Python >= 3.9
84
+ - A network-reachable Redfish-compliant BMC endpoint
85
+
86
+ ## Installation
87
+
88
+ ```bash
89
+ # Install from PyPI
90
+ pip install redfish-python-sdk
91
+
92
+ # Or install from GitHub
93
+ pip install git+https://github.com/rednote-infra/redfish-python-sdk.git
94
+
95
+ # Install a specific version
96
+ pip install redfish-python-sdk==1.0.0
97
+ pip install git+https://github.com/rednote-infra/redfish-python-sdk.git@v1.0.0
98
+
99
+ # In requirements.txt
100
+ # redfish-python-sdk>=1.0.0
101
+ ```
102
+
103
+ ## Quick Start
104
+
105
+ > **Credential management**: All BMC credentials should be injected via environment variables. **Never** hardcode them in your source code.
106
+ > Before running examples or tests, set `export BMC_IP=...`, `export BMC_USER=...`, `export BMC_PASSWORD=...`.
107
+
108
+ ```python
109
+ import os
110
+ from redfish_sdk import RedfishClient
111
+
112
+ # Connect to BMC (credentials from environment variables)
113
+ client = RedfishClient(
114
+ host=os.environ["BMC_IP"],
115
+ username=os.environ["BMC_USER"],
116
+ password=os.environ["BMC_PASSWORD"],
117
+ )
118
+
119
+ # Get system info
120
+ system = client.systems.get()
121
+ print(f"Server: {system.manufacturer} {system.model}")
122
+ print(f"SN: {system.serial_number}")
123
+ print(f"Power: {system.power_state}")
124
+
125
+ # Get CPU info
126
+ for cpu in client.get_processors():
127
+ print(f"CPU: {cpu.model}, {cpu.total_cores} cores / {cpu.total_threads} threads")
128
+
129
+ # Get memory info
130
+ for mem in client.get_memory():
131
+ print(f"DIMM: {mem.manufacturer} {(mem.capacity_mib or 0) // 1024} GB")
132
+
133
+ # Get drive info
134
+ for drive in client.get_drives():
135
+ print(f"Drive: {drive.model} {(drive.capacity_bytes or 0) / 1e12:.1f} TB")
136
+
137
+ # Don't forget to close
138
+ client.close()
139
+ ```
140
+
141
+ ## Testing
142
+
143
+ ```bash
144
+ # Run unit tests (no BMC or env vars required)
145
+ pytest tests/test_models_mock.py tests/test_client_mock.py -v
146
+
147
+ # Run offline tests (using pre-collected JSON data)
148
+ export REDFISH_JSON_DIR="./testdata"
149
+ pytest tests/test_offline_json.py -v
150
+
151
+ # Run integration tests (requires a real BMC)
152
+ export BMC_IP="<your-bmc-ip>"
153
+ export BMC_USER="<your-bmc-user>"
154
+ export BMC_PASSWORD="<your-bmc-password>"
155
+ pytest tests/test_real_bmc.py -v
156
+ ```
157
+
158
+ ## Contributing
159
+
160
+ Contributions are welcome! Please feel free to submit a Pull Request.
161
+
162
+ ## License
163
+
164
+ This project is licensed under the [BSD 3-Clause License](LICENSE).
@@ -0,0 +1,99 @@
1
+ # Redfish Python SDK
2
+
3
+ [English](README.md) | [中文](README_zh.md)
4
+
5
+ > A lightweight Python SDK for managing server BMCs (Baseboard Management Controllers) via the [DMTF Redfish](https://www.dmtf.org/standards/redfish) protocol. Covers system inventory, hardware inspection, power control, boot management, event subscriptions, and more.
6
+
7
+ ## Features
8
+
9
+ - **Comprehensive hardware queries** — CPU, memory, drives, GPU, NIC, PCIe, PSU, fans — one line of code each
10
+ - **Power & boot management** — power on/off, restart, PXE/HDD/BIOS boot source switching
11
+ - **Multi-vendor compatible** — auto-adapts to OEM extensions from Huawei, xFusion, Lenovo, HPE, Dell, and others
12
+ - **Pydantic v2 models** — all return values are strongly-typed objects with full IDE autocompletion
13
+ - **Context manager** — `with` statement support for automatic connection cleanup
14
+ - **Minimal dependencies** — only `requests`, `pydantic`, and `urllib3`
15
+
16
+ ## Requirements
17
+
18
+ - Python >= 3.9
19
+ - A network-reachable Redfish-compliant BMC endpoint
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ # Install from PyPI
25
+ pip install redfish-python-sdk
26
+
27
+ # Or install from GitHub
28
+ pip install git+https://github.com/rednote-infra/redfish-python-sdk.git
29
+
30
+ # Install a specific version
31
+ pip install redfish-python-sdk==1.0.0
32
+ pip install git+https://github.com/rednote-infra/redfish-python-sdk.git@v1.0.0
33
+
34
+ # In requirements.txt
35
+ # redfish-python-sdk>=1.0.0
36
+ ```
37
+
38
+ ## Quick Start
39
+
40
+ > **Credential management**: All BMC credentials should be injected via environment variables. **Never** hardcode them in your source code.
41
+ > Before running examples or tests, set `export BMC_IP=...`, `export BMC_USER=...`, `export BMC_PASSWORD=...`.
42
+
43
+ ```python
44
+ import os
45
+ from redfish_sdk import RedfishClient
46
+
47
+ # Connect to BMC (credentials from environment variables)
48
+ client = RedfishClient(
49
+ host=os.environ["BMC_IP"],
50
+ username=os.environ["BMC_USER"],
51
+ password=os.environ["BMC_PASSWORD"],
52
+ )
53
+
54
+ # Get system info
55
+ system = client.systems.get()
56
+ print(f"Server: {system.manufacturer} {system.model}")
57
+ print(f"SN: {system.serial_number}")
58
+ print(f"Power: {system.power_state}")
59
+
60
+ # Get CPU info
61
+ for cpu in client.get_processors():
62
+ print(f"CPU: {cpu.model}, {cpu.total_cores} cores / {cpu.total_threads} threads")
63
+
64
+ # Get memory info
65
+ for mem in client.get_memory():
66
+ print(f"DIMM: {mem.manufacturer} {(mem.capacity_mib or 0) // 1024} GB")
67
+
68
+ # Get drive info
69
+ for drive in client.get_drives():
70
+ print(f"Drive: {drive.model} {(drive.capacity_bytes or 0) / 1e12:.1f} TB")
71
+
72
+ # Don't forget to close
73
+ client.close()
74
+ ```
75
+
76
+ ## Testing
77
+
78
+ ```bash
79
+ # Run unit tests (no BMC or env vars required)
80
+ pytest tests/test_models_mock.py tests/test_client_mock.py -v
81
+
82
+ # Run offline tests (using pre-collected JSON data)
83
+ export REDFISH_JSON_DIR="./testdata"
84
+ pytest tests/test_offline_json.py -v
85
+
86
+ # Run integration tests (requires a real BMC)
87
+ export BMC_IP="<your-bmc-ip>"
88
+ export BMC_USER="<your-bmc-user>"
89
+ export BMC_PASSWORD="<your-bmc-password>"
90
+ pytest tests/test_real_bmc.py -v
91
+ ```
92
+
93
+ ## Contributing
94
+
95
+ Contributions are welcome! Please feel free to submit a Pull Request.
96
+
97
+ ## License
98
+
99
+ This project is licensed under the [BSD 3-Clause License](LICENSE).
@@ -0,0 +1,80 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "redfish-python-sdk"
7
+ version = "1.0.0"
8
+ description = "A Python SDK for interacting with Redfish-compliant BMC endpoints"
9
+ requires-python = ">=3.9"
10
+ readme = "README.md"
11
+ license = {file = "LICENSE"}
12
+ authors = [
13
+ {name = "RedNote Infrastructure"},
14
+ ]
15
+ keywords = ["redfish", "bmc", "ipmi", "server", "oob"]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Intended Audience :: System Administrators",
19
+ "Intended Audience :: Developers",
20
+ "License :: OSI Approved :: BSD License",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3.9",
23
+ "Programming Language :: Python :: 3.10",
24
+ "Programming Language :: Python :: 3.11",
25
+ "Programming Language :: Python :: 3.12",
26
+ "Programming Language :: Python :: 3.13",
27
+ "Topic :: System :: Hardware",
28
+ "Topic :: System :: Networking",
29
+ "Topic :: System :: Systems Administration",
30
+ "Typing :: Typed",
31
+ ]
32
+ dependencies = [
33
+ "requests>=2.31.0",
34
+ "pydantic>=2.5.0",
35
+ "urllib3>=2.0.0",
36
+ ]
37
+
38
+ [project.optional-dependencies]
39
+ dev = [
40
+ "pytest>=7.0.0",
41
+ "ruff>=0.4.0",
42
+ ]
43
+
44
+ [project.urls]
45
+ Homepage = "https://github.com/rednote-infra/redfish-python-sdk"
46
+ Repository = "https://github.com/rednote-infra/redfish-python-sdk"
47
+ Issues = "https://github.com/rednote-infra/redfish-python-sdk/issues"
48
+ Changelog = "https://github.com/rednote-infra/redfish-python-sdk/blob/main/CHANGELOG.md"
49
+
50
+ [tool.setuptools.packages.find]
51
+ include = ["redfish_sdk*"]
52
+
53
+ [tool.pytest.ini_options]
54
+ testpaths = ["tests"]
55
+
56
+ [tool.ruff]
57
+ target-version = "py39"
58
+ line-length = 120
59
+
60
+ [tool.ruff.lint]
61
+ select = [
62
+ "E", # pycodestyle errors
63
+ "W", # pycodestyle warnings
64
+ "F", # pyflakes
65
+ "I", # isort
66
+ "UP", # pyupgrade
67
+ "B", # flake8-bugbear
68
+ "SIM", # flake8-simplify
69
+ ]
70
+ ignore = [
71
+ "E501", # 行长由 formatter 控制
72
+ "UP006", # Use `list` instead of `List` — 保持 typing.List 以兼容 Python 3.9 运行时
73
+ "UP007", # Use `X | Y` instead of `Union[X, Y]` — 同上
74
+ "UP035", # `typing.List` is deprecated — 同上
75
+ "UP045", # Use `X | None` instead of `Optional[X]` — 同上,pydantic v2 在 3.9 运行时需要 Optional
76
+ "SIM105", # Use contextlib.suppress — 可读性偏好
77
+ ]
78
+
79
+ [tool.ruff.lint.isort]
80
+ known-first-party = ["redfish_sdk"]
@@ -0,0 +1,164 @@
1
+ Metadata-Version: 2.4
2
+ Name: redfish-python-sdk
3
+ Version: 1.0.0
4
+ Summary: A Python SDK for interacting with Redfish-compliant BMC endpoints
5
+ Author: RedNote Infrastructure
6
+ License: BSD 3-Clause License
7
+
8
+ Copyright (c) 2025-present, Xingyin Information Technology Co., Ltd.
9
+ All rights reserved.
10
+
11
+ Redistribution and use in source and binary forms, with or without
12
+ modification, are permitted provided that the following conditions are met:
13
+
14
+ 1. Redistributions of source code must retain the above copyright notice, this
15
+ list of conditions and the following disclaimer.
16
+
17
+ 2. Redistributions in binary form must reproduce the above copyright notice,
18
+ this list of conditions and the following disclaimer in the documentation
19
+ and/or other materials provided with the distribution.
20
+
21
+ 3. Neither the name of the copyright holder nor the names of its
22
+ contributors may be used to endorse or promote products derived from
23
+ this software without specific prior written permission.
24
+
25
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
+
36
+ Project-URL: Homepage, https://github.com/rednote-infra/redfish-python-sdk
37
+ Project-URL: Repository, https://github.com/rednote-infra/redfish-python-sdk
38
+ Project-URL: Issues, https://github.com/rednote-infra/redfish-python-sdk/issues
39
+ Project-URL: Changelog, https://github.com/rednote-infra/redfish-python-sdk/blob/main/CHANGELOG.md
40
+ Keywords: redfish,bmc,ipmi,server,oob
41
+ Classifier: Development Status :: 4 - Beta
42
+ Classifier: Intended Audience :: System Administrators
43
+ Classifier: Intended Audience :: Developers
44
+ Classifier: License :: OSI Approved :: BSD License
45
+ Classifier: Programming Language :: Python :: 3
46
+ Classifier: Programming Language :: Python :: 3.9
47
+ Classifier: Programming Language :: Python :: 3.10
48
+ Classifier: Programming Language :: Python :: 3.11
49
+ Classifier: Programming Language :: Python :: 3.12
50
+ Classifier: Programming Language :: Python :: 3.13
51
+ Classifier: Topic :: System :: Hardware
52
+ Classifier: Topic :: System :: Networking
53
+ Classifier: Topic :: System :: Systems Administration
54
+ Classifier: Typing :: Typed
55
+ Requires-Python: >=3.9
56
+ Description-Content-Type: text/markdown
57
+ License-File: LICENSE
58
+ Requires-Dist: requests>=2.31.0
59
+ Requires-Dist: pydantic>=2.5.0
60
+ Requires-Dist: urllib3>=2.0.0
61
+ Provides-Extra: dev
62
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
63
+ Requires-Dist: ruff>=0.4.0; extra == "dev"
64
+ Dynamic: license-file
65
+
66
+ # Redfish Python SDK
67
+
68
+ [English](README.md) | [中文](README_zh.md)
69
+
70
+ > A lightweight Python SDK for managing server BMCs (Baseboard Management Controllers) via the [DMTF Redfish](https://www.dmtf.org/standards/redfish) protocol. Covers system inventory, hardware inspection, power control, boot management, event subscriptions, and more.
71
+
72
+ ## Features
73
+
74
+ - **Comprehensive hardware queries** — CPU, memory, drives, GPU, NIC, PCIe, PSU, fans — one line of code each
75
+ - **Power & boot management** — power on/off, restart, PXE/HDD/BIOS boot source switching
76
+ - **Multi-vendor compatible** — auto-adapts to OEM extensions from Huawei, xFusion, Lenovo, HPE, Dell, and others
77
+ - **Pydantic v2 models** — all return values are strongly-typed objects with full IDE autocompletion
78
+ - **Context manager** — `with` statement support for automatic connection cleanup
79
+ - **Minimal dependencies** — only `requests`, `pydantic`, and `urllib3`
80
+
81
+ ## Requirements
82
+
83
+ - Python >= 3.9
84
+ - A network-reachable Redfish-compliant BMC endpoint
85
+
86
+ ## Installation
87
+
88
+ ```bash
89
+ # Install from PyPI
90
+ pip install redfish-python-sdk
91
+
92
+ # Or install from GitHub
93
+ pip install git+https://github.com/rednote-infra/redfish-python-sdk.git
94
+
95
+ # Install a specific version
96
+ pip install redfish-python-sdk==1.0.0
97
+ pip install git+https://github.com/rednote-infra/redfish-python-sdk.git@v1.0.0
98
+
99
+ # In requirements.txt
100
+ # redfish-python-sdk>=1.0.0
101
+ ```
102
+
103
+ ## Quick Start
104
+
105
+ > **Credential management**: All BMC credentials should be injected via environment variables. **Never** hardcode them in your source code.
106
+ > Before running examples or tests, set `export BMC_IP=...`, `export BMC_USER=...`, `export BMC_PASSWORD=...`.
107
+
108
+ ```python
109
+ import os
110
+ from redfish_sdk import RedfishClient
111
+
112
+ # Connect to BMC (credentials from environment variables)
113
+ client = RedfishClient(
114
+ host=os.environ["BMC_IP"],
115
+ username=os.environ["BMC_USER"],
116
+ password=os.environ["BMC_PASSWORD"],
117
+ )
118
+
119
+ # Get system info
120
+ system = client.systems.get()
121
+ print(f"Server: {system.manufacturer} {system.model}")
122
+ print(f"SN: {system.serial_number}")
123
+ print(f"Power: {system.power_state}")
124
+
125
+ # Get CPU info
126
+ for cpu in client.get_processors():
127
+ print(f"CPU: {cpu.model}, {cpu.total_cores} cores / {cpu.total_threads} threads")
128
+
129
+ # Get memory info
130
+ for mem in client.get_memory():
131
+ print(f"DIMM: {mem.manufacturer} {(mem.capacity_mib or 0) // 1024} GB")
132
+
133
+ # Get drive info
134
+ for drive in client.get_drives():
135
+ print(f"Drive: {drive.model} {(drive.capacity_bytes or 0) / 1e12:.1f} TB")
136
+
137
+ # Don't forget to close
138
+ client.close()
139
+ ```
140
+
141
+ ## Testing
142
+
143
+ ```bash
144
+ # Run unit tests (no BMC or env vars required)
145
+ pytest tests/test_models_mock.py tests/test_client_mock.py -v
146
+
147
+ # Run offline tests (using pre-collected JSON data)
148
+ export REDFISH_JSON_DIR="./testdata"
149
+ pytest tests/test_offline_json.py -v
150
+
151
+ # Run integration tests (requires a real BMC)
152
+ export BMC_IP="<your-bmc-ip>"
153
+ export BMC_USER="<your-bmc-user>"
154
+ export BMC_PASSWORD="<your-bmc-password>"
155
+ pytest tests/test_real_bmc.py -v
156
+ ```
157
+
158
+ ## Contributing
159
+
160
+ Contributions are welcome! Please feel free to submit a Pull Request.
161
+
162
+ ## License
163
+
164
+ This project is licensed under the [BSD 3-Clause License](LICENSE).
@@ -0,0 +1,68 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ redfish_python_sdk.egg-info/PKG-INFO
5
+ redfish_python_sdk.egg-info/SOURCES.txt
6
+ redfish_python_sdk.egg-info/dependency_links.txt
7
+ redfish_python_sdk.egg-info/requires.txt
8
+ redfish_python_sdk.egg-info/top_level.txt
9
+ redfish_sdk/__init__.py
10
+ redfish_sdk/client.py
11
+ redfish_sdk/exceptions.py
12
+ redfish_sdk/http_client.py
13
+ redfish_sdk/managers/__init__.py
14
+ redfish_sdk/managers/_log_helpers.py
15
+ redfish_sdk/managers/account.py
16
+ redfish_sdk/managers/chassis.py
17
+ redfish_sdk/managers/event.py
18
+ redfish_sdk/managers/managers.py
19
+ redfish_sdk/managers/registries.py
20
+ redfish_sdk/managers/session.py
21
+ redfish_sdk/managers/systems.py
22
+ redfish_sdk/managers/task.py
23
+ redfish_sdk/managers/update.py
24
+ redfish_sdk/managers/update_strategies/__init__.py
25
+ redfish_sdk/managers/update_strategies/base.py
26
+ redfish_sdk/managers/update_strategies/h3c.py
27
+ redfish_sdk/managers/update_strategies/inspur.py
28
+ redfish_sdk/managers/update_strategies/lenovo.py
29
+ redfish_sdk/managers/update_strategies/nettrix.py
30
+ redfish_sdk/managers/update_strategies/registry.py
31
+ redfish_sdk/managers/update_strategies/vendor_detect.py
32
+ redfish_sdk/managers/update_strategies/xfusion.py
33
+ redfish_sdk/managers/update_strategies/zte.py
34
+ redfish_sdk/models/__init__.py
35
+ redfish_sdk/models/account.py
36
+ redfish_sdk/models/chassis.py
37
+ redfish_sdk/models/check.py
38
+ redfish_sdk/models/common.py
39
+ redfish_sdk/models/drive.py
40
+ redfish_sdk/models/event.py
41
+ redfish_sdk/models/fru.py
42
+ redfish_sdk/models/gpu.py
43
+ redfish_sdk/models/logs.py
44
+ redfish_sdk/models/managers.py
45
+ redfish_sdk/models/memory.py
46
+ redfish_sdk/models/network_adapter.py
47
+ redfish_sdk/models/oem.py
48
+ redfish_sdk/models/pcie_device.py
49
+ redfish_sdk/models/power.py
50
+ redfish_sdk/models/processor.py
51
+ redfish_sdk/models/registry.py
52
+ redfish_sdk/models/resource_key.py
53
+ redfish_sdk/models/root.py
54
+ redfish_sdk/models/session.py
55
+ redfish_sdk/models/storage.py
56
+ redfish_sdk/models/systems.py
57
+ redfish_sdk/models/task.py
58
+ redfish_sdk/models/thermal.py
59
+ redfish_sdk/models/update.py
60
+ tests/test_client_mock.py
61
+ tests/test_log_entries_mock.py
62
+ tests/test_models.py
63
+ tests/test_models_mock.py
64
+ tests/test_offline_json.py
65
+ tests/test_real_bmc.py
66
+ tests/test_sdk_mock.py
67
+ tests/test_update_strategies.py
68
+ tests/test_v1_1_apis_mock.py
@@ -0,0 +1,7 @@
1
+ requests>=2.31.0
2
+ pydantic>=2.5.0
3
+ urllib3>=2.0.0
4
+
5
+ [dev]
6
+ pytest>=7.0.0
7
+ ruff>=0.4.0
@@ -0,0 +1,63 @@
1
+ """
2
+ Redfish Python SDK
3
+
4
+ A Python SDK for interacting with Redfish-compliant BMC (Baseboard Management Controller)
5
+ endpoints.
6
+
7
+ Quick start:
8
+ import os
9
+ from redfish_sdk import RedfishClient
10
+
11
+ # Credentials are read from environment variables:
12
+ # export BMC_IP="<bmc-ip>"
13
+ # export BMC_USER="<bmc-user>"
14
+ # export BMC_PASSWORD="<bmc-password>"
15
+ client = RedfishClient(
16
+ host=os.environ["BMC_IP"],
17
+ username=os.environ["BMC_USER"],
18
+ password=os.environ["BMC_PASSWORD"],
19
+ )
20
+
21
+ # Get system information
22
+ system = client.get_system()
23
+ print(f"System: {system.manufacturer} {system.model}")
24
+ print(f"Power: {system.power_state}")
25
+ print(f"SN: {system.serial_number}")
26
+
27
+ client.close()
28
+ """
29
+ from .client import RedfishClient
30
+ from .exceptions import (
31
+ RedfishAuthError,
32
+ RedfishConnectionError,
33
+ RedfishException,
34
+ RedfishNotFoundError,
35
+ RedfishTimeoutError,
36
+ RedfishValidationError,
37
+ )
38
+ from .models.drive import Drive
39
+ from .models.event import EventService, Subscription
40
+ from .models.logs import Log, LogEntry
41
+ from .models.resource_key import RedfishResource
42
+ from .models.systems import BootOption
43
+
44
+ __version__ = "1.0.0"
45
+ __author__ = "RedNote Infrastructure"
46
+
47
+ __all__ = [
48
+ "RedfishClient",
49
+ "RedfishResource",
50
+ "RedfishException",
51
+ "RedfishNotFoundError",
52
+ "RedfishAuthError",
53
+ "RedfishConnectionError",
54
+ "RedfishTimeoutError",
55
+ "RedfishValidationError",
56
+ # Models commonly used at API boundary.
57
+ "BootOption",
58
+ "Drive",
59
+ "EventService",
60
+ "Log",
61
+ "LogEntry",
62
+ "Subscription",
63
+ ]