-
Notifications
You must be signed in to change notification settings - Fork 7
/
redfish.go
193 lines (173 loc) · 6.13 KB
/
redfish.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package virtualbmc
import (
"net/http"
"github.com/gin-gonic/gin"
)
type redfishServer struct {
machine Machine
systemIDs map[string]struct{}
}
// OdataID represents the unique identifier for a resource
type OdataID struct {
OdataID string `json:"@odata.id"`
}
// ServiceRoot represents Redfish service root(/redfish/v1)
type ServiceRoot struct {
OdataContext string `json:"@odata.context"`
OdataID string `json:"@odata.id"`
OdataType string `json:"@odata.type"`
AccountService OdataID `json:"AccountService"`
Chassis OdataID `json:"Chassis"`
Description string `json:"Description"`
EventService OdataID `json:"EventService"`
Fabrics OdataID `json:"Fabrics"`
ID string `json:"Id"`
JSONSchemas OdataID `json:"JsonSchemas"`
Links ServiceRootLinks `json:"Links"`
Managers OdataID `json:"Managers"`
Name string `json:"Name"`
Oem ServiceRootOem `json:"Oem"`
Product string `json:"Product"`
ProtocolFeaturesSupported ProtocolFeaturesSupported `json:"ProtocolFeaturesSupported"`
RedfishVersion string `json:"RedfishVersion"`
Registries OdataID `json:"Registries"`
SessionService OdataID `json:"SessionService"`
Systems OdataID `json:"Systems"`
Tasks OdataID `json:"Tasks"`
UpdateService OdataID `json:"UpdateService"`
}
// ServiceRootLinks represents ServiceRoot's Links field
type ServiceRootLinks struct {
Sessions OdataID `json:"Sessions"`
}
// ServiceRootOem represents ServiceRoot's Oem field
type ServiceRootOem struct {
}
// ProtocolFeaturesSupported represents ServiceRoot's ProtocolFeaturesSupported field
type ProtocolFeaturesSupported struct {
ExpandQuery ExpandQuery `json:"ExpandQuery"`
FilterQuery bool `json:"FilterQuery"`
SelectQuery bool `json:"SelectQuery"`
}
// ExpandQuery represents ServiceRoot's ExpandQuery field
type ExpandQuery struct {
ExpandAll bool `json:"ExpandAll"`
Levels bool `json:"Levels"`
Links bool `json:"Links"`
MaxLevels int `json:"MaxLevels"`
NoLinks bool `json:"NoLinks"`
}
// ResourceCollection represents the collection of resource instances
type ResourceCollection struct {
OdataContext string `json:"@odata.context"`
OdataID string `json:"@odata.id"`
OdataType string `json:"@odata.type"`
Description string `json:"Description"`
Members []OdataID `json:"Members"`
MembersOdataCount int `json:"Members@odata.count"`
Name string `json:"Name"`
}
// RequestBody represents Post request body
type RequestBody struct {
ResetType ResetType `json:"ResetType"`
}
// ErrorResponse represents Error response
type ErrorResponse struct {
Error Error `json:"error"`
}
// Error represents ErrorResponse's Error field
type Error struct {
MessageExtendedInfo []MessageExtendedInfo `json:"@Message.ExtendedInfo"`
Code string `json:"code"`
Message string `json:"message"`
}
// MessageExtendedInfo represents ErrorResponse's MessageExtendedInfo field
type MessageExtendedInfo struct {
Message string `json:"Message"`
MessageArgs []string `json:"MessageArgs"`
MessageArgsOdataCount int `json:"MessageArgs@odata.count"`
MessageID string `json:"MessageId"`
RelatedProperties []interface{} `json:"RelatedProperties"`
RelatedPropertiesOdataCount int `json:"RelatedProperties@odata.count"`
Resolution string `json:"Resolution"`
Severity string `json:"Severity"`
}
const systemID = "System.Embedded.1"
type ResetType string
const (
ResetTypeOn = ResetType("On")
ResetTypeForceOff = ResetType("ForceOff")
ResetTypeForceRestart = ResetType("ForceRestart")
ResetTypeGracefulShutdown = ResetType("GracefulShutdown")
ResetTypePushPowerButton = ResetType("PushPowerButton")
ResetTypeNmi = ResetType("Nmi")
)
var serviceRootResponse = ServiceRoot{
OdataContext: "/redfish/v1/$metadata#ServiceRoot.ServiceRoot",
OdataID: "/redfish/v1",
OdataType: "#ServiceRoot.v1_3_0.ServiceRoot",
AccountService: OdataID{
OdataID: "/redfish/v1/Managers/Embedded.1/AccountService",
},
Chassis: OdataID{
OdataID: "/redfish/v1/Chassis",
},
Description: "Root Service",
EventService: OdataID{
OdataID: "/redfish/v1/EventService",
},
Fabrics: OdataID{
OdataID: "/redfish/v1/Fabrics",
},
ID: "RootService",
JSONSchemas: OdataID{
OdataID: "/redfish/v1/JSONSchemas",
},
Links: ServiceRootLinks{
Sessions: OdataID{
OdataID: "/redfish/v1/Sessions",
},
},
Managers: OdataID{
OdataID: "/redfish/v1/Managers",
},
Name: "Root Service",
Oem: ServiceRootOem{},
Product: "Placemat",
ProtocolFeaturesSupported: ProtocolFeaturesSupported{
ExpandQuery: ExpandQuery{
ExpandAll: true,
Levels: true,
Links: true,
MaxLevels: 1,
NoLinks: true,
},
FilterQuery: true,
SelectQuery: true,
},
RedfishVersion: "1.4.0",
Registries: OdataID{
OdataID: "/redfish/v1/Registries",
},
SessionService: OdataID{
OdataID: "/redfish/v1/SessionService",
},
Systems: OdataID{
OdataID: "/redfish/v1/Systems",
},
Tasks: OdataID{
OdataID: "/redfish/v1/TaskService",
},
UpdateService: OdataID{
OdataID: "/redfish/v1/UpdateService",
},
}
func newRedfishServer(machine Machine) *redfishServer {
return &redfishServer{
machine: machine,
systemIDs: map[string]struct{}{systemID: {}},
}
}
func handleServiceRoot(c *gin.Context) {
c.JSON(http.StatusOK, serviceRootResponse)
}