Finish create_servers.py
This commit is contained in:
parent
b2ee7e3590
commit
8b0322cd22
@ -3,6 +3,8 @@ from hcloud.images.domain import Image
|
|||||||
from hcloud.server_types.domain import ServerType
|
from hcloud.server_types.domain import ServerType
|
||||||
from hcloud.locations.domain import Location
|
from hcloud.locations.domain import Location
|
||||||
|
|
||||||
|
servers_no = 2
|
||||||
|
|
||||||
TOKEN = "V5gkzZ13coCVPKWkQbmbyGPyxDdsTjiubwVtx35jH7mix8A32JqM5CWJtqoLjtFK"
|
TOKEN = "V5gkzZ13coCVPKWkQbmbyGPyxDdsTjiubwVtx35jH7mix8A32JqM5CWJtqoLjtFK"
|
||||||
|
|
||||||
client = Client(
|
client = Client(
|
||||||
@ -13,12 +15,17 @@ PREFIX = "PD"
|
|||||||
YOUR_LOCAL_SSH_PUBKEY = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCrv0JDOSvGT+UUZBVW/pJyP4LO2Myof+ZQtYkko1fPVEK0w+QnQmnWCCsbtHuYM1SnlhGxCHG0iMhAHpWO5vIF119Ia5aV2q/weQy67isO3puHgtEFGXBabp+qIJUHh9pfR+2mVYl5cze1SrqfFj/B4axoPDjRo10mnQfwXxIrqPpA98XOkea0SUky1S9nSSt6V+OSaInvy0xSigoAp1L8CJRTyclAbub0EiS8S8rEi0/5Wa77TgRmiVfyXE5ZG4VmcOgpvt0FHMCMkTC6VaC4vPBmamMho5zceRYn1/yPyHofFv6NSfHqDfCBO64e6K0XlP7lMegfh5mtzzaz2PPP"
|
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)
|
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
|
cloud_init=r'''#cloud-config
|
||||||
|
packages:
|
||||||
|
- fail2ban
|
||||||
|
- ufw
|
||||||
|
- git
|
||||||
|
- python3
|
||||||
|
- python3-pip
|
||||||
|
package_update: true
|
||||||
|
package_upgrade: true
|
||||||
runcmd:
|
runcmd:
|
||||||
- sudo apt update
|
|
||||||
- sudo apt install -y git python3 python3-pip
|
|
||||||
- git clone https://git.wmi.amu.edu.pl/s495719/cloud_3_3
|
- git clone https://git.wmi.amu.edu.pl/s495719/cloud_3_3
|
||||||
- cd cloud_3_3
|
- cd cloud_3_3
|
||||||
- chmod +x computeC
|
- chmod +x computeC
|
||||||
@ -26,17 +33,28 @@ runcmd:
|
|||||||
- python3 main.py
|
- python3 main.py
|
||||||
'''
|
'''
|
||||||
|
|
||||||
db_server = client.servers.create(
|
servers = []
|
||||||
name=f"{PREFIX}-db",
|
for i in range(servers_no):
|
||||||
server_type=ServerType("cpx11"),
|
server = client.servers.create(
|
||||||
image=Image(name="ubuntu-22.04"),
|
name=f"{PREFIX}-{i}-3",
|
||||||
ssh_keys=[ssh_key],
|
server_type=ServerType("cpx11"),
|
||||||
location=Location("hel1"),
|
image=Image(name="ubuntu-22.04"),
|
||||||
user_data=cloud_init,
|
location=Location("hel1"),
|
||||||
)
|
user_data=cloud_init,
|
||||||
|
)
|
||||||
|
servers.append(server)
|
||||||
|
|
||||||
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")
|
for i in range(servers_no):
|
||||||
print(f"Serwer: {db_server.data_model.name}\n\tpubliczne IP: {db_server.data_model.public_net.ipv4.ip}")
|
servers[i].action.wait_until_finished()
|
||||||
|
|
||||||
|
ip_list = []
|
||||||
|
for i in range(servers_no):
|
||||||
|
server = client.servers.get_by_name(f"{PREFIX}-{i}-3")
|
||||||
|
ip_list.append(server.data_model.public_net.ipv4.ip)
|
||||||
|
|
||||||
|
with open('my_list.txt', 'w') as file:
|
||||||
|
for item in ip_list:
|
||||||
|
file.write(item + '\n')
|
||||||
|
|
||||||
|
print("Finished")
|
Loading…
Reference in New Issue
Block a user