Skip to content

Commit 3e8af64

Browse files
committed
hpcloud support
1 parent 9d1b8af commit 3e8af64

File tree

17 files changed

+227
-79
lines changed

17 files changed

+227
-79
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@
8080
<dependency>
8181
<groupId>org.glassfish.jersey.core</groupId>
8282
<artifactId>jersey-client</artifactId>
83-
<version>2.0-m03</version>
83+
<version>2.0-SNAPSHOT</version>
8484
</dependency>
8585
<dependency>
8686
<groupId>org.glassfish.jersey.media</groupId>
8787
<artifactId>jersey-media-json</artifactId>
88-
<version>2.0-m03</version>
88+
<version>2.0-SNAPSHOT</version>
8989
</dependency>
9090
</dependencies>
9191

src/main/java/org/openstack/api/common/RestClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import org.codehaus.jackson.map.introspect.JacksonAnnotationIntrospector;
1515
import org.glassfish.jersey.client.JerseyClient;
1616
import org.glassfish.jersey.client.JerseyClientFactory;
17-
import org.glassfish.jersey.media.json.JsonFeature;
17+
import org.glassfish.jersey.media.json.JsonJacksonFeature;
1818

1919
public enum RestClient {
2020

@@ -28,7 +28,7 @@ private RestClient() {
2828

2929
client = (JerseyClient) JerseyClientFactory.newClient();
3030

31-
client.configuration().enable(new JsonFeature());
31+
client.configuration().enable(new JsonJacksonFeature());
3232

3333
client.configuration().register(OpenStackObjectMapperProvider.class);
3434

src/main/java/org/openstack/api/compute/FlavorsResource.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.Properties;
44

55
import javax.ws.rs.client.Target;
6+
import javax.ws.rs.core.MediaType;
67

78
import org.openstack.api.common.Resource;
89
import org.openstack.model.compute.FlavorList;
@@ -15,7 +16,7 @@ public FlavorsResource(Target target, Properties properties) {
1516
}
1617

1718
public FlavorList get() {
18-
return target.path("/detail").request().get(NovaFlavorList.class);
19+
return target.path("/detail").request(MediaType.APPLICATION_JSON).get(NovaFlavorList.class);
1920
}
2021

2122
public FlavorResource flavor(String id) {

src/main/java/org/openstack/api/compute/ServersResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public ServersResource(Target target, Properties properties) {
3232
* @return
3333
*/
3434
public ServerList get() {
35-
return target.path("/detail").request().get(NovaServerList.class);
35+
return target.path("/detail").request(MediaType.APPLICATION_JSON).get(NovaServerList.class);
3636
}
3737

3838
public Server post(ServerForCreate serverForCreate) {

src/main/java/org/openstack/api/identity/resources/TokensResource.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,9 @@ public TokensResource(Target target, Properties properties) {
2020
public Access post(Authentication authentication) {
2121
return target.request(MediaType.APPLICATION_JSON).post(Entity.json(authentication), KeystoneAccess.class);
2222
}
23+
24+
public <T> T post(Authentication authentication, Class<T> type) {
25+
return target.request(MediaType.APPLICATION_JSON).post(Entity.json(authentication), type);
26+
}
2327

2428
}

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
import java.io.IOException;
44
import java.util.Properties;
5-
import java.util.logging.Logger;
65

76
import javax.ws.rs.client.Target;
87

9-
import org.glassfish.jersey.filter.LoggingFilter;
108
import org.openstack.api.common.Resource;
119
import org.openstack.api.common.RestClient;
1210
import org.openstack.api.compute.TenantResource;
@@ -52,17 +50,31 @@ public static OpenStackClient authenticate(Properties properties, Access access)
5250
public static OpenStackClient authenticate(Properties properties) {
5351
OpenStackClient client = new OpenStackClient();
5452
client.properties = properties;
55-
String username = properties.getProperty("auth.username");
56-
String password = properties.getProperty("auth.password");
57-
String tenantId = properties.getProperty("auth.tenant.id");
58-
String tenantName = properties.getProperty("auth.tenant.name");
59-
KeystoneAuthentication authentication = new KeystoneAuthentication().withPasswordCredentials(username, password);
53+
54+
String credentials = properties.getProperty("auth.credentials");
55+
56+
KeystoneAuthentication authentication = null;
57+
58+
if("apiAccessKeyCredentials".equals(credentials)) {
59+
String accessKey = properties.getProperty("auth.accessKey");
60+
String secretKey = properties.getProperty("auth.secretKey");
61+
authentication = KeystoneAuthentication.withApiAccessKeyCredentials(accessKey, secretKey);
62+
} else {
63+
String username = properties.getProperty("auth.username");
64+
String password = properties.getProperty("auth.password");
65+
authentication = KeystoneAuthentication.withPasswordCredentials(username, password);
66+
}
67+
68+
String tenantId = properties.getProperty("auth.tenantId");
69+
String tenantName = properties.getProperty("auth.tenantName");
70+
6071
if(tenantId != null) {
6172
authentication.setTenantId(tenantId);
6273
} else if(tenantName != null) {
6374
authentication.setTenantName(tenantName);
6475
}
6576
Access access = client.getIdentityEndpoint().tokens().post(authentication);
77+
System.out.println(access);
6678
return authenticate(properties, access);
6779
}
6880

@@ -83,7 +95,7 @@ public void reauthenticateOnTenant(String tenantName) {
8395

8496
public void exchangeTokenForTenant(String tenantId) {
8597
String endpoint = properties.getProperty("identity.endpoint.publicURL");
86-
Authentication authentication = new KeystoneAuthentication().withTokenAndTenant(access.getToken().getId(), tenantId);
98+
Authentication authentication = KeystoneAuthentication.withTokenAndTenant(access.getToken().getId(), tenantId);
8799
this.access = target(endpoint, IdentityPublicEndpoint.class).tokens().post(authentication);
88100
System.out.println("EX " + this.access);
89101
}

src/main/java/org/openstack/model/compute/nova/securitygroup/NovaSecurityGroupRule.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static final class Group implements Serializable {
2424
private String name;
2525

2626
@XmlElement(name = "tenant_id")
27+
@JsonProperty("tenant_id")
2728
private String tenantId;
2829

2930
public String getName() {

src/main/java/org/openstack/model/identity/Authentication.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package org.openstack.model.identity;
22

3-
import org.openstack.model.identity.keystone.KeystoneAuthentication.PasswordCredentials;
4-
53
public interface Authentication {
64

75
Token getToken();
86

97
//void setToken(Token token);
108

11-
PasswordCredentials getPasswordCredentials();
9+
Credentials getCredentials();
1210

1311
//void setPasswordCredentials(PasswordCredentials passwordCredentials);
1412

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.openstack.model.identity;
2+
3+
public interface Credentials {
4+
5+
}

src/main/java/org/openstack/model/identity/Endpoint.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,4 @@ public interface Endpoint {
2626

2727
void setInternalURL(String internalURL);
2828

29-
30-
3129
}

0 commit comments

Comments
 (0)