from hcloud import Client from hcloud.images.domain import Image from hcloud.server_types.domain import ServerType from hcloud.locations.domain import Location TOKEN = "V5gkzZ13coCVPKWkQbmbyGPyxDdsTjiubwVtx35jH7mix8A32JqM5CWJtqoLjtFK" client = Client( token=TOKEN ) PREFIX = "PD" 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=r'''#cloud-config runcmd: - 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( name=f"{PREFIX}-db", server_type=ServerType("cpx11"), image=Image(name="ubuntu-22.04"), ssh_keys=[ssh_key], location=Location("hel1"), user_data=cloud_init, ) db_server.action.wait_until_finished() print(f"Tworzenie serwera db: {db_server.action.complete}") db_server = client.servers.get_by_name(f"{PREFIX}-db") print(f"Serwer: {db_server.data_model.name}\n\tpubliczne IP: {db_server.data_model.public_net.ipv4.ip}")