From 43cbf6776a656d3a1d5929cab28c702af740b7f6 Mon Sep 17 00:00:00 2001 From: Dainius S Date: Wed, 13 Nov 2019 15:46:35 +0200 Subject: [PATCH 01/12] WIP --- go.mod | 1 + go.sum | 2 + govcd/api_vcd_test.go | 2 +- govcd/externalnetwork_test.go | 63 ++++++++++++++++++-- govcd/system_test.go | 107 +++++++++++++++++++++++++++++++++- types/v56/types.go | 22 +++++-- 6 files changed, 184 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 75b7f110b..653ee258f 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,7 @@ module github.com/vmware/go-vcloud-director/v2 require ( + github.com/davecgh/go-spew v1.1.1 github.com/hashicorp/go-version v1.1.0 github.com/kr/pretty v0.1.0 // indirect gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 diff --git a/go.sum b/go.sum index 91cfce57f..bb14533fc 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/hashicorp/go-version v1.1.0 h1:bPIoEKD27tNdebFGGxxYwcL4nepeY4j1QP23PFRGzg0= github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= diff --git a/govcd/api_vcd_test.go b/govcd/api_vcd_test.go index 9601af0b6..61db9f284 100644 --- a/govcd/api_vcd_test.go +++ b/govcd/api_vcd_test.go @@ -468,7 +468,7 @@ func (vcd *TestVCD) SetUpSuite(check *C) { } } else { vcd.skipVappTests = true - fmt.Printf("Skipping all vapp tests because one of the following wasn't given: Network, StorageProfile, Catalog, Catalogitem") + fmt.Println("Skipping all vapp tests because one of the following wasn't given: Network, StorageProfile, Catalog, Catalogitem") } } diff --git a/govcd/externalnetwork_test.go b/govcd/externalnetwork_test.go index ac78eb6ca..ca35759fc 100644 --- a/govcd/externalnetwork_test.go +++ b/govcd/externalnetwork_test.go @@ -89,7 +89,33 @@ func (vcd *TestVCD) testCreateExternalNetwork(testName, networkName, dnsSuffix s IPRange: []*types.IPRange{ &types.IPRange{ StartAddress: "192.168.201.3", - EndAddress: "192.168.201.250", + EndAddress: "192.168.201.100", + }, + &types.IPRange{ + StartAddress: "192.168.201.105", + EndAddress: "192.168.201.140", + }, + }, + }, + }, &types.IPScope{ + Gateway: "192.168.231.1", + Netmask: "255.255.255.0", + DNS1: "192.168.232.253", + DNS2: "192.168.232.254", + DNSSuffix: dnsSuffix, + IPRanges: &types.IPRanges{ + IPRange: []*types.IPRange{ + &types.IPRange{ + StartAddress: "192.168.231.3", + EndAddress: "192.168.231.100", + }, + &types.IPRange{ + StartAddress: "192.168.231.105", + EndAddress: "192.168.231.140", + }, + &types.IPRange{ + StartAddress: "192.168.231.145", + EndAddress: "192.168.231.150", }, }, }, @@ -183,16 +209,41 @@ func (vcd *TestVCD) Test_CreateExternalNetwork(check *C) { check.Assert(newExternalNetwork.ExternalNetwork.Name, Equals, TestCreateExternalNetwork) ipScope := newExternalNetwork.ExternalNetwork.Configuration.IPScopes.IPScope + check.Assert(len(ipScope), Equals, 2) + // Check IPScope 1 check.Assert(ipScope[0].Gateway, Equals, "192.168.201.1") check.Assert(ipScope[0].Netmask, Equals, "255.255.255.0") check.Assert(ipScope[0].DNS1, Equals, "192.168.202.253") check.Assert(ipScope[0].DNS2, Equals, "192.168.202.254") check.Assert(ipScope[0].DNSSuffix, Equals, dnsSuffix) - - check.Assert(len(ipScope[0].IPRanges.IPRange), Equals, 1) - ipRange := ipScope[0].IPRanges.IPRange[0] - check.Assert(ipRange.StartAddress, Equals, "192.168.201.3") - check.Assert(ipRange.EndAddress, Equals, "192.168.201.250") + // Check IPScope 2 + check.Assert(ipScope[1].Gateway, Equals, "192.168.231.1") + check.Assert(ipScope[1].Netmask, Equals, "255.255.255.0") + check.Assert(ipScope[1].DNS1, Equals, "192.168.232.253") + check.Assert(ipScope[1].DNS2, Equals, "192.168.232.254") + check.Assert(ipScope[1].DNSSuffix, Equals, dnsSuffix) + // Check IP ranges on IPScope 1 + check.Assert(len(ipScope[0].IPRanges.IPRange), Equals, 2) + ipRange1 := ipScope[0].IPRanges.IPRange[0] + check.Assert(ipRange1.StartAddress, Equals, "192.168.201.3") + check.Assert(ipRange1.EndAddress, Equals, "192.168.201.100") + + ipRange2 := ipScope[0].IPRanges.IPRange[1] + check.Assert(ipRange2.StartAddress, Equals, "192.168.201.105") + check.Assert(ipRange2.EndAddress, Equals, "192.168.201.140") + + // Check IP ranges on IPScope 2 + ipRange1 = ipScope[1].IPRanges.IPRange[0] + check.Assert(ipRange1.StartAddress, Equals, "192.168.231.3") + check.Assert(ipRange1.EndAddress, Equals, "192.168.231.100") + + ipRange2 = ipScope[1].IPRanges.IPRange[1] + check.Assert(ipRange2.StartAddress, Equals, "192.168.231.105") + check.Assert(ipRange2.EndAddress, Equals, "192.168.231.140") + + ipRange3 := ipScope[1].IPRanges.IPRange[2] + check.Assert(ipRange3.StartAddress, Equals, "192.168.231.145") + check.Assert(ipRange3.EndAddress, Equals, "192.168.231.150") check.Assert(newExternalNetwork.ExternalNetwork.Configuration.FenceMode, Equals, "isolated") check.Assert(newExternalNetwork.ExternalNetwork.Description, Equals, "Test Create External Network") diff --git a/govcd/system_test.go b/govcd/system_test.go index 18ec0c1e9..4ce4257f7 100644 --- a/govcd/system_test.go +++ b/govcd/system_test.go @@ -8,6 +8,7 @@ package govcd import ( "fmt" + "time" . "gopkg.in/check.v1" @@ -221,11 +222,115 @@ func (vcd *TestVCD) Test_CreateDeleteEdgeGateway(check *C) { // Once deleted, look for the edge gateway again. It should return an error newEdge, err := vcd.vdc.GetEdgeGatewayByName(egc.Name, true) - check.Assert(err, NotNil) + check.Assert(err, Equals, ErrorEntityNotFound) check.Assert(newEdge, IsNil) } } +// Test_CreateDeleteEdgeGatewayAdvanced sets up external network which has multiple IP scopes and IP +// ranges defined. This helps to test edge gateway capabilities for multiple networks and scopes +func (vcd *TestVCD) Test_CreateDeleteEdgeGatewayAdvanced(check *C) { + // Setup external network with multiple IP scopes and multiple ranges + dnsSuffix := "some.net" + skippingReason, externalNetwork, task, err := vcd.testCreateExternalNetwork(check.TestName(), check.TestName(), dnsSuffix) + if skippingReason != "" { + check.Skip(skippingReason) + } + + check.Assert(err, IsNil) + check.Assert(task.Task, Not(Equals), types.Task{}) + + AddToCleanupList(externalNetwork.Name, "externalNetwork", "", check.TestName()) + err = task.WaitTaskCompletion() + check.Assert(err, IsNil) + + // "Refresh" external network to fill in all fields (like HREF) + extNet, err := vcd.client.GetExternalNetworkByName(externalNetwork.Name) + check.Assert(err, IsNil) + externalNetwork = extNet.ExternalNetwork + + edgeName := "Test-Multi-Scope-Gw" + // Initialize edge gateway structure + edgeGatewayConfig := &types.EdgeGateway{ + Xmlns: types.XMLNamespaceVCloud, + Name: edgeName, + Description: edgeName, + Configuration: &types.GatewayConfiguration{ + HaEnabled: false, + GatewayBackingConfig: "compact", + GatewayInterfaces: &types.GatewayInterfaces{ + GatewayInterface: []*types.GatewayInterface{}, + }, + AdvancedNetworkingEnabled: true, + DistributedRoutingEnabled: false, + FipsModeEnabled: takeBoolPointer(false), + UseDefaultRouteForDNSRelay: true, + }, + } + + // Create subnet participation structure + subnetParticipation := make([]*types.SubnetParticipation, len(externalNetwork.Configuration.IPScopes.IPScope)) + // Loop over IP scopes + for ipScopeIndex, ipScope := range externalNetwork.Configuration.IPScopes.IPScope { + subnetParticipation[ipScopeIndex] = &types.SubnetParticipation{ + Gateway: ipScope.Gateway, + Netmask: ipScope.Netmask, + // IPAddress: string, // Can be set to specify IP address of edge gateway + // UseForDefaultRoute: bool, // Can be specified to use subnet as default gateway + IPRanges: &types.IPRanges{}, + } + } + + // Set static IP assignment + subnetParticipation[0].IPAddress = "192.168.201.100" + + // Set default gateway subnet + subnetParticipation[1].UseForDefaultRoute = true + + // Inject an IP range (in UI it is called "sub-allocated pools" in separate tab) + subnetParticipation[0].IPRanges = &types.IPRanges{ + IPRange: []*types.IPRange{ + &types.IPRange{ + StartAddress: "192.168.201.120", + EndAddress: "192.168.201.130", + }, + }, + } + + // Setup network interface config + networkConf := &types.GatewayInterface{ + Name: externalNetwork.Name, + DisplayName: externalNetwork.Name, + InterfaceType: "uplink", + Network: &types.Reference{ + HREF: externalNetwork.HREF, + ID: externalNetwork.ID, + Type: "application/vnd.vmware.admin.network+xml", + Name: externalNetwork.Name, + }, + UseForDefaultRoute: true, + SubnetParticipation: subnetParticipation, + } + + edgeGatewayConfig.Configuration.GatewayInterfaces.GatewayInterface = + append(edgeGatewayConfig.Configuration.GatewayInterfaces.GatewayInterface, networkConf) + + orgName := vcd.config.VCD.Org + vdcName := vcd.config.VCD.Vdc + + edge, err := CreateAndConfigureEdgeGateway(vcd.client, orgName, vdcName, edgeName, edgeGatewayConfig) + check.Assert(err, IsNil) + PrependToCleanupList(edge.EdgeGateway.Name, "edgegateway", orgName+"|"+vdcName, "Test_CreateDeleteEdgeGateway") + + // validate edge GW stuff + + time.Sleep(3 * time.Minute) +} + +func takeBoolPointer(value bool) *bool { + return &value +} + func (vcd *TestVCD) Test_FindBadlyNamedStorageProfile(check *C) { reNotFound := `can't find any VDC Storage_profiles` _, err := vcd.vdc.FindStorageProfileReference("name with spaces") diff --git a/types/v56/types.go b/types/v56/types.go index aa434921c..cc137ab8f 100644 --- a/types/v56/types.go +++ b/types/v56/types.go @@ -1570,10 +1570,19 @@ type GatewayConfiguration struct { GatewayBackingConfig string `xml:"GatewayBackingConfig"` // Configuration of the vShield edge VM for this gateway. One of: compact, full. GatewayInterfaces *GatewayInterfaces `xml:"GatewayInterfaces"` // List of Gateway interfaces. EdgeGatewayServiceConfiguration *GatewayFeatures `xml:"EdgeGatewayServiceConfiguration,omitempty"` // Represents Gateway Features. - HaEnabled bool `xml:"HaEnabled,omitempty"` // True if this gateway is highly available. (Requires two vShield edge VMs.) - AdvancedNetworkingEnabled bool `xml:"AdvancedNetworkingEnabled,omitempty"` // True if the gateway uses advanced networking - DistributedRoutingEnabled bool `xml:"DistributedRoutingEnabled,omitempty"` // True if gateway is attached to a Distributed Logical Router - UseDefaultRouteForDNSRelay bool `xml:"UseDefaultRouteForDnsRelay,omitempty"` // True if the default gateway on the external network selected for default route should be used as the DNS relay. + // True if this gateway is highly available. (Requires two vShield edge VMs.) + HaEnabled bool `xml:"HaEnabled,omitempty"` + // True if the default gateway on the external network selected for default route should be used + // as the DNS relay. + UseDefaultRouteForDNSRelay bool `xml:"UseDefaultRouteForDnsRelay,omitempty"` + AdvancedNetworkingEnabled bool `xml:"AdvancedNetworkingEnabled,omitempty"` // True if the gateway uses advanced networking + //Enable Distributed Routing on the gateway to allow creation of many more organization VDC + //networks. Traffic in those networks is optimized for VM-to-VM communication. + DistributedRoutingEnabled bool `xml:"DistributedRoutingEnabled,omitempty"` + // FipsModeEnabled allows any secure communication to or from the NSX Edge uses cryptographic + // algorithms or protocols that are allowed by United States Federal Information Processing + // Standards (FIPS). FIPS mode turns on the cipher suites that comply with FIPS. + FipsModeEnabled *bool `xml:"FipsModeEnabled,omitempty"` } // GatewayInterfaces is a list of Gateway Interfaces. @@ -1607,11 +1616,14 @@ type GatewayInterface struct { // Namespace: http://www.vmware.com/vcloud/v1.5 // Description: Allows to chose which subnets a gateway can be part of // Since: 5.1 +// +// Note. Field order is important and should not be changed as API returns errors if IPRanges come +// before Gateway and Netmask type SubnetParticipation struct { Gateway string `xml:"Gateway"` // Gateway for subnet + Netmask string `xml:"Netmask"` // Netmask for the subnet. IPAddress string `xml:"IpAddress,omitempty"` // Ip Address to be assigned. Keep empty or omit element for auto assignment IPRanges *IPRanges `xml:"IpRanges,omitempty"` // Range of IP addresses available for external interfaces. - Netmask string `xml:"Netmask"` // Netmask for the subnet UseForDefaultRoute bool `xml:"UseForDefaultRoute,omitempty"` // True if this network is default route for the gateway. } From 5c4a3f237643683367c678d1479a2eaa7bfe8b75 Mon Sep 17 00:00:00 2001 From: Dainius S Date: Mon, 18 Nov 2019 21:10:08 +0200 Subject: [PATCH 02/12] Cleanup tests, patch things --- govcd/edgegateway.go | 4 +++- govcd/system.go | 6 +++--- govcd/system_test.go | 36 +++++++++++++++++++++++++++++------- types/v56/types.go | 36 ++++++++++++++++++++++++++---------- 4 files changed, 61 insertions(+), 21 deletions(-) diff --git a/govcd/edgegateway.go b/govcd/edgegateway.go index bdd195162..02f1adef8 100644 --- a/govcd/edgegateway.go +++ b/govcd/edgegateway.go @@ -1059,7 +1059,9 @@ func (egw *EdgeGateway) HasDefaultGateway() bool { // HasAdvancedNetworking returns true if the edge gateway has advanced network configuration enabled func (egw *EdgeGateway) HasAdvancedNetworking() bool { - return egw.EdgeGateway.Configuration != nil && egw.EdgeGateway.Configuration.AdvancedNetworkingEnabled + return egw.EdgeGateway.Configuration != nil && + egw.EdgeGateway.Configuration.AdvancedNetworkingEnabled != nil && + *egw.EdgeGateway.Configuration.AdvancedNetworkingEnabled } // buildProxiedEdgeEndpointURL helps to get root endpoint for Edge Gateway using the diff --git a/govcd/system.go b/govcd/system.go index 578de301a..a912f65fd 100644 --- a/govcd/system.go +++ b/govcd/system.go @@ -128,10 +128,10 @@ func CreateEdgeGatewayAsync(vcdClient *VCDClient, egwc EdgeGatewayCreation) (Tas Name: egwc.Name, Description: egwc.Description, Configuration: &types.GatewayConfiguration{ - UseDefaultRouteForDNSRelay: egwc.UseDefaultRouteForDNSRelay, - HaEnabled: egwc.HAEnabled, + UseDefaultRouteForDNSRelay: &egwc.UseDefaultRouteForDNSRelay, + HaEnabled: &egwc.HAEnabled, GatewayBackingConfig: egwc.BackingConfiguration, - AdvancedNetworkingEnabled: egwc.AdvancedNetworkingEnabled, + AdvancedNetworkingEnabled: &egwc.AdvancedNetworkingEnabled, DistributedRoutingEnabled: &distributed, GatewayInterfaces: &types.GatewayInterfaces{ GatewayInterface: []*types.GatewayInterface{}, diff --git a/govcd/system_test.go b/govcd/system_test.go index 4ce4257f7..649dd6a99 100644 --- a/govcd/system_test.go +++ b/govcd/system_test.go @@ -8,7 +8,6 @@ package govcd import ( "fmt" - "time" . "gopkg.in/check.v1" @@ -256,15 +255,15 @@ func (vcd *TestVCD) Test_CreateDeleteEdgeGatewayAdvanced(check *C) { Name: edgeName, Description: edgeName, Configuration: &types.GatewayConfiguration{ - HaEnabled: false, + HaEnabled: takeBoolPointer(false), GatewayBackingConfig: "compact", GatewayInterfaces: &types.GatewayInterfaces{ GatewayInterface: []*types.GatewayInterface{}, }, - AdvancedNetworkingEnabled: true, - DistributedRoutingEnabled: false, + AdvancedNetworkingEnabled: takeBoolPointer(true), + DistributedRoutingEnabled: takeBoolPointer(false), FipsModeEnabled: takeBoolPointer(false), - UseDefaultRouteForDNSRelay: true, + UseDefaultRouteForDNSRelay: takeBoolPointer(true), }, } @@ -322,9 +321,32 @@ func (vcd *TestVCD) Test_CreateDeleteEdgeGatewayAdvanced(check *C) { check.Assert(err, IsNil) PrependToCleanupList(edge.EdgeGateway.Name, "edgegateway", orgName+"|"+vdcName, "Test_CreateDeleteEdgeGateway") - // validate edge GW stuff + // Patch known differences for comparison deep comparison + edgeGatewayConfig.Configuration.GatewayInterfaces.GatewayInterface[0].SubnetParticipation[1].IPAddress = "192.168.231.3" + edgeGatewayConfig.Configuration.GatewayInterfaces.GatewayInterface[0].Network.HREF = + edge.EdgeGateway.Configuration.GatewayInterfaces.GatewayInterface[0].Network.HREF + + // Sort gateway interfaces so that comparison is easier + edgeGatewayConfig.Configuration.GatewayInterfaces.GatewayInterface[0].SortBySubnetParticipationGateway() + edge.EdgeGateway.Configuration.GatewayInterfaces.GatewayInterface[0].SortBySubnetParticipationGateway() + + check.Assert(edge.EdgeGateway.Configuration.GatewayInterfaces.GatewayInterface[0], DeepEquals, + edgeGatewayConfig.Configuration.GatewayInterfaces.GatewayInterface[0]) + check.Assert(edge.EdgeGateway.Configuration.DistributedRoutingEnabled, NotNil) + check.Assert(*edge.EdgeGateway.Configuration.DistributedRoutingEnabled, Equals, false) + + // FIPS mode is not being returned from API (neither when it is enabled, nor when disabled), but + // does allow to turn it on. + // check.Assert(edge.EdgeGateway.Configuration.FipsModeEnabled, NotNil) + // check.Assert(*edge.EdgeGateway.Configuration.FipsModeEnabled, Equals, true) + + check.Assert(edge.EdgeGateway.Configuration.AdvancedNetworkingEnabled, NotNil) + check.Assert(*edge.EdgeGateway.Configuration.AdvancedNetworkingEnabled, Equals, true) + check.Assert(edge.EdgeGateway.Configuration.UseDefaultRouteForDNSRelay, NotNil) + check.Assert(*edge.EdgeGateway.Configuration.UseDefaultRouteForDNSRelay, Equals, true) + check.Assert(edge.EdgeGateway.Configuration.HaEnabled, NotNil) + check.Assert(*edge.EdgeGateway.Configuration.HaEnabled, Equals, false) - time.Sleep(3 * time.Minute) } func takeBoolPointer(value bool) *bool { diff --git a/types/v56/types.go b/types/v56/types.go index 88e976818..72c54dc1c 100644 --- a/types/v56/types.go +++ b/types/v56/types.go @@ -1567,17 +1567,26 @@ type EdgeGateway struct { // Since: 5.1 type GatewayConfiguration struct { Xmlns string `xml:"xmlns,attr,omitempty"` - // Elements - BackwardCompatibilityMode bool `xml:"BackwardCompatibilityMode,omitempty"` // Compatibility mode. Default is false. If set to true, will allow users to write firewall rules in the old 1.5 format. The new format does not require to use direction in firewall rules. Also, for firewall rules to allow NAT traffic the filter is applied on the original IP addresses. Once set to true cannot be reverted back to false. - GatewayBackingConfig string `xml:"GatewayBackingConfig"` // Configuration of the vShield edge VM for this gateway. One of: compact, full. - GatewayInterfaces *GatewayInterfaces `xml:"GatewayInterfaces"` // List of Gateway interfaces. - EdgeGatewayServiceConfiguration *GatewayFeatures `xml:"EdgeGatewayServiceConfiguration,omitempty"` // Represents Gateway Features. + // BackwardCompatibilityMode. Default is false. If set to true, will allow users to write firewall + // rules in the old 1.5 format. The new format does not require to use direction in firewall + // rules. Also, for firewall rules to allow NAT traffic the filter is applied on the original IP + // addresses. Once set to true cannot be reverted back to false. + BackwardCompatibilityMode bool `xml:"BackwardCompatibilityMode,omitempty"` + // GatewayBackingConfig defines configuration of the vShield edge VM for this gateway. One of: + // compact, full. + GatewayBackingConfig string `xml:"GatewayBackingConfig"` + // GatewayInterfaces holds configuration for + GatewayInterfaces *GatewayInterfaces `xml:"GatewayInterfaces"` + // EdgeGatewayServiceConfiguration represents Gateway Features. + EdgeGatewayServiceConfiguration *GatewayFeatures `xml:"EdgeGatewayServiceConfiguration,omitempty"` // True if this gateway is highly available. (Requires two vShield edge VMs.) - HaEnabled bool `xml:"HaEnabled,omitempty"` - // True if the default gateway on the external network selected for default route should be used - // as the DNS relay. - UseDefaultRouteForDNSRelay bool `xml:"UseDefaultRouteForDnsRelay,omitempty"` - AdvancedNetworkingEnabled bool `xml:"AdvancedNetworkingEnabled,omitempty"` // True if the gateway uses advanced networking + HaEnabled *bool `xml:"HaEnabled,omitempty"` + // UseDefaultRouteForDNSRelay defines if the default gateway on the external network selected + // for default route should be used as the DNS relay. + UseDefaultRouteForDNSRelay *bool `xml:"UseDefaultRouteForDnsRelay,omitempty"` + // AdvancedNetworkingEnabled allows to use NSX capabilities such dynamic routing (BGP, OSPF), + // zero trust networking (DLR), enchanced VPN support (IPsec VPN, SSL VPN-Plus). + AdvancedNetworkingEnabled *bool `xml:"AdvancedNetworkingEnabled,omitempty"` // DistributedRoutingEnabled enables distributed routing on the gateway to allow creation of // many more organization VDC networks. Traffic in those networks is optimized for VM-to-VM // communication. @@ -1614,6 +1623,13 @@ type GatewayInterface struct { UseForDefaultRoute bool `xml:"UseForDefaultRoute,omitempty"` // True if this network is default route for the gateway. } +// SortByGateway allows to sort SubnetParticipation property slice by gateway +func (g *GatewayInterface) SortBySubnetParticipationGateway() { + sort.SliceStable(g.SubnetParticipation, func(i, j int) bool { + return g.SubnetParticipation[i].Gateway < g.SubnetParticipation[j].Gateway + }) +} + // SubnetParticipation allows to chose which subnets a gateway can be a part of // Type: SubnetParticipationType // Namespace: http://www.vmware.com/vcloud/v1.5 From 59580b1db944eb1c96ae3f0cc7d8f1c6f64269c7 Mon Sep 17 00:00:00 2001 From: Dainius S Date: Mon, 18 Nov 2019 21:46:20 +0200 Subject: [PATCH 03/12] Cleanup go.mod --- go.mod | 1 - go.sum | 2 -- 2 files changed, 3 deletions(-) diff --git a/go.mod b/go.mod index 653ee258f..75b7f110b 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,6 @@ module github.com/vmware/go-vcloud-director/v2 require ( - github.com/davecgh/go-spew v1.1.1 github.com/hashicorp/go-version v1.1.0 github.com/kr/pretty v0.1.0 // indirect gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 diff --git a/go.sum b/go.sum index bb14533fc..91cfce57f 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,3 @@ -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/hashicorp/go-version v1.1.0 h1:bPIoEKD27tNdebFGGxxYwcL4nepeY4j1QP23PFRGzg0= github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= From bed932a42c3d3fb54b214b8b8d45616d13044f9f Mon Sep 17 00:00:00 2001 From: Dainius S Date: Tue, 19 Nov 2019 09:29:43 +0200 Subject: [PATCH 04/12] Cleanup tests --- govcd/metadata_test.go | 4 ---- govcd/system_test.go | 9 ++++++++- govcd/vapp_test.go | 24 +++++++++--------------- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/govcd/metadata_test.go b/govcd/metadata_test.go index 0df15e757..e494a1346 100644 --- a/govcd/metadata_test.go +++ b/govcd/metadata_test.go @@ -130,8 +130,6 @@ func (vcd *TestVCD) Test_AddMetadataOnVm(check *C) { check.Skip("skipping test because no VM is found") } - fmt.Printf("Running: %s\n", check.TestName()) - vm := NewVM(&vcd.client.Client) vm.VM = &vmType @@ -164,8 +162,6 @@ func (vcd *TestVCD) Test_DeleteMetadataOnVm(check *C) { check.Skip("skipping test because no VM is found") } - fmt.Printf("Running: %s\n", check.TestName()) - vm := NewVM(&vcd.client.Client) vm.VM = &vmType diff --git a/govcd/system_test.go b/govcd/system_test.go index 649dd6a99..dbbe6787b 100644 --- a/govcd/system_test.go +++ b/govcd/system_test.go @@ -202,7 +202,8 @@ func (vcd *TestVCD) Test_CreateDeleteEdgeGateway(check *C) { // -1 : creation error check.Assert(edge.EdgeGateway.Status, Equals, 1) - check.Assert(edge.EdgeGateway.Configuration.AdvancedNetworkingEnabled, Equals, true) + check.Assert(edge.EdgeGateway.Configuration.AdvancedNetworkingEnabled, NotNil) + check.Assert(*edge.EdgeGateway.Configuration.AdvancedNetworkingEnabled, Equals, true) util.Logger.Printf("Edge Gateway:\n%s\n", prettyEdgeGateway(*edge.EdgeGateway)) check.Assert(edge.HasDefaultGateway(), Equals, builtWithDefaultGateway) @@ -347,6 +348,12 @@ func (vcd *TestVCD) Test_CreateDeleteEdgeGatewayAdvanced(check *C) { check.Assert(edge.EdgeGateway.Configuration.HaEnabled, NotNil) check.Assert(*edge.EdgeGateway.Configuration.HaEnabled, Equals, false) + // Remove created objects to free them up + err = edge.Delete(true, false) + check.Assert(err, IsNil) + + err = extNet.DeleteWait() + check.Assert(err, IsNil) } func takeBoolPointer(value bool) *bool { diff --git a/govcd/vapp_test.go b/govcd/vapp_test.go index 373c5a689..ba5a4c706 100644 --- a/govcd/vapp_test.go +++ b/govcd/vapp_test.go @@ -646,21 +646,15 @@ func (vcd *TestVCD) Test_RemoveAllNetworks(check *C) { } vappNetworkSettings2 := &VappNetworkSettings{ - Name: networkName2, - Gateway: gateway, - NetMask: netmask, - DNS1: dns1, - DNS2: dns2, - DNSSuffix: dnsSuffix, - StaticIPRanges: []*types.IPRange{{StartAddress: startAddress, EndAddress: endAddress}}, - DhcpSettings: &DhcpSettings{IsEnabled: true, MaxLeaseTime: maxLeaseTime, DefaultLeaseTime: defaultLeaseTime, IPRange: &types.IPRange{StartAddress: dhcpStartAddress, EndAddress: dhcpEndAddress}}, - } - - // vCD 8.20 does not support sending guestVlanAllowed - if vcd.client.APIVCDMaxVersionIs("> 27.0") { - vappNetworkSettings.GuestVLANAllowed = &guestVlanAllowed - } else { - fmt.Printf("Skipping GuestVLANAllowed parameter as it is not supported on vCD 8.20") + Name: networkName2, + Gateway: gateway, + NetMask: netmask, + DNS1: dns1, + DNS2: dns2, + DNSSuffix: dnsSuffix, + StaticIPRanges: []*types.IPRange{{StartAddress: startAddress, EndAddress: endAddress}}, + DhcpSettings: &DhcpSettings{IsEnabled: true, MaxLeaseTime: maxLeaseTime, DefaultLeaseTime: defaultLeaseTime, IPRange: &types.IPRange{StartAddress: dhcpStartAddress, EndAddress: dhcpEndAddress}}, + GuestVLANAllowed: &guestVlanAllowed, } task, err := vcd.vapp.AddIsolatedNetwork(vappNetworkSettings) From 15d8265bdee656f91941d5f250b93b338f3c82a2 Mon Sep 17 00:00:00 2001 From: Dainius S Date: Tue, 19 Nov 2019 10:07:04 +0200 Subject: [PATCH 05/12] Fix doc typo and add changelog notes --- CHANGELOG.md | 8 +++++++- types/v56/types.go | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25b971f5c..01afd2fc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,13 @@ * Increment vCD API version used from 27.0 to 29.0 * Remove fields `VdcEnabled`, `VAppParentHREF`, `VAppParentName`, `HighestSupportedVersion`, `VmToolsVersion`, `TaskHREF`, `TaskStatusName`, `TaskDetails`, `TaskStatus` from `QueryResultVMRecordType` * Add fields `ID, Type, ContainerName, ContainerID, OwnerName, Owner, NetworkHref, IpAddress, CatalogName, VmToolsStatus, GcStatus, AutoUndeployDate, AutoDeleteDate, AutoUndeployNotified, AutoDeleteNotified, Link, MetaData` to `QueryResultVMRecordType`, `DistributedInterface` to `NetworkConfiguration` and `RegenerateBiosUuid` to `VMGeneralParams` - * Change to pointers `DistributedRoutingEnabled` in `GatewayConfiguration` and `DistributedInterface` in `NetworkConfiguration` + * Change to pointers `DistributedRoutingEnabled` in `GatewayConfiguration` and + `DistributedInterface` in `NetworkConfiguration` +* Add news fields to type `GatewayConfiguration`: `FipsModeEnabled` - + [#267](https://github.com/vmware/go-vcloud-director/pull/267) +* Change bool to bool pointer for fields in type `GatewayConfiguration`: `HaEnabled`, + `UseDefaultRouteForDNSRelay`, `AdvancedNetworkingEnabled` - + [#267](https://github.com/vmware/go-vcloud-director/pull/267) BUGS FIXED: diff --git a/types/v56/types.go b/types/v56/types.go index 72c54dc1c..398d66627 100644 --- a/types/v56/types.go +++ b/types/v56/types.go @@ -1623,7 +1623,8 @@ type GatewayInterface struct { UseForDefaultRoute bool `xml:"UseForDefaultRoute,omitempty"` // True if this network is default route for the gateway. } -// SortByGateway allows to sort SubnetParticipation property slice by gateway +// SortBySubnetParticipationGateway allows to sort SubnetParticipation property slice by gateway +// address func (g *GatewayInterface) SortBySubnetParticipationGateway() { sort.SliceStable(g.SubnetParticipation, func(i, j int) bool { return g.SubnetParticipation[i].Gateway < g.SubnetParticipation[j].Gateway From 03c56a5bcd6182787447cec4c245424287091f13 Mon Sep 17 00:00:00 2001 From: Dainius S Date: Tue, 19 Nov 2019 10:08:04 +0200 Subject: [PATCH 06/12] changelog syntax --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01afd2fc8..20633ff68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ * Remove fields `VdcEnabled`, `VAppParentHREF`, `VAppParentName`, `HighestSupportedVersion`, `VmToolsVersion`, `TaskHREF`, `TaskStatusName`, `TaskDetails`, `TaskStatus` from `QueryResultVMRecordType` * Add fields `ID, Type, ContainerName, ContainerID, OwnerName, Owner, NetworkHref, IpAddress, CatalogName, VmToolsStatus, GcStatus, AutoUndeployDate, AutoDeleteDate, AutoUndeployNotified, AutoDeleteNotified, Link, MetaData` to `QueryResultVMRecordType`, `DistributedInterface` to `NetworkConfiguration` and `RegenerateBiosUuid` to `VMGeneralParams` * Change to pointers `DistributedRoutingEnabled` in `GatewayConfiguration` and - `DistributedInterface` in `NetworkConfiguration` + `DistributedInterface` in `NetworkConfiguration` * Add news fields to type `GatewayConfiguration`: `FipsModeEnabled` - [#267](https://github.com/vmware/go-vcloud-director/pull/267) * Change bool to bool pointer for fields in type `GatewayConfiguration`: `HaEnabled`, From 68c35eda6304182081683ce492bc8422af4c8a1d Mon Sep 17 00:00:00 2001 From: Dainius S Date: Tue, 19 Nov 2019 14:05:04 +0200 Subject: [PATCH 07/12] Add subnet ordering in test --- govcd/system_test.go | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/govcd/system_test.go b/govcd/system_test.go index dbbe6787b..33b629d27 100644 --- a/govcd/system_test.go +++ b/govcd/system_test.go @@ -281,22 +281,6 @@ func (vcd *TestVCD) Test_CreateDeleteEdgeGatewayAdvanced(check *C) { } } - // Set static IP assignment - subnetParticipation[0].IPAddress = "192.168.201.100" - - // Set default gateway subnet - subnetParticipation[1].UseForDefaultRoute = true - - // Inject an IP range (in UI it is called "sub-allocated pools" in separate tab) - subnetParticipation[0].IPRanges = &types.IPRanges{ - IPRange: []*types.IPRange{ - &types.IPRange{ - StartAddress: "192.168.201.120", - EndAddress: "192.168.201.130", - }, - }, - } - // Setup network interface config networkConf := &types.GatewayInterface{ Name: externalNetwork.Name, @@ -312,6 +296,23 @@ func (vcd *TestVCD) Test_CreateDeleteEdgeGatewayAdvanced(check *C) { SubnetParticipation: subnetParticipation, } + // Sort by subnet participation gateway so that below injected variables are not being added to + // incorrect network + networkConf.SortBySubnetParticipationGateway() + // Set static IP assignment + networkConf.SubnetParticipation[0].IPAddress = "192.168.201.100" + // Set default gateway subnet + networkConf.SubnetParticipation[1].UseForDefaultRoute = true + // Inject an IP range (in UI it is called "sub-allocated pools" in separate tab) + networkConf.SubnetParticipation[0].IPRanges = &types.IPRanges{ + IPRange: []*types.IPRange{ + &types.IPRange{ + StartAddress: "192.168.201.120", + EndAddress: "192.168.201.130", + }, + }, + } + edgeGatewayConfig.Configuration.GatewayInterfaces.GatewayInterface = append(edgeGatewayConfig.Configuration.GatewayInterfaces.GatewayInterface, networkConf) From 00d2d4f242876164e5f0946e85a8c5e8a0ed5a0e Mon Sep 17 00:00:00 2001 From: Dainius S Date: Tue, 19 Nov 2019 15:11:03 +0200 Subject: [PATCH 08/12] sort IP scopes in external network --- govcd/externalnetwork_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/govcd/externalnetwork_test.go b/govcd/externalnetwork_test.go index ca35759fc..c858db890 100644 --- a/govcd/externalnetwork_test.go +++ b/govcd/externalnetwork_test.go @@ -9,6 +9,7 @@ package govcd import ( "fmt" "net/url" + "sort" . "gopkg.in/check.v1" @@ -209,6 +210,13 @@ func (vcd *TestVCD) Test_CreateExternalNetwork(check *C) { check.Assert(newExternalNetwork.ExternalNetwork.Name, Equals, TestCreateExternalNetwork) ipScope := newExternalNetwork.ExternalNetwork.Configuration.IPScopes.IPScope + + // Sort returned IP scopes by gateway because API is not guaranteed to return it in the same + // order + sort.SliceStable(ipScope, func(i, j int) bool { + return ipScope[i].Gateway < ipScope[j].Gateway + }) + check.Assert(len(ipScope), Equals, 2) // Check IPScope 1 check.Assert(ipScope[0].Gateway, Equals, "192.168.201.1") From 2c1c2c2ae71c8a0230f0b3d62cd4a8d6f390799c Mon Sep 17 00:00:00 2001 From: Dainius S Date: Tue, 19 Nov 2019 15:17:02 +0200 Subject: [PATCH 09/12] Fix typo in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20633ff68..3b88b1513 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ * Add fields `ID, Type, ContainerName, ContainerID, OwnerName, Owner, NetworkHref, IpAddress, CatalogName, VmToolsStatus, GcStatus, AutoUndeployDate, AutoDeleteDate, AutoUndeployNotified, AutoDeleteNotified, Link, MetaData` to `QueryResultVMRecordType`, `DistributedInterface` to `NetworkConfiguration` and `RegenerateBiosUuid` to `VMGeneralParams` * Change to pointers `DistributedRoutingEnabled` in `GatewayConfiguration` and `DistributedInterface` in `NetworkConfiguration` -* Add news fields to type `GatewayConfiguration`: `FipsModeEnabled` - +* Add new fields to type `GatewayConfiguration`: `FipsModeEnabled` - [#267](https://github.com/vmware/go-vcloud-director/pull/267) * Change bool to bool pointer for fields in type `GatewayConfiguration`: `HaEnabled`, `UseDefaultRouteForDNSRelay`, `AdvancedNetworkingEnabled` - From 9bc46fb8410bfca436a20bd2ef13a754e71cd4d1 Mon Sep 17 00:00:00 2001 From: Dainius S Date: Tue, 19 Nov 2019 17:41:42 +0200 Subject: [PATCH 10/12] Fix typo in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b88b1513..a464195c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ * Add fields `ID, Type, ContainerName, ContainerID, OwnerName, Owner, NetworkHref, IpAddress, CatalogName, VmToolsStatus, GcStatus, AutoUndeployDate, AutoDeleteDate, AutoUndeployNotified, AutoDeleteNotified, Link, MetaData` to `QueryResultVMRecordType`, `DistributedInterface` to `NetworkConfiguration` and `RegenerateBiosUuid` to `VMGeneralParams` * Change to pointers `DistributedRoutingEnabled` in `GatewayConfiguration` and `DistributedInterface` in `NetworkConfiguration` -* Add new fields to type `GatewayConfiguration`: `FipsModeEnabled` - +* Add new field to type `GatewayConfiguration`: `FipsModeEnabled` - [#267](https://github.com/vmware/go-vcloud-director/pull/267) * Change bool to bool pointer for fields in type `GatewayConfiguration`: `HaEnabled`, `UseDefaultRouteForDNSRelay`, `AdvancedNetworkingEnabled` - From 5d99e3d9e134be8764d5e69ae749a85fc445c58f Mon Sep 17 00:00:00 2001 From: Dainius S Date: Wed, 20 Nov 2019 15:00:28 +0200 Subject: [PATCH 11/12] Fix unfinished sentence in docs --- types/v56/types.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/v56/types.go b/types/v56/types.go index 398d66627..930ba671a 100644 --- a/types/v56/types.go +++ b/types/v56/types.go @@ -1575,7 +1575,8 @@ type GatewayConfiguration struct { // GatewayBackingConfig defines configuration of the vShield edge VM for this gateway. One of: // compact, full. GatewayBackingConfig string `xml:"GatewayBackingConfig"` - // GatewayInterfaces holds configuration for + // GatewayInterfaces holds configuration for edge gateway interfaces, ip allocations, traffic + // rate limits and ip sub-allocations GatewayInterfaces *GatewayInterfaces `xml:"GatewayInterfaces"` // EdgeGatewayServiceConfiguration represents Gateway Features. EdgeGatewayServiceConfiguration *GatewayFeatures `xml:"EdgeGatewayServiceConfiguration,omitempty"` From 94b243c1b1119894856c93b07c3010f2f6a5fbba Mon Sep 17 00:00:00 2001 From: Dainius S Date: Fri, 29 Nov 2019 08:32:56 +0200 Subject: [PATCH 12/12] Remove duplicate function --- govcd/nsxv_ipset_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/govcd/nsxv_ipset_test.go b/govcd/nsxv_ipset_test.go index 26b8d506d..80bbf2503 100644 --- a/govcd/nsxv_ipset_test.go +++ b/govcd/nsxv_ipset_test.go @@ -115,7 +115,3 @@ func (vcd *TestVCD) Test_NsxvIpSet(check *C) { check.Assert(err, IsNil) } - -func takeBoolPointer(value bool) *bool { - return &value -}