You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Debugging a Hetzner Cloud Server Snapshot Script
3
+
lang: en
4
+
layout: post
5
+
audio: false
6
+
translated: false
7
+
generated: true
8
+
---
9
+
10
+
# Debugging and Enhancing a Hetzner Cloud Server Snapshot Script
11
+
12
+
This article documents the process of troubleshooting and improving a Python script for managing Hetzner Cloud server snapshots and cloning servers.
13
+
14
+
## The Initial Problem
15
+
16
+
The script was encountering an error where a 'Server' object had no attribute 'create_snapshot'. The issue was in the `scripts/auto-ss-config/hetzner.py` file, which needed to be fixed to properly create snapshots.
17
+
18
+
## Step 1: Identifying the Bug
19
+
20
+
After examining the code, I identified that the error occurred because the script was trying to call `create_snapshot()` directly on a server object, but this method doesn't exist in the hcloud Python library's Server class.
However, this led to a new error: `'ServersClient' object has no attribute 'create_snapshot'`
37
+
38
+
## Step 3: Investigating the Correct API
39
+
40
+
To understand the correct API method, I examined the hcloud Python library. This revealed that I needed to use `client.servers.create_image()` rather than trying to use a non-existent method.
- Creating a server from an existing snapshot: `python scripts/auto-ss-config/hetzner.py --create-server --snapshot-id ID [--server-name NAME]`
63
+
- Doing both in one command: `python scripts/auto-ss-config/hetzner.py --create-snapshot --create-server [--server-name NAME]`
64
+
65
+
The script successfully creates snapshots and then uses them to create new server instances with the same specifications (server type, datacenter location) as the original server.
66
+
67
+
## Key Learnings
68
+
69
+
1. When working with cloud provider APIs, it's important to use the correct method calls as specified in their documentation
70
+
2. Resources like snapshots often have states (e.g., "creating", "available") that need to be properly handled
0 commit comments