feat: unify cacher tag list to a single script

This commit is contained in:
Ben Grande 2024-07-06 22:30:36 +02:00
parent 35fa43dadf
commit 8604887c66
No known key found for this signature in database
GPG Key ID: 00C64E14F51F9E56
3 changed files with 44 additions and 37 deletions

View File

@ -1,27 +0,0 @@
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2024 Benjamin Grande M. S. <ben.grande.b@gmail.com>
#
# 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()

View File

@ -6,19 +6,53 @@
"""list-extra-tag - List qubes that can be tagged for cacher""" """list-extra-tag - List qubes that can be tagged for cacher"""
import argparse
import qubesadmin # pylint: disable=import-error import qubesadmin # pylint: disable=import-error
import qubesadmin.vm # 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 def main(): # pylint: disable=missing-function-docstring
wanted_domains = ['debian', 'fedora', 'arch', 'ubuntu', 'kicksecure'] parser = argparse.ArgumentParser(description="List cacher tagged qubes")
domains = [ parser.add_argument("--extraneous", action="store_true",
vm.name help="List only extraneously tagged qubes")
for vm in qubesadmin.Qubes().domains args = parser.parse_args()
if vm.klass == "TemplateVM"
and "whonix-updatevm" not in vm.tags wanted_dist = ["debian", "fedora", "arch", "ubuntu", "kicksecure"]
and (vm.features.get("os-distribution-like") in wanted_domains qubes = qubesadmin.Qubes()
or vm.features.get("os-distribution") in wanted_domains) domains = get_cacher_tagged_qubes(qubes, wanted_dist,
] extraneous=args.extraneous)
print("\n".join(domains)) print("\n".join(domains))

View File

@ -4,7 +4,7 @@ SPDX-FileCopyrightText: 2023 - 2024 Benjamin Grande M. S. <ben.grande.b@gmail.co
SPDX-License-Identifier: AGPL-3.0-or-later SPDX-License-Identifier: AGPL-3.0-or-later
#} #}
{% set extraneous = salt['cmd.script']('salt://' ~ slsdotpath ~ '/files/admin/list_extra_tag.py') -%} {% set extraneous = salt['cmd.script']('salt://' ~ slsdotpath ~ '/files/admin/tag.py', args='--extraneous') -%}
"{{ slsdotpath }}-list-extra-tag": "{{ slsdotpath }}-list-extra-tag":
cmd.run: cmd.run:
- name: echo {{ extraneous.stdout.split("\n") }} - name: echo {{ extraneous.stdout.split("\n") }}