From 4a8ebe752c0772b5cd4c3f0ebc07dc49860d272e Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Wed, 2 Feb 2022 16:46:54 +0100 Subject: [PATCH 01/18] Replace API 33.0 to 34.0 Signed-off-by: Miguel Sama --- govcd/api_vcd.go | 2 +- samples/openapi/main.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/govcd/api_vcd.go b/govcd/api_vcd.go index 7bc70cb41..7e6be33c2 100644 --- a/govcd/api_vcd.go +++ b/govcd/api_vcd.go @@ -105,7 +105,7 @@ func NewVCDClient(vcdEndpoint url.URL, insecure bool, options ...VCDClientOption // Setting defaults vcdClient := &VCDClient{ Client: Client{ - APIVersion: "33.0", // supported by 10.0+ + APIVersion: "34.0", // supported by 10.1+ // UserAgent cannot embed exact version by default because this is source code and is supposed to be used by programs, // but any client can customize or disable it at all using WithHttpUserAgent() configuration options function. UserAgent: "go-vcloud-director", diff --git a/samples/openapi/main.go b/samples/openapi/main.go index b5e8b49e3..0dbfddef7 100644 --- a/samples/openapi/main.go +++ b/samples/openapi/main.go @@ -58,8 +58,8 @@ func main() { os.Exit(3) } - if vcdCli.Client.APIVCDMaxVersionIs("< 33.0") { - fmt.Println("This example requires VCD API to support at least version 33.0 (VCD 10.0) to use '1.0.0/auditTrail' endpoint") + if vcdCli.Client.APIVCDMaxVersionIs("< 34.0") { + fmt.Println("This example requires VCD API to support at least version 34.0 (VCD 10.1) to use '1.0.0/auditTrail' endpoint") os.Exit(4) } @@ -87,7 +87,7 @@ func openAPIGetRawJsonAuditTrail(vcdClient *govcd.VCDClient) { queryParams.Add("filter", "timestamp=gt="+filterTime) allResponses := []json.RawMessage{{}} - err = vcdClient.Client.OpenApiGetAllItems("33.0", urlRef, queryParams, &allResponses, nil) + err = vcdClient.Client.OpenApiGetAllItems("34.0", urlRef, queryParams, &allResponses, nil) if err != nil { panic(err) } @@ -145,7 +145,7 @@ func openAPIGetStructAuditTrail(vcdClient *govcd.VCDClient) { filterTime := time.Now().Add(-12 * time.Hour).Format(types.FiqlQueryTimestampFormat) queryParams.Add("filter", "timestamp=gt="+filterTime) - err = vcdClient.Client.OpenApiGetAllItems("33.0", urlRef, queryParams, &response, nil) + err = vcdClient.Client.OpenApiGetAllItems("34.0", urlRef, queryParams, &response, nil) if err != nil { panic(err) } From ed22adbc55385df22e06260508704627ca97533a Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Wed, 2 Feb 2022 16:59:26 +0100 Subject: [PATCH 02/18] Add mock version v34.0 Signed-off-by: Miguel Sama --- .../golden/TestSamlAdfsAuthenticate_RESP_api_versions.golden | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test-resources/golden/TestSamlAdfsAuthenticate_RESP_api_versions.golden b/test-resources/golden/TestSamlAdfsAuthenticate_RESP_api_versions.golden index 2f6ecedbf..8647852fc 100644 --- a/test-resources/golden/TestSamlAdfsAuthenticate_RESP_api_versions.golden +++ b/test-resources/golden/TestSamlAdfsAuthenticate_RESP_api_versions.golden @@ -56,6 +56,10 @@ 33.0 https://192.168.1.109/api/sessions + + 34.0 + https://192.168.1.109/api/sessions + 5.5 https://192.168.1.109/api/sessions From f43b44d763f08c15a595bc337f8b14fbe852ae74 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Fri, 4 Feb 2022 17:06:07 +0100 Subject: [PATCH 03/18] Add deployVappForTest private function to remove createVappForTest Signed-off-by: Miguel Sama --- govcd/common_test.go | 78 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/govcd/common_test.go b/govcd/common_test.go index 035bad0bc..2ee39dcb9 100644 --- a/govcd/common_test.go +++ b/govcd/common_test.go @@ -320,6 +320,84 @@ func createVappForTest(vcd *TestVCD, vappName string) (*VApp, error) { return vapp, nil } +// deployVappForTest aims to replace createVappForTest +func deployVappForTest(vcd *TestVCD, vappName string) (*VApp, error) { + // Populate OrgVDCNetwork + var networks []*types.OrgVDCNetwork + net, err := vcd.vdc.GetOrgVdcNetworkByName(vcd.config.VCD.Network.Net1, false) + if err != nil { + return nil, fmt.Errorf("error finding network : %s", err) + } + networks = append(networks, net.OrgVDCNetwork) + // Populate Catalog + cat, err := vcd.org.GetCatalogByName(vcd.config.VCD.Catalog.Name, false) + if err != nil || cat == nil { + return nil, fmt.Errorf("error finding catalog : %s", err) + } + // Populate Catalog Item + catitem, err := cat.GetCatalogItemByName(vcd.config.VCD.Catalog.CatalogItem, false) + if err != nil { + return nil, fmt.Errorf("error finding catalog item : %s", err) + } + // Get VAppTemplate + vAppTemplate, err := catitem.GetVAppTemplate() + if err != nil { + return nil, fmt.Errorf("error finding vapptemplate : %s", err) + } + // Get StorageProfileReference + storageProfileRef, err := vcd.vdc.FindStorageProfileReference(vcd.config.VCD.StorageProfile.SP1) + if err != nil { + return nil, fmt.Errorf("error finding storage profile: %s", err) + } + + // Create empty vApp + vapp, err := vcd.vdc.CreateRawVApp(vappName, "description") + if err != nil { + return nil, fmt.Errorf("error creating vapp: %s", err) + } + + // After a successful creation, the entity is added to the cleanup list. + // If something fails after this point, the entity will be removed + AddToCleanupList(vappName, "vapp", "", "createTestVapp") + + // Create vApp networking + vAppNetworkConfig, err := vapp.AddOrgNetwork(&VappNetworkSettings{}, net.OrgVDCNetwork, false) + if err != nil { + return nil, fmt.Errorf("error creating vApp network. %s", err) + } + + // Create VM with only one NIC connected to vapp_net + networkConnectionSection := &types.NetworkConnectionSection{ + PrimaryNetworkConnectionIndex: 0, + } + + netConn := &types.NetworkConnection{ + Network: vAppNetworkConfig.NetworkConfig[0].NetworkName, + IsConnected: true, + NetworkConnectionIndex: 0, + IPAddressAllocationMode: types.IPAllocationModePool, + } + + networkConnectionSection.NetworkConnection = append(networkConnectionSection.NetworkConnection, netConn) + + task, err := vapp.AddNewVMWithStorageProfile("test_vm", vAppTemplate, networkConnectionSection, &storageProfileRef, true) + if err != nil { + return nil, fmt.Errorf("error creating the VM: %s", err) + } + + err = task.WaitTaskCompletion() + if err != nil { + return nil, fmt.Errorf("error while waiting for the VM to be created %s", err) + } + + err = vapp.BlockWhileStatus("UNRESOLVED", vapp.client.MaxRetryTimeout) + if err != nil { + return nil, fmt.Errorf("error waiting for created test vApp to have working state: %s", err) + } + + return vapp, nil +} + // Checks whether an independent disk is attached to a VM, and detaches it // moved from disk_test.go func (vcd *TestVCD) detachIndependentDisk(disk Disk) error { From 3bde4605371e05e3e0635b39b9694f7e6b13dc15 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Mon, 7 Feb 2022 09:53:11 +0100 Subject: [PATCH 04/18] Replace createVappForTest by deployVappForTest Signed-off-by: Miguel Sama --- govcd/vapp_network_test.go | 2 +- govcd/vapp_test.go | 24 ++++++++++++------------ govcd/vm_test.go | 6 +++--- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/govcd/vapp_network_test.go b/govcd/vapp_network_test.go index f6678f633..d3766da46 100644 --- a/govcd/vapp_network_test.go +++ b/govcd/vapp_network_test.go @@ -84,7 +84,7 @@ func (vcd *TestVCD) Test_UpdateNetworkFirewallRules(check *C) { func (vcd *TestVCD) prepareVappWithVappNetwork(check *C, vappName, orgVdcNetworkName string) (*VApp, string, *types.NetworkConfigSection, error) { fmt.Printf("Running: %s\n", check.TestName()) - vapp, err := createVappForTest(vcd, vappName) + vapp, err := deployVappForTest(vcd, vappName) check.Assert(err, IsNil) check.Assert(vapp, NotNil) diff --git a/govcd/vapp_test.go b/govcd/vapp_test.go index d40a044ae..8ddffaf4a 100644 --- a/govcd/vapp_test.go +++ b/govcd/vapp_test.go @@ -456,7 +456,7 @@ func (vcd *TestVCD) Test_AddNewVMNilNIC(check *C) { vapptemplate, err := catitem.GetVAppTemplate() check.Assert(err, IsNil) - vapp, err := createVappForTest(vcd, "Test_AddNewVMNilNIC") + vapp, err := deployVappForTest(vcd, "Test_AddNewVMNilNIC") check.Assert(err, IsNil) check.Assert(vapp, NotNil) task, err := vapp.AddNewVM(check.TestName(), vapptemplate, nil, true) @@ -511,7 +511,7 @@ func (vcd *TestVCD) Test_AddNewVMMultiNIC(check *C) { vapptemplate, err := catitem.GetVAppTemplate() check.Assert(err, IsNil) - vapp, err := createVappForTest(vcd, "Test_AddNewVMMultiNIC") + vapp, err := deployVappForTest(vcd, "Test_AddNewVMMultiNIC") check.Assert(err, IsNil) check.Assert(vapp, NotNil) @@ -751,7 +751,7 @@ func (vcd *TestVCD) Test_GetVM(check *C) { func (vcd *TestVCD) Test_AddAndRemoveIsolatedVappNetwork(check *C) { fmt.Printf("Running: %s\n", check.TestName()) - vapp, err := createVappForTest(vcd, "Test_AddAndRemoveIsolatedVappNetwork") + vapp, err := deployVappForTest(vcd, "Test_AddAndRemoveIsolatedVappNetwork") check.Assert(err, IsNil) check.Assert(vapp, NotNil) @@ -838,7 +838,7 @@ func (vcd *TestVCD) Test_AddAndRemoveNatVappNetwork(check *C) { check.Skip("Skipping test because no network was given") } - vapp, err := createVappForTest(vcd, "Test_AddAndRemoveNatVappNetwork") + vapp, err := deployVappForTest(vcd, "Test_AddAndRemoveNatVappNetwork") check.Assert(err, IsNil) check.Assert(vapp, NotNil) @@ -935,7 +935,7 @@ func (vcd *TestVCD) Test_UpdateVappNetwork(check *C) { check.Skip("Skipping test because no network was given") } - vapp, err := createVappForTest(vcd, "Test_UpdateVappNetwork") + vapp, err := deployVappForTest(vcd, "Test_UpdateVappNetwork") check.Assert(err, IsNil) check.Assert(vapp, NotNil) @@ -1094,7 +1094,7 @@ func (vcd *TestVCD) Test_UpdateVappNetwork(check *C) { func (vcd *TestVCD) Test_AddAndRemoveVappNetworkWithMinimumValues(check *C) { fmt.Printf("Running: %s\n", check.TestName()) - vapp, err := createVappForTest(vcd, "Test_AddAndRemoveVappNetworkWithMinimumValues") + vapp, err := deployVappForTest(vcd, "Test_AddAndRemoveVappNetworkWithMinimumValues") check.Assert(err, IsNil) check.Assert(vapp, NotNil) @@ -1164,7 +1164,7 @@ func (vcd *TestVCD) Test_AddAndRemoveOrgVappNetworkWithMinimumValues(check *C) { check.Skip("Skipping test because no network was given") } - vapp, err := createVappForTest(vcd, "Test_AddAndRemoveOrgVappNetworkWithMinimumValues") + vapp, err := deployVappForTest(vcd, "Test_AddAndRemoveOrgVappNetworkWithMinimumValues") check.Assert(err, IsNil) check.Assert(vapp, NotNil) @@ -1198,7 +1198,7 @@ func (vcd *TestVCD) Test_AddAndRemoveOrgVappNetworkWithMinimumValues(check *C) { check.Assert(networkFound.Configuration.ParentNetwork.Name, Equals, vcd.config.VCD.Network.Net1) - err = vcd.vapp.Refresh() + err = vapp.Refresh() check.Assert(err, IsNil) vappNetworkConfig, err = vapp.RemoveNetwork(vcd.config.VCD.Network.Net1) check.Assert(err, IsNil) @@ -1226,7 +1226,7 @@ func (vcd *TestVCD) Test_AddAndRemoveOrgVappNetwork(check *C) { check.Skip("Skipping test because no network was given") } - vapp, err := createVappForTest(vcd, "Test_AddAndRemoveOrgVappNetwork") + vapp, err := deployVappForTest(vcd, "Test_AddAndRemoveOrgVappNetwork") check.Assert(err, IsNil) check.Assert(vapp, NotNil) @@ -1289,7 +1289,7 @@ func (vcd *TestVCD) Test_UpdateOrgVappNetwork(check *C) { check.Skip("Skipping test because no network was given") } - vapp, err := createVappForTest(vcd, "Test_UpdateOrgVappNetwork") + vapp, err := deployVappForTest(vcd, "Test_UpdateOrgVappNetwork") check.Assert(err, IsNil) check.Assert(vapp, NotNil) @@ -1420,7 +1420,7 @@ func (vcd *TestVCD) Test_AddNewVMFromMultiVmTemplate(check *C) { returnedVappTemplate, err := catalog.GetVappTemplateByHref(vmInTemplateRecord.HREF) check.Assert(err, IsNil) - vapp, err := createVappForTest(vcd, "Test_AddNewVMFromMultiVmTemplate") + vapp, err := deployVappForTest(vcd, "Test_AddNewVMFromMultiVmTemplate") check.Assert(err, IsNil) check.Assert(vapp, NotNil) task, err := vapp.AddNewVM(check.TestName(), *returnedVappTemplate, nil, true) @@ -1469,7 +1469,7 @@ func (vcd *TestVCD) Test_AddNewVMWithComputeCapacity(check *C) { vapptemplate, err := catitem.GetVAppTemplate() check.Assert(err, IsNil) - vapp, err := createVappForTest(vcd, "Test_AddNewVMWithComputeCapacity") + vapp, err := deployVappForTest(vcd, "Test_AddNewVMWithComputeCapacity") check.Assert(err, IsNil) check.Assert(vapp, NotNil) diff --git a/govcd/vm_test.go b/govcd/vm_test.go index 78c6f6976..497b02587 100644 --- a/govcd/vm_test.go +++ b/govcd/vm_test.go @@ -1221,7 +1221,7 @@ func (vcd *TestVCD) Test_AddNewEmptyVMMultiNIC(check *C) { check.Skip("skipping test because no vApp is found") } - vapp, err := createVappForTest(vcd, "Test_AddNewEmptyVMMultiNIC") + vapp, err := deployVappForTest(vcd, "Test_AddNewEmptyVMMultiNIC") check.Assert(err, IsNil) check.Assert(vapp, NotNil) @@ -1455,7 +1455,7 @@ func (vcd *TestVCD) Test_UpdateVmCpuAndMemoryHotAdd(check *C) { } func (vcd *TestVCD) Test_AddNewEmptyVMWithVmComputePolicyAndUpdate(check *C) { - vapp, err := createVappForTest(vcd, "Test_AddNewEmptyVMWithVmComputePolicy") + vapp, err := deployVappForTest(vcd, "Test_AddNewEmptyVMWithVmComputePolicy") check.Assert(err, IsNil) check.Assert(vapp, NotNil) @@ -1609,7 +1609,7 @@ func (vcd *TestVCD) Test_VMUpdateStorageProfile(check *C) { check.Skip("Skipping test because both storage profiles have to be configured") } - vapp, err := createVappForTest(vcd, "Test_VMUpdateStorageProfile") + vapp, err := deployVappForTest(vcd, "Test_VMUpdateStorageProfile") check.Assert(err, IsNil) check.Assert(vapp, NotNil) From 0aac28d366f706c740ae135f739b81868bc22c64 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Tue, 8 Feb 2022 14:58:07 +0100 Subject: [PATCH 05/18] Remove leftovers Signed-off-by: Miguel Sama --- govcd/common_test.go | 58 +------------------------------------------- 1 file changed, 1 insertion(+), 57 deletions(-) diff --git a/govcd/common_test.go b/govcd/common_test.go index 2ee39dcb9..8c7998111 100644 --- a/govcd/common_test.go +++ b/govcd/common_test.go @@ -265,70 +265,14 @@ func isTcpPortOpen(host, port string, timeout int) bool { } -// moved from vapp_test.go -func createVappForTest(vcd *TestVCD, vappName string) (*VApp, error) { - // Populate OrgVDCNetwork - var networks []*types.OrgVDCNetwork - net, err := vcd.vdc.GetOrgVdcNetworkByName(vcd.config.VCD.Network.Net1, false) - if err != nil { - return nil, fmt.Errorf("error finding network : %s", err) - } - networks = append(networks, net.OrgVDCNetwork) - // Populate Catalog - cat, err := vcd.org.GetCatalogByName(vcd.config.VCD.Catalog.Name, false) - if err != nil || cat == nil { - return nil, fmt.Errorf("error finding catalog : %s", err) - } - // Populate Catalog Item - catitem, err := cat.GetCatalogItemByName(vcd.config.VCD.Catalog.CatalogItem, false) - if err != nil { - return nil, fmt.Errorf("error finding catalog item : %s", err) - } - // Get VAppTemplate - vAppTemplate, err := catitem.GetVAppTemplate() - if err != nil { - return nil, fmt.Errorf("error finding vapptemplate : %s", err) - } - // Get StorageProfileReference - storageProfileRef, err := vcd.vdc.FindStorageProfileReference(vcd.config.VCD.StorageProfile.SP1) - if err != nil { - return nil, fmt.Errorf("error finding storage profile: %s", err) - } - // Compose VApp - task, err := vcd.vdc.ComposeVApp(networks, vAppTemplate, storageProfileRef, vappName, "description", true) - if err != nil { - return nil, fmt.Errorf("error composing vapp: %s", err) - } - // After a successful creation, the entity is added to the cleanup list. - // If something fails after this point, the entity will be removed - AddToCleanupList(vappName, "vapp", "", "createTestVapp") - err = task.WaitTaskCompletion() - if err != nil { - return nil, fmt.Errorf("error composing vapp: %s", err) - } - // Get VApp - vapp, err := vcd.vdc.GetVAppByName(vappName, true) - if err != nil { - return nil, fmt.Errorf("error getting vapp: %s", err) - } - - err = vapp.BlockWhileStatus("UNRESOLVED", vapp.client.MaxRetryTimeout) - if err != nil { - return nil, fmt.Errorf("error waiting for created test vApp to have working state: %s", err) - } - - return vapp, nil -} - // deployVappForTest aims to replace createVappForTest func deployVappForTest(vcd *TestVCD, vappName string) (*VApp, error) { // Populate OrgVDCNetwork - var networks []*types.OrgVDCNetwork net, err := vcd.vdc.GetOrgVdcNetworkByName(vcd.config.VCD.Network.Net1, false) if err != nil { return nil, fmt.Errorf("error finding network : %s", err) } - networks = append(networks, net.OrgVDCNetwork) + // Populate Catalog cat, err := vcd.org.GetCatalogByName(vcd.config.VCD.Catalog.Name, false) if err != nil || cat == nil { From c4c05fe94981b69b795e30ec8801e92883add9fc Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Tue, 8 Feb 2022 14:58:27 +0100 Subject: [PATCH 06/18] Add API bump to changelog Signed-off-by: Miguel Sama --- .changes/v2.15.0/434-improvements.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 .changes/v2.15.0/434-improvements.md diff --git a/.changes/v2.15.0/434-improvements.md b/.changes/v2.15.0/434-improvements.md new file mode 100644 index 000000000..6efcfe3a3 --- /dev/null +++ b/.changes/v2.15.0/434-improvements.md @@ -0,0 +1 @@ +* Bumped Default API Version to V34.0 [GH-434] From 9e6e0076d5f58c2c0d1f428e463ceb1abb8d1970 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Mon, 21 Feb 2022 08:45:31 +0100 Subject: [PATCH 07/18] Bump API to v35.0 Signed-off-by: Miguel Sama --- .changes/v2.15.0/434-improvements.md | 2 +- govcd/api_vcd.go | 2 +- samples/openapi/main.go | 8 ++++---- .../TestSamlAdfsAuthenticate_RESP_api_versions.golden | 4 ++++ 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.changes/v2.15.0/434-improvements.md b/.changes/v2.15.0/434-improvements.md index 6efcfe3a3..4c94da355 100644 --- a/.changes/v2.15.0/434-improvements.md +++ b/.changes/v2.15.0/434-improvements.md @@ -1 +1 @@ -* Bumped Default API Version to V34.0 [GH-434] +* Bumped Default API Version to V35.0 [GH-434] diff --git a/govcd/api_vcd.go b/govcd/api_vcd.go index 7e6be33c2..187e89d58 100644 --- a/govcd/api_vcd.go +++ b/govcd/api_vcd.go @@ -105,7 +105,7 @@ func NewVCDClient(vcdEndpoint url.URL, insecure bool, options ...VCDClientOption // Setting defaults vcdClient := &VCDClient{ Client: Client{ - APIVersion: "34.0", // supported by 10.1+ + APIVersion: "35.0", // supported by 10.2+ // UserAgent cannot embed exact version by default because this is source code and is supposed to be used by programs, // but any client can customize or disable it at all using WithHttpUserAgent() configuration options function. UserAgent: "go-vcloud-director", diff --git a/samples/openapi/main.go b/samples/openapi/main.go index 0dbfddef7..b1c8d560b 100644 --- a/samples/openapi/main.go +++ b/samples/openapi/main.go @@ -58,8 +58,8 @@ func main() { os.Exit(3) } - if vcdCli.Client.APIVCDMaxVersionIs("< 34.0") { - fmt.Println("This example requires VCD API to support at least version 34.0 (VCD 10.1) to use '1.0.0/auditTrail' endpoint") + if vcdCli.Client.APIVCDMaxVersionIs("< 35.0") { + fmt.Println("This example requires VCD API to support at least version 35.0 (VCD 10.2) to use '1.0.0/auditTrail' endpoint") os.Exit(4) } @@ -87,7 +87,7 @@ func openAPIGetRawJsonAuditTrail(vcdClient *govcd.VCDClient) { queryParams.Add("filter", "timestamp=gt="+filterTime) allResponses := []json.RawMessage{{}} - err = vcdClient.Client.OpenApiGetAllItems("34.0", urlRef, queryParams, &allResponses, nil) + err = vcdClient.Client.OpenApiGetAllItems("35.0", urlRef, queryParams, &allResponses, nil) if err != nil { panic(err) } @@ -145,7 +145,7 @@ func openAPIGetStructAuditTrail(vcdClient *govcd.VCDClient) { filterTime := time.Now().Add(-12 * time.Hour).Format(types.FiqlQueryTimestampFormat) queryParams.Add("filter", "timestamp=gt="+filterTime) - err = vcdClient.Client.OpenApiGetAllItems("34.0", urlRef, queryParams, &response, nil) + err = vcdClient.Client.OpenApiGetAllItems("35.0", urlRef, queryParams, &response, nil) if err != nil { panic(err) } diff --git a/test-resources/golden/TestSamlAdfsAuthenticate_RESP_api_versions.golden b/test-resources/golden/TestSamlAdfsAuthenticate_RESP_api_versions.golden index 8647852fc..260db6a42 100644 --- a/test-resources/golden/TestSamlAdfsAuthenticate_RESP_api_versions.golden +++ b/test-resources/golden/TestSamlAdfsAuthenticate_RESP_api_versions.golden @@ -60,6 +60,10 @@ 34.0 https://192.168.1.109/api/sessions + + 35.0 + https://192.168.1.109/api/sessions + 5.5 https://192.168.1.109/api/sessions From 687da8e7dfb07c05b3b00122295ec60bd612dc13 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Tue, 22 Feb 2022 16:35:18 +0100 Subject: [PATCH 08/18] Change OrgVdc for OwnerRef as OrgVdc attribute is no longer supported. Improve Vdc.UpdateOpenApiOrgVdcNetworkDhcp method to allow setting OpenApiOrgVdcNetworkDhcp.LeaseTime and OpenApiOrgVdcNetworkDhcp.Mode to default values in case the passed struct doesn't have them set Signed-off-by: Miguel Sama --- ...nsxt_firewall_group_security_group_test.go | 4 +++- govcd/openapi_org_network_dhcp.go | 12 ++++++++++ govcd/openapi_org_network_test.go | 24 ++++++++++++++----- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/govcd/nsxt_firewall_group_security_group_test.go b/govcd/nsxt_firewall_group_security_group_test.go index bed52d545..9ceb4f521 100644 --- a/govcd/nsxt_firewall_group_security_group_test.go +++ b/govcd/nsxt_firewall_group_security_group_test.go @@ -171,7 +171,9 @@ func createNsxtRoutedNetwork(check *C, vcd *TestVCD, vdc *Vdc, edgeGatewayId str orgVdcNetworkConfig := &types.OpenApiOrgVdcNetwork{ Name: check.TestName() + "routed-net", Description: check.TestName() + "-description", - OrgVdc: &types.OpenApiReference{ID: vcd.nsxtVdc.Vdc.ID}, + + // On v35.0 orgVdc is not supported anymore. Using ownerRef instead. + OwnerRef: &types.OpenApiReference{ID: vcd.nsxtVdc.Vdc.ID}, NetworkType: types.OrgVdcNetworkTypeRouted, diff --git a/govcd/openapi_org_network_dhcp.go b/govcd/openapi_org_network_dhcp.go index a059d1fd1..f2caa7d9a 100644 --- a/govcd/openapi_org_network_dhcp.go +++ b/govcd/openapi_org_network_dhcp.go @@ -73,6 +73,18 @@ func (vdc *Vdc) UpdateOpenApiOrgVdcNetworkDhcp(orgNetworkId string, orgVdcNetwor client: vdc.client, } + // From v35.0 onwards, if orgVdcNetworkDhcpConfig.LeaseTime or orgVdcNetworkDhcpConfig.Mode are not explicitly + // passed, the API doesn't use any defaults returning an error. Previous API versions were setting + // LeaseTime to 86400 seconds and Mode to EDGE if these values were not supplied. These two conditional + // address the situation. + if orgVdcNetworkDhcpConfig.LeaseTime == nil { + orgVdcNetworkDhcpConfig.LeaseTime = takeIntAddress(86400) + } + + if len(orgVdcNetworkDhcpConfig.Mode) == 0 { + orgVdcNetworkDhcpConfig.Mode = "EDGE" + } + err = vdc.client.OpenApiPutItem(minimumApiVersion, urlRef, nil, orgVdcNetworkDhcpConfig, orgNetDhcpResponse.OpenApiOrgVdcNetworkDhcp, nil) if err != nil { return nil, fmt.Errorf("error updating Org VDC network DHCP configuration: %s", err) diff --git a/govcd/openapi_org_network_test.go b/govcd/openapi_org_network_test.go index c54d23afd..1f02b6db0 100644 --- a/govcd/openapi_org_network_test.go +++ b/govcd/openapi_org_network_test.go @@ -21,7 +21,9 @@ func (vcd *TestVCD) Test_NsxtOrgVdcNetworkIsolated(check *C) { orgVdcNetworkConfig := &types.OpenApiOrgVdcNetwork{ Name: check.TestName(), Description: check.TestName() + "-description", - OrgVdc: &types.OpenApiReference{ID: vcd.nsxtVdc.Vdc.ID}, + + // On v35.0 orgVdc is not supported anymore. Using ownerRef instead. + OwnerRef: &types.OpenApiReference{ID: vcd.nsxtVdc.Vdc.ID}, NetworkType: types.OrgVdcNetworkTypeIsolated, Subnets: types.OrgVdcNetworkSubnets{ @@ -65,7 +67,9 @@ func (vcd *TestVCD) Test_NsxtOrgVdcNetworkRouted(check *C) { orgVdcNetworkConfig := &types.OpenApiOrgVdcNetwork{ Name: check.TestName(), Description: check.TestName() + "-description", - OrgVdc: &types.OpenApiReference{ID: vcd.nsxtVdc.Vdc.ID}, + + // On v35.0 orgVdc is not supported anymore. Using ownerRef instead. + OwnerRef: &types.OpenApiReference{ID: vcd.nsxtVdc.Vdc.ID}, NetworkType: types.OrgVdcNetworkTypeRouted, @@ -130,7 +134,9 @@ func (vcd *TestVCD) Test_NsxtOrgVdcNetworkImported(check *C) { orgVdcNetworkConfig := &types.OpenApiOrgVdcNetwork{ Name: check.TestName(), Description: check.TestName() + "-description", - OrgVdc: &types.OpenApiReference{ID: vcd.nsxtVdc.Vdc.ID}, + + // On v35.0 orgVdc is not supported anymore. Using ownerRef instead. + OwnerRef: &types.OpenApiReference{ID: vcd.nsxtVdc.Vdc.ID}, NetworkType: types.OrgVdcNetworkTypeOpaque, // BackingNetworkId contains NSX-T logical switch ID for Imported networks @@ -170,7 +176,9 @@ func (vcd *TestVCD) Test_NsxvOrgVdcNetworkIsolated(check *C) { orgVdcNetworkConfig := &types.OpenApiOrgVdcNetwork{ Name: check.TestName(), Description: check.TestName() + "-description", - OrgVdc: &types.OpenApiReference{ID: vcd.vdc.Vdc.ID}, + + // On v35.0 orgVdc is not supported anymore. Using ownerRef instead. + OwnerRef: &types.OpenApiReference{ID: vcd.vdc.Vdc.ID}, NetworkType: types.OrgVdcNetworkTypeIsolated, Subnets: types.OrgVdcNetworkSubnets{ @@ -213,7 +221,9 @@ func (vcd *TestVCD) Test_NsxvOrgVdcNetworkRouted(check *C) { orgVdcNetworkConfig := &types.OpenApiOrgVdcNetwork{ Name: check.TestName(), Description: check.TestName() + "-description", - OrgVdc: &types.OpenApiReference{ID: vcd.vdc.Vdc.ID}, + + // On v35.0 orgVdc is not supported anymore. Using ownerRef instead. + OwnerRef: &types.OpenApiReference{ID: vcd.vdc.Vdc.ID}, NetworkType: types.OrgVdcNetworkTypeRouted, @@ -275,7 +285,9 @@ func (vcd *TestVCD) Test_NsxvOrgVdcNetworkDirect(check *C) { orgVdcNetworkConfig := &types.OpenApiOrgVdcNetwork{ Name: check.TestName(), Description: check.TestName() + "-description", - OrgVdc: &types.OpenApiReference{ID: vcd.vdc.Vdc.ID}, + + // On v35.0 orgVdc is not supported anymore. Using ownerRef instead. + OwnerRef: &types.OpenApiReference{ID: vcd.vdc.Vdc.ID}, NetworkType: types.OrgVdcNetworkTypeDirect, ParentNetwork: &types.OpenApiReference{ID: externalNetwork.ExternalNetwork.ID}, From b15874a08f235053d404d4e8e529e6f73b5cdf80 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Wed, 23 Feb 2022 14:57:30 +0100 Subject: [PATCH 09/18] Remove createTestVapp since it was using the bad implemented method Vcd.ComposeVApp. Replace vcd.createTestVapp in favor of deployVappForTest when setting up the test suite. Signed-off-by: Miguel Sama --- govcd/api_vcd_test.go | 66 ++----------------------------------------- 1 file changed, 2 insertions(+), 64 deletions(-) diff --git a/govcd/api_vcd_test.go b/govcd/api_vcd_test.go index 833b1c9e0..e75705755 100644 --- a/govcd/api_vcd_test.go +++ b/govcd/api_vcd_test.go @@ -618,7 +618,8 @@ func (vcd *TestVCD) SetUpSuite(check *C) { // creates a new VApp for vapp tests if !skipVappCreation && config.VCD.Network.Net1 != "" && config.VCD.StorageProfile.SP1 != "" && config.VCD.Catalog.Name != "" && config.VCD.Catalog.CatalogItem != "" { - vcd.vapp, err = vcd.createTestVapp(TestSetUpSuite) + // deployVappForTest replaces the old createTestVapp() because it was using bad implemented method vdc.ComposeVApp + vcd.vapp, err = deployVappForTest(vcd, TestSetUpSuite) // If no vApp is created, we skip all vApp tests if err != nil { fmt.Printf("%s\n", err) @@ -1611,69 +1612,6 @@ func TestVCDClient_Authenticate(t *testing.T) { } } -func (vcd *TestVCD) createTestVapp(name string) (*VApp, error) { - // ========================= issue#252 ================================== - // TODO: To be enabled when issue#252 is resolved. - // Allows re-using a pre-created vApp - // existingVapp, err := vcd.vdc.GetVAppByName(name, false) - // if err == nil { - // fmt.Printf("vApp %s already exists. Skipping creation\n",name) - // return existingVapp, nil - // } - // ====================================================================== - // Populate OrgVDCNetwork - var networks []*types.OrgVDCNetwork - net, err := vcd.vdc.GetOrgVdcNetworkByName(vcd.config.VCD.Network.Net1, false) - if err != nil { - return nil, fmt.Errorf("error finding network : %s, err: %s", vcd.config.VCD.Network.Net1, err) - } - networks = append(networks, net.OrgVDCNetwork) - // Populate Catalog - cat, err := vcd.org.GetCatalogByName(vcd.config.VCD.Catalog.Name, false) - if err != nil || cat == nil { - return nil, fmt.Errorf("error finding catalog : %s", err) - } - // Populate Catalog Item - catitem, err := cat.GetCatalogItemByName(vcd.config.VCD.Catalog.CatalogItem, false) - if err != nil { - return nil, fmt.Errorf("error finding catalog item : %s", err) - } - // Get VAppTemplate - vAppTemplate, err := catitem.GetVAppTemplate() - if err != nil { - return nil, fmt.Errorf("error finding vapptemplate : %s", err) - } - // Get StorageProfileReference - storageProfileRef, err := vcd.vdc.FindStorageProfileReference(vcd.config.VCD.StorageProfile.SP1) - if err != nil { - return nil, fmt.Errorf("error finding storage profile: %s", err) - } - // Compose VApp - task, err := vcd.vdc.ComposeVApp(networks, vAppTemplate, storageProfileRef, name, "description", true) - if err != nil { - return nil, fmt.Errorf("error composing vapp: %s", err) - } - // After a successful creation, the entity is added to the cleanup list. - // If something fails after this point, the entity will be removed - AddToCleanupList(name, "vapp", "", "createTestVapp") - err = task.WaitTaskCompletion() - if err != nil { - return nil, fmt.Errorf("error composing vapp: %s", err) - } - // Get VApp - vapp, err := vcd.vdc.GetVAppByName(name, true) - if err != nil { - return nil, fmt.Errorf("error getting vapp: %s", err) - } - - err = vapp.BlockWhileStatus("UNRESOLVED", vapp.client.MaxRetryTimeout) - if err != nil { - return nil, fmt.Errorf("error waiting for created test vApp to have working state: %s", err) - } - - return vapp, err -} - func Test_splitParent(t *testing.T) { type args struct { parent string From aeb79435da4dc1b2351d93615afc1caf5e9e23b0 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Wed, 23 Feb 2022 15:03:13 +0100 Subject: [PATCH 10/18] Remove ComposeVApp since it was a bad implementation and it wasn't used anymore Signed-off-by: Miguel Sama --- govcd/vdc.go | 93 ---------------------------------------------------- 1 file changed, 93 deletions(-) diff --git a/govcd/vdc.go b/govcd/vdc.go index 98613da6f..ef74402af 100644 --- a/govcd/vdc.go +++ b/govcd/vdc.go @@ -555,99 +555,6 @@ func (vdc *Vdc) CreateRawVApp(name string, description string) (*VApp, error) { return vapp, nil } -// ComposeVApp creates a vapp with the given template, name, and description -// that uses the storageprofile and networks given. If you want all eulas -// to be accepted set acceptalleulas to true. Returns a successful task -// if completed successfully, otherwise returns an error and an empty task. -// Deprecated: bad implementation -func (vdc *Vdc) ComposeVApp(orgvdcnetworks []*types.OrgVDCNetwork, vapptemplate VAppTemplate, storageprofileref types.Reference, name string, description string, acceptalleulas bool) (Task, error) { - if vapptemplate.VAppTemplate.Children == nil || orgvdcnetworks == nil { - return Task{}, fmt.Errorf("can't compose a new vApp, objects passed are not valid") - } - - // Determine primary network connection index number. We normally depend on it being inherited from vApp template - // but in the case when vApp template does not have network card it would fail on the index being undefined. We - // set the value to 0 (first NIC instead) - primaryNetworkConnectionIndex := 0 - if vapptemplate.VAppTemplate.Children != nil && len(vapptemplate.VAppTemplate.Children.VM) > 0 && - vapptemplate.VAppTemplate.Children.VM[0].NetworkConnectionSection != nil { - primaryNetworkConnectionIndex = vapptemplate.VAppTemplate.Children.VM[0].NetworkConnectionSection.PrimaryNetworkConnectionIndex - } - - // Build request XML - vcomp := &types.ComposeVAppParams{ - Ovf: types.XMLNamespaceOVF, - Xsi: types.XMLNamespaceXSI, - Xmlns: types.XMLNamespaceVCloud, - Deploy: false, - Name: name, - PowerOn: false, - Description: description, - InstantiationParams: &types.InstantiationParams{ - NetworkConfigSection: &types.NetworkConfigSection{ - Info: "Configuration parameters for logical networks", - }, - }, - AllEULAsAccepted: acceptalleulas, - SourcedItem: &types.SourcedCompositionItemParam{ - Source: &types.Reference{ - HREF: vapptemplate.VAppTemplate.Children.VM[0].HREF, - Name: vapptemplate.VAppTemplate.Children.VM[0].Name, - }, - InstantiationParams: &types.InstantiationParams{ - NetworkConnectionSection: &types.NetworkConnectionSection{ - Info: "Network config for sourced item", - PrimaryNetworkConnectionIndex: primaryNetworkConnectionIndex, - }, - }, - }, - } - for index, orgvdcnetwork := range orgvdcnetworks { - vcomp.InstantiationParams.NetworkConfigSection.NetworkConfig = append(vcomp.InstantiationParams.NetworkConfigSection.NetworkConfig, - types.VAppNetworkConfiguration{ - NetworkName: orgvdcnetwork.Name, - Configuration: &types.NetworkConfiguration{ - FenceMode: types.FenceModeBridged, - ParentNetwork: &types.Reference{ - HREF: orgvdcnetwork.HREF, - Name: orgvdcnetwork.Name, - Type: orgvdcnetwork.Type, - }, - }, - }, - ) - vcomp.SourcedItem.InstantiationParams.NetworkConnectionSection.NetworkConnection = append(vcomp.SourcedItem.InstantiationParams.NetworkConnectionSection.NetworkConnection, - &types.NetworkConnection{ - Network: orgvdcnetwork.Name, - NetworkConnectionIndex: index, - IsConnected: true, - IPAddressAllocationMode: types.IPAllocationModePool, - }, - ) - vcomp.SourcedItem.NetworkAssignment = append(vcomp.SourcedItem.NetworkAssignment, - &types.NetworkAssignment{ - InnerNetwork: orgvdcnetwork.Name, - ContainerNetwork: orgvdcnetwork.Name, - }, - ) - } - if storageprofileref.HREF != "" { - vcomp.SourcedItem.StorageProfile = &storageprofileref - } - - vdcHref, err := url.ParseRequestURI(vdc.Vdc.HREF) - if err != nil { - return Task{}, fmt.Errorf("error getting vdc href: %s", err) - } - vdcHref.Path += "/action/composeVApp" - - // Like ComposeRawVApp, this function returns a task, while it should be returning a vApp - // Since we don't use this function in terraform-provider-vcd, we are not going to - // replace it. - return vdc.client.ExecuteTaskRequest(vdcHref.String(), http.MethodPost, - types.MimeComposeVappParams, "error instantiating a new vApp: %s", vcomp) -} - // Deprecated: use vdc.GetVAppByName instead func (vdc *Vdc) FindVAppByName(vapp string) (VApp, error) { From 4944f750f5d7f00d937cff60eba05e20285aaaa2 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Wed, 23 Feb 2022 15:04:30 +0100 Subject: [PATCH 11/18] Remove Test_ComposeVApp since ComposeVApp function doesn't exist anymore Signed-off-by: Miguel Sama --- govcd/vdc_test.go | 74 ----------------------------------------------- 1 file changed, 74 deletions(-) diff --git a/govcd/vdc_test.go b/govcd/vdc_test.go index 748c33698..fb1f096db 100644 --- a/govcd/vdc_test.go +++ b/govcd/vdc_test.go @@ -144,80 +144,6 @@ func (vcd *TestVCD) Test_NewVdc(check *C) { } -// Tests ComposeVApp with given parameters in the config file. -// Throws an error if networks, catalog, catalog item, and -// storage preference are omitted from the config file. -func (vcd *TestVCD) Test_ComposeVApp(check *C) { - if vcd.config.VCD.Network.Net1 == "" { - check.Skip("Skipping test because no network was given") - } - if vcd.skipVappTests { - check.Skip("Skipping test because vapp wasn't properly created") - } - fmt.Printf("Running: %s\n", check.TestName()) - - // Populate OrgVDCNetwork - networks := []*types.OrgVDCNetwork{} - net, err := vcd.vdc.GetOrgVdcNetworkByName(vcd.config.VCD.Network.Net1, false) - check.Assert(err, IsNil) - networks = append(networks, net.OrgVDCNetwork) - check.Assert(err, IsNil) - // Populate Catalog - cat, err := vcd.org.GetCatalogByName(vcd.config.VCD.Catalog.Name, false) - check.Assert(err, IsNil) - check.Assert(cat, NotNil) - // Populate Catalog Item - catitem, err := cat.GetCatalogItemByName(vcd.config.VCD.Catalog.CatalogItem, false) - check.Assert(err, IsNil) - check.Assert(catitem, NotNil) - // Get VAppTemplate - vapptemplate, err := catitem.GetVAppTemplate() - check.Assert(err, IsNil) - // Get StorageProfileReference - storageprofileref, err := vcd.vdc.FindStorageProfileReference(vcd.config.VCD.StorageProfile.SP1) - check.Assert(err, IsNil) - // Compose VApp - task, err := vcd.vdc.ComposeVApp(networks, vapptemplate, storageprofileref, TestComposeVapp, TestComposeVappDesc, true) - check.Assert(err, IsNil) - check.Assert(task.Task.Tasks.Task[0].OperationName, Equals, "vdcComposeVapp") - // Get VApp - vapp, err := vcd.vdc.GetVAppByName(TestComposeVapp, true) - check.Assert(err, IsNil) - // After a successful creation, the entity is added to the cleanup list. - // If something fails after this point, the entity will be removed - AddToCleanupList(TestComposeVapp, "vapp", "", "Test_ComposeVApp") - // Once the operation is successful, we won't trigger a failure - // until after the vApp deletion - check.Check(vapp.VApp.Name, Equals, TestComposeVapp) - check.Check(vapp.VApp.Description, Equals, TestComposeVappDesc) - - vapp_status, err := vapp.GetStatus() - check.Check(err, IsNil) - check.Check(vapp_status, Equals, "UNRESOLVED") - // Let the VApp creation complete - err = task.WaitTaskCompletion() - if err != nil { - panic(err) - } - err = vapp.BlockWhileStatus("UNRESOLVED", vapp.client.MaxRetryTimeout) - check.Check(err, IsNil) - vapp_status, err = vapp.GetStatus() - check.Check(err, IsNil) - check.Check(vapp_status, Equals, "POWERED_OFF") - // Deleting VApp - task, err = vapp.Delete() - check.Assert(err, IsNil) - err = task.WaitTaskCompletion() - if err != nil { - panic(err) - } - check.Assert(err, IsNil) - noSuchVapp, err := vcd.vdc.GetVAppByName(TestComposeVapp, true) - check.Assert(err, NotNil) - check.Assert(noSuchVapp, IsNil) - -} - func (vcd *TestVCD) Test_FindVApp(check *C) { if vcd.skipVappTests { From b09306205ce313ff4c7242c16a4c90ecac82108d Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Wed, 23 Feb 2022 15:06:24 +0100 Subject: [PATCH 12/18] Replace Vcd.createTestVapp() for deployVappForTest() Signed-off-by: Miguel Sama --- govcd/vm_dhcp_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/govcd/vm_dhcp_test.go b/govcd/vm_dhcp_test.go index 7d662a721..7e510fd45 100644 --- a/govcd/vm_dhcp_test.go +++ b/govcd/vm_dhcp_test.go @@ -29,7 +29,7 @@ func (vcd *TestVCD) Test_VMGetDhcpAddress(check *C) { } // Construct new VM for test - vapp, err := vcd.createTestVapp("GetDhcpAddress") + vapp, err := deployVappForTest(vcd, "GetDhcpAddress") check.Assert(err, IsNil) vmType, _ := vcd.findFirstVm(*vapp) vm := &VM{ From f0f33ec0cbe5a340c1b09493f18055e15d560348 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Wed, 23 Feb 2022 16:15:23 +0100 Subject: [PATCH 13/18] Add tags alb, certificate, vdcGroup and metadata to common_test.go Signed-off-by: Miguel Sama --- govcd/common_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/govcd/common_test.go b/govcd/common_test.go index 8c7998111..769cf4373 100644 --- a/govcd/common_test.go +++ b/govcd/common_test.go @@ -1,5 +1,5 @@ -//go:build api || auth || functional || catalog || vapp || gateway || network || org || query || extnetwork || task || vm || vdc || system || disk || lb || lbAppRule || lbAppProfile || lbServerPool || lbServiceMonitor || lbVirtualServer || user || role || nsxv || nsxt || openapi || affinity || search || ALL -// +build api auth functional catalog vapp gateway network org query extnetwork task vm vdc system disk lb lbAppRule lbAppProfile lbServerPool lbServiceMonitor lbVirtualServer user role nsxv nsxt openapi affinity search ALL +//go:build api || auth || functional || catalog || vapp || gateway || network || org || query || extnetwork || task || vm || vdc || system || disk || lb || lbAppRule || lbAppProfile || lbServerPool || lbServiceMonitor || lbVirtualServer || user || role || nsxv || nsxt || openapi || affinity || search || alb || certificate || vdcGroup || metadata || ALL +// +build api auth functional catalog vapp gateway network org query extnetwork task vm vdc system disk lb lbAppRule lbAppProfile lbServerPool lbServiceMonitor lbVirtualServer user role nsxv nsxt openapi affinity search alb certificate vdcGroup metadata ALL /* * Copyright 2021 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. From c3a89f6e47cad3ba4659d58fc6aab3665312042b Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Thu, 24 Feb 2022 17:07:25 +0100 Subject: [PATCH 14/18] Fix small typo Signed-off-by: Miguel Sama --- .changes/v2.15.0/434-improvements.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changes/v2.15.0/434-improvements.md b/.changes/v2.15.0/434-improvements.md index 4c94da355..edf9a5cef 100644 --- a/.changes/v2.15.0/434-improvements.md +++ b/.changes/v2.15.0/434-improvements.md @@ -1 +1 @@ -* Bumped Default API Version to V35.0 [GH-434] +* Bump Default API Version to V35.0 [GH-434] From 6eebffc7285b2d4ff14ade215a19362911751302 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Thu, 24 Feb 2022 17:07:45 +0100 Subject: [PATCH 15/18] Add env var GOVCD_API_VERSION so API version can be set manually Signed-off-by: Miguel Sama --- .changes/v2.15.0/434-features.md | 1 + govcd/api_vcd.go | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 .changes/v2.15.0/434-features.md diff --git a/.changes/v2.15.0/434-features.md b/.changes/v2.15.0/434-features.md new file mode 100644 index 000000000..df64d4374 --- /dev/null +++ b/.changes/v2.15.0/434-features.md @@ -0,0 +1 @@ +* Add environment variable `GOVCD_API_VERSION` so API version can be set manually [GH-434] diff --git a/govcd/api_vcd.go b/govcd/api_vcd.go index 187e89d58..971638747 100644 --- a/govcd/api_vcd.go +++ b/govcd/api_vcd.go @@ -7,8 +7,10 @@ package govcd import ( "crypto/tls" "fmt" + semver "github.com/hashicorp/go-version" "net/http" "net/url" + "os" "strings" "time" @@ -102,10 +104,22 @@ func (vcdClient *VCDClient) vcdCloudApiAuthorize(user, pass, org string) (*http. // NewVCDClient initializes VMware vCloud Director client with reasonable defaults. // It accepts functions of type VCDClientOption for adjusting defaults. func NewVCDClient(vcdEndpoint url.URL, insecure bool, options ...VCDClientOption) *VCDClient { + minVcdApiVersion := "35.0" // supported by 10.2+ + userDefinedApiVersion := os.Getenv("GOVCD_API_VERSION") + if userDefinedApiVersion != "" { + _, err := semver.NewVersion(userDefinedApiVersion) + if err != nil { + // We do not have error in return of this function signature. + // To avoid breaking API the only thing we can do is panic. + panic(fmt.Sprintf("unable to initialize VCD client from environment variable GOVCD_API_VERSION. Version '%s' is not valid: %s", userDefinedApiVersion, err)) + } + minVcdApiVersion = userDefinedApiVersion + } + // Setting defaults vcdClient := &VCDClient{ Client: Client{ - APIVersion: "35.0", // supported by 10.2+ + APIVersion: minVcdApiVersion, // supported by 10.2+ // UserAgent cannot embed exact version by default because this is source code and is supposed to be used by programs, // but any client can customize or disable it at all using WithHttpUserAgent() configuration options function. UserAgent: "go-vcloud-director", @@ -130,7 +144,7 @@ func NewVCDClient(vcdEndpoint url.URL, insecure bool, options ...VCDClientOption if err != nil { // We do not have error in return of this function signature. // To avoid breaking API the only thing we can do is panic. - panic(fmt.Sprintf("unable to initialize vCD client: %s", err)) + panic(fmt.Sprintf("unable to initialize VCD client: %s", err)) } } return vcdClient From cd9be000e7cd98d3aa0c6932e9c9c0229ade2e02 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Tue, 1 Mar 2022 11:51:49 +0100 Subject: [PATCH 16/18] Add testing docs regarding GOVCD_API_VERSION env var Signed-off-by: Miguel Sama --- TESTING.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TESTING.md b/TESTING.md index 0c3f31e19..0ea0a2f3a 100644 --- a/TESTING.md +++ b/TESTING.md @@ -342,6 +342,8 @@ While running tests, the following environment variables can be used: * `VCD_TOKEN` : specifies the authorization token to use instead of username/password (Use `./scripts/get_token.sh` to retrieve one) * `GOVCD_KEEP_TEST_OBJECTS` will skip deletion of objects created during tests. +* `GOVCD_API_VERSION` allows to select the API version to use. This must be used for testing purposes only as the SDK + has been tested to use certain version of the API. Using this environment variable my lead to unexpected failures. When both the environment variable and the command line option are possible, the environment variable gets evaluated first. From 5682ffc93bc6c69fba21c5fefbf54f390ed59181 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Tue, 1 Mar 2022 12:03:13 +0100 Subject: [PATCH 17/18] Fix small typo Signed-off-by: Miguel Sama --- TESTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TESTING.md b/TESTING.md index 0ea0a2f3a..65b133a6c 100644 --- a/TESTING.md +++ b/TESTING.md @@ -342,8 +342,8 @@ While running tests, the following environment variables can be used: * `VCD_TOKEN` : specifies the authorization token to use instead of username/password (Use `./scripts/get_token.sh` to retrieve one) * `GOVCD_KEEP_TEST_OBJECTS` will skip deletion of objects created during tests. -* `GOVCD_API_VERSION` allows to select the API version to use. This must be used for testing purposes only as the SDK - has been tested to use certain version of the API. Using this environment variable my lead to unexpected failures. +* `GOVCD_API_VERSION` allows to select the API version to use. This must be used **for testing purposes only** as the SDK + has been tested to use certain version of the API. Using this environment variable may lead to unexpected failures. When both the environment variable and the command line option are possible, the environment variable gets evaluated first. From 9d5334d61836baa130a28fd225e9d4dc9feda013 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Wed, 2 Mar 2022 12:10:19 +0100 Subject: [PATCH 18/18] Restore Vdc.ComposeVApp and its test Test_ComposeVApp Signed-off-by: Miguel Sama --- govcd/vdc.go | 93 +++++++++++++++++++++++++++++++++++++++++++++++ govcd/vdc_test.go | 74 +++++++++++++++++++++++++++++++++++++ 2 files changed, 167 insertions(+) diff --git a/govcd/vdc.go b/govcd/vdc.go index ef74402af..98613da6f 100644 --- a/govcd/vdc.go +++ b/govcd/vdc.go @@ -555,6 +555,99 @@ func (vdc *Vdc) CreateRawVApp(name string, description string) (*VApp, error) { return vapp, nil } +// ComposeVApp creates a vapp with the given template, name, and description +// that uses the storageprofile and networks given. If you want all eulas +// to be accepted set acceptalleulas to true. Returns a successful task +// if completed successfully, otherwise returns an error and an empty task. +// Deprecated: bad implementation +func (vdc *Vdc) ComposeVApp(orgvdcnetworks []*types.OrgVDCNetwork, vapptemplate VAppTemplate, storageprofileref types.Reference, name string, description string, acceptalleulas bool) (Task, error) { + if vapptemplate.VAppTemplate.Children == nil || orgvdcnetworks == nil { + return Task{}, fmt.Errorf("can't compose a new vApp, objects passed are not valid") + } + + // Determine primary network connection index number. We normally depend on it being inherited from vApp template + // but in the case when vApp template does not have network card it would fail on the index being undefined. We + // set the value to 0 (first NIC instead) + primaryNetworkConnectionIndex := 0 + if vapptemplate.VAppTemplate.Children != nil && len(vapptemplate.VAppTemplate.Children.VM) > 0 && + vapptemplate.VAppTemplate.Children.VM[0].NetworkConnectionSection != nil { + primaryNetworkConnectionIndex = vapptemplate.VAppTemplate.Children.VM[0].NetworkConnectionSection.PrimaryNetworkConnectionIndex + } + + // Build request XML + vcomp := &types.ComposeVAppParams{ + Ovf: types.XMLNamespaceOVF, + Xsi: types.XMLNamespaceXSI, + Xmlns: types.XMLNamespaceVCloud, + Deploy: false, + Name: name, + PowerOn: false, + Description: description, + InstantiationParams: &types.InstantiationParams{ + NetworkConfigSection: &types.NetworkConfigSection{ + Info: "Configuration parameters for logical networks", + }, + }, + AllEULAsAccepted: acceptalleulas, + SourcedItem: &types.SourcedCompositionItemParam{ + Source: &types.Reference{ + HREF: vapptemplate.VAppTemplate.Children.VM[0].HREF, + Name: vapptemplate.VAppTemplate.Children.VM[0].Name, + }, + InstantiationParams: &types.InstantiationParams{ + NetworkConnectionSection: &types.NetworkConnectionSection{ + Info: "Network config for sourced item", + PrimaryNetworkConnectionIndex: primaryNetworkConnectionIndex, + }, + }, + }, + } + for index, orgvdcnetwork := range orgvdcnetworks { + vcomp.InstantiationParams.NetworkConfigSection.NetworkConfig = append(vcomp.InstantiationParams.NetworkConfigSection.NetworkConfig, + types.VAppNetworkConfiguration{ + NetworkName: orgvdcnetwork.Name, + Configuration: &types.NetworkConfiguration{ + FenceMode: types.FenceModeBridged, + ParentNetwork: &types.Reference{ + HREF: orgvdcnetwork.HREF, + Name: orgvdcnetwork.Name, + Type: orgvdcnetwork.Type, + }, + }, + }, + ) + vcomp.SourcedItem.InstantiationParams.NetworkConnectionSection.NetworkConnection = append(vcomp.SourcedItem.InstantiationParams.NetworkConnectionSection.NetworkConnection, + &types.NetworkConnection{ + Network: orgvdcnetwork.Name, + NetworkConnectionIndex: index, + IsConnected: true, + IPAddressAllocationMode: types.IPAllocationModePool, + }, + ) + vcomp.SourcedItem.NetworkAssignment = append(vcomp.SourcedItem.NetworkAssignment, + &types.NetworkAssignment{ + InnerNetwork: orgvdcnetwork.Name, + ContainerNetwork: orgvdcnetwork.Name, + }, + ) + } + if storageprofileref.HREF != "" { + vcomp.SourcedItem.StorageProfile = &storageprofileref + } + + vdcHref, err := url.ParseRequestURI(vdc.Vdc.HREF) + if err != nil { + return Task{}, fmt.Errorf("error getting vdc href: %s", err) + } + vdcHref.Path += "/action/composeVApp" + + // Like ComposeRawVApp, this function returns a task, while it should be returning a vApp + // Since we don't use this function in terraform-provider-vcd, we are not going to + // replace it. + return vdc.client.ExecuteTaskRequest(vdcHref.String(), http.MethodPost, + types.MimeComposeVappParams, "error instantiating a new vApp: %s", vcomp) +} + // Deprecated: use vdc.GetVAppByName instead func (vdc *Vdc) FindVAppByName(vapp string) (VApp, error) { diff --git a/govcd/vdc_test.go b/govcd/vdc_test.go index fb1f096db..748c33698 100644 --- a/govcd/vdc_test.go +++ b/govcd/vdc_test.go @@ -144,6 +144,80 @@ func (vcd *TestVCD) Test_NewVdc(check *C) { } +// Tests ComposeVApp with given parameters in the config file. +// Throws an error if networks, catalog, catalog item, and +// storage preference are omitted from the config file. +func (vcd *TestVCD) Test_ComposeVApp(check *C) { + if vcd.config.VCD.Network.Net1 == "" { + check.Skip("Skipping test because no network was given") + } + if vcd.skipVappTests { + check.Skip("Skipping test because vapp wasn't properly created") + } + fmt.Printf("Running: %s\n", check.TestName()) + + // Populate OrgVDCNetwork + networks := []*types.OrgVDCNetwork{} + net, err := vcd.vdc.GetOrgVdcNetworkByName(vcd.config.VCD.Network.Net1, false) + check.Assert(err, IsNil) + networks = append(networks, net.OrgVDCNetwork) + check.Assert(err, IsNil) + // Populate Catalog + cat, err := vcd.org.GetCatalogByName(vcd.config.VCD.Catalog.Name, false) + check.Assert(err, IsNil) + check.Assert(cat, NotNil) + // Populate Catalog Item + catitem, err := cat.GetCatalogItemByName(vcd.config.VCD.Catalog.CatalogItem, false) + check.Assert(err, IsNil) + check.Assert(catitem, NotNil) + // Get VAppTemplate + vapptemplate, err := catitem.GetVAppTemplate() + check.Assert(err, IsNil) + // Get StorageProfileReference + storageprofileref, err := vcd.vdc.FindStorageProfileReference(vcd.config.VCD.StorageProfile.SP1) + check.Assert(err, IsNil) + // Compose VApp + task, err := vcd.vdc.ComposeVApp(networks, vapptemplate, storageprofileref, TestComposeVapp, TestComposeVappDesc, true) + check.Assert(err, IsNil) + check.Assert(task.Task.Tasks.Task[0].OperationName, Equals, "vdcComposeVapp") + // Get VApp + vapp, err := vcd.vdc.GetVAppByName(TestComposeVapp, true) + check.Assert(err, IsNil) + // After a successful creation, the entity is added to the cleanup list. + // If something fails after this point, the entity will be removed + AddToCleanupList(TestComposeVapp, "vapp", "", "Test_ComposeVApp") + // Once the operation is successful, we won't trigger a failure + // until after the vApp deletion + check.Check(vapp.VApp.Name, Equals, TestComposeVapp) + check.Check(vapp.VApp.Description, Equals, TestComposeVappDesc) + + vapp_status, err := vapp.GetStatus() + check.Check(err, IsNil) + check.Check(vapp_status, Equals, "UNRESOLVED") + // Let the VApp creation complete + err = task.WaitTaskCompletion() + if err != nil { + panic(err) + } + err = vapp.BlockWhileStatus("UNRESOLVED", vapp.client.MaxRetryTimeout) + check.Check(err, IsNil) + vapp_status, err = vapp.GetStatus() + check.Check(err, IsNil) + check.Check(vapp_status, Equals, "POWERED_OFF") + // Deleting VApp + task, err = vapp.Delete() + check.Assert(err, IsNil) + err = task.WaitTaskCompletion() + if err != nil { + panic(err) + } + check.Assert(err, IsNil) + noSuchVapp, err := vcd.vdc.GetVAppByName(TestComposeVapp, true) + check.Assert(err, NotNil) + check.Assert(noSuchVapp, IsNil) + +} + func (vcd *TestVCD) Test_FindVApp(check *C) { if vcd.skipVappTests {