Final fixes

This commit is contained in:
Maciej Sobkowiak 2021-11-28 22:04:50 +01:00
parent b25f79dd4d
commit 6e5a0fbe7b

View File

@ -6,6 +6,7 @@ from hcloud.networks.domain import NetworkSubnet
from hcloud.locations.domain import Location from hcloud.locations.domain import Location
from hcloud.images.domain import Image from hcloud.images.domain import Image
from hcloud.server_types.domain import ServerType from hcloud.server_types.domain import ServerType
from hcloud.volumes.domain import Volume
class Client_MS: class Client_MS:
@ -64,8 +65,7 @@ class Client_MS:
volume = self.client.volumes.create( volume = self.client.volumes.create(
size=10, name=self.config["volume"], location=Location(id=self.config["location"])) size=10, name=self.config["volume"], location=Location(id=self.config["location"]))
volume.action.wait_until_finished() volume.action.wait_until_finished()
time.sleep(5) return volume.volume
return volume
def create_db_server(self): def create_db_server(self):
with open("db.yml", "r") as f: with open("db.yml", "r") as f:
@ -86,7 +86,7 @@ class Client_MS:
networks=[self.network], networks=[self.network],
location=Location(self.config["location"]), location=Location(self.config["location"]),
user_data=db_yml) user_data=db_yml)
return self.server_db return self.server_db.server
def create_gitea_server(self): def create_gitea_server(self):
with open("gitea.yml", "r") as f: with open("gitea.yml", "r") as f:
@ -109,7 +109,16 @@ class Client_MS:
user_data=gitea_yml, user_data=gitea_yml,
volumes=[self.volume] volumes=[self.volume]
) )
return self.server_gitea return self.server_gitea.server
def print_info(self):
print("----- Server info -----")
print(
f"\t{self.server_db.data_model.name}\n\t\tIP: {self.server_db.data_model.public_net.ipv4.ip}")
print(
f"\t{self.server_gitea.data_model.name}\n\t\tIP: {self.server_gitea.data_model.public_net.ipv4.ip}")
print(
f"\nTo access gitea go to: {self.server_gitea.data_model.public_net.ipv4.ip}:3000\n")
def delete_all(self): def delete_all(self):
self.network.delete() self.network.delete()
@ -129,5 +138,16 @@ if __name__ == '__main__':
print("Podaj ścieżkę do pliku konfiguracyjnego.") print("Podaj ścieżkę do pliku konfiguracyjnego.")
else: else:
c = Client_MS(sys.argv[1]) c = Client_MS(sys.argv[1])
# time.sleep(10) c.print_info()
# c.delete_all() try:
for remaining in range(60, 0, -1):
sys.stdout.write("\r")
sys.stdout.write(
"Deleting servers starts in: {:2d}. Press Ctrl + C to stop.".format(remaining))
sys.stdout.flush()
time.sleep(1)
print("")
except KeyboardInterrupt:
sys.exit()
c.delete_all()