37 lines
1.2 KiB
Plaintext
37 lines
1.2 KiB
Plaintext
let client = new_hetzner_client(HETZNER_API_TOKEN);
|
|
|
|
try {
|
|
print("Listing servers...");
|
|
let servers = client.list_servers();
|
|
|
|
if servers.len() == 0 {
|
|
print("No servers found.");
|
|
} else {
|
|
for server in servers {
|
|
print(`Server: ${server.name} (${server.id}), Status: ${server.status}`);
|
|
}
|
|
|
|
let first_server = servers[0];
|
|
print(`Getting details for server: ${first_server.name}`);
|
|
let detailed_server = client.get_server(first_server.id);
|
|
print(detailed_server.show_details());
|
|
print(`Pinging server ${detailed_server.name}...`);
|
|
let is_online = detailed_server.ping();
|
|
if is_online {
|
|
print("Server is online.");
|
|
} else {
|
|
print("Server is offline.");
|
|
}
|
|
|
|
// To reboot the server, uncomment the following lines:
|
|
// print("\nAttempting to reboot the server...");
|
|
// try {
|
|
// first_server.reboot(client);
|
|
// print("Reboot command sent successfully.");
|
|
// } catch(e) {
|
|
// print(`Error during reboot: ${e}`);
|
|
// }
|
|
}
|
|
} catch (e) {
|
|
print(`An error occurred: ${e}`);
|
|
} |