Skip to content

Commit

Permalink
feat: Use Blade serial number as device ID (#25)
Browse files Browse the repository at this point in the history
Handle chassis collection with more than one member
Check for optional CMA enclosure SN
Pass blade and enclosure SN back to manager layer
User BladeSN as bladeID when customID is not provided
  • Loading branch information
HJ-Fan authored Aug 7, 2024
1 parent 3622498 commit 012ae65
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
28 changes: 20 additions & 8 deletions pkg/backend/httpfish.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ type Session struct {
protocol string // http or https
insecure bool // ignore secure flag in https
xToken string // Authentication token

BladeSN string // The serial number of the blade
ApplianceSN string // The serial number of the appliance if applicable
}

// Map of UUID to Session object
Expand Down Expand Up @@ -407,19 +410,28 @@ func (session *Session) pathInit() {

if err == nil {
response := session.query(HTTPOperation.GET, path)
session.redfishPaths[ChassisKey], err = response.memberOdataIndex(0)

// Check if the collection contains more than 1 member
chassisCollection, err := response.memberOdataArray()
if err == nil {
session.redfishPaths[ChassisMemoryKey] = session.redfishPaths[ChassisKey] + "/Memory"
response := session.query(HTTPOperation.GET, session.redfishPaths[ChassisKey])
session.redfishPaths[ChassisPcieDevKey], err = response.odataStringFromJSON("PCIeDevices")
if err != nil {
fmt.Println("init ChassisPcieDev path err", err)
for _, chassisPath := range chassisCollection {
response := session.query(HTTPOperation.GET, chassisPath)
PartNumber, _ := response.stringFromJSON("PartNumber")
if PartNumber == "62-00000629-00-01" { // Seagate CMA enclosure part number
session.ApplianceSN, _ = response.stringFromJSON("SerialNumber")
} else {
session.redfishPaths[ChassisKey] = chassisPath
session.redfishPaths[ChassisMemoryKey] = session.redfishPaths[ChassisKey] + "/Memory"
session.redfishPaths[ChassisPcieDevKey], err = response.odataStringFromJSON("PCIeDevices")
if err != nil {
fmt.Println("init ChassisPcieDev path err", err)
}
session.BladeSN, _ = response.stringFromJSON("SerialNumber")
}
}
} else {
fmt.Println("init ChassisMemory path err", err)
}

} else {
fmt.Println("init Chassis path err", err)
}
Expand Down Expand Up @@ -529,7 +541,7 @@ func (service *httpfishService) CreateSession(ctx context.Context, settings *Con
activeSessions[session.SessionId] = &session
service.service.session = &session

return &CreateSessionResponse{SessionId: session.SessionId, Status: "Success", ServiceError: nil}, nil
return &CreateSessionResponse{SessionId: session.SessionId, Status: "Success", ServiceError: nil, ChassisSN: session.BladeSN, EnclosureSN: session.ApplianceSN}, nil
}

// DeleteSession: Delete a session previously established with an endpoint service
Expand Down
2 changes: 2 additions & 0 deletions pkg/backend/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type CreateSessionResponse struct {
SessionId string // The session id returned form creating a session
Status string // The status of the request
ServiceError error // Any error returned by the service
ChassisSN string // The serial number returned from the redfish chassis schema
EnclosureSN string // The serial number returned from the redfish chassis schema for the enclosure
}

type DeleteSessionRequest struct {
Expand Down
9 changes: 6 additions & 3 deletions pkg/manager/appliance.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,12 @@ func (a *Appliance) AddBlade(ctx context.Context, c *openapi.Credentials) (*Blad
}

bladeId := c.CustomId
if bladeId == "" {
// Generate default id using last N digits of the session id combined with the default prefix
bladeId = fmt.Sprintf("%s-%s", ID_PREFIX_BLADE_DFLT, response.SessionId[(len(response.SessionId)-common.NumUuidCharsForId):])
if bladeId == "" { // Order CustomeId > BladeSN > UUID
bladeId = response.ChassisSN
if bladeId == "" {
// Generate default id using last N digits of the session id combined with the default prefix
bladeId = fmt.Sprintf("%s-%s", ID_PREFIX_BLADE_DFLT, response.SessionId[(len(response.SessionId)-common.NumUuidCharsForId):])
}
}

// Check for duplicate ID
Expand Down
9 changes: 6 additions & 3 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,12 @@ func AddHost(ctx context.Context, c *openapi.Credentials) (*Host, error) {
}

hostId := c.CustomId
if hostId == "" {
// Generate default id using last N digits of the session id combined with the default prefix
hostId = fmt.Sprintf("%s-%s", ID_PREFIX_HOST_DFLT, response.SessionId[(len(response.SessionId)-common.NumUuidCharsForId):])
if hostId == "" { // Order CustomeId > HostSN > UUID
hostId = response.ChassisSN
if hostId == "" {
// Generate default id using last N digits of the session id combined with the default prefix
hostId = fmt.Sprintf("%s-%s", ID_PREFIX_HOST_DFLT, response.SessionId[(len(response.SessionId)-common.NumUuidCharsForId):])
}
}

// Check for duplicate ID.
Expand Down

0 comments on commit 012ae65

Please sign in to comment.