Skip to content

介绍

  • Redfish 是一种管理标准,它使用 HTTP RESTful 接口的数据模型表示法,此模型以标准的机器可读模式表示,其消息负载以 JSON 来表示,和普通的浏览器访问站点一样

  • 协议本身利用了 OData v4 版本,Redfish APIHTTP API,可通过统一的接口来表示,各种实现Redfish API 提供数据中心资源管理、事件处理、长时间任务以及发现等机制

版本

  • 协议版本:协议版本包含在URI中,从/redfish/v1/开始,这表示正在访问协议版本,V1版本是目前唯一的版本,但未来会有其它版本,以这种方式开头的URI表示实现方法符合Redfish规范V1版本
  • 资源模式版本: 资源类型在带有版本的命名空间中定义,每个资源实例的类型由OData类型注释@odata.type来表示,类型注释的值是资源类型URI,包括带有版本的命名空间,@odata.type: # ServiceRoot.1.0.0.ServiceRoot表示处理的是ServiceRoot模式1.0.0版本中定义的ServiceRoot类型的资源,相应的模式文件位于Redfish模式库的/schema /v1/ServiceRoot路径下,因此,此类型的完整URI/schema/v1/ServiceRoot#ServiceRoot.1.0.0.ServiceRoot

python client操作库

https://github.com/DMTF/python-redfish-library
https://github.com/DMTF/python-redfish-library

从操作库的代码来看,redfish有些服务需要账号密码,可以采用session会话保持的方式,也可以采用Basic Authorization方式认证

Basic Authorization认证

假设现在有账号user-a, 密码pass-a,计算出认证参数如下

python
>>> import base64
>>> base64.b64encode('user-a:pass-a'.encode('utf-8')).decode('utf-8')
'dXNlci1hOnBhc3MtYQ=='
>>> import base64
>>> base64.b64encode('user-a:pass-a'.encode('utf-8')).decode('utf-8')
'dXNlci1hOnBhc3MtYQ=='

在请求头headers中加入参数Authorization: Basic dXNlci1hOnBhc3MtYQ==完成认证了

python mock server

由于redfish服务需要硬件厂商支持,并开放相应服务,所以DMTF项目提供了一个可供测试使用的redfish server

https://github.com/DMTF/Redfish-Mockup-Server
https://github.com/DMTF/Redfish-Mockup-Server

可以通过docker启动服务,开放8000端口

$ docker run --rm -p8000:8000 dmtf/redfish-mockup-server:latest
$ docker run --rm -p8000:8000 dmtf/redfish-mockup-server:latest

依据mock server项目的配置文件, 该redfish server提供的接口包含了/redfish/v1/Systems, /redfish/v1/Chassis...

https://github.com/DMTF/Redfish-Mockup-Server/blob/main/public-rackmount1/index.json
https://github.com/DMTF/Redfish-Mockup-Server/blob/main/public-rackmount1/index.json

使用curl工具测试服务

shell
$ curl http://127.0.0.1:8000/redfish/v1/Systems
{
    "@odata.id": "/redfish/v1/Systems",
    "@odata.type": "#ComputerSystemCollection.ComputerSystemCollection",
    "Members": [
        {
            "@odata.id": "/redfish/v1/Systems/437XR1138R2"
        }
    ],
    "Members@odata.count": 1,
    "Name": "Computer System Collection"
}

$ curl http://127.0.0.1:8000/redfish/v1/TaskService
$ curl http://127.0.0.1:8000/redfish/v1/Systems
{
    "@odata.id": "/redfish/v1/Systems",
    "@odata.type": "#ComputerSystemCollection.ComputerSystemCollection",
    "Members": [
        {
            "@odata.id": "/redfish/v1/Systems/437XR1138R2"
        }
    ],
    "Members@odata.count": 1,
    "Name": "Computer System Collection"
}

$ curl http://127.0.0.1:8000/redfish/v1/TaskService

如果需要带上认证信息,可以修改命令为

shell
$ curl -H "Authorization: Basic dXNlci1hOnBhc3MtYQ==" http://127.0.0.1:8000/redfish/v1/Systems
$ curl -H "Authorization: Basic dXNlci1hOnBhc3MtYQ==" http://127.0.0.1:8000/redfish/v1/Systems

参考阅读

DSP2044 Redfish 白皮书 1.0.0

Last updated:

Released under the MIT License.