From 5687d99944b12046650ac4e00ade19093fb883c7 Mon Sep 17 00:00:00 2001 From: Ondra Machacek Date: Thu, 28 Nov 2024 15:40:51 +0100 Subject: [PATCH] User forklift to get vCenter ID Signed-off-by: Ondra Machacek --- go.mod | 10 +++---- go.sum | 11 ++++---- internal/agent/collector.go | 54 +++++++------------------------------ 3 files changed, 18 insertions(+), 57 deletions(-) diff --git a/go.mod b/go.mod index 225749b..bf3dcf9 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,6 @@ require ( github.com/lthibault/jitterbug v2.0.0+incompatible github.com/oapi-codegen/nethttp-middleware v1.0.2 github.com/oapi-codegen/runtime v1.1.1 - github.com/onsi/ginkgo v1.16.5 github.com/onsi/ginkgo/v2 v2.15.0 github.com/onsi/gomega v1.32.0 github.com/openshift/assisted-image-service v0.0.0-20240827125623-ad5c4b36a817 @@ -47,12 +46,11 @@ require ( github.com/coreos/go-systemd/v22 v22.5.0 // indirect github.com/coreos/ignition/v2 v2.18.0 // indirect github.com/coreos/vcontext v0.0.0-20230201181013-d72178a18687 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/diskfs/go-diskfs v1.4.0 // indirect github.com/elliotwutingfeng/asciiset v0.0.0-20230602022725-51bbb787efab // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/evanphx/json-patch/v5 v5.6.0 // indirect - github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/gin-contrib/cors v1.3.1 // indirect github.com/gin-contrib/sse v0.1.0 // indirect @@ -97,7 +95,6 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect - github.com/nxadm/tail v1.4.11 // indirect github.com/openshift/api v0.0.0-20230613151523-ba04973d3ed1 // indirect github.com/openshift/custom-resource-status v1.1.2 // indirect github.com/pborman/uuid v1.2.1 // indirect @@ -106,7 +103,7 @@ require ( github.com/pierrec/lz4/v4 v4.1.17 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pkg/xattr v0.4.9 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/stretchr/testify v1.9.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect @@ -129,7 +126,6 @@ require ( google.golang.org/protobuf v1.33.0 // indirect gopkg.in/djherbis/times.v1 v1.3.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect - gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/apiextensions-apiserver v0.28.3 // indirect @@ -144,6 +140,6 @@ require ( ) replace ( - github.com/konveyor/forklift-controller => github.com/kubev2v/forklift v0.0.0-20240729073638-8978e272380e + github.com/konveyor/forklift-controller => github.com/kubev2v/forklift v0.0.0-20241128114951-4c1195e2a8f0 github.com/vmware/govmomi => github.com/vmware/govmomi v0.34.1 ) diff --git a/go.sum b/go.sum index 1932c66..d4bfcb6 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,9 @@ github.com/coreos/vcontext v0.0.0-20230201181013-d72178a18687/go.mod h1:Salmysdw github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= 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/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/diskfs/go-diskfs v1.4.0 h1:MAybY6TPD+fmhY+a2qFhmdvMeIKvCqlgh4QIc1uCmBs= github.com/diskfs/go-diskfs v1.4.0/go.mod h1:G8cyy+ngM+3yKlqjweMmtqvE+TxsnIo1xumbJX1AeLg= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= @@ -231,8 +232,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/kubev2v/forklift v0.0.0-20240729073638-8978e272380e h1:5vkfPODgIBbBB269Gg/rCOzpTMxetCheK/H/EDfbcHc= -github.com/kubev2v/forklift v0.0.0-20240729073638-8978e272380e/go.mod h1:1jmlC7LOW4l5xu6JEw6Vo0c/AyqbznOFQocbme7F0Tg= +github.com/kubev2v/forklift v0.0.0-20241128114951-4c1195e2a8f0 h1:08QJ05m30zyQFU2bBNmQHZ+2robnTm6V2FEjGJYm0FQ= +github.com/kubev2v/forklift v0.0.0-20241128114951-4c1195e2a8f0/go.mod h1:fHaGLhv09dWXKv0/0GNl3rgLe/KH5Y6IyG6eGLYaA6k= github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= @@ -310,8 +311,9 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/xattr v0.4.9 h1:5883YPCtkSd8LFbs13nXplj9g9tlrwoJRjgpgMu1/fE= github.com/pkg/xattr v0.4.9/go.mod h1:di8WF84zAKk8jzR1UBTEWh9AUlIZZ7M/JNt8e9B6ktU= -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/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU= github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= @@ -463,7 +465,6 @@ golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= diff --git a/internal/agent/collector.go b/internal/agent/collector.go index 0d2227a..75a182a 100644 --- a/internal/agent/collector.go +++ b/internal/agent/collector.go @@ -11,7 +11,6 @@ import ( "os" "path/filepath" "slices" - "strings" "sync" "time" @@ -20,15 +19,10 @@ import ( "github.com/konveyor/forklift-controller/pkg/controller/provider/model" vspheremodel "github.com/konveyor/forklift-controller/pkg/controller/provider/model/vsphere" web "github.com/konveyor/forklift-controller/pkg/controller/provider/web/vsphere" - liberr "github.com/konveyor/forklift-controller/pkg/lib/error" libmodel "github.com/konveyor/forklift-controller/pkg/lib/inventory/model" apiplanner "github.com/kubev2v/migration-planner/api/v1alpha1" "github.com/kubev2v/migration-planner/internal/util" "github.com/kubev2v/migration-planner/pkg/log" - "github.com/vmware/govmomi" - "github.com/vmware/govmomi/session" - "github.com/vmware/govmomi/vim25" - "github.com/vmware/govmomi/vim25/soap" core "k8s.io/api/core/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -94,12 +88,6 @@ func (c *Collector) run() { } defer resp.Body.Close() - vCenterID, err := getVCenterID(context.TODO(), &creds) - if err != nil { - c.log.Errorf("failed to get vCenterID: %s", err) - return - } - c.log.Infof("Create DB") db, err := createDB(provider) if err != nil { @@ -140,8 +128,16 @@ func (c *Collector) run() { return } + c.log.Infof("Get About") + about := &vspheremodel.About{} + err = collector.DB().Get(about) + if err != nil { + c.log.Errorf("Error list database about table: %s", err) + return + } + c.log.Infof("Create inventory") - inv := createBasicInventoryObj(vCenterID, vms, collector, hosts, clusters) + inv := createBasicInventoryObj(about.InstanceUuid, vms, collector, hosts, clusters) c.log.Infof("Run the validation of VMs") vms, err = validation(vms, opaServer) @@ -576,38 +572,6 @@ func waitForFile(filename string) { } } -func getVCenterID(ctx context.Context, credentials *Credentials) (string, error) { - u, err := parseUrl(credentials) - if err != nil { - return "", liberr.Wrap(err) - } - - ctx, cancel := context.WithTimeout(ctx, 10*time.Second) - defer cancel() - vimClient, err := vim25.NewClient(ctx, soap.NewClient(u, true)) - if err != nil { - return "", liberr.Wrap(err) - } - client := &govmomi.Client{ - SessionManager: session.NewManager(vimClient), - Client: vimClient, - } - err = client.Login(ctx, u.User) - if err != nil { - err = liberr.Wrap(err) - if strings.Contains(err.Error(), "incorrect") && strings.Contains(err.Error(), "password") { - return "", err - } - return "", err - } - - id := client.ServiceContent.About.InstanceUuid - _ = client.Logout(ctx) - client.CloseIdleConnections() - - return id, nil -} - type NotMigratableReasons []NotMigratableReason type NotMigratableReason struct {