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

Import sls #52

Merged
merged 30 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6490634
Checkin
rsjostrand-hpe Jun 6, 2023
46e6d21
Merge remote-tracking branch 'origin/develop' into import-sls
rsjostrand-hpe Jun 6, 2023
fa50a66
Checkin
rsjostrand-hpe Jun 6, 2023
db7ed43
Generate the HSM client from its swagger like SLS
rsjostrand-hpe Jun 6, 2023
b948313
Checkin
rsjostrand-hpe Jun 12, 2023
c3c60c5
Merge remote-tracking branch 'origin/develop' into import-sls
rsjostrand-hpe Jun 12, 2023
1e1a844
checkin
rsjostrand-hpe Jun 12, 2023
1306da9
Checkin
rsjostrand-hpe Jun 12, 2023
e6a691a
Checkin
rsjostrand-hpe Jun 12, 2023
e2fbbb4
Checkin
rsjostrand-hpe Jun 12, 2023
3e78624
Checkin
rsjostrand-hpe Jun 13, 2023
3b3c776
Speed up getLocation slightly
rsjostrand-hpe Jun 13, 2023
06a1899
Checkin
rsjostrand-hpe Jun 13, 2023
b9cdb3b
Add custom template for models to include the mapstruture tag
rsjostrand-hpe Jun 13, 2023
b5a6121
Checkin
rsjostrand-hpe Jun 13, 2023
d98b3b4
Support multiple aliases, untested
rsjostrand-hpe Jun 13, 2023
72a783a
Parallize update to SLS
rsjostrand-hpe Jun 15, 2023
016d8c2
Checkin
rsjostrand-hpe Jun 15, 2023
eb8f3c9
Merge remote-tracking branch 'origin/develop' into import-sls
rsjostrand-hpe Jun 15, 2023
e5ce011
VLAN max is now 4094
rsjostrand-hpe Jun 15, 2023
7e49097
Change log level and leave TODO
rsjostrand-hpe Jun 15, 2023
d1d06cb
Add TODO
rsjostrand-hpe Jun 15, 2023
73b5d11
Checkin
rsjostrand-hpe Jun 15, 2023
ae4b197
Reconcile kind of works now
rsjostrand-hpe Jun 15, 2023
e918b2e
Checkin
rsjostrand-hpe Jun 16, 2023
dbaeb07
Fix
rsjostrand-hpe Jun 16, 2023
a370394
Remove debug code and unused code
rsjostrand-hpe Jun 16, 2023
910d617
Remove more code
rsjostrand-hpe Jun 16, 2023
897028c
Allow for a session to start if datastore does not have required fields
rsjostrand-hpe Jun 16, 2023
2580ab9
Merge pull request #69 from Cray-HPE/hack-sls-import-till-it-works
rsjostrand-hpe Jun 16, 2023
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
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,19 @@ generate-go:

# Generate clients from the following swagger files:
# System Layout Service: ./pkg/sls-client/openapi.yaml
generate-swagger: bin/swagger-codegen-cli.jar
java -jar bin/swagger-codegen-cli.jar generate -i ./pkg/sls-client/openapi.yaml -l go -o ./pkg/sls-client/ -DpackageName=sls_client
generate-swagger-sls-client: bin/swagger-codegen-cli.jar
java -jar bin/swagger-codegen-cli.jar generate -i ./pkg/sls-client/openapi.yaml -l go -o ./pkg/sls-client/ -DpackageName=sls_client -t ./pkg/sls-client/templates
go fmt ./pkg/sls-client/...
goimports -w ./pkg/sls-client

generate: generate-swagger generate-go
# Generate clients from the following swagger files:
# Hardware State Manager: ./pkg/hsm-client/openapi.yaml
generate-swagger-hsm-client: bin/swagger-codegen-cli.jar
java -jar bin/swagger-codegen-cli.jar generate -i ./pkg/hsm-client/openapi.yaml -l go -o ./pkg/hsm-client/ -DpackageName=hsm_client
go fmt ./pkg/hsm-client/...
goimports -w ./pkg/hsm-client

generate: generate-swagger-sls-client generate-swagger-hsm-client generate-go

# Jenkins doesn't have java installed, so the generate target fails to run
bin:
Expand Down
1 change: 1 addition & 0 deletions cmd/session/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func init() {
root.SessionCmd.AddCommand(SessionStopCmd)
root.SessionCmd.AddCommand(SessionStatusCmd)
root.SessionCmd.AddCommand(SessionSummaryCmd)
root.SessionCmd.AddCommand(SessionImportCmd)
jacobsalmela marked this conversation as resolved.
Show resolved Hide resolved

// Session start flags
// TODO need a quick simulation environment flag
Expand Down
61 changes: 61 additions & 0 deletions cmd/session/session_import.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package session

import (
"fmt"
"os"

root "github.com/Cray-HPE/cani/cmd"
"github.com/Cray-HPE/cani/internal/domain"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)

// SessionStopCmd represents the session stop command
var SessionImportCmd = &cobra.Command{
Use: "import",
Short: "TODO THIS IS JUST A SHIM COMMAND",
Long: `TODO THIS IS JUST A SHIM COMMAND`,
SilenceUsage: true, // Errors are more important than the usage
PersistentPreRunE: DatastoreExists, // A session must be active to write to a datastore
RunE: importSession,
// PersistentPostRunE: writeSession,
}

// stopSession stops a session if one exists
func importSession(cmd *cobra.Command, args []string) error {
// Setup profiling
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nice to toggle with a flag

// f, err := os.Create("cpu_profile")
// if err != nil {
// panic(err)
// }

// pprof.StartCPUProfile(f)
// defer pprof.StopCPUProfile()

ds := root.Conf.Session.DomainOptions.DatastorePath
providerName := root.Conf.Session.DomainOptions.Provider
d, err := domain.New(root.Conf.Session.DomainOptions)
if err != nil {
return err
}

if root.Conf.Session.Active {
// Check that the datastore exists before proceeding since we cannot continue without it
_, err := os.Stat(ds)
if err != nil {
return fmt.Errorf("Session is STOPPED with provider '%s' but datastore '%s' does not exist", providerName, ds)
}
log.Info().Msgf("Session is STOPPED")
} else {
log.Info().Msgf("Session with provider '%s' and datastore '%s' is already STOPPED", providerName, ds)
}

log.Info().Msgf("Committing changes to session")

// Commit the external inventory
if err := d.Import(cmd.Context()); err != nil {
return err
}

return nil
}
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/Cray-HPE/hms-sls/v2 v2.1.0
github.com/Cray-HPE/hms-xname v1.1.0
github.com/Cray-HPE/hms-xname v1.1.1-0.20230602152417-25bcdeda83c9
jacobsalmela marked this conversation as resolved.
Show resolved Hide resolved
github.com/antihax/optional v1.0.0
github.com/fatih/color v1.13.0
github.com/google/uuid v1.3.0
Expand All @@ -15,6 +15,7 @@ require (
github.com/santhosh-tekuri/jsonschema/v5 v5.3.0
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.5.1
golang.org/x/oauth2 v0.8.0
gopkg.in/yaml.v3 v3.0.1
inet.af/netaddr v0.0.0-20220617031823-097006376321
Expand All @@ -23,6 +24,7 @@ require (
require (
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
Expand All @@ -31,6 +33,7 @@ require (
github.com/kr/pretty v0.3.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
go4.org/intern v0.0.0-20220617035311-6925f38cc365 // indirect
Expand All @@ -40,4 +43,5 @@ require (
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v2 v2.2.7 // indirect
)
7 changes: 6 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ github.com/Cray-HPE/hms-base/v2 v2.0.1/go.mod h1:Mq+Ao3q4YtNZJZ1ly9wnEIKyvc3+QaA
github.com/Cray-HPE/hms-s3 v1.9.2/go.mod h1:p5pVsMDeOdXKssd9qyFtXo4ztrn2lhD04nrO8+NOi7g=
github.com/Cray-HPE/hms-sls/v2 v2.1.0 h1:NSHlsITIA2pXajnG4kuoZz59+StYWKSLhDb7lkmYqa0=
github.com/Cray-HPE/hms-sls/v2 v2.1.0/go.mod h1:+MSzZViGwiVaip5pZhbrtFTv/8uTXeGrjSnsJMlU8uw=
github.com/Cray-HPE/hms-xname v1.1.0 h1:y/JEM2PbBaD8VbU7u85+/YIugf1Evji59z5IeSffeO8=
github.com/Cray-HPE/hms-xname v1.1.0/go.mod h1:3A70QF0ddmkt/nz0jis5o8UIB4zAmsgsUiN71dr97n4=
github.com/Cray-HPE/hms-xname v1.1.1-0.20230602152417-25bcdeda83c9 h1:mL9LycLicBSk0ROgwqqTy+CQOLME5RDH0mb/7BW0ib8=
github.com/Cray-HPE/hms-xname v1.1.1-0.20230602152417-25bcdeda83c9/go.mod h1:XKdjQSzoTps5KDOE8yWojBTAWASGaS6LfRrVDxwTQO8=
github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA=
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwcg=
Expand Down Expand Up @@ -77,6 +78,7 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cznic/mathutil v0.0.0-20180504122225-ca4c9f2c1369/go.mod h1:e6NPNENfs9mPDVNRekM7lKScauxd5kXTr1Mfyig6TDM=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/denisenkom/go-mssqldb v0.0.0-20200620013148-b91950f658ec/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
Expand Down Expand Up @@ -281,6 +283,7 @@ github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/remyoudompheng/bigfft v0.0.0-20190728182440-6a916e37a237/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
Expand Down Expand Up @@ -318,6 +321,7 @@ github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/tidwall/pretty v0.0.0-20180105212114-65a9db5fad51/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/xanzy/go-gitlab v0.15.0/go.mod h1:8zdQa/ri1dfn8eS3Ir1SyfvOKlw7WBJ8DVThkpGiXrs=
Expand Down Expand Up @@ -647,6 +651,7 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
11 changes: 6 additions & 5 deletions internal/domain/blade.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,12 @@ func (d *Domain) AddBlade(ctx context.Context, deviceTypeSlug string, cabinetOrd
locationOrdinal := hardwareBuildOut.OrdinalPath[len(hardwareBuildOut.OrdinalPath)-1]

hardware := inventory.Hardware{
ID: hardwareBuildOut.ID,
Parent: hardwareBuildOut.ParentID,
Type: hardwareBuildOut.DeviceType.HardwareType,
Vendor: hardwareBuildOut.DeviceType.Manufacturer,
Model: hardwareBuildOut.DeviceType.Model,
ID: hardwareBuildOut.ID,
Parent: hardwareBuildOut.ParentID,
Type: hardwareBuildOut.DeviceType.HardwareType,
DeviceTypeSlug: hardwareBuildOut.DeviceType.Slug,
Vendor: hardwareBuildOut.DeviceType.Manufacturer,
Model: hardwareBuildOut.DeviceType.Model,

LocationOrdinal: &locationOrdinal,

Expand Down
11 changes: 6 additions & 5 deletions internal/domain/cabinet.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ func (d *Domain) AddCabinet(ctx context.Context, deviceTypeSlug string, cabinetO
locationOrdinal := hardwareBuildOut.OrdinalPath[len(hardwareBuildOut.OrdinalPath)-1]

hardware := inventory.Hardware{
ID: hardwareBuildOut.ID,
Parent: hardwareBuildOut.ParentID,
Type: hardwareBuildOut.DeviceType.HardwareType,
Vendor: hardwareBuildOut.DeviceType.Manufacturer,
Model: hardwareBuildOut.DeviceType.Model,
ID: hardwareBuildOut.ID,
Parent: hardwareBuildOut.ParentID,
Type: hardwareBuildOut.DeviceType.HardwareType,
DeviceTypeSlug: hardwareBuildOut.DeviceType.Slug,
Vendor: hardwareBuildOut.DeviceType.Manufacturer,
Model: hardwareBuildOut.DeviceType.Model,

LocationOrdinal: &locationOrdinal,

Expand Down
2 changes: 1 addition & 1 deletion internal/domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func New(opts *NewOpts) (*Domain, error) {
// Determine which external inventory provider to use
switch inventoryProvider {
case inventory.CSMProvider:
domain.externalInventoryProvider, err = csm.New(&opts.CsmOptions)
domain.externalInventoryProvider, err = csm.New(&opts.CsmOptions, domain.hardwareTypeLibrary)
if err != nil {
return nil, errors.Join(
fmt.Errorf("failed to initialize CSM external inventory provider"),
Expand Down
9 changes: 9 additions & 0 deletions internal/domain/import.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package domain

import (
"context"
)

func (d *Domain) Import(ctx context.Context) error {
return d.externalInventoryProvider.Import(ctx, d.datastore)
}
6 changes: 6 additions & 0 deletions internal/inventory/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ type Datastore interface {
GetSystem(hardware Hardware) (Hardware, error) // Not yet implemented until multiple systems are supported

// TODO for search properties

// Clone creates a in-memory version of the datastore to perform location operations
Clone() (Datastore, error)

// Merge the contents of the remote datastore (most likely a in-memory one with changes)
Merge(Datastore) error
}
Loading