guivm: use getattr instead of try/except and direct property access

This commit is contained in:
Frédéric Pierret (fepitre) 2019-10-20 15:11:24 +02:00
parent 6b4a99f83f
commit e63510b4cf
No known key found for this signature in database
GPG Key ID: 484010B5CDC576E2

View File

@ -252,9 +252,10 @@ class GUILauncher(object):
one for target AppVM is running. one for target AppVM is running.
:param monitor_layout: monitor layout configuration :param monitor_layout: monitor layout configuration
""" """
if vm.guivm != vm.app.get_local_name(): guivm_name = getattr(vm, 'guivm', None)
if guivm_name != vm.app.get_local_name():
vm.log.info( vm.log.info(
'{} has GuiVM {}. Skipping.'.format(vm.name, vm.guivm)) '{} has GuiVM {}. Skipping.'.format(vm.name, guivm_name))
return return
if vm.virt_mode == 'hvm': if vm.virt_mode == 'hvm':
@ -316,7 +317,7 @@ class GUILauncher(object):
"""Send monitor layout to all (running) VMs""" """Send monitor layout to all (running) VMs"""
monitor_layout = get_monitor_layout() monitor_layout = get_monitor_layout()
for vm in self.app.domains: for vm in self.app.domains:
if vm.guivm != vm.app.get_local_name(): if getattr(vm, 'guivm', None) != vm.app.get_local_name():
continue continue
if vm.klass == 'AdminVM': if vm.klass == 'AdminVM':
continue continue
@ -329,7 +330,7 @@ class GUILauncher(object):
def on_domain_spawn(self, vm, _event, **kwargs): def on_domain_spawn(self, vm, _event, **kwargs):
"""Handler of 'domain-spawn' event, starts GUI daemon for stubdomain""" """Handler of 'domain-spawn' event, starts GUI daemon for stubdomain"""
try: try:
if vm.guivm != vm.app.get_local_name(): if getattr(vm, 'guivm', None) != vm.app.get_local_name():
return return
if not vm.features.check_with_template('gui', True): if not vm.features.check_with_template('gui', True):
return return
@ -342,7 +343,7 @@ class GUILauncher(object):
def on_domain_start(self, vm, _event, **kwargs): def on_domain_start(self, vm, _event, **kwargs):
"""Handler of 'domain-start' event, starts GUI daemon for actual VM""" """Handler of 'domain-start' event, starts GUI daemon for actual VM"""
try: try:
if vm.guivm != vm.app.get_local_name(): if getattr(vm, 'guivm', None) != vm.app.get_local_name():
return return
if not vm.features.check_with_template('gui', True): if not vm.features.check_with_template('gui', True):
return return
@ -360,10 +361,7 @@ class GUILauncher(object):
for vm in self.app.domains: for vm in self.app.domains:
if vm.klass == 'AdminVM': if vm.klass == 'AdminVM':
continue continue
try: if getattr(vm, 'guivm', None) != vm.app.get_local_name():
if vm.guivm != vm.app.get_local_name():
continue
except qubesadmin.exc.QubesPropertyAccessError:
continue continue
if not vm.features.check_with_template('gui', True): if not vm.features.check_with_template('gui', True):
continue continue