clean solution
This commit is contained in:
parent
9060e0faf2
commit
362dbc3379
7
.env_template
Normal file
7
.env_template
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
hetzner_api_token=
|
||||||
|
hetzner_ssh_public_key=
|
||||||
|
|
||||||
|
aws_access_key_id=
|
||||||
|
aws_secret_access_key=
|
||||||
|
aws_session_token=
|
||||||
|
AWS_REGION =
|
19
README.md
19
README.md
@ -1,5 +1,16 @@
|
|||||||
## 3.1, 3.2:
|
# Uruchamianie rozwiazań
|
||||||
należy uruchomić skrypt run.sh, uruchomienie pliku del_gitea.py usuwa stworzone serwery
|
|
||||||
|
|
||||||
## 3.4
|
## Przed uruchomieniem
|
||||||
rozwiązanie w pliki cloud-init.yml
|
należy uzupełnić wartości w pliku .env według szablonu z pliku .env_template
|
||||||
|
|
||||||
|
Uruchomienie pliku clear_hetzer.py usuwa wszystkie stworzone serwery i load balancer z moim prefixem
|
||||||
|
|
||||||
|
### Zadania 3.1, 3.2, katalog lab3/3.2:
|
||||||
|
należy uruchomić skrypt lab3/3.2/deploy.sh
|
||||||
|
gitea dostępna na porcie 3000
|
||||||
|
|
||||||
|
### 3.4
|
||||||
|
rozwiązanie w pliki lab3/3.4/cloud-init.yml
|
||||||
|
|
||||||
|
### 4.1 Hetzner
|
||||||
|
rozwiązanie w katalogu lab4/4.1-hetzner, należy uruchomić deploy.sh
|
||||||
|
@ -1,8 +1,17 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
from hcloud import Client
|
from hcloud import Client
|
||||||
|
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv(dotenv_path=".env")
|
||||||
|
|
||||||
|
api_token = os.getenv("hetzner_api_token")
|
||||||
|
|
||||||
client = Client(
|
client = Client(
|
||||||
token="KccUEiddxtzGoLWSNC3V8tylq7MYHCjdnShtgasQ8jSbHqCjGoaa6Rq7yoz4uS23"
|
token=api_token
|
||||||
)
|
)
|
||||||
|
|
||||||
PREFIX = "s444417"
|
PREFIX = "s444417"
|
||||||
|
|
||||||
servers = client.servers.get_all()
|
servers = client.servers.get_all()
|
||||||
@ -12,3 +21,9 @@ for s in servers:
|
|||||||
action = client.servers.delete(s)
|
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}")
|
||||||
|
|
||||||
|
servers = client.load_balancers.get_all()
|
||||||
|
print(f"Usuwanie {len(servers)} load balancer")
|
||||||
|
for s in servers:
|
||||||
|
if s.data_model.name.startswith(PREFIX):
|
||||||
|
action = client.load_balancers.delete(s)
|
||||||
|
|
5
lab3/3.2/deploy.sh
Normal file
5
lab3/3.2/deploy.sh
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
pip install hcloud
|
||||||
|
|
||||||
|
python clear_hetnzer.py
|
||||||
|
python lab3/3.2/gitea_auto.py
|
@ -1,22 +1,21 @@
|
|||||||
from hcloud import Client
|
import os
|
||||||
|
|
||||||
|
from hcloud import Client
|
||||||
from hcloud.images.domain import Image
|
from hcloud.images.domain import Image
|
||||||
from hcloud.server_types.domain import ServerType
|
from hcloud.server_types.domain import ServerType
|
||||||
|
|
||||||
from hcloud.networks.domain import NetworkSubnet
|
from hcloud.networks.domain import NetworkSubnet
|
||||||
|
|
||||||
from hcloud.locations.domain import Location
|
from hcloud.locations.domain import Location
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
api_token = ""
|
load_dotenv(dotenv_path=".env")
|
||||||
|
|
||||||
with open("token.txt", "r") as file:
|
api_token = os.getenv("hetzner_api_token")
|
||||||
api_token = file.read().strip()
|
|
||||||
|
|
||||||
client = Client(token=api_token)
|
client = Client(token=api_token)
|
||||||
|
|
||||||
PREFIX = "s444417"
|
PREFIX = "s444417"
|
||||||
|
|
||||||
YOUR_LOCAL_SSH_PUBKEY = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQChkJi01w/rrQ7HICEJYDN/4ldPxorU4umbc8Sw1MRIU2Mz/rds/pd2f+B/PYTjvvtOdZml4SyC4Y8kFoBo4AmRUTxn2yk3g/d1eiDtRzhY1c22+mua6V1dee72EhWAWHaAAa9caChMWV3oP2TljgUEF/Hd7ctMkMxo0Hlh6EVHec1HR6lMIWspYRWjIKPLzknW7WePNgAB5MBDz6+WzokwnULbglUnJ5uy+WrFgWl9tfN7MoNyG1aZkLiWuXvF1HUddAS+gmhs2MEEWeGi3kNewBKQfviAxdCgEKirPra+4ffgLUej7exDzcacxU8AjcK5DLlk3LJr34YTpeV+LMN6M3FB/XVu4vAv9IAyHCOJRer8Vb7gM+ehukgr6HCPrFyCgO3GBh9TvQaBeUajtqjJQ2YHw7D2SFWEfZ6XSx2YSW0NQpfturEHlFLLzN7ohpzSzupe/8yHXlhASSntducXrsXNm1Sz2PdqjDSkoMRZjCzNIxhUS67SZDncOxqsmjE= s444417@MIK"
|
YOUR_LOCAL_SSH_PUBKEY = os.getenv("hetzner_ssh_public_key")
|
||||||
|
|
||||||
vnet_name = f"{PREFIX}-pzc-test-vnet"
|
vnet_name = f"{PREFIX}-pzc-test-vnet"
|
||||||
vnet = client.networks.get_by_name(vnet_name) or None
|
vnet = client.networks.get_by_name(vnet_name) or None
|
@ -1,26 +1,23 @@
|
|||||||
from hcloud import Client
|
import os
|
||||||
|
|
||||||
|
from hcloud import Client
|
||||||
from hcloud.images.domain import Image
|
from hcloud.images.domain import Image
|
||||||
from hcloud.server_types.domain import ServerType
|
from hcloud.server_types.domain import ServerType
|
||||||
|
|
||||||
from hcloud.networks.domain import NetworkSubnet
|
from hcloud.networks.domain import NetworkSubnet
|
||||||
|
|
||||||
from hcloud.locations.domain import Location
|
from hcloud.locations.domain import Location
|
||||||
|
|
||||||
from hcloud.load_balancer_types.domain import LoadBalancerType
|
from hcloud.load_balancer_types.domain import LoadBalancerType
|
||||||
|
|
||||||
from hcloud.load_balancers.domain import LoadBalancerHealthCheck, LoadBalancerService, LoadBalancerHealtCheckHttp, LoadBalancerTarget
|
from hcloud.load_balancers.domain import LoadBalancerHealthCheck, LoadBalancerService, LoadBalancerHealtCheckHttp, LoadBalancerTarget
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
api_token = ""
|
load_dotenv(dotenv_path=".env")
|
||||||
|
|
||||||
with open("token.txt", "r") as file:
|
api_token = os.getenv("hetzner_api_token")
|
||||||
api_token = file.read().strip()
|
|
||||||
|
|
||||||
client = Client(token=api_token)
|
client = Client(token=api_token)
|
||||||
|
|
||||||
PREFIX = "s444417"
|
PREFIX = "s444417"
|
||||||
|
|
||||||
YOUR_LOCAL_SSH_PUBKEY = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQChkJi01w/rrQ7HICEJYDN/4ldPxorU4umbc8Sw1MRIU2Mz/rds/pd2f+B/PYTjvvtOdZml4SyC4Y8kFoBo4AmRUTxn2yk3g/d1eiDtRzhY1c22+mua6V1dee72EhWAWHaAAa9caChMWV3oP2TljgUEF/Hd7ctMkMxo0Hlh6EVHec1HR6lMIWspYRWjIKPLzknW7WePNgAB5MBDz6+WzokwnULbglUnJ5uy+WrFgWl9tfN7MoNyG1aZkLiWuXvF1HUddAS+gmhs2MEEWeGi3kNewBKQfviAxdCgEKirPra+4ffgLUej7exDzcacxU8AjcK5DLlk3LJr34YTpeV+LMN6M3FB/XVu4vAv9IAyHCOJRer8Vb7gM+ehukgr6HCPrFyCgO3GBh9TvQaBeUajtqjJQ2YHw7D2SFWEfZ6XSx2YSW0NQpfturEHlFLLzN7ohpzSzupe/8yHXlhASSntducXrsXNm1Sz2PdqjDSkoMRZjCzNIxhUS67SZDncOxqsmjE= s444417@MIK"
|
YOUR_LOCAL_SSH_PUBKEY = os.getenv("hetzner_ssh_public_key")
|
||||||
|
|
||||||
vnet_name = f"{PREFIX}-pzc-test-vnet"
|
vnet_name = f"{PREFIX}-pzc-test-vnet"
|
||||||
vnet = client.networks.get_by_name(vnet_name) or None
|
vnet = client.networks.get_by_name(vnet_name) or None
|
||||||
@ -44,9 +41,10 @@ print(f"Klucz {ssh_key.data_model.name} został dodany: {ssh_key.data_model.publ
|
|||||||
|
|
||||||
cloud_init_wp1=r'''#cloud-config
|
cloud_init_wp1=r'''#cloud-config
|
||||||
runcmd:
|
runcmd:
|
||||||
|
- cd /home
|
||||||
- git clone https://git.wmi.amu.edu.pl/s444417/dpzc
|
- git clone https://git.wmi.amu.edu.pl/s444417/dpzc
|
||||||
- chmod +x /dpzc/lab4/4.1-hetzner/webservice
|
- chmod +x /home/dpzc/lab4/4.1-hetzner/webservice
|
||||||
- systemctl start /dpzc/lab4/4.1-hetzner/webservice
|
- /home/dpzc/lab4/4.1-hetzner/webservice
|
||||||
'''
|
'''
|
||||||
|
|
||||||
servers = []
|
servers = []
|
||||||
@ -69,7 +67,7 @@ for i in range(2):
|
|||||||
servers.append(server)
|
servers.append(server)
|
||||||
|
|
||||||
|
|
||||||
name = f"{PREFIX}-load-balancer-${i}"
|
name = f"{PREFIX}-load-balancer"
|
||||||
|
|
||||||
targets = []
|
targets = []
|
||||||
for s in servers:
|
for s in servers:
|
||||||
|
Loading…
Reference in New Issue
Block a user