Skip to content

Commit

Permalink
Merge pull request #3644 from dougm/issue-3643
Browse files Browse the repository at this point in the history
govc: remove minimum API version check
  • Loading branch information
dougm authored Dec 6, 2024
2 parents 8b2a311 + 228b445 commit b0bf309
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 90 deletions.
57 changes: 0 additions & 57 deletions cli/flags/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ const (
envVimVersion = "GOVC_VIM_VERSION"
envTLSCaCerts = "GOVC_TLS_CA_CERTS"
envTLSKnownHosts = "GOVC_TLS_KNOWN_HOSTS"

defaultMinVimVersion = "5.5"
)

const cDescr = "ESX or vCenter URL"
Expand All @@ -69,7 +67,6 @@ type ClientFlag struct {
cert string
key string
persist bool
minAPIVersion string
vimNamespace string
vimVersion string
tlsCaCerts string
Expand Down Expand Up @@ -167,15 +164,6 @@ func (flag *ClientFlag) Register(ctx context.Context, f *flag.FlagSet) {
f.BoolVar(&flag.persist, "persist-session", persist, usage)
}

{
env := os.Getenv(envMinAPIVersion)
if env == "" {
env = defaultMinVimVersion
}

flag.minAPIVersion = env
}

{
value := os.Getenv(envVimNamespace)
if value == "" {
Expand Down Expand Up @@ -310,45 +298,6 @@ func (flag *ClientFlag) SetRootCAs(c *soap.Client) error {
return nil
}

func isDevelopmentVersion(apiVersion string) bool {
// Skip version check for development builds which can be in the form of "r4A70F" or "6.5.x"
return strings.Count(apiVersion, ".") == 0 || strings.HasSuffix(apiVersion, ".x")
}

// apiVersionValid returns whether or not the API version supported by the
// server the client is connected to is not recent enough.
func apiVersionValid(c *vim25.Client, minVersionString string) error {
if minVersionString == "-" {
// Disable version check
return nil
}

apiVersion := c.ServiceContent.About.ApiVersion
if isDevelopmentVersion(apiVersion) {
return nil
}

realVersion, err := ParseVersion(apiVersion)
if err != nil {
return fmt.Errorf("error parsing API version %q: %s", apiVersion, err)
}

minVersion, err := ParseVersion(minVersionString)
if err != nil {
return fmt.Errorf("error parsing %s=%q: %s", envMinAPIVersion, minVersionString, err)
}

if !minVersion.Lte(realVersion) {
err = fmt.Errorf("require API version %q, connected to API version %q (set %s to override)",
minVersionString,
c.ServiceContent.About.ApiVersion,
envMinAPIVersion)
return err
}

return nil
}

func (flag *ClientFlag) RoundTripper(c *soap.Client) soap.RoundTripper {
// Retry twice when a temporary I/O error occurs.
// This means a maximum of 3 attempts.
Expand All @@ -375,12 +324,6 @@ func (flag *ClientFlag) Client() (*vim25.Client, error) {
return nil, err
}

// Check that the endpoint has the right API version
err = apiVersionValid(c, flag.minAPIVersion)
if err != nil {
return nil, err
}

if flag.vimVersion == "" || flag.vimVersion == "-" {
err = c.UseServiceVersion()
if err != nil {
Expand Down
14 changes: 0 additions & 14 deletions cli/flags/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,3 @@ func TestLte(t *testing.T) {
t.Errorf("Expected not 5.6 <= 5.5")
}
}

func TestDevelopmentVersion(t *testing.T) {
if !isDevelopmentVersion("6.5.x") {
t.Error("expected true")
}

if !isDevelopmentVersion("r4A70F") {
t.Error("expected true")
}

if isDevelopmentVersion("6.5") {
t.Error("expected false")
}
}
19 changes: 0 additions & 19 deletions govc/test/cli.bats
Original file line number Diff line number Diff line change
Expand Up @@ -122,25 +122,6 @@ load test_helper
assert_success
}

@test "API version check" {
vcsim_env -esx

run env GOVC_MIN_API_VERSION=24.4 govc about
assert grep -q "^govc: require API version \"24.4\"," <<<"${output}"

run env GOVC_MIN_API_VERSION=no.no govc about
assert_failure

run env GOVC_MIN_API_VERSION=- govc about
assert_success

run env GOVC_MIN_API_VERSION=5.0 govc about
assert_success

run govc about -vim-namespace urn:vim25 -vim-version 6.0
assert_success
}

@test "govc env" {
output="$(govc env -x -u 'user:pass@enoent:99999?key=val#anchor')"
assert grep -q GOVC_URL=enoent:99999 <<<${output}
Expand Down

0 comments on commit b0bf309

Please sign in to comment.