Skip to content
Permalink
Browse files
JCLOUDS-1328: Update ProfitBricks to the latest API version
  • Loading branch information
alibazlamit authored and nacx committed Sep 8, 2017
1 parent 948fa2b commit 0422e623b2970a03afdd3aa23901b958cd1859aa
Showing 29 changed files with 205 additions and 111 deletions.
@@ -32,7 +32,7 @@
<packaging>bundle</packaging>

<properties>
<test.profitbricks-rest.endpoint>https://api.profitbricks.com/cloudapi/v3/</test.profitbricks-rest.endpoint>
<test.profitbricks-rest.endpoint>https://api.profitbricks.com/cloudapi/v4/</test.profitbricks-rest.endpoint>
<test.profitbricks-rest.identity>FIXME</test.profitbricks-rest.identity>
<test.profitbricks-rest.credential>FIXME</test.profitbricks-rest.credential>
<test.profitbricks-rest.api-version>1.3</test.profitbricks-rest.api-version>
@@ -54,7 +54,7 @@ protected Builder() {
.identityName("API Username")
.credentialName("API Password")
.documentation(URI.create("https://devops.profitbricks.com/api/rest/"))
.defaultEndpoint("https://api.profitbricks.com/cloudapi/v3/")
.defaultEndpoint("https://api.profitbricks.com/cloudapi/v4/")
.view(ComputeServiceContext.class)
.defaultProperties(ProfitBricksApiMetadata.defaultProperties())
.defaultModules(ImmutableSet.<Class<? extends Module>>builder()
@@ -25,6 +25,7 @@
import static org.jclouds.Constants.PROPERTY_CONNECTION_TIMEOUT;
import static org.jclouds.Constants.PROPERTY_ISO3166_CODES;
import static org.jclouds.Constants.PROPERTY_SO_TIMEOUT;
import static org.jclouds.compute.config.ComputeServiceProperties.TEMPLATE;
import static org.jclouds.location.reference.LocationConstants.ISO3166_CODES;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
@@ -68,6 +69,7 @@ public static Properties defaultProperties() {
properties.setProperty(PROPERTY_ZONE + ".us/ewr." + ISO3166_CODES, "US-NJ");
properties.setProperty(PROPERTY_ZONE + ".us/las." + ISO3166_CODES, "US-NV");
properties.setProperty(PROPERTY_ZONE + ".us/lasdev." + ISO3166_CODES, "US-NV");
properties.put(TEMPLATE, "imageNameMatches=Ubuntu,osVersionMatches=1[467]\\.04");

properties.put("jclouds.ssh.max-retries", "7");
properties.put("jclouds.ssh.retry-auth", "true");
@@ -92,7 +94,7 @@ protected Builder() {
.homepage(URI.create("https://www.profitbricks.com/"))
.console(URI.create("https://my.profitbricks.com/dashboard/dcdr2"))
.iso3166Codes("DE-BW", "DE-HE", "US-NJ", "US-NV")
.endpoint("https://api.profitbricks.com/cloudapi/v3/")
.endpoint("https://api.profitbricks.com/cloudapi/v4/")
.defaultProperties(ProfitBricksProviderMetadata.defaultProperties());
}

@@ -32,7 +32,7 @@ public class UpdateLanRequestBinder extends BaseProfitBricksRequestBinder<Lan.Re
private String lanId;

@Inject
UpdateLanRequestBinder(Json jsonBinder, @Provider Supplier<URI> endpointSupplier) {
UpdateLanRequestBinder(Json jsonBinder, @Provider Supplier<URI> endpointSupplier) {
super("lan", jsonBinder, endpointSupplier);
}

@@ -42,18 +42,22 @@ protected String createPayload(Lan.Request.UpdatePayload payload) {
checkNotNull(payload, "payload");
checkNotNull(payload.dataCenterId(), "dataCenterId");
checkNotNull(payload.id(), "id");

dataCenterId = payload.dataCenterId();
lanId = payload.id();

if (payload.isPublic() != null)
requestBuilder.put("public", payload.isPublic());


if (payload.isPublic() != null) {
requestBuilder.put("public", payload.isPublic());
}
if (payload.ipFailover() != null) {
requestBuilder.put("ipFailover", payload.ipFailover());
}

return jsonBinder.toJson(requestBuilder);
}

@Override
protected <R extends HttpRequest> R createRequest(R fromRequest, String payload) {
protected <R extends HttpRequest> R createRequest(R fromRequest, String payload) {
return super.createRequest(genRequest(String.format("datacenters/%s/lans/%s", dataCenterId, lanId), fromRequest), payload);
}

@@ -16,17 +16,17 @@
*/
package org.apache.jclouds.profitbricks.rest.binder.volume;

import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Supplier;
import com.google.inject.Inject;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import org.apache.jclouds.profitbricks.rest.binder.BaseProfitBricksRequestBinder;
import org.apache.jclouds.profitbricks.rest.domain.Volume;
import org.jclouds.http.HttpRequest;
import org.jclouds.json.Json;
import com.google.common.base.Supplier;
import java.net.URI;
import org.jclouds.location.Provider;
import static com.google.common.base.Preconditions.checkNotNull;

public class CreateVolumeRequestBinder extends BaseProfitBricksRequestBinder<Volume.Request.CreatePayload> {

@@ -63,6 +63,9 @@ protected String createPayload(Volume.Request.CreatePayload payload) {
if (payload.imagePassword() != null)
properties.put("imagePassword", payload.imagePassword());

if (payload.imageAlias() != null)
properties.put("imageAlias", payload.imageAlias());

if (payload.image() != null)
properties.put("image", payload.image());
else if (payload.licenceType() != null)
@@ -34,6 +34,8 @@
import static java.lang.String.format;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
@@ -146,6 +148,7 @@ protected NodeAndInitialCredentials<ServerInDataCenter> createNodeWithGroupEncod
Hardware hardware = template.getHardware();
TemplateOptions options = template.getOptions();
final String loginUser = isNullOrEmpty(options.getLoginUser()) ? "root" : options.getLoginUser();
final String pubKey = options.getPublicKey();
final String password = options.hasLoginPassword() ? options.getLoginPassword() : Passwords.generate();
final org.jclouds.compute.domain.Image image = template.getImage();
final int[] inboundPorts = template.getOptions().getInboundPorts();
@@ -165,7 +168,11 @@ protected NodeAndInitialCredentials<ServerInDataCenter> createNodeWithGroupEncod
Provisionable.Type provisionableType = Provisionable.Type.fromValue(
image.getUserMetadata().get(ProvisionableToImage.KEY_PROVISIONABLE_TYPE));
if (provisionableType == Provisionable.Type.IMAGE) {
request.imagePassword(password);
if (pubKey != null) {
request.sshKeys(new HashSet<String>(Arrays.asList(pubKey)));
} else {
request.imagePassword(password);
}
}

}
@@ -347,6 +354,7 @@ public Object get() {

LoginCredentials serverCredentials = LoginCredentials.builder()
.user(loginUser)
.privateKey(pubKey)
.password(password)
.build();

@@ -17,6 +17,8 @@
package org.apache.jclouds.profitbricks.rest.domain;

import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import static com.google.common.collect.ImmutableList.copyOf;
import java.util.List;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;
@@ -25,7 +27,7 @@
public abstract class Lan extends Trackable {

public abstract String id();

@Nullable
public abstract String dataCenterId();

@@ -49,14 +51,32 @@ public static Lan create(String id, String dataCenterId, String type, String hre

@AutoValue
public abstract static class Properties {

@Nullable
public abstract String name();

public abstract boolean isPublic();

@SerializedNames({"name", "public"})
public static Properties create(String name, boolean isPublic) {
return new AutoValue_Lan_Properties(name, isPublic);

@Nullable
public abstract List<IpFailover> ipFailover();

@SerializedNames({"name", "public", "ipFailover"})
public static Properties create(String name, boolean isPublic, List<IpFailover> ipFailover) {
return new AutoValue_Lan_Properties(name, isPublic, ipFailover == null ? ImmutableList.<IpFailover>of() : copyOf(ipFailover));
}
}

@AutoValue
public abstract static class IpFailover {

@Nullable
public abstract String ip();

public abstract String nicUuid();

@SerializedNames({"ip", "nicUuid"})
public static IpFailover create(String ip, String nicUuid) {
return new AutoValue_Lan_IpFailover(ip, nicUuid);
}
}

@@ -71,8 +91,7 @@ public static Entities create(Nics nics) {
}

}



public static final class Request {

public static CreatePayload.Builder creatingBuilder() {
@@ -82,7 +101,7 @@ public static CreatePayload.Builder creatingBuilder() {
public static UpdatePayload.Builder updatingBuilder() {
return new AutoValue_Lan_Request_UpdatePayload.Builder();
}

@AutoValue
public abstract static class CreatePayload {

@@ -94,15 +113,18 @@ public abstract static class CreatePayload {

@Nullable
public abstract List<Nic> nics();

public abstract String dataCenterId();

@AutoValue.Builder
public abstract static class Builder {

public abstract Builder name(String name);

public abstract Builder isPublic(Boolean isPublic);

public abstract Builder nics(List<Nic> nics);

public abstract Builder dataCenterId(String dataCenterId);

abstract CreatePayload autoBuild();
@@ -118,24 +140,33 @@ public CreatePayload build() {
public abstract static class UpdatePayload {

public abstract Boolean isPublic();

public abstract String dataCenterId();

public abstract String id();

@Nullable
public abstract List<IpFailover> ipFailover();

@AutoValue.Builder
public abstract static class Builder {

public abstract Builder isPublic(Boolean isPublic);

public abstract Builder dataCenterId(String dataCenterId);

public abstract Builder id(String id);

public abstract Builder ipFailover(List<IpFailover> ipFailover);

abstract UpdatePayload autoBuild();

public UpdatePayload build() {
return autoBuild();
}
}
}

}

}
@@ -148,6 +148,9 @@ public abstract static class CreatePayload {

@Nullable
public abstract String image();

@Nullable
public abstract String imageAlias();

@Nullable
public abstract AvailabilityZone availabilityZone();
@@ -177,7 +180,9 @@ public abstract static class Builder {
public abstract Builder availabilityZone(AvailabilityZone size);

public abstract Builder image(String image);


public abstract Builder imageAlias(String imageAlias);

public abstract Builder imagePassword(String imagePassword);

public abstract Builder bus(Properties.BusType bus);
@@ -196,8 +201,8 @@ public CreatePayload build() {
}

checkArgument(
payload.image() != null || payload.licenceType() != null,
"Either image or licenceType need to be present"
payload.image() != null || payload.licenceType() != null || payload.imageAlias() != null,
"Either image, imageAlias or licenceType need to be present"
);

return payload;
@@ -51,7 +51,7 @@ public void testUpdatePayload() {
actual
);

assertEquals(request.getEndpoint().getPath(), "/cloudapi/v3/datacenters/datacenter-id/servers/server-id/nics/nic-id/firewallrules");
assertEquals(request.getEndpoint().getPath(), "/cloudapi/v4/datacenters/datacenter-id/servers/server-id/nics/nic-id/firewallrules");
assertNotNull(actual, "Binder returned null payload");

Json json = injector.getInstance(Json.class);
@@ -48,7 +48,7 @@ public void testUpdatePayload() {
actual
);

assertEquals(request.getEndpoint().getPath(), "/cloudapi/v3/datacenters/datacenter-id/servers/server-id/nics/nic-id/firewallrules/id");
assertEquals(request.getEndpoint().getPath(), "/cloudapi/v4/datacenters/datacenter-id/servers/server-id/nics/nic-id/firewallrules/id");
assertNotNull(actual, "Binder returned null payload");

Json json = injector.getInstance(Json.class);
@@ -46,7 +46,7 @@ public void testUpdatePayload() {
actual
);

assertEquals(request.getEndpoint().getPath(), "/cloudapi/v3/images/some-id");
assertEquals(request.getEndpoint().getPath(), "/cloudapi/v4/images/some-id");
assertNotNull(actual, "Binder returned null payload");

Json json = injector.getInstance(Json.class);
@@ -46,7 +46,7 @@ public void testUpdatePayload() {
actual
);

assertEquals(request.getEndpoint().getPath(), "/cloudapi/v3/datacenters/datacenter-id/lans");
assertEquals(request.getEndpoint().getPath(), "/cloudapi/v4/datacenters/datacenter-id/lans");
assertNotNull(actual, "Binder returned null payload");

Json json = injector.getInstance(Json.class);
@@ -46,7 +46,7 @@ public void testUpdatePayload() {
actual
);

assertEquals(request.getEndpoint().getPath(), "/cloudapi/v3/datacenters/datacenter-id/lans/lan-id");
assertEquals(request.getEndpoint().getPath(), "/cloudapi/v4/datacenters/datacenter-id/lans/lan-id");
assertNotNull(actual, "Binder returned null payload");

Json json = injector.getInstance(Json.class);
@@ -48,7 +48,7 @@ public void testUpdatePayload() {
actual
);

assertEquals(request.getEndpoint().getPath(), "/cloudapi/v3/datacenters/datacenter-id/servers/server-id/nics");
assertEquals(request.getEndpoint().getPath(), "/cloudapi/v4/datacenters/datacenter-id/servers/server-id/nics");
assertNotNull(actual, "Binder returned null payload");

Json json = injector.getInstance(Json.class);
@@ -47,7 +47,7 @@ public void testUpdatePayload() {
actual
);

assertEquals(request.getEndpoint().getPath(), "/cloudapi/v3/datacenters/datacenter-id/servers/server-id/nics/nic-id");
assertEquals(request.getEndpoint().getPath(), "/cloudapi/v4/datacenters/datacenter-id/servers/server-id/nics/nic-id");
assertNotNull(actual, "Binder returned null payload");

Json json = injector.getInstance(Json.class);
@@ -48,7 +48,7 @@ public void testCreatePayload() {
actual
);

assertEquals(request.getEndpoint().getPath(), "/cloudapi/v3/datacenters/datacenter-id/servers/server-id/cdroms");
assertEquals(request.getEndpoint().getPath(), "/cloudapi/v4/datacenters/datacenter-id/servers/server-id/cdroms");
assertNotNull(actual, "Binder returned null payload");

Json json = injector.getInstance(Json.class);
@@ -48,7 +48,7 @@ public void testCreatePayload() {
actual
);

assertEquals(request.getEndpoint().getPath(), "/cloudapi/v3/datacenters/datacenter-id/servers/server-id/volumes");
assertEquals(request.getEndpoint().getPath(), "/cloudapi/v4/datacenters/datacenter-id/servers/server-id/volumes");
assertNotNull(actual, "Binder returned null payload");

Json json = injector.getInstance(Json.class);

0 comments on commit 0422e62

Please sign in to comment.