Skip to content
Permalink
Browse files
Support REST API v3 in ProfitBricks
  • Loading branch information
alibazlamit authored and nacx committed Oct 31, 2016
1 parent bf9ed5b commit 61e5651beabcd9f90a14d96eda9ffe64a33007bd
Show file tree
Hide file tree
Showing 26 changed files with 286 additions and 212 deletions.
@@ -32,7 +32,7 @@
<packaging>bundle</packaging>

<properties>
<test.profitbricks-rest.endpoint>https://api.profitbricks.com/rest/v2/</test.profitbricks-rest.endpoint>
<test.profitbricks-rest.endpoint>https://api.profitbricks.com/cloudapi/v3/</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/rest/v2/")
.defaultEndpoint("https://api.profitbricks.com/cloudapi/v3/")
.view(ComputeServiceContext.class)
.defaultProperties(ProfitBricksApiMetadata.defaultProperties())
.defaultModules(ImmutableSet.<Class<? extends Module>>builder()
@@ -16,18 +16,18 @@
*/
package org.apache.jclouds.profitbricks.rest.binder;

import java.util.Map;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Strings;
import com.google.common.base.Supplier;
import com.google.inject.Inject;
import java.net.URI;
import java.util.HashMap;
import org.jclouds.json.Json;
import java.util.Map;
import org.jclouds.http.HttpRequest;
import org.jclouds.io.MutableContentMetadata;
import org.jclouds.io.payloads.BaseMutableContentMetadata;
import java.net.URI;
import com.google.common.base.Supplier;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.json.Json;
import org.jclouds.rest.MapBinder;

public abstract class BaseProfitBricksRequestBinder<T> implements MapBinder {

@@ -69,7 +69,7 @@ protected static String nullableToString(Object object) {

protected <R extends HttpRequest> R createRequest(R fromRequest, String payload) {
MutableContentMetadata metadata = new BaseMutableContentMetadata();
metadata.setContentType("application/vnd.profitbricks.resource+json");
metadata.setContentType("application/json");
metadata.setContentLength(Long.valueOf(payload.getBytes().length));

fromRequest.setPayload(payload);
@@ -80,14 +80,15 @@ protected <R extends HttpRequest> R createRequest(R fromRequest, String payload)
@SuppressWarnings("unchecked")
protected <R extends HttpRequest> R genRequest(String path, R fromRequest) {
R request = (R) fromRequest.toBuilder()
.replacePath(endpointSupplier.get().getPath() + path)
.build();
.replacePath(endpointSupplier.get().getPath() + path)
.build();

return request;
}

protected void putIfPresent(Map<String, Object> list, String key, Object value) {
if (value != null)
if (value != null) {
list.put(key, value);
}
}
}
@@ -17,22 +17,22 @@
package org.apache.jclouds.profitbricks.rest.domain;

import com.google.auto.value.AutoValue;
import java.util.List;
import org.jclouds.json.SerializedNames;
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;

@AutoValue
public abstract class Nic extends Trackable {

public abstract String id();

@Nullable
public abstract String dataCenterId();

@Nullable
public abstract String serverId();
public abstract String serverId();

public abstract String type();

@@ -68,15 +68,18 @@ public abstract static class Properties {

public abstract int lan();

@Nullable
public abstract Boolean nat();

@Nullable
public abstract Boolean firewallActive();

@Nullable
public abstract Entities entities();

@SerializedNames({"name", "mac", "ips", "dhcp", "lan", "firewallActive", "entities"})
public static Properties create(String name, String mac, List<String> ips, Boolean dhcp, int lan, Boolean firewallactive, Entities entities) {
return new AutoValue_Nic_Properties(name, mac, ips == null ? ImmutableList.<String>of() : copyOf(ips), dhcp, lan, firewallactive, entities);
@SerializedNames({"name", "mac", "ips", "dhcp", "lan", "nat", "firewallActive", "entities"})
public static Properties create(String name, String mac, List<String> ips, Boolean dhcp, int lan, Boolean nat, Boolean firewallactive, Entities entities) {
return new AutoValue_Nic_Properties(name, mac, ips == null ? ImmutableList.<String>of() : copyOf(ips), dhcp, lan, nat, firewallactive, entities);
}
}

@@ -87,10 +90,10 @@ public abstract static class Entities {

@SerializedNames({"firewallrules"})
public static Entities create(FirewallRules firewallrules) {
return new AutoValue_Nic_Entities(firewallrules);
return new AutoValue_Nic_Entities(firewallrules);
}
}

public static final class Request {

public static CreatePayload.Builder creatingBuilder() {
@@ -114,28 +117,41 @@ public abstract static class CreatePayload {
public abstract Boolean dhcp();

public abstract int lan();


@Nullable
public abstract Boolean nat();

@Nullable
public abstract Boolean firewallActive();

@Nullable
public abstract List<FirewallRule> firewallrules();

public abstract String dataCenterId();

public abstract String serverId();

@AutoValue.Builder
public abstract static class Builder {

public abstract Builder name(String name);

public abstract Builder ips(List<String> ips);

public abstract Builder dhcp(Boolean dhcp);

public abstract Builder lan(int lan);

public abstract Builder nat(Boolean nat);

public abstract Builder firewallActive(Boolean firewallActive);

public abstract Builder firewallrules(List<FirewallRule> firewallrules);

public abstract Builder dataCenterId(String dataCenterId);

public abstract Builder serverId(String serverId);

abstract CreatePayload autoBuild();

public CreatePayload build() {
@@ -158,31 +174,43 @@ public abstract static class UpdatePayload {

@Nullable
public abstract Integer lan();


@Nullable
public abstract Boolean nat();

public abstract String dataCenterId();

public abstract String serverId();

public abstract String id();

@AutoValue.Builder
public abstract static class Builder {

public abstract Builder name(String name);

public abstract Builder ips(List<String> ips);

public abstract Builder dhcp(Boolean dhcp);

public abstract Builder lan(Integer lan);

public abstract Builder nat(Boolean nat);

public abstract Builder dataCenterId(String dataCenterId);

public abstract Builder serverId(String serverId);

public abstract Builder id(String id);

abstract UpdatePayload autoBuild();

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

}


}

0 comments on commit 61e5651

Please sign in to comment.