This PR introduced a few new functions for Edge Gateway IP allocation management:
NsxtEdgeGateway.Refresh
NsxtEdgeGateway.GetUsedIpAddresses
It uses direct VCD endpoint edgeGateways/%s/usedIpAddresses
NsxtEdgeGateway.GetUsedIpAddressSlice is using the same endpoint as NsxtEdgeGateway.GetUsedIpAddresses, but returns values using Go's native []netip.Addr
NsxtEdgeGateway.GetAllocatedIpCount that traverses Edge Gateway structure and sums up amount of TotalIPCount in each subnet value
NsxtEdgeGateway.QuickDeallocateIpCount and NsxtEdgeGateway.DeallocateIpCount
functions to manually alter Edge Gateway body for IP deallocation (API does not officially support deallocation using negative numbers in QuickAddAllocatedIPCount even though it works in some versions)
NsxtEdgeGateway.GetUnusedExternalIPAddresses - is a function which performs the following actions to get the result
Retrieves a complete list of IPs in Edge Gateway uplinks (returns error if none are found)
if 'optionalSubnet' was specified - filter IP addresses to only fall into that subnet
Retrieves all used IP addresses in Edge Gateway using dedicated API endpoint
Subtracts used IP addresses from available list of IPs in uplink (optionally filtered by optionalSubnet in step 2)
Checks if 'requiredIpCount' criteria is met, returns error otherwise
Returns required amount of unused IPs (as defined in 'requiredIpCount')
NsxtEdgeGateway.GetAllUnusedExternalIPAddresses - almost the same as NsxtEdgeGateway.GetUnusedExternalIPAddresses, but without steps 2, 5 and 6:
Retrieves a complete list of IPs in Edge Gateway uplinks (returns error if none are found)
Retrieves all used IP addresses in Edge Gateway using dedicated API endpoint
Subtracts used IP addresses from available list of IPs in uplink (optionally filtered by optionalSubnet in step 2)
Note. Functions use Go's built-in netip package to handle IPs and prefixes. It provides a robust solution to support IPv4 and IPv6 addresses and ease dealing with IP ranges and comparisons which wouldn't be easy to deal when operating with strings (especially IPv6)
Not directly related changes
Flipping type aliases so that OpenApiIPRanges is original type, while ExternalNetworkV2IPRanges is just an alias.
Flipping type aliases so that OpenApiIPRangeValues is original type, while ExternalNetworkV2IPRange is just an alias.
The reason for it is that IDE suggests using the the main type and it keeps pushing the External Network types. Technically they are identical, but using generalized names is more correct.
Testing
In addition to regular integration testing (test Test_NsxtEdgeGatewayUsedAndUnusedIPs) function GetUnallocatedExternalIPAddresses has quite a few unit tests. (nsxt_edgegateway_unit_test.go).
This is because this function relies on a lot of client-side computations and testing and many cases in integration tests would become expensive.
About
This PR introduced a few new functions for Edge Gateway IP allocation management:
NsxtEdgeGateway.Refresh
NsxtEdgeGateway.GetUsedIpAddresses
It uses direct VCD endpointedgeGateways/%s/usedIpAddresses
NsxtEdgeGateway.GetUsedIpAddressSlice
is using the same endpoint asNsxtEdgeGateway.GetUsedIpAddresses
, but returns values using Go's native[]netip.Addr
NsxtEdgeGateway.GetAllocatedIpCount
that traverses Edge Gateway structure and sums up amount ofTotalIPCount
in each subnet valueNsxtEdgeGateway.QuickDeallocateIpCount
andNsxtEdgeGateway.DeallocateIpCount
functions to manually alter Edge Gateway body for IP deallocation (API does not officially support deallocation using negative numbers inQuickAddAllocatedIPCount
even though it works in some versions)NsxtEdgeGateway.GetUnusedExternalIPAddresses
- is a function which performs the following actions to get the resultNsxtEdgeGateway.GetAllUnusedExternalIPAddresses
- almost the same asNsxtEdgeGateway.GetUnusedExternalIPAddresses
, but without steps 2, 5 and 6:Note. Functions use Go's built-in
netip
package to handle IPs and prefixes. It provides a robust solution to support IPv4 and IPv6 addresses and ease dealing with IP ranges and comparisons which wouldn't be easy to deal when operating with strings (especially IPv6)Not directly related changes
OpenApiIPRanges
is original type, whileExternalNetworkV2IPRanges
is just an alias.OpenApiIPRangeValues
is original type, whileExternalNetworkV2IPRange
is just an alias.The reason for it is that IDE suggests using the the main type and it keeps pushing the External Network types. Technically they are identical, but using generalized names is more correct.
Testing
In addition to regular integration testing (test
Test_NsxtEdgeGatewayUsedAndUnusedIPs
) functionGetUnallocatedExternalIPAddresses
has quite a few unit tests. (nsxt_edgegateway_unit_test.go
). This is because this function relies on a lot of client-side computations and testing and many cases in integration tests would become expensive.