commit 04eaceed1f1a349bc1b31092864c6b847a722bdc Author: s444501 Date: Thu Jan 12 17:04:10 2023 +0100 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7564f41 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.credentials/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..577b710 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +## Przed uruchomieniem +W głównym katalogu repozytorium utwórz katalog ``.credentials/`` + +Umieść w nim plik ``token`` zawierający token do Hetznera. + +Upewnij się, że w katalogu domowym ``~/.ssh/`` posiadasz klucz ``id_ed25519.pub`` + +Upewnij się, że zainstalowany jest ``Python3.9`` lub nowszy oraz ``pip`` + +## Uruchamianie +,,,,,,,, \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..db16161 --- /dev/null +++ b/main.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +from pathlib import Path + +from hcloud import Client +from hcloud.images.domain import Image +from hcloud.locations.domain import Location +from hcloud.networks.domain import NetworkSubnet +from hcloud.server_types.domain import ServerType + +with open('.credentials/token', 'r') as file: + client = Client(token=str(file.readline()).strip()) + +with open(f'{str(Path.home())}/.ssh/id_ed25519.pub', 'r') as file: + ssh_raw = file.readline() + +index = 's444501' +ssh_name = index + '-ssh' +network_name = index + '-network' +server_base_name = index + '-server' +SERVER_COUNT = 5 + +ssh_key = client.ssh_keys.create(name=ssh_name, public_key=ssh_raw) + +vnet = client.networks.create( + name=network_name, + ip_range="10.10.10.0/24", + subnets=[ + NetworkSubnet(ip_range="10.10.10.0/24", network_zone="eu-central", type="cloud") + ] +) + +cloud_init = r'''#cloud-config +runcmd: + - +''' +servers = [] +for i in range(SERVER_COUNT): + server = client.servers.create( + name=server_base_name + '-' + str(i+1), + server_type=ServerType("cx11"), + image=Image(name="ubuntu-22.04"), + ssh_keys=[ssh_key], + networks=[vnet], + location=Location("hel1"), + user_data=cloud_init + ) + server.action.wait_until_finished() + print(f"Tworzenie serwera: {server.action.complete}") + servers.append(server) + +print(f"Webserwis pod adresem http://{server.server.data_model.public_net.ipv4.ip}:8080/factors/") diff --git a/webservice b/webservice new file mode 100644 index 0000000..afd2204 Binary files /dev/null and b/webservice differ