### Install Hetzner Cloud Python from local source Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/installation.md Installs the Hetzner Cloud Python library after downloading or cloning the source code. This command should be run from the root directory of the source code. ```console pip install . ``` -------------------------------- ### Install Hetzner Cloud Python using pip Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/installation.md Installs the latest stable release of the Hetzner Cloud Python library using pip. Ensure pip is installed on your system. This is the recommended installation method. ```console pip install hcloud ``` -------------------------------- ### Install and Use Hetzner Cloud Python Library Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/index.md Install the `hcloud` library using pip and use it to create and list servers. This example demonstrates client initialization with an API token, server creation specifying name, server type, and image, and then retrieving all existing servers. ```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=}") ``` -------------------------------- ### Download Hetzner Cloud Python source tarball Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/installation.md Downloads the source code of the Hetzner Cloud Python library as a tarball from the main branch of the GitHub repository. This is an alternative to cloning the repository. ```bash curl -OL https://github.com/hetznercloud/hcloud-python/tarball/main ``` -------------------------------- ### Clone Hetzner Cloud Python repository from GitHub Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/installation.md Clones the official Hetzner Cloud Python GitHub repository to obtain the source code. This allows for direct access to the latest development version. ```git git clone git://github.com/hetznercloud/hcloud-python ``` -------------------------------- ### Install Hetzner Cloud Python using conda Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/installation.md Installs the Hetzner Cloud Python library 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 ``` -------------------------------- ### Python Development Pre-commit Hook Setup Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/index.md Install and set up pre-commit hooks to automatically run checks before committing code. This helps maintain code quality and consistency. ```sh pre-commit install ``` -------------------------------- ### Create Hetzner Cloud Server (Python) Source: https://context7.com/fahreddinozcan/hcloud-python-test5/llms.txt Shows how to programmatically create a new cloud server instance on Hetzner Cloud. Includes examples for basic server creation with a name, server type, and image, as well as advanced creation with SSH keys, labels, datacenter location, user data, and controlling the start-after-create option. The response provides the created server object, root password, and an action object to track the creation progress. ```python from hcloud import Client from hcloud.images import Image from hcloud.server_types import ServerType from hcloud.locations import Location from hcloud.ssh_keys import SSHKey client = Client(token="YOUR_API_TOKEN") # Basic server creation response = client.servers.create( name="my-web-server", server_type=ServerType(name="cx22"), # 2 vCPU, 4GB RAM image=Image(name="ubuntu-24.04"), ) server = response.server root_password = response.root_password action = response.action print(f"Server created: ID={server.id}, Status={server.status}") print(f"Root password: {root_password}") print(f"IPv4: {server.public_net.ipv4.ip}") print(f"IPv6: {server.public_net.ipv6.ip}") # Advanced server creation with SSH keys, labels, and location response = client.servers.create( name="production-api-server", server_type=ServerType(name="cx42"), image=Image(name="ubuntu-24.04"), ssh_keys=[SSHKey(name="my-key")], location=Location(name="nbg1"), # Nuremberg datacenter labels={"env": "production", "app": "api"}, user_data="#cloud-config\nruncmd:\n - apt-get update", automount=False, start_after_create=True, ) # Wait for server to be ready action.wait_until_finished() print(f"Server is running: {response.server.status}") ``` -------------------------------- ### Manage Images with hcloud-python Source: https://context7.com/fahreddinozcan/hcloud-python-test5/llms.txt This section provides Python code examples for listing and managing system images and snapshots using the hcloud-python library. It assumes an initialized `Client` object. ```python from hcloud import Client client = Client(token="YOUR_API_TOKEN") # Example usage for image management would go here. # For instance, listing all images: # images = client.images.get_all() # for image in images: # print(f"Image ID: {image.id}, Name: {image.name}, Type: {image.type}") ``` -------------------------------- ### Pagination with Filtering - Get Specific Servers Source: https://context7.com/fahreddinozcan/hcloud-python-test5/llms.txt Shows how to use `get_list()` with filtering parameters to retrieve a specific subset of servers. This example filters by labels (`env=production`) and status (`running`), combined with pagination controls (`page`, `per_page`). It returns the total count of matching servers. ```python page_result = client.servers.get_list( label_selector="env=production", status=["running"], page=1, per_page=25 ) print(f"Found {page_result.meta.pagination.total_entries} matching servers") ``` -------------------------------- ### Client Initialization Source: https://context7.com/fahreddinozcan/hcloud-python-test5/llms.txt Demonstrates how to create an authenticated client instance for interacting with the Hetzner Cloud API. Supports basic and advanced configurations including custom endpoints, application identification, polling intervals, and timeouts. ```APIDOC ## Client Initialization Create an authenticated client instance for all API operations. ### Method Initialization ### Parameters #### Request Body - **token** (string) - Required - Your Hetzner Cloud API token. - **api_endpoint** (string) - Optional - Custom API endpoint URL. - **application_name** (string) - Optional - Name for application identification. - **application_version** (string) - Optional - Version of the application. - **poll_interval** (float) - Optional - Seconds between action status polls (default: 1.0). - **poll_max_retries** (int) - Optional - Maximum retries when polling actions (default: 120). - **timeout** (tuple) - Optional - (connect_timeout, read_timeout) in seconds. ### Request Example ```python from hcloud import Client # Basic initialization with API token client = Client(token="YOUR_HETZNER_CLOUD_API_TOKEN") # Advanced initialization with custom configuration client = Client( token="YOUR_API_TOKEN", api_endpoint="https://api.hetzner.cloud/v1", # Optional custom endpoint application_name="my-app", # Optional app identification application_version="1.0.0", # Optional version tracking poll_interval=2.0, # Seconds between action status polls poll_max_retries=120, # Max retries when polling actions timeout=(5.0, 30.0) # (connect_timeout, read_timeout) in seconds ) ``` ### Notes The client provides automatic retry with exponential backoff for: - Network timeouts - HTTP 502/504 errors - rate_limit_exceeded API errors - conflict API errors ``` -------------------------------- ### Monitor Actions and Poll Status with Hetzner Cloud Python SDK Source: https://context7.com/fahreddinozcan/hcloud-python-test5/llms.txt This section shows how to retrieve all actions, get a specific action by ID, and wait for an action to complete using the Hetzner Cloud Python SDK. It also includes an example of manually polling an action's status with a timeout mechanism. ```python from hcloud import Client import time client = Client(token="YOUR_API_TOKEN") # Get all actions actions = client.actions.get_all() for action in actions: print(f"{action.id}: {action.command} - {action.status} ({action.progress}%)") # Get specific action action = client.actions.get_by_id(12345) print(f"Action: {action.command}, Status: {action.status}") # Wait for action to complete server = client.servers.get_by_name("my-web-server") action = server.reboot() print(f"Rebooting server... (Action ID: {action.id})") action.wait_until_finished() # Blocks until action completes print(f"Reboot complete: {action.status}") # Poll action manually with timeout timeout = 300 # 5 minutes start_time = time.time() while action.status == "running": if time.time() - start_time > timeout: raise TimeoutError("Action did not complete in time") time.sleep(2) action = client.actions.get_by_id(action.id) print(f"Progress: {action.progress}%") if action.status == "error": print(f"Action failed: {action.error}") else: print("Action completed successfully") ``` -------------------------------- ### Perform Actions on Hetzner Cloud Servers (Python) Source: https://context7.com/fahreddinozcan/hcloud-python-test5/llms.txt Illustrates how to perform various lifecycle actions on Hetzner Cloud servers, such as rebooting or powering off. The example shows retrieving a server by name and then initiating an action. Further actions like power on, reset, and delete would follow a similar pattern. ```python from hcloud import Client client = Client(token="YOUR_API_TOKEN") server = client.servers.get_by_name("my-web-server") # Example: Rebooting a server (other actions like power_on, shutdown, reset follow) # action = server.reboot() # action.wait_until_finished() # print(f"Server rebooted: {server.status}") ``` -------------------------------- ### Enable Rescue System Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/api.clients.servers.md Enables the Hetzner Rescue System for a server, allowing booting into a rescue environment. ```APIDOC ## POST /servers/{server_id}/enable_rescue ### Description Enable the Hetzner Rescue System for this server. ### Method POST ### Endpoint `/servers/{server_id}/enable_rescue` ### Parameters #### Path Parameters - **server_id** (int) - Required - The ID of the server to enable the rescue system for. #### Request Body - **type** (string) - Optional - Type of rescue system to boot. Choices: `linux64`, `linux32`, `freebsd64`. Defaults to `linux64`. - **ssh_keys** (list[string]) - Optional - Array of SSH key IDs to inject into the rescue system. Only available for `linux64` and `linux32` types. ### Request Example ```json { "type": "linux64", "ssh_keys": ["ssh-key-id-1", "ssh-key-id-2"] } ``` ### Response #### Success Response (200) - **rescue** (object) - Information about the enabled rescue system. - **id** (int) - ID of the rescue system - **type** (string) - Type of the rescue system - **last_error** (string) - Last error message if any - **ssh_keys** (list[object]) - SSH keys injected into the rescue system - **id** (int) - ID of the SSH key - **fingerprint** (string) - Fingerprint of the SSH key - **name** (string) - Name of the SSH key - **public_key** (string) - Public key string - **iso_url** (string) - URL of the ISO image used - **iso_date** (string) - Date of the ISO image - **password** (string) - Password for the rescue system #### Response Example ```json { "rescue": { "id": 11223, "type": "linux64", "last_error": null, "ssh_keys": [ { "id": 1, "fingerprint": "abcdef12345...", "name": "My Key", "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAA..." } ], "iso_url": "http://distro.куб/linux-rescue-amd64.iso", "iso_date": "2022-01-01", "password": "p@$$wOrd" } } ``` ``` -------------------------------- ### GET /networks Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/api.clients.networks.md Retrieves a network by its name. ```APIDOC ## GET /networks ### Description Get network by name. ### Method GET ### Endpoint `/networks` ### Parameters #### Query Parameters - **name** (str) - Required - The name of the network to retrieve. ### Request Example `GET /networks?name=my-network` ### Response #### Success Response (200) - **network** (BoundNetwork or None) - The network object if found, otherwise null. #### Response Example ```json { "network": { "id": 123, "name": "my-network", "ip_range": "10.0.0.0/16", "created": "2023-10-27T10:00:00Z", "labels": {}, "subnets": [], "routes": [], "servers": [] } } ``` ``` -------------------------------- ### Python Development Environment Setup Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/index.md Set up a virtual environment and activate it for development. This is a standard practice for managing project dependencies in Python. ```sh make venv source venv/bin/activate ``` -------------------------------- ### GET /networks Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/api.clients.networks.md Retrieves a paginated list of networks from the account. ```APIDOC ## GET /networks ### Description Get a list of networks from this account. ### Method GET ### Endpoint `/networks` ### Parameters #### Query Parameters - **name** (str) - Optional - Filters networks by their name. - **label_selector** (str) - Optional - Filters networks by labels. The response will only contain networks matching the label selector. - **page** (int) - Optional - Specifies the page to fetch. - **per_page** (int) - Optional - Specifies how many results are returned by page. ### Request Example `GET /networks?page=1&per_page=50` ### Response #### Success Response (200) - **networks** (list[BoundNetwork]) - A list of network objects. - **meta** (Meta) - Metadata about the pagination. #### Response Example ```json { "networks": [ { "id": 123, "name": "network-1", "ip_range": "10.0.1.0/24", "created": "2023-10-27T10:00:00Z", "labels": {}, "subnets": [], "routes": [], "servers": [] }, { "id": 124, "name": "network-2", "ip_range": "10.0.2.0/24", "created": "2023-10-27T10:05:00Z", "labels": {}, "subnets": [], "routes": [], "servers": [] } ], "meta": { "pagination": { "page": 1, "per_page": 50, "total_entries": 2, "total_pages": 1 } } } ``` ``` -------------------------------- ### GET /networks Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/api.clients.networks.md Retrieves a list of all networks accessible to the account. ```APIDOC ## GET /networks ### Description Get all networks from this account. ### Method GET ### Endpoint `/networks` ### Parameters #### Query Parameters - **name** (str) - Optional - Filters networks by their name. - **label_selector** (str) - Optional - Filters networks by labels. The response will only contain networks matching the label selector. ### Request Example `GET /networks?name=my-network&label_selector=environment=production` ### Response #### Success Response (200) - **networks** (list[BoundNetwork]) - A list of network objects. #### Response Example ```json { "networks": [ { "id": 123, "name": "my-network", "ip_range": "10.0.0.0/16", "created": "2023-10-27T10:00:00Z", "labels": { "environment": "production" }, "subnets": [...], "routes": [...], "servers": [...] } ] } ``` ``` -------------------------------- ### Initialize Hetzner Cloud Client (Python) Source: https://context7.com/fahreddinozcan/hcloud-python-test5/llms.txt Demonstrates how to create an authenticated client instance for interacting with the Hetzner Cloud API. Supports basic initialization with an API token and advanced configuration including custom endpoints, application identification, polling intervals, and timeouts. The client includes automatic retry mechanisms for network issues and specific API errors. ```python from hcloud import Client # Basic initialization with API token client = Client(token="YOUR_HETZNER_CLOUD_API_TOKEN") # Advanced initialization with custom configuration client = Client( token="YOUR_API_TOKEN", api_endpoint="https://api.hetzner.cloud/v1", # Optional custom endpoint application_name="my-app", # Optional app identification application_version="1.0.0", # Optional version tracking poll_interval=2.0, # Seconds between action status polls poll_max_retries=120, # Max retries when polling actions timeout=(5.0, 30.0) # (connect_timeout, read_timeout) in seconds ) # The client provides automatic retry with exponential backoff for: # - Network timeouts # - HTTP 502/504 errors # - rate_limit_exceeded API errors # - conflict API errors ``` -------------------------------- ### CreateServerResponse Domain Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/api.clients.servers.md Contains details about a newly created server, including the server object, associated actions, and the root password. ```APIDOC ## CreateServerResponse Domain ### Description Contains details about a newly created server, including the server object, associated actions (like creation progress and subsequent actions), and the root password if no SSH key was provided. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **server** (BoundServer) - Required - The created server object. * **action** (BoundAction) - Required - An object representing the progress of the server creation. * **next_actions** (list[BoundAction]) - Optional - A list of additional actions that can be performed after server creation, such as starting the server. * **root_password** (str | None) - Optional - The root password for the server, provided if no SSH key was specified during creation. ### Request Example ```json { "server": { "id": 12345, "name": "my-server", "image": "ubuntu-20.04", "flavor": "cx11", "status": "creating" }, "action": { "id": 67890, "command": "create_server", "status": "running" }, "next_actions": [ { "id": 67891, "command": "start_server", "status": "pending" } ], "root_password": "s3cur3p4ssw0rd" } ``` ### Response #### Success Response (200) * **server** (BoundServer) - The created server object. * **action** (BoundAction) - An object representing the progress of the server creation. * **next_actions** (list[BoundAction]) - A list of additional actions that can be performed after server creation. * **root_password** (str | None) - The root password for the server. #### Response Example ```json { "server": { "id": 12345, "name": "my-server", "image": "ubuntu-20.04", "flavor": "cx11", "status": "running" }, "action": { "id": 67890, "command": "create_server", "status": "success" }, "next_actions": [], "root_password": "s3cur3p4ssw0rd" } ``` ``` -------------------------------- ### GET /isos/{id} Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/api.clients.isos.md Retrieves a specific ISO by its ID. ```APIDOC ## GET /isos/{id} ### Description Retrieves a specific ISO by its ID. ### Method GET ### Endpoint /isos/{id} ### Parameters #### Path Parameters - **id** (int) - Required - The ID of the ISO to retrieve. ### Response #### Success Response (200) - **iso** (BoundIso) - The requested BoundIso object. #### Response Example { "iso": { "id": 1, "name": "ubuntu-20.04", "type": "public", "architecture": "x86", "description": "Ubuntu 20.04 LTS", "deprecated": null, "deprecation": null } } ``` -------------------------------- ### POST /servers Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/api.clients.servers.md Creates a new server with specified configurations. This endpoint allows for detailed customization of server type, image, storage, networking, and other properties. ```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 /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. Reference `hcloud.server_types.domain.ServerType` or `hcloud.server_types.client.BoundServerType`. - **image** (object) - Required - Image the server is created from. Reference `hcloud.images.domain.Image` or `hcloud.images.client.BoundImage`. - **ssh_keys** (list[object]) - Optional - SSH keys which should be injected into the server at creation time. Each item should be a reference to `hcloud.ssh_keys.domain.SSHKey` or `hcloud.ssh_keys.client.BoundSSHKey`. - **volumes** (list[object]) - Optional - Volumes which should be attached to the server at the creation time. Volumes must be in the same location. Each item should be a reference to `hcloud.volumes.domain.Volume` or `hcloud.volumes.client.BoundVolume`. - **firewalls** (list[object]) - Optional - Firewall rules to apply to the server. Each item should be a reference to `hcloud.firewalls.domain.Firewall` or `hcloud.firewalls.client.BoundFirewall`. - **networks** (list[object]) - Optional - Networks which should be attached to the server at the creation time. Each item should be a reference to `hcloud.networks.domain.Network` or `hcloud.networks.client.BoundNetwork`. - **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) - Optional - Location where the server should be created. Reference `hcloud.locations.domain.Location` or `hcloud.locations.client.BoundLocation`. - **datacenter** (object) - Optional - Datacenter where the server should be created. Reference `hcloud.datacenters.domain.Datacenter` or `hcloud.datacenters.client.BoundDatacenter`. - **start_after_create** (bool) - Optional - Start Server right after creation. Defaults to True. - **automount** (bool) - Optional - Auto mount volumes after attach. - **placement_group** (object) - Optional - Placement Group where server should be added during creation. Reference `hcloud.placement_groups.domain.PlacementGroup` or `hcloud.placement_groups.client.BoundPlacementGroup`. - **public_net** (object) - Optional - Options to configure the public network of a server on creation. Reference `hcloud.servers.domain.ServerCreatePublicNetwork`. ### Request Example ```json { "name": "my-server", "server_type": {"id": 123, "name": "cx11"}, "image": {"id": 456, "name": "ubuntu-20.04"}, "labels": {"environment": "production"} } ``` ### Response #### Success Response (200) - **server** (object) - Preliminary information about the created server. - **action** (object) - Information about the server creation action. #### Response Example ```json { "server": { "id": 789, "name": "my-server", "status": "creating", "created": "2023-10-27T10:00:00Z" }, "action": { "id": 101, "command": "create_server", "status": "running" } } ``` ``` -------------------------------- ### GET /networks/{id} Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/api.clients.networks.md Retrieves details of a specific network by its 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. ### Request Example `GET /networks/123` ### Response #### Success Response (200) - **network** (BoundNetwork) - The network object. #### Response Example ```json { "network": { "id": 123, "name": "my-network", "ip_range": "10.0.0.0/16", "created": "2023-10-27T10:00:00Z", "labels": { "environment": "production" }, "subnets": [...], "routes": [...], "servers": [...] } } ``` ``` -------------------------------- ### Get Server Type by Name Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/api.clients.server_types.md Retrieves a server type by its name. ```APIDOC ## GET /server_types?name={name} ### Description Retrieves a server type by its name. ### Method GET ### Endpoint /server_types ### Parameters #### Query Parameters - **name** (str) - Required - Used to get Server type by name. ### Response #### Success Response (200) - **server_type** (dict | None) - The server type object, or null if not found. - **id** (int) - ID of the server type - **name** (str) - Unique identifier of the server type - **description** (str) - Description of the server type - **category** (str) - Category of the Server Type. - **cores** (int) - Number of cpu cores a server of this type will have - **memory** (int) - Memory a server of this type will have in GB - **disk** (int) - Disk size a server of this type will have in GB - **prices** (list[dict]) - Prices in different locations - **storage_type** (str) - Type of server boot drive. Choices: local, network - **cpu_type** (str) - Type of cpu. Choices: shared, dedicated - **architecture** (str) - Architecture of cpu. Choices: x86, arm - **deprecated** (bool | None) - True if server type is deprecated. This field is deprecated. Use deprecation instead. - **deprecation** (dict | None) - Describes if, when & how the resources was deprecated. If this field is set to None the resource is not deprecated. If it has a value, it is considered deprecated. - **included_traffic** (int | None) - Free traffic per month in bytes - **locations** (list[dict]) - Supported Location of the Server Type. ### Response Example { "server_type": { "id": 1, "name": "cx11", "description": "General Purpose", "category": "general", "cores": 2, "memory": 2, "disk": 20, "prices": [ { "location": "nbg1", "price_hourly": "0.00385714", "price_monthly": "0.276786" } ], "storage_type": "local", "cpu_type": "shared", "architecture": "x86", "deprecated": false, "deprecation": null, "included_traffic": 10737418240, "locations": [ { "name": "nbg1", "url": "https://robot-ur.your-server.de/loadbalancer/prices", "price_ranges": [] } ] } } ``` -------------------------------- ### Server Power and Reset Operations (Python) Source: https://context7.com/fahreddinozcan/hcloud-python-test5/llms.txt Demonstrates how to control the power state (on, off, reboot) and perform reset operations on a Hetzner Cloud server. It also shows how to wait for actions to complete. ```python from hcloud.images import Image from hcloud.server_types import ServerType # Assuming 'server' is an initialized Server object # Power operations server.power_on() # Start server server.power_off() # Force shutdown (like pulling power) server.shutdown() # Graceful shutdown (sends ACPI signal) server.reboot() # Graceful reboot # Reset operations action = server.reset() # Force reboot (like pressing reset button) action.wait_until_finished() # Wait for action to complete # Password reset result = server.reset_password() print(f"New root password: {result.root_password}") # Rebuild server with new image result = server.rebuild(image=Image(name="debian-12")) print(f"Rebuilding server, new root password: {result.root_password}") # Enable rescue mode and reboot into it result = server.enable_rescue(type="linux64") print(f"Rescue mode enabled, password: {result.root_password}") server.reboot() # Disable rescue mode server.disable_rescue() # Resize server (requires server to be off) server.power_off().wait_until_finished() server.change_type( server_type=ServerType(name="cx32"), upgrade_disk=True ).wait_until_finished() server.power_on() # Create server image/snapshot result = server.create_image( description="Backup before upgrade", type="snapshot", labels={"backup": "pre-upgrade"} ) image = result.image print(f"Created snapshot: {image.id}") # Request console access result = server.request_console() print(f"Console URL: {result.wss_url}") print(f"Password: {result.password}") # Attach/detach from network from hcloud.networks import Network server.attach_to_network( network=Network(id=4711), ip="10.0.0.5" ) server.detach_from_network(network=Network(id=4711)) ``` -------------------------------- ### Enable Rescue System Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/api.clients.servers.md Enable the Hetzner Rescue System for this server. ```APIDOC ## POST /servers/{server_id}/enable_rescue ### Description Enable the Hetzner Rescue System for this server. ### Method POST ### Endpoint `/servers/{server_id}/enable_rescue` ### Parameters #### Path Parameters - **server_id** (int) - Required - The ID of the server to enable rescue for. #### Query Parameters None #### Request Body - **type** (str) - Optional - Type of rescue system to boot. Choices: `linux64`, `linux32`, `freebsd64`. Defaults to `linux64`. - **ssh_keys** (list[str]) - Optional - Array of SSH key IDs which should be injected into the rescue system. Only available for types: `linux64` and `linux32`. ### Request Example ```json { "type": "linux64", "ssh_keys": ["ssh-rsa AAAAB3NzaC1... user@host"] } ``` ### Response #### Success Response (200) - **enable_rescue_response** (object) - Contains information about the enabled rescue system. - **rescue** (object) - **id** (int) - The ID of the rescue session. - **created** (str) - The creation date of the rescue session. - **type** (str) - The type of the rescue system. - **root_enabled** (bool) - Whether the root rescue is enabled. - **devices** (object) - Information about the devices. - **ssh_keys** (array) - SSH keys injected into the rescue system. - **next_actions** (array) - Actions related to enabling rescue. #### Response Example ```json { "enable_rescue_response": { "rescue": { "id": 10101, "created": "2023-01-01T17:00:00Z", "type": "linux64", "root_enabled": true, "devices": {}, "ssh_keys": ["ssh-rsa AAAAB3NzaC1... user@host"] }, "next_actions": [] } } ``` ``` -------------------------------- ### Get Zone by ID or Name Source: https://github.com/fahreddinozcan/hcloud-python-test5/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 Returns a single Zone. ### Method GET ### Endpoint `/zones/{id_or_name}` ### Parameters #### Path Parameters - **id_or_name** (int | str) - Required - ID or Name of the Zone. ### Request Example ```json { "example": "N/A (GET request)" } ``` ### Response #### Success Response (200) - **zone** (BoundZone) - The retrieved zone object. #### Response Example ```json { "zone": { "id": 123, "name": "zone-name", "server_count": 5, "prices": [ { "location": "nbg1", "price_hourly": { "net": "0.003", "gross": "0.00357" }, "price_monthly": { "net": "0.06", "gross": "0.0714" } } ], "cname": "zone-cname.example.com", "deprecated": false } } ``` **Experimental**: DNS API is in beta, breaking changes may occur within minor releases. See https://docs.hetzner.cloud/changelog#2025-10-07-dns-beta for more details. ``` -------------------------------- ### Get Network Actions Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/api.clients.networks.md Returns all action objects associated with a specific network. ```APIDOC ## GET /v1/networks/{network_id}/actions ### Description Returns all action objects for a network. ### Method GET ### Endpoint /v1/networks/{network_id}/actions ### Parameters #### Path Parameters - **network_id** (int) - Required - The ID of the network whose actions are to be retrieved. #### 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) - A list of action objects. - **id** (int) - ID of the action. - **command** (str) - Command executed. - **status** (str) - Status of the action. - **progress** (int) - Progress of the action in percent. - **started** (str) - Timestamp when the action started. - **finished** (str) - Timestamp when the action finished. - **resources** (list) - Resources associated with the action. - **error** (object | null) - Error details if the action failed. #### Response Example ```json { "actions": [ { "id": 153, "command": "create_network", "status": "success", "progress": 100, "started": "2023-01-01T10:00:00Z", "finished": "2023-01-01T10:01:00Z", "resources": [], "error": null } ] } ``` ``` -------------------------------- ### List and Retrieve Hetzner Cloud Servers (Python) Source: https://context7.com/fahreddinozcan/hcloud-python-test5/llms.txt Explains how to query existing cloud servers, including retrieving all servers, a single server by ID, or by name. It also demonstrates filtering servers by labels and status, and handling pagination for large numbers of servers. The `get_all()` method automatically manages pagination. ```python from hcloud import Client client = Client(token="YOUR_API_TOKEN") # Get all servers (automatically handles pagination) all_servers = client.servers.get_all() for server in all_servers: print(f"{server.id}: {server.name} - {server.status} - {server.public_net.ipv4.ip}") # Get single server by ID server = client.servers.get_by_id(12345) print(f"Server: {server.name}, Type: {server.server_type.name}") # Get server by name server = client.servers.get_by_name("my-web-server") if server: print(f"Found server: {server.id}") # Filtered listing with label selector and status servers_page = client.servers.get_list( label_selector="env=production", status=["running"], page=1, per_page=25 ) for server in servers_page.servers: print(f"{server.name}: {server.status}") print(f"Total pages: {servers_page.meta.pagination.total_entries // 25}") ``` -------------------------------- ### Get All Actions for Floating IP Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/api.clients.floating_ips.md Returns all action objects for a Floating IP. ```APIDOC ## GET /v1/floating_ips/{id}/actions ### Description Returns all action objects for a Floating IP. ### Method GET ### Endpoint /v1/floating_ips/{id}/actions ### Parameters #### Path Parameters - **id** (int) - Required - The ID of the Floating IP. #### 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** (array) - A list of action objects. - Each object has the same structure as described in Assign Floating IP to Server response. #### Response Example { "actions": [ { "id": 56789, "command": "assign_floating_ip", "status": "success", "progress": 100, "started": "2023-01-01T11:00:00+01:00", "finished": "2023-01-01T11:01:00+01:00", "resources": [ { "type": "floating_ip", "id": 12345 }, { "type": "server", "id": 98765 } ], "error": null } ] } ``` -------------------------------- ### Python Development - Build Documentation Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/index.md Build the project's documentation locally and open it in a web browser. This command is typically used to preview documentation changes. ```sh make docs ``` -------------------------------- ### Primary IPs - Get By Name Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/api.clients.primary_ips.md Retrieves a Primary IP object by its name. ```APIDOC ## GET /primary_ips?name={name} ### Description Get Primary IP by name. ### Method GET ### Endpoint /primary_ips ### Parameters #### Query Parameters - **name** (str) - Required - Used to get Primary IP by name. ### Response #### Success Response (200) - **primary_ip** (BoundPrimaryIP | None) - The Primary IP object if found, otherwise null. ``` -------------------------------- ### POST /servers/{id}/actions/attach_iso Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/api.clients.servers.md Attaches an ISO image to a server. This allows for booting the server from a specific ISO. ```APIDOC ## POST /servers/{id}/actions/attach_iso ### Description Attaches an ISO image to a server. This allows for booting the server from a specific ISO. ### Method POST ### Endpoint /servers/{id}/actions/attach_iso ### Parameters #### Path Parameters - **id** (int) - Required - The ID of the server to attach the ISO to. #### Request Body - **iso** (int | dict) - Required - The ID or data of the ISO to attach. ### Response #### Success Response (202) - **action** (BoundAction) - An object representing the asynchronous action performed. #### Response Example ```json { "action": { "id": 54321, "command": "attach_iso", "status": "running" } } ``` ``` -------------------------------- ### Create Server Image Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/api.clients.servers.md Creates a server image (snapshot) from a server's disks. ```APIDOC ## POST /servers/{server_id}/create_image ### Description Creates an image (snapshot) from a server by copying the contents of its disks. ### Method POST ### Endpoint `/servers/{server_id}/create_image` ### Parameters #### Path Parameters - **server_id** (int) - Required - The ID of the server to create an image from. #### Request Body - **description** (string) - Optional - Description of the image. Auto-generates if not provided. - **type** (string) - Optional - Type of image to create. Choices: `snapshot`, `backup`. Defaults to `snapshot`. - **labels** (dict[str, str]) - Optional - User-defined labels (key-value pairs). ### Request Example ```json { "description": "My server snapshot", "type": "snapshot", "labels": {"environment": "production"} } ``` ### Response #### Success Response (200) - **image** (object) - The created image object. - **id** (int) - ID of the image - **type** (string) - Type of the image - **name** (string) - Name of the image - **description** (string) - Description of the image - **created** (string) - Timestamp when the image was created - **status** (string) - Status of the image - **os_flavor** (string) - OS flavor of the image - **os_version** (string) - OS version of the image - **protection** (object) - Protection level of the image - **delete** (boolean) - Whether the image can be deleted - **server_id** (int) - ID of the server the image was created from - **size_graphics** (float) - Size of the image in GB - **labels** (dict[str, str]) - User-defined labels #### Response Example ```json { "image": { "id": 98765, "type": "snapshot", "name": "my-server-snapshot", "description": "My server snapshot", "created": "2023-01-01T11:00:00Z", "status": "creating", "os_flavor": "ubuntu", "os_version": "20.04", "protection": {"delete": false}, "server_id": 67890, "size_graphics": 20.5, "labels": {"environment": "production"} } } ``` ``` -------------------------------- ### GET /load_balancer_types/{id} Source: https://github.com/fahreddinozcan/hcloud-python-test5/blob/main/_context7_rst_markdown_build/api.clients.load_balancer_types.md Retrieves a specific Load Balancer type by its ID. ```APIDOC ## GET /load_balancer_types/{id} ### Description Retrieves a specific Load Balancer Type by its unique ID. ### Method GET ### Endpoint /load_balancer_types/{id} ### Parameters #### Path Parameters - **id** (int) - Required - The ID of the Load Balancer type to retrieve. ### Response #### Success Response (200) - **load_balancer_type** (LoadBalancerType) - The requested Load Balancer type object. #### Response Example { "load_balancer_type": { "id": 1, "name": "lb_type_1", "description": "A standard load balancer type", "max_connections": 1000, "max_services": 5, "max_targets": 50, "max_assigned_certificates": 10, "prices": [ { "location": "fkb", "price_hourly": {"gross": 0.0123,"net": 0.0103}, "price_monthly": {"gross": 1.23,"net": 1.03} } ] } } ```