Skip to content

Commit

Permalink
Merge pull request #531 from vmware/fix_vmc_version
Browse files Browse the repository at this point in the history
Initialize VMC NSX version to 3.0.0
  • Loading branch information
annakhm authored Dec 18, 2020
2 parents 710f5f6 + cfefb06 commit cf37acf
Show file tree
Hide file tree
Showing 10 changed files with 698 additions and 0 deletions.
4 changes: 4 additions & 0 deletions nsxt/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,10 @@ func configurePolicyConnectorData(d *schema.ResourceData, clients *nsxtClients)
clients.PolicyEnforcementPoint = policyEnforcementPoint
clients.PolicyGlobalManager = policyGlobalManager

if len(vmcAccessToken) > 0 {
// Special treatment for VMC since MP API is not available there
initNSXVersionVMC(*clients)
}
return nil
}

Expand Down
30 changes: 30 additions & 0 deletions nsxt/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
api "github.com/vmware/go-vmware-nsxt"
"github.com/vmware/go-vmware-nsxt/common"
"github.com/vmware/go-vmware-nsxt/manager"

"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/search"
)

var adminStateValues = []string{"UP", "DOWN"}
Expand Down Expand Up @@ -530,6 +532,34 @@ func initNSXVersion(nsxClient *api.APIClient) error {
return err
}

func initNSXVersionVMC(clients interface{}) {
// TODO: find a ireliable way to retrieve NSX version on VMC
// For now, we need to determine whether the deployment is 3.0.0 and up, or below
// For this purpose, we fire indicator search API (introduced in 3.0.0)
nsxVersion = "3.0.0"

connector := getPolicyConnector(clients)
client := search.NewDefaultQueryClient(connector)
var cursor *string
query := "resource_type:dummy"
_, err := client.List(query, cursor, nil, nil, nil, nil)
if err == nil {
// we are 3.0.0 and above
log.Printf("[INFO] Assuming NSX version >= 3.0.0 in VMC environment")
return
}

if isNotFoundError(err) {
// search API not supported
log.Printf("[INFO] Assuming NSX version < 3.0.0 in VMC environment")
nsxVersion = "2.5.0"
return
}

// Connectivity error - alert the user
log.Printf("[ERROR] Failed to determine NSX version in VMC environment: %s", err)
}

func nsxVersionLower(ver string) bool {

requestedVersion, err1 := version.NewVersion(ver)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cf37acf

Please sign in to comment.