Skip to content

Commit

Permalink
Merge branch 'main' into ehaligow-chassis-alignment-with-OpenRMC1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaligow authored Jan 24, 2024
2 parents e822d52 + d0423cd commit ccd3f5b
Show file tree
Hide file tree
Showing 10 changed files with 298 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ prereq:
&& sudo mv /tmp/protoc3/bin/* /usr/local/bin/ \
&& sudo mv /tmp/protoc3/include/* /usr/local/include/
rm -rf /tmp/protoc3
GOROOT=${GO_DIR} GOPATH=$(HOME)/app ${GO_BIN_PATH}/go get -v google.golang.org/grpc
GOROOT=${GO_DIR} GOPATH=$(HOME)/app ${GO_BIN_PATH}/go get -v google.golang.org/grpc@v1.57.0
GOROOT=${GO_DIR} GOPATH=$(HOME)/app ${GO_BIN_PATH}/go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
GOROOT=${GO_DIR} GOPATH=$(HOME)/app ${GO_BIN_PATH}/go install github.com/golang/protobuf/[email protected]

Expand Down
7 changes: 7 additions & 0 deletions lib-utilities/proto/chassis/chassis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ syntax = "proto3";
rpc CreateChassis(CreateChassisRequest) returns (GetChassisResponse){}
rpc DeleteChassis(DeleteChassisRequest) returns (GetChassisResponse){}
rpc UpdateChassis(UpdateChassisRequest) returns (GetChassisResponse){}
rpc UpdateChassisResource(UpdateChassisResourceRequest) returns (GetChassisResponse){}
}

message GetChassisRequest{
Expand Down Expand Up @@ -53,3 +54,9 @@ syntax = "proto3";
string URL=2;
bytes RequestBody = 3;
}

message UpdateChassisResourceRequest{
string sessionToken=1;
string URL=2;
bytes RequestBody = 3;
}
33 changes: 33 additions & 0 deletions svc-api/handle/chassis.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type ChassisRPCs struct {
CreateChassisRPC func(req chassisproto.CreateChassisRequest) (*chassisproto.GetChassisResponse, error)
DeleteChassisRPC func(req chassisproto.DeleteChassisRequest) (*chassisproto.GetChassisResponse, error)
UpdateChassisRPC func(req chassisproto.UpdateChassisRequest) (*chassisproto.GetChassisResponse, error)
UpdateChassisResourceRPC func(req chassisproto.UpdateChassisResourceRequest) (*chassisproto.GetChassisResponse, error)
}

//CreateChassis creates a new chassis
Expand Down Expand Up @@ -229,3 +230,35 @@ func (chassis *ChassisRPCs) DeleteChassis(ctx iris.Context) {

writeResponse(ctx, rpcResp.Header, rpcResp.StatusCode, rpcResp.Body)
}


// UpdateChassisResource updates an existing resource under chassis
func (chassis *ChassisRPCs) UpdateChassisResource(ctx iris.Context) {
defer ctx.Next()
requestBody := new(json.RawMessage)
e := ctx.ReadJSON(requestBody)
if e != nil {
errorMessage := "error while trying to read obligatory json body: " + e.Error()
log.Warn(errorMessage)
response := common.GeneralError(http.StatusBadRequest, response.MalformedJSON, errorMessage, nil, nil)
common.SetResponseHeader(ctx, response.Header)
ctx.StatusCode(http.StatusBadRequest)
ctx.JSON(&response.Body)
return
}
rpcResponse, err := chassis.UpdateChassisResourceRPC(chassisproto.UpdateChassisResourceRequest{
SessionToken: ctx.Request().Header.Get("X-Auth-Token"),
URL: ctx.Request().RequestURI,
RequestBody: *requestBody,
})

if err != nil {
log.Println("RPC error:" + err.Error())
re := common.GeneralError(http.StatusInternalServerError, response.InternalError, err.Error(), nil, nil)
writeResponse(ctx, re.Header, re.StatusCode, re.Body)
return
}

writeResponse(ctx, rpcResponse.Header, rpcResponse.StatusCode, rpcResponse.Body)

}
17 changes: 17 additions & 0 deletions svc-api/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func Router() *iris.Application {
CreateChassisRPC: rpc.CreateChassis,
DeleteChassisRPC: rpc.DeleteChassis,
UpdateChassisRPC: rpc.UpdateChassis,
UpdateChassisResourceRPC: rpc.UpdateChassisResource,
}

evt := handle.EventsRPCs{
Expand Down Expand Up @@ -312,10 +313,18 @@ func Router() *iris.Application {
systems.Get("/{id}", system.GetSystem)
systems.Get("/{id}/Processors", system.GetSystemResource)
systems.Get("/{id}/Processors/{rid}", system.GetSystemResource)
systems.Get("/{id}/Processors/{rid}/AccelerationFunctions", system.GetSystemResource)
systems.Get("/{id}/Processors/{rid}/Assembly", system.GetSystemResource)
systems.Get("/{id}/Processors/{rid}/Metrics", system.GetSystemResource)
systems.Get("/{id}/Processors/{rid}/Processors", system.GetSystemResource)
systems.Get("/{id}/Memory", system.GetSystemResource)
systems.Get("/{id}/Memory/{rid}", system.GetSystemResource)
systems.Get("/{id}/Memory/{id2}/Metrics", system.GetSystemResource)
systems.Get("/{id}/NetworkInterfaces", system.GetSystemResource)
systems.Get("/{id}/NetworkInterfaces/{rid}", system.GetSystemResource)
systems.Get("/{id}/NetworkInterfaces/{rid}/NetworkDeviceFunctions", system.GetSystemResource)
systems.Get("/{id}/NetworkInterfaces/{rid}/NetworkPorts", system.GetSystemResource)
systems.Get("/{id}/NetworkInterfaces/{rid}/Ports", system.GetSystemResource)
systems.Get("/{id}/MemoryDomains", system.GetSystemResource)
systems.Get("/{id}/EthernetInterfaces", system.GetSystemResource)
systems.Get("/{id}/EthernetInterfaces/{rid}", system.GetSystemResource)
Expand All @@ -330,7 +339,9 @@ func Router() *iris.Application {
systems.Get("/{id}/LogServices/{rid}/Entries/{rid2}", system.GetSystemResource)
systems.Post("/{id}/LogServices/{rid}/Actions/LogService.ClearLog", system.GetSystemResource)
systems.Patch("/{id}", system.ChangeBootOrderSettings)
systems.Get("/{id}/PCIeDevices", system.GetSystemResource)
systems.Get("/{id}/PCIeDevices/{rid}", system.GetSystemResource)
systems.Get("/{id}/PCIeDevices/{rid}/Assembly", system.GetSystemResource)
systems.Any("/{id}/PCIeDevices/{rid}", handle.SystemsMethodNotAllowed)
systems.Any("/", handle.SystemsMethodNotAllowed)
systems.Any("/{id}", handle.SystemsMethodNotAllowed)
Expand All @@ -349,12 +360,17 @@ func Router() *iris.Application {
systems.Any("/{id}/LogServices/{rid}/Entries/{rid2}", handle.SystemsMethodNotAllowed)
systems.Any("/{id}/LogServices/{rid}/Actions", handle.SystemsMethodNotAllowed)
systems.Any("/{id}/LogServices/{rid}/Actions/LogService.ClearLog", handle.SystemsMethodNotAllowed)
systems.Get("/{id}/Certificates", system.GetSystemResource)

systems.Get("/{id}/Bios", system.GetSystemResource)
systems.Get("/{id}/Bios/Settings", system.GetSystemResource)
systems.Patch("/{id}/Bios/Settings", system.ChangeBiosSettings)
systems.Any("/{id}/Bios", handle.SystemsMethodNotAllowed)
systems.Any("/{id}/Processors/{rid}", handle.SystemsMethodNotAllowed)
systems.Get("/{id}/SimpleStorage", system.GetSystemResource)
systems.Get("/{id}/StorageServices", system.GetSystemResource)
systems.Get("/{id}/Metrics", system.GetSystemResource)
systems.Get("/{id}/VirtualMedia", system.GetSystemResource)

storage := v1.Party("/Systems/{id}/Storage", middleware.SessionDelMiddleware)
storage.SetRegisterRule(iris.RouteSkip)
Expand Down Expand Up @@ -485,6 +501,7 @@ func Router() *iris.Application {
chassis.Any("/{id}/LogServices/{rid}/Actions", handle.ChassisMethodNotAllowed)

chassisPower := chassis.Party("/{id}/Power")
chassisPower.Patch("", cha.UpdateChassisResource)
chassisPower.SetRegisterRule(iris.RouteSkip)
chassisPower.Get("/", cha.GetChassisResource)
chassisPower.Get("#PowerControl/{id1}", cha.GetChassisResource)
Expand Down
18 changes: 17 additions & 1 deletion svc-api/rpc/chassis.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package rpc
import (
"context"
"fmt"

chassisproto "github.com/ODIM-Project/ODIM/lib-utilities/proto/chassis"
"github.com/ODIM-Project/ODIM/lib-utilities/services"
)
Expand Down Expand Up @@ -113,3 +112,20 @@ func UpdateChassis(req chassisproto.UpdateChassisRequest) (*chassisproto.GetChas
}
return resp, nil
}

//UpdateChassisResource will do the rpc call to update a chassis resource
func UpdateChassisResource(req chassisproto.UpdateChassisResourceRequest) (*chassisproto.GetChassisResponse, error) {
conn, err := services.ODIMService.Client(services.Systems)
if err != nil {
return nil, fmt.Errorf("Failed to create client connection: %v", err)
}
defer conn.Close()
service := chassisproto.NewChassisClient(conn)

resp, err := service.UpdateChassisResource(context.TODO(), &req)
if err != nil && resp == nil {
return nil, fmt.Errorf("Something went wrong with rpc call: %v", err)
}

return resp, err
}
71 changes: 71 additions & 0 deletions svc-device-manager/rest/patchPower.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package rest

import (
"devicemanager/config"
"devicemanager/rest/redfish"
"fmt"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/context"
"github.com/sirupsen/logrus"
"io"
"net/http"
)

type patchPowerHandler struct {
cfg config.Config
}

func (r *patchPowerHandler) handle(ctx iris.Context) {
if ctx.GetHeader("Authorization") == "" {
noValidAuthError := "No valid authorization"
ctx.StatusCode(http.StatusUnauthorized)
logrus.Error(noValidAuthError)
ctx.WriteString(noValidAuthError)
return
}

var reqInfo redfish.RequestInformation

// Get information from the request.
err := ctx.ReadJSON(&reqInfo)
if err != nil {
missingInfoError := "Unable to retrieve information from a request: " + err.Error()
logrus.Error(missingInfoError)
ctx.StatusCode(http.StatusBadRequest)
ctx.WriteString(missingInfoError)
return
}

httpClient := redfish.NewHttpClient(r.cfg).WithBasicAuth(reqInfo.Username, string(reqInfo.Password))
uri := fmt.Sprintf("https://%s%s", reqInfo.Host, ctx.Request().RequestURI)

response, err := httpClient.Patch(uri, reqInfo.Body)
if err != nil {
errorMessage := fmt.Sprintf("PATCH action failed on %s due to: %s", uri, err.Error())
logrus.Error(errorMessage)
if response == nil {
ctx.StatusCode(http.StatusInternalServerError)
ctx.WriteString(errorMessage)
return
}
}

defer response.Body.Close()
body, err := io.ReadAll(response.Body)
if err != nil {
errorMessage := "Error while reading response body: " + err.Error()
logrus.Error(errorMessage)
ctx.StatusCode(http.StatusInternalServerError)
ctx.WriteString(errorMessage)
return
}

ctx.StatusCode(response.StatusCode)
ctx.Write(body)
}

func newPatchPowerHandler(cfg config.Config) context.Handler {
return (&patchPowerHandler{
cfg: cfg,
}).handle
}
34 changes: 34 additions & 0 deletions svc-device-manager/rest/redfish/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,40 @@ func (h *HttpClient) Post(uri string, requestBody []byte) (*http.Response, error
return resp, nil
}

// Patch sends PATCH action to a requested endpoint with requested body.
func (h *HttpClient) Patch(uri string, requestBody []byte) (*http.Response, error) {
requestedUrl, err := url.Parse(uri)
if err != nil {
return nil, err
}

body := io.NopCloser(bytes.NewBuffer(requestBody))
req := &http.Request{
Method: http.MethodPatch,
URL: requestedUrl,
Body: body,
Header: http.Header{},
}
h.addDefaultHeaders(req)

err = translateRequest(req)
if err != nil {
return nil, err
}

resp, err := h.client.Do(req)
if err != nil {
return resp, err
}

err = translateResponse(resp)
if err != nil {
return nil, err
}

return resp, nil
}

func translateRequest(req *http.Request) error {
req.URL, _ = url.Parse(utils.UriConverter.DmToRedfish(req.URL.String()))

Expand Down
37 changes: 31 additions & 6 deletions svc-device-manager/rest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func createRouting(app *iris.Application, config config.Config) {
chassis.Get("/{id}/LogServices", getGenericResourceHandler)
chassisPower := chassis.Party("/{id}/Power")
chassisPower.Get("", getGenericResourceHandler)
chassisPower.Patch("", newPatchPowerHandler(config))
chassisNetworkAdapters := chassis.Party("/{id}/NetworkAdapters")
chassisNetworkAdapters.Get("", getGenericResourceHandler)
chassisNetworkAdapters.Get("/{id}", getGenericResourceHandler)
Expand All @@ -52,20 +53,44 @@ func createRouting(app *iris.Application, config config.Config) {
chassisNetworkAdapters.Get("/{id}/NetworkPorts", getGenericResourceHandler)
chassisNetworkAdapters.Get("/{id}/NetworkPorts/{id2}", getGenericResourceHandler)
chassisNetworkAdapters.Get("/{id}/Ports", getGenericResourceHandler)

systems := routes.Party("/Systems", basicAuthHandler)
systems.Get("", getGenericResourceHandler)
systems.Get("/{id}", getGenericResourceHandler)
systems.Get("/{id}/Certificates", getGenericResourceHandler)
systems.Get("/{id}/StorageServices", getGenericResourceHandler)
systems.Get("/{id}/Metrics", getGenericResourceHandler)
systems.Get("/{id}/SimpleStorage", getGenericResourceHandler)
systems.Get("/{id}/Storage", getGenericResourceHandler)
systems.Get("/{id}/VirtualMedia", getGenericResourceHandler)
systems.Get("/{id}/BootOptions", getGenericResourceHandler)
systems.Get("/{id}/BootOptions/{id2}", getGenericResourceHandler)
systems.Get("/{id}/Processors", getGenericResourceHandler)
systems.Get("/{id}/Processors/{id2}", getGenericResourceHandler)

processors := systems.Party("/{id}/Processors", basicAuthHandler)
processors.Get("", getGenericResourceHandler)
processors.Get("/{id}", getGenericResourceHandler)
processors.Get("/{id}/AccelerationFunctions", getGenericResourceHandler)
processors.Get("/{id}/Assembly", getGenericResourceHandler)
processors.Get("/{id}/Metrics", getGenericResourceHandler)
processors.Get("/{id}/Processors", getGenericResourceHandler)

systems.Get("/{id}/Memory", getGenericResourceHandler)
systems.Get("/{id}/Memory/{id2}", getGenericResourceHandler)
systems.Get("/{id}/NetworkInterfaces", getGenericResourceHandler)
systems.Get("/{id}/NetworkInterfaces/{id2}", getGenericResourceHandler)
systems.Get("/{id}/Memory/{id2}/Metrics", getGenericResourceHandler)

networkInterfaces := systems.Party("/{id}/NetworkInterfaces", basicAuthHandler)
networkInterfaces.Get("", getGenericResourceHandler)
networkInterfaces.Get("/{id}", getGenericResourceHandler)
networkInterfaces.Get("/{id}/NetworkDeviceFunctions", getGenericResourceHandler)
networkInterfaces.Get("/{id}/NetworkPorts", getGenericResourceHandler)
networkInterfaces.Get("/{id}/Ports", getGenericResourceHandler)

systems.Get("/{id}/MemoryDomains", getGenericResourceHandler)
systems.Get("/{id}/SecureBoot", getGenericResourceHandler)
systems.Get("/{id}/PCIeDevices/{id2}", getGenericResourceHandler)
pcieDevices := systems.Party("/{id}/PCIeDevices")
pcieDevices.Get("", getGenericResourceHandler)
pcieDevices.Get("/{id}", getGenericResourceHandler)
pcieDevices.Get("/{id}/Assembly", getGenericResourceHandler)
systems.Get("/{id}/Bios", getGenericResourceHandler)
systems.Get("/{id}/Bios/Settings", getGenericResourceHandler)
systems.Post("/{id}/Actions/ComputerSystem.Reset", newResetComputerSystemHandler(config))
Expand All @@ -82,7 +107,7 @@ func createRouting(app *iris.Application, config config.Config) {
logService.Get("/{id}/Entries", getGenericResourceHandler)
logService.Get("/{id}/Entries/{id2}", getGenericResourceHandler)

storage := routes.Party("/{id}/Storage")
storage := systems.Party("/{id}/Storage")
storage.Get("", getGenericResourceHandler)
storage.Get("/{id}", getGenericResourceHandler)
storage.Get("/{id}/Volumes", getGenericResourceHandler)
Expand Down
Loading

0 comments on commit ccd3f5b

Please sign in to comment.