volumins (that dont work)
This commit is contained in:
parent
db9277f366
commit
e2549f61c5
53
main.py
53
main.py
@ -1,4 +1,4 @@
|
||||
from hcloud import Client
|
||||
from hcloud import Client, APIException
|
||||
from hcloud.images.domain import Image
|
||||
from hcloud.networks.domain import NetworkSubnet
|
||||
from hcloud.locations.domain import Location
|
||||
@ -13,7 +13,7 @@ with open(f'{str(Path.home())}/.ssh/id_ed25519.pub', 'r') as file:
|
||||
|
||||
ssh_name = "ssh-s444501"
|
||||
network_name = "s444501-gitea"
|
||||
|
||||
volume_name = "s444501-gitea"
|
||||
|
||||
try:
|
||||
client.ssh_keys.delete(client.ssh_keys.get_by_name(ssh_name))
|
||||
@ -36,6 +36,25 @@ vnet = client.networks.create(
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
try:
|
||||
v = client.volumes.get_by_name(volume_name)
|
||||
try:
|
||||
action = client.volumes.detach(v)
|
||||
action.wait_until_finished()
|
||||
except APIException:
|
||||
pass
|
||||
client.volumes.delete(v)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
volume = client.volumes.create(
|
||||
name=volume_name,
|
||||
size=10,
|
||||
format='ext4',
|
||||
location=Location("hel1")
|
||||
)
|
||||
|
||||
cloud_init_db = r'''#cloud-config
|
||||
packages:
|
||||
- apt-transport-https
|
||||
@ -147,6 +166,8 @@ gitea_server = client.servers.create(
|
||||
image=Image(name="ubuntu-22.04"),
|
||||
ssh_keys=[ssh_key],
|
||||
networks=[vnet],
|
||||
volumes=[volume.volume],
|
||||
automount=True,
|
||||
location=Location("hel1"),
|
||||
user_data=cloud_init_gitea
|
||||
)
|
||||
@ -154,14 +175,24 @@ gitea_server = client.servers.create(
|
||||
gitea_server.action.wait_until_finished()
|
||||
print(f"Tworzenie serwera gitea: {gitea_server.action.complete}")
|
||||
|
||||
# automount dirty fix
|
||||
# v = client.volumes.get_by_name(volume_name)
|
||||
# client.volumes.attach(v, gitea_server.server, automount=True)
|
||||
# HC_Volume_id
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
servers = client.servers.get_all()
|
||||
print(f"Usuwanie {len(servers)} serwerów")
|
||||
for s in servers:
|
||||
action = client.servers.delete(s)
|
||||
print(f"Usuwanie serwera {s.data_model.name} ({s.data_model.public_net.ipv4.ip}): {action.data_model.status}")
|
||||
# print(f"Usuwanie volumenu")
|
||||
# v = client.volumes.get_by_name(volume_name)
|
||||
# try:
|
||||
# action = client.volumes.detach(v)
|
||||
# action.wait_until_finished()
|
||||
# except APIException:
|
||||
# pass
|
||||
#
|
||||
# client.volumes.delete(v)
|
||||
#
|
||||
# servers = client.servers.get_all()
|
||||
# print(f"Usuwanie {len(servers)} serwerów")
|
||||
# for s in servers:
|
||||
# action = client.servers.delete(s)
|
||||
# print(f"Usuwanie serwera {s.data_model.name} ({s.data_model.public_net.ipv4.ip}): {action.data_model.status}")
|
||||
|
Loading…
Reference in New Issue
Block a user