mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
api/types/network: use netip types as appropriate
And generate the ServiceInfo struct from the Swagger spec. Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
committed by
Sebastiaan van Stijn
parent
ef31514a9f
commit
a90adb6dc1
@@ -2,6 +2,7 @@ package container
|
||||
|
||||
import (
|
||||
"maps"
|
||||
"net/netip"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
@@ -173,7 +174,7 @@ func WithIPv4(networkName, ip string) func(*TestContainerConfig) {
|
||||
if c.NetworkingConfig.EndpointsConfig[networkName].IPAMConfig == nil {
|
||||
c.NetworkingConfig.EndpointsConfig[networkName].IPAMConfig = &network.EndpointIPAMConfig{}
|
||||
}
|
||||
c.NetworkingConfig.EndpointsConfig[networkName].IPAMConfig.IPv4Address = ip
|
||||
c.NetworkingConfig.EndpointsConfig[networkName].IPAMConfig.IPv4Address = netip.MustParseAddr(ip)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +190,7 @@ func WithIPv6(networkName, ip string) func(*TestContainerConfig) {
|
||||
if c.NetworkingConfig.EndpointsConfig[networkName].IPAMConfig == nil {
|
||||
c.NetworkingConfig.EndpointsConfig[networkName].IPAMConfig = &network.EndpointIPAMConfig{}
|
||||
}
|
||||
c.NetworkingConfig.EndpointsConfig[networkName].IPAMConfig.IPv6Address = ip
|
||||
c.NetworkingConfig.EndpointsConfig[networkName].IPAMConfig.IPv6Address = netip.MustParseAddr(ip)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package network
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
|
||||
"github.com/moby/moby/api/types/network"
|
||||
"github.com/moby/moby/client"
|
||||
)
|
||||
@@ -137,12 +139,19 @@ func WithIPAM(subnet, gateway string) func(*client.NetworkCreateOptions) {
|
||||
|
||||
// WithIPAMRange adds an IPAM with the specified Subnet, IPRange and Gateway to the network
|
||||
func WithIPAMRange(subnet, iprange, gateway string) func(*client.NetworkCreateOptions) {
|
||||
return WithIPAMConfig(network.IPAMConfig{
|
||||
Subnet: subnet,
|
||||
IPRange: iprange,
|
||||
Gateway: gateway,
|
||||
AuxAddress: map[string]string{},
|
||||
})
|
||||
c := network.IPAMConfig{
|
||||
AuxAddress: map[string]netip.Addr{},
|
||||
}
|
||||
if subnet != "" {
|
||||
c.Subnet = netip.MustParsePrefix(subnet)
|
||||
}
|
||||
if iprange != "" {
|
||||
c.IPRange = netip.MustParsePrefix(iprange)
|
||||
}
|
||||
if gateway != "" {
|
||||
c.Gateway = netip.MustParseAddr(gateway)
|
||||
}
|
||||
return WithIPAMConfig(c)
|
||||
}
|
||||
|
||||
// WithIPAMConfig adds the provided IPAM configurations to the network
|
||||
|
||||
Reference in New Issue
Block a user