github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/integration/internal/network/ops.go (about) 1 package network 2 3 import ( 4 "github.com/demonoid81/moby/api/types" 5 "github.com/demonoid81/moby/api/types/network" 6 ) 7 8 // WithDriver sets the driver of the network 9 func WithDriver(driver string) func(*types.NetworkCreate) { 10 return func(n *types.NetworkCreate) { 11 n.Driver = driver 12 } 13 } 14 15 // WithIPv6 Enables IPv6 on the network 16 func WithIPv6() func(*types.NetworkCreate) { 17 return func(n *types.NetworkCreate) { 18 n.EnableIPv6 = true 19 } 20 } 21 22 // WithCheckDuplicate sets the CheckDuplicate field on create network request 23 func WithCheckDuplicate() func(*types.NetworkCreate) { 24 return func(n *types.NetworkCreate) { 25 n.CheckDuplicate = true 26 } 27 } 28 29 // WithInternal enables Internal flag on the create network request 30 func WithInternal() func(*types.NetworkCreate) { 31 return func(n *types.NetworkCreate) { 32 n.Internal = true 33 } 34 } 35 36 // WithAttachable sets Attachable flag on the create network request 37 func WithAttachable() func(*types.NetworkCreate) { 38 return func(n *types.NetworkCreate) { 39 n.Attachable = true 40 } 41 } 42 43 // WithMacvlan sets the network as macvlan with the specified parent 44 func WithMacvlan(parent string) func(*types.NetworkCreate) { 45 return func(n *types.NetworkCreate) { 46 n.Driver = "macvlan" 47 if parent != "" { 48 n.Options = map[string]string{ 49 "parent": parent, 50 } 51 } 52 } 53 } 54 55 // WithIPvlan sets the network as ipvlan with the specified parent and mode 56 func WithIPvlan(parent, mode string) func(*types.NetworkCreate) { 57 return func(n *types.NetworkCreate) { 58 n.Driver = "ipvlan" 59 if n.Options == nil { 60 n.Options = map[string]string{} 61 } 62 if parent != "" { 63 n.Options["parent"] = parent 64 } 65 if mode != "" { 66 n.Options["ipvlan_mode"] = mode 67 } 68 } 69 } 70 71 // WithOption adds the specified key/value pair to network's options 72 func WithOption(key, value string) func(*types.NetworkCreate) { 73 return func(n *types.NetworkCreate) { 74 if n.Options == nil { 75 n.Options = map[string]string{} 76 } 77 n.Options[key] = value 78 } 79 } 80 81 // WithIPAM adds an IPAM with the specified Subnet and Gateway to the network 82 func WithIPAM(subnet, gateway string) func(*types.NetworkCreate) { 83 return func(n *types.NetworkCreate) { 84 if n.IPAM == nil { 85 n.IPAM = &network.IPAM{} 86 } 87 88 n.IPAM.Config = append(n.IPAM.Config, network.IPAMConfig{ 89 Subnet: subnet, 90 Gateway: gateway, 91 AuxAddress: map[string]string{}, 92 }) 93 } 94 }