### Install Hetzner Cloud Python from local source Source: https://github.com/fahreddinozcan/hcloud-python-test14/blob/main/_context7_rst_markdown_build/installation.md Installs the Hetzner Cloud Python SDK after cloning the source code. This command should be run from the root directory of the cloned repository. ```console pip install . ``` -------------------------------- ### Clone Hetzner Cloud Python repository Source: https://github.com/fahreddinozcan/hcloud-python-test14/blob/main/_context7_rst_markdown_build/installation.md Clones the Hetzner Cloud Python SDK source code from the official GitHub repository. ```console git clone git://github.com/hetznercloud/hcloud-python ``` -------------------------------- ### Server Power On Source: https://github.com/fahreddinozcan/hcloud-python-test14/blob/main/_context7_rst_markdown_build/api.clients.servers.md Starts a server by turning its power on. ```APIDOC ## POST /servers/{id}/actions/power_on ### Description Starts a server by turning its power on. ### Method POST ### Endpoint `/servers/{id}/actions/power_on` ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the server to power on. #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **action** (object) - Details of the power on action. #### Response Example { "action": { "id": 12346, "command": "power_on", "status": "running", "started_at": "2023-01-01T12:05:00Z", "finished_at": null, "resources": { "id": 67890, "type": "server" } } } ``` -------------------------------- ### Install and Use Hetzner Cloud Python Library Source: https://github.com/fahreddinozcan/hcloud-python-test14/blob/main/_context7_rst_markdown_build/index.md Installs the hcloud library using pip and demonstrates creating a server and listing existing servers using the Hetzner Cloud Python client. Requires an API token. ```sh pip install hcloud ``` ```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=}") ``` -------------------------------- ### Python Development Environment Setup Source: https://github.com/fahreddinozcan/hcloud-python-test14/blob/main/_context7_rst_markdown_build/index.md Sets up a virtual environment for developing the hcloud-python library and installs pre-commit hooks for automated code checks before committing. ```sh make venv source venv/bin/activate pre-commit install ``` -------------------------------- ### Install Pre-commit Hooks for Development Source: https://github.com/fahreddinozcan/hcloud-python-test14/blob/main/README.md Installs `pre-commit` hooks, which automate code formatting and linting checks before each commit. This helps maintain code quality and consistency. ```sh pre-commit install ``` -------------------------------- ### Server Reset Source: https://github.com/fahreddinozcan/hcloud-python-test14/blob/main/_context7_rst_markdown_build/api.clients.servers.md Cuts power to a server and starts it again, effectively resetting it. ```APIDOC ## POST /servers/{id}/actions/reset ### Description Cuts power to a server and starts it again. ### Method POST ### Endpoint `/servers/{id}/actions/reset` ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the server to reset. #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **action** (object) - Details of the reset action. #### Response Example { "action": { "id": 12350, "command": "reset", "status": "running", "started_at": "2023-01-01T12:25:00Z", "finished_at": null, "resources": { "id": 67890, "type": "server" } } } ``` -------------------------------- ### Get All ISOs Source: https://github.com/fahreddinozcan/hcloud-python-test14/blob/main/_context7_rst_markdown_build/api.clients.isos.md Retrieves a list of all ISOs, with options to filter by name and architecture. ```APIDOC ## GET /isos ### Description Retrieves a list of all ISOs. This endpoint allows filtering by name and architecture. ### Method GET ### Endpoint /isos ### Parameters #### Query Parameters - **name** (str) - Optional - Can be used to filter ISOs by their name. - **architecture** (list[str]) - Optional - Can be used to filter ISOs by their architecture. Choices: x86, arm - **include_architecture_wildcard** (bool) - Optional - Set to True if filtering by architecture and also want to include custom ISOs. ### Response #### Success Response (200) - **isos** (list[BoundIso]) - A list of ISO objects. #### Response Example { "isos": [ { "id": 123, "name": "ubuntu-20.04", "type": "public", "architecture": "x86", "description": "Ubuntu 20.04 LTS", "deprecated": null, "deprecation": null } ] } ``` -------------------------------- ### Install Hetzner Cloud Python using conda-forge Source: https://github.com/fahreddinozcan/hcloud-python-test14/blob/main/_context7_rst_markdown_build/installation.md Installs the Hetzner Cloud Python SDK using the conda package manager from the conda-forge channel. Note that this package may not be actively maintained by Hetzner Cloud. ```console conda install -c conda-forge hcloud ``` -------------------------------- ### Create Hetzner Cloud Server (Python) Source: https://context7.com/fahreddinozcan/hcloud-python-test14/llms.txt Shows how to create Hetzner Cloud servers, including basic and advanced configurations. Specify server name, type, image, location, SSH keys, user data, labels, and more. The code also demonstrates how to retrieve server details and the root password, and how to wait for the server creation action 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.ssh_keys import SSHKey client = Client(token="YOUR_API_TOKEN") # Create a basic server response = client.servers.create( name="my-server", server_type=ServerType(name="cx22"), image=Image(name="ubuntu-24.04") ) 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"Server status: {server.status}") print(f"Root password: {root_password}") # Wait for server creation to complete action.wait_until_finished() # 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"), ssh_keys=[SSHKey(name="my-ssh-key")], volumes=[], firewalls=[], user_data="#!/bin/bash\napt-get update\napt-get install -y nginx", labels={"environment": "production", "app": "web"}, automount=False, start_after_create=True ) ``` -------------------------------- ### Build Documentation with Make Source: https://github.com/fahreddinozcan/hcloud-python-test14/blob/main/README.md Builds the project's documentation and opens it in the default web browser. This command is useful for previewing documentation changes locally. ```sh make docs ``` -------------------------------- ### Install Hetzner Cloud Python Library Source: https://github.com/fahreddinozcan/hcloud-python-test14/blob/main/README.md Installs the Hetzner Cloud Python library using pip. This is the primary method for acquiring the library for use in Python projects. ```sh pip install hcloud ``` -------------------------------- ### Create and List Hetzner Cloud Servers with Python Source: https://github.com/fahreddinozcan/hcloud-python-test14/blob/main/README.md Demonstrates how to use the hcloud-python library to create a new server with a specified name, server type, and image, and then lists all existing servers. Requires an API token for authentication. Outputs server ID, name, status, and root password for creation, and ID, name, and status for listed 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=}") ``` -------------------------------- ### Server Creation Source: https://context7.com/fahreddinozcan/hcloud-python-test14/llms.txt Create and configure cloud servers with various options, from basic to advanced settings. ```APIDOC ## Server Creation ### Description Create and configure cloud servers with various options. ### Method ```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="my-server", server_type=ServerType(name="cx22"), image=Image(name="ubuntu-24.04") ) 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"Server status: {server.status}") print(f"Root password: {root_password}") # Wait for server creation to complete action.wait_until_finished() # 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"), ssh_keys=[SSHKey(name="my-ssh-key")], volumes=[], firewalls=[], user_data="#!/bin/bash\napt-get update\napt-get install -y nginx", labels={"environment": "production", "app": "web"}, automount=False, start_after_create=True ) ``` ``` -------------------------------- ### GET /zones Source: https://github.com/fahreddinozcan/hcloud-python-test14/blob/main/_context7_rst_markdown_build/api.clients.zones.md Retrieves a list of all Zones with optional filtering. ```APIDOC ## GET /zones ### Description Returns a list of all Zone. ### Method GET ### Endpoint /zones ### Parameters #### Query Parameters - **name** (str | None) - Optional - Filter resources by their name. The response will only contain the resources matching exactly the specified name. - **mode** (Literal['primary', 'secondary'] | None) - Optional - Filter resources by their mode. The response will only contain the resources matching exactly the specified mode. - **label_selector** (str | None) - Optional - Filter resources by labels. The response will only contain resources matching the label selector. - **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": "zone1", "server_count": 5, "primary_dns_provider": "hetzner_dns", "paid_until": "2024-12-31T23:59:59Z" }, { "id": 456, "name": "zone2", "server_count": 0, "primary_dns_provider": "hetzner_dns", "paid_until": "2024-12-31T23:59:59Z" } ] } ``` **Note:** The DNS API is in beta, and breaking changes may occur within minor releases. ``` -------------------------------- ### POST /servers Source: https://github.com/fahreddinozcan/hcloud-python-test14/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, networking, storage, and security. ```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 #### Path Parameters None #### Query Parameters None #### 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** (ServerType | BoundServerType) - Required - Server type this server should be created with - **image** (Image | BoundImage) - Required - Image the server is created from - **ssh_keys** (list[SSHKey | BoundSSHKey]) - Optional - SSH keys which should be injected into the server at creation time - **volumes** (list[Volume | BoundVolume]) - Optional - Volumes which should be attached to the server at the creation time. Volumes must be in the same location. - **firewalls** (list[Firewall | BoundFirewall]) - Optional - Firewalls which should be attached to the server at the creation time. - **networks** (list[Network | BoundNetwork]) - 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** (Location | BoundLocation) - Optional - Specifies the location for the server. - **datacenter** (Datacenter | BoundDatacenter) - Optional - Specifies the datacenter for the server. - **start_after_create** (bool) - Optional - Start Server right after creation. Defaults to True. - **automount** (bool) - Optional - Auto mount volumes after attach. - **placement_group** (PlacementGroup | BoundPlacementGroup) - Optional - Placement Group where server should be added during creation - **public_net** (ServerCreatePublicNetwork) - 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} } ``` ### Response #### Success Response (200) - **server** (Server) - The created server object. - **action** (Action) - The action object that covers 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" } } ``` ``` -------------------------------- ### Create and Manage Servers and Volumes with Python Source: https://context7.com/fahreddinozcan/hcloud-python-test14/llms.txt This snippet demonstrates creating servers and volumes, attaching volumes to servers, detaching volumes, performing power operations, updating servers, and retrieving actions for a specific server using the Hetzner Cloud Python client. It utilizes object-oriented patterns for resource management. ```python from hcloud import Client from hcloud.images import Image from hcloud.server_types import ServerType client = Client(token="YOUR_API_TOKEN") # Create servers using OOP style response1 = client.servers.create( "Server1", server_type=ServerType(name="cx22"), image=Image(id=4711) ) server1 = response1.server response2 = client.servers.create( "Server2", server_type=ServerType(name="cx22"), image=Image(id=4711) ) server2 = response2.server # Create volumes response1 = client.volumes.create( size=15, name="Volume1", location=server1.datacenter.location ) volume1 = response1.volume response2 = client.volumes.create( size=10, name="Volume2", location=server2.datacenter.location ) volume2 = response2.volume # Attach volumes using bound methods action1 = volume1.attach(server1) action1.wait_until_finished() action2 = volume2.attach(server2) action2.wait_until_finished() # Detach volume action = volume2.detach() action.wait_until_finished() # Power operations on bound objects action = server2.power_off() action.wait_until_finished() # Update server using bound object server1 = server1.update( name="UpdatedServer1", labels={"env": "production"} ) # Get actions for specific server actions = server1.get_actions(status=["running", "success"]) for action in actions: print(f"Action: {action.command}, Status: {action.status}") ``` -------------------------------- ### GET /zones/{zone}/actions Source: https://github.com/fahreddinozcan/hcloud-python-test14/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 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 for the zone. #### Response Example ```json { "actions": [ { "id": 1, "command": "delete_zone", "status": "success", "started_at": "2023-01-01T10:00:00Z", "completed_at": "2023-01-01T10:05:00Z" } ] } ``` **Note:** The DNS API is in beta, and breaking changes may occur within minor releases. ``` -------------------------------- ### Client Initialization Source: https://context7.com/fahreddinozcan/hcloud-python-test14/llms.txt Initialize the Hetzner Cloud API client with your authentication token and optional advanced configurations. ```APIDOC ## Client Initialization ### Description Initialize the Hetzner Cloud API client with authentication token. ### Method ```python from hcloud import Client # Basic client initialization client = Client(token="YOUR_API_TOKEN") # Advanced client with custom configuration client = Client( token="YOUR_API_TOKEN", api_endpoint="https://api.hetzner.cloud/v1", application_name="my-app", application_version="1.0.0", poll_interval=2.0, # seconds between action polls poll_max_retries=120, timeout=(5.0, 30.0) # (connect timeout, read timeout) ) # Client automatically handles retries for: # - Network timeouts # - HTTP 502 (Bad Gateway) and 504 (Gateway Timeout) # - API errors: 'rate_limit_exceeded' and 'conflict' ``` ``` -------------------------------- ### GET /zones/{id_or_name} Source: https://github.com/fahreddinozcan/hcloud-python-test14/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. ### Response #### Success Response (200) - **zone** (BoundZone) - The retrieved Zone object. #### Response Example ```json { "zone": { "id": 123, "name": "zone1", "server_count": 5, "primary_dns_provider": "hetzner_dns", "paid_until": "2024-12-31T23:59:59Z" } } ``` **Note:** The DNS API is in beta, and breaking changes may occur within minor releases. ``` -------------------------------- ### Get Action by ID Source: https://github.com/fahreddinozcan/hcloud-python-test14/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 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 { "action": { "id": 12345, "command": "create_server", "status": "running", "progress": 50, "started": "2023-10-27T10:00:00Z", "finished": null, "resources": [ { "id": 67890, "type": "server" } ], "error": null } } ``` -------------------------------- ### Setup Python Virtual Environment for Development Source: https://github.com/fahreddinozcan/hcloud-python-test14/blob/main/README.md Sets up and activates a Python virtual environment using `make venv`. This isolates project dependencies and ensures a consistent development environment. ```sh make venv source venv/bin/activate ``` -------------------------------- ### Get Location by ID Source: https://github.com/fahreddinozcan/hcloud-python-test14/blob/main/_context7_rst_markdown_build/api.clients.locations.md Retrieves a specific location by its unique identifier. ```APIDOC ## GET /locations/{id} ### Description Retrieves a specific location by its unique identifier. ### Method GET ### Endpoint /locations/{id} ### Parameters #### Path Parameters - **id** (int) - Required - The unique ID of the location to retrieve. ### Response #### Success Response (200) - **location** (BoundLocation) - The BoundLocation object corresponding to the provided ID. #### Response Example ```json { "location": { "id": 1, "name": "fsn1", "description": "Falkenstein 1", "country": "DE", "city": "Falkenstein", "latitude": 50.4756, "longitude": 12.3456, "network_zone": "zone-a" } } ``` ``` -------------------------------- ### Create and Manage Block Storage Volumes Source: https://context7.com/fahreddinozcan/hcloud-python-test14/llms.txt Demonstrates the creation, retrieval, attachment, resizing, detaching, updating, and deletion of block storage volumes. It also shows how to enable delete protection for a volume. ```python from hcloud import Client from hcloud.volumes import Volume from hcloud.locations import Location client = Client(token="YOUR_API_TOKEN") # Create a volume response = client.volumes.create( size=50, # Size in GB name="my-volume", location=Location(name="nbg1"), labels={"type": "database"}, automount=True, format="ext4" ) volume = response.volume action = response.action action.wait_until_finished() # Get volume by name volume = client.volumes.get_by_name("my-volume") # List all volumes volumes = client.volumes.get_all() # Attach volume to server server = client.servers.get_by_name("my-server") action = volume.attach(server=server, automount=True) action.wait_until_finished() # Resize volume (only increase size) action = volume.resize(size=100) action.wait_until_finished() # Detach volume action = volume.detach() action.wait_until_finished() # Update volume metadata volume = volume.update( name="database-volume", labels={"type": "database", "env": "production"} ) # Enable delete protection action = volume.change_protection(delete=True) action.wait_until_finished() # Delete volume volume.delete() ``` -------------------------------- ### Create and Manage Private Networks Source: https://context7.com/fahreddinozcan/hcloud-python-test14/llms.txt Provides examples for creating and managing private networks, including adding subnets and routes, attaching and detaching servers to networks, and deleting subnets and networks. ```python from hcloud import Client from hcloud.networks import Network, NetworkSubnet, NetworkRoute client = Client(token="YOUR_API_TOKEN") # Create a network response = client.networks.create( name="my-network", ip_range="10.0.0.0/16", labels={"env": "production"} ) network = response.network # Add subnet to network subnet = NetworkSubnet( type="cloud", ip_range="10.0.1.0/24", network_zone="eu-central" ) action = network.add_subnet(subnet) action.wait_until_finished() # Add route to network route = NetworkRoute( destination="10.100.0.0/16", gateway="10.0.1.1" ) action = network.add_route(route) action.wait_until_finished() # Attach server to network server = client.servers.get_by_name("my-server") action = client.servers.attach_to_network( server=server, network=network, ip="10.0.1.5", alias_ips=["10.0.1.6", "10.0.1.7"] ) action.wait_until_finished() # Detach server from network action = client.servers.detach_from_network(server=server, network=network) action.wait_until_finished() # Delete subnet action = network.delete_subnet(subnet) action.wait_until_finished() # Delete network network.delete() ``` -------------------------------- ### GET /zones Source: https://github.com/fahreddinozcan/hcloud-python-test14/blob/main/_context7_rst_markdown_build/api.clients.zones.md Retrieves a list of Zones for a specific page with optional filtering. ```APIDOC ## GET /zones ### Description Returns a list of Zone for a specific page. ### Method GET ### Endpoint /zones ### Parameters #### Query Parameters - **name** (str | None) - Optional - Filter resources by their name. The response will only contain the resources matching exactly the specified name. - **mode** (Literal['primary', 'secondary'] | None) - Optional - Filter resources by their mode. The response will only contain the resources matching exactly the specified mode. - **label_selector** (str | None) - Optional - Filter resources by labels. The response will only contain resources matching the label selector. - **sort** (list[str] | None) - Optional - Sort resources by field and direction. - **page** (int | None) - Optional - Page number to return. - **per_page** (int | None) - Optional - Maximum number of entries returned per page. ### Response #### Success Response (200) - **zones_page_result** (ZonesPageResult) - An object containing a list of zones and pagination information. #### Response Example ```json { "zones": [ { "id": 123, "name": "zone1", "server_count": 5, "primary_dns_provider": "hetzner_dns", "paid_until": "2024-12-31T23:59:59Z" } ], "pagination": { "next_page": null, "previous_page": null, "last_page": 1, "first_page": 1, "per_page": 25, "total_entries": 1 } } ``` **Note:** The DNS API is in beta, and breaking changes may occur within minor releases. ``` -------------------------------- ### Get Network Actions Source: https://github.com/fahreddinozcan/hcloud-python-test14/blob/main/_context7_rst_markdown_build/api.clients.networks.md Retrieves all action objects associated with a specific network. ```APIDOC ## GET /networks/{id}/actions ### Description Returns all action objects for a network. ### Method GET ### Endpoint /networks/{id}/actions ### Parameters #### Path Parameters - **id** (int) - Required - The ID of the network whose actions to retrieve. #### Query Parameters - **status** (list[str]) - Optional - Filters actions by their status. Possible values: 'running', 'success', 'error'. - **sort** (list[str]) - Optional - Specifies the order of sorting. 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'. ### Request Example ```http GET /v1/networks/12345/actions?status=running&sort=started:desc ``` ### Response #### Success Response (200) - **actions** (list[object]) - A list of action objects associated with the network. See [BoundAction Object](#hcloud.actions.client.BoundAction) for details. #### Response Example ```json { "actions": [ { "id": 9882, "command": "update_network", "status": "success", "progress": 100, "started": "2023-01-01T10:30:00Z", "finished": "2023-01-01T10:31:00Z", "resources": [ { "id": 12345, "type": "network" } ] } ] } ``` ``` -------------------------------- ### Create and Manage Floating IPs Source: https://context7.com/fahreddinozcan/hcloud-python-test14/llms.txt Demonstrates the management of Floating IPs, including creation, retrieval by ID, assignment to servers, unassigning, setting reverse DNS PTR records, updating metadata, and deletion. ```python from hcloud import Client from hcloud.floating_ips import FloatingIP from hcloud.locations import Location client = Client(token="YOUR_API_TOKEN") # Create a floating IP response = client.floating_ips.create( type="ipv4", description="Web server IP", home_location=Location(name="nbg1"), labels={"service": "web"} ) floating_ip = response.floating_ip action = response.action print(f"Floating IP: {floating_ip.ip}") print(f"IP type: {floating_ip.type}") # Get floating IP by ID floating_ip = client.floating_ips.get_by_id(12345) # Assign floating IP to server server = client.servers.get_by_name("my-server") action = floating_ip.assign(server=server) action.wait_until_finished() # Unassign floating IP action = floating_ip.unassign() action.wait_until_finished() # Set reverse DNS PTR record action = floating_ip.change_dns_ptr( ip=floating_ip.ip, dns_ptr="web.example.com" ) action.wait_until_finished() # Update floating IP metadata floating_ip = floating_ip.update( description="Updated description", name="web-ip", labels={"service": "web", "env": "prod"} ) # Delete floating IP floating_ip.delete() ``` -------------------------------- ### Enable Backup Source: https://github.com/fahreddinozcan/hcloud-python-test14/blob/main/_context7_rst_markdown_build/api.clients.servers.md Enables and configures the automatic daily backup option for the server. This action increases the server price by 20%. ```APIDOC ## POST /servers/{id}/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/{id}/enable_backup` ### Parameters #### Path Parameters - **id** (int) - Required - The ID of the server to enable backups for. #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **action** (object) - Contains details about the enable backup action. - **id** (int) - The ID of the action. - **command** (str) - The command executed. - **started_at** (str) - The date and time the action was started. - **completed_at** (str) - The date and time the action was completed. - **status** (str) - The status of the action (`running`, `successful`, `error`). - **resources** (array) - Resources affected by the action. - **error** (object) - Error details if the action failed. #### Response Example ```json { "action": { "id": 98769, "command": "enable_backup", "started_at": "2023-10-27T12:00:00Z", "completed_at": null, "status": "running", "resources": [ { "type": "server", "id": 67890 } ], "error": null } } ``` ``` -------------------------------- ### Get Network by ID API Source: https://github.com/fahreddinozcan/hcloud-python-test14/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 unique identifier of the network. ### Request Example ```python # This is a conceptual representation as the SDK uses method calls # client.networks.get_by_id(id=12345) ``` ### Response #### Success Response (200 OK) - **network** (BoundNetwork) - The requested BoundNetwork object. ```