Skip to content

Commit

Permalink
Import old code from oob (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
5kt authored Apr 19, 2024
1 parent f7986ac commit 277b312
Show file tree
Hide file tree
Showing 6 changed files with 1,343 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ linters:
- dupl
- errcheck
- exportloopref
- goconst
# - goconst
- gofmt
- goimports
- gosimple
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/golangci/golangci-lint v1.57.2
github.com/google/addlicense v1.1.1
github.com/google/uuid v1.6.0
github.com/hashicorp/go-multierror v1.1.1
github.com/ironcore-dev/ipam v0.2.1
github.com/ironcore-dev/vgopath v0.1.4
github.com/onsi/ginkgo/v2 v2.17.1
Expand All @@ -16,6 +17,8 @@ require (
github.com/sethvargo/go-password v0.3.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.18.2
github.com/stmcginnis/gofish v0.15.0
golang.org/x/text v0.14.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.29.4
k8s.io/apimachinery v0.29.4
Expand Down Expand Up @@ -116,6 +119,7 @@ require (
github.com/gostaticanalysis/comment v1.4.2 // indirect
github.com/gostaticanalysis/forcetypeassert v0.1.0 // indirect
github.com/gostaticanalysis/nilerr v0.1.1 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hexops/gotextdiff v1.0.3 // indirect
Expand Down Expand Up @@ -227,7 +231,6 @@ require (
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.19.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ github.com/gostaticanalysis/nilerr v0.1.1/go.mod h1:wZYb6YI5YAxxq0i1+VJbY0s2YONW
github.com/gostaticanalysis/testutil v0.3.1-0.20210208050101-bfb5c8eec0e4/go.mod h1:D+FIZ+7OahH3ePw/izIEeH5I06eKs1IKI4Xr64/Am3M=
github.com/gostaticanalysis/testutil v0.4.0 h1:nhdCmubdmDF6VEatUNjgUZBJKWRqugoISdUv3PPQgHY=
github.com/gostaticanalysis/testutil v0.4.0/go.mod h1:bLIoPefWXrRi/ssLFWX1dx7Repi5x3CuviD3dgAZaBU=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
Expand Down Expand Up @@ -574,6 +578,8 @@ github.com/ssgreg/nlreturn/v2 v2.2.1 h1:X4XDI7jstt3ySqGU86YGAURbxw3oTDPK9sPEi6YE
github.com/ssgreg/nlreturn/v2 v2.2.1/go.mod h1:E/iiPB78hV7Szg2YfRgyIrk1AD6JVMTRkkxBiELzh2I=
github.com/stbenjam/no-sprintf-host-port v0.1.1 h1:tYugd/yrm1O0dV+ThCbaKZh195Dfm07ysF0U6JQXczc=
github.com/stbenjam/no-sprintf-host-port v0.1.1/go.mod h1:TLhvtIvONRzdmkFiio4O8LHsN9N74I+PhRquPsxpL0I=
github.com/stmcginnis/gofish v0.15.0 h1:8TG41+lvJk/0Nf8CIIYErxbMlQUy80W0JFRZP3Ld82A=
github.com/stmcginnis/gofish v0.15.0/go.mod h1:BLDSFTp8pDlf/xDbLZa+F7f7eW0E/CHCboggsu8CznI=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
Expand Down
73 changes: 73 additions & 0 deletions internal/bmc/bmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,80 @@

package bmc

import (
"context"
"fmt"
"regexp"
"time"

"github.com/ironcore-dev/metal/internal/log"
)

type BMC interface {
Type() string
Tags() map[string]string
Credentials() (Credentials, time.Time)
EnsureInitialCredentials(ctx context.Context, defaultCreds []Credentials, tempPassword string) error
Connect(ctx context.Context) error
CreateUser(ctx context.Context, creds Credentials, tempPassword string) error
DeleteUsers(ctx context.Context, regex *regexp.Regexp) error
ReadInfo(ctx context.Context) (Info, error)
}

type LEDControl interface {
SetLocatorLED(ctx context.Context, state string) (string, error)
}

type PowerControl interface {
PowerOn(ctx context.Context) error
PowerOff(ctx context.Context, immediate bool) error
}

type ResetControl interface {
Reset(ctx context.Context, immediate bool) error
}

type newBMCFunc func(tags map[string]string, host string, port int, creds Credentials, exp time.Time) BMC

var (
bmcs = make(map[string]newBMCFunc)
)

func registerBMC(newFunc newBMCFunc) {
bmcs[newFunc(nil, "", 0, Credentials{}, time.Time{}).Type()] = newFunc
}

func NewBMC(typ string, tags map[string]string, host string, port int, creds Credentials, exp time.Time) (BMC, error) {
newFunc, ok := bmcs[typ]
if !ok {
return nil, fmt.Errorf("BMC of type %s is not supported", typ)
}

return newFunc(tags, host, port, creds, exp), nil
}

type Credentials struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
}

type Info struct {
UUID string
Type string
Capabilities []string
SerialNumber string
SKU string
Manufacturer string
LocatorLED string
Power string
OS string
OSReason string
Console string
FWVersion string
}

func must(ctx context.Context, err error) {
if err != nil {
log.Error(ctx, fmt.Errorf("impossible error (this should never happen lol): %w", err))
}
}
Loading

0 comments on commit 277b312

Please sign in to comment.