Make qubes-set-updates set also default state for new VMs

This makes possible to also check if the "updates check enabled" state
is consistent across VMs.

Fixes qubesos/qubes-issues#892
This commit is contained in:
Marek Marczykowski-Górecki 2015-08-03 22:43:07 +02:00
parent fbfaa98b80
commit 46b94b6682
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
3 changed files with 38 additions and 5 deletions

View File

@ -43,6 +43,7 @@ from qubes.qubes import dry_run,vmm
from qubes.qubes import register_qubes_vm_class
from qubes.qubes import QubesVmCollection,QubesException,QubesHost,QubesVmLabels
from qubes.qubes import defaults,system_path,vm_files,qubes_max_qid
qmemman_present = False
try:
from qubes.qmemman_client import QMemmanClient
@ -334,6 +335,11 @@ class QubesVm(object):
if len(self.pcidevs) > 0:
self.services['meminfo-writer'] = False
if 'xml_element' not in kwargs:
# New VM, disable updates check if requested for new VMs
if os.path.exists(qubes.qubesutils.UPDATES_DEFAULT_VM_DISABLE_FLAG):
self.services['qubes-update-check'] = False
# Initialize VM image storage class
self.storage = defaults["storage_class"](self)
if hasattr(self, 'kernels_dir'):

View File

@ -844,8 +844,18 @@ class QubesWatch(object):
##### updates check #####
UPDATES_DOM0_DISABLE_FLAG='/var/lib/qubes/updates/disable-updates'
UPDATES_DEFAULT_VM_DISABLE_FLAG=\
'/var/lib/qubes/updates/vm-default-disable-updates'
def updates_vms_toggle(qvm_collection, value):
# Flag for new VMs
if value:
if os.path.exists(UPDATES_DEFAULT_VM_DISABLE_FLAG):
os.unlink(UPDATES_DEFAULT_VM_DISABLE_FLAG)
else:
open(UPDATES_DEFAULT_VM_DISABLE_FLAG, "w").close()
# Change for existing VMs
for vm in qvm_collection.values():
if vm.qid == 0:
continue
@ -875,5 +885,16 @@ def updates_dom0_toggle(qvm_collection, value):
def updates_dom0_status(qvm_collection):
return not os.path.exists(UPDATES_DOM0_DISABLE_FLAG)
def updates_vms_status(qvm_collection):
# default value:
status = not os.path.exists(UPDATES_DEFAULT_VM_DISABLE_FLAG)
# check if all the VMs uses the default value
for vm in qvm_collection.values():
if vm.qid == 0:
continue
if vm.services.get('qubes-update-check', True) != status:
# "mixed"
return None
return status
# vim:sw=4:et:

View File

@ -27,15 +27,14 @@ import os
import sys
from qubes.qubes import QubesVmCollection
from qubes.qubesutils import updates_vms_toggle,updates_dom0_toggle,\
updates_dom0_status
updates_dom0_status,updates_vms_status
from qubes.qubes import vmm
def main():
usage = "%prog enable|disable|status\n"\
" Enable or disable globally checking for updates (both dom0 and VM)"\
" Status option checks only dom0 updates status"
" Enable or disable globally checking for updates (both dom0 and VM)"
parser = OptionParser (usage)
parser.add_option("--offline-mode", dest="offline_mode",
action="store_true", default=False,
@ -67,9 +66,16 @@ def main():
updates_vms_toggle(qvm_collection, False)
else:
if updates_dom0_status(qvm_collection):
print "enabled"
print "dom0: enabled"
else:
print "disabled"
print "dom0: disabled"
status_vms = updates_vms_status(qvm_collection)
if status_vms is None:
print "vms: mixed"
elif status_vms:
print "vms: enabled"
else:
print "vms: disabled"
if action != 'status':
qvm_collection.save()