refactored token and ssh key loading

This commit is contained in:
test 2022-12-05 12:20:40 +01:00
parent de1891f9b1
commit db9277f366
2 changed files with 14 additions and 8 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.credentials/

21
main.py
View File

@ -3,10 +3,15 @@ from hcloud.images.domain import Image
from hcloud.networks.domain import NetworkSubnet
from hcloud.locations.domain import Location
from hcloud.server_types.domain import ServerType
from pathlib import Path
client = Client(token="")
ssh_raw = ""
ssh_name = ssh_raw.split()[2]
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()
ssh_name = "ssh-s444501"
network_name = "s444501-gitea"
@ -155,8 +160,8 @@ print(f"Tworzenie serwera gitea: {gitea_server.action.complete}")
# servers = client.servers.get_all()
# print(f"Usuwanie {len(servers)} serwerów")
# for s in servers:
# action = client.servers.delete(s)
# print(f"Usuwanie serwera {s.data_model.name} ({s.data_model.public_net.ipv4.ip}): {action.data_model.status}")
servers = client.servers.get_all()
print(f"Usuwanie {len(servers)} serwerów")
for s in servers:
action = client.servers.delete(s)
print(f"Usuwanie serwera {s.data_model.name} ({s.data_model.public_net.ipv4.ip}): {action.data_model.status}")