github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/core/network/address_options.go (about) 1 // Copyright 2021 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package network 5 6 // AddressMutator describes setter methods for an address. 7 type AddressMutator interface { 8 // SetScope sets the scope property of the address. 9 SetScope(Scope) 10 11 // SetCIDR sets the CIDR property of the address. 12 SetCIDR(string) 13 14 // SetSecondary indicates whether this address is not the 15 // primary address of the device it is associated with. 16 SetSecondary(bool) 17 18 // SetConfigType indicates how this address was configured. 19 SetConfigType(AddressConfigType) 20 } 21 22 // SetScope (AddressMutator) sets the input 23 // scope on the address receiver. 24 func (a *MachineAddress) SetScope(scope Scope) { 25 a.Scope = scope 26 } 27 28 // SetCIDR (AddressMutator) sets the input 29 // CIDR on the address receiver. 30 func (a *MachineAddress) SetCIDR(cidr string) { 31 a.CIDR = cidr 32 } 33 34 // SetSecondary (AddressMutator) sets the IsSecondary 35 // member to true on the address receiver. 36 func (a *MachineAddress) SetSecondary(isSecondary bool) { 37 a.IsSecondary = isSecondary 38 } 39 40 // SetConfigType (AddressMutator) sets the input 41 // AddressConfigType on the address receiver. 42 func (a *MachineAddress) SetConfigType(configType AddressConfigType) { 43 a.ConfigType = configType 44 } 45 46 // WithScope returns a functional option that can 47 // be used to set the input scope on an address. 48 func WithScope(scope Scope) func(AddressMutator) { 49 return func(a AddressMutator) { 50 a.SetScope(scope) 51 } 52 } 53 54 // WithCIDR returns a functional option that can 55 // be used to set the input CIDR on an address. 56 func WithCIDR(cidr string) func(AddressMutator) { 57 return func(a AddressMutator) { 58 a.SetCIDR(cidr) 59 } 60 } 61 62 // WithSecondary returns a functional option that can be used to 63 // indicate whether an address is not the primary for its NIC. 64 func WithSecondary(isSecondary bool) func(AddressMutator) { 65 return func(a AddressMutator) { 66 a.SetSecondary(isSecondary) 67 } 68 } 69 70 func WithConfigType(configType AddressConfigType) func(AddressMutator) { 71 return func(a AddressMutator) { 72 a.SetConfigType(configType) 73 } 74 } 75 76 // ProviderAddressMutator describes setter methods for a ProviderAddress 77 type ProviderAddressMutator interface { 78 AddressMutator 79 80 // SetSpaceName sets the SpaceName property of the provider address 81 SetSpaceName(string) 82 83 // SetProviderSpaceID sets the ProviderSpaceID property of the provider address 84 SetProviderSpaceID(Id) 85 86 // SetProviderID sets the ProviderID property of the provider address 87 SetProviderID(Id) 88 89 // SetProviderSubnetID sets the ProviderSubnetID property of the provider address 90 SetProviderSubnetID(Id) 91 92 // SetProviderVLANID sets the ProviderVLANID property of the provider address 93 SetProviderVLANID(Id) 94 95 // SetVLANTag sets the VLANTag property of the provider address 96 SetVLANTag(int) 97 } 98 99 // SetSpaceName (ProviderAddressMutator) sets the input 100 // space name on the provider address receiver 101 func (a *ProviderAddress) SetSpaceName(spaceName string) { 102 a.SpaceName = SpaceName(spaceName) 103 } 104 105 // SetProviderSpaceID (ProviderAddressMutator) sets the input 106 // provider space id on the provider address receiver 107 func (a *ProviderAddress) SetProviderSpaceID(id Id) { 108 a.ProviderSpaceID = id 109 } 110 111 // SetProviderID (ProviderAddressMutator) sets the input 112 // provider id on the provider address receiver 113 func (a *ProviderAddress) SetProviderID(id Id) { 114 a.ProviderID = id 115 } 116 117 // SetProviderSubnetID (ProviderAddressMutator) sets the input 118 // provider subnet id on the provider addrerss reviever 119 func (a *ProviderAddress) SetProviderSubnetID(id Id) { 120 a.ProviderSubnetID = id 121 } 122 123 // SetProviderVLANID (ProviderAddressMutator) sets the input 124 // provider VLAN id on the provider addrerss reviever 125 func (a *ProviderAddress) SetProviderVLANID(id Id) { 126 a.ProviderVLANID = id 127 } 128 129 // SetVLANTag (ProviderAddressMutator) sets the input 130 // VLAN tag on the provider addrerss reviever 131 func (a *ProviderAddress) SetVLANTag(tag int) { 132 a.VLANTag = tag 133 } 134 135 // WithSpaceName returns a functional option that can 136 // be used to set the input space name on a provider address. 137 func WithSpaceName(space string) func(ProviderAddressMutator) { 138 return func(a ProviderAddressMutator) { 139 a.SetSpaceName(space) 140 } 141 } 142 143 // WithProviderSpaceID returns a functional option that can 144 // be used to set the input provider space id on a provider address 145 func WithProviderSpaceID(id Id) func(ProviderAddressMutator) { 146 return func(a ProviderAddressMutator) { 147 a.SetProviderSpaceID(id) 148 } 149 } 150 151 // WithProviderID returns a functional option that can 152 // be used to set the input provider id on a provider address 153 func WithProviderID(id Id) func(ProviderAddressMutator) { 154 return func(a ProviderAddressMutator) { 155 a.SetProviderID(id) 156 } 157 } 158 159 // WithProviderSubnetID returns a functional option that can 160 // be used to set the input provider subnet id on a provider address 161 func WithProviderSubnetID(id Id) func(ProviderAddressMutator) { 162 return func(a ProviderAddressMutator) { 163 a.SetProviderSubnetID(id) 164 } 165 } 166 167 // WithProviderVLANID returns a functional option that can 168 // be used to set the input provider VLAN id on a provider address 169 func WithProviderVLANID(id Id) func(ProviderAddressMutator) { 170 return func(a ProviderAddressMutator) { 171 a.SetProviderVLANID(id) 172 } 173 } 174 175 // WithVLANTag returns a functional option that can 176 // be used to set the input VLAN tag on a provider address 177 func WithVLANTag(tag int) func(ProviderAddressMutator) { 178 return func(a ProviderAddressMutator) { 179 a.SetVLANTag(tag) 180 } 181 }