Add volume

This commit is contained in:
adi 2023-01-07 17:13:20 +01:00
parent abae99ebd5
commit d5a7592258
2 changed files with 31 additions and 4 deletions

View File

@ -12,4 +12,13 @@ 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"Usuwanie serwera {s.data_model.name} ({s.data_model.public_net.ipv4.ip}): {action.data_model.status}")
print(f"Usuwanie serwera {s.data_model.name} ({s.data_model.public_net.ipv4.ip}): {action.data_model.status}")
volumes = client.volumes.get_all()
print(f"Usuwanie {len(volumes)} wolumenów")
for v in volumes:
if s.data_model.name.startswith(PREFIX):
action = client.volumes.detach(v)
action.wait_until_finished()
action = client.volumes.delete(v)
print(f"\tUsuwanie wolumenu {v.name}: {action}")

View File

@ -33,6 +33,12 @@ if not vnet:
)
print(f"Utworzono sieć wirtualną {vnet.data_model.name} ({vnet.data_model.ip_range})")
volume_name = f"{PREFIX}-volume"
volume = client.volumes.create(
name=volume_name, size=10, format="ext4", location=Location("hel1")
)
print("successfully CREATED")
cloud_init_db=r'''
#cloud-config
# lista podstawowych pakietów, które należy zainstalować
@ -140,7 +146,17 @@ runcmd:
- chmod +x /usr/local/bin/docker-compose
- systemctl start docker
- systemctl enable docker
- cd /root/ && docker-compose up -d
- cd /root/
- IP=$(hostname -I | cut -d ' ' -f 1)
- echo "DOMAIN=$IP" >> .env
- sudo mkfs.ext4 -F /dev/disk/by-id/scsi-0HC_Volume_{volume.volume.id}
- mkdir /mnt/{volume_name}
- mount -o discard,defaults /dev/disk/by-id/scsi-0HC_Volume_{volume.volume.id} /mnt/{volume_name}
- echo "/dev/disk/by-id/scsi-0HC_Volume_{volume.volume.id} /mnt/{volume_name} ext4 discard,nofail,defaults 0 0" >> /etc/fstab
- mkdir /mnt/{volume_name}/data
- mkdir /mnt/{volume_name}/config
- sudo chown 1000:1000 /mnt/{volume_name}/config/ /mnt/{volume_name}/data
- docker-compose up -d
'''
gitea_server = client.servers.create(
@ -148,7 +164,9 @@ gitea_server = client.servers.create(
server_type=ServerType("cx11"),
image=Image(name="ubuntu-20.04"),
ssh_keys=[ssh_key],
networks=[vnet],
networks=[vnet],
volumes=[volume.volume],
automount=True,
location=Location("hel1"),
user_data=cloud_init_gitea
)
@ -157,4 +175,4 @@ gitea_server.action.wait_until_finished()
print(f"Tworzenie serwera gitea: {gitea_server.action.complete}")
gitea_server = client.servers.get_by_name(f"{PREFIX}-gitea")
print(f"Serwer: {gitea_server.data_model.name}\n\tpubliczne IP: {gitea_server.data_model.public_net.ipv4.ip}\n\tprywatne IP: {gitea_server.data_model.private_net[0].ip}")
print(f"Serwer: {gitea_server.data_model.name}\n\tpubliczne IP: {gitea_server.data_model.public_net.ipv4.ip}")