Skip to content

Commit cc279df

Browse files
committed
migrate away from nsq
1 parent 91b9eaa commit cc279df

File tree

10 files changed

+159
-306
lines changed

10 files changed

+159
-306
lines changed

go.mod

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ require (
66
github.com/gliderlabs/ssh v0.3.8
77
github.com/google/go-cmp v0.7.0
88
github.com/kelseyhightower/envconfig v1.4.0
9-
github.com/metal-stack/api v0.0.40-0.20260116144635-78c74c55ac7e
9+
github.com/metal-stack/api v0.0.40-0.20260119070955-8b2e235057ef
1010
github.com/metal-stack/go-hal v0.6.1
1111
github.com/metal-stack/metal-lib v0.23.5
1212
github.com/metal-stack/v v1.0.3
13-
github.com/nsqio/go-nsq v1.1.0
1413
github.com/stretchr/testify v1.11.1
1514
golang.org/x/crypto v0.47.0
1615
golang.org/x/sync v0.19.0
@@ -20,27 +19,25 @@ require (
2019
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.11-20251209175733-2a1774d88802.1 // indirect
2120
connectrpc.com/connect v1.19.1 // indirect
2221
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
23-
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
2422
github.com/avast/retry-go/v4 v4.7.0 // indirect
2523
github.com/creack/pty v1.1.24 // indirect
2624
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
27-
github.com/go-openapi/errors v0.22.0 // indirect
28-
github.com/go-openapi/strfmt v0.23.0 // indirect
25+
github.com/go-openapi/errors v0.22.6 // indirect
26+
github.com/go-openapi/strfmt v0.25.0 // indirect
27+
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
2928
github.com/golang-jwt/jwt/v5 v5.3.0 // indirect
30-
github.com/golang/snappy v1.0.0 // indirect
3129
github.com/google/uuid v1.6.0 // indirect
3230
github.com/klauspost/compress v1.18.3 // indirect
3331
github.com/klauspost/connect-compress/v2 v2.1.0 // indirect
3432
github.com/minio/minlz v1.0.1 // indirect
35-
github.com/mitchellh/mapstructure v1.5.0 // indirect
3633
github.com/oklog/ulid v1.3.1 // indirect
3734
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
3835
github.com/rogpeppe/go-internal v1.14.1 // indirect
3936
github.com/sethvargo/go-password v0.3.1 // indirect
4037
github.com/stmcginnis/gofish v0.20.0 // indirect
4138
github.com/stretchr/objx v0.5.3 // indirect
4239
github.com/vmware/goipmi v0.0.0-20181114221114-2333cd82d702 // indirect
43-
go.mongodb.org/mongo-driver v1.17.1 // indirect
40+
go.mongodb.org/mongo-driver v1.17.6 // indirect
4441
golang.org/x/net v0.49.0 // indirect
4542
golang.org/x/sys v0.40.0 // indirect
4643
golang.org/x/text v0.33.0 // indirect

go.sum

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ connectrpc.com/connect v1.19.1 h1:R5M57z05+90EfEvCY1b7hBxDVOUl45PrtXtAV2fOC14=
44
connectrpc.com/connect v1.19.1/go.mod h1:tN20fjdGlewnSFeZxLKb0xwIZ6ozc3OQs2hTXy4du9w=
55
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
66
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
7-
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
8-
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
97
github.com/avast/retry-go/v4 v4.7.0 h1:yjDs35SlGvKwRNSykujfjdMxMhMQQM0TnIjJaHB+Zio=
108
github.com/avast/retry-go/v4 v4.7.0/go.mod h1:ZMPDa3sY2bKgpLtap9JRUgk2yTAba7cgiFhqxY2Sg6Q=
119
github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s=
@@ -15,15 +13,16 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
1513
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1614
github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c=
1715
github.com/gliderlabs/ssh v0.3.8/go.mod h1:xYoytBv1sV0aL3CavoDuJIQNURXkkfPA/wxQ1pL1fAU=
18-
github.com/go-openapi/errors v0.22.0 h1:c4xY/OLxUBSTiepAg3j/MHuAv5mJhnf53LLMWFB+u/w=
19-
github.com/go-openapi/errors v0.22.0/go.mod h1:J3DmZScxCDufmIMsdOuDHxJbdOGC0xtUynjIx092vXE=
20-
github.com/go-openapi/strfmt v0.23.0 h1:nlUS6BCqcnAk0pyhi9Y+kdDVZdZMHfEKQiS4HaMgO/c=
21-
github.com/go-openapi/strfmt v0.23.0/go.mod h1:NrtIpfKtWIygRkKVsxh7XQMDQW5HKQl6S5ik2elW+K4=
16+
github.com/go-openapi/errors v0.22.6 h1:eDxcf89O8odEnohIXwEjY1IB4ph5vmbUsBMsFNwXWPo=
17+
github.com/go-openapi/errors v0.22.6/go.mod h1:z9S8ASTUqx7+CP1Q8dD8ewGH/1JWFFLX/2PmAYNQLgk=
18+
github.com/go-openapi/strfmt v0.25.0 h1:7R0RX7mbKLa9EYCTHRcCuIPcaqlyQiWNPTXwClK0saQ=
19+
github.com/go-openapi/strfmt v0.25.0/go.mod h1:nNXct7OzbwrMY9+5tLX4I21pzcmE6ccMGXl3jFdPfn8=
20+
github.com/go-openapi/testify/v2 v2.0.2 h1:X999g3jeLcoY8qctY/c/Z8iBHTbwLz7R2WXd6Ub6wls=
21+
github.com/go-openapi/testify/v2 v2.0.2/go.mod h1:HCPmvFFnheKK2BuwSA0TbbdxJ3I16pjwMkYkP4Ywn54=
22+
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
23+
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
2224
github.com/golang-jwt/jwt/v5 v5.3.0 h1:pv4AsKCKKZuqlgs5sUmn4x8UlGa0kEVt/puTpKx9vvo=
2325
github.com/golang-jwt/jwt/v5 v5.3.0/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
24-
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
25-
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
26-
github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
2726
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
2827
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
2928
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
@@ -38,8 +37,8 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
3837
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
3938
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
4039
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
41-
github.com/metal-stack/api v0.0.40-0.20260116144635-78c74c55ac7e h1:pcGKjenVHnodSL+DMy1yG2+TdQPFqMYq7vysRYamYr4=
42-
github.com/metal-stack/api v0.0.40-0.20260116144635-78c74c55ac7e/go.mod h1:vdBRx9vlAnSjyn7gEjD0M6JqQNFt/w+KRTzvZIl2ixQ=
40+
github.com/metal-stack/api v0.0.40-0.20260119070955-8b2e235057ef h1:rFp0/NdlPjSIe3Axa9q/ocomEqobhtVzl/Sv+/pCOTE=
41+
github.com/metal-stack/api v0.0.40-0.20260119070955-8b2e235057ef/go.mod h1:vdBRx9vlAnSjyn7gEjD0M6JqQNFt/w+KRTzvZIl2ixQ=
4342
github.com/metal-stack/go-hal v0.6.1 h1:HIagf4i109pnTZonPwF6zk/W/f2Ifl68zSQxE81xIls=
4443
github.com/metal-stack/go-hal v0.6.1/go.mod h1:teNH6t6Iznbdq/DmofAcVWeRxmfLPsrubFzFMpRkWEY=
4544
github.com/metal-stack/metal-lib v0.23.5 h1:ozrkB3DNr3Cqn8nkBvmzc/KKpYqC1j1mv2OVOj8i7Ac=
@@ -48,10 +47,6 @@ github.com/metal-stack/v v1.0.3 h1:Sh2oBlnxrCUD+mVpzfC8HiqL045YWkxs0gpTvkjppqs=
4847
github.com/metal-stack/v v1.0.3/go.mod h1:YTahEu7/ishwpYKnp/VaW/7nf8+PInogkfGwLcGPdXg=
4948
github.com/minio/minlz v1.0.1 h1:OUZUzXcib8diiX+JYxyRLIdomyZYzHct6EShOKtQY2A=
5049
github.com/minio/minlz v1.0.1/go.mod h1:qT0aEB35q79LLornSzeDH75LBf3aH1MV+jB5w9Wasec=
51-
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
52-
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
53-
github.com/nsqio/go-nsq v1.1.0 h1:PQg+xxiUjA7V+TLdXw7nVrJ5Jbl3sN86EhGCQj4+FYE=
54-
github.com/nsqio/go-nsq v1.1.0/go.mod h1:vKq36oyeVXgsS5Q8YEO7WghqidAVXQlcFxzQbQTuDEY=
5550
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
5651
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
5752
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@@ -70,8 +65,8 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
7065
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
7166
github.com/vmware/goipmi v0.0.0-20181114221114-2333cd82d702 h1:yx587LNBbOpIxzCBHBiI94Wx8ryIAFlu1w0lDwm64cA=
7267
github.com/vmware/goipmi v0.0.0-20181114221114-2333cd82d702/go.mod h1:YiWonbS/PuCtti3wt9jl+FvNEJ7c0nvmjGoEYxdjyk0=
73-
go.mongodb.org/mongo-driver v1.17.1 h1:Wic5cJIwJgSpBhe3lx3+/RybR5PiYRMpVFgO7cOHyIM=
74-
go.mongodb.org/mongo-driver v1.17.1/go.mod h1:wwWm/+BuOddhcq3n68LKRmgk2wXzmF6s0SFOa0GINL4=
68+
go.mongodb.org/mongo-driver v1.17.6 h1:87JUG1wZfWsr6rIz3ZmpH90rL5tea7O3IHuSwHUpsss=
69+
go.mongodb.org/mongo-driver v1.17.6/go.mod h1:Hy04i7O2kC4RS06ZrhPRqj/u4DTYkFDAAccj+rVKqgQ=
7570
golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8=
7671
golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A=
7772
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=

internal/bmc/bmc.go

Lines changed: 126 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,161 @@
11
package bmc
22

33
import (
4+
"context"
45
"fmt"
6+
"io"
57
"log/slog"
68
"strconv"
79
"strings"
8-
"time"
910

11+
apiclient "github.com/metal-stack/api/go/client"
12+
apiv2 "github.com/metal-stack/api/go/metalstack/api/v2"
13+
infrav2 "github.com/metal-stack/api/go/metalstack/infra/v2"
1014
"github.com/metal-stack/go-hal"
1115
"github.com/metal-stack/go-hal/connect"
1216
halslog "github.com/metal-stack/go-hal/pkg/logger/slog"
1317
"github.com/metal-stack/metal-bmc/pkg/config"
1418
)
1519

1620
type BMCService struct {
17-
log *slog.Logger
18-
// NSQ related config options
19-
mqAddress string
20-
mqCACertFile string
21-
mqClientCertFile string
22-
mqClientCertKeyFile string
23-
mqLogLevel string
24-
machineTopic string
25-
machineTopicTTL time.Duration
21+
log *slog.Logger
22+
cfg *config.Config
23+
client apiclient.Client
2624
}
2725

28-
func New(log *slog.Logger, c *config.Config) *BMCService {
26+
func New(log *slog.Logger, client apiclient.Client, c *config.Config) *BMCService {
2927
b := &BMCService{
30-
log: log,
31-
mqAddress: c.MQAddress,
32-
mqCACertFile: c.MQCACertFile,
33-
mqClientCertFile: c.MQClientCertFile,
34-
mqClientCertKeyFile: c.MQClientCertKeyFile,
35-
mqLogLevel: c.MQLogLevel,
36-
machineTopic: c.MachineTopic,
37-
machineTopicTTL: c.MachineTopicTTL,
28+
log: log,
29+
cfg: c,
30+
client: client,
3831
}
3932
return b
4033
}
4134

42-
type MachineEvent struct {
43-
Type EventType `json:"type,omitempty"`
44-
OldMachineID string `json:"old,omitempty"`
45-
Cmd *MachineExecCommand `json:"cmd,omitempty"`
35+
func (b *BMCService) ProcessCommands() {
36+
b.log.Info("processCommand, start waiting for bmc commands")
37+
go func() {
38+
messageChan, errChan := b.subscribeAsync(context.Background(), b.cfg.PartitionID)
39+
select {
40+
case message := <-messageChan:
41+
err := b.handleMessage(message)
42+
if err != nil {
43+
b.log.Error("processCommand", "error", err)
44+
}
45+
case err := <-errChan:
46+
b.log.Error("processCommand", "error", err)
47+
}
48+
}()
4649
}
4750

48-
type MachineExecCommand struct {
49-
TargetMachineID string `json:"target,omitempty"`
50-
Command MachineCommand `json:"cmd,omitempty"`
51-
IPMI *IPMI `json:"ipmi,omitempty"`
52-
FirmwareUpdate *FirmwareUpdate `json:"firmwareupdate,omitempty"`
53-
}
51+
func (b *BMCService) handleMessage(message *infrav2.WaitForBMCCommandResponse) error {
52+
b.log.Info("handlemessage", "message", message)
5453

55-
type IPMI struct {
56-
// Address is host:port of the connection to the ipmi BMC, host can be either a ip address or a hostname
57-
Address string `json:"address"`
58-
User string `json:"user"`
59-
Password string `json:"password"`
60-
Fru Fru `json:"fru"`
61-
}
54+
if message.MachineBmc == nil {
55+
return fmt.Errorf("event does not contain bmc details:%v", message)
56+
}
57+
outBand, err := b.outBand(message.MachineBmc)
58+
if err != nil {
59+
b.log.Error("error creating outband connection", "error", err)
60+
return err
61+
}
6262

63-
type FirmwareUpdate struct {
64-
Kind string `json:"kind"`
65-
URL string `json:"url"`
63+
switch message.BmcCommand {
64+
case apiv2.MachineBMCCommand_MACHINE_BMC_COMMAND_MACHINE_DELETED:
65+
err := outBand.BootFrom(hal.BootTargetPXE)
66+
if err != nil {
67+
return err
68+
}
69+
return outBand.PowerReset()
70+
case apiv2.MachineBMCCommand_MACHINE_BMC_COMMAND_ON:
71+
return outBand.PowerOn()
72+
case apiv2.MachineBMCCommand_MACHINE_BMC_COMMAND_OFF:
73+
return outBand.PowerOff()
74+
case apiv2.MachineBMCCommand_MACHINE_BMC_COMMAND_RESET:
75+
return outBand.PowerReset()
76+
case apiv2.MachineBMCCommand_MACHINE_BMC_COMMAND_CYCLE:
77+
return outBand.PowerCycle()
78+
case apiv2.MachineBMCCommand_MACHINE_BMC_COMMAND_BOOT_TO_BIOS:
79+
return outBand.BootFrom(hal.BootTargetBIOS)
80+
case apiv2.MachineBMCCommand_MACHINE_BMC_COMMAND_BOOT_FROM_DISK:
81+
return outBand.BootFrom(hal.BootTargetDisk)
82+
case apiv2.MachineBMCCommand_MACHINE_BMC_COMMAND_BOOT_FROM_PXE:
83+
return outBand.BootFrom(hal.BootTargetPXE)
84+
case apiv2.MachineBMCCommand_MACHINE_BMC_COMMAND_IDENTIFY_LED_ON:
85+
return outBand.IdentifyLEDOn()
86+
case apiv2.MachineBMCCommand_MACHINE_BMC_COMMAND_IDENTIFY_LED_OFF:
87+
return outBand.IdentifyLEDOff()
88+
case apiv2.MachineBMCCommand_MACHINE_BMC_COMMAND_MACHINE_CREATED:
89+
return outBand.BootFrom(hal.BootTargetDisk)
90+
default:
91+
b.log.Warn("unhandled command", "command", message.BmcCommand.String())
92+
}
93+
return nil
6694
}
6795

68-
type Fru struct {
69-
BoardPartNumber string `json:"board_part_number"`
96+
// messageHandler is called when a message is received
97+
type messageHandler func(*infrav2.WaitForBMCCommandResponse) error
98+
99+
// Subscribe subscribes to a topic and calls the handler for each message
100+
func (c *BMCService) subscribe(ctx context.Context, topic string, handler messageHandler) error {
101+
stream, err := c.client.Infrav2().BMC().WaitForBMCCommand(ctx, &infrav2.WaitForBMCCommandRequest{Partition: topic})
102+
if err != nil {
103+
return fmt.Errorf("failed to subscribe: %w", err)
104+
}
105+
defer func() {
106+
_ = stream.Close()
107+
}()
108+
109+
c.log.Info("subscribed to machine bmc command", "topic", topic)
110+
111+
// Receive messages
112+
for stream.Receive() {
113+
msg := stream.Msg()
114+
if err := handler(msg); err != nil {
115+
c.log.Error("handler error", "error", err)
116+
}
117+
}
118+
119+
if err := stream.Err(); err != nil {
120+
if err == io.EOF || err == context.Canceled {
121+
return nil
122+
}
123+
return fmt.Errorf("stream error: %w", err)
124+
}
125+
126+
return nil
70127
}
71128

72-
type MachineCommand string
73-
74-
// FIXME these constants must move to a single location
75-
const (
76-
MachineOnCmd MachineCommand = "ON"
77-
MachineOffCmd MachineCommand = "OFF"
78-
MachineResetCmd MachineCommand = "RESET"
79-
MachineCycleCmd MachineCommand = "CYCLE"
80-
MachineBiosCmd MachineCommand = "BIOS"
81-
MachineDiskCmd MachineCommand = "DISK"
82-
MachinePxeCmd MachineCommand = "PXE"
83-
MachineReinstallCmd MachineCommand = "REINSTALL"
84-
ChassisIdentifyLEDOnCmd MachineCommand = "LED-ON"
85-
ChassisIdentifyLEDOffCmd MachineCommand = "LED-OFF"
86-
UpdateFirmwareCmd MachineCommand = "UPDATE-FIRMWARE"
87-
)
129+
// SubscribeAsync subscribes asynchronously and returns a channel of messages
130+
func (c *BMCService) subscribeAsync(ctx context.Context, topic string) (<-chan *infrav2.WaitForBMCCommandResponse, <-chan error) {
131+
var (
132+
msgChan = make(chan *infrav2.WaitForBMCCommandResponse, 100)
133+
errChan = make(chan error, 1)
134+
)
88135

89-
type EventType string
136+
go func() {
137+
defer close(msgChan)
138+
defer close(errChan)
90139

91-
// FIXME these constants must move to a single location
92-
const (
93-
Create EventType = "create"
94-
Update EventType = "update"
95-
Delete EventType = "delete"
96-
Command EventType = "command"
97-
)
140+
err := c.subscribe(ctx, topic, func(msg *infrav2.WaitForBMCCommandResponse) error {
141+
select {
142+
case msgChan <- msg:
143+
return nil
144+
case <-ctx.Done():
145+
return ctx.Err()
146+
}
147+
})
148+
149+
if err != nil && err != context.Canceled {
150+
errChan <- err
151+
}
152+
}()
153+
154+
return msgChan, errChan
155+
}
98156

99-
func (b *BMCService) outBand(ipmi *IPMI) (hal.OutBand, error) {
100-
host, portString, found := strings.Cut(ipmi.Address, ":")
157+
func (b *BMCService) outBand(bmc *apiv2.MachineBMC) (hal.OutBand, error) {
158+
host, portString, found := strings.Cut(bmc.Address, ":")
101159
if !found {
102160
portString = "623"
103161

@@ -106,7 +164,7 @@ func (b *BMCService) outBand(ipmi *IPMI) (hal.OutBand, error) {
106164
if err != nil {
107165
return nil, fmt.Errorf("unable to convert port to an int %w", err)
108166
}
109-
outBand, err := connect.OutBand(host, port, ipmi.User, ipmi.Password, halslog.New(b.log))
167+
outBand, err := connect.OutBand(host, port, bmc.User, bmc.Password, halslog.New(b.log))
110168
if err != nil {
111169
return nil, err
112170
}

internal/bmc/console.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (c *console) sessionHandler(s ssh.Session) {
108108

109109
host, portStr, found := strings.Cut(bmc.Address, ":")
110110
if !found {
111-
c.log.Error("invalid ipmi address", "address", bmc.Address)
111+
c.log.Error("invalid bmc address", "address", bmc.Address)
112112
return
113113
}
114114
port, err := strconv.Atoi(portStr)
@@ -119,7 +119,7 @@ func (c *console) sessionHandler(s ssh.Session) {
119119

120120
ob, err := halconnect.OutBand(host, port, bmc.User, bmc.Password, halslog.New(c.log))
121121
if err != nil {
122-
c.log.Error("failed to out-band connect", "host", host, "port", port, "machineID", machineID, "ipmiuser", bmc.User)
122+
c.log.Error("failed to out-band connect", "host", host, "port", port, "machineID", machineID, "bmc user", bmc.User)
123123
return
124124
}
125125

0 commit comments

Comments
 (0)