This commit is contained in:
Maciej Sobkowiak 2022-01-04 22:22:32 +01:00
parent bf5c2e4731
commit 73c8d2443b
7 changed files with 11 additions and 34 deletions

View File

@ -1,11 +0,0 @@
#cloud-config
write_files:
- content: |
curl -fsSL https://code-server.dev/install.sh > /root/install.sh
permissions: "755"
owner: root:root
path: /root/install.sh
runcmd:
- bash /root/install.sh
- code-server --bind-addr 0.0.0.0:8080

View File

@ -1,7 +1,6 @@
import json
import time
import sys
import paramiko
import requests
from hcloud import Client
from hcloud.networks.domain import NetworkSubnet
@ -39,18 +38,18 @@ class Client_MS:
return self.client.ssh_keys.create(name=self.config["ssh_name"], public_key=self.config["ssh_public"])
def create_vscode_server(self):
with open("vscode.yml", "r") as f:
with open("webservice.yml", "r") as f:
vs = f.read()
if(self.client.servers.get_by_name(self.config["vs-code-name"])):
if(self.client.servers.get_by_name(self.config["server-name"])):
print("Server exists.")
self.vscode = self.client.servers.get_by_name(
self.config["vs-code-name"])
self.config["server-name"])
return self.vscode
else:
print("Creating server.")
vscode = self.client.servers.create(
name=self.config["vs-code-name"],
name=self.config["server-name"],
server_type=ServerType(self.config["server-type"]),
image=Image(name=self.config["server-image"]),
ssh_keys=[self.ssh_key],
@ -60,23 +59,6 @@ class Client_MS:
self.vscode = vscode.server
return vscode.server
def get_password(self):
while(True):
try:
print("Status: Setting up...", end='\r')
requests.get(f'http://{self.vscode.data_model.public_net.ipv4.ip}:8080')
break
except:
time.sleep(1)
print("Status: Running. ", end='\n')
ssh = paramiko.SSHClient()
k = paramiko.RSAKey.from_private_key_file(self.config["ssh_private"])
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect( hostname=self.vscode.data_model.public_net.ipv4.ip, username="root", pkey=k, timeout=1000)
stdin, stdout, stderr = ssh.exec_command('cat < ~/.config/code-server/config.yaml')
print(f'VS Code password: {stdout.readlines()[2].split()[1]}\n')
def print_info(self):
print("----- Server info -----")
print(
@ -95,7 +77,7 @@ if __name__ == '__main__':
else:
c = Client_MS(sys.argv[1])
c.print_info()
c.get_password()
# c.get_password()
try:
for remaining in range(60, 0, -1):
sys.stdout.write("\r")

Binary file not shown.

View File

@ -0,0 +1,6 @@
#cloud-config
runcmd:
- cd /home
- git clone https://git.wmi.amu.edu.pl/s434784/04_Public_cloud
- chmod -x /04_Public_cloud/webservice
- bash /home/04_Public_cloud/webservice