Skip to content

Commit

Permalink
Added missing endpoints and
Browse files Browse the repository at this point in the history
properties in Managers service

Signed-off-by: ehaligow <[email protected]>
  • Loading branch information
ehaligow committed Jun 5, 2024
1 parent d092404 commit 9e62cde
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 39 deletions.
23 changes: 21 additions & 2 deletions lib-dmtf/model/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Manager struct {
SerialNumber string `json:"SerialNumber,omitempty"`
ServiceEntryPointUUID string `json:"ServiceEntryPointUUID,omitempty"`
SerialInterfaces *Link `json:"SerialInterfaces,omitempty"`
SerialConsole SerialConsole `json:"SerialConsole,omitempty"`
TimeZoneName string `json:"TimeZoneName,omitempty"`
UUID string `json:"UUID,omitempty"`
Measurements []*Link `json:"Measurements,omitempty"`
Expand Down Expand Up @@ -76,15 +77,15 @@ type ManagerLinks struct {
ActiveSoftwareImage *Link `json:"ActiveSoftwareImage,omitempty"`
ManagedBy []Link `json:"ManagedBy,omitempty"`
ManagerByCount int `json:"[email protected],omitempty"`
ManagerForChassis []Link `json:"ManagerForChassis,omitempty"`
ManagerForChassis []Link `json:"ManagerForChassis"`
ManagerForChassisCount int `json:"[email protected],omitempty"`
ManagerForManagers []Link `json:"ManagerForManagers,omitempty"`
ManagerForManagersCount int `json:"[email protected],omitempty"`
ManagerForServers []Link `json:"ManagerForServers,omitempty"`
ManagerForServersCount int `json:"[email protected],omitempty"`
ManagerForSwitches []Link `json:"ManagerForSwitches,omitempty"`
ManagerForSwitchesCount int `json:"[email protected],omitempty"`
ManagerInChassis []Link `json:"ManagerInChassis,omitempty"`
ManagerInChassis *Link `json:"ManagerInChassis,omitempty"`
ManagerInChassisCount int `json:"[email protected],omitempty"`
Oem interface{} `json:"Oem,omitempty"`
SoftwareImages *Link `json:"SoftwareImages,omitempty"`
Expand Down Expand Up @@ -131,3 +132,21 @@ type VMActions struct {
type ActionTarget struct {
Target string `json:"target"`
}

// NetworkProtocol contains the property details of NetworkProtocol
type NetworkProtocol struct{
ODataID string `json:"@odata.id"`
ODataType string `json:"@odata.type"`
Description string `json:"Description,omitempty"`
ID string `json:"Id"`
Name string `json:"Name"`
Status *Status `json:"Status"`
HTTP *HTTP `json:"HTTP"`
HTTPS *HTTP `json:"HTTPS"`
}

// HTTP redfish structure
type HTTP struct {
ProtocolEnabled string `json:"ProtocolEnabled"`
Port string `json:"Port"`
}
3 changes: 3 additions & 0 deletions svc-aggregation/system/addcompute.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ func (e *ExternalInterface) addCompute(taskID, targetURI, pluginID string, perce
managerLinks["ManagerForServers"] = serverLink
managerData["Links"] = managerLinks
}

addEmptyManagersCollections(aggSourceIDChassisAndManager + plugin.ManagerUUID)

mgrData, err := json.Marshal(managerData)
if err != nil {
errorMessage := "unable to marshal data while updating managers detail: " + err.Error()
Expand Down
46 changes: 46 additions & 0 deletions svc-aggregation/system/addplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,52 @@ func (e *ExternalInterface) addPluginData(req AddResourceRequest, taskID, target

return common.GeneralError(http.StatusConflict, response.ResourceAlreadyExists, errMsg, []interface{}{"Plugin", "PluginID", plugin.ID}, taskInfo), "", nil
}

//adding empty EthernetInterfaces Collection
eidata := model.Collection{
ODataContext: "/redfish/v1/$metadata#EthernetInterfacesCollection.EthernetInterfacesCollection",
ODataID: "/redfish/v1/Managers/" + managerUUID + "/EthernetInterfaces",
ODataType: "#EthernetInterfacesCollection.EthernetInterfacesCollection",
Description: "EthernetInterfaces collection view",
Members: []*model.Link{},
MembersCount: 1,
Name: "EthernetInterfaces",
}
dbdata, err = json.Marshal(eidata)
if err != nil {
log.Error()
}
key = "/redfish/v1/Managers/" + managerUUID + "/EthernetInterfaces"
dbError := agmodel.SavePluginManagerInfo([]byte(dbdata), "EthernetInterfacesCollection", key)
if dbError != nil {
errMsg := dbError.Error()
log.Error(errMsg)

return common.GeneralError(http.StatusConflict, response.ResourceAlreadyExists, errMsg, []interface{}{"Plugin", "PluginID", plugin.ID}, taskInfo), "", nil
}

//adding NetworkProtocol
networkProtocol := model.NetworkProtocol{
ODataID: "/redfish/v1/Managers/" + managerUUID + "/NetworkProtocol",
ODataType: "#ManagerNetworkProtocol.ManagerNetworkProtocol",
Description: "NetworkProtocol",
ID: "NetworkProtocol",
Name: "NetworkProtocol",
}
dbdata, err = json.Marshal(networkProtocol)
if err != nil {
log.Error()
}

key = "/redfish/v1/Managers/" + managerUUID + "/NetworkProtocol"
dbError = agmodel.SavePluginManagerInfo([]byte(dbdata), "NetworkProtocol", key)
if dbError != nil {
errMsg := dbError.Error()
log.Error(errMsg)

return common.GeneralError(http.StatusConflict, response.ResourceAlreadyExists, errMsg, []interface{}{"Plugin", "PluginID", plugin.ID}, taskInfo), "", nil
}

// saving all plugin manager data
var listMembers = make([]agresponse.ListMember, 0)
for oid, data := range managersData {
Expand Down
73 changes: 64 additions & 9 deletions svc-aggregation/system/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package system

import (
"regexp"
"context"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -552,6 +553,58 @@ func isFileExist(existingFiles []string, substr string) bool {
}
return fileExist
}
func addEmptyManagersCollections(managerUUID string) {

//adding empty EthernetInterfaces Collection
entriesdata := dmtf.Collection{
ODataContext: "/redfish/v1/$metadata#EthernetInterfacesCollection.EthernetInterfacesCollection",
ODataID: "/redfish/v1/Managers/" + managerUUID + "/EthernetInterfaces",
ODataType: "#EthernetInterfacesCollection.EthernetInterfacesCollection",
Description: "EthernetInterfaces collection view",
Members: []*dmtf.Link{},
MembersCount: 1,
Name: "EthernetInterfaces",
}
dbdata, err := json.Marshal(entriesdata)
if err != nil {
log.Error()
}
key := "/redfish/v1/Managers/" + managerUUID + "/EthernetInterfaces"
agmodel.GenericSave([]byte(dbdata), "EthernetInterfacesCollection", key)

//adding NetworkProtocol
networkProtocol := dmtf.NetworkProtocol{
ODataID: "/redfish/v1/Managers/" + managerUUID + "/NetworkProtocol",
ODataType: "#ManagerNetworkProtocol.ManagerNetworkProtocol",
Description: "NetworkProtocol",
ID: "NetworkProtocol",
Name: "NetworkProtocol",
}
dbdata, err = json.Marshal(networkProtocol)
if err != nil {
log.Error()
}

key = "/redfish/v1/Managers/" + managerUUID + "/NetworkProtocol"
agmodel.GenericSave([]byte(dbdata), "NetworkProtocol", key)

//adding empty LogService Collection
entriesdata = dmtf.Collection{
ODataContext: "/redfish/v1/$metadata#LogServicesCollection.LogServicesCollection",
ODataID: "/redfish/v1/Managers/" + managerUUID + "/LogServices",
ODataType: "#LogServicesCollection.LogServicesCollection",
Description: "Logs view",
Members: []*dmtf.Link{},
MembersCount: 1,
Name: "Logs",
}
dbdata, err = json.Marshal(entriesdata)
if err != nil {
log.Error()
}
key = "/redfish/v1/Managers/" + managerUUID + "/LogServices"
agmodel.GenericSave([]byte(dbdata), "LogServicesCollection", key)
}

func (h *respHolder) getAllRootInfo(taskID string, progress int32, alottedWork int32, req getResourceRequest, resourceList []string) int32 {
resourceName := req.OID
Expand Down Expand Up @@ -643,7 +696,7 @@ func (h *respHolder) getSystemInfo(taskID string, progress int32, alottedWork in
}

}
updatedResourceData := updateResourceDataWithUUID(string(body), req.DeviceUUID)
updatedResourceData := updateResourceDataWithUUID(string(body), req.DeviceUUID, req.Plugin.ManagerUUID)
// persist the response with table ComputerSystem and key as system UUID + Oid Needs relook TODO
err = agmodel.GenericSave([]byte(updatedResourceData), "ComputerSystem", oidKey)
if err != nil {
Expand Down Expand Up @@ -733,7 +786,7 @@ func (h *respHolder) getStorageInfo(progress int32, alottedWork int32, req getRe
computeSystemUUID := systemData["UUID"].(string)
oidKey := keyFormation(oid, computeSystemID, req.DeviceUUID)

updatedResourceData := updateResourceDataWithUUID(string(body), req.DeviceUUID)
updatedResourceData := updateResourceDataWithUUID(string(body), req.DeviceUUID, req.Plugin.ManagerUUID)
// persist the response with table Storage
resourceName := getResourceName(req.OID, true)
err = agmodel.GenericSave([]byte(updatedResourceData), resourceName, oidKey)
Expand Down Expand Up @@ -873,11 +926,10 @@ func (h *respHolder) getIndivdualInfo(taskID string, progress int32, alottedWork
}
oid := resource["@odata.id"].(string)
resourceID := resource["Id"].(string)

oidKey := keyFormation(oid, resourceID, req.DeviceUUID)

//replacing the uuid while saving the data
updatedResourceData := updateResourceDataWithUUID(string(body), req.DeviceUUID)
updatedResourceData := updateResourceDataWithUUID(string(body), req.DeviceUUID, req.Plugin.ManagerUUID)
// persist the response with table resource and key as system UUID + Oid Needs relook TODO
err = agmodel.GenericSave([]byte(updatedResourceData), resourceName, oidKey)
if err != nil {
Expand Down Expand Up @@ -942,7 +994,7 @@ func (h *respHolder) getResourceDetails(taskID string, progress int32, alottedWo
resourceName := getResourceName(req.OID, memberFlag)

//replacing the uuid while saving the data
updatedResourceData := updateResourceDataWithUUID(string(body), req.DeviceUUID)
updatedResourceData := updateResourceDataWithUUID(string(body), req.DeviceUUID, req.Plugin.ManagerUUID)
// persist the response with table resourceName and key as system UUID + Oid Needs relook TODO
err = agmodel.GenericSave([]byte(updatedResourceData), resourceName, oidKey)
if err != nil {
Expand Down Expand Up @@ -1192,13 +1244,16 @@ func (e *ExternalInterface) rollbackInMemory(resourceURI string) {
}
}

func updateResourceDataWithUUID(resourceData, uuid string) string {
func updateResourceDataWithUUID(resourceData, uuid, managerUUID string) string {
//replacing the uuid while saving the data
//to replace the id of system
var updatedResourceData = strings.Replace(resourceData, "/redfish/v1/Systems/", "/redfish/v1/Systems/"+uuid+".", -1)
updatedResourceData = strings.Replace(updatedResourceData, "/redfish/v1/systems/", "/redfish/v1/Systems/"+uuid+".", -1)
// to replace the id in managers
updatedResourceData = strings.Replace(updatedResourceData, "/redfish/v1/Managers/", "/redfish/v1/Managers/"+uuid+".", -1)

re := regexp.MustCompile("Managers/.+?\"")
updatedResourceData = string(re.ReplaceAll([]byte(updatedResourceData), []byte("Managers/"+uuid+"."+managerUUID+"\"")))

// to replace id in chassis
updatedResourceData = strings.Replace(updatedResourceData, "/redfish/v1/Chassis/", "/redfish/v1/Chassis/"+uuid+".", -1)

Expand Down Expand Up @@ -1457,7 +1512,7 @@ func (e *ExternalInterface) getTeleInfo(taskID string, progress, alottedWork int
return progress
}
//replacing the uuid while saving the data
updatedResourceData := updateResourceDataWithUUID(string(body), req.DeviceUUID)
updatedResourceData := updateResourceDataWithUUID(string(body), req.DeviceUUID, req.Plugin.ManagerUUID)

updatedResourceData, err = e.createWildCard(updatedResourceData, resourceName, req.OID)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion svc-aggregation/system/systemstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (e *ExternalInterface) UpdateSystemState(updateReq *aggregatorproto.UpdateS
}

//replacing the uuid while saving the data
updatedResourceData := updateResourceDataWithUUID(string(rawData), req.DeviceUUID)
updatedResourceData := updateResourceDataWithUUID(string(rawData), req.DeviceUUID, req.Plugin.ManagerUUID)
var systemInfo map[string]interface{}

if err := json.Unmarshal([]byte(updatedResourceData), &systemInfo); err != nil {
Expand Down
27 changes: 25 additions & 2 deletions svc-device-manager/rest/getManagerHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/context"
"net/http"
"time"
)

type managerHandler struct {
Expand Down Expand Up @@ -35,10 +36,32 @@ func createDmManager(cfg config.Config) model.Manager {
ODataID: "/ODIM/v1/Managers/" + cfg.RootServiceUUID,
ODataType: "#Manager.v1_13_0.Manager",
Name: deviceManagerName,
ManagerType: "Service",
ManagerType: "RackManager",
ID: cfg.RootServiceUUID,
UUID: cfg.RootServiceUUID,
FirmwareVersion: cfg.FirmwareVersion,
Status: &model.Status{State: "Enabled"},
Status: &model.Status{State: "Enabled", Health: "OK", HealthRollup: "OK"},
DateTime: time.Now().Format(time.RFC3339),
DateTimeLocalOffset: "+00:00",
Description: "Device Manager",
Model: "Device Manager",
ServiceEntryPointUUID: cfg.RootServiceUUID,
PowerState: "On",
SerialConsole: model.SerialConsole{},
EthernetInterfaces: &model.Link{
Oid: "/redfish/v1/Managers/" + cfg.RootServiceUUID + "/EthernetInterfaces",
},
NetworkProtocol: &model.Link{
Oid: "/redfish/v1/Managers/" + cfg.RootServiceUUID + "/NetworkProtocol",
},
LogServices: &model.Link{
Oid: "/redfish/v1/Managers/" + cfg.RootServiceUUID + "/LogServices",
},
Links: &model.ManagerLinks{
ManagerForChassis: []model.Link{},
ManagerForServers: []model.Link{},
ManagerForManagers: []model.Link{},
ManagerInChassis: &model.Link{},
},
}
}
Loading

0 comments on commit 9e62cde

Please sign in to comment.