Skip to content

Commit

Permalink
Drop support for VCD 9.5 (bump API version to 32.0) (#330)
Browse files Browse the repository at this point in the history
* Drop support for VCD 9.5 (bump default API version to 32.0)
* CheckOpenApiEndpointCompatibility() returns system default API version when it is higher than minimum required
* Remove code for handling API versions pre 32.0
* Deprecated vdc.UploadMediaImage because it does not work anymore with API v32.0
  • Loading branch information
Didainius authored Aug 25, 2020
1 parent bc933b6 commit 8886b5b
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 220 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
`OpenApiPostItem`, `OpenApiGetItem`, `OpenApiPutItem`, `OpenApiPutItemSync`, `OpenApiPutItemAsync`,
`OpenApiDeleteItem`, `OpenApiIsSupported`, `OpenApiBuildEndpoints`
[#325](https://github.com/vmware/go-vcloud-director/pull/325)
* Add OVF file upload support in UploadOvf function besides OVA. The input should be OVF file path inside the OVF folder. It will check if input file is XML content type, if yes, skip some OVA steps (like unpacking), if not, keep the old logic. [#323](https://github.com/vmware/go-vcloud-director/pull/323)
* Dropped support for VMware Cloud Director 9.5 [#330](https://github.com/vmware/go-vcloud-director/pull/330)
* Deprecated Vdc.UploadMediaImage because it no longer works with API V32.0+ [#330](https://github.com/vmware/go-vcloud-director/pull/330)

## 2.8.0 (June 30, 2020)

Expand Down Expand Up @@ -38,7 +41,6 @@
* Added methods `vapp.UpdateNetworkFirewallRules`, `vapp.UpdateNetworkFirewallRulesAsync`, `vapp.GetVappNetworkById`, `vapp.GetVappNetworkByName` and `vapp.GetVappNetworkByNameOrId` [#308](https://github.com/vmware/go-vcloud-director/pull/308)
* Added methods `vapp.UpdateNetworkNatRulesAsync`, `vapp.UpdateNetworkNatRulesAsync`, `vapp.RemoveAllNetworkFirewallRules` and `vapp.RemoveAllNetworkNatRules` [#316](https://github.com/vmware/go-vcloud-director/pull/316)
* Added methods `vapp.UpdateNetworkStaticRouting`, `vapp.UpdateNetworkStaticRoutingAsync` and `vapp.RemoveAllNetworkStaticRoutes` [#318](https://github.com/vmware/go-vcloud-director/pull/318)
* Add OVF file upload support in UploadOvf function besides OVA. The input should be OVF file path inside the OVF folder. It will check if input file is XML content type, if yes, skip some OVA steps (like unpacking), if not, keep the old logic. [#323](https://github.com/vmware/go-vcloud-director/pull/323)

## 2.7.0 (April 10,2020)

Expand Down
5 changes: 2 additions & 3 deletions govcd/adminorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,8 @@ func (adminOrg *AdminOrg) GetVDCByHref(vdcHref string) (*Vdc, error) {

vdc := NewVdc(adminOrg.client)

_, err := adminOrg.client.ExecuteRequestWithApiVersion(vdcHREF, http.MethodGet,
"", "error getting vdc: %s", nil, vdc.Vdc,
adminOrg.client.GetSpecificApiVersionOnCondition(">= 32.0", "32.0"))
_, err := adminOrg.client.ExecuteRequest(vdcHREF, http.MethodGet,
"", "error getting vdc: %s", nil, vdc.Vdc)

if err != nil {
return nil, err
Expand Down
94 changes: 8 additions & 86 deletions govcd/adminvdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,6 @@ type vdcVersionedFuncs struct {
UpdateVdcAsync func(adminVdc *AdminVdc) (Task, error)
}

// VDC function mapping for API version 31.0 (from vCD 9.5)
var vdcVersionedFuncsV95 = vdcVersionedFuncs{
SupportedVersion: "31.0",
CreateVdc: createVdc,
CreateVdcAsync: createVdcAsync,
UpdateVdc: updateVdc,
UpdateVdcAsync: updateVdcAsync,
}

// VDC function mapping for API version 32.0 (from vCD 9.7)
var vdcVersionedFuncsV97 = vdcVersionedFuncs{
SupportedVersion: "32.0",
Expand All @@ -54,7 +45,6 @@ var vdcVersionedFuncsV97 = vdcVersionedFuncs{

// vdcVersionedFuncsByVcdVersion is a map of VDC functions by vCD version
var vdcVersionedFuncsByVcdVersion = map[string]vdcVersionedFuncs{
"vdc9.5": vdcVersionedFuncsV95,
"vdc9.7": vdcVersionedFuncsV97,

// If we add a new function to this list, we also need to update the "default" entry
Expand Down Expand Up @@ -91,16 +81,9 @@ func (adminOrg *AdminOrg) GetAdminVdcByName(vdcname string) (AdminVdc, error) {

// GetAdminVDCByHref retrieves a VDC using a direct call with the HREF
func (adminOrg *AdminOrg) GetAdminVDCByHref(vdcHref string) (*AdminVdc, error) {

adminVdc := NewAdminVdc(adminOrg.client)

// We are executing below request with a specific API version in the header, because we want to retrieve the most
// available fields in AdminVdc which vCD provides, but also which our code understands. As we can't blindly use
// the latest version, we're limiting the highest used version to the one we support with
// the GetSpecificApiVersionOnCondition(...) function. Specifically, the API version 32 returns
// two additional fields: IncludeMemoryOverhead and IsElastic for Flex allocation
_, err := adminOrg.client.ExecuteRequestWithApiVersion(vdcHref, http.MethodGet,
"", "error getting vdc: %s", nil, adminVdc.AdminVdc, adminVdc.client.GetSpecificApiVersionOnCondition(">= 32.0", "32.0"))
_, err := adminOrg.client.ExecuteRequest(vdcHref, http.MethodGet,
"", "error getting vdc: %s", nil, adminVdc.AdminVdc)

if err != nil {
return nil, err
Expand Down Expand Up @@ -219,13 +202,8 @@ func (adminVdc *AdminVdc) Refresh() error {
// elements in slices.
unmarshalledAdminVdc := &types.AdminVdc{}

// We are executing below request with a specific API version in the header, because we want to retrieve the most
// available fields in AdminVdc which vCD provides, but also which our code understands. As we can't blindly use
// the latest version, we're limiting the highest used version to the one we support with
// the GetSpecificApiVersionOnCondition(...) function. Specifically, the API version 32 returns
// two additional fields: IncludeMemoryOverhead and IsElastic for Flex allocation
_, err := adminVdc.client.ExecuteRequestWithApiVersion(adminVdc.AdminVdc.HREF, http.MethodGet,
"", "error refreshing VDC: %s", nil, unmarshalledAdminVdc, adminVdc.client.GetSpecificApiVersionOnCondition(">= 32.0", "32.0"))
_, err := adminVdc.client.ExecuteRequest(adminVdc.AdminVdc.HREF, http.MethodGet,
"", "error refreshing VDC: %s", nil, unmarshalledAdminVdc)
if err != nil {
return err
}
Expand Down Expand Up @@ -311,63 +289,15 @@ func (adminOrg *AdminOrg) CreateOrgVdcAsync(vdcConfiguration *types.VdcConfigura
return vdcFunctions.CreateVdcAsync(adminOrg, vdcConfiguration)
}

// createVdc creates a VDC with the given params under the given organization.
// Returns a Vdc pointer and an error
func createVdc(adminOrg *AdminOrg, vdcConfiguration *types.VdcConfiguration) (*Vdc, error) {
util.Logger.Printf("[TRACE] createVdc called %#v", *vdcConfiguration)
err := adminOrg.CreateVdcWait(vdcConfiguration)
if err != nil {
return nil, err
}

vdc, err := adminOrg.GetVDCByName(vdcConfiguration.Name, true)
if err != nil {
return nil, err
}
return vdc, nil
}

// updateVdcAsync updates a VDC with the given params. Returns a Task and error
func updateVdcAsync(adminVdc *AdminVdc) (Task, error) {
util.Logger.Printf("[TRACE] updateVdcAsync called %#v", *adminVdc)
adminVdc.AdminVdc.Xmlns = types.XMLNamespaceVCloud

// Return the task
return adminVdc.client.ExecuteTaskRequest(adminVdc.AdminVdc.HREF, http.MethodPut,
types.MimeAdminVDC, "error updating VDC: %s", adminVdc.AdminVdc)
}

// updateVdc updates a VDC with the given params. Returns an AdminVdc.
func updateVdc(adminVdc *AdminVdc) (*AdminVdc, error) {
util.Logger.Printf("[TRACE] updateVdc called %#v", *adminVdc)
task, err := updateVdcAsync(adminVdc)
if err != nil {
return nil, err
}

err = task.WaitTaskCompletion()
if err != nil {
return nil, err
}

err = adminVdc.Refresh()
if err != nil {
return nil, err
}

return adminVdc, nil
}

// updateVdcAsyncV97 updates a VDC with the given params. Supports Flex type allocation.
// Needs vCD 9.7+ to work. Returns a Task and an error.
func updateVdcAsyncV97(adminVdc *AdminVdc) (Task, error) {
util.Logger.Printf("[TRACE] updateVdcAsyncV97 called %#v", *adminVdc)
adminVdc.AdminVdc.Xmlns = types.XMLNamespaceVCloud

// Return the task
return adminVdc.client.ExecuteTaskRequestWithApiVersion(adminVdc.AdminVdc.HREF, http.MethodPut,
types.MimeAdminVDC, "error updating VDC: %s", adminVdc.AdminVdc,
adminVdc.client.GetSpecificApiVersionOnCondition(">= 32.0", "32.0"))
return adminVdc.client.ExecuteTaskRequest(adminVdc.AdminVdc.HREF, http.MethodPut,
types.MimeAdminVDC, "error updating VDC: %s", adminVdc.AdminVdc)
}

// updateVdcV97 updates a VDC with the given params
Expand All @@ -390,13 +320,6 @@ func updateVdcV97(adminVdc *AdminVdc) (*AdminVdc, error) {
return adminVdc, nil
}

// createVdcAsync creates a VDC with the given params under the given organization.
// Returns a Task and an error
func createVdcAsync(adminOrg *AdminOrg, vdcConfiguration *types.VdcConfiguration) (Task, error) {
util.Logger.Printf("[TRACE] createVdcAsync called %#v", *vdcConfiguration)
return adminOrg.CreateVdc(vdcConfiguration)
}

// createVdcV97 creates a VDC with the given params under the given organization
// and waits for the asynchronous task to complete. Supports Flex type allocation.
// Needs vCD 9.7+ to work. Returns a Vdc pointer and error.
Expand Down Expand Up @@ -437,10 +360,9 @@ func createVdcAsyncV97(adminOrg *AdminOrg, vdcConfiguration *types.VdcConfigurat

adminVdc := NewAdminVdc(adminOrg.client)

_, err = adminOrg.client.ExecuteRequestWithApiVersion(vdcCreateHREF.String(), http.MethodPost,
_, err = adminOrg.client.ExecuteRequest(vdcCreateHREF.String(), http.MethodPost,
"application/vnd.vmware.admin.createVdcParams+xml", "error creating VDC: %s",
vdcConfiguration, adminVdc.AdminVdc,
adminOrg.client.GetSpecificApiVersionOnCondition(">= 32.0", "32.0"))
vdcConfiguration, adminVdc.AdminVdc)
if err != nil {
return Task{}, err
}
Expand Down
10 changes: 0 additions & 10 deletions govcd/adminvdc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ func (vcd *TestVCD) Test_CreateOrgVdcWithFlex(check *C) {
check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName()))
}

// Flex vCD supported from 9.7 vCD
if vcd.client.Client.APIVCDMaxVersionIs("< 32.0") {
check.Skip(fmt.Sprintf("Test %s requires vCD 9.7 (API version 32) or higher", check.TestName()))
}

if vcd.config.VCD.ProviderVdc.Name == "" {
check.Skip("No Provider VDC name given for VDC tests")
}
Expand Down Expand Up @@ -162,11 +157,6 @@ func (vcd *TestVCD) Test_UpdateVdcFlex(check *C) {
check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName()))
}

// Flex vCD supported from 9.7 vCD
if vcd.client.Client.APIVCDMaxVersionIs("< 32.0") {
check.Skip(fmt.Sprintf("Test %s requires vCD 9.7 (API version 32) or higher", check.TestName()))
}

adminOrg, vdcConfiguration, err := setupVdc(vcd, check, "Flex")
check.Assert(err, IsNil)

Expand Down
2 changes: 1 addition & 1 deletion govcd/api_vcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func NewVCDClient(vcdEndpoint url.URL, insecure bool, options ...VCDClientOption
// Setting defaults
vcdClient := &VCDClient{
Client: Client{
APIVersion: "31.0", // supported by 9.5, 9.7, 10.0, 10.1
APIVersion: "32.0", // supported by 9.7+
VCDHREF: vcdEndpoint,
Http: http.Client{
Transport: &http.Transport{
Expand Down
4 changes: 0 additions & 4 deletions govcd/catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,6 @@ func (vcd *TestVCD) Test_CatalogUploadMediaImage_error_withSameItem(check *C) {
check.Assert(err, IsNil)

AddToCleanupList(itemName, "mediaCatalogImage", vcd.org.Org.Name+"|"+vcd.config.VCD.Catalog.Name, "Test_CatalogUploadMediaImage_error_withSameItem")

_, err2 := vcd.vdc.UploadMediaImage(itemName, "upload from test", vcd.config.Media.MediaPath, 1024)
check.Assert(err2, NotNil)
check.Assert(err2.Error(), Matches, ".*already exists. Upload with different name.*")
}

// Tests System function Delete by creating media item and
Expand Down
4 changes: 3 additions & 1 deletion govcd/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ func NewMediaRecord(cli *Client) *MediaRecord {
// Uploads an ISO file as media. This method only uploads bits to vCD spool area.
// Returns errors if any occur during upload from vCD or upload process. On upload fail client may need to
// remove vCD catalog item which waits for files to be uploaded.
// Recommend to use catalog.UploadMediaImage which let's expect in which catalog file will be placed
//
// Deprecated: This method is broken in API V32.0+. Please use catalog.UploadMediaImage because VCD does not support
// uploading directly to VDC anymore.
func (vdc *Vdc) UploadMediaImage(mediaName, mediaDescription, filePath string, uploadPieceSize int64) (UploadTask, error) {
util.Logger.Printf("[TRACE] UploadImage: %s, image name: %v \n", mediaName, mediaDescription)

Expand Down
101 changes: 0 additions & 101 deletions govcd/media_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,111 +8,10 @@ package govcd

import (
"fmt"
"io/ioutil"
"os"

. "gopkg.in/check.v1"
)

// Tests System function UploadMediaImage by checking if provided standard iso file uploaded.
func (vcd *TestVCD) Test_UploadMediaImage(check *C) {
fmt.Printf("Running: %s\n", check.TestName())

skipWhenMediaPathMissing(vcd, check)

uploadTask, err := vcd.vdc.UploadMediaImage(TestUploadMedia, "upload from test", vcd.config.Media.MediaPath, 1024)
check.Assert(err, IsNil)
err = uploadTask.WaitTaskCompletion()
check.Assert(err, IsNil)

AddToCleanupList(TestUploadMedia, "mediaImage", vcd.org.Org.Name+"|"+vcd.vdc.Vdc.Name, "Test_UploadMediaImage")

verifyMediaImageUploaded(vcd.vdc, check, TestUploadMedia)
}

func verifyMediaImageUploaded(vdc *Vdc, check *C, itemName string) {
results, err := queryMediaWithFilter(vdc, "name=="+itemName)

check.Assert(err, Equals, nil)
check.Assert(len(results), Equals, 1)
}

// Tests System function UploadMediaImage by checking UploadTask.GetUploadProgress returns values of progress.
func (vcd *TestVCD) Test_UploadMediaImage_progress_works(check *C) {
fmt.Printf("Running: %s\n", check.TestName())

skipWhenMediaPathMissing(vcd, check)
itemName := TestUploadMedia + "2"

uploadTask, err := vcd.vdc.UploadMediaImage(itemName, "upload from test", vcd.config.Media.MediaPath, 1024)
check.Assert(err, IsNil)
for {
if value := uploadTask.GetUploadProgress(); value == "100.00" {
break
} else {
check.Assert(value, Not(Equals), "")
}
}
err = uploadTask.WaitTaskCompletion()
check.Assert(err, IsNil)

AddToCleanupList(itemName, "mediaImage", vcd.org.Org.Name+"|"+vcd.vdc.Vdc.Name, "Test_UploadMediaImage")

verifyMediaImageUploaded(vcd.vdc, check, itemName)
}

// Tests System function UploadMediaImage by checking UploadTask.ShowUploadProgress writes values of progress to stdin.
func (vcd *TestVCD) Test_UploadMediaImage_ShowUploadProgress_works(check *C) {
fmt.Printf("Running: %s\n", check.TestName())

skipWhenMediaPathMissing(vcd, check)
itemName := TestUploadMedia + "3"

uploadTask, err := vcd.vdc.UploadMediaImage(itemName, "upload from test", vcd.config.Media.MediaPath, 1024)
check.Assert(err, IsNil)

//take control of stdout
oldStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w

err = uploadTask.ShowUploadProgress()
check.Assert(err, IsNil)

w.Close()
//read stdin
result, _ := ioutil.ReadAll(r)
os.Stdout = oldStdout

err = uploadTask.WaitTaskCompletion()
check.Assert(err, IsNil)

AddToCleanupList(itemName, "mediaImage", vcd.org.Org.Name+"|"+vcd.vdc.Vdc.Name, "Test_UploadMediaImage")

check.Assert(string(result), Matches, ".*Upload progress 100.00%")
verifyMediaImageUploaded(vcd.vdc, check, itemName)
}

// Tests System function UploadMediaImage by creating media item and expecting specific error
// then trying to create same media item. As vCD returns cryptic error for such case.
func (vcd *TestVCD) Test_UploadMediaImage_error_withSameItem(check *C) {
fmt.Printf("Running: %s\n", check.TestName())

skipWhenMediaPathMissing(vcd, check)
itemName := TestUploadMedia + "4"

uploadTask, err := vcd.vdc.UploadMediaImage(itemName, "upload from test", vcd.config.Media.MediaPath, 1024)
check.Assert(err, IsNil)
err = uploadTask.WaitTaskCompletion()
check.Assert(err, IsNil)

AddToCleanupList(itemName, "mediaImage", vcd.org.Org.Name+"|"+vcd.vdc.Vdc.Name, "Test_UploadMediaImage")

_, err2 := vcd.vdc.UploadMediaImage(itemName, "upload from test", vcd.config.Media.MediaPath, 1024)
check.Assert(err2, NotNil)
check.Assert(err2.Error(), Matches, ".*already exists. Upload with different name.*")
}

// Tests System function Delete by creating media item and
// deleting it after.
func (vcd *TestVCD) Test_DeleteMedia(check *C) {
Expand Down
7 changes: 7 additions & 0 deletions govcd/openapi_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package govcd

import (
"fmt"

"github.com/vmware/go-vcloud-director/v2/types/v56"
)

Expand All @@ -17,6 +18,7 @@ var endpointMinApiVersions = map[string]string{
// checkOpenApiEndpointCompatibility checks if VCD version (to which the client is connected) is sufficient to work with
// specified OpenAPI endpoint and returns either error, either Api version to use for calling that endpoint. This Api
// version can then be supplied to low level OpenAPI client functions.
// If the system default API version is higher than endpoint introduction version - default system one is used.
func (client *Client) checkOpenApiEndpointCompatibility(endpoint string) (string, error) {
minimumApiVersion, ok := endpointMinApiVersions[endpoint]
if !ok {
Expand All @@ -32,5 +34,10 @@ func (client *Client) checkOpenApiEndpointCompatibility(endpoint string) (string
endpoint, minimumApiVersion, maxSupportedVersion)
}

// If default API version is higher than minimum required API version for endpoint - use the system default one.
if client.APIClientVersionIs("> " + minimumApiVersion) {
return client.APIVersion, nil
}

return minimumApiVersion, nil
}
3 changes: 2 additions & 1 deletion govcd/openapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ func (vcd *TestVCD) Test_OpenApiInlineStructAudiTrail(check *C) {
// 8. Update role once more using "Sync" version of PUT function
// 9. Delete role once again
func (vcd *TestVCD) Test_OpenApiInlineStructCRUDRoles(check *C) {
minimumRequiredApiVersion := "31.0"
endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointRoles
minimumRequiredApiVersion, err := vcd.client.Client.checkOpenApiEndpointCompatibility(endpoint)
check.Assert(err, IsNil)
skipOpenApiEndpointTest(vcd, check, endpoint, minimumRequiredApiVersion)

// Step 1 - Get all roles
Expand Down
4 changes: 2 additions & 2 deletions govcd/vapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -1255,8 +1255,8 @@ func (client *Client) GetVMByHref(vmHref string) (*VM, error) {

newVm := NewVM(client)

_, err := client.ExecuteRequestWithApiVersion(vmHref, http.MethodGet,
"", "error retrieving vm: %s", nil, newVm.VM, client.GetSpecificApiVersionOnCondition(">= 32.0", "32.0"))
_, err := client.ExecuteRequest(vmHref, http.MethodGet,
"", "error retrieving vm: %s", nil, newVm.VM)

if err != nil {

Expand Down
Loading

0 comments on commit 8886b5b

Please sign in to comment.