hetzner

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package hetzner wraps the Hetzner Cloud API for provisioning and tearing down the box: a default-deny firewall, an SSH key, and the server itself.

Index

Constants

View Source
const (
	GroupShared    = "Shared Resources"
	GroupDedicated = "Dedicated Resources"

	ClassCostOptimized = "Cost-Optimized"
	ClassRegular       = "Regular Performance"
	ClassGeneral       = "General Purpose"

	ArchX86Intel = "x86 (Intel)"
	ArchX86AMD   = "x86 (AMD)"
	ArchArm      = "Arm64 (Ampere)"
)

Hetzner's selection hierarchy: Type (Shared/Dedicated) -> Class -> Architecture.

Variables

This section is empty.

Functions

This section is empty.

Types

type Catalog

type Catalog struct {
	// contains filtered or unexported fields
}

Catalog holds every available (type, region) option, classified.

func (*Catalog) All

func (c *Catalog) All() []SizeOption

All returns the full option set (sorted cheapest-first within the same family).

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a thin wrapper around the hcloud client.

func New

func New(token string) *Client

New builds a client from a project API token.

func (*Client) Create

func (h *Client) Create(ctx context.Context, o CreateOpts) (Result, error)

Create provisions the server with the firewall attached at create time (so there is never a window with open public ports).

func (*Client) Destroy

func (h *Client) Destroy(ctx context.Context, name string) error

Destroy deletes the server and its firewall. Missing resources are ignored. The server delete is async; we wait for it before deleting the firewall, otherwise Hetzner rejects the firewall delete (409, still attached).

func (*Client) Exists

func (h *Client) Exists(ctx context.Context, name string) (bool, error)

Exists reports whether a server with the name already exists.

func (*Client) IsAdopted

func (h *Client) IsAdopted(ctx context.Context, name string) bool

IsAdopted reports whether the named server carries the adopted marker.

func (*Client) LabelAdopted

func (h *Client) LabelAdopted(ctx context.Context, name string) error

LabelAdopted tags an adopted server so it is recognizable, with an "adopted" marker so teardown refuses to delete a machine the user owned first.

func (*Client) ListServers

func (h *Client) ListServers(ctx context.Context) ([]ExistingServer, error)

ListServers returns every server in the project.

func (*Client) TypeCatalog

func (h *Client) TypeCatalog(ctx context.Context) (*Catalog, error)

TypeCatalog fetches all server types once and builds the classified option set with per-region net monthly price. No size floor: the cheapest options show too.

func (*Client) Validate

func (h *Client) Validate(ctx context.Context) error

Validate confirms the token works (read probe).

type CreateOpts

type CreateOpts struct {
	Name        string
	Region      string
	ServerType  string
	WithoutIPv4 bool
	UserData    string
	PublicKeys  []string
}

CreateOpts describes the server to create.

type ExistingServer

type ExistingServer struct {
	Name, Type, Location, Status, IPv4, IPv6 string
	HasIPv4                                  bool
	Managed                                  bool // already pocketdev-managed
}

ExistingServer is a server already in the project, for the adopt path.

type Result

type Result struct {
	IPv4 string // empty when WithoutIPv4
	IPv6 string
}

Result is what Create returns to the caller.

type SizeOption

type SizeOption struct {
	Type     string
	Region   string // location code, e.g. "nbg1"
	City     string // e.g. "Nuremberg"
	Country  string // ISO-3166 alpha-2, e.g. "DE"
	Cores    int
	MemoryGB float32
	DiskGB   int
	Monthly  float64 // net monthly price (ex VAT), in Currency
	Currency string  // account currency, e.g. EUR or USD

	Group     string // GroupShared | GroupDedicated
	Class     string // ClassCostOptimized | ClassRegular | ClassGeneral
	ArchLabel string // ArchX86Intel | ArchX86AMD | ArchArm
}

SizeOption is one buyable (server type, region) combination, classified into Hetzner's Type -> Class -> Architecture hierarchy.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL