Skip to content

Commit 8f2d95d

Browse files
committed
Issue #11 - added alternate method for adding floating IP without the fixed address param
1 parent e411756 commit 8f2d95d

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/main/java/org/openstack4j/api/compute/ComputeFloatingIPService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ public interface ComputeFloatingIPService extends RestService {
5656
*/
5757
ActionResponse addFloatingIP(Server server, String fixedIpAddress, String ipAddress);
5858

59+
/**
60+
* Adds floating-ip to server.
61+
*
62+
* @param server the server
63+
* @param ipAddress the ip address
64+
* @return the action response
65+
*/
66+
ActionResponse addFloatingIP(Server server, String ipAddress);
67+
5968
/**
6069
* Remove floating-ip from server
6170
*

src/main/java/org/openstack4j/openstack/compute/internal/ComputeFloatingIPServiceImpl.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public void deallocateIP(String id) {
5959
*/
6060
@Override
6161
public ActionResponse addFloatingIP(Server server, String fixedIpAddress, String ipAddress) {
62+
if (fixedIpAddress == null)
63+
return addFloatingIP(server, ipAddress);
64+
6265
checkNotNull(server);
6366
checkNotNull(fixedIpAddress);
6467
checkNotNull(ipAddress);
@@ -69,6 +72,21 @@ public ActionResponse addFloatingIP(Server server, String fixedIpAddress, String
6972
String uri = uri("/servers/%s/action", server.getId());
7073
return invokeAction(uri, action, innerJson);
7174
}
75+
76+
/**
77+
* {@inheritDoc}
78+
*/
79+
@Override
80+
public ActionResponse addFloatingIP(Server server, String ipAddress) {
81+
checkNotNull(server);
82+
checkNotNull(ipAddress);
83+
84+
String action = "addFloatingIp";
85+
String innerJson = String.format("{ \"address\": \"%s\" }", ipAddress);
86+
87+
String uri = uri("/servers/%s/action", server.getId());
88+
return invokeAction(uri, action, innerJson);
89+
}
7290

7391
/**
7492
* {@inheritDoc}

0 commit comments

Comments
 (0)