74 lines
1.9 KiB
Markdown
74 lines
1.9 KiB
Markdown
# Hetzner Cloud API - Rhai Wrapper
|
|
|
|
This project provides a Rhai wrapper for interacting with the Hetzner Cloud API, allowing you to manage your servers through simple scripts.
|
|
|
|
## Setup
|
|
|
|
To use this wrapper, you need to set your Hetzner API Token as an environment variable.
|
|
|
|
```bash
|
|
export HETZNER_API_TOKEN="YOUR_API_TOKEN_HERE"
|
|
```
|
|
|
|
Replace `"YOUR_API_TOKEN_HERE"` with your actual Hetzner API token.
|
|
|
|
## Usage
|
|
|
|
You can execute any `.rhai` script by passing it as an argument to `cargo run`.
|
|
|
|
```bash
|
|
cargo run -- <script_name>.rhai
|
|
```
|
|
|
|
For example, to run the provided `test.rhai` script:
|
|
|
|
```bash
|
|
cargo run -- test.rhai
|
|
```
|
|
|
|
## API Examples
|
|
|
|
Here are some examples of what you can do with the API, taken from the `test.rhai` script.
|
|
|
|
### 1. Create a Client
|
|
|
|
All API interactions start by creating a client instance.
|
|
|
|
```rust
|
|
// Create client to communicate with Hetzner API
|
|
let client = new_hetzner_client(HETZNER_API_TOKEN);
|
|
```
|
|
|
|
### 2. List Servers & Display Details
|
|
|
|
You can fetch all your servers and display their details in a formatted table.
|
|
|
|
```rust
|
|
// List all servers and print in table
|
|
print("Listing all servers...");
|
|
let servers = client.list_servers();
|
|
print(servers.show_table());
|
|
|
|
// Get a specific server by ID and show its details
|
|
let test_server = client.get_server(104301883);
|
|
print(test_server.show_details());
|
|
```
|
|
|
|
### 3. Manage Server State
|
|
|
|
Perform actions like enabling rescue mode, disabling it, or rebooting the server.
|
|
|
|
```rust
|
|
// Enable rescue mode and get the root password
|
|
print(`Enabling rescue mode on server with ID: ${test_server.id}`);
|
|
let root_password = client.enable_rescue_mode(test_server.id);
|
|
print(`Root password is: ${root_password}`);
|
|
|
|
// Disable rescue mode
|
|
print(`Disabling rescue mode on server with ID: ${test_server.id}`);
|
|
client.disable_rescue_mode(test_server.id);
|
|
|
|
// Reboot server
|
|
print(`Rebooting server with ID: ${test_server.id}`);
|
|
client.reboot(test_server.id);
|