Skip to content

Commit e0dc334

Browse files
authored
Merge pull request juju#11819 from manadart/2.8-address-cidr-config
juju#11819 ## Description of change This patch adds new members and corresponding accessors to `network.Address`. These are not yet recruited or reflected in DTOs, but will be used in forthcoming refactoring around usage of `InterfaceInfo`. `InterfaceConfigType` is renamed to `AddressConfigType` as it applies to links and not the interface they are on. ## QA steps None required. ## Documentation changes None. ## Bug reference N/A
2 parents 66c1521 + 9f3cae2 commit e0dc334

File tree

5 files changed

+50
-26
lines changed

5 files changed

+50
-26
lines changed

api/provisioner/provisioner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func (st *State) prepareOrGetContainerInterfaceInfo(
314314
InterfaceType: corenetwork.InterfaceType(cfg.InterfaceType),
315315
Disabled: cfg.Disabled,
316316
NoAutoStart: cfg.NoAutoStart,
317-
ConfigType: corenetwork.InterfaceConfigType(cfg.ConfigType),
317+
ConfigType: corenetwork.AddressConfigType(cfg.ConfigType),
318318
Addresses: corenetwork.ProviderAddresses{corenetwork.NewProviderAddress(cfg.Address)},
319319
DNSServers: corenetwork.NewProviderAddresses(cfg.DNSServers...),
320320
DNSSearchDomains: cfg.DNSSearchDomains,

apiserver/params/network.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ type NetworkConfig struct {
143143
NoAutoStart bool `json:"no-auto-start,omitempty"`
144144

145145
// ConfigType, if set, defines what type of configuration to use.
146-
// See network.InterfaceConfigType for more info. If not set, for
146+
// See network.AddressConfigType for more info. If not set, for
147147
// backwards-compatibility, "dhcp" is assumed.
148148
ConfigType string `json:"config-type,omitempty"`
149149

@@ -282,7 +282,7 @@ func InterfaceInfoFromNetworkConfig(configs []NetworkConfig) network.InterfaceIn
282282
InterfaceType: network.InterfaceType(v.InterfaceType),
283283
Disabled: v.Disabled,
284284
NoAutoStart: v.NoAutoStart,
285-
ConfigType: network.InterfaceConfigType(v.ConfigType),
285+
ConfigType: network.AddressConfigType(v.ConfigType),
286286
Addresses: ToProviderAddresses(v.Addresses...),
287287
ShadowAddresses: ToProviderAddresses(v.ShadowAddresses...),
288288
DNSServers: network.NewProviderAddresses(v.DNSServers...),

core/network/address.go

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ func mustParseCIDR(s string) *net.IPNet {
3333
return ipNet
3434
}
3535

36+
// AddressConfigType defines valid network link configuration types.
37+
// See interfaces(5) for details.
38+
type AddressConfigType string
39+
40+
const (
41+
ConfigUnknown AddressConfigType = ""
42+
ConfigDHCP AddressConfigType = "dhcp"
43+
ConfigStatic AddressConfigType = "static"
44+
ConfigManual AddressConfigType = "manual"
45+
ConfigLoopback AddressConfigType = "loopback"
46+
)
47+
3648
// AddressType represents the possible ways of specifying a machine location by
3749
// either a hostname resolvable by dns lookup, or IPv4 or IPv6 address.
3850
type AddressType string
@@ -83,6 +95,12 @@ type Address interface {
8395

8496
// AddressScope returns the scope of the address.
8597
AddressScope() Scope
98+
99+
// AddressCIDR returns the subnet CIDR of the address.
100+
AddressCIDR() string
101+
102+
// AddressConfigType returns the configuration method of the address.
103+
AddressConfigType() AddressConfigType
86104
}
87105

88106
// ScopeMatchFunc is an alias for a function that accepts an Address,
@@ -105,9 +123,22 @@ func ExactScopeMatch(addr Address, addrScopes ...Scope) bool {
105123
// directly on a machine or container, or returned for requests where space
106124
// information is irrelevant to usage.
107125
type MachineAddress struct {
126+
// Value is an IP address or hostname.
108127
Value string
109-
Type AddressType
128+
129+
// Type indicates the form of the address value;
130+
// IPv4, IPv6 or host-name.
131+
Type AddressType
132+
133+
// Scope indicates the visibility of this address.
110134
Scope Scope
135+
136+
// CIDR is used for IP addresses to indicate
137+
// the subnet that they are part of.
138+
CIDR string
139+
140+
// ConfigType denotes how this address was configured.
141+
ConfigType AddressConfigType
111142
}
112143

113144
// Host returns the value for the host-name/IP address.
@@ -125,6 +156,16 @@ func (a MachineAddress) AddressScope() Scope {
125156
return a.Scope
126157
}
127158

159+
// AddressCIDR returns the subnet CIDR of the address.
160+
func (a MachineAddress) AddressCIDR() string {
161+
return a.CIDR
162+
}
163+
164+
// AddressConfigType returns the configuration method of the address.
165+
func (a MachineAddress) AddressConfigType() AddressConfigType {
166+
return a.ConfigType
167+
}
168+
128169
// GoString implements fmt.GoStringer.
129170
func (a MachineAddress) GoString() string {
130171
return a.String()
@@ -146,6 +187,8 @@ func (a MachineAddress) IP() net.IP {
146187

147188
// ValueForCIDR returns the value of the address combined with a subnet mask
148189
// indicated by the input CIDR.
190+
// TODO (manadart 2020-07-10): This should evolve to use the address CIDR
191+
// directly instead of receiving a value, once we clean up InterfaceInfo.
149192
func (a MachineAddress) ValueForCIDR(cidr string) (string, error) {
150193
_, ipNet, err := net.ParseCIDR(cidr)
151194
if err != nil {
@@ -313,7 +356,7 @@ func (a ProviderAddress) String() string {
313356
buf.WriteByte('@')
314357
buf.WriteString(string(a.SpaceName))
315358
}
316-
if a.ProviderSpaceID != Id("") {
359+
if a.ProviderSpaceID != "" {
317360
if !spaceFound {
318361
buf.WriteByte('@')
319362
}
@@ -448,13 +491,6 @@ func (a SpaceAddress) GoString() string {
448491
return a.String()
449492
}
450493

451-
// Converts the space address to a net.IP address assuming the space address is
452-
// either v4 or v6. If the SpaceAddress value is not a valid ip address nil is
453-
// returned
454-
func (a SpaceAddress) IP() net.IP {
455-
return net.ParseIP(a.Value)
456-
}
457-
458494
// String returns a string representation of the address, in the form:
459495
// `<scope>:<address-value>@space:<space-id>`; for example:
460496
//

core/network/nic.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,6 @@ import (
1010
"github.com/juju/errors"
1111
)
1212

13-
// InterfaceConfigType defines valid network interface configuration
14-
// types. See interfaces(5) for details
15-
type InterfaceConfigType string
16-
17-
const (
18-
ConfigUnknown InterfaceConfigType = ""
19-
ConfigDHCP InterfaceConfigType = "dhcp"
20-
ConfigStatic InterfaceConfigType = "static"
21-
ConfigManual InterfaceConfigType = "manual"
22-
ConfigLoopback InterfaceConfigType = "loopback"
23-
)
24-
2513
// InterfaceType defines valid network interface types.
2614
type InterfaceType string
2715

@@ -143,7 +131,7 @@ type InterfaceInfo struct {
143131
// ConfigType determines whether the interface should be
144132
// configured via DHCP, statically, manually, etc. See
145133
// interfaces(5) for more information.
146-
ConfigType InterfaceConfigType
134+
ConfigType AddressConfigType
147135

148136
// Addresses contains an optional list of static IP address to
149137
// configure for this network interface. The subnet mask to set will be

provider/maas/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ func parseInterfaces(jsonBytes []byte) ([]maasInterface, error) {
441441
return interfaces, nil
442442
}
443443

444-
func maasLinkToInterfaceConfigType(mode string) corenetwork.InterfaceConfigType {
444+
func maasLinkToInterfaceConfigType(mode string) corenetwork.AddressConfigType {
445445
switch maasLinkMode(mode) {
446446
case modeUnknown:
447447
return corenetwork.ConfigUnknown

0 commit comments

Comments
 (0)