mirror of
https://github.com/ben-grande/qusal.git
synced 2024-12-24 06:59:26 -05:00
feat: unify cacher tag list to a single script
This commit is contained in:
parent
35fa43dadf
commit
8604887c66
@ -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()
|
|
@ -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))
|
||||||
|
|
||||||
|
|
||||||
|
@ -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") }}
|
||||||
|
Loading…
Reference in New Issue
Block a user