vmware / go-vcloud-director

Golang SDK for VMware Cloud Director
Other
80 stars 76 forks source link

Expand NSX-T Edge Gateway support for IP allocation management #532

Closed Didainius closed 1 year ago

Didainius commented 1 year ago

About

This PR introduced a few new functions for Edge Gateway IP allocation management:

  1. Retrieves a complete list of IPs in Edge Gateway uplinks (returns error if none are found)
  2. Retrieves all used IP addresses in Edge Gateway using dedicated API endpoint
  3. 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

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.