From 012ae651cc15b601edc7232b965b8f4adbc5a822 Mon Sep 17 00:00:00 2001 From: Hongjian Fan <86060531+HJ-Fan@users.noreply.github.com> Date: Wed, 7 Aug 2024 14:59:46 -0500 Subject: [PATCH] feat: Use Blade serial number as device ID (#25) 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 --- pkg/backend/httpfish.go | 28 ++++++++++++++++++++-------- pkg/backend/ops.go | 2 ++ pkg/manager/appliance.go | 9 ++++++--- pkg/manager/manager.go | 9 ++++++--- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/pkg/backend/httpfish.go b/pkg/backend/httpfish.go index 7d9d29e..42c1541 100644 --- a/pkg/backend/httpfish.go +++ b/pkg/backend/httpfish.go @@ -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 @@ -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) } @@ -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 diff --git a/pkg/backend/ops.go b/pkg/backend/ops.go index 6922e99..aab9d6b 100644 --- a/pkg/backend/ops.go +++ b/pkg/backend/ops.go @@ -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 { diff --git a/pkg/manager/appliance.go b/pkg/manager/appliance.go index bddfb63..d010595 100644 --- a/pkg/manager/appliance.go +++ b/pkg/manager/appliance.go @@ -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 diff --git a/pkg/manager/manager.go b/pkg/manager/manager.go index f16351d..7ef05b5 100644 --- a/pkg/manager/manager.go +++ b/pkg/manager/manager.go @@ -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.