Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit a371c0e

Browse files
author
Travis Truman
committed
AllowedAddressPairs support for Port creation
1 parent d3e3a10 commit a371c0e

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

openstack/networking/v2/ports/requests.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,16 @@ type CreateOptsBuilder interface {
9595

9696
// CreateOpts represents the attributes used when creating a new port.
9797
type CreateOpts struct {
98-
NetworkID string
99-
Name string
100-
AdminStateUp *bool
101-
MACAddress string
102-
FixedIPs interface{}
103-
DeviceID string
104-
DeviceOwner string
105-
TenantID string
106-
SecurityGroups []string
98+
NetworkID string
99+
Name string
100+
AdminStateUp *bool
101+
MACAddress string
102+
FixedIPs interface{}
103+
DeviceID string
104+
DeviceOwner string
105+
TenantID string
106+
SecurityGroups []string
107+
AllowedAddressPairs interface{}
107108
}
108109

109110
// ToPortCreateMap casts a CreateOpts struct to a map.
@@ -139,6 +140,9 @@ func (opts CreateOpts) ToPortCreateMap() (map[string]interface{}, error) {
139140
if opts.MACAddress != "" {
140141
p["mac_address"] = opts.MACAddress
141142
}
143+
if opts.AllowedAddressPairs != nil {
144+
p["allowed_address_pairs"] = opts.AllowedAddressPairs
145+
}
142146

143147
return map[string]interface{}{"port": p}, nil
144148
}

openstack/networking/v2/ports/requests_test.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,13 @@ func TestCreate(t *testing.T) {
164164
"ip_address": "10.0.0.2"
165165
}
166166
],
167-
"security_groups": ["foo"]
167+
"security_groups": ["foo"],
168+
"allowed_address_pairs": [
169+
{
170+
"ip_address": "10.0.0.4",
171+
"mac_address": "fa:16:3e:c9:cb:f0"
172+
}
173+
]
168174
}
169175
}
170176
`)
@@ -177,7 +183,6 @@ func TestCreate(t *testing.T) {
177183
"port": {
178184
"status": "DOWN",
179185
"name": "private-port",
180-
"allowed_address_pairs": [],
181186
"admin_state_up": true,
182187
"network_id": "a87cc70a-3e15-4acf-8205-9b711a3531b7",
183188
"tenant_id": "d6700c0c9ffa4f1cb322cd4a1f3906fa",
@@ -193,6 +198,12 @@ func TestCreate(t *testing.T) {
193198
"security_groups": [
194199
"f0ac4394-7e4a-4409-9701-ba8be283dbc3"
195200
],
201+
"allowed_address_pairs": [
202+
{
203+
"ip_address": "10.0.0.4",
204+
"mac_address": "fa:16:3e:c9:cb:f0"
205+
}
206+
],
196207
"device_id": ""
197208
}
198209
}
@@ -208,6 +219,9 @@ func TestCreate(t *testing.T) {
208219
IP{SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.2"},
209220
},
210221
SecurityGroups: []string{"foo"},
222+
AllowedAddressPairs: []AddressPair{
223+
AddressPair{IPAddress: "10.0.0.4", MACAddress: "fa:16:3e:c9:cb:f0"},
224+
},
211225
}
212226
n, err := Create(fake.ServiceClient(), options).Extract()
213227
th.AssertNoErr(t, err)
@@ -224,6 +238,9 @@ func TestCreate(t *testing.T) {
224238
})
225239
th.AssertEquals(t, n.ID, "65c0ee9f-d634-4522-8954-51021b570b0d")
226240
th.AssertDeepEquals(t, n.SecurityGroups, []string{"f0ac4394-7e4a-4409-9701-ba8be283dbc3"})
241+
th.AssertDeepEquals(t, n.AllowedAddressPairs, []AddressPair{
242+
AddressPair{IPAddress: "10.0.0.4", MACAddress: "fa:16:3e:c9:cb:f0"},
243+
})
227244
}
228245

229246
func TestRequiredCreateOpts(t *testing.T) {

0 commit comments

Comments
 (0)