replaced json by yaml, improved traefik lxc and git detection/update
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
d6123581bc
commit
d0cdb6d55f
@ -1 +1,2 @@
|
|||||||
fabric~=3.1.0
|
fabric~=3.1.0
|
||||||
|
PyYAML~=6.0
|
@ -89,13 +89,13 @@ def check_conditions(c_type: str, parent: dict, lxc: LXC, result: list = None):
|
|||||||
if not result:
|
if not result:
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
if c_type == "files":
|
if c_type == "files" or c_type == "file":
|
||||||
for file in parent[c_type]:
|
for file in parent[c_type]:
|
||||||
result.append(lxc.has_file(Path(file)))
|
result.append(lxc.has_file(Path(file)))
|
||||||
elif c_type == "folders":
|
elif c_type == "folders" or c_type == "folder":
|
||||||
for folder in parent[c_type]:
|
for folder in parent[c_type]:
|
||||||
result.append(lxc.has_directory(Path(folder)))
|
result.append(lxc.has_directory(Path(folder)))
|
||||||
elif c_type == "programs":
|
elif c_type == "programs" or c_type == "program":
|
||||||
for program in parent[c_type]:
|
for program in parent[c_type]:
|
||||||
result.append(lxc.has_program(program))
|
result.append(lxc.has_program(program))
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import json
|
import yaml
|
||||||
|
|
||||||
from .lxc import LXC
|
from .lxc import LXC
|
||||||
from ..utils import utils
|
from ..utils import utils
|
||||||
@ -33,7 +33,8 @@ def load_lxc(lxc_id: int, content: str or bytes, pve: ProxmoxHost):
|
|||||||
content = content.decode("utf-8")
|
content = content.decode("utf-8")
|
||||||
|
|
||||||
# Load JSON data
|
# Load JSON data
|
||||||
data = json.loads(content)
|
# data = json.loads(content)
|
||||||
|
data = yaml.safe_load(content)
|
||||||
|
|
||||||
# Extract values from JSON
|
# Extract values from JSON
|
||||||
lxc_id = lxc_id
|
lxc_id = lxc_id
|
||||||
|
11
src/main.py
11
src/main.py
@ -20,10 +20,11 @@ def run(args):
|
|||||||
# Check if the repo is already cloned
|
# Check if the repo is already cloned
|
||||||
if not pve.has_directory(pve.repo_path):
|
if not pve.has_directory(pve.repo_path):
|
||||||
logging.info(f"Cloning repository {args.repo} to {args.path}...")
|
logging.info(f"Cloning repository {args.repo} to {args.path}...")
|
||||||
git_utils.clone_repo(url=args.repo, path=args.path, linux_machine=pve)
|
git_utils.clone_repo(url=args.repo, path=pve.repo_path, linux_machine=pve)
|
||||||
elif pve.has_directory(Path(args.path).joinpath(".git")):
|
|
||||||
logging.info(f"Repository already cloned at {args.path}, updating...")
|
if pve.has_directory(Path(pve.repo_path).joinpath(".git")):
|
||||||
git_utils.update_repo(path=args.path, linux_machine=pve)
|
logging.info(f"Repository already cloned at {pve.repo_path}, updating...")
|
||||||
|
git_utils.update_repo(path=pve.repo_path, linux_machine=pve)
|
||||||
|
|
||||||
if not pve.has_directory(pve.repo_path):
|
if not pve.has_directory(pve.repo_path):
|
||||||
raise FileNotFoundError(f"Repo not found at {pve.repo_path}")
|
raise FileNotFoundError(f"Repo not found at {pve.repo_path}")
|
||||||
@ -38,7 +39,7 @@ def run(args):
|
|||||||
# Read all files in the LXC directory
|
# Read all files in the LXC directory
|
||||||
lxc_folders = pve.list_dir(Path(args.path).joinpath(resource))
|
lxc_folders = pve.list_dir(Path(args.path).joinpath(resource))
|
||||||
for lxc_folder in lxc_folders:
|
for lxc_folder in lxc_folders:
|
||||||
lxc_file_content = pve.read_file(Path(args.path).joinpath(resource, lxc_folder, "config.json"))
|
lxc_file_content = pve.read_file(Path(args.path).joinpath(resource, lxc_folder, "config.yml"))
|
||||||
|
|
||||||
load_lxc(content=lxc_file_content, lxc_id=int(lxc_folder), pve=pve)
|
load_lxc(content=lxc_file_content, lxc_id=int(lxc_folder), pve=pve)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user