Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Dainius Serplis <dserplis@vmware.com>
  • Loading branch information
Didainius committed Aug 28, 2024
1 parent be2d396 commit 7ff5108
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
28 changes: 28 additions & 0 deletions govcd/external_network_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/vmware/go-vcloud-director/v2/types/v56"
)

const labelNsxtTier0RouterInterface = "NSX-T Tier0 Router Interface"

// ExternalNetworkV2 is a type for version 2 of external network which uses OpenAPI endpoint to
// manage external networks of both types (NSX-V and NSX-T)
type ExternalNetworkV2 struct {
Expand Down Expand Up @@ -190,3 +192,29 @@ func (extNet *ExternalNetworkV2) Delete() error {

return nil
}

// GetAllTier0RouterInterfaces returns all Provider Gateway (aka Tier0 Router) associated interfaces
func (vcdClient *VCDClient) GetAllTier0RouterInterfaces(externalNetworkId string, queryParameters url.Values) ([]*types.NsxtTier0RouterInterface, error) {
if externalNetworkId == "" {
return nil, fmt.Errorf("mandatory External Network ID is empty")
}

queryparams := queryParameterFilterAnd(fmt.Sprintf("externalNetworkId==%s", externalNetworkId), queryParameters)
c := crudConfig{
endpoint: types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointNsxtTier0RouterInterfaces,
entityLabel: labelNsxtTier0RouterInterface,
queryParameters: queryparams,
}

return getAllInnerEntities[types.NsxtTier0RouterInterface](&vcdClient.Client, c)
}

// GetTier0RouterInterfaceByName retrieves a Provider Gateway (aka Tier0 Router) associated interface by Name in a given External Network
func (vcdClient *VCDClient) GetTier0RouterInterfaceByName(externalNetworkId, displayName string) (*types.NsxtTier0RouterInterface, error) {
allT0Interfaces, err := vcdClient.GetAllTier0RouterInterfaces(externalNetworkId, nil)
if err != nil {
return nil, fmt.Errorf("error getting %s by DisplayName '%s':%s", labelNsxtTier0RouterInterface, displayName, err)
}

return localFilterOneOrError(labelNsxtTier0RouterInterface, allT0Interfaces, "DisplayName", displayName)
}
8 changes: 8 additions & 0 deletions govcd/openapi_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ var endpointMinApiVersions = map[string]string{
// Endpoint for managing vGPU profiles
types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVgpuProfile: "36.2",

// Orgs
types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointOrgs: "37.0",

// NSX-T Tier 0 router interfaces that can be used for IP Space uplink assignment
types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointNsxtTier0RouterInterfaces: "38.0",
}

// endpointElevatedApiVersions endpoint elevated API versions
Expand Down Expand Up @@ -229,6 +233,10 @@ var endpointElevatedApiVersions = map[string][]string{
//"37.1", // Introduced support
"38.0", // Adds 'DefaultGatewayServiceConfig' structure for firewall and NAT rule creation
},
types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointIpSpaceUplinks: {
//"37.1", // Introduced support
"38.0", // Adds 'Interfaces' structure for associating particular Tier-0 router interfaces
},
}

// checkOpenApiEndpointCompatibility checks if VCD version (to which the client is connected) is sufficient to work with
Expand Down
1 change: 1 addition & 0 deletions types/v56/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ const (
OpenApiEndpointImportableDvpgs = "virtualCenters/resources/importableDvpgs"
OpenApiEndpointEdgeClusters = "nsxTResources/edgeClusters"
OpenApiEndpointQosProfiles = "nsxTResources/gatewayQoSProfiles"
OpenApiEndpointNsxtTier0RouterInterfaces = "nsxTResources/tier0RouterInterfaces"
OpenApiEndpointExternalNetworks = "externalNetworks/"
OpenApiEndpointVdcComputePolicies = "vdcComputePolicies/"
OpenApiEndpointVdcAssignedComputePolicies = "vdcs/%s/computePolicies"
Expand Down
23 changes: 23 additions & 0 deletions types/v56/ip_space.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,15 @@ type IpSpaceUplink struct {
// SHARED_SERVICES. This property is read-only.
IPSpaceType string `json:"ipSpaceType,omitempty"`
Status string `json:"status,omitempty"`

// Interfaces allows to associate uplink with Tier-0 router interfaces on VCD 10.5.0+
Interfaces []IpSpaceUplinkInterface `json:"interfaces,omitempty"`
}

type IpSpaceUplinkInterface struct {
ID string `json:"id"`
Name string `json:"name"`
InterfaceType string `json:"interfaceType"`
}

// IpSpaceIpAllocationRequest is an IP Space IP Allocation request object. An IP Space IP allocation
Expand Down Expand Up @@ -371,3 +380,17 @@ type IpSpaceFloatingIpSuggestion struct {
// UnusedValues lists unused IP Addresses or IP Prefixes from the referenced IP Space
UnusedValues []string `json:"unusedValues"`
}

// NsxtTier0RouterInterface reflects single associated interface to Tier0/Provider gateway
type NsxtTier0RouterInterface struct {
ID string `json:"id"`
Description string `json:"description"`
DisplayName string `json:"displayName"`
// InterfaceType as defined in NSX-T manager
// * EXTERNAL - Interface that can be used to connect externally to a physical router with
// support for dynamic routing protocols.
// * SERVICE - Interface that supports edge services such as DHCP relay.
// * LOOPBACK - Interface that isn't connect to any segment and can be used to identify the
// Tier-0 Router.
InterfaceType string `json:"interfaceType"`
}

0 comments on commit 7ff5108

Please sign in to comment.