Skip to content

Commit

Permalink
Added Server-,FloatingIP- and Image-Protection
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Siewert committed Apr 21, 2018
1 parent cc8a527 commit 19999a5
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Hetzner Cloud API for Java

Simple Java client for the Hetzner Cloud API.

The current version is **2.1.1**.
The current version is **2.2.0**.

It would be nice, if you submit pull requests.

Expand Down Expand Up @@ -37,7 +37,7 @@ Dependency:
<dependency>
<groupId>me.tomsdevsn</groupId>
<artifactId>hetznercloud-api</artifactId>
<version>2.1.1</version>
<version>2.2.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand All @@ -55,7 +55,7 @@ repositories({
})
dependencies({
compile "me.tomsdevsn:hetznercloud-api:2.1.1"
compile "me.tomsdevsn:hetznercloud-api:2.2.0"
})
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.tomsdevsn</groupId>
<artifactId>hetznercloud-api</artifactId>
<version>2.1.1</version>
<version>2.2.0</version>

<name>HetznerCloud-API</name>
<description>Java-client for the Hetzner Cloud</description>
Expand Down
44 changes: 39 additions & 5 deletions src/main/java/me/tomsdevsn/hetznercloud/HetznerCloudAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ public ConsoleResponse requestConsole(long id) {
return restTemplate.postForEntity(API_URL + "/servers/" + id + "/actions/request_console", httpEntity, ConsoleResponse.class).getBody();
}

/**
* Change the protection configuration from a server
*
* @param id ID of the server
* @param changeProtection Request Object (both optional)
* @return ActionResponse object
*/
public ActionResponse changeServerProtection(long id, ChangeProtectionRequest changeProtection) {
return restTemplate.postForEntity(API_URL + "/servers/" + id + "/actions/change_protection", new HttpEntity<>(changeProtection, httpHeaders), ActionResponse.class).getBody();
}

/**
* Get all performed Actions for a Server
*
Expand Down Expand Up @@ -174,7 +185,7 @@ public ActionResponse getActionOfFloatingIP(long floatingIPID, long actionID) {
* @return respond
*/
public ActionResponse powerOnServer(long id) {
return restTemplate.exchange(API_URL + "/servers/" + id + "/actions/poweron", HttpMethod.POST, httpEntity, ActionResponse.class).getBody();
return restTemplate.exchange(API_URL + "/servers/" + id + "/actions/poweron", HttpMethod.POST, new HttpEntity<>(httpHeaders), ActionResponse.class).getBody();
}

/**
Expand All @@ -184,7 +195,7 @@ public ActionResponse powerOnServer(long id) {
* @return respond
*/
public ActionResponse powerOffServer(long id) {
return restTemplate.exchange(API_URL + "/servers/" + id + "/actions/poweroff", HttpMethod.POST, httpEntity, ActionResponse.class).getBody();
return restTemplate.exchange(API_URL + "/servers/" + id + "/actions/poweroff", HttpMethod.POST, new HttpEntity<>(httpHeaders), ActionResponse.class).getBody();
}

/**
Expand All @@ -194,7 +205,7 @@ public ActionResponse powerOffServer(long id) {
* @return respond
*/
public ActionResponse softRebootServer(long id) {
return restTemplate.exchange(API_URL + "/servers/" + id + "/actions/reboot", HttpMethod.POST, httpEntity, ActionResponse.class).getBody();
return restTemplate.exchange(API_URL + "/servers/" + id + "/actions/reboot", HttpMethod.POST, new HttpEntity<>(httpHeaders), ActionResponse.class).getBody();
}

/**
Expand All @@ -204,7 +215,7 @@ public ActionResponse softRebootServer(long id) {
* @return respond
*/
public ActionResponse resetServer(long id) {
return restTemplate.exchange(API_URL + "/servers/" + id + "/actions/reset", HttpMethod.POST, httpEntity, ActionResponse.class).getBody();
return restTemplate.exchange(API_URL + "/servers/" + id + "/actions/reset", HttpMethod.POST, new HttpEntity<>(httpHeaders), ActionResponse.class).getBody();
}

/**
Expand All @@ -214,7 +225,7 @@ public ActionResponse resetServer(long id) {
* @return respond
*/
public ActionResponse shutdownServer(long id) {
return restTemplate.exchange(API_URL + "/servers/" + id + "/actions/shutdown", HttpMethod.POST, httpEntity, ActionResponse.class).getBody();
return restTemplate.exchange(API_URL + "/servers/" + id + "/actions/shutdown", HttpMethod.POST, new HttpEntity<>(httpHeaders), ActionResponse.class).getBody();
}

/**
Expand Down Expand Up @@ -339,6 +350,18 @@ public CreateImageResponse createImage(long id, CreateImageRequest createImageRe
return restTemplate.exchange(API_URL + "/servers/" + id + "/actions/create_image", HttpMethod.POST, new HttpEntity<>(createImageRequest, httpHeaders), CreateImageResponse.class).getBody();
}


/**
* Enable or disable the Protection of an Image
*
* @param id ID of the Image
* @param protectionRequest Only the delete parameter!
* @return ActionResponse object
*/
public ActionResponse changeImageProtection(long id, ChangeProtectionRequest protectionRequest) {
return restTemplate.postForEntity(API_URL + "/images/" + id + "/actions/change_protection", new HttpEntity<>(protectionRequest, httpHeaders), ActionResponse.class).getBody();
}

/**
* Enable the backups from a server
* <p>
Expand Down Expand Up @@ -487,6 +510,17 @@ public FloatingIPResponse createFloatingIP(FloatingIPRequest floatingIPRequest)
return restTemplate.postForEntity(API_URL + "/floating_ips", new HttpEntity<>(floatingIPRequest, httpHeaders), FloatingIPResponse.class).getBody();
}

/**
* Enable or disable the Protection of a Floating IP
*
* @param id ID of the Floating IP
* @param protectionRequest Only the delete parameter!
* @return ActionResponse object
*/
public ActionResponse changeFloatingIPProtection(long id, ChangeProtectionRequest protectionRequest) {
return restTemplate.postForEntity(API_URL + "/floating_ips/" + id + "/actions/change_protection", new HttpEntity<>(protectionRequest, httpHeaders), ActionResponse.class).getBody();
}

/**
* Change the description of a Floating IP.
* <p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.tomsdevsn.hetznercloud.objects.general;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import lombok.Data;
import me.tomsdevsn.hetznercloud.deserialize.DateDeserializer;
Expand Down Expand Up @@ -33,11 +34,16 @@ public class Image {
private boolean rapidRedeploy;
@JsonDeserialize(using = DateDeserializer.class)
private Date deprecated;
private Protect protection;

@Data
public static class CreatedFrom {
private Long id;
private String name;
}

@Data
public static class Protect {
private boolean delete;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@ public class Server {
private Long ingoingTraffic;
@JsonProperty("included_traffic")
private Long includedTraffic;
private Protect protection;

@Data
public static class Protect {
private boolean delete;
private boolean rebuild;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package me.tomsdevsn.hetznercloud.objects.request;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ChangeProtectionRequest {

private boolean delete;
private boolean rebuild;
}

0 comments on commit 19999a5

Please sign in to comment.