diff --git a/requirements.txt b/requirements.txt index c69bbfc..1237ea2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -fabric~=3.1.0 \ No newline at end of file +fabric~=3.1.0 +PyYAML~=6.0 \ No newline at end of file diff --git a/src/lxc/creation_utils.py b/src/lxc/creation_utils.py index ec6aaa1..7e2af18 100644 --- a/src/lxc/creation_utils.py +++ b/src/lxc/creation_utils.py @@ -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)) diff --git a/src/lxc/lxc_utils.py b/src/lxc/lxc_utils.py index 16343eb..f45b8b0 100644 --- a/src/lxc/lxc_utils.py +++ b/src/lxc/lxc_utils.py @@ -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 diff --git a/src/main.py b/src/main.py index cd2ada6..1d62a28 100644 --- a/src/main.py +++ b/src/main.py @@ -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)