From 819c50982409d0a90f21c40704c0b5f3ab46a013 Mon Sep 17 00:00:00 2001 From: Dainius Serplis Date: Mon, 13 Nov 2023 16:05:55 +0200 Subject: [PATCH] Add option to apply default services Signed-off-by: Dainius Serplis --- govcd/nsxt_edgegateway.go | 30 ++++++++++++++++++++++++++++++ govcd/openapi_endpoints.go | 27 ++++++++++++++------------- types/v56/constants.go | 1 + 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/govcd/nsxt_edgegateway.go b/govcd/nsxt_edgegateway.go index 88c59864f..39e1f3ef9 100644 --- a/govcd/nsxt_edgegateway.go +++ b/govcd/nsxt_edgegateway.go @@ -890,6 +890,36 @@ func (egw *NsxtEdgeGateway) UpdateSlaacProfile(slaacProfileConfig *types.NsxtEdg return updatedSlaacProfile, nil } +func (egw *NsxtEdgeGateway) ApplyIpSpaceDefaultServices() error { + if egw.EdgeGateway == nil || egw.client == nil || egw.EdgeGateway.ID == "" { + return fmt.Errorf("cannot Apply default IP Space Services for NSX-T Edge Gateway without ID") + } + + client := egw.client + endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointEdgeGatewayIpSpaceDefaultServices + apiVersion, err := client.getOpenApiHighestElevatedVersion(endpoint) + if err != nil { + return err + } + + urlRef, err := client.OpenApiBuildEndpoint(fmt.Sprintf(endpoint, egw.EdgeGateway.ID)) + if err != nil { + return err + } + + task, err := client.OpenApiPostItemAsync(apiVersion, urlRef, nil, nil) + if err != nil { + return err + } + + err = task.WaitTaskCompletion() + if err != nil { + return fmt.Errorf("error in task when applying default IP Space Services for Edge Gateway '%s': %s", egw.EdgeGateway.ID, err) + } + + return nil +} + func getAllUnusedExternalIPAddresses(uplinks []types.EdgeGatewayUplinks, usedIpAddresses []*types.GatewayUsedIpAddress, optionalSubnet netip.Prefix) ([]netip.Addr, error) { // 1. Flatten all IP ranges in Edge Gateway using Go's native 'netip.Addr' IP container instead // of plain strings because it is more robust (supports IPv4 and IPv6 and also comparison diff --git a/govcd/openapi_endpoints.go b/govcd/openapi_endpoints.go index f2283ed71..0f62a0ee5 100644 --- a/govcd/openapi_endpoints.go +++ b/govcd/openapi_endpoints.go @@ -30,19 +30,20 @@ var endpointMinApiVersions = map[string]string{ types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointTestConnection: "34.0", // OpenApiEndpointExternalNetworks endpoint support was introduced with version 32.0 however it was still not stable // enough to be used. (i.e. it did not support update "PUT") - types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointExternalNetworks: "33.0", - types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcComputePolicies: "32.0", - types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcAssignedComputePolicies: "33.0", - types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointSessionCurrent: "34.0", - types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointEdgeClusters: "34.0", // VCD 10.1+ - types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointQosProfiles: "36.2", // VCD 10.3.2+ (NSX-T only) - types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointEdgeGatewayQos: "36.2", // VCD 10.3.2+ (NSX-T only) - types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointEdgeGatewayDhcpForwarder: "36.1", // VCD 10.3.1+ (NSX-T only) - types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointEdgeGatewayL2VpnTunnel: "35.0", // VCD 10.2.0+ (NSX-T only) - types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointEdgeGatewaySlaacProfile: "35.0", - types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointEdgeGatewayStaticRoutes: "37.0", // VCD 10.4.0+ (NSX-T only) - types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointEdgeGateways: "34.0", - types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointEdgeGatewayUsedIpAddresses: "34.0", + types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointExternalNetworks: "33.0", + types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcComputePolicies: "32.0", + types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcAssignedComputePolicies: "33.0", + types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointSessionCurrent: "34.0", + types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointEdgeClusters: "34.0", // VCD 10.1+ + types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointQosProfiles: "36.2", // VCD 10.3.2+ (NSX-T only) + types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointEdgeGatewayQos: "36.2", // VCD 10.3.2+ (NSX-T only) + types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointEdgeGatewayDhcpForwarder: "36.1", // VCD 10.3.1+ (NSX-T only) + types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointEdgeGatewayL2VpnTunnel: "35.0", // VCD 10.2.0+ (NSX-T only) + types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointEdgeGatewaySlaacProfile: "35.0", + types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointEdgeGatewayIpSpaceDefaultServices: "38.0", // VCD 10.5.0+ + types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointEdgeGatewayStaticRoutes: "37.0", // VCD 10.4.0+ (NSX-T only) + types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointEdgeGateways: "34.0", + types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointEdgeGatewayUsedIpAddresses: "34.0", // Static security groups and IP sets in VCD 10.2, Dynamic security groups in VCD 10.3+ types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointFirewallGroups: "34.0", diff --git a/types/v56/constants.go b/types/v56/constants.go index 946104065..eee2a7d73 100644 --- a/types/v56/constants.go +++ b/types/v56/constants.go @@ -383,6 +383,7 @@ const ( OpenApiEndpointEdgeGatewayQos = "edgeGateways/%s/qos" OpenApiEndpointEdgeGatewayDhcpForwarder = "edgeGateways/%s/dhcpForwarder" OpenApiEndpointEdgeGatewaySlaacProfile = "edgeGateways/%s/slaacProfile" + OpenApiEndpointEdgeGatewayIpSpaceDefaultServices = "edgeGateways/%s/applyIpSpaceDefaultServices" OpenApiEndpointEdgeGatewayStaticRoutes = "edgeGateways/%s/routing/staticRoutes/" OpenApiEndpointEdgeGatewayUsedIpAddresses = "edgeGateways/%s/usedIpAddresses" OpenApiEndpointNsxtFirewallRules = "edgeGateways/%s/firewall/rules"