Skip to content

Commit 9fcde4e

Browse files
authored
Merge pull request juju#13594 from jack-w-shaw/JUJU-335_expand_use_of_ProviderAddress_constructors
juju#13594 This is to setup a later change described in JUJU-335. Add some more properties to `ProviderAddress`, particularly `ProviderID`, so they can later be dropped from `InterfaceInfo` ## Checklist - ~[ ] Requires a [pylibjuju](https://github.com/juju/python-libjuju) change~ - [x] Added [integration tests](https://github.com/juju/juju/tree/develop/tests) for the PR - ~[ ] Added or updated [doc.go](https://discourse.jujucharms.com/t/readme-in-packages/451) related to packages changed~ - [ ] Comments answer the question of why design decisions were made ## QA steps ```sh make static-analysis go test github.com/juju/juju/core/network ``` ## Documentation changes No documentations changes ## Bug reference No bug reference
2 parents 6c854e0 + 9329435 commit 9fcde4e

File tree

3 files changed

+185
-7
lines changed

3 files changed

+185
-7
lines changed

core/network/address.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,24 @@ func isIPv6UniqueLocalAddress(addrType AddressType, ip net.IP) bool {
404404
// address resides.
405405
type ProviderAddress struct {
406406
MachineAddress
407-
SpaceName SpaceName
407+
408+
// SpaceName is the space in which this address resides
409+
SpaceName SpaceName
410+
411+
// ProviderSpaceID is the provider's ID for the space this address is in
408412
ProviderSpaceID Id
413+
414+
// ProviderID is the ID of this address's provider
415+
ProviderID Id
416+
417+
// ProviderSubnetID is the provider's ID for the subnet this address is in
418+
ProviderSubnetID Id
419+
420+
// ProviderVLANID is the provider's ID for the VLAN this address is in
421+
ProviderVLANID Id
422+
423+
// VLANTag is the tag associated with this address's VLAN
424+
VLANTag int
409425
}
410426

411427
// GoString implements fmt.GoStringer.

core/network/address_options.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,23 @@ func WithConfigType(configType AddressConfigType) func(AddressMutator) {
7777
type ProviderAddressMutator interface {
7878
AddressMutator
7979

80+
// SetSpaceName sets the SpaceName property of the provider address
8081
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)
8197
}
8298

8399
// SetSpaceName (ProviderAddressMutator) sets the input
@@ -86,10 +102,80 @@ func (a *ProviderAddress) SetSpaceName(spaceName string) {
86102
a.SpaceName = SpaceName(spaceName)
87103
}
88104

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+
89135
// WithSpaceName returns a functional option that can
90136
// be used to set the input space name on a provider address.
91137
func WithSpaceName(space string) func(ProviderAddressMutator) {
92138
return func(a ProviderAddressMutator) {
93139
a.SetSpaceName(space)
94140
}
95141
}
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+
}

core/network/address_test.go

Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,29 @@ func (s *AddressSuite) TestNewScopedAddressIPv6(c *gc.C) {
122122
}
123123

124124
func (s *AddressSuite) TestAsProviderAddress(c *gc.C) {
125-
addr1 := network.NewMachineAddress("0.1.2.3").AsProviderAddress(network.WithSpaceName("foo"))
126-
addr2 := network.NewMachineAddress("2001:db8::123").AsProviderAddress(network.WithSpaceName(""))
125+
addr1 := network.NewMachineAddress("0.1.2.3").AsProviderAddress(
126+
network.WithSpaceName("foo"),
127+
network.WithProviderSpaceID("3"),
128+
network.WithProviderID("523"),
129+
network.WithProviderSubnetID("5"),
130+
network.WithProviderVLANID("5001"),
131+
network.WithVLANTag(50),
132+
)
133+
addr2 := network.NewMachineAddress("2001:db8::123").AsProviderAddress(
134+
network.WithSpaceName(""),
135+
)
127136
c.Check(addr1, jc.DeepEquals, network.ProviderAddress{
128137
MachineAddress: network.MachineAddress{
129138
Value: "0.1.2.3",
130139
Type: "ipv4",
131140
Scope: "public",
132141
},
133-
SpaceName: "foo",
142+
SpaceName: "foo",
143+
ProviderSpaceID: "3",
144+
ProviderID: "523",
145+
ProviderSubnetID: "5",
146+
ProviderVLANID: "5001",
147+
VLANTag: 50,
134148
})
135149
c.Check(addr2, jc.DeepEquals, network.ProviderAddress{
136150
MachineAddress: network.MachineAddress{
@@ -143,21 +157,35 @@ func (s *AddressSuite) TestAsProviderAddress(c *gc.C) {
143157
}
144158

145159
func (s *AddressSuite) TestAsProviderAddresses(c *gc.C) {
146-
addrs := network.NewMachineAddresses([]string{"0.2.3.4", "fc00::1"}).AsProviderAddresses(network.WithSpaceName("bar"))
160+
addrs := network.NewMachineAddresses([]string{"0.2.3.4", "fc00::1"}).AsProviderAddresses(
161+
network.WithSpaceName("bar"),
162+
network.WithProviderSpaceID("4"),
163+
network.WithProviderSubnetID("6"),
164+
network.WithProviderVLANID("5002"),
165+
network.WithVLANTag(100),
166+
)
147167
c.Check(addrs, jc.DeepEquals, network.ProviderAddresses{{
148168
MachineAddress: network.MachineAddress{
149169
Value: "0.2.3.4",
150170
Type: "ipv4",
151171
Scope: "public",
152172
},
153-
SpaceName: "bar",
173+
SpaceName: "bar",
174+
ProviderSpaceID: "4",
175+
ProviderSubnetID: "6",
176+
ProviderVLANID: "5002",
177+
VLANTag: 100,
154178
}, {
155179
MachineAddress: network.MachineAddress{
156180
Value: "fc00::1",
157181
Type: "ipv6",
158182
Scope: "local-cloud",
159183
},
160-
SpaceName: "bar",
184+
SpaceName: "bar",
185+
ProviderSpaceID: "4",
186+
ProviderSubnetID: "6",
187+
ProviderVLANID: "5002",
188+
VLANTag: 100,
161189
}})
162190
}
163191

@@ -676,6 +704,54 @@ var stringTests = []struct {
676704
ProviderSpaceID: network.Id("3"),
677705
},
678706
str: "public:foo.com@badlands(id:3)",
707+
}, {
708+
addr: network.ProviderAddress{
709+
MachineAddress: network.MachineAddress{
710+
Type: network.HostName,
711+
Value: "foo.com",
712+
Scope: network.ScopePublic,
713+
},
714+
SpaceName: "badlands",
715+
ProviderSpaceID: network.Id("3"),
716+
ProviderID: "523",
717+
},
718+
str: "public:foo.com@badlands(id:3)",
719+
}, {
720+
addr: network.ProviderAddress{
721+
MachineAddress: network.MachineAddress{
722+
Type: network.HostName,
723+
Value: "foo.com",
724+
Scope: network.ScopePublic,
725+
},
726+
SpaceName: "badlands",
727+
ProviderSpaceID: network.Id("3"),
728+
ProviderSubnetID: "5",
729+
},
730+
str: "public:foo.com@badlands(id:3)",
731+
}, {
732+
addr: network.ProviderAddress{
733+
MachineAddress: network.MachineAddress{
734+
Type: network.HostName,
735+
Value: "foo.com",
736+
Scope: network.ScopePublic,
737+
},
738+
SpaceName: "badlands",
739+
ProviderSpaceID: network.Id("3"),
740+
ProviderVLANID: "5001",
741+
},
742+
str: "public:foo.com@badlands(id:3)",
743+
}, {
744+
addr: network.ProviderAddress{
745+
MachineAddress: network.MachineAddress{
746+
Type: network.HostName,
747+
Value: "foo.com",
748+
Scope: network.ScopePublic,
749+
},
750+
SpaceName: "badlands",
751+
ProviderSpaceID: network.Id("3"),
752+
VLANTag: 50,
753+
},
754+
str: "public:foo.com@badlands(id:3)",
679755
}}
680756

681757
func (s *AddressSuite) TestString(c *gc.C) {

0 commit comments

Comments
 (0)