Skip to content

Commit

Permalink
Merge branch 'main' into test/auto-discovery-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-howe-1 committed Dec 10, 2024
2 parents 7b0e7b2 + 609f9ef commit d20a488
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 12 deletions.
8 changes: 8 additions & 0 deletions cmd/cfm-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ func main() {
defaultRedfishController := redfishapi.NewDefaultAPIController(defaultRedfishService)
api.AddRedfishRouter(ctx, router, defaultRedfishController)

// Discover devices before loading datastore
bladeDevices, errBlade := services.DiscoverDevices(ctx, defaultApiService, "blade")
hostDevices, errHost := services.DiscoverDevices(ctx, defaultApiService, "cxl-host")
// Add the discovered devices into datastore
if errBlade == nil && errHost == nil {
services.AddDiscoveredDevices(ctx, defaultApiService, bladeDevices, hostDevices)
}

// Load datastore
datastore.DStore().Restore()
data := datastore.DStore().GetDataStore()
Expand Down
22 changes: 20 additions & 2 deletions pkg/manager/appliance.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package manager
import (
"context"
"fmt"
"strings"

"github.com/google/uuid"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -97,12 +98,27 @@ func (a *Appliance) AddBlade(ctx context.Context, c *openapi.Credentials) (*Blad
newErr := fmt.Errorf("create session failure at [%s:%d] using interface [%s]: %w", c.IpAddress, c.Port, backendName, err)
logger.Error(newErr, "failure: add blade")

bladeId := c.CustomId
if bladeId == "" { // Order CustomeId > BladeSN > UUID
bladeId = response.ChassisSN
if bladeId == "" {
// Generate default id using last N digits of a randomly generated uuid combined with the default prefix
// Example uuid: ee0328d9-258a-4e81-976e-b75aa4a2d8f5
uuid := uuid.New().String()
uuid = strings.ReplaceAll(uuid, "-", "")
bladeId = fmt.Sprintf("%s-%s", ID_PREFIX_BLADE_DFLT, uuid[(len(uuid)-common.NumUuidCharsForId):])
}
c.CustomId = bladeId
}

// Continue adding the failed blade to the datastore, but update the connection status to unavailable
newBlade := &Blade{
Id: c.CustomId,
Uri: GetCfmUriBladeId(a.Id, c.CustomId),
Status: common.UNAVAILABLE,
ApplianceId: a.Id,
backendOps: ops,
creds: c,
}
a.Blades[newBlade.Id] = newBlade

Expand Down Expand Up @@ -171,6 +187,8 @@ func (a *Appliance) AddBlade(ctx context.Context, c *openapi.Credentials) (*Blad
Uri: GetCfmUriBladeId(a.Id, c.CustomId),
Status: common.UNAVAILABLE,
ApplianceId: a.Id,
backendOps: ops,
creds: c,
}
a.Blades[newBlade.Id] = newBlade

Expand Down Expand Up @@ -295,11 +313,11 @@ func (a *Appliance) DeleteBladeById(ctx context.Context, bladeId string) (*Blade

blade, err := a.DeleteBladeByIdBackend(ctx, bladeId)
if err != nil || blade == nil {
logger.V(2).Info("success: delete blade by id after backend session failure", "bladeId", blade.Id, "applianceId", a.Id)
logger.V(2).Info("success: delete blade by id after backend session failure", "bladeId", bladeId, "applianceId", a.Id)
return blade, err
}

logger.V(2).Info("success: delete blade by id", "bladeId", blade.Id, "applianceId", a.Id)
logger.V(2).Info("success: delete blade by id", "bladeId", bladeId, "applianceId", a.Id)

return blade, nil
}
Expand Down
35 changes: 27 additions & 8 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ package manager
import (
"context"
"fmt"
"strings"

"github.com/google/uuid"
"k8s.io/klog/v2"

"cfm/pkg/backend"
Expand Down Expand Up @@ -281,11 +283,26 @@ func AddHost(ctx context.Context, c *openapi.Credentials) (*Host, error) {
newErr := fmt.Errorf("create session failure at [%s:%d] using interface [%s]: %w", c.IpAddress, c.Port, backendName, err)
logger.Error(newErr, "failure: add host")

hostId := c.CustomId
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
// Example uuid: ee0328d9-258a-4e81-976e-b75aa4a2d8f5
uuid := uuid.New().String()
uuid = strings.ReplaceAll(uuid, "-", "")
hostId = fmt.Sprintf("%s-%s", ID_PREFIX_HOST_DFLT, uuid[(len(uuid)-common.NumUuidCharsForId):])
}
c.CustomId = hostId
}

// Continue adding the failed host to the datastore, but update the connection status to unavailable
host := &Host{
Id: c.CustomId,
Uri: GetCfmUriHostId(c.CustomId),
Status: common.UNAVAILABLE,
Id: c.CustomId,
Uri: GetCfmUriHostId(c.CustomId),
Status: common.UNAVAILABLE,
backendOps: ops,
creds: c,
}
deviceCache.AddHost(host, false)

Expand Down Expand Up @@ -348,9 +365,11 @@ func AddHost(ctx context.Context, c *openapi.Credentials) (*Host, error) {

// Continue adding the failed host to the datastore, but update the connection status to unavailable
host := &Host{
Id: c.CustomId,
Uri: GetCfmUriHostId(c.CustomId),
Status: common.UNAVAILABLE,
Id: c.CustomId,
Uri: GetCfmUriHostId(c.CustomId),
Status: common.UNAVAILABLE,
backendOps: ops,
creds: c,
}
deviceCache.AddHost(host, false)

Expand Down Expand Up @@ -487,11 +506,11 @@ func DeleteHostById(ctx context.Context, hostId string) (*Host, error) {

host, err := DeleteHostByIdBackend(ctx, hostId)
if err != nil || host == nil {
logger.V(2).Info("success: delete host by id after backend session failure", "hostId", host.Id)
logger.V(2).Info("success: delete host by id after backend session failure", "hostId", hostId)
return host, err
}

logger.V(2).Info("success: delete host by id", "hostId", host.Id)
logger.V(2).Info("success: delete host by id", "hostId", hostId)

return host, nil
}
Expand Down
2 changes: 1 addition & 1 deletion webui/src/components/Stores/ApplianceStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,4 @@ export const useApplianceStore = defineStore('appliance', {
this.selectedApplianceId = applianceId;
},
}
})
})
2 changes: 1 addition & 1 deletion webui/src/components/Stores/HostStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,4 @@ export const useHostStore = defineStore('host', {
this.selectedHostStatus = status
}
}
})
})

0 comments on commit d20a488

Please sign in to comment.