diff --git a/salt/sys-cacher/files/admin/list_extra_tag.py b/salt/sys-cacher/files/admin/list_extra_tag.py deleted file mode 100755 index f49f23a..0000000 --- a/salt/sys-cacher/files/admin/list_extra_tag.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python3 - -# SPDX-FileCopyrightText: 2024 Benjamin Grande M. S. -# -# SPDX-License-Identifier: AGPL-3.0-or-later - -"""list-extra-tag - List qubes tagged for cacher incorrectly""" - -import qubesadmin # pylint: disable=import-error -import qubesadmin.vm # pylint: disable=import-error - -def main(): # pylint: disable=missing-function-docstring - wanted_domains = ['debian', 'fedora', 'arch', 'ubuntu', 'kicksecure'] - domains = [ - vm.name - for vm in qubesadmin.Qubes().domains - if "updatevm-sys-cacher" in vm.tags - and vm.features.check_with_template("os-distribution-like") - not in wanted_domains - and vm.features.check_with_template("os-distribution") - not in wanted_domains - ] - print("\n".join(domains)) - - -if __name__ == "__main__": - main() diff --git a/salt/sys-cacher/files/admin/tag.py b/salt/sys-cacher/files/admin/tag.py index 086f5b1..22fb59f 100755 --- a/salt/sys-cacher/files/admin/tag.py +++ b/salt/sys-cacher/files/admin/tag.py @@ -6,19 +6,53 @@ """list-extra-tag - List qubes that can be tagged for cacher""" +import argparse import qubesadmin # pylint: disable=import-error import qubesadmin.vm # pylint: disable=import-error +def get_cacher_tagged_qubes(qubes, wanted_dist, extraneous=False): + """Get qubes tagged for ACNG""" + domains = [] + for qube in qubes.domains: # pylint: disable=invalid-name + if qube.klass == "TemplateVM" and "whonix-updatevm" not in qube.tags: + os_dist = qube.features.get("os-distribution") + os_dist_like = qube.features.get("os-distribution-like") + if os_dist_like is not None: + os_dist_like_list = os_dist_like.split() + + if extraneous and "updatevm-sys-cacher" in qube.tags: + if (os_dist not in wanted_dist \ + and os_dist_like is None) \ + or (os_dist_like is not None and + not any(domain in os_dist_like_list + for domain in wanted_dist + ) + ): + domains.append(qube.name) + else: + if os_dist in wanted_dist: + domains.append(qube.name) + elif os_dist_like is not None: + os_dist_like_list = os_dist_like.split() + if any( + domain in os_dist_like_list + for domain in wanted_dist + ): + domains.append(qube.name) + + return domains + + def main(): # pylint: disable=missing-function-docstring - wanted_domains = ['debian', 'fedora', 'arch', 'ubuntu', 'kicksecure'] - domains = [ - vm.name - for vm in qubesadmin.Qubes().domains - if vm.klass == "TemplateVM" - and "whonix-updatevm" not in vm.tags - and (vm.features.get("os-distribution-like") in wanted_domains - or vm.features.get("os-distribution") in wanted_domains) - ] + parser = argparse.ArgumentParser(description="List cacher tagged qubes") + parser.add_argument("--extraneous", action="store_true", + help="List only extraneously tagged qubes") + args = parser.parse_args() + + wanted_dist = ["debian", "fedora", "arch", "ubuntu", "kicksecure"] + qubes = qubesadmin.Qubes() + domains = get_cacher_tagged_qubes(qubes, wanted_dist, + extraneous=args.extraneous) print("\n".join(domains)) diff --git a/salt/sys-cacher/list-extra-tag.sls b/salt/sys-cacher/list-extra-tag.sls index f4190e7..83fa8ac 100644 --- a/salt/sys-cacher/list-extra-tag.sls +++ b/salt/sys-cacher/list-extra-tag.sls @@ -4,7 +4,7 @@ SPDX-FileCopyrightText: 2023 - 2024 Benjamin Grande M. S.