From 6e5a0fbe7b6a19273bdf9235005d14f5f813312b Mon Sep 17 00:00:00 2001 From: Maciej Sobkowiak Date: Sun, 28 Nov 2021 22:04:50 +0100 Subject: [PATCH] Final fixes --- deploy.py | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/deploy.py b/deploy.py index 7addb8f..16740d7 100644 --- a/deploy.py +++ b/deploy.py @@ -6,6 +6,7 @@ from hcloud.networks.domain import NetworkSubnet from hcloud.locations.domain import Location from hcloud.images.domain import Image from hcloud.server_types.domain import ServerType +from hcloud.volumes.domain import Volume class Client_MS: @@ -64,8 +65,7 @@ class Client_MS: volume = self.client.volumes.create( size=10, name=self.config["volume"], location=Location(id=self.config["location"])) volume.action.wait_until_finished() - time.sleep(5) - return volume + return volume.volume def create_db_server(self): with open("db.yml", "r") as f: @@ -86,7 +86,7 @@ class Client_MS: networks=[self.network], location=Location(self.config["location"]), user_data=db_yml) - return self.server_db + return self.server_db.server def create_gitea_server(self): with open("gitea.yml", "r") as f: @@ -109,7 +109,16 @@ class Client_MS: user_data=gitea_yml, 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): self.network.delete() @@ -129,5 +138,16 @@ if __name__ == '__main__': print("Podaj ścieżkę do pliku konfiguracyjnego.") else: c = Client_MS(sys.argv[1]) - # time.sleep(10) - # c.delete_all() + c.print_info() + 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()