Skip to content

Commit

Permalink
Add option to apply default services
Browse files Browse the repository at this point in the history
Signed-off-by: Dainius Serplis <dserplis@vmware.com>
  • Loading branch information
Didainius committed Nov 13, 2023
1 parent 8b03813 commit 819c509
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
30 changes: 30 additions & 0 deletions govcd/nsxt_edgegateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 14 additions & 13 deletions govcd/openapi_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions types/v56/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 819c509

Please sign in to comment.