NAME

WWW::Hetzner::Cloud::API::Servers - Hetzner Cloud Servers API

VERSION

version 0.001

SYNOPSIS

use WWW::Hetzner::Cloud;

my $cloud = WWW::Hetzner::Cloud->new(token => $ENV{HETZNER_API_TOKEN});

# List all servers
my $servers = $cloud->servers->list;

# Create a server
my $server = $cloud->servers->create(
    name        => 'my-server',
    server_type => 'cx22',
    image       => 'debian-12',
    location    => 'fsn1',
    ssh_keys    => ['my-key'],
    labels      => { env => 'prod' },
);

# Server is a WWW::Hetzner::Cloud::Server object
print $server->id, "\n";
print $server->ipv4, "\n";

# Wait for server to be running
$cloud->servers->wait_for_status($server->id, 'running');

# Power actions via API
$cloud->servers->shutdown($server->id);

# Or directly on the object
$server->power_on;
$server->shutdown;

# Update server
$server->name('new-name');
$server->update;

# Delete server
$server->delete;

DESCRIPTION

This module provides the API for managing Hetzner Cloud servers. All methods return WWW::Hetzner::Cloud::Server objects.

NAME

WWW::Hetzner::Cloud::API::Servers - Hetzner Cloud Servers API

METHODS

list

my $servers = $cloud->servers->list;
my $servers = $cloud->servers->list(label_selector => 'env=prod');

Returns an arrayref of WWW::Hetzner::Cloud::Server objects. Optional parameters: label_selector, name, status, sort.

list_by_label

my $servers = $cloud->servers->list_by_label('env=production');

Convenience method to list servers by label selector.

get

my $server = $cloud->servers->get($id);

Returns a WWW::Hetzner::Cloud::Server object.

create

my $server = $cloud->servers->create(
    name        => 'my-server',      # required
    server_type => 'cx23',           # required
    image       => 'debian-13',      # required
    location    => 'fsn1',           # optional
    datacenter  => 'fsn1-dc14',      # optional (alternative to location)
    ssh_keys    => ['my-key'],       # optional
    labels      => { env => 'prod' },# optional
    user_data   => '...',            # optional (cloud-init)
    start_after_create => 1,         # optional (default: true)
    placement_group => 'my-group',   # optional
    networks    => [123, 456],       # optional (network IDs)
    volumes     => [789],            # optional (volume IDs)
    automount   => 1,                # optional (automount volumes)
    firewalls   => [111, 222],       # optional (firewall IDs)
    enable_ipv4 => 1,                # optional (default: true)
    enable_ipv6 => 1,                # optional (default: true)
    ipv4        => 'primary-ip-id',  # optional (existing Primary IP)
    ipv6        => 'primary-ip-id',  # optional (existing Primary IP)
);

Creates a new server. Returns a WWW::Hetzner::Cloud::Server object.

delete

$cloud->servers->delete($id);

Deletes a server.

power_on

$cloud->servers->power_on($id);

Powers on a server.

power_off

$cloud->servers->power_off($id);

Hard power off (like pulling the power cord).

shutdown

$cloud->servers->shutdown($id);

Graceful shutdown via ACPI.

reboot

$cloud->servers->reboot($id);

Hard reboot.

rebuild

$cloud->servers->rebuild($id, 'debian-13');

Rebuilds server with a new image. Data on the server will be lost.

change_type

$cloud->servers->change_type($id, 'cx33', upgrade_disk => 1);

Changes server type. Server must be powered off.

update

$cloud->servers->update($id, name => 'new-name', labels => { env => 'dev' });

Updates server name or labels.

wait_for_status

$cloud->servers->wait_for_status($id, 'running', 120);

Polls until server reaches the specified status. Default timeout is 120 seconds.

SUPPORT

Source Code

The code is open to the world, and available for you to hack on. Please feel free to browse it and play with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull from your repository :)

https://github.com/Getty/p5-www-hetzner

git clone https://github.com/Getty/p5-www-hetzner.git

AUTHOR

Torsten Raudssus <torsten@raudssus.de>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.