Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
use bmc-toolbox component types
Browse files Browse the repository at this point in the history
  • Loading branch information
Alva8756 committed Apr 29, 2024
1 parent 23d610c commit 98912db
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 21 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22
toolchain go1.22.2

require (
github.com/bmc-toolbox/common v0.0.0-20240416132216-a56a09c16f4e
github.com/bmc-toolbox/common v0.0.0-20240423132505-01bb4bac6913
github.com/equinix-labs/otel-init-go v0.0.9
github.com/gin-gonic/gin v1.9.1
github.com/google/uuid v1.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bmc-toolbox/common v0.0.0-20240416132216-a56a09c16f4e h1:MepqMSwXZPngO7KWD0MyaUKuQkZD/yNfpRJhYZszbr4=
github.com/bmc-toolbox/common v0.0.0-20240416132216-a56a09c16f4e/go.mod h1:SY//n1PJjZfbFbmAsB6GvEKbc7UXz3d30s3kWxfJQ/c=
github.com/bmc-toolbox/common v0.0.0-20240423132505-01bb4bac6913 h1:tqNUIR23EV+jn/0uPI+yqJoHEKa59M+WrL3oaXPxwwc=
github.com/bmc-toolbox/common v0.0.0-20240423132505-01bb4bac6913/go.mod h1:SY//n1PJjZfbFbmAsB6GvEKbc7UXz3d30s3kWxfJQ/c=
github.com/bytedance/sonic v1.11.5 h1:G00FYjjqll5iQ1PYXynbg/hyzqBqavH8Mo9/oTopd9k=
github.com/bytedance/sonic v1.11.5/go.mod h1:X2PC2giUdj/Cv2lliWFLk6c/DUQok5rViJSemeB0wDw=
github.com/bytedance/sonic/loader v0.1.0/go.mod h1:UmRT+IRTGKz/DAkzcEGzyVqQFJ7H9BqwBO3pm9H/+HY=
Expand Down
17 changes: 5 additions & 12 deletions internal/fleetdb/fleetdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package internalfleetdb

import (
"context"
"fmt"

common "github.com/bmc-toolbox/common"
"github.com/google/uuid"
"github.com/metal-toolbox/component-inventory/internal/app"
"github.com/metal-toolbox/component-inventory/internal/inventoryconverter"
Expand All @@ -20,7 +20,7 @@ type Client interface {
}

// Creates a new Client, with reasonable defaults
func NewFleetDBClient(ctx context.Context, cfg *app.Configuration) (Client, error) {
func NewFleetDBClient(_ context.Context, cfg *app.Configuration) (Client, error) {
client, err := fleetdb.NewClient(cfg.FleetDBAddress, nil)
if err != nil {
return nil, err
Expand All @@ -30,17 +30,10 @@ func NewFleetDBClient(ctx context.Context, cfg *app.Configuration) (Client, erro
client.SetToken(cfg.FleetDBToken)
}

// TODO: replace it with common.ComponentTypes() after figuring out
// how to fetch ServerComponentType ID.
// Then it's cleaner to move inventoryConverterInstance to the router
// instead of the Client interface.
slugs := make(map[string]*fleetdb.ServerComponentType)
serverComponentTypes, _, err := client.ListServerComponentTypes(ctx, nil)
if err != nil {
return nil, fmt.Errorf("failed to get server component types: %w", err)
}
slugs := make(map[string]bool)
serverComponentTypes := common.ComponentTypes()
for _, ct := range serverComponentTypes {
slugs[ct.Slug] = ct
slugs[ct] = true
}

return &fleetDBClient{
Expand Down
8 changes: 3 additions & 5 deletions internal/inventoryconverter/inventoryconverter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import (
"strings"

"github.com/bmc-toolbox/common"
fleetdb "github.com/metal-toolbox/fleetdb/pkg/api/v1"
rivets "github.com/metal-toolbox/rivets/types"
)

type InventoryConverter struct {
componentSlug map[string]*fleetdb.ServerComponentType
componentSlug map[string]bool
}

func NewInventoryConverter(componentSlug map[string]*fleetdb.ServerComponentType) *InventoryConverter {
func NewInventoryConverter(componentSlug map[string]bool) *InventoryConverter {
return &InventoryConverter{
componentSlug: componentSlug,
}
Expand Down Expand Up @@ -55,11 +54,10 @@ func (ic *InventoryConverter) newComponent(slug, cvendor, cmodel, cserial, cprod
cmodel = cproduct
}
return &rivets.Component{
ID: ic.componentSlug[slug].ID,
Firmware: firmware,
Status: status,
Attributes: attrs,
Name: ic.componentSlug[slug].Name,
Name: slug,
Vendor: cvendor,
Model: cmodel,
Serial: cserial,
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/routes/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func compareComponents(fleetServer, alloyServer *rivets.Server, log *zap.Logger)
}

if !listedByAlloy {
// has slug in alloy list, but fleet vendor+model doesn't in alloy list
// alloy did not report hardware that has previously been in fleetdb
match = false
fields := []zap.Field{
zap.String("device.id", fleetServer.ID),
Expand Down

0 comments on commit 98912db

Please sign in to comment.