init
This commit is contained in:
commit
04eaceed1f
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.credentials/
|
11
README.md
Normal file
11
README.md
Normal file
@ -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
|
||||
,,,,,,,,
|
51
main.py
Normal file
51
main.py
Normal file
@ -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/")
|
BIN
webservice
Normal file
BIN
webservice
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user