Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
ad57aaa
Adding improved core method
MajMcCloud Jul 31, 2025
a2a98dd
Adding first server actions
MajMcCloud Jul 31, 2025
57b84c6
Adding more action methods
MajMcCloud Aug 1, 2025
b74daf6
Renaming methods
MajMcCloud Aug 1, 2025
8ef39e3
Making server class partial and adding status enum
MajMcCloud Aug 1, 2025
671ae16
Improve core methods
MajMcCloud Aug 1, 2025
53f786d
Adding Action response to server power methods
MajMcCloud Aug 1, 2025
9b79a83
Replacing action and server status property with enum directly
MajMcCloud Aug 1, 2025
511877c
Adding more methods to server actions
MajMcCloud Aug 1, 2025
fec7fde
Adding iso client
MajMcCloud Aug 1, 2025
67d3702
Update ISOClient.cs
MajMcCloud Aug 1, 2025
eee0275
Adding last server action methods
MajMcCloud Aug 1, 2025
768c753
Replacing image status with enum
MajMcCloud Aug 1, 2025
c502852
Adding more enums
MajMcCloud Aug 1, 2025
7ed75bb
Adding more clearer not found exception instead of generic one
MajMcCloud Aug 1, 2025
565846b
Adding server actions to readme
MajMcCloud Aug 1, 2025
6b7fabc
Update README.md
MajMcCloud Aug 1, 2025
7d9875a
Update README.md
MajMcCloud Aug 1, 2025
9c08234
Update README.md
MajMcCloud Aug 1, 2025
d886c6b
Fix to invalid deserialization
MajMcCloud Aug 1, 2025
c38bb7e
Adding improved put method to core
MajMcCloud Aug 1, 2025
c3ff161
Adding primary IP tools
MajMcCloud Aug 1, 2025
014bd0f
Enabling labels again
MajMcCloud Aug 1, 2025
c108651
Rename ISO properties
MajMcCloud Aug 1, 2025
9ba86c3
Enable ISO for server again
MajMcCloud Aug 1, 2025
b0b8719
Add DnsPtr to IPv6
MajMcCloud Aug 1, 2025
db11009
Adding firewall shortcut
MajMcCloud Aug 3, 2025
31084b3
Adding firewall name filter on Get
MajMcCloud Aug 3, 2025
f0aa6c0
Adding primary ip override
MajMcCloud Aug 3, 2025
ee81862
Adding more enums
MajMcCloud Aug 3, 2025
8f74ece
Fix to invalid action result in new server actions
MajMcCloud Aug 4, 2025
c367d25
Add more details to server type model
MajMcCloud Aug 4, 2025
1b1f257
Improve action getter for server actions
MajMcCloud Aug 5, 2025
9fe8e30
Adding generic get method
MajMcCloud Aug 5, 2025
4b11166
Add debugger details to Action object
MajMcCloud Aug 5, 2025
f27ef87
Adding Net/Gross decimal properties to server type prices
MajMcCloud Aug 5, 2025
1f81eff
Adding debugging info to Action
MajMcCloud Aug 5, 2025
eb3f971
Adding debugger display attribute to Image class
MajMcCloud Aug 17, 2025
d306e34
Adding string to port converter
MajMcCloud Oct 17, 2025
741df66
Adding string replacement for firewall port
MajMcCloud Oct 17, 2025
227cfb3
Adding more debugger display stuff
MajMcCloud Oct 17, 2025
4d7fba6
Adding port to long operator
MajMcCloud Oct 17, 2025
f23365b
Improve firewall rule comment
MajMcCloud Oct 17, 2025
5914db2
Adding response bucket for easier response data retrieval
MajMcCloud Oct 18, 2025
be348f5
Adding generic delete request method & return json on normal one
MajMcCloud Oct 18, 2025
94e179b
Improve firewall client to allow full creation instead of "only name"…
MajMcCloud Oct 18, 2025
e57615b
Allow server delete action retrieval
MajMcCloud Oct 18, 2025
e6b2d35
Improve server creation and allow root password return
MajMcCloud Oct 18, 2025
07ceb1a
Add more method overloads for firewall client
MajMcCloud Oct 20, 2025
b7e9b3b
Adding primary IP action client
MajMcCloud Oct 20, 2025
14afdb8
Allow primary IP creation without assignee
MajMcCloud Oct 20, 2025
d0075b4
Allow primary ip without assignee id
MajMcCloud Oct 20, 2025
2966ded
Return Action/Primary IP tuple instead of just Primary IP
MajMcCloud Oct 20, 2025
86d3f47
Allowing IP reuse for server creation
MajMcCloud Oct 20, 2025
e2cfc49
Remove "empty" IPv4 and IPv6 property values to allow detect if no pu…
MajMcCloud Oct 20, 2025
422b86a
Update documentation on ssh
MajMcCloud Oct 20, 2025
46a4bf1
Adding missing primary IP actions
MajMcCloud Oct 21, 2025
b20545d
Unify create server call
MajMcCloud Oct 21, 2025
b14c3b1
Adding implicit overloads to ResponseBucket for easier retrieval of A…
MajMcCloud Oct 21, 2025
91c86ea
Adding Responsebucket to firewall methods to allow status retrieval
MajMcCloud Oct 21, 2025
898968a
Adding more implicit operators
MajMcCloud Oct 21, 2025
1bb4132
Adding improved intellisense comments to give hints on static operators
MajMcCloud Oct 21, 2025
67c7f89
Adding bucket to allow improved server details
MajMcCloud Oct 21, 2025
f4e088f
Fix ISO response
MajMcCloud Oct 21, 2025
e2b3673
Add operator on simple action response
MajMcCloud Oct 21, 2025
0fbfc0b
Adding multi action operator
MajMcCloud Oct 21, 2025
50699ac
Adding missing comment
MajMcCloud Oct 21, 2025
6de3b4a
Adding missing methods to network action client & improve docs
MajMcCloud Oct 22, 2025
bb06c3b
Cleanup network client
MajMcCloud Oct 22, 2025
1d422c5
Cleanup primary ip client
MajMcCloud Oct 22, 2025
7d9ed56
Add docs
MajMcCloud Oct 22, 2025
ca195cb
Adding missing vswitch id parameter to Subnet
MajMcCloud Oct 22, 2025
5f191e4
Cleanup server client
MajMcCloud Oct 22, 2025
4aa9bc8
Cleanup firewall & firewall action client
MajMcCloud Oct 22, 2025
8200094
Adding debugging info to route & subnet
MajMcCloud Oct 22, 2025
e8fa2ff
Reduce return value on get server
MajMcCloud Oct 22, 2025
f3f8fff
Adding deconstruct to response bucket
MajMcCloud Oct 22, 2025
9954cce
Adding architecture type enum to images
MajMcCloud Nov 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
* [🗺️ Location](functions-and-methods/location.md)
* [🌐 Networks](functions-and-methods/networks/README.md)
* [Networks Actions](functions-and-methods/networks/networks-actions.md)
* [🖥️ Servers](functions-and-methods/servers.md)
* [🖥️ Servers](functions-and-methods/servers/README.md)
* [Servers Actions](functions-and-methods/servers/server-actions.md)
* [🗄️ Servers Types](functions-and-methods/servers-types.md)
* [🔐 SSH Keys](functions-and-methods/ssh-keys.md)
* [📦 Volumes](functions-and-methods/volumes/README.md)
Expand Down
160 changes: 160 additions & 0 deletions Docs/functions-and-methods/servers/server-actions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Server Actions

With Server Actions, you can perform various actions on your servers, such as starting, stopping, rebooting, attaching networks, and much more. The methods are provided via the `ServerActionClient` class.

---

## Initialization

```csharp
using HetznerCloudApi.Client;

HetznerCloudClient hetznerCloudClient = new HetznerCloudClient("apiKey");
```

---

## Start server

```csharp
long serverId = 123456;
var action = await hetznerCloudClient.ServerActions.PowerOn(serverId);
```

## Stop server (Power Off)

```csharp
long serverId = 123456;
var action = await hetznerCloudClient.ServerActions.PowerOff(serverId);
```

## Soft reboot server

```csharp
long serverId = 123456;
var action = await hetznerCloudClient.ServerActions.SoftReboot(serverId);
```

## Hard reboot server (Reset)

```csharp
long serverId = 123456;
var action = await hetznerCloudClient.ServerActions.Reset(serverId);
```

## Shutdown server

```csharp
long serverId = 123456;
var action = await hetznerCloudClient.ServerActions.Shutdown(serverId);
```

## Change server type

```csharp
long serverId = 123456;
bool upgradeDisk = true;
string serverType = "cx21";
var action = await hetznerCloudClient.ServerActions.ChangeType(serverId, upgradeDisk, serverType);
```

## Attach server to network

```csharp
long serverId = 123456;
long networkId = 654321;
var action = await hetznerCloudClient.ServerActions.AttachToNetwork(serverId, networkId);
```

## Detach server from network

```csharp
long serverId = 123456;
long networkId = 654321;
var action = await hetznerCloudClient.ServerActions.DetachFromNetwork(serverId, networkId);
```

## Enable backup

```csharp
long serverId = 123456;
var action = await hetznerCloudClient.ServerActions.EnableBackup(serverId);
```

## Disable backup

```csharp
long serverId = 123456;
var action = await hetznerCloudClient.ServerActions.DisableBackup(serverId);
```

## Enable rescue mode

```csharp
long serverId = 123456;
string type = "linux64";
var action = await hetznerCloudClient.ServerActions.EnableRescueMode(serverId, type);
```

## Disable rescue mode

```csharp
long serverId = 123456;
var action = await hetznerCloudClient.ServerActions.DisableRescueMode(serverId);
```

## Reset root password

```csharp
long serverId = 123456;
var response = await hetznerCloudClient.ServerActions.ResetRootPassword(serverId);
string newPassword = response.RootPassword;
```

## Request console (VNC)

```csharp
long serverId = 123456;
var response = await hetznerCloudClient.ServerActions.RequestConsole(serverId);
string wssUrl = response.Wss_Url;
string password = response.Password;
```

## Attach ISO

```csharp
long serverId = 123456;
string isoName = "ubuntu-22.04";
var action = await hetznerCloudClient.ServerActions.AttachISO(serverId, isoName);
```

## Detach ISO

```csharp
long serverId = 123456;
var action = await hetznerCloudClient.ServerActions.DetachISO(serverId);
```

## Create snapshot/image

```csharp
long serverId = 123456;
string description = "Backup before update";
string type = "snapshot";
var labels = new Dictionary<string, string> { { "env", "prod" } };
var action = await hetznerCloudClient.ServerActions.CreateImage(serverId, description, type, labels);
```

## Rebuild server from image

```csharp
long serverId = 123456;
string image = "ubuntu-22.04";
var response = await hetznerCloudClient.ServerActions.RebuildFromImage(serverId, image);
string newRootPassword = response.RootPassword;
```

---

You can find more methods and details in the API documentation and in the source code of the `ServerActionClient` class.

4 changes: 2 additions & 2 deletions Docs/functions-and-methods/ssh-keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ sshKey.Name = $"new-name-{Guid.NewGuid()}";
sshKey = await hetznerCloudClient.SshKey.Update(sshKey);
```

## Delete a Volume
## Delete an SSH Key

Deletes a volume. All Volume data is irreversibly destroyed. The Volume must not be attached to a Server and it must not have delete protection enabled.
Deletes a ssh key.

```csharp
HetznerCloudClient hetznerCloudClient = new HetznerCloudClient("ApiKey");
Expand Down
147 changes: 129 additions & 18 deletions HetznerCloudApi/Client/FirewallActionClient.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Newtonsoft.Json.Linq;
using HetznerCloudApi.Object.Action;
using HetznerCloudApi.Object.Action.Get;
using HetznerCloudApi.Object.Firewall;
using HetznerCloudApi.Object.Server;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using HetznerCloudApi.Object.Action;
using HetznerCloudApi.Object.Action.Get;
using HetznerCloudApi.Object.Firewall;

namespace HetznerCloudApi.Client
{
Expand All @@ -18,22 +20,88 @@ public FirewallActionClient(string token)
}

/// <summary>
/// Apply to Resources
/// Apply to a single server by id
/// </summary>
/// <param name="firewallId"></param>
/// <param name="serverId"></param>
/// <returns></returns>
public async Task<List<Action>> ApplyToResources(long firewallId, long serverId)
{
// Preparing raw
string raw = $"{{ \"apply_to\": [ {{ \"server\": {{ \"id\": {serverId} }}, \"type\": \"server\" }} ] }}";
return await ApplyToResources(firewallId, new List<AppliedTo>() { AppliedTo.FromServerId(serverId) });
}

// Send update
string jsonResponse = await Core.SendPostRequest(_token, $"/firewalls/{firewallId}/actions/apply_to_resources", raw);
/// <summary>
/// Apply to a single server by id
/// </summary>
/// <param name="firewall"></param>
/// <param name="server"></param>
/// <returns></returns>
public async Task<List<Action>> ApplyToServer(Firewall firewall, long serverId)
{
return await ApplyToResources(firewall.Id, serverId);
}

// Return
JObject result = JObject.Parse(jsonResponse);
return JsonConvert.DeserializeObject<List<Action>>($"{result["actions"]}") ?? new List<Action>();
/// <summary>
/// Apply to a single server
/// </summary>
/// <param name="firewall"></param>
/// <param name="server"></param>
/// <returns></returns>
public async Task<List<Action>> ApplyToServer(Firewall firewall, Object.Server.Server server)
{
return await ApplyToResources(firewall.Id, server.Id);
}


/// <summary>
/// Apply to multiple servers
/// </summary>
/// <param name="firewall"></param>
/// <param name="server"></param>
/// <returns></returns>
public async Task<List<Action>> ApplyToServers(Firewall firewall, IEnumerable<Object.Server.Server> servers)
{
return await ApplyToResources(firewall.Id, servers.Select(a => AppliedTo.FromServer(a)));
}

/// <summary>
/// Apply to multiple servers by id
/// </summary>
/// <param name="firewall"></param>
/// <param name="server"></param>
/// <returns></returns>
public async Task<List<Action>> ApplyToServers(Firewall firewall, IEnumerable<long> serverIds)
{
return await ApplyToResources(firewall.Id, serverIds.Select(a => AppliedTo.FromServerId(a)));
}

/// <summary>
/// Apply to Resources
/// </summary>
/// <param name="firewallId"></param>
/// <param name="appliedTo"
/// <returns></returns>
public async Task<List<Action>> ApplyToResources(Firewall firewall, IEnumerable<AppliedTo> appliedTo)
{
return await ApplyToResources(firewall.Id, appliedTo);
}


/// <summary>
/// Apply to Resources
/// </summary>
/// <param name="firewallId"></param>
/// <param name="appliedTo"
/// <returns></returns>
public async Task<List<Action>> ApplyToResources(long firewallId, IEnumerable<AppliedTo> appliedTo)
{
// Preparing raw
var temp = new
{
apply_to = appliedTo
};

return await Core.SendPostRequest<ResponseBucket<string>>(_token, $"/firewalls/{firewallId}/actions/apply_to_resources", temp);
}

/// <summary>
Expand All @@ -43,16 +111,59 @@ public async Task<List<Action>> ApplyToResources(long firewallId, long serverId)
/// <param name="serverId"></param>
/// <returns></returns>
public async Task<List<Action>> RemoveFromResources(long firewallId, long serverId)
{
return await RemoveFromResources(firewallId, new List<AppliedTo>() { AppliedTo.FromServerId(serverId) });
}

/// <summary>
/// Removes one Firewall from multiple resources.
/// </summary>
/// <param name="firewallId"></param>
/// <param name="serverId"></param>
/// <returns></returns>
public async Task<List<Action>> RemoveFromResources(long firewallId, IEnumerable<AppliedTo> removeFrom)
{
// Preparing raw
string raw = $"{{ \"remove_from\": [ {{ \"server\": {{ \"id\": {serverId} }}, \"type\": \"server\" }} ] }}";
var temp = new
{
remove_from = removeFrom
};

// Send update
string jsonResponse = await Core.SendPostRequest(_token, $"/firewalls/{firewallId}/actions/remove_from_resources", raw);
return await Core.SendPostRequest<ResponseBucket<string>>(_token, $"/firewalls/{firewallId}/actions/remove_from_resources", temp);

// Return
JObject result = JObject.Parse(jsonResponse);
return JsonConvert.DeserializeObject<List<Action>>($"{result["actions"]}") ?? new List<Action>();
}

/// <summary>
/// Removes one Firewall from multiple resources.
/// </summary>
/// <param name="firewall"></param>
/// <param name="server"></param>
/// <returns></returns>
public async Task<List<Action>> RemoveFromResources(Firewall firewall, Object.Server.Server server)
{
return await RemoveFromResources(firewall.Id, new List<AppliedTo>() { AppliedTo.FromServerId(server.Id) });
}

/// <summary>
/// Remove from multiple servers
/// </summary>
/// <param name="firewall"></param>
/// <param name="server"></param>
/// <returns></returns>
public async Task<List<Action>> RemoveFromResources(Firewall firewall, IEnumerable<Object.Server.Server> servers)
{
return await RemoveFromResources(firewall.Id, servers.Select(a => AppliedTo.FromServer(a)));
}

/// <summary>
/// Remove from multiple servers by id
/// </summary>
/// <param name="firewall"></param>
/// <param name="server"></param>
/// <returns></returns>
public async Task<List<Action>> RemoveFromResources(Firewall firewall, IEnumerable<long> serverIds)
{
return await RemoveFromResources(firewall.Id, serverIds.Select(a => AppliedTo.FromServerId(a)));
}

/// <summary>
Expand Down
Loading