hetzner_robot_rhai/examples/server_management.rhai
2025-07-24 13:01:05 +02:00

101 lines
3.6 KiB
Plaintext

// --- Input Variables ---
// These variables should be updated by the user before running the script.
// Server number for operations like getting, updating, canceling, or withdrawing cancellation.
// Example: 1234567
let SERVER_NUMBER = 0; // Replace with an actual server number
// New name for updating a server's name.
// Example: "my-new-server-name"
let NEW_SERVER_NAME = "your-new-server-name";
// Desired cancellation date for a server.
// Format: "YYYY-MM-DD"
// Example: "2025-12-31"
let CANCELLATION_DATE = "YYYY-MM-DD";
// --- Server Management Operations ---
// 1. Get all servers
// This section retrieves all servers associated with your Hetzner account
// and prints them in a human-readable table format.
print("Fetching all servers...");
try {
let all_servers = hetzner.get_servers();
all_servers.pretty_print();
print("All servers fetched and displayed.");
} catch (err) {
print("Error fetching all servers: " + err);
}
// 2. Get a specific server by number
// This section demonstrates how to retrieve details for a single server
// using its server number.
// Uncomment the following lines and set SERVER_NUMBER to an actual server number to use.
/*
print("\nAttempting to fetch specific server with number: " + SERVER_NUMBER);
try {
let specific_server = hetzner.get_server(SERVER_NUMBER);
print("Specific server details:");
print(specific_server);
} catch (err) {
print("Error fetching specific server: " + err);
}
*/
// 3. Update a server's name
// This section updates the name of an existing server.
// Uncomment the following lines and set SERVER_NUMBER and NEW_SERVER_NAME to actual values to use.
/*
print("\nAttempting to update server name for server number: " + SERVER_NUMBER + " to new name: " + NEW_SERVER_NAME);
try {
let updated_server = hetzner.update_server_name(SERVER_NUMBER, NEW_SERVER_NAME);
print("Server name updated successfully:");
print(updated_server);
} catch (err) {
print("Error updating server name: " + err);
}
*/
// 4. Query cancellation data for a server
// This section retrieves the cancellation data for a specific server.
// Uncomment the following lines and set SERVER_NUMBER to an actual server number to use.
/*
print("\nAttempting to query cancellation data for server number: " + SERVER_NUMBER);
try {
let cancellation_data = hetzner.get_cancellation_data(SERVER_NUMBER);
print("Cancellation data:");
print(cancellation_data);
} catch (err) {
print("Error querying cancellation data: " + err);
}
*/
// 5. Cancel a server
// This section cancels a server with a specified cancellation date.
// Use with caution! This action will initiate the cancellation process for the server.
// Uncomment the following lines and set SERVER_NUMBER and CANCELLATION_DATE to actual values to use.
/*
print("\nAttempting to cancel server number: " + SERVER_NUMBER + " with cancellation date: " + CANCELLATION_DATE);
try {
let cancelled_server = hetzner.cancel_server(SERVER_NUMBER, CANCELLATION_DATE);
print("Server cancellation initiated successfully:");
print(cancelled_server);
} catch (err) {
print("Error canceling server: " + err);
}
*/
// 6. Withdraw a server cancellation
// This section withdraws a previously initiated server cancellation.
// Uncomment the following lines and set SERVER_NUMBER to an actual server number to use.
/*
print("\nAttempting to withdraw cancellation for server number: " + SERVER_NUMBER);
try {
hetzner.withdraw_cancellation(SERVER_NUMBER);
print("Server cancellation withdrawn successfully.");
} catch (err) {
print("Error withdrawing server cancellation: " + err);
}
*/