replaced json by yaml, improved traefik lxc and git detection/update
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Mathieu Broillet 2023-06-21 17:10:15 +02:00
parent d6123581bc
commit d0cdb6d55f
No known key found for this signature in database
GPG Key ID: 7D4F25BC50A0AA32
4 changed files with 14 additions and 11 deletions

View File

@ -1 +1,2 @@
fabric~=3.1.0
PyYAML~=6.0

View File

@ -89,13 +89,13 @@ def check_conditions(c_type: str, parent: dict, lxc: LXC, result: list = None):
if not result:
result = []
if c_type == "files":
if c_type == "files" or c_type == "file":
for file in parent[c_type]:
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]:
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]:
result.append(lxc.has_program(program))

View File

@ -1,4 +1,4 @@
import json
import yaml
from .lxc import LXC
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")
# Load JSON data
data = json.loads(content)
# data = json.loads(content)
data = yaml.safe_load(content)
# Extract values from JSON
lxc_id = lxc_id

View File

@ -20,10 +20,11 @@ def run(args):
# Check if the repo is already cloned
if not pve.has_directory(pve.repo_path):
logging.info(f"Cloning repository {args.repo} to {args.path}...")
git_utils.clone_repo(url=args.repo, path=args.path, linux_machine=pve)
elif pve.has_directory(Path(args.path).joinpath(".git")):
logging.info(f"Repository already cloned at {args.path}, updating...")
git_utils.update_repo(path=args.path, linux_machine=pve)
git_utils.clone_repo(url=args.repo, path=pve.repo_path, linux_machine=pve)
if pve.has_directory(Path(pve.repo_path).joinpath(".git")):
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):
raise FileNotFoundError(f"Repo not found at {pve.repo_path}")
@ -38,7 +39,7 @@ def run(args):
# Read all files in the LXC directory
lxc_folders = pve.list_dir(Path(args.path).joinpath(resource))
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)