Skip to content
Permalink
Browse files
Update endpoint to v3
  • Loading branch information
alibazlamit authored and nacx committed May 22, 2017
1 parent cb70f32 commit 7aa033a9706e46d82eacbe5612647a8d89f29b10
Showing 26 changed files with 45 additions and 28 deletions.
@@ -91,7 +91,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-NV")
.endpoint("https://api.profitbricks.com/rest/v2/")
.endpoint("https://api.profitbricks.com/cloudapi/v3/")
.defaultProperties(ProfitBricksProviderMetadata.defaultProperties());
}

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

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

if (payload.firewallrules() != null) {
Map<String, Object> entities = new HashMap<String, Object>();
entities.put("firewallrules", payload.firewallrules());
@@ -60,6 +60,9 @@ protected String createPayload(Nic.Request.UpdatePayload payload) {
if (payload.dhcp() != null)
requestBuilder.put("dhcp", payload.dhcp());

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

return jsonBinder.toJson(requestBuilder);
}

@@ -61,6 +61,9 @@ protected String createPayload(Server.Request.CreatePayload payload) {
else if (payload.bootCdrom() != null)
properties.put("bootCdrom", payload.bootCdrom());

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

requestBuilder.put("properties", properties);

Server.Entities entities = payload.entities();
@@ -16,15 +16,15 @@
*/
package org.apache.jclouds.profitbricks.rest.binder.server;

import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Supplier;
import com.google.inject.Inject;
import java.net.URI;
import org.apache.jclouds.profitbricks.rest.binder.BaseProfitBricksRequestBinder;
import org.apache.jclouds.profitbricks.rest.domain.Server;
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 UpdateServerRequestBinder extends BaseProfitBricksRequestBinder<Server.Request.UpdatePayload> {

@@ -60,6 +60,9 @@ protected String createPayload(Server.Request.UpdatePayload payload) {
else if (payload.bootCdrom() != null)
requestBuilder.put("bootCdrom", payload.bootCdrom());

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

return jsonBinder.toJson(requestBuilder);
}

@@ -20,7 +20,7 @@

public enum LicenceType {

WINDOWS, LINUX, OTHER, UNRECOGNIZED;
WINDOWS, LINUX, OTHER, WINDOWS2016, UNRECOGNIZED;

public static LicenceType fromValue(String v) {
return Enums.getIfPresent(LicenceType.class, v).or(UNRECOGNIZED);
@@ -215,6 +215,9 @@ public abstract static class UpdatePayload {

@Nullable
public abstract Volume bootCdrom();

@Nullable
public abstract CpuFamily cpuFamily();

@Nullable
public abstract AvailabilityZone availabilityZone();
@@ -238,6 +241,8 @@ public abstract static class Builder {
public abstract Builder bootVolume(BootVolume bootVolume);

public abstract Builder bootCdrom(Volume bootCdrom);

public abstract Builder cpuFamily(CpuFamily cpuFamily);

public abstract Builder availabilityZone(AvailabilityZone availabilityZone);

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

assertEquals(request.getEndpoint().getPath(), "/rest/v2/datacenters/datacenter-id/servers/server-id/nics/nic-id/firewallrules");
assertEquals(request.getEndpoint().getPath(), "/cloudapi/v3/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(), "/rest/v2/datacenters/datacenter-id/servers/server-id/nics/nic-id/firewallrules/id");
assertEquals(request.getEndpoint().getPath(), "/cloudapi/v3/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(), "/rest/v2/images/some-id");
assertEquals(request.getEndpoint().getPath(), "/cloudapi/v3/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(), "/rest/v2/datacenters/datacenter-id/lans");
assertEquals(request.getEndpoint().getPath(), "/cloudapi/v3/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(), "/rest/v2/datacenters/datacenter-id/lans/lan-id");
assertEquals(request.getEndpoint().getPath(), "/cloudapi/v3/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(), "/rest/v2/datacenters/datacenter-id/servers/server-id/nics");
assertEquals(request.getEndpoint().getPath(), "/cloudapi/v3/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(), "/rest/v2/datacenters/datacenter-id/servers/server-id/nics/nic-id");
assertEquals(request.getEndpoint().getPath(), "/cloudapi/v3/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(), "/rest/v2/datacenters/datacenter-id/servers/server-id/cdroms");
assertEquals(request.getEndpoint().getPath(), "/cloudapi/v3/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(), "/rest/v2/datacenters/datacenter-id/servers/server-id/volumes");
assertEquals(request.getEndpoint().getPath(), "/cloudapi/v3/datacenters/datacenter-id/servers/server-id/volumes");
assertNotNull(actual, "Binder returned null payload");

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

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

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

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

Json json = injector.getInstance(Json.class);
@@ -52,7 +52,7 @@ public void testCreatePayload() {
expectedPayload.put("name", "test-snapshot");
expectedPayload.put("description", "snapshot desc...");

assertEquals(request.getEndpoint().getPath(), "/rest/v2/datacenters/datacenter-id/volumes/volume-id/create-snapshot");
assertEquals(request.getEndpoint().getPath(), "/cloudapi/v3/datacenters/datacenter-id/volumes/volume-id/create-snapshot");
assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.APPLICATION_FORM_URLENCODED);
assertEquals(request.getPayload().getRawContent(), "&" + (new UrlEncodedFormPayload(expectedPayload)).getRawContent());

@@ -51,7 +51,7 @@ public void testCreatePayload() {
actual
);

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

Json json = injector.getInstance(Json.class);
@@ -42,7 +42,7 @@ public void testRestorePayload() {
binder.createPayload(payload)
);

assertEquals(request.getEndpoint().getPath(), "/rest/v2/datacenters/datacenter-id/volumes/volume-id/restore-snapshot");
assertEquals(request.getEndpoint().getPath(), "/cloudapi/v3/datacenters/datacenter-id/volumes/volume-id/restore-snapshot");
assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.APPLICATION_FORM_URLENCODED);
assertEquals(request.getPayload().getRawContent(), "&snapshotId=snapshot-id");

@@ -48,7 +48,7 @@ public void testCreatePayload() {
actual
);

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

Json json = injector.getInstance(Json.class);
@@ -20,9 +20,9 @@
import org.apache.jclouds.profitbricks.rest.domain.DataCenter;
import org.apache.jclouds.profitbricks.rest.domain.options.DepthOptions;
import org.apache.jclouds.profitbricks.rest.internal.BaseProfitBricksLiveTest;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import org.testng.annotations.Test;

@Test(groups = "live", testName = "DataCenterApiLiveTest")
public class DataCenterApiLiveTest extends BaseProfitBricksLiveTest {
@@ -1,7 +1,7 @@
{
"id": "6c53515b-8557-44a8-9339-ea34e7e5baa2",
"type": "ipblock",
"href": "https://api.profitbricks.com/rest/v2/ipblocks/6c53515b-8557-44a8-9339-ea34e7e5baa2",
"href": "https://api.profitbricks.com/cloudapi/v3/ipblocks/6c53515b-8557-44a8-9339-ea34e7e5baa2",
"metadata": {
"createdDate": "2016-06-18T21:38:20Z",
"createdBy": "jasmin.gacic@gmail.com",
@@ -1,11 +1,11 @@
{
"id": "ipblocks",
"type": "collection",
"href": "https://api.profitbricks.com/rest/v2/ipblocks",
"href": "https://api.profitbricks.com/cloudapi/v3/ipblocks",
"items": [{
"id": "6c53515b-8557-44a8-9339-ea34e7e5baa2",
"type": "ipblock",
"href": "https://api.profitbricks.com/rest/v2/ipblocks/6c53515b-8557-44a8-9339-ea34e7e5baa2",
"href": "https://api.profitbricks.com/cloudapi/v3/ipblocks/6c53515b-8557-44a8-9339-ea34e7e5baa2",
"metadata": {
"createdDate": "2016-06-18T21:38:20Z",
"createdBy": "jasmin.gacic@gmail.com",
@@ -23,7 +23,7 @@
}, {
"id": "b6f3be55-d7e1-4a62-835a-0c4a64dda433",
"type": "ipblock",
"href": "https://api.profitbricks.com/rest/v2/ipblocks/b6f3be55-d7e1-4a62-835a-0c4a64dda433",
"href": "https://api.profitbricks.com/cloudapi/v3/ipblocks/b6f3be55-d7e1-4a62-835a-0c4a64dda433",
"metadata": {
"createdDate": "2016-06-09T21:27:26Z",
"createdBy": "jasmin.gacic@gmail.com",
@@ -1,14 +1,14 @@
{
"id": "ipblocks",
"type": "collection",
"href": "https://api.profitbricks.com/rest/v2/ipblocks",
"href": "https://api.profitbricks.com/cloudapi/v3/ipblocks",
"items": [{
"id": "6c53515b-8557-44a8-9339-ea34e7e5baa2",
"type": "ipblock",
"href": "https://api.profitbricks.com/rest/v2/ipblocks/6c53515b-8557-44a8-9339-ea34e7e5baa2"
"href": "https://api.profitbricks.com/cloudapi/v3/ipblocks/6c53515b-8557-44a8-9339-ea34e7e5baa2"
}, {
"id": "b6f3be55-d7e1-4a62-835a-0c4a64dda433",
"type": "ipblock",
"href": "https://api.profitbricks.com/rest/v2/ipblocks/b6f3be55-d7e1-4a62-835a-0c4a64dda433"
"href": "https://api.profitbricks.com/cloudapi/v3/ipblocks/b6f3be55-d7e1-4a62-835a-0c4a64dda433"
}]
}

0 comments on commit 7aa033a

Please sign in to comment.