Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move tags shared between metal-api and metal-bmc to metal-lib #42

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/kelseyhightower/envconfig v1.4.0
github.com/metal-stack/go-hal v0.4.3
github.com/metal-stack/metal-go v0.21.5
github.com/metal-stack/metal-lib v0.11.2
github.com/metal-stack/metal-lib v0.11.3-0.20221027084003-85902ea85904
github.com/metal-stack/v v1.0.3
github.com/stretchr/testify v1.8.1
go.uber.org/zap v1.24.0
Expand Down Expand Up @@ -60,8 +60,8 @@ require (
github.com/stmcginnis/gofish v0.13.0 // indirect
github.com/vmware/goipmi v0.0.0-20181114221114-2333cd82d702 // indirect
go.mongodb.org/mongo-driver v1.11.1 // indirect
go.opentelemetry.io/otel v1.11.1 // indirect
go.opentelemetry.io/otel/trace v1.11.1 // indirect
go.opentelemetry.io/otel v1.11.2 // indirect
go.opentelemetry.io/otel/trace v1.11.2 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/net v0.5.0 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ github.com/avast/retry-go/v4 v4.3.2 h1:x4sTEu3jSwr7zNjya8NTdIN+U88u/jtO/q3OupBoD
github.com/avast/retry-go/v4 v4.3.2/go.mod h1:rg6XFaiuFYII0Xu3RDbZQkxCofFwruZKW8oEF1jpWiU=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/bmizerany/perks v0.0.0-20141205001514-d9a9656a3a4b h1:AP/Y7sqYicnjGDfD5VcY4CIfh1hRXBUavxrvELjTiOE=
github.com/bmizerany/perks v0.0.0-20220928223023-dcf613bf3504 h1:3MsMltJRxil0bYwpVHwa1JO6Aw83/X7cyjvScSvgNRo=
github.com/coreos/go-oidc/v3 v3.5.0 h1:VxKtbccHZxs8juq7RdJntSqtXFtde9YpNpGn0yqgEHw=
github.com/coreos/go-oidc/v3 v3.5.0/go.mod h1:ecXRtV4romGPeO6ieExAsUK9cb/3fp9hXNz1tlv8PIM=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand Down Expand Up @@ -163,8 +163,8 @@ github.com/metal-stack/go-hal v0.4.3 h1:1DlpbXZ2lBu/pmeVpYZxUFRabB37LJTo8EiyVDb5
github.com/metal-stack/go-hal v0.4.3/go.mod h1:8Lgr1frBkp6+6lZ7FoKYMH8rCKoT5THqSvwP+BZVM7I=
github.com/metal-stack/metal-go v0.21.5 h1:MoJqJRzbciMflV3CzMPV4oYIcl0whvboG5kGrnIGosk=
github.com/metal-stack/metal-go v0.21.5/go.mod h1:IZ7qY6dUAi72ZTz7Ni5cwWzzUXJj2Or1t04c3u4AUzU=
github.com/metal-stack/metal-lib v0.11.2 h1:HqPMbHS7zMBRAcoGhbsUZRjDPvOtgI6qNshzd0bSmJQ=
github.com/metal-stack/metal-lib v0.11.2/go.mod h1:Ge1ypz6aOf2ab98kr8GYMXD8eZ7VfKFUfUE3p/8Sm3g=
github.com/metal-stack/metal-lib v0.11.3-0.20221027084003-85902ea85904 h1:SztkhpjrVQmnTQkNBzeIOfhS6xDzPQ5EeqtVmOjhD48=
github.com/metal-stack/metal-lib v0.11.3-0.20221027084003-85902ea85904/go.mod h1:noKHbVdZ9UDgDQOWBpU/uVOLk0oOXmDDR921HECbOVM=
github.com/metal-stack/security v0.6.6 h1:KSPNN8YZd2EJEjsJ0xCBcd5o53uU0iFupahHA9Twuh0=
github.com/metal-stack/security v0.6.6/go.mod h1:WchPm3+2Xjj1h7AxM+DsnR9EWgLw+ktoGCl/0gcmgSA=
github.com/metal-stack/v v1.0.3 h1:Sh2oBlnxrCUD+mVpzfC8HiqL045YWkxs0gpTvkjppqs=
Expand Down Expand Up @@ -218,7 +218,7 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/vmware/goipmi v0.0.0-20181114221114-2333cd82d702 h1:yx587LNBbOpIxzCBHBiI94Wx8ryIAFlu1w0lDwm64cA=
github.com/vmware/goipmi v0.0.0-20181114221114-2333cd82d702/go.mod h1:YiWonbS/PuCtti3wt9jl+FvNEJ7c0nvmjGoEYxdjyk0=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
Expand All @@ -233,11 +233,11 @@ go.mongodb.org/mongo-driver v1.7.5/go.mod h1:VXEWRZ6URJIkUq2SCAyapmhH0ZLRBP+FT4x
go.mongodb.org/mongo-driver v1.10.0/go.mod h1:wsihk0Kdgv8Kqu1Anit4sfK+22vSFbUrAVEYRhCXrA8=
go.mongodb.org/mongo-driver v1.11.1 h1:QP0znIRTuL0jf1oBQoAoM0C6ZJfBK4kx0Uumtv1A7w8=
go.mongodb.org/mongo-driver v1.11.1/go.mod h1:s7p5vEtfbeR1gYi6pnj3c3/urpbLv2T5Sfd6Rp2HBB8=
go.opentelemetry.io/otel v1.11.1 h1:4WLLAmcfkmDk2ukNXJyq3/kiz/3UzCaYq6PskJsaou4=
go.opentelemetry.io/otel v1.11.1/go.mod h1:1nNhXBbWSD0nsL38H6btgnFN2k4i0sNLHNNMZMSbUGE=
go.opentelemetry.io/otel v1.11.2 h1:YBZcQlsVekzFsFbjygXMOXSs6pialIZxcjfO/mBDmR0=
go.opentelemetry.io/otel v1.11.2/go.mod h1:7p4EUV+AqgdlNV9gL97IgUZiVR3yrFXYo53f9BM3tRI=
go.opentelemetry.io/otel/sdk v1.11.1 h1:F7KmQgoHljhUuJyA+9BiU+EkJfyX5nVVF4wyzWZpKxs=
go.opentelemetry.io/otel/trace v1.11.1 h1:ofxdnzsNrGBYXbP7t7zpUK281+go5rF7dvdIZXF8gdQ=
go.opentelemetry.io/otel/trace v1.11.1/go.mod h1:f/Q9G7vzk5u91PhbmKbg1Qn0rzH1LJ4vbPHFGkTPtOk=
go.opentelemetry.io/otel/trace v1.11.2 h1:Xf7hWSF2Glv0DE3MH7fBHvtpSBsjcBUe5MYAmZM/+y0=
go.opentelemetry.io/otel/trace v1.11.2/go.mod h1:4N+yC7QEz7TTsG9BSRLNAa63eg5E06ObSbKPmxQ/pKA=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
Expand Down
45 changes: 11 additions & 34 deletions internal/bmc/bmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/metal-stack/go-hal"
"github.com/metal-stack/go-hal/connect"
halzap "github.com/metal-stack/go-hal/pkg/logger/zap"
"github.com/metal-stack/metal-lib/pkg/tag"

"go.uber.org/zap"
)
Expand Down Expand Up @@ -47,19 +48,21 @@ func New(c Config) *BMCService {
return b
}

// FIXME these structs are duplicates of metal-api ones
type MachineEvent struct {
Type EventType `json:"type,omitempty"`
OldMachineID string `json:"old,omitempty"`
Cmd *MachineExecCommand `json:"cmd,omitempty"`
Type tag.MachineEventType `json:"type,omitempty"`
Cmd *MachineExecCommand `json:"cmd,omitempty"`
}

// FIXME these structs are duplicates of metal-api ones
type MachineExecCommand struct {
TargetMachineID string `json:"target,omitempty"`
Command MachineCommand `json:"cmd,omitempty"`
IPMI *IPMI `json:"ipmi,omitempty"`
FirmwareUpdate *FirmwareUpdate `json:"firmwareupdate,omitempty"`
TargetMachineID string `json:"target,omitempty"`
Command tag.MachineCommand `json:"cmd,omitempty"`
IPMI *IPMI `json:"ipmi,omitempty"`
FirmwareUpdate *FirmwareUpdate `json:"firmwareupdate,omitempty"`
}

// FIXME these structs are duplicates of metal-api ones
type IPMI struct {
// Address is host:port of the connection to the ipmi BMC, host can be either a ip address or a hostname
Address string `json:"address"`
Expand All @@ -68,6 +71,7 @@ type IPMI struct {
Fru Fru `json:"fru"`
}

// FIXME these structs are duplicates of metal-api ones
type FirmwareUpdate struct {
Kind string `json:"kind"`
URL string `json:"url"`
Expand All @@ -77,33 +81,6 @@ type Fru struct {
BoardPartNumber string `json:"board_part_number"`
}

type MachineCommand string

// FIXME these constants must move to a single location
const (
MachineOnCmd MachineCommand = "ON"
MachineOffCmd MachineCommand = "OFF"
MachineResetCmd MachineCommand = "RESET"
MachineCycleCmd MachineCommand = "CYCLE"
MachineBiosCmd MachineCommand = "BIOS"
MachineDiskCmd MachineCommand = "DISK"
MachinePxeCmd MachineCommand = "PXE"
MachineReinstallCmd MachineCommand = "REINSTALL"
ChassisIdentifyLEDOnCmd MachineCommand = "LED-ON"
ChassisIdentifyLEDOffCmd MachineCommand = "LED-OFF"
UpdateFirmwareCmd MachineCommand = "UPDATE-FIRMWARE"
)

type EventType string

// FIXME these constants must move to a single location
const (
Create EventType = "create"
Update EventType = "update"
Delete EventType = "delete"
Command EventType = "command"
)

func (b *BMCService) outBand(ipmi *IPMI) (hal.OutBand, error) {
host, portString, found := strings.Cut(ipmi.Address, ":")
if !found {
Expand Down
4 changes: 2 additions & 2 deletions internal/bmc/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ func (b *BMCService) UpdateFirmware(outBand hal.OutBand, event *MachineEvent) er

fw := event.Cmd.FirmwareUpdate
switch fw.Kind {
case string(models.V1MachineUpdateFirmwareRequestKindBios):
case models.V1MachineUpdateFirmwareRequestKindBios:
b.log.Infow("update firmware bios", "download url", fw.URL)
go func() {
err := outBand.UpdateBIOS(fw.URL)
if err != nil {
b.log.Errorw("updatebios", "error", err)
}
}()
case string(models.V1MachineUpdateFirmwareRequestKindBmc):
case models.V1MachineUpdateFirmwareRequestKindBmc:
b.log.Infow("update firmware bmc", "download url", fw.URL)
go func() {
err := outBand.UpdateBMC(fw.URL)
Expand Down
29 changes: 15 additions & 14 deletions internal/bmc/nsq.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/metal-stack/go-hal"

"github.com/metal-stack/metal-lib/bus"
"github.com/metal-stack/metal-lib/pkg/tag"
)

// timeout for the nsq handler methods
Expand Down Expand Up @@ -59,44 +60,44 @@ func (b *BMCService) InitConsumer() error {
}

switch event.Type {
case Delete:
case tag.MachineEventDelete:
err := outBand.BootFrom(hal.BootTargetPXE)
if err != nil {
return err
}
return outBand.PowerReset()
case Command:
case tag.MachineEventCommand:
switch event.Cmd.Command {
case MachineOnCmd:
case tag.MachineOnCmd:
return outBand.PowerOn()
case MachineOffCmd:
case tag.MachineOffCmd:
return outBand.PowerOff()
case MachineResetCmd:
case tag.MachineResetCmd:
return outBand.PowerReset()
case MachineCycleCmd:
case tag.MachineCycleCmd:
return outBand.PowerCycle()
case MachineBiosCmd:
case tag.MachineBiosCmd:
return outBand.BootFrom(hal.BootTargetBIOS)
case MachineDiskCmd:
case tag.MachineDiskCmd:
return outBand.BootFrom(hal.BootTargetDisk)
case MachinePxeCmd:
case tag.MachinePxeCmd:
return outBand.BootFrom(hal.BootTargetPXE)
case MachineReinstallCmd:
case tag.MachineReinstallCmd:
err := outBand.BootFrom(hal.BootTargetPXE)
if err != nil {
return err
}
return outBand.PowerCycle()
case ChassisIdentifyLEDOnCmd:
case tag.ChassisIdentifyLEDOnCmd:
return outBand.IdentifyLEDOn()
case ChassisIdentifyLEDOffCmd:
case tag.ChassisIdentifyLEDOffCmd:
return outBand.IdentifyLEDOff()
case UpdateFirmwareCmd:
case tag.UpdateFirmwareCmd:
return b.UpdateFirmware(outBand, event)
default:
b.log.Errorw("unhandled command", "topic", b.machineTopic, "channel", "core", "event", event)
}
case Create, Update:
case tag.MachineEventCreate, tag.MachineEventUpdate:
fallthrough
default:
b.log.Warnw("unhandled event", "topic", b.machineTopic, "channel", "core", "event", event)
Expand Down