Skip to content

Commit 2ee0490

Browse files
committed
floating ips stuff
1 parent 2a86ea8 commit 2ee0490

53 files changed

Lines changed: 685 additions & 517 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

openstack-api/src/main/java/org/openstack/api/compute/ServerActionResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public ServerActionResource(Target target) {
1515
super(target);
1616
}
1717

18-
public Server post(ServerAction action) {
19-
return target.request(MediaType.APPLICATION_JSON).post(Entity.entity(action, MediaType.APPLICATION_JSON), NovaServer.class);
18+
public <T> T post(ServerAction action, Class<T> type) {
19+
return target.request(MediaType.APPLICATION_JSON).post(Entity.entity(action, MediaType.APPLICATION_JSON), type);
2020
}
2121

2222
}
Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package org.openstack.api.compute.ext;
22

3-
import java.util.HashMap;
4-
import java.util.Map;
5-
63
import javax.ws.rs.client.Target;
74
import javax.ws.rs.core.MediaType;
85

96
import org.openstack.api.common.Resource;
10-
import org.openstack.model.compute.nova.floatingip.NovaCreateFloatingIpResponse;
7+
import org.openstack.model.compute.FloatingIp;
8+
import org.openstack.model.compute.FloatingIpList;
9+
import org.openstack.model.compute.nova.floatingip.NovaFloatingIp;
1110
import org.openstack.model.compute.nova.floatingip.NovaFloatingIpList;
1211

1312
/**
@@ -20,40 +19,25 @@
2019
// TODO: Is this an OpenStack bug or an HP bug?
2120
public class FloatingIpsResource extends Resource {
2221

23-
protected FloatingIpsResource(Target target) {
22+
public FloatingIpsResource(Target target) {
2423
super(target);
2524
}
26-
27-
public NovaFloatingIpList get() {
28-
return get(new HashMap<String, Object>());
29-
}
3025

3126
/**
3227
* Return a list of floating ips allocated to a project.
3328
*
3429
* @return
3530
*/
36-
public NovaFloatingIpList get(Map<String, Object> properties) {
31+
public FloatingIpList get() {
3732
return target.request(MediaType.APPLICATION_JSON).get(NovaFloatingIpList.class);
3833
}
3934

40-
public NovaCreateFloatingIpResponse post() {
41-
throw new UnsupportedOperationException();
35+
public FloatingIp post(String pool) {
36+
return target.request(MediaType.APPLICATION_JSON).post(null,NovaFloatingIp.class);
4237
}
4338

44-
public NovaCreateFloatingIpResponse post(Map<String,Object> properties, String pool) {
45-
throw new UnsupportedOperationException();
46-
//return target.request(MediaType.APPLICATION_JSON).post(rule, NovaCreateFloatingIpResponse.class);
47-
}
48-
49-
50-
51-
public FloatingIpResource floatingIp(String id) {
39+
public FloatingIpResource floatingIp(Integer id) {
5240
return new FloatingIpResource(target.path("/{id}").pathParam("id", id));
5341
}
5442

55-
56-
57-
58-
5943
}

openstack-api/src/main/java/org/openstack/api/compute/ext/VolumeResource.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package org.openstack.api.compute.ext;
22

3-
import java.util.HashMap;
4-
53
import javax.ws.rs.client.Target;
64
import javax.ws.rs.core.MediaType;
75

86
import org.openstack.api.common.Resource;
97
import org.openstack.model.compute.Volume;
10-
import org.openstack.model.compute.nova.securitygroup.NovaSecurityGroup;
118
import org.openstack.model.compute.nova.volume.NovaVolume;
129

1310
public class VolumeResource extends Resource {
@@ -21,11 +18,11 @@ public VolumeResource(Target target) {
2118
*
2219
* @return
2320
*/
24-
public Volume get(HashMap<String, Object> properties) {
21+
public Volume get() {
2522
return target.request(MediaType.APPLICATION_JSON).get(NovaVolume.class);
2623
}
2724

28-
public void delete(HashMap<String, Object> properties) {
25+
public void delete() {
2926
target.request().delete();
3027
}
3128

openstack-api/src/main/java/org/openstack/api/compute/ext/VolumesResource.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package org.openstack.api.compute.ext;
22

3-
import java.util.HashMap;
4-
import java.util.Map;
5-
3+
import javax.ws.rs.client.Entity;
64
import javax.ws.rs.client.Target;
75
import javax.ws.rs.core.MediaType;
86

97
import org.openstack.api.common.Resource;
10-
import org.openstack.api.compute.ImageResource;
8+
import org.openstack.model.compute.Volume;
119
import org.openstack.model.compute.VolumeList;
1210
import org.openstack.model.compute.nova.volume.NovaVolumeList;
1311

@@ -23,23 +21,18 @@ public VolumesResource(Target target) {
2321
super(target);
2422
}
2523

26-
public VolumeList get() {
27-
Map<String, Object> properties = new HashMap<String, Object>();
28-
properties.put("detail",true);
29-
return get(properties);
30-
}
31-
3224
/**
3325
* Returns the list of volume types
3426
*
3527
* @return
3628
*/
37-
public VolumeList get(Map<String, Object> properties) {
38-
if(properties.get("detail") != null) {
39-
target = target.path("/detail");
40-
}
29+
public VolumeList get() {
4130
return target.request(MediaType.APPLICATION_JSON).get(NovaVolumeList.class);
4231
}
32+
33+
public Volume post(Volume volume) {
34+
return target.request(MediaType.APPLICATION_JSON).post(Entity.entity(volume, MediaType.APPLICATION_JSON), Volume.class);
35+
}
4336

4437
/**
4538
* Creates a new volume type.

openstack-api/src/main/java/org/openstack/client/OpenStackClient.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.openstack.model.identity.Service;
2626
import org.openstack.model.identity.ServiceEndpoint;
2727
import org.openstack.model.identity.keystone.KeystoneAuthentication;
28+
import org.openstack.model.identity.keystone.ServiceCatalogEntry;
2829

2930
import com.google.common.base.Preconditions;
3031
import com.google.common.base.Predicate;
@@ -164,19 +165,17 @@ private <T extends Resource> T target(String absoluteURL, Class<T> clazz, boolea
164165
private ServiceEndpoint getEndpoint(final String type, final String region) {
165166
Preconditions.checkNotNull(access, "You must be authenticated before get a identity client");
166167
try {
167-
Service service = Iterables.find(access.getServices(), new Predicate<Service>() {
168+
ServiceCatalogEntry service = Iterables.find(access.getServices(), new Predicate<ServiceCatalogEntry>() {
168169

169170
@Override
170-
public boolean apply(Service service) {
171-
System.out.println(service);
171+
public boolean apply(ServiceCatalogEntry service) {
172172
return type.equals(service.getType());
173173
}
174174

175175
});
176-
List<? extends ServiceEndpoint> endpoints = service.getEndpoints();
176+
List<ServiceEndpoint> endpoints = service.getEndpoints();
177177
if (region != null) {
178-
return Iterables.find(endpoints,
179-
new Predicate<ServiceEndpoint>() {
178+
return Iterables.find(endpoints, new Predicate<ServiceEndpoint>() {
180179

181180
@Override
182181
public boolean apply(ServiceEndpoint endpoint) {

openstack-api/src/main/java/org/openstack/model/compute/FloatingIp.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
public interface FloatingIp {
44

5-
String getId();
5+
Integer getId();
66

77
String getIp();
88

99
String getPool();
1010

1111
String getInstanceId();
1212

13+
String getFixedIp();
14+
1315
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.openstack.model.compute;
2+
3+
import java.util.List;
4+
5+
public interface FloatingIpList {
6+
7+
List<FloatingIp> getList();
8+
9+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.openstack.model.compute;
22

3-
public interface ServerAction {
3+
import java.io.Serializable;
4+
5+
public interface ServerAction extends Serializable {
46

57
}

openstack-api/src/main/java/org/openstack/model/compute/nova/floatingip/NovaFloatingIp.java

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
import javax.xml.bind.annotation.XmlAttribute;
88
import javax.xml.bind.annotation.XmlRootElement;
99

10+
import org.openstack.model.common.JsonRootElement;
1011
import org.openstack.model.compute.FloatingIp;
1112

1213
@XmlRootElement(name = "floating_ip", namespace = "")
1314
@XmlAccessorType(XmlAccessType.NONE)
15+
@JsonRootElement("floating_ip")
1416
public class NovaFloatingIp implements Serializable, FloatingIp {
1517

1618
@XmlAttribute
17-
private String id;
19+
private Integer id;
1820

1921
@XmlAttribute
2022
private String ip;
@@ -29,19 +31,19 @@ public class NovaFloatingIp implements Serializable, FloatingIp {
2931
private String fixedIp;
3032

3133
/* (non-Javadoc)
32-
* @see org.openstack.model.compute.FloatingIp#getId()
34+
* @see org.openstack.model.compute.nova.floatingip.FloatingIp#getId()
3335
*/
3436
@Override
35-
public String getId() {
37+
public Integer getId() {
3638
return id;
3739
}
3840

39-
public void setId(String id) {
41+
public void setId(Integer id) {
4042
this.id = id;
4143
}
4244

4345
/* (non-Javadoc)
44-
* @see org.openstack.model.compute.FloatingIp#getIp()
46+
* @see org.openstack.model.compute.nova.floatingip.FloatingIp#getIp()
4547
*/
4648
@Override
4749
public String getIp() {
@@ -53,7 +55,7 @@ public void setIp(String ip) {
5355
}
5456

5557
/* (non-Javadoc)
56-
* @see org.openstack.model.compute.FloatingIp#getPool()
58+
* @see org.openstack.model.compute.nova.floatingip.FloatingIp#getPool()
5759
*/
5860
@Override
5961
public String getPool() {
@@ -64,13 +66,8 @@ public void setPool(String pool) {
6466
this.pool = pool;
6567
}
6668

67-
@Override
68-
public String toString() {
69-
return "FloatingIp [id=" + id + ", ip=" + ip + ", pool=" + pool + "]";
70-
}
71-
7269
/* (non-Javadoc)
73-
* @see org.openstack.model.compute.FloatingIp#getInstanceId()
70+
* @see org.openstack.model.compute.nova.floatingip.FloatingIp#getInstanceId()
7471
*/
7572
@Override
7673
public String getInstanceId() {
@@ -81,4 +78,22 @@ public void setInstanceId(String instanceId) {
8178
this.instanceId = instanceId;
8279
}
8380

81+
/* (non-Javadoc)
82+
* @see org.openstack.model.compute.nova.floatingip.FloatingIp#getFixedIp()
83+
*/
84+
@Override
85+
public String getFixedIp() {
86+
return fixedIp;
87+
}
88+
89+
public void setFixedIp(String fixedIp) {
90+
this.fixedIp = fixedIp;
91+
}
92+
93+
@Override
94+
public String toString() {
95+
return "NovaFloatingIp [id=" + id + ", ip=" + ip + ", pool=" + pool
96+
+ ", instanceId=" + instanceId + ", fixedIp=" + fixedIp + "]";
97+
}
98+
8499
}
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.openstack.model.compute.nova.floatingip;
22

3-
import java.util.Iterator;
3+
import java.io.Serializable;
44
import java.util.List;
55

66
import javax.xml.bind.annotation.XmlAccessType;
@@ -9,26 +9,31 @@
99
import javax.xml.bind.annotation.XmlElementWrapper;
1010
import javax.xml.bind.annotation.XmlRootElement;
1111

12+
import org.openstack.model.compute.FloatingIp;
13+
import org.openstack.model.compute.FloatingIpList;
14+
15+
import com.google.gson.annotations.SerializedName;
16+
1217
@XmlRootElement(name="floating_ips", namespace="")
1318
@XmlAccessorType(XmlAccessType.NONE)
14-
public class NovaFloatingIpList implements Iterable<NovaFloatingIp> {
19+
public class NovaFloatingIpList implements Serializable, FloatingIpList {
1520

1621
@XmlElementWrapper(name = "floating_ips")
1722
@XmlElement(name = "floating_ip")
23+
@SerializedName("floating_ips")
1824
private List<NovaFloatingIp> list;
1925

20-
public List<NovaFloatingIp> getList() {
21-
return list;
26+
/* (non-Javadoc)
27+
* @see org.openstack.model.compute.nova.floatingip.FloatingIpList#getList()
28+
*/
29+
@Override
30+
public List<FloatingIp> getList() {
31+
return (List<FloatingIp>) (List<?>) list;
2232
}
2333

2434
public void setList(List<NovaFloatingIp> list) {
2535
this.list = list;
2636
}
27-
28-
@Override
29-
public Iterator<NovaFloatingIp> iterator() {
30-
return getList().iterator();
31-
}
3237

3338
}
3439

0 commit comments

Comments
 (0)