71 lines
1.6 KiB
Python
71 lines
1.6 KiB
Python
from hcloud import Client
|
|
from hcloud.networks.domain import NetworkSubnet
|
|
from hcloud.locations.domain import Location
|
|
from hcloud.images.domain import Image
|
|
from hcloud.server_types.domain import ServerType
|
|
|
|
|
|
INDEKS = "s444455"
|
|
|
|
hetzner_token = ""
|
|
ssh_name = f"{INDEKS}-key"
|
|
code_name = f"{INDEKS}-code"
|
|
vnet_name = f"{INDEKS}-pzc-vnet"
|
|
|
|
|
|
with open("token.txt", "r") as file:
|
|
hetzner_token = file.read().strip()
|
|
|
|
client = Client(token=hetzner_token)
|
|
|
|
|
|
vnet = client.networks.get_by_name(vnet_name) or None
|
|
if not vnet:
|
|
vnet = client.networks.create(
|
|
name=vnet_name,
|
|
ip_range="10.10.10.0/24",
|
|
subnets=[
|
|
NetworkSubnet(ip_range="10.10.10.0/24", network_zone="eu-central", type="cloud")
|
|
]
|
|
)
|
|
print("Vnet: done")
|
|
|
|
|
|
ssh_key = client.ssh_keys.get_by_name(ssh_name)
|
|
print("Key: done")
|
|
|
|
cloud_init_db=r'''
|
|
#cloud-config
|
|
write_files:
|
|
- content: |
|
|
curl -fsSL https://code-server.dev/install.sh > /root/install.sh
|
|
path: /root/install.sh
|
|
owner: root:root
|
|
- content: |
|
|
bind-addr: 0.0.0.0:8080
|
|
auth: password
|
|
password: vscpassword
|
|
cert: false
|
|
path: /root/config.yml
|
|
owner: root:root
|
|
|
|
runcmd:
|
|
- cd /root/
|
|
- chmod u+x install.sh
|
|
- ./install.sh
|
|
- code-server --config config.yml
|
|
'''
|
|
|
|
db_server = client.servers.create(
|
|
name=code_name,
|
|
server_type=ServerType("cx11"),
|
|
image=Image(name="ubuntu-20.04"),
|
|
ssh_keys=[ssh_key],
|
|
networks=[vnet],
|
|
location=Location("hel1"),
|
|
user_data=cloud_init_db
|
|
)
|
|
|
|
db_server.action.wait_until_finished()
|
|
db_server = client.servers.get_by_name(code_name)
|
|
print("Serwer code: done") |