mirror of
https://github.com/ben-grande/qusal.git
synced 2025-07-24 15:05:25 -04:00
fix: use Admin API for fast queries
This commit is contained in:
parent
13c57939a7
commit
75d992b041
6 changed files with 63 additions and 99 deletions
|
@ -1,66 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# SPDX-FileCopyrightText: 2023 - 2024 Benjamin Grande M. S. <ben.grande.b@gmail.com>
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
set -eu
|
|
||||||
|
|
||||||
get_os_distro(){
|
|
||||||
distro_qube="${1}"
|
|
||||||
os_distro="$(qvm-features "${distro_qube}" os-distribution || true)"
|
|
||||||
}
|
|
||||||
|
|
||||||
tagged="$(qvm-ls --no-spinner --raw-list --tags updatevm-sys-cacher | tr "\n" " ")"
|
|
||||||
|
|
||||||
wanted=""
|
|
||||||
for qube in ${tagged}; do
|
|
||||||
get_os_distro "${qube}"
|
|
||||||
case "${os_distro}" in
|
|
||||||
debian|kali|kicksecure|parrot| \
|
|
||||||
ubuntu|linuxmint| \
|
|
||||||
arch|blackarch| \
|
|
||||||
fedora)
|
|
||||||
continue
|
|
||||||
;;
|
|
||||||
"")
|
|
||||||
## AppVMs and DispVMs do not report the features, discover from
|
|
||||||
## their templates.
|
|
||||||
klass="$(qvm-prefs "${qube}" klass)"
|
|
||||||
case "${klass}" in
|
|
||||||
TemplateVM|StandaloneVM)
|
|
||||||
## WARN: creates false positives in case qube never did an update to
|
|
||||||
## report the OS ID, thus reporting both supported qubes that are
|
|
||||||
## not updated yet and unsupported that didn't update yet also.
|
|
||||||
wanted="${wanted:+"${wanted} "}${qube}"
|
|
||||||
;;
|
|
||||||
AppVM|DispVM)
|
|
||||||
case "${klass}" in
|
|
||||||
AppVM)
|
|
||||||
template="$(qvm-prefs "${qube}" template)"
|
|
||||||
;;
|
|
||||||
DispVM)
|
|
||||||
app="$(qvm-prefs "${qube}" template)"
|
|
||||||
template="$(qvm-prefs "${app}" template)"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
get_os_distro "${template}"
|
|
||||||
case "${os_distro}" in
|
|
||||||
debian|kali|kicksecure|parrot| \
|
|
||||||
ubuntu|linuxmint| \
|
|
||||||
arch|blackarch| \
|
|
||||||
fedora)
|
|
||||||
continue
|
|
||||||
;;
|
|
||||||
## Qube is not supported.
|
|
||||||
*) wanted="${wanted:+"${wanted} "}${qube}";;
|
|
||||||
esac
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
;;
|
|
||||||
## Qube is not supported.
|
|
||||||
*) wanted="${wanted:+"${wanted} "}${qube}";;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "${wanted}" | tr " " "\n"
|
|
31
salt/sys-cacher/files/admin/list_extra_tag.py
Executable file
31
salt/sys-cacher/files/admin/list_extra_tag.py
Executable file
|
@ -0,0 +1,31 @@
|
||||||
|
#!/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
|
||||||
|
import qubesadmin.vm
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""main"""
|
||||||
|
wanted_domains = ['debian', 'fedora', 'arch']
|
||||||
|
## TODO: remove after https://github.com/QubesOS/qubes-core-agent-linux/pull/504
|
||||||
|
wanted_domains_extra = wanted_domains + ['kali', 'kicksecure', 'parrot',
|
||||||
|
'ubuntu', 'linuxmint', 'blackarch']
|
||||||
|
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_extra
|
||||||
|
]
|
||||||
|
print("\n".join(domains))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
30
salt/sys-cacher/files/admin/tag.py
Executable file
30
salt/sys-cacher/files/admin/tag.py
Executable file
|
@ -0,0 +1,30 @@
|
||||||
|
#!/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 that can be tagged for cacher"""
|
||||||
|
|
||||||
|
import qubesadmin
|
||||||
|
import qubesadmin.vm
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""main"""
|
||||||
|
wanted_domains = ['debian', 'fedora', 'arch']
|
||||||
|
## TODO: remove after https://github.com/QubesOS/qubes-core-agent-linux/pull/504
|
||||||
|
wanted_domains_extra = wanted_domains + ['kali', 'kicksecure', 'parrot',
|
||||||
|
'ubuntu', 'linuxmint', 'blackarch']
|
||||||
|
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_extra)
|
||||||
|
]
|
||||||
|
print("\n".join(domains))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
|
@ -1,31 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# SPDX-FileCopyrightText: 2023 - 2024 Benjamin Grande M. S. <ben.grande.b@gmail.com>
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
set -eu
|
|
||||||
|
|
||||||
exclude="$(qvm-ls --no-spinner --raw-list --tags whonix-updatevm \
|
|
||||||
| sed "s/^./--exclude &/" | tr "\n" " ")"
|
|
||||||
|
|
||||||
# shellcheck disable=SC2086
|
|
||||||
templates="$(qvm-ls --no-spinner --raw-data --fields=NAME,CLASS --all ${exclude} \
|
|
||||||
| awk -v class="TemplateVM" -F "|" '$2 ~ class {print $1}' \
|
|
||||||
| tr "\n" " ")"
|
|
||||||
|
|
||||||
wanted=""
|
|
||||||
for qube in ${templates}; do
|
|
||||||
os_distro="$(qvm-features "${qube}" os-distribution || true)"
|
|
||||||
case "${os_distro}" in
|
|
||||||
debian|kali|kicksecure|parrot| \
|
|
||||||
ubuntu|linuxmint| \
|
|
||||||
arch|blackarch| \
|
|
||||||
fedora)
|
|
||||||
wanted="${wanted:+"${wanted} "}${qube}"
|
|
||||||
;;
|
|
||||||
*) continue
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "${wanted}" | tr " " "\n"
|
|
|
@ -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.sh') -%}
|
{% set extraneous = salt['cmd.script']('salt://' ~ slsdotpath ~ '/files/admin/list_extra_tag.py') -%}
|
||||||
"{{ slsdotpath }}-list-extra-tag":
|
"{{ slsdotpath }}-list-extra-tag":
|
||||||
cmd.run:
|
cmd.run:
|
||||||
- name: echo {{ extraneous.stdout.split("\n") }}
|
- name: echo {{ extraneous.stdout.split("\n") }}
|
||||||
|
|
|
@ -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 templates = salt['cmd.script']('salt://' ~ slsdotpath ~ '/files/admin/tag.sh') -%}
|
{% set templates = salt['cmd.script']('salt://' ~ slsdotpath ~ '/files/admin/tag.py') -%}
|
||||||
{% for tpl in templates.stdout.split("\n") -%}
|
{% for tpl in templates.stdout.split("\n") -%}
|
||||||
"{{ slsdotpath }}-add-tag-of-{{ tpl }}":
|
"{{ slsdotpath }}-add-tag-of-{{ tpl }}":
|
||||||
qvm.tags:
|
qvm.tags:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue