Skip to content

Commit

Permalink
fix: make cns.Client independent of vim25.Client
Browse files Browse the repository at this point in the history
  • Loading branch information
dougm committed Apr 12, 2024
1 parent f421c8c commit 7d9a954
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
22 changes: 19 additions & 3 deletions cns/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,25 @@ type Client struct {
// NewClient creates a new CNS client
func NewClient(ctx context.Context, c *vim25.Client) (*Client, error) {
sc := c.Client.NewServiceClient(Path, Namespace)
sc.Namespace = c.Namespace
sc.Version = c.Version
return &Client{sc, sc, c}, nil

// Use current vCenter vsan version by default
err := sc.UseServiceVersion(Namespace)
if err != nil {
return nil, err
}

// PropertyCollector related methods (task.Wait) need to send requests to vim25.Path (/sdk).
// This vim25.Client shares the same http.Transport and Namespace/Version, but requests to '/sdk'
rt := sc.NewServiceClient(vim25.Path, Namespace)
rt.Version = sc.Version

vc := &vim25.Client{
ServiceContent: c.ServiceContent,
Client: rt,
RoundTripper: rt,
}

return &Client{sc, sc, vc}, nil
}

// RoundTrip dispatches to the RoundTripper field.
Expand Down
2 changes: 0 additions & 2 deletions cns/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,6 @@ func TestClient(t *testing.T) {
if err != nil {
t.Fatal(err)
}
// UseServiceVersion sets soap.Client.Version to the current version of the service endpoint via /sdk/vsanServiceVersions.xml
remoteVcClient.UseServiceVersion("vsan")
remoteCnsClient, err := NewClient(ctx, remoteVcClient.Client)
if err != nil {
t.Fatal(err)
Expand Down
1 change: 0 additions & 1 deletion govc/flags/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ func (flag *ClientFlag) CnsClient() (*cns.Client, error) {
if err != nil {
return nil, err
}
_ = vc.UseServiceVersion("vsan")

c, err := cns.NewClient(context.Background(), vc)
if err != nil {
Expand Down

0 comments on commit 7d9a954

Please sign in to comment.