diff --git a/3_2_delete.py b/3_2_delete.py new file mode 100644 index 0000000..bf9d7d5 --- /dev/null +++ b/3_2_delete.py @@ -0,0 +1,29 @@ +from hcloud import Client + +client = Client( + token="V5gkzZ13coCVPKWkQbmbyGPyxDdsTjiubwVtx35jH7mix8A32JqM5CWJtqoLjtFK" +) +PREFIX = "PD" + +YOUR_LOCAL_SSH_PUBKEY = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCzIOEX3AABgr3ZKLFcvZYkKr10JJjD0+AXlXoJ5CfpNw56SVj17Gh/Qbag4QeB8eJYaJxHV+TPhIOtHNxDJFlcVXUKPCBDErlIFYIJ8t0uhqvssd9r6XCZxvDjTC20FNayG+Zr1adB3BYe501I3JB9KiGZxg9juh/lY/1jZyqjjPzt8vLE1M2j6C7rbLAlIOub37B8OC7SGsy/nz4Ub5kS3Jxh9Trmr6vtuXa5WnASIaqX+3jl9hBhsg55j5WKUrGM1BOEKmwYxFJEH7bY0NjmcNAeaw1mm5bxERSW6EFXX3hEk+kx5zuFbO1LXDBh3HP5FyjwOXDKY70aLfVVpdGj" + +servers = client.servers.get_all() +print(f"Usuwanie {len(servers)} serwerów") +for s in servers: + if s.data_model.name.startswith(PREFIX): + action = client.servers.delete(s) + print(f"\tUsuwanie serwera {s.data_model.name}: {action.data_model.status}") + +ssh_keys = client.ssh_keys.get_all() +print(f"Usuwanie {len(ssh_keys)} kluczy SSH") +for s in ssh_keys: + if s.data_model.name.startswith(PREFIX): + action = client.ssh_keys.delete(s) + print(f"\tUsuwanie klucza {s.name}: {action}") + +vnets = client.networks.get_all() +print(f"Usuwanie {len(vnets)} sieci wirtualnych") +for s in vnets: + if s.data_model.name.startswith(PREFIX): + action = client.networks.delete(s) + print(f"\tUsuwanie sieci wirtualnej {s.name}: {action}") diff --git a/create_servers.py b/create_servers.py index 4a5c49d..203c354 100644 --- a/create_servers.py +++ b/create_servers.py @@ -10,22 +10,20 @@ client = Client( ) PREFIX = "PD" -YOUR_LOCAL_SSH_PUBKEY = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCzIOEX3AABgr3ZKLFcvZYkKr10JJjD0+AXlXoJ5CfpNw56SVj17Gh/Qbag4QeB8eJYaJxHV+TPhIOtHNxDJFlcVXUKPCBDErlIFYIJ8t0uhqvssd9r6XCZxvDjTC20FNayG+Zr1adB3BYe501I3JB9KiGZxg9juh/lY/1jZyqjjPzt8vLE1M2j6C7rbLAlIOub37B8OC7SGsy/nz4Ub5kS3Jxh9Trmr6vtuXa5WnASIaqX+3jl9hBhsg55j5WKUrGM1BOEKmwYxFJEH7bY0NjmcNAeaw1mm5bxERSW6EFXX3hEk+kx5zuFbO1LXDBh3HP5FyjwOXDKY70aLfVVpdGj" +YOUR_LOCAL_SSH_PUBKEY = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCrv0JDOSvGT+UUZBVW/pJyP4LO2Myof+ZQtYkko1fPVEK0w+QnQmnWCCsbtHuYM1SnlhGxCHG0iMhAHpWO5vIF119Ia5aV2q/weQy67isO3puHgtEFGXBabp+qIJUHh9pfR+2mVYl5cze1SrqfFj/B4axoPDjRo10mnQfwXxIrqPpA98XOkea0SUky1S9nSSt6V+OSaInvy0xSigoAp1L8CJRTyclAbub0EiS8S8rEi0/5Wa77TgRmiVfyXE5ZG4VmcOgpvt0FHMCMkTC6VaC4vPBmamMho5zceRYn1/yPyHofFv6NSfHqDfCBO64e6K0XlP7lMegfh5mtzzaz2PPP" ssh_key = client.ssh_keys.create(name=f"{PREFIX}-pzc-ssh-key", public_key=YOUR_LOCAL_SSH_PUBKEY) print(f"Klucz {ssh_key.data_model.name} został dodany: {ssh_key.data_model.public_key}") -cloud_init_db=r'''#cloud-config +cloud_init=r'''#cloud-config runcmd: - - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - - - add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" - - apt-get update -y - - apt-get install -y docker-ce docker-ce-cli containerd.io - - curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose - - chmod +x /usr/local/bin/docker-compose - - systemctl start docker - - systemctl enable docker - - cd /root/ && docker-compose up -d + - sudo apt update + - sudo apt install -y git python3 python3-pip + - git clone https://git.wmi.amu.edu.pl/s495719/cloud_3_3 + - cd cloud_3_3 + - chmod +x computeC + - pip install -r requirements.txt + - python3 main.py ''' db_server = client.servers.create( @@ -34,7 +32,7 @@ db_server = client.servers.create( image=Image(name="ubuntu-22.04"), ssh_keys=[ssh_key], location=Location("hel1"), - user_data=cloud_init_db, + user_data=cloud_init, ) db_server.action.wait_until_finished() diff --git a/main.py b/main.py index ea93f80..d4f65f7 100644 --- a/main.py +++ b/main.py @@ -26,4 +26,4 @@ async def compute(data: ComputeInput): return result.stdout.strip() if __name__ == "__main__": - uvicorn.run(app, host="0.0.0.0", port=5000) + uvicorn.run(app, host="0.0.0.0", port=8000)