From 7c5adf85171a9538a2a3087ac945fdd848ee9cd2 Mon Sep 17 00:00:00 2001 From: MatOgr Date: Sat, 31 Dec 2022 13:16:46 +0100 Subject: [PATCH] code-server ssh-key path parameter --- .gitignore | 3 ++- code-server/README.md | 19 +++++++++++++++++++ code-server/create_code_server.py | 16 +++++++++------- code-server/deploy.sh | 11 ++++++----- 4 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 code-server/README.md diff --git a/.gitignore b/.gitignore index 62f1212..35f493a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ */token_file -*/*venv \ No newline at end of file +*/*venv +*/current_ip.txt diff --git a/code-server/README.md b/code-server/README.md new file mode 100644 index 0000000..b1a10c7 --- /dev/null +++ b/code-server/README.md @@ -0,0 +1,19 @@ +# Just some README +W celu utworzenia zasobów z wykorzystaniem skryptów zawartych w tym folderze należy: +- posiadać zainstalowanego `Pythona` oraz menedżera `pip` +- umieścić token dostępu do zasobów Hetznera w pliku `DPZC-Hetzner/tokens/token_file`, obok skryptu `.py` oraz `.sh` +- umieścić klucz `id_ed25519.pub` w folderze `~/.ssh/` +- zmienić prawa dostępu na wykonywalne dla skryptów bashowych poprzez poniższe komendy: + ```bash + chmod +x clean.sh deploy.sh + ``` +- w celu utworzenia zasobów wykonać skrypt + ```bash + ./deploy.sh + ``` +- w celu usunięcia utworzonych zasobów wykonać skrypt + ```bash + ./clean.sh + ``` +----------------- +To chyba wszystko diff --git a/code-server/create_code_server.py b/code-server/create_code_server.py index 41cfd1d..55e0022 100755 --- a/code-server/create_code_server.py +++ b/code-server/create_code_server.py @@ -60,18 +60,17 @@ def create_client(creds_path): return client -def load_key(key_folder, pub_key_name): - home_path = Path.home().joinpath(key_folder, pub_key_name) - print(f"\t\tUsing the {home_path} file") - with open(home_path) as f: +def load_key(pub_key_path): + print(f"\t\tUsing the {pub_key_path} file") + with open(pub_key_path) as f: key = f.readline() print("\t\tThe SSH KEY has been LOADED") return key -def create_key(client, key_name, key_folder, pub_key_name): +def create_key(client, key_name, pub_key_path): print("The SSH KEY has been...") - key_of_power = load_key(key_folder, pub_key_name) + key_of_power = load_key(pub_key_path) key = client.ssh_keys.create(name=key_name, public_key=key_of_power) print("\tCREATED") return key @@ -167,10 +166,11 @@ def remove_code_server(client, server_name): if __name__ == "__main__": client = create_client("../tokens/token_file") + ssh_path = sys.argv[-2] action = sys.argv[-1] if action == "--create": - ssh_key = create_key(client, key_name, ".ssh", "id_ed25519.pub") + ssh_key = create_key(client, key_name, ssh_path) vnet = create_network(client, net_name, "10.10.10.0/24") volume = create_volume(client, volume_name, location) @@ -182,6 +182,8 @@ if __name__ == "__main__": f"You can access the server (in a few minutes) under the address: http://localhost:8888" ) print("\n\n\t\tHave fun!") + with open("current_ip.txt", "w") as f: + f.write(server.server.data_model.public_net.ipv4.ip) elif action == "--clean": remove_code_server(client, server_name) remove_network(client, net_name) diff --git a/code-server/deploy.sh b/code-server/deploy.sh index f1947c1..59426ee 100755 --- a/code-server/deploy.sh +++ b/code-server/deploy.sh @@ -10,7 +10,9 @@ echo "-------------------------------------------------------------------------- echo " Success! I guess..." echo "############################" echo "Let's spawn some new machines!" -python create_code_server.py --create +python create_code_server.py $1 --create +current_ip=$(