From c013de47476d0f19f8bf21db63cb516740a17d3a Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Mon, 27 Feb 2012 15:46:23 +0100 Subject: [PATCH 1/5] dom0/qubes-firewall: make protocol selection smart --- dom0/qvm-core/qubes.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/dom0/qvm-core/qubes.py b/dom0/qvm-core/qubes.py index 7fc2edf8..0bf293ce 100755 --- a/dom0/qvm-core/qubes.py +++ b/dom0/qvm-core/qubes.py @@ -995,7 +995,10 @@ class QubesVm(object): for rule in conf["rules"]: # For backward compatibility if "proto" not in rule: - rule["proto"] = "tcp" + if rule["portBegin"] is not None and rule["portBegin"] > 0: + rule["proto"] = "tcp" + else: + rule["proto"] = "any" element = xml.etree.ElementTree.Element( "rule", address=rule["address"], @@ -1054,16 +1057,19 @@ class QubesVm(object): else: rule["netmask"] = 32 - # For backward compatibility default to tcp - if rule["proto"] is None: - rule["proto"] = "tcp" - if rule["port"] is not None: rule["portBegin"] = int(rule["port"]) else: # backward compatibility rule["portBegin"] = 0 + # For backward compatibility + if rule["proto"] is None: + if rule["portBegin"] > 0: + rule["proto"] = "tcp" + else: + rule["proto"] = "any" + if rule["toport"] is not None: rule["portEnd"] = int(rule["toport"]) else: From d7caf5cedc12ee8cd661160e4140a886f75b40a5 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Wed, 29 Feb 2012 03:16:31 +0100 Subject: [PATCH 2/5] dom0/qvm-backup: force correct default exclude_list Treat "None" also as empty list. --- dom0/qvm-core/qubesutils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dom0/qvm-core/qubesutils.py b/dom0/qvm-core/qubesutils.py index 483d259d..4c2456ba 100644 --- a/dom0/qvm-core/qubesutils.py +++ b/dom0/qvm-core/qubesutils.py @@ -323,6 +323,9 @@ def backup_prepare(base_backup_dir, vms_list = None, exclude_list = [], print_ca files_to_backup = file_to_backup (qubes_store_filename) + if exclude_list is None: + exclude_list = [] + if vms_list is None: qvm_collection = QubesVmCollection() qvm_collection.lock_db_for_reading() From 4d739c1909e85289fe277303b50e4c5616eb3a2a Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Wed, 29 Feb 2012 03:17:25 +0100 Subject: [PATCH 3/5] dom0/qvm-backup-restore: fix restore of StandaloneVM/TemplateVM --- dom0/qvm-core/qubesutils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dom0/qvm-core/qubesutils.py b/dom0/qvm-core/qubesutils.py index 4c2456ba..4ac6d470 100644 --- a/dom0/qvm-core/qubesutils.py +++ b/dom0/qvm-core/qubesutils.py @@ -616,7 +616,7 @@ def backup_restore_prepare(backup_dir, options = {}, host_collection = None): vms_to_restore[vm.name]['already-exists'] = True vms_to_restore[vm.name]['good-to-go'] = False - if vm.template_vm is not None: + if vm.template_vm is None: vms_to_restore[vm.name]['template'] = None else: templatevm_name = find_template_name(vm.template_vm.name, options['replace-template']) From e10fa6babdebae1f9415a30371ac475d81a17cf3 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Wed, 29 Feb 2012 03:33:43 +0100 Subject: [PATCH 4/5] dom0/qvm-backup-restore: fixes - custom templates, error handling --- dom0/qvm-core/qubesutils.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/dom0/qvm-core/qubesutils.py b/dom0/qvm-core/qubesutils.py index 4ac6d470..4f96aadf 100644 --- a/dom0/qvm-core/qubesutils.py +++ b/dom0/qvm-core/qubesutils.py @@ -627,13 +627,12 @@ def backup_restore_prepare(backup_dir, options = {}, host_collection = None): if not ((template_vm_on_host is not None) and template_vm_on_host.is_template()): # Maybe the (custom) template is in the backup? template_vm_on_backup = backup_collection.get_vm_by_name (templatevm_name) - if template_vm_on_backup is None or template_vm_on_backup.is_template(): + if template_vm_on_backup is None or not template_vm_on_backup.is_template(): if options['use-default-template']: - vms_to_restore[vm.name]['template'] = host_collection.get_default_tempate_vm().name + vms_to_restore[vm.name]['template'] = host_collection.get_default_template_vm().name else: vms_to_restore[vm.name]['missing-template'] = True vms_to_restore[vm.name]['good-to-go'] = False - continue if vm.netvm_vm is None: vms_to_restore[vm.name]['netvm'] = None @@ -656,7 +655,6 @@ def backup_restore_prepare(backup_dir, options = {}, host_collection = None): else: vms_to_restore[vm.name]['missing-netvm'] = True vms_to_restore[vm.name]['good-to-go'] = False - continue if 'good-to-go' not in vms_to_restore[vm.name].keys(): vms_to_restore[vm.name]['good-to-go'] = True From a5ee72c55f88b55ba0bd949791a8c9fc0e56c0c2 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Wed, 29 Feb 2012 03:34:57 +0100 Subject: [PATCH 5/5] dom0/qvm-backup-restore: show original template name --- dom0/qvm-core/qubesutils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dom0/qvm-core/qubesutils.py b/dom0/qvm-core/qubesutils.py index 4f96aadf..e95b299d 100644 --- a/dom0/qvm-core/qubesutils.py +++ b/dom0/qvm-core/qubesutils.py @@ -629,6 +629,7 @@ def backup_restore_prepare(backup_dir, options = {}, host_collection = None): template_vm_on_backup = backup_collection.get_vm_by_name (templatevm_name) if template_vm_on_backup is None or not template_vm_on_backup.is_template(): if options['use-default-template']: + vms_to_restore[vm.name]['orig-template'] = templatevm_name vms_to_restore[vm.name]['template'] = host_collection.get_default_template_vm().name else: vms_to_restore[vm.name]['missing-template'] = True @@ -758,6 +759,8 @@ def backup_restore_print_summary(restore_info, print_callback = print_stdout): s += " <-- No matching template on the host or in the backup found!" elif 'missing-netvm' in vm_info: s += " <-- No matching netvm on the host or in the backup found!" + elif 'orig-template' in vm_info: + s += " <-- Original template was '%s'" % (vm_info['orig-template']) print_callback(s)