Skip to content

Commit 02d4ead

Browse files
committed
Merge pull request #199 from n-r-anderson/master
Added AllowedAddressPair to NeutronPort
2 parents f39c610 + 56de7d7 commit 02d4ead

File tree

5 files changed

+128
-10
lines changed

5 files changed

+128
-10
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.openstack4j.model.network;
2+
3+
import org.openstack4j.model.ModelEntity;
4+
5+
6+
/**
7+
* Allowed Address Pair for Neutron Port
8+
*
9+
* @author Nathan Anderson
10+
*/
11+
public interface AllowedAddressPair extends ModelEntity {
12+
13+
/**
14+
* @return the ip address
15+
*/
16+
String getIpAddress();
17+
18+
}

core/src/main/java/org/openstack4j/model/network/Port.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public interface Port extends Resource, Buildable<PortBuilder> {
4343
* @return the set of fixed IPs this port has been assigned
4444
*/
4545
Set<? extends IP> getFixedIps();
46+
47+
Set<? extends AllowedAddressPair> getAllowedAddressPairs();
4648

4749
/**
4850
* @return the MacAddress of this port

core/src/main/java/org/openstack4j/model/network/builder/PortBuilder.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,26 @@ public interface PortBuilder extends Builder<PortBuilder, Port> {
6666
*/
6767
PortBuilder removeFixedIp(String address, String subnetId);
6868

69+
70+
/**
71+
* Adds an allowed address pair to the current list of allowed addresses
72+
* @param address the Subnet Address (i.e. 192.168.1.0/24)
73+
* @return PortBuilder
74+
* @see Port#getAllowedAddressPairs()
75+
*/
76+
PortBuilder allowedAddressPair(String address);
77+
78+
79+
80+
/**
81+
* Removes an allowed address pair from the current list of allowed addresses
82+
* @param address the Subnet Address (i.e. 192.168.1.0/24)
83+
* @return PortBuilder
84+
* @see Port#getAllowedAddressPairs()
85+
*/
86+
PortBuilder removeAddressPair(String address);
87+
88+
6989
/**
7090
* @see Port#isAdminStateUp()
7191
*/
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.openstack4j.openstack.networking.domain;
2+
3+
import org.openstack4j.model.network.AllowedAddressPair;
4+
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import com.google.common.base.Objects;
7+
8+
/**
9+
* A Fixed IP Address
10+
*
11+
* @author Jeremy Unruh
12+
*/
13+
public class NeutronAllowedAddressPair implements AllowedAddressPair {
14+
15+
private static final long serialVersionUID = 1L;
16+
17+
@JsonProperty("ip_address")
18+
private String ipAddress;
19+
20+
public NeutronAllowedAddressPair() { }
21+
22+
public NeutronAllowedAddressPair(String address) {
23+
this.ipAddress = address;
24+
}
25+
26+
/**
27+
* {@inheritDoc}
28+
*/
29+
@Override
30+
public String getIpAddress() {
31+
return ipAddress;
32+
}
33+
34+
/**
35+
* {@inheritDoc}
36+
*/
37+
@Override
38+
public String toString() {
39+
return Objects.toStringHelper(this).omitNullValues().add("ipAddress", ipAddress).toString();
40+
}
41+
42+
}

core/src/main/java/org/openstack4j/openstack/networking/domain/NeutronPort.java

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.Set;
77

88
import org.openstack4j.model.common.builder.ResourceBuilder;
9+
import org.openstack4j.model.network.AllowedAddressPair;
910
import org.openstack4j.model.network.ExtraDhcpOptCreate;
1011
import org.openstack4j.model.network.IP;
1112
import org.openstack4j.model.network.Port;
@@ -45,6 +46,9 @@ public class NeutronPort implements Port {
4546

4647
@JsonProperty("fixed_ips")
4748
private Set<NeutronIP> fixedIps;
49+
50+
@JsonProperty("allowed_address_pairs")
51+
private Set<NeutronAllowedAddressPair> allowedAddressPairs;
4852

4953
@JsonProperty("mac_address")
5054
private String macAddress;
@@ -61,7 +65,7 @@ public class NeutronPort implements Port {
6165
@JsonProperty("security_groups")
6266
private List<String> securityGroups;
6367

64-
@JsonProperty("extra_dhcp_opts")
68+
@JsonProperty("extra_dhcp_opts")
6569
private List<NeutronExtraDhcpOptCreate> extraDhcpOptCreates = Lists.newArrayList();
6670

6771
public static PortBuilder builder() {
@@ -144,6 +148,14 @@ public String getDeviceOwner() {
144148
public Set<? extends IP> getFixedIps() {
145149
return fixedIps;
146150
}
151+
152+
/**
153+
* {@inheritDoc}
154+
*/
155+
@Override
156+
public Set<? extends AllowedAddressPair> getAllowedAddressPairs() {
157+
return allowedAddressPairs;
158+
}
147159

148160
/**
149161
* {@inheritDoc}
@@ -194,6 +206,7 @@ public String toString() {
194206
.add("id", id).add("name", name).add("adminStateUp", adminStateUp).add("deviceId", deviceId)
195207
.add("deviceOwner", deviceOwner).add("fixedIps", fixedIps).add("macAddress", macAddress)
196208
.add("networkId", networkId).add("tenantId", tenantId).add("securityGroups", securityGroups)
209+
.add("allowed_address_pairs", allowedAddressPairs)
197210
.toString();
198211
}
199212

@@ -271,6 +284,33 @@ public PortBuilder removeFixedIp(String address, String subnetId) {
271284

272285
return this;
273286
}
287+
288+
@Override
289+
public PortBuilder allowedAddressPair(String address) {
290+
if (m.allowedAddressPairs == null)
291+
m.allowedAddressPairs = Sets.newHashSet();
292+
293+
m.allowedAddressPairs.add(new NeutronAllowedAddressPair(address));
294+
return this;
295+
}
296+
297+
@Override
298+
public PortBuilder removeAddressPair(String address) {
299+
if (m.allowedAddressPairs == null)
300+
m.allowedAddressPairs = Sets.newHashSet();
301+
302+
Iterator<NeutronAllowedAddressPair> iter = m.allowedAddressPairs.iterator();
303+
304+
while (iter.hasNext()) {
305+
NeutronAllowedAddressPair allowedAddress = iter.next();
306+
if (allowedAddress.getIpAddress() != null && allowedAddress.getIpAddress().equals(address)) {
307+
iter.remove();
308+
}
309+
}
310+
311+
return this;
312+
}
313+
274314

275315
@Override
276316
public PortBuilder adminState(boolean adminStateUp) {
@@ -300,11 +340,11 @@ protected Port reference() {
300340
return m;
301341
}
302342

303-
@Override
304-
public PortBuilder extraDhcpOpt(ExtraDhcpOptCreate extraDhcpOptCreate) {
305-
m.extraDhcpOptCreates.add((NeutronExtraDhcpOptCreate)extraDhcpOptCreate);
306-
return this;
307-
}
343+
@Override
344+
public PortBuilder extraDhcpOpt(ExtraDhcpOptCreate extraDhcpOptCreate) {
345+
m.extraDhcpOptCreates.add((NeutronExtraDhcpOptCreate)extraDhcpOptCreate);
346+
return this;
347+
}
308348

309349
@Override
310350
public PortBuilder securityGroup(String groupName) {
@@ -314,9 +354,5 @@ public PortBuilder securityGroup(String groupName) {
314354
m.securityGroups.add(groupName);
315355
return this;
316356
}
317-
318-
319-
320-
321357
}
322358
}

0 commit comments

Comments
 (0)