### Power On Server Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/api.clients.servers.md Starts a server by turning its power on. ```APIDOC ## POST /servers/{id}/poweron ### Description Starts a server by turning its power on. ### Method POST ### Endpoint `/servers/{id}/poweron` ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the server to power on. #### Request Body This endpoint does not require a request body. ### Response #### Success Response (200) - **action** (BoundAction) - Details of the initiated power on action. #### Response Example ```json { "action": { "id": 12346, "command": "poweron", "started_at": "2023-10-27T10:05:00Z", "completed_at": null, "status": "running", "resources": [ { "id": 67890, "type": "server" } ] } } ``` ``` -------------------------------- ### Install Pre-commit Hooks for Development Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/index.md Instructions to install pre-commit hooks, which automate code formatting and linting before committing changes. ```sh pre-commit install ``` -------------------------------- ### Reset Server Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/api.clients.servers.md Cuts power to a server and then starts it again. ```APIDOC ## POST /servers/{id}/reset ### Description Cuts power to a server and starts it again. ### Method POST ### Endpoint `/servers/{id}/reset` ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the server to reset. #### Request Body This endpoint does not require a request body. ### Response #### Success Response (200) - **action** (BoundAction) - Details of the initiated reset action. #### Response Example ```json { "action": { "id": 12350, "command": "reset", "started_at": "2023-10-27T10:25:00Z", "completed_at": null, "status": "running", "resources": [ { "id": 67890, "type": "server" } ] } } ``` ``` -------------------------------- ### Install hcloud Python Library Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/index.md Command to install the hcloud Python library using pip. This is the first step to using the library in your Python projects. ```sh pip install hcloud ``` -------------------------------- ### POST /servers Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/api.clients.servers.md Creates a new server with specified configurations. ```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 - **image** (object) - Required - Image the server is created from - **ssh_keys** (list[object]) - Optional - SSH keys which should be injected into the server at creation time - **volumes** (list[object]) - Optional - Volumes which should be attached to the server at the creation time. Volumes must be in the same location. - **firewalls** (list[object]) - Optional - Firewalls which should be attached to the server at the creation time. - **networks** (list[object]) - Optional - Networks which should be attached to the server at the creation time. - **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 the server should be created in - **datacenter** (object) - Optional - Datacenter the server should be created in - **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 - **public_net** (object) - Optional - Options to configure the public network of a server on creation ### Request Example ```json { "name": "my-server", "server_type": {"id": 123}, "image": {"id": 456}, "ssh_keys": [{"id": 789}], "location": {"id": 101} } ``` ### Response #### Success Response (200) - **server** (object) - Preliminary information about the created server. - **action** (object) - Information about the progress of the server creation. #### Response Example ```json { "server": { "id": 12345, "name": "my-server", "status": "creating", "created": "2023-10-27T10:00:00Z" }, "action": { "id": 67890, "command": "create_server", "status": "running" } } ``` ``` -------------------------------- ### Build and Open Documentation Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/index.md Command to build the project's documentation using Make and open it in a web browser. ```sh make docs ``` -------------------------------- ### Create and List Hetzner Cloud Servers with Python Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/index.md Example demonstrating how to create a new server and then list all existing servers using the hcloud Python client. It requires an API token and specifies server type and image. ```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 Network Actions Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/api.clients.networks.md Returns all action objects for a network. ```APIDOC ## GET /v1/networks/{id}/actions ### Description Retrieves a list of all actions performed on a specific network. ### Method GET ### Endpoint /v1/networks/{id}/actions ### Parameters #### Path Parameters - **id** (int) - Required - The ID of the network to retrieve actions for. #### Query Parameters - **status** (list[str]) - Optional - Filters actions by their status. Possible values: `running`, `success`, `error`. - **sort** (list[str]) - Optional - Specifies the sorting order of the actions. 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) - 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 was started. - **finished** (str) - Timestamp when the action was finished. - **resources** (list) - Resources affected by the action. - **error** (object) - Error details if the action failed. #### Response Example ```json { "actions": [ { "id": 54321, "command": "add_network_route", "status": "success", "progress": 100, "started": "2023-10-26T11:00:00Z", "finished": "2023-10-26T11:01:00Z", "resources": [ { "type": "network", "id": 12345 } ], "error": null }, { "id": 54322, "command": "add_network_subnet", "status": "running", "progress": 50, "started": "2023-10-26T11:05:00Z", "finished": null, "resources": [ { "type": "network", "id": 12345 } ], "error": null } ] } ``` ``` -------------------------------- ### Create and Manage Load Balancers Source: https://context7.com/fahreddinozcan/hcloud-python-test6/llms.txt Demonstrates creating a load balancer, adding HTTP/HTTPS services, configuring targets, updating algorithms, retrieving all load balancers, and deleting a load balancer. Requires a Hetzner Cloud client instance. ```python from hcloud import Client from hcloud.load_balancer_types import LoadBalancerType from hcloud.locations import Location from hcloud.load_balancer_services import LoadBalancerService, LoadBalancerServiceHttp from hcloud.load_balancer_health_checks import LoadBalancerHealthCheck, LoadBalancerHealthCheckHttp from hcloud.load_balancer_targets import LoadBalancerTarget, LoadBalancerTargetLabelSelector from hcloud.load_balancer_algorithms import LoadBalancerAlgorithm # Assuming 'client' is an initialized Hcloud Client instance # client = Client(token="YOUR_API_TOKEN") # Create load balancer response = client.load_balancers.create( name="web-lb", load_balancer_type=LoadBalancerType(name="lb11"), location=Location(name="nbg1"), labels={"environment": "production"}, network_zone="eu-central" ) load_balancer = response.load_balancer action = response.action print(f"Load Balancer ID: {load_balancer.id}") print(f"Public IPv4: {load_balancer.public_net.ipv4.ip}") action.wait_until_finished() # Add service to load balancer action = load_balancer.add_service( LoadBalancerService( protocol="http", listen_port=80, destination_port=80, proxyprotocol=False, http=LoadBalancerServiceHttp( sticky_sessions=True, cookie_name="HCLBSTICKY", cookie_lifetime=300, redirect_http=False ), health_check=LoadBalancerHealthCheck( protocol="http", port=80, interval=15, timeout=10, retries=3, http=LoadBalancerHealthCheckHttp( path="/health", status_codes=["200", "201"], tls=False ) ) ) ) action.wait_until_finished() # Add HTTPS service action = load_balancer.add_service( LoadBalancerService( protocol="https", listen_port=443, destination_port=443, proxyprotocol=False, http=LoadBalancerServiceHttp( certificates=[client.certificates.get_by_name("my-cert").id] ) ) ) action.wait_until_finished() # Add targets (servers) to load balancer server = client.servers.get_by_name("web-server-01") action = load_balancer.add_target( LoadBalancerTarget(type="server", server=server, use_private_ip=False) ) action.wait_until_finished() # Add target using label selector action = load_balancer.add_target( LoadBalancerTarget( type="label_selector", label_selector=LoadBalancerTargetLabelSelector(selector="role=webserver"), use_private_ip=True ) ) action.wait_until_finished() # Update load balancer algorithm action = load_balancer.change_algorithm( LoadBalancerAlgorithm(type="least_connections") ) action.wait_until_finished() # Get all load balancers load_balancers = client.load_balancers.get_all() for lb in load_balancers: print(f"LB: {lb.name}, Targets: {len(lb.targets)}, Services: {len(lb.services)}") # Delete load balancer success = load_balancer.delete() print(f"Load balancer deleted: {success}") ``` -------------------------------- ### GET /volumes?name={name} Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/api.clients.volumes.md Retrieves a volume by its name. ```APIDOC ## GET /volumes?name={name} ### Description Get volume by name. ### Method GET ### Endpoint `/volumes` ### Parameters #### Query Parameters - **name** (str) - Required - Used to get volume by name. ### Response #### Success Response (200) - **volumes** (list[BoundVolume]) - A list containing the volume object if found, otherwise an empty list. #### Response Example { "volumes": [ { "id": 12345, "name": "my-volume", "size": 10, "created": "2023-10-27T09:00:00Z", "status": "available", "protection": { "delete": false }, "server": null, "location": { "id": 1, "name": "fsn1", "description": "Falkenstein" }, "labels": {} } ], "meta": { "pagination": { "page": 1, "per_page": 25, "total_entries": 1, "total_pages": 1 } } } ``` -------------------------------- ### GET /volumes/{id} Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/api.clients.volumes.md Retrieves a specific volume by its ID. ```APIDOC ## GET /volumes/{id} ### Description Get a specific volume by its id. ### Method GET ### Endpoint `/volumes/{id}` ### Parameters #### Path Parameters - **id** (int) - Required - The ID of the volume to retrieve. ### Response #### Success Response (200) - **volume** (BoundVolume) - The volume object. #### Response Example { "volume": { "id": 12345, "name": "my-volume", "size": 10, "created": "2023-10-27T09:00:00Z", "status": "available", "protection": { "delete": false }, "server": null, "location": { "id": 1, "name": "fsn1", "description": "Falkenstein" }, "labels": {} } } ``` -------------------------------- ### Set up Virtual Environment for Development Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/index.md Commands to create and activate a virtual environment for developing the hcloud Python library. This isolates project dependencies. ```sh make venv source venv/bin/activate ``` -------------------------------- ### GET /volumes Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/api.clients.volumes.md Retrieves a list of all volumes associated with the account. ```APIDOC ## GET /volumes ### Description Get all volumes from this account. ### Method GET ### Endpoint `/volumes` ### Parameters #### Query Parameters - **label_selector** (str) - Optional - Filter volumes by labels. The response will only contain volumes matching the label selector. - **status** (list[str]) - Optional - Filter volumes by their status. - **name** (str) - Optional - Filter volumes by their name. - **page** (int) - Optional - Specifies the page to fetch. - **per_page** (int) - Optional - Specifies how many results are returned per page. ### Response #### Success Response (200) - **volumes** (list[BoundVolume]) - A list of volume objects. - **meta** (Meta) - Metadata about the pagination. #### Response Example { "volumes": [ { "id": 12345, "name": "my-volume", "size": 10, "created": "2023-10-27T09:00:00Z", "status": "available", "protection": { "delete": false }, "server": null, "location": { "id": 1, "name": "fsn1", "description": "Falkenstein" }, "labels": {} } ], "meta": { "pagination": { "page": 1, "per_page": 25, "total_entries": 1, "total_pages": 1 } } } ``` -------------------------------- ### Create Hetzner Cloud Server (Python) Source: https://context7.com/fahreddinozcan/hcloud-python-test6/llms.txt Creates a new Hetzner Cloud server with specified configurations, including name, server type, image, and location. Supports advanced options like SSH key injection, labels, user data, and automatic startup. ```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") # Create a basic server response = client.servers.create( name="web-server-01", server_type=ServerType(name="cx22"), # 2 vCPU, 4GB RAM image=Image(name="ubuntu-24.04"), location=Location(name="nbg1") ) server = response.server root_password = response.root_password action = response.action print(f"Server ID: {server.id}") print(f"Server Name: {server.name}") print(f"Status: {server.status}") print(f"Public IPv4: {server.public_net.ipv4.ip}") print(f"Public IPv6: {server.public_net.ipv6.ip}") print(f"Root Password: {root_password}") # Wait for server creation to complete action.wait_until_finished(max_retries=100) print(f"Server creation completed: {action.status}") # Create server with SSH keys and labels response = client.servers.create( name="app-server-01", server_type=ServerType(name="cx32"), image=Image(name="debian-12"), ssh_keys=[SSHKey(name="my-ssh-key")], labels={"environment": "production", "team": "backend"}, user_data="#cloud-config\npackages:\n - docker.io\n - nginx", automount=False, start_after_create=True ) server = response.server print(f"Created server {server.name} with labels: {server.labels}") ``` -------------------------------- ### Client Initialization for Hetzner Cloud (Python) Source: https://context7.com/fahreddinozcan/hcloud-python-test6/llms.txt Initializes the main hcloud-python client for interacting with Hetzner Cloud resources. Supports basic initialization with an API token and advanced configuration for custom retry, timeout, and endpoint settings. ```Python from hcloud import Client, exponential_backoff_function # Basic initialization with API token client = Client(token="YOUR_HETZNER_API_TOKEN") # Advanced initialization with custom retry and timeout settings client = Client( token="YOUR_HETZNER_API_TOKEN", api_endpoint="https://api.hetzner.cloud/v1", application_name="MyApp", application_version="1.0.0", poll_interval=exponential_backoff_function( base=1.0, multiplier=2, cap=60.0, jitter=True ), poll_max_retries=120, timeout=(5.0, 30.0) # (connect_timeout, read_timeout) ) # Client provides access to all resource endpoints print(f"Server client: {client.servers}") print(f"Volume client: {client.volumes}") print(f"Network client: {client.networks}") ``` -------------------------------- ### GET /zones Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/api.clients.zones.md Retrieves a list of all Zones with optional filtering and sorting. ```APIDOC ## GET /zones ### Description Returns a list of all Zones. ### Method GET ### Endpoint `/zones` ### Parameters #### Query Parameters - **name** (str | None) - Optional - Filter resources by their name. - **mode** (Literal['primary', 'secondary'] | None) - Optional - Filter resources by their mode. - **label_selector** (str | None) - Optional - Filter resources by labels. - **sort** (list[str] | None) - Optional - Sort resources by field and direction. ### Response #### Success Response (200) - **zones** (list[BoundZone]) - A list of Zone objects. #### Response Example ```json { "zones": [ { "id": 123, "name": "zone.example.com", "server_type": "cx11", "price_monthly": 0.0, "price_hourly": 0.0, "currency": "EUR", "created": "2023-01-01T12:00:00Z", "deprecated": false, "ttl": 3600, "is_default": true } ] } ``` ``` -------------------------------- ### GET /zones/{zone}/actions Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/api.clients.zones.md Retrieves all actions for a specific Zone. ```APIDOC ## GET /zones/{zone}/actions ### Description Returns all actions for a specific Zone. ### Method GET ### Endpoint `/zones/{zone}/actions` ### Parameters #### Path Parameters - **zone** (Zone | BoundZone) - Required - Zone to fetch the Actions from. #### Query Parameters - **status** (list[str] | None) - Optional - Filter the actions by status. The response will only contain actions matching the specified statuses. - **sort** (list[str] | None) - Optional - Sort resources by field and direction. ### Response #### Success Response (200) - **actions** (list[BoundAction]) - A list of actions associated with the Zone. #### Response Example ```json { "actions": [ { "id": 1, "command": "delete_zone", "status": "success", "started": "2023-01-01T12:00:00Z", "finished": "2023-01-01T12:05:00Z" } ] } ``` ``` -------------------------------- ### Enable Rescue System Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/api.clients.servers.md Enables the Hetzner Rescue System for a server. ```APIDOC ## POST /servers/{server_id}/actions/enable_rescue ### Description Enable the Hetzner Rescue System for this server. ### Method POST ### Endpoint `/servers/{server_id}/actions/enable_rescue` ### Parameters #### Path Parameters - **server_id** (int) - Required - The ID of the server. #### 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`. ### Response #### Success Response (200) - **enable_rescue** (object) - Details of the enable rescue response. - **root_password** (str) - The root password for the rescue system. - **iso_image** (str) - The ISO image used for the rescue system. - **nx_servers** (array) - List of nx servers. #### Response Example ```json { "enable_rescue": { "root_password": "a_very_secret_password", "iso_image": "linux64", "nx_servers": ["1.2.3.4", "5.6.7.8"] } } ``` ``` -------------------------------- ### GET /zones/{id_or_name} Source: https://github.com/fahreddinozcan/hcloud-python-test6/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 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": 123, "name": "zone.example.com", "server_type": "cx11", "price_monthly": 0.0, "price_hourly": 0.0, "currency": "EUR", "created": "2023-01-01T12:00:00Z", "deprecated": false, "ttl": 3600, "is_default": true } } ``` ``` -------------------------------- ### Create Server Response Domain Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/api.clients.servers.md Details the response from a server creation request, including the created server, associated actions, and root password. ```APIDOC ## class CreateServerResponse ### Description Create Server Response Domain ### Parameters #### Response Body - **server** (BoundServer) - The created server - **action** (BoundAction) - Shows the progress of the server creation - **next_actions** (List[BoundAction]) - Additional actions like a start_server action after the server creation - **root_password** (str | None) - The root password of the server if no SSH-Key was given on server creation ``` -------------------------------- ### GET /servers/{id}/actions Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/api.clients.servers.md Returns all action objects for a server. ```APIDOC ## GET /servers/{id}/actions ### Description Returns all action objects for a server. ### Method GET ### Endpoint /servers/{id}/actions ### Parameters #### Path Parameters - **id** (int) - Required - The ID of the server to retrieve actions for. #### 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`. ### Request Example (No request body for GET) ### Response #### Success Response (200) - **actions** (list) - A list of action objects. - Each object contains: - **id** (int) - ID of the action - **command** (str) - Command of the action - **status** (str) - Status of the action - **progress** (int) - Progress of the action in percent - **started** (str) - Timestamp of when the action was started - **finished** (str) - Timestamp of when the action was finished - **resources** (object) - Resources affected by the action - **error** (object) - Error message if the action failed #### Response Example ```json { "actions": [ { "id": 12345, "command": "change_server_type", "status": "success", "progress": 100, "started": "2023-10-27T10:00:00Z", "finished": "2023-10-27T10:02:00Z", "resources": { "server": { "id": 67890, "name": "my-server", "server_number": 123456789 } }, "error": null }, { "id": 12347, "command": "delete_server", "status": "running", "progress": 10, "started": "2023-10-27T10:10:00Z", "finished": null, "resources": { "server": { "id": 67890, "name": "my-server", "server_number": 123456789 } }, "error": null } ] } ``` ``` -------------------------------- ### Get Network by ID Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/api.clients.networks.md Retrieves a specific network by its unique identifier. ```APIDOC ## GET /networks/{id} ### Description Get a specific network by its ID. ### Method GET ### Endpoint `/networks/{id}` ### Parameters #### Path Parameters - **id** (int) - Required - The ID of the network to retrieve. ### 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", "subnet_range": "10.0.1.0/24", "created": "2023-01-01T10:00:00Z", "labels": { "environment": "production" }, "protection": { "delete": false }, "routes": [], "subnets": [ { "id": 456, "type": "cloud", "ip_range": "10.0.1.0/24", "gateway": "10.0.1.1" } ] } } ``` ``` -------------------------------- ### Create, Configure, and Apply Firewalls with hcloud-python Source: https://context7.com/fahreddinozcan/hcloud-python-test6/llms.txt Shows how to define firewall rules, create a firewall, apply it to servers or using label selectors, set rules, remove it from resources, list firewalls, and delete them. Requires a valid API token. ```python from hcloud import Client from hcloud.firewalls import Firewall, FirewallRule, FirewallResource client = Client(token="YOUR_API_TOKEN") # Define firewall rules rules = [ FirewallRule( direction="in", protocol="tcp", source_ips=["0.0.0.0/0", "::/0"], port="80", description="Allow HTTP" ), FirewallRule( direction="in", protocol="tcp", source_ips=["0.0.0.0/0", "::/0"], port="443", description="Allow HTTPS" ), FirewallRule( direction="in", protocol="tcp", source_ips=["10.0.0.0/8"], port="22", description="Allow SSH from internal network" ), FirewallRule( direction="out", protocol="tcp", destination_ips=["0.0.0.0/0", "::/0"], port="any", description="Allow all outbound TCP" ) ] # Create firewall response = client.firewalls.create( name="web-firewall", rules=rules, labels={"type": "web-server"} ) firewall = response.firewall actions = response.actions print(f"Firewall ID: {firewall.id}, Name: {firewall.name}") # Wait for all actions to complete for action in actions: action.wait_until_finished() # Apply firewall to server server = client.servers.get_by_name("web-server-01") actions = firewall.apply_to_resources([ FirewallResource(type="server", server=server) ]) for action in actions: action.wait_until_finished() print(f"Firewall applied to {server.name}") # Apply firewall using label selector from hcloud.firewalls import FirewallResourceLabelSelector actions = firewall.apply_to_resources([ FirewallResource( type="label_selector", label_selector=FirewallResourceLabelSelector(selector="environment=production") ) ]) # Set firewall rules (replaces all existing rules) actions = firewall.set_rules(rules=[ FirewallRule( direction="in", protocol="tcp", source_ips=["0.0.0.0/0"], port="8080", description="Allow custom port" ) ]) # Remove firewall from resources actions = firewall.remove_from_resources([ FirewallResource(type="server", server=server) ]) # Get all firewalls firewalls = client.firewalls.get_all(label_selector="type=web-server") for fw in firewalls: print(f"Firewall: {fw.name}, Rules: {len(fw.rules)}") # Delete firewall success = firewall.delete() print(f"Firewall deleted: {success}") ``` -------------------------------- ### Zone Creation API Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/api.clients.zones.md Create a new DNS zone within Hetzner Cloud. ```APIDOC ## POST /zones ### Description Creates a Zone. A default SOA and three NS resource records with the assigned Hetzner nameservers are created automatically. ### Method POST ### Endpoint `/zones` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **name** (str) - Required - Name of the Zone. - **mode** (Literal['primary', 'secondary']) - Required - Mode of the Zone. - **ttl** (int | None) - Optional - Default Time To Live (TTL) of the Zone. - **labels** (dict[str, str] | None) - Optional - User-defined labels (key/value pairs) for the Resource. - **primary_nameservers** (list[[ZonePrimaryNameserver](#hcloud.zones.domain.ZonePrimaryNameserver)] | None) - Optional - Primary nameservers of the Zone. - **rrsets** (list[[ZoneRRSet](#hcloud.zones.domain.ZoneRRSet)] | None) - Optional - RRSets to be added to the Zone. - **zonefile** (str | None) - Optional - Zone file to import. ### Request Example ```json { "name": "example.com", "mode": "primary", "ttl": 3600, "labels": {"environment": "production"} } ``` ### Response #### Success Response (200) - **zone** (object) - The created Zone object. - **id** (int) - ID of the zone. - **name** (str) - Name of the zone. - **ttl** (int) - Default TTL of the zone. - **created** (string) - Timestamp when the zone was created. - **verification_records** (list) - Verification records for the zone. - **labels** (dict[str, str]) - User-defined labels for the zone. - **status** (string) - Status of the zone. - **records_count** (int) - Number of resource records in the zone. - **name_server** (string) - Primary name server for the zone. - **account_id** (int) - ID of the account the zone belongs to. - **zone_type** (string) - Type of the zone (primary/secondary). #### Response Example ```json { "zone": { "id": 12345, "name": "example.com", "ttl": 3600, "created": "2023-01-01T10:00:00Z", "verification_records": [], "labels": {"environment": "production"}, "status": "active", "records_count": 0, "name_server": "ns1.hetzner.com", "account_id": 1, "zone_type": "primary" } } ``` **Experimental**: DNS API is in beta, breaking changes may occur within minor releases. See [https://docs.hetzner.cloud/changelog#2025-10-07-dns-beta](https://docs.hetzner.cloud/changelog#2025-10-07-dns-beta) for more details. ``` -------------------------------- ### GET /volumes/actions Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/api.clients.volumes.md Retrieves a list of all actions performed on a specific volume. ```APIDOC ## GET /volumes/actions ### Description Returns all action objects for a volume. ### Method GET ### Endpoint `/volumes/{volume_id}/actions` ### Parameters #### Query Parameters - **status** (list[str]) - Optional - Filter actions by their status (running, success, error). - **sort** (list[str]) - Optional - Specify how the results are sorted (e.g., `id`, `status:asc`). - **page** (int) - Optional - Specifies the page to fetch. - **per_page** (int) - Optional - Specifies how many results are returned per page. ### Response #### Success Response (200) - **actions** (list[BoundAction]) - A list of action objects. - **meta** (Meta) - Metadata about the pagination. #### Response Example { "actions": [ { "id": 12345, "command": "attach_volume", "status": "success", "progress": 100, "started": "2023-10-27T10:00:00Z", "finished": "2023-10-27T10:05:00Z", "resources": [ { "id": 67890, "type": "volume" } ], "error": null } ], "meta": { "pagination": { "page": 1, "per_page": 25, "total_entries": 1, "total_pages": 1 } } } ``` -------------------------------- ### Server Class Documentation Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/api.clients.servers.md Details about the Server class, including its properties and available status options. ```APIDOC ## Server Class ### Description Represents a server resource in the Hetzner Cloud. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None #### Server Properties: - **id** (int) - ID of the server - **name** (str) - Name of the server (must be unique per project and a valid hostname as per RFC 1123) - **status** (str) - Status of the server. Choices: running, initializing, starting, stopping, off, deleting, migrating, rebuilding, unknown - **created** (datetime) - Point in time when the server was created - **public_net** (PublicNetwork) - Public network information. - **server_type** (BoundServerType) - Server type details. - **datacenter** (BoundDatacenter) - Datacenter where the server is located. - **image** (BoundImage) - Image used for the server. - **iso** (BoundIso) - ISO image attached to the server. - **rescue_enabled** (bool) - True if rescue mode is enabled. - **locked** (bool) - True if server is locked. - **backup_window** (str) - Time window for backups. - **outgoing_traffic** (int) - Outbound traffic for the current billing period. - **ingoing_traffic** (int) - Inbound traffic for the current billing period. - **included_traffic** (int) - Free traffic for the current billing period. - **primary_disk_size** (int) - Size of the primary disk. - **protection** (dict) - Protection configuration for the server. - **labels** (dict[str, str]) - User-defined labels. - **volumes** (list[BoundVolume]) - Volumes assigned to this server. - **private_net** (list[PrivateNet]) - Private network information. ### Server Statuses: - **STATUS_DELETING** (*str*) - 'deleting' - **STATUS_INIT** (*str*) - 'initializing' - **STATUS_MIGRATING** (*str*) - 'migrating' - **STATUS_OFF** (*str*) - 'off' - **STATUS_REBUILDING** (*str*) - 'rebuilding' - **STATUS_RUNNING** (*str*) - 'running' - **STATUS_STARTING** (*str*) - 'starting' - **STATUS_STOPPING** (*str*) - 'stopping' - **STATUS_UNKNOWN** (*str*) - 'unknown' ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Get Action by ID Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/api.clients.actions.md Retrieves a specific action by its unique ID. ```APIDOC ## GET /actions/{id} ### Description Retrieves a specific action by its unique ID. ### Method GET ### Endpoint /actions/{id} ### Parameters #### Path Parameters - **id** (int) - Required - The ID of the action to retrieve. ### Response #### Success Response (200) - **action** (BoundAction) - The requested BoundAction object. #### Response Example ```json { "action": { "id": 12345, "command": "create_server", "status": "success", "progress": 100, "started": "2023-10-27T10:00:00Z", "finished": "2023-10-27T10:05:00Z", "resources": [ { "id": 67890, "type": "server" } ], "error": null } } ``` ``` -------------------------------- ### Get ISO by ID Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/api.clients.isos.md Retrieves a specific ISO by its unique identifier. ```APIDOC ## GET /isos/{id} ### Description Retrieves a specific ISO by its unique identifier. ### 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 ISO object. #### Response Example { "iso": { "id": 123, "name": "ubuntu-20.04", "type": "public", "description": "Ubuntu 20.04 LTS", "architecture": "x86", "created": "2023-01-01T10:00:00Z", "deprecated": null } } ``` -------------------------------- ### Enable Backup Source: https://github.com/fahreddinozcan/hcloud-python-test6/blob/main/_context7_rst_markdown_build/api.clients.servers.md Enables and configures the automatic daily backup option for the server. ```APIDOC ## POST /servers/{server_id}/actions/enable_backup ### Description Enables and configures the automatic daily backup option for the server. Enabling automatic backups will increase the price of the server by 20%. ### Method POST ### Endpoint `/servers/{server_id}/actions/enable_backup` ### Parameters #### Path Parameters - **server_id** (int) - Required - The ID of the server. ### Response #### Success Response (200) - **action** (object) - Details of the enable backup action. - **id** (int) - The ID of the action. - **command** (str) - The command executed. - **status** (str) - The status of the action (`running`, `success`, `error`). - **started_at** (datetime) - The time the action was started. - **completed_at** (datetime) - The time the action was completed. - **resources** (array) - Resources affected by the action. - **error** (object) - Error details if the action failed. #### Response Example ```json { "action": { "id": 98769, "command": "enable_backup", "status": "running", "started_at": "2023-10-27T11:20:00Z", "completed_at": null, "resources": [ { "type": "server", "id": 67890 } ], "error": null } } ``` ``` -------------------------------- ### Create, Configure, and Manage Networks with hcloud-python Source: https://context7.com/fahreddinozcan/hcloud-python-test6/llms.txt Demonstrates creating, adding subnets and routes, attaching/detaching servers, listing, updating, and deleting private networks using the hcloud-python client. Requires a valid API token. ```python from hcloud import Client from hcloud.networks import Network, NetworkSubnet client = Client(token="YOUR_API_TOKEN") # Create a network response = client.networks.create( name="app-network", ip_range="10.0.0.0/16", labels={"environment": "production"} ) network = response.network print(f"Network ID: {network.id}, IP Range: {network.ip_range}") # Add subnet to network action = network.add_subnet( NetworkSubnet( ip_range="10.0.1.0/24", network_zone="eu-central", type="cloud" ) ) action.wait_until_finished() print("Subnet added") # Add route to network from hcloud.networks import NetworkRoute action = network.add_route( NetworkRoute(destination="10.100.0.0/16", gateway="10.0.1.1") ) action.wait_until_finished() # Attach server to network server = client.servers.get_by_name("web-server-01") action = network.attach_server(server=server, ip="10.0.1.5") action.wait_until_finished() print(f"Server attached to network with IP: 10.0.1.5") # Detach server from network action = network.detach_server(server=server) action.wait_until_finished() # Get all networks networks = client.networks.get_all() for net in networks: print(f"Network: {net.name}, IP Range: {net.ip_range}") print(f" Subnets: {len(net.subnets)}") print(f" Servers: {len(net.servers)}") # Update network updated_network = network.update( name="app-network-renamed", expose_routes_to_vswitch=True ) # Delete network success = network.delete() print(f"Network deleted: {success}") ```