qubesutils: enable/disable updates check on all the VMs and dom0 (#800)

This commit is contained in:
Marek Marczykowski-Górecki 2014-04-11 07:06:12 +02:00
parent cd6504f8ea
commit 5cbfb64a57
2 changed files with 82 additions and 0 deletions

View File

@ -775,4 +775,39 @@ class QubesWatch(object):
while True:
self.watch_single()
##### updates check #####
UPDATES_DOM0_DISABLE_FLAG='/var/lib/qubes/updates/disable-updates'
def updates_vms_toggle(qvm_collection, value):
for vm in qvm_collection.values():
if vm.qid == 0:
continue
if value:
vm.services.pop('qubes-update-check', None)
if vm.is_running():
try:
vm.run("systemctl start qubes-update-check.timer",
user="root")
except:
pass
else:
vm.services['qubes-update-check'] = False
if vm.is_running():
try:
vm.run("systemctl stop qubes-update-check.timer",
user="root")
except:
pass
def updates_dom0_toggle(qvm_collection, value):
if value:
if os.path.exists(UPDATES_DOM0_DISABLE_FLAG):
os.unlink(UPDATES_DOM0_DISABLE_FLAG)
else:
open(UPDATES_DOM0_DISABLE_FLAG, "w").close()
def updates_dom0_status(qvm_collection):
return not os.path.exists(UPDATES_DOM0_DISABLE_FLAG)
# vim:sw=4:et:

47
qvm-tools/qubes-set-updates Executable file
View File

@ -0,0 +1,47 @@
#!/usr/bin/python2
import os
import sys
from qubes.qubes import QubesVmCollection
from qubes.qubesutils import updates_vms_toggle,updates_dom0_toggle,\
updates_dom0_status
def usage():
print "Usage: qubes-set-updates enable|disable|status"
print " Enable or disable globally checking for updates (both dom0 and VM)"
print " Status option checks only dom0 updates status"
def main():
if len(sys.argv) < 2:
usage()
return 1
action = sys.argv[1]
if action not in ['enable', 'disable', 'status']:
usage()
return 1
qvm_collection = QubesVmCollection()
if action == 'status':
qvm_collection.lock_db_for_reading()
else:
qvm_collection.lock_db_for_writing()
qvm_collection.load()
if action == 'enable':
updates_dom0_toggle(qvm_collection, True)
updates_vms_toggle(qvm_collection, True)
elif action == 'disable':
updates_dom0_toggle(qvm_collection, False)
updates_vms_toggle(qvm_collection, False)
else:
if updates_dom0_status(qvm_collection):
print "enabled"
else:
print "disabled"
if action != 'status':
qvm_collection.save()
qvm_collection.unlock_db()
if __name__ == "__main__":
main()