### Install Hetzner Cloud Python from Source Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/installation.md Installs the Hetzner Cloud Python SDK locally after downloading or cloning the source code. ```console pip install . ``` -------------------------------- ### Install Hetzner Cloud Python via pip Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/installation.md Installs the latest stable release of the Hetzner Cloud Python SDK using pip. This is the recommended installation method. Ensure pip is installed. ```console pip install hcloud ``` -------------------------------- ### Download Hetzner Cloud Python Source Tarball Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/installation.md Downloads the source code archive for the Hetzner Cloud Python SDK from GitHub. ```console curl -OL https://github.com/hetznercloud/hcloud-python/tarball/main ``` -------------------------------- ### Clone Hetzner Cloud Python from GitHub Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/installation.md Clones the Hetzner Cloud Python SDK repository from GitHub to obtain the source code. ```console git clone git://github.com/hetznercloud/hcloud-python ``` -------------------------------- ### Install pre-commit Hooks for Development Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/index.md This command installs the pre-commit framework, which automates the running of linters and other pre-commit checks. This ensures code quality before committing changes. ```sh pre-commit install ``` -------------------------------- ### Install Hetzner Cloud Python via conda Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/installation.md Installs the Hetzner Cloud Python SDK using conda from the conda-forge channel. Note that this package is third-party and may not be up-to-date. ```console conda install -c conda-forge hcloud ``` -------------------------------- ### Set up Development Environment for Hetzner Cloud Python Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/README.md Commands to set up a virtual environment and activate it for development. It also includes installing pre-commit hooks for automated checks before committing. ```shell make venv source venv/bin/activate pre-commit install ``` -------------------------------- ### Setup Development Environment with make venv Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/index.md This command sequence sets up a Python virtual environment for development using the 'make venv' command, followed by activating it using the 'source' command. ```sh make venv source venv/bin/activate ``` -------------------------------- ### Create and Manage Hetzner Cloud Servers Source: https://context7.com/fahreddinozcan/hcloud-python-test7/llms.txt Create new Hetzner Cloud servers with basic or advanced configurations, including specifying server type, image, location, SSH keys, user data, labels, and firewalls. Includes examples of accessing server details and waiting for creation to complete. ```python from hcloud import Client from hcloud.images import Image from hcloud.server_types import ServerType from hcloud.locations import Location from hcloud.datacenters import Datacenter client = Client(token="YOUR_API_TOKEN") # Create a new server with minimal configuration response = client.servers.create( name="my-server", server_type=ServerType(name="cx22"), # 2 vCPU, 4GB RAM image=Image(name="ubuntu-24.04"), # Operating system image ) # Access server details and credentials server = response.server root_password = response.root_password print(f"Server ID: {server.id}") print(f"Server Name: {server.name}") print(f"Status: {server.status}") # 'initializing', 'starting', 'running', 'stopping', 'off' print(f"Public IPv4: {server.public_net.ipv4.ip}") print(f"Public IPv6: {server.public_net.ipv6.network}/{server.public_net.ipv6.network_mask}") print(f"Root Password: {root_password}") # Wait for server creation to complete action = response.action action.wait_until_finished(max_retries=120) # Blocks until server is ready print(f"Action status: {action.status}") # 'success', 'running', or 'error' # Create server with advanced configuration response = client.servers.create( name="production-server", server_type=ServerType(name="cx32"), image=Image(name="ubuntu-24.04"), location=Location(name="nbg1"), # Nuremberg, Germany ssh_keys=[12345], # SSH key IDs to inject user_data="#!/bin/bash\napt-get update", # Cloud-init script labels={"env": "production", "team": "backend"}, automount=False, # Don't auto-mount volumes start_after_create=True, # Start immediately (default) firewalls=[54321], # Firewall IDs to apply ) ``` -------------------------------- ### Get All Datacenters Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/api.clients.datacenters.md Retrieves a list of all datacenters. This can be filtered by name. ```APIDOC ## GET /datacenters ### Description Retrieves a list of all datacenters. This can be filtered by name. ### Method GET ### Endpoint /datacenters ### Parameters #### Query Parameters - **name** (str) - Optional - Can be used to filter datacenters by their name. ### Response #### Success Response (200) - **datacenters** (list[BoundDatacenter]) - A list of datacenter objects. #### Response Example { "datacenters": [ { "id": 1, "name": "fsn1-dc1", "location": { "id": 1, "name": "fscent1", "description": "Hetzner Online GmbH", "country": "de", "city": "Falkenstein", "latitude": 50.47612, "longitude": 12.37223 }, "server_types": { "available": ["cx11", "cx21"], "supported": ["cx11", "cx21"], "available_for_migration": ["cx11", "cx21"] } } ] } ``` -------------------------------- ### Get Zone Actions Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/api.clients.zones.md Retrieves all actions associated with a specific Zone. ```APIDOC ## GET /zones/{zone_id}/actions ### Description Retrieves all actions associated with a specific Zone. ### Method GET ### Endpoint `/zones/{zone_id}/actions` ### Parameters #### Path Parameters - **zone_id** (int | str) - Required - The ID or Name of the Zone. #### Query Parameters - **status** (list[str]) - Optional - Filter the actions by status. - **sort** (list[str]) - Optional - Sort resources by field and direction. ### Response #### Success Response (200) - **actions** (list[BoundAction]) - A list of Action objects associated with the Zone. #### Response Example ```json { "actions": [ { "id": 112233, "command": "create_server", "status": "success", "started": "2024-01-01T10:00:00Z", "finished": "2024-01-01T10:05:00Z" } ] } ``` ``` -------------------------------- ### Hetzner Cloud Client Initialization Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/api.md This section details how to initialize the main Client for the Hetzner Cloud API, including authentication and optional parameters. ```APIDOC ## class Client ### Description Client for the Hetzner Cloud API. ### Parameters - **token** (str) - Required - API token for authentication. - **api_endpoint** (str) - Optional - The base URL for the API. Defaults to 'https://api.hetzner.cloud/v1'. - **application_name** (str | None) - Optional - Name of the application using the client. - **application_version** (str | None) - Optional - Version of the application using the client. - **poll_interval** (int | float | BackoffFunction) - Optional - Interval for polling operations. Defaults to 1.0. - **poll_max_retries** (int) - Optional - Maximum number of retries for polling operations. Defaults to 120. - **timeout** (float | tuple[float, float] | None) - Optional - Timeout for API requests. ``` -------------------------------- ### Build and Open Documentation with make docs Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/index.md This command builds the project's documentation and opens it in the default web browser. It requires the documentation generation tools to be set up. ```sh make docs ``` -------------------------------- ### Get All Zones Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/api.clients.zones.md Retrieves a list of all available Zones, with optional filtering. ```APIDOC ## GET /zones ### Description Retrieves a list of all available Zones, with optional filtering. ### Method GET ### Endpoint `/zones` ### Parameters #### Query Parameters - **name** (str) - Optional - Filter resources by their name. - **mode** (Literal['primary', 'secondary']) - Optional - Filter resources by their mode. - **label_selector** (str) - Optional - Filter resources by labels. - **sort** (list[str]) - Optional - Sort resources by field and direction. ### Response #### Success Response (200) - **zones** (list[BoundZone]) - A list of Zone objects. #### Response Example ```json { "zones": [ { "id": 12345, "name": "zone-name-1", "server_count": 5, "paid_until": "2024-12-31T23:59:59Z", "is_public": true }, { "id": 67890, "name": "zone-name-2", "server_count": 2, "paid_until": "2025-01-15T23:59:59Z", "is_public": false } ] } ``` ``` -------------------------------- ### Get a Single Zone Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/api.clients.zones.md Retrieves a single Zone by its ID or Name. ```APIDOC ## GET /zones/{id_or_name} ### Description Retrieves a single Zone by its ID or Name. ### Method GET ### Endpoint `/zones/{id_or_name}` ### Parameters #### Path Parameters - **id_or_name** (int | str) - Required - ID or Name of the Zone. ### Response #### Success Response (200) - **zone** (BoundZone) - The requested Zone object. #### Response Example ```json { "zone": { "id": 12345, "name": "zone-name", "server_count": 5, "paid_until": "2024-12-31T23:59:59Z", "is_public": true } } ``` ``` -------------------------------- ### List Available System Images with Python Source: https://context7.com/fahreddinozcan/hcloud-python-test7/llms.txt Fetches and displays details of available system images from Hetzner Cloud, sorted by creation date in descending order. Includes image name, description, OS flavor and version, architecture, disk size, creation date, and support for rapid deploy. Requires the Hetzner Cloud Python library. ```python images = client.images.get_all(type=["system"], sort=["created:desc"]) for img in images: print(f"{img.name}: {img.description}") print(f" OS flavor: {img.os_flavor} {img.os_version}") print(f" Architecture: {img.architecture}") print(f" Disk size: {img.disk_size}GB") print(f" Created: {img.created}") if img.rapid_deploy: print(" Supports rapid deploy") ``` -------------------------------- ### Get Network by ID Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/api.clients.networks.md Retrieves a specific network by its unique ID. ```APIDOC ## GET /networks/{id} ### Description Get a specific network. ### Method GET ### Endpoint `/networks/{id}` ### Parameters #### Path Parameters - **id** (int) - Required - The ID of the network to retrieve. ### Response #### Success Response (200) - **network** (object) - The network object. - **id** (int) - The ID of the network. - **name** (string) - The name of the network. - **ip_range** (string) - The IP range of the network. - **created** (string) - The creation date of the network. - **labels** (object) - Labels assigned to the network. #### Response Example ```json { "network": { "id": 1, "name": "my-network", "ip_range": "10.0.0.0/16", "created": "2023-01-01T10:00:00Z", "labels": { "environment": "production" } } } ``` ``` -------------------------------- ### Create and List Servers with hcloud-python Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/index.md This Python code snippet demonstrates how to use the hcloud library to create a new server and then list all existing servers. It requires an API token and specifies server type and image. It outputs server ID, name, status, and the root password for the newly created server. ```python from hcloud import Client from hcloud.images import Image from hcloud.server_types import ServerType client = Client(token="{YOUR_API_TOKEN}") # Please paste your API token here # Create a server named my-server response = client.servers.create( name="my-server", server_type=ServerType(name="cx22"), image=Image(name="ubuntu-22.04"), ) server = response.server print(f"{server.id=} {server.name=} {server.status=}") print(f"root password: {response.root_password}") # List your servers servers = client.servers.get_all() for server in servers: print(f"{server.id=} {server.name=} {server.status=}") ``` -------------------------------- ### Get Action by ID Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/api.clients.actions.md Retrieves a specific action by its unique identifier. ```APIDOC ## GET /actions/{id} ### Description Retrieves a specific action by its unique identifier. ### Method GET ### Endpoint /actions/{id} ### Parameters #### Path Parameters - **id** (int) - Required - The unique identifier of the action. ### Response #### Success Response (200) - **action** (BoundAction) - The action object corresponding to the provided ID. #### Response Example ```json { "action": { "id": 123, "command": "create_server", "status": "success", "progress": 100, "started": "2023-10-27T10:00:00Z", "finished": "2023-10-27T10:05:00Z", "resources": [ { "id": 456, "type": "server" } ], "error": null } } ``` ``` -------------------------------- ### Run Development Tasks with Makefile Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/README.md Common development tasks for the Hetzner Cloud Python library using the Makefile. Includes building documentation, linting code, and running tests. ```shell make docs make lint make test ``` -------------------------------- ### Get Network Actions Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/api.clients.networks.md Retrieves a list of all actions performed on a specific network. ```APIDOC ## GET /networks/{network_id}/actions ### Description Returns all action objects for a network. ### Method GET ### Endpoint /networks/{network_id}/actions ### Parameters #### Path Parameters - **network_id** (int) - Required - The ID of the network to retrieve actions for. #### Query Parameters - **status** (list[str]) - Optional - Filter actions by status. Possible values: "running", "success", "error". - **sort** (list[str]) - Optional - Specify how the results are sorted. Possible values: "id", "id:asc", "id:desc", "command", "command:asc", "command:desc", "status", "status:asc", "status:desc", "progress", "progress:asc", "progress:desc", "started", "started:asc", "started:desc", "finished", "finished:asc", "finished:desc". ### Response #### Success Response (200) - **actions** (list[BoundAction]) - A list of action objects associated with the network. #### Response Example ```json { "actions": [ { "id": 98771, "command": "update_network", "status": "success", "started": "2023-01-01T10:00:00Z", "finished": "2023-01-01T10:05:00Z" } ] } ``` ``` -------------------------------- ### Get Volume by ID Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/api.clients.volumes.md Retrieves a specific volume using its unique identifier. ```APIDOC ## GET /volumes/{id} ### Description Retrieves a specific volume by its ID. ### Method GET ### Endpoint /volumes/{id} ### Parameters #### Path Parameters - **id** (int) - Required - The unique identifier of the volume. ### Response #### Success Response (200) - **volume** (BoundVolume) - The requested volume object. ``` -------------------------------- ### POST /servers Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/api.clients.servers.md Creates a new server with specified configurations. This endpoint allows for detailed customization of the server, including its type, image, storage, networking, and more. ```APIDOC ## POST /servers ### Description Creates a new server. Returns preliminary information about the server as well as an action that covers progress of creation. ### Method POST ### Endpoint /v1/servers ### Parameters #### Request Body - **name** (str) - Required - Name of the server to create (must be unique per project and a valid hostname as per RFC 1123) - **server_type** (object) - Required - Server type this server should be created with. Can be an ID or Name. - **image** (object) - Required - Image the server is created from. Can be an ID or Name. - **ssh_keys** (list[object]) - Optional - SSH keys which should be injected into the server at creation time. Can be IDs or Names. - **volumes** (list[object]) - Optional - Volumes which should be attached to the server at the creation time. Volumes must be in the same location. Can be IDs or Names. - **networks** (list[object]) - Optional - Networks which should be attached to the server at the creation time. Can be IDs or Names. - **user_data** (str) - Optional - Cloud-Init user data to use during server creation. This field is limited to 32KiB. - **labels** (dict[str, str]) - Optional - User-defined labels (key-value pairs) - **location** (object | str) - Optional - Location the server should be created in. Can be an ID, Name or Object. - **datacenter** (object | str) - Optional - Datacenter the server should be created in. Can be an ID, Name or Object. - **start_after_create** (bool) - Optional - Start Server right after creation. Defaults to True. - **automount** (bool) - Optional - Auto mount volumes after attach. - **placement_group** (object | str) - Optional - Placement Group where server should be added during creation. Can be an ID, Name or Object. - **public_net** (object) - Optional - Options to configure the public network of a server on creation - **ipv4** (bool) - Optional - Enable IPv4 - **ipv6** (bool) - Optional - Enable IPv6 ### Request Example ```json { "name": "my-server", "server_type": "cx11", "image": "ubuntu-22.04", "ssh_keys": ["my-ssh-key"], "labels": { "environment": "production" }, "public_net": { "ipv4": true, "ipv6": false } } ``` ### Response #### Success Response (200 OK) - **server** (object) - Preliminary information about the created server. - **id** (int) - ID of the server - **name** (str) - Name of the server - **created** (str) - Timestamp of creation - **state** (str) - Current state of the server (e.g., `running`, `stopped`) - **public_net** (object) - Public network information - **ipv4** (object) - **ip** (str) - IPv4 address - **dns_ptr** (str) - Reverse DNS entry - **ipv6** (object) - **ip** (str) - IPv6 address - **dns_ptr** (list[str]) - Reverse DNS entries - **private_net** (list[object]) - Private network information - **protection** (object) - Protection level of the server - **labels** (dict[str, str]) - User-defined labels - **placed_servers** (list[int]) - IDs of servers in the same placement group - **backup_window** (str) - Backup window - **rescue_enabled** (bool) - Whether rescue mode is enabled - **iso_image** (object | null) - Attached ISO image - **vm_type** (str) - VM type - **storage_size** (int) - Storage size in GB - **image** (object) - Image used for the server - **server_type** (object) - Server type details - **datacenter** (object) - Datacenter details - **volume_ids** (list[int]) - IDs of attached volumes - **primary_ip** (object) - Primary IP address details - **primary_zone** (str) - Primary zone - **billing_rate** (str) - Billing rate - **maintenance** (object) - Maintenance information - **action** (object) - Information about the action that was started to create the server. - **id** (int) - ID of the action - **command** (str) - Command of the action - **status** (str) - Status of the action (e.g., `running`, `successful`, `failed`) - **progress** (int) - Progress of the action in percent - **started** (str) - Timestamp of when the action was started - **completed** (str | null) - Timestamp of when the action was completed - **resources** (object) - Resources affected by the action - **type** (str) - Type of resource - **id** (int) - ID of resource - **error** (object | null) - Error details if the action failed - **code** (str) - Error code - **message** (str) - Error message #### Response Example ```json { "server": { "id": 12345, "name": "my-server", "created": "2023-01-01T10:00:00Z", "state": "creating", "public_net": { "ipv4": { "ip": "192.0.2.1", "dns_ptr": "server.example.com" }, "ipv6": { "ip": "2001:db8::1", "dns_ptr": [] } }, "private_net": [], "protection": { "delete": false, "rebuild": false }, "labels": { "environment": "production" }, "placed_servers": [], "backup_window": null, "rescue_enabled": false, "iso_image": null, "vm_type": "vm-cx11", "storage_size": 25, "image": { "id": 123, "type": "generic", "name": "Ubuntu 22.04 LTS", "description": "Ubuntu 22.04 LTS", "image_size": 2.5, "disk_size": 10, "os_flavor": "ubuntu", "os_version": "22.04", "architecture": "x86", "deprecated": "2025-01-01T00:00:00Z" }, "server_type": { "id": 1, "name": "cx11", "description": "General Purpose", "cores": 1, "memory": 2048.0, "disk": 25, "storage_type": "local", "prices": [ { "location": "fcn", "price_hourly": { "amount": "0.0048000000", "currency": "EUR", "unit": "hour" }, "price_monthly": { "amount": "1.0000000000", "currency": "EUR", "unit": "month" } } ] }, "datacenter": { "id": 1, "name": "fsn1-dc18", "location": { "id": 1, "name": "Falkenstein", "description": "Falkenstein DC 18", "country": "de", "city": "Falkenstein", "latitude": 50.4711, "longitude": 12.3747 } }, "volume_ids": [], "primary_ip": { "ipv4": { "ip": "192.0.2.1", "blocked": false }, "ipv6": { "ip": "2001:db8::1", "blocked": false } }, "primary_zone": "de-central-1" }, "action": { "id": 98765, "command": "create_server", "status": "running", "progress": 10, "started": "2023-01-01T10:00:05Z", "completed": null, "resources": [ { "type": "server", "id": 12345 } ], "error": null } } ``` ``` -------------------------------- ### List Available Server Types with Python Source: https://context7.com/fahreddinozcan/hcloud-python-test7/llms.txt Retrieves and prints details of all available server types from Hetzner Cloud. Includes information on cores, memory, disk, architecture, CPU type, storage type, pricing per location, and deprecation status if applicable. No specific dependencies are needed beyond the Hetzner Cloud Python library. ```python server_types = client.server_types.get_all() for st in server_types: print(f"{st.name}: {st.cores} cores, {st.memory}GB RAM, {st.disk}GB disk") print(f" Architecture: {st.architecture}") print(f" CPU type: {st.cpu_type}") print(f" Storage type: {st.storage_type}") for price in st.prices: print(f" Price ({price.location.name}): €{price.price_monthly.gross}/month") if st.deprecation: print(f" Deprecated: {st.deprecation.announced} - {st.deprecation.unavailable_after}") ``` -------------------------------- ### Get Datacenter by ID Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/api.clients.datacenters.md Retrieves a specific datacenter using its unique identifier. ```APIDOC ## GET /datacenters/{id} ### Description Retrieves a specific datacenter using its unique identifier. ### Method GET ### Endpoint /datacenters/{id} ### Parameters #### Path Parameters - **id** (int) - Required - The unique identifier of the datacenter. ### Response #### Success Response (200) - **datacenter** (BoundDatacenter) - The datacenter object matching the provided ID. #### Response Example { "datacenter": { "id": 1, "name": "fsn1-dc1", "location": { "id": 1, "name": "fscent1", "description": "Hetzner Online GmbH", "country": "de", "city": "Falkenstein", "latitude": 50.47612, "longitude": 12.37223 }, "server_types": { "available": ["cx11", "cx21"], "supported": ["cx11", "cx21"], "available_for_migration": ["cx11", "cx21"] } } } ``` -------------------------------- ### Get All Zones (Paginated) Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/api.clients.zones.md Retrieves a paginated list of all available Zones, with optional filtering. ```APIDOC ## GET /zones ### Description Retrieves a paginated list of all available Zones, with optional filtering. ### Method GET ### Endpoint `/zones` ### Parameters #### Query Parameters - **name** (str) - Optional - Filter resources by their name. - **mode** (Literal['primary', 'secondary']) - Optional - Filter resources by their mode. - **label_selector** (str) - Optional - Filter resources by labels. - **sort** (list[str]) - Optional - Sort resources by field and direction. - **page** (int) - Optional - Page number to return. - **per_page** (int) - Optional - Maximum number of entries returned per page. ### Response #### Success Response (200) - **zones_page_result** (ZonesPageResult) - An object containing a list of Zone objects and pagination information. #### Response Example ```json { "zones": [ { "id": 12345, "name": "zone-name-1", "server_count": 5, "paid_until": "2024-12-31T23:59:59Z", "is_public": true } ], "pagination": { "page": 1, "per_page": 10, "total_entries": 50, "next_page": "/v1/zones?page=2&per_page=10", "previous_page": null } } ``` ``` -------------------------------- ### Manage DNS Zones Source: https://context7.com/fahreddinozcan/hcloud-python-test7/llms.txt Demonstrates the creation, retrieval, update, and listing of DNS zones using the beta API. Note that the DNS API is in beta and may be subject to changes. ```python from hcloud.zones import Zone # Create DNS zone zone = client.zones.create( name="example.com", ttl=86400 # Default TTL in seconds ) print(f"Zone created: {zone.id} - {zone.name}") print(f"Nameservers: {zone.name_servers}") # Get zone by ID or name zone = client.zones.get_by_name("example.com") # Update zone updated_zone = zone.update(ttl=3600) # List all zones zones = client.zones.get_all() for z in zones: print(f"{z.id}: {z.name} - {len(z.records)} records") # Note: DNS API is in Beta and may have breaking changes # See https://docs.hetzner.cloud/changelog for updates ``` -------------------------------- ### CreateServerResponse Class Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/api.clients.servers.md Contains information returned after a server creation request, including the created server, associated actions, and the root password. ```APIDOC ## CreateServerResponse Class ### Description Response object after creating a server. Includes details about the created server, ongoing actions, and the root password if applicable. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (This is a response object) ### Response #### Success Response (200) - **server** (`BoundServer`) - Required - The created server object. - **action** (`BoundAction`) - Required - An action object showing the progress of the server creation. - **next_actions** (list[`BoundAction`]) - Optional - A list of subsequent actions, such as starting the server. - **root_password** (str | None) - Optional - The root password for the server if no SSH key was provided during creation. #### Response Example ```json { "server": { "id": 12345, "name": "my-server", "status": "creating" }, "action": { "id": 67890, "command": "create_server", "status": "running" }, "next_actions": [], "root_password": "s3cureP@ssw0rd!" } ``` ``` -------------------------------- ### GET /certificates/{id}/actions Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/api.clients.certificates.md Retrieves a list of all actions associated with a specific certificate. ```APIDOC ## GET /certificates/{id}/actions ### Description Returns all action objects for a Certificate. ### Method GET ### Endpoint /certificates/{certificate_id}/actions ### Parameters #### Path Parameters - **certificate** (int | object) - Required - The ID or a certificate object. #### Query Parameters - **status** (list[str]) - Optional - Response will have only actions with specified statuses. Choices: `running`, `success`, `error`. - **sort** (list[str]) - Optional - Specify how the results are sorted. Choices: `id`, `id:asc`, `id:desc`, `command`, `command:asc`, `command:desc`, `status`, `status:asc`, `status:desc`, `progress`, `progress:asc`, `progress:desc`, `started`, `started:asc`, `started:desc`, `finished`, `finished:asc`, `finished:desc`. ### Response #### Success Response (200) - **actions** (list[object]) - A list of action objects. - **id** (int) - The ID of the action. - **command** (str) - The command executed. - **status** (str) - The status of the action. - **progress** (int) - The progress of the action in percent. - **started** (str) - The start time of the action. - **finished** (str) - The finish time of the action. - **error** (object | null) - Error details if the action failed. - **resources** (list[object]) - Resources associated with the action. - **root_element_id** (int) - The ID of the root element the action belongs to. - **root_element_type** (str) - The type of the root element. #### Response Example ```json { "actions": [ { "id": 1, "command": "create_certificate", "status": "success", "progress": 100, "started": "2023-10-27T10:05:00Z", "finished": "2023-10-27T10:06:00Z", "error": null, "resources": [], "root_element_id": 12346, "root_element_type": "certificate" } ] } ``` ``` -------------------------------- ### Hetzner Cloud API Clients Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/api.md Overview of the client instances available for interacting with different Hetzner Cloud resources. ```APIDOC ## API Resource Clients ### Description Instances for interacting with various Hetzner Cloud API resources. ### Clients - **actions**: [`ActionsClient`](api.clients.actions.md#hcloud.actions.client.ActionsClient) - **certificates**: [`CertificatesClient`](api.clients.certificates.md#hcloud.certificates.client.CertificatesClient) - **datacenters**: [`DatacentersClient`](api.clients.datacenters.md#hcloud.datacenters.client.DatacentersClient) - **firewalls**: [`FirewallsClient`](api.clients.firewalls.md#hcloud.firewalls.client.FirewallsClient) - **floating_ips**: [`FloatingIPsClient`](api.clients.floating_ips.md#hcloud.floating_ips.client.FloatingIPsClient) - **images**: [`ImagesClient`](api.clients.images.md#hcloud.images.client.ImagesClient) - **isos**: [`IsosClient`](api.clients.isos.md#hcloud.isos.client.IsosClient) - **load_balancer_types**: [`LoadBalancerTypesClient`](api.clients.load_balancer_types.md#hcloud.load_balancer_types.client.LoadBalancerTypesClient) - **load_balancers**: [`LoadBalancersClient`](api.clients.load_balancers.md#hcloud.load_balancers.client.LoadBalancersClient) - **locations**: [`LocationsClient`](api.clients.locations.md#hcloud.locations.client.LocationsClient) - **networks**: [`NetworksClient`](api.clients.networks.md#hcloud.networks.client.NetworksClient) - **placement_groups**: [`PlacementGroupsClient`](api.clients.placement_groups.md#hcloud.placement_groups.client.PlacementGroupsClient) - **primary_ips**: [`PrimaryIPsClient`](api.clients.primary_ips.md#hcloud.primary_ips.client.PrimaryIPsClient) - **server_types**: [`ServerTypesClient`](api.clients.server_types.md#hcloud.server_types.client.ServerTypesClient) - **servers**: [`ServersClient`](api.clients.servers.md#hcloud.servers.client.ServersClient) - **ssh_keys**: [`SSHKeysClient`](api.clients.ssh_keys.md#hcloud.ssh_keys.client.SSHKeysClient) - **volumes**: [`VolumesClient`](api.clients.volumes.md#hcloud.volumes.client.VolumesClient) - **zones**: [`ZonesClient`](api.clients.zones.md#hcloud.zones.client.ZonesClient) ``` -------------------------------- ### Get Server Type by Name Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/api.clients.server_types.md Retrieves a specific server type using its name. ```APIDOC ## GET /server_types?name={name} ### Description Retrieves a specific server type using its name. ### Method GET ### Endpoint /server_types ### Parameters #### Query Parameters - **name** (str) - Required - The name of the server type to retrieve. ### Response #### Success Response (200) - **server_types** (list[ServerType]) - A list containing the server type object if found, otherwise an empty list. #### Response Example ```json { "server_types": [ { "id": 1, "name": "cx11", "description": "1 vCPU, 2 GB RAM, 20 GB SSD", "cores": 1, "memory": 2, "disk": 20, "storage_type": "local", "cpu_type": "shared", "architecture": "x86", "prices": [ { "location": "fkb", "price_hourly": "0.007142857142857143", "price_monthly": "1.0" } ], "included_traffic": 10000000000, "locations": [ { "name": "fkb", "url": "https://robot-ws.your-server.de/server-types/1/locations/fkb" } ], "deprecated": false } ] } ``` ``` -------------------------------- ### List, Update, and Manage Servers Source: https://context7.com/fahreddinozcan/hcloud-python-test7/llms.txt This section covers listing servers with pagination, updating server properties like name and labels, and managing server power states (on, off, reboot, reset). It also includes operations for resetting the root password and deleting a server. ```APIDOC ## List Servers with Pagination ### Description Retrieves a list of servers with support for pagination and filtering by label selector. ### Method GET ### Endpoint /servers ### Query Parameters - **page** (int) - Optional - The page number to retrieve. - **per_page** (int) - Optional - The number of servers to return per page. - **label_selector** (string) - Optional - Filters servers by labels (e.g., "env=production"). ### Response #### Success Response (200) - **servers** (list) - A list of server objects. - **meta** (object) - Metadata including pagination information. - **pagination** (object) - Pagination details. - **page** (int) - Current page number. - **last_page** (int) - The last page number. - **total_entries** (int) - Total number of servers. ### Request Example ```python result = client.servers.get_list(page=1, per_page=25, label_selector="env=production") servers = result.servers meta = result.meta print(f"Page {meta.pagination.page} of {meta.pagination.last_page}") print(f"Total servers: {meta.pagination.total_entries}") ``` ## Update and Manage Server State ### Description Allows updating server properties such as name and labels, and managing power states including on, off, graceful shutdown, reboot, and reset. Also includes operations for resetting the root password and deleting a server. ### Method PUT / POST / DELETE ### Endpoint /servers/{id} ### Parameters #### Path Parameters - **id** (int) - Required - The ID of the server to manage. #### Request Body (for update) - **name** (string) - Optional - The new name for the server. - **labels** (dict) - Optional - A dictionary of labels to update or set. ### Request Example (Update Server) ```python server = client.servers.get_by_name("my-server") updated_server = server.update( name="renamed-server", labels={"env": "staging", "version": "v2"} ) ``` ### Request Example (Power Management) ```python server = client.servers.get_by_name("my-server") server.power_on() # Turn on server server.power_off() # Force power off (immediate) server.shutdown() # Graceful shutdown (ACPI request) server.reboot() # Graceful reboot (ACPI request) server.reset() # Force reset (power cycle) # Wait for action completion action = server.power_on() action.wait_until_finished() ``` ### Request Example (Reset Password) ```python server = client.servers.get_by_name("my-server") response = server.reset_password() new_password = response.root_password print(f"New root password: {new_password}") ``` ### Request Example (Delete Server) ```python server = client.servers.get_by_name("my-server") action = server.delete() action.wait_until_finished() print("Server deleted successfully") ``` ``` -------------------------------- ### Get Load Balancer Type by Name Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/api.clients.load_balancer_types.md Retrieves a Load Balancer type by its name. ```APIDOC ## GET /load_balancer_types?name={name} ### Description Retrieves a Load Balancer type by its name. ### Method GET ### Endpoint /load_balancer_types ### Parameters #### Query Parameters - **name** (str) - Required - The name of the Load Balancer type to retrieve. ### Response #### Success Response (200) - **load_balancer_type** (BoundLoadBalancerType | None) - The requested Load Balancer type, or None if not found. #### Response Example { "load_balancer_type": { "id": 1, "name": "lb-type-1", "description": "Basic Load Balancer Type", "max_connections": 1000, "max_services": 10, "max_targets": 50, "max_assigned_certificates": 5, "prices": [ { "location": "f1", "price_hourly": 0.005, "price_monthly": 1.5 } ] } } ``` -------------------------------- ### Get Datacenter by Name Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/api.clients.datacenters.md Retrieves a datacenter using its name. Returns null if not found. ```APIDOC ## GET /datacenters?name={name} ### Description Retrieves a datacenter using its name. Returns null if not found. ### Method GET ### Endpoint /datacenters ### Parameters #### Query Parameters - **name** (str) - Required - The name of the datacenter to retrieve. ### Response #### Success Response (200) - **datacenter** (BoundDatacenter | None) - The datacenter object matching the provided name, or null if not found. #### Response Example { "datacenter": { "id": 1, "name": "fsn1-dc1", "location": { "id": 1, "name": "fscent1", "description": "Hetzner Online GmbH", "country": "de", "city": "Falkenstein", "latitude": 50.47612, "longitude": 12.37223 }, "server_types": { "available": ["cx11", "cx21"], "supported": ["cx11", "cx21"], "available_for_migration": ["cx11", "cx21"] } } } ``` -------------------------------- ### Manage SSH Keys Source: https://context7.com/fahreddinozcan/hcloud-python-test7/llms.txt Provides examples for adding, retrieving, using during server creation, updating, and deleting SSH keys. Requires a client object and server configuration details. ```python # Add SSH public key ssh_key = client.ssh_keys.create( name="laptop-key", public_key="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC...", labels={"user": "john", "device": "laptop"} ) print(f"SSH key added: {ssh_key.id} - {ssh_key.name}") # Get all SSH keys ssh_keys = client.ssh_keys.get_all() for key in ssh_keys: print(f"{key.id}: {key.name} - {key.fingerprint}") # Use SSH key when creating server response = client.servers.create( name="secure-server", server_type=ServerType(name="cx22"), image=Image(name="ubuntu-24.04"), ssh_keys=[ssh_key.id] # Will be injected into authorized_keys ) # Update SSH key updated_key = ssh_key.update( name="john-laptop", labels={"user": "john.doe", "device": "macbook"} ) # Delete SSH key ssh_key.delete() ``` -------------------------------- ### Get ISO by ID Source: https://github.com/fahreddinozcan/hcloud-python-test7/blob/main/_context7_rst_markdown_build/api.clients.isos.md Retrieves a specific ISO image using its unique ID. ```APIDOC ## GET /isos/{id} ### Description Retrieves a specific ISO image by its unique ID. ### Method GET ### Endpoint /isos/{id} ### Parameters #### Path Parameters - **id** (int) - Required - The unique identifier of the ISO. ### Response #### Success Response (200) - **iso** (Iso) - The ISO object with the specified ID. #### Response Example ```json { "iso": { "id": 123, "name": "ubuntu-20.04", "type": "public", "description": "Ubuntu 20.04 LTS", "architecture": "x86", "deprecated": null, "deprecation": null } } ``` ```