dom0/qvm-tools: output diagnostics to stderr instead of stdout (#276)

This commit is contained in:
Marek Marczykowski 2011-10-07 21:56:58 +02:00
parent 05605f1394
commit ed23b0d6a2
26 changed files with 237 additions and 217 deletions

View File

@ -23,6 +23,7 @@
from qubes.qubes import QubesVmCollection from qubes.qubes import QubesVmCollection
from qubes.qubes import QubesException from qubes.qubes import QubesException
from optparse import OptionParser; from optparse import OptionParser;
import sys
def main(): def main():
usage = "usage: %prog [options] <appvm-name> <vm-template-name>\n\n"\ usage = "usage: %prog [options] <appvm-name> <vm-template-name>\n\n"\
@ -48,12 +49,12 @@ def main():
qvm_collection.load() qvm_collection.load()
if qvm_collection.get_vm_by_name(vmname) is not None: if qvm_collection.get_vm_by_name(vmname) is not None:
print "ERROR: A VM with the name '{0}' already exists in the system.".format(vmname) print >> sys.stderr, "ERROR: A VM with the name '{0}' already exists in the system.".format(vmname)
exit(1) exit(1)
template_vm = qvm_collection.get_vm_by_name(templatename) template_vm = qvm_collection.get_vm_by_name(templatename)
if template_vm is None: if template_vm is None:
print "ERROR: A Template VM with the name '{0}' does not exist in the system.".format(templatename) print >> sys.stderr, "ERROR: A Template VM with the name '{0}' does not exist in the system.".format(templatename)
exit(1) exit(1)
@ -64,7 +65,7 @@ def main():
try: try:
vm.verify_files() vm.verify_files()
except QubesException as err: except QubesException as err:
print "ERROR: {0}".format(err) print >> sys.stderr, "ERROR: {0}".format(err)
qvm_collection.pop(vm.qid) qvm_collection.pop(vm.qid)
exit (1) exit (1)

View File

@ -23,6 +23,7 @@
from qubes.qubes import QubesVmCollection from qubes.qubes import QubesVmCollection
from qubes.qubes import QubesException from qubes.qubes import QubesException
from optparse import OptionParser; from optparse import OptionParser;
import sys
def main(): def main():
usage = "usage: %prog [options] <vm-template-name>\n"\ usage = "usage: %prog [options] <vm-template-name>\n"\
@ -49,7 +50,7 @@ def main():
qvm_collection.load() qvm_collection.load()
if qvm_collection.get_vm_by_name(vmname) is not None: if qvm_collection.get_vm_by_name(vmname) is not None:
print "ERROR: A VM with the name '{0}' already exists in the system.".format(vmname) print >> sys.stderr, "ERROR: A VM with the name '{0}' already exists in the system.".format(vmname)
exit(1) exit(1)
vm = qvm_collection.add_new_templatevm(vmname, vm = qvm_collection.add_new_templatevm(vmname,
@ -60,7 +61,7 @@ def main():
try: try:
vm.verify_files() vm.verify_files()
except QubesException as err: except QubesException as err:
print "ERROR: {0}".format(err) print >> sys.stderr, "ERROR: {0}".format(err)
qvm_collection.pop(vm.qid) qvm_collection.pop(vm.qid)
exit (1) exit (1)

View File

@ -62,14 +62,14 @@ def main():
(options, args) = parser.parse_args () (options, args) = parser.parse_args ()
if (len (args) != 1): if (len (args) != 1):
print "You must specify the target backup directory (e.g. /mnt/backup)" print >> sys.stderr, "You must specify the target backup directory (e.g. /mnt/backup)"
print "qvm-backup will create a subdirectory there for each individual backup." print >> sys.stderr, "qvm-backup will create a subdirectory there for each individual backup."
exit (0) exit (0)
base_backup_dir = args[0] base_backup_dir = args[0]
if not os.path.exists (base_backup_dir): if not os.path.exists (base_backup_dir):
print "The target directory doesn't exist!" print >> sys.stderr, "The target directory doesn't exist!"
exit(1) exit(1)
qvm_collection = QubesVmCollection() qvm_collection = QubesVmCollection()
@ -78,7 +78,7 @@ def main():
if options is not None and options.exclude_list is not None: if options is not None and options.exclude_list is not None:
print "Excluding the following VMs:", options.exclude_list print >> sys.stderr, "Excluding the following VMs:", options.exclude_list
vms_list = [vm for vm in qvm_collection.values() if vm.name not in options.exclude_list] vms_list = [vm for vm in qvm_collection.values() if vm.name not in options.exclude_list]
else: else:
vms_list = [vm for vm in qvm_collection.values()] vms_list = [vm for vm in qvm_collection.values()]
@ -215,18 +215,18 @@ def main():
backup_fs_free_sz = stat.f_bsize * stat.f_bavail backup_fs_free_sz = stat.f_bsize * stat.f_bavail
print print
if (total_backup_sz > backup_fs_free_sz): if (total_backup_sz > backup_fs_free_sz):
print "Not enough space avilable on the backup filesystem!" print >> sys.stderr, "Not enough space avilable on the backup filesystem!"
exit (1) exit (1)
if (there_are_running_vms): if (there_are_running_vms):
print "Please shutdown all VMs before proceeding." print >> sys.stderr, "Please shutdown all VMs before proceeding."
exit (1) exit (1)
backup_dir = base_backup_dir + "/qubes-{0}".format (time.strftime("%Y-%m-%d-%H%M%S")) backup_dir = base_backup_dir + "/qubes-{0}".format (time.strftime("%Y-%m-%d-%H%M%S"))
if os.path.exists (backup_dir): if os.path.exists (backup_dir):
print "ERROR: the path {0} already exists?!".format(backup_dir) print >> sys.stderr, "ERROR: the path {0} already exists?!".format(backup_dir)
print "Aborting..." print >> sys.stderr, "Aborting..."
exit (1) exit (1)
print "-> Backup dir: {0}".format (backup_dir) print "-> Backup dir: {0}".format (backup_dir)
@ -239,8 +239,8 @@ def main():
os.mkdir (backup_dir) os.mkdir (backup_dir)
if not os.path.exists (backup_dir): if not os.path.exists (backup_dir):
print "ERROR: Strange: couldn't create backup dir: {0}?!".format(backup_dir) print >> sys.stderr, "ERROR: Strange: couldn't create backup dir: {0}?!".format(backup_dir)
print "Aborting..." print >> sys.stderr, "Aborting..."
exit (1) exit (1)
bytes_backedup = 0 bytes_backedup = 0
@ -252,13 +252,13 @@ def main():
if file["subdir"] != "": if file["subdir"] != "":
retcode = subprocess.call (["mkdir", "-p", dest_dir]) retcode = subprocess.call (["mkdir", "-p", dest_dir])
if retcode != 0: if retcode != 0:
print "Cannot create directory: {0}?!".format(dest_dir) print >> sys.stderr, "Cannot create directory: {0}?!".format(dest_dir)
print "Aborting..." print >> sys.stderr, "Aborting..."
exit(1) exit(1)
retcode = subprocess.call (["cp", "-rp", file["path"], dest_dir]) retcode = subprocess.call (["cp", "-rp", file["path"], dest_dir])
if retcode != 0: if retcode != 0:
print "Error while copying file {0} to {1}".format(file["path"], dest_dir) print >> sys.stderr, "Error while copying file {0} to {1}".format(file["path"], dest_dir)
exit (1) exit (1)
bytes_backedup += file["size"] bytes_backedup += file["size"]

View File

@ -94,7 +94,7 @@ def restore_vm_file (backup_dir, file_path):
# We prefer to use Linux's cp, because it nicely handles sparse files # We prefer to use Linux's cp, because it nicely handles sparse files
retcode = subprocess.call (["cp", "-p", backup_file_path, file_path]) retcode = subprocess.call (["cp", "-p", backup_file_path, file_path])
if retcode != 0: if retcode != 0:
print "*** Error while copying file {0} to {1}".format(backup_file_path, file_path) print >> sys.stderr, "*** Error while copying file {0} to {1}".format(backup_file_path, file_path)
exit (1) exit (1)
def restore_vm_dir (backup_dir, src_dir, dst_dir): def restore_vm_dir (backup_dir, src_dir, dst_dir):
@ -104,7 +104,7 @@ def restore_vm_dir (backup_dir, src_dir, dst_dir):
# We prefer to use Linux's cp, because it nicely handles sparse files # We prefer to use Linux's cp, because it nicely handles sparse files
retcode = subprocess.call (["cp", "-rp", backup_src_dir, dst_dir]) retcode = subprocess.call (["cp", "-rp", backup_src_dir, dst_dir])
if retcode != 0: if retcode != 0:
print "*** Error while copying file {0} to {1}".format(backup_src_dir, dest_dir) print >> sys.stderr, "*** Error while copying file {0} to {1}".format(backup_src_dir, dest_dir)
exit (1) exit (1)
def find_template_name(template, replaces): def find_template_name(template, replaces):
@ -138,13 +138,13 @@ def main():
(options, args) = parser.parse_args () (options, args) = parser.parse_args ()
if (len (args) != 1): if (len (args) != 1):
print "You must specify the backup directory (e.g. /mnt/backup/qubes-2010-12-01-235959)" print >> sys.stderr, "You must specify the backup directory (e.g. /mnt/backup/qubes-2010-12-01-235959)"
exit (0) exit (0)
backup_dir = args[0] backup_dir = args[0]
if not os.path.exists (backup_dir): if not os.path.exists (backup_dir):
print "The backup directory doesn't exist!" print >> sys.stderr, "The backup directory doesn't exist!"
exit(1) exit(1)
backup_collection = QubesVmCollection(store_filename = backup_dir + "/qubes.xml") backup_collection = QubesVmCollection(store_filename = backup_dir + "/qubes.xml")
@ -245,52 +245,52 @@ def main():
print print
if os.geteuid() == 0: if os.geteuid() == 0:
print "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems." print >> sys.stderr, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems."
if options.force_root: if options.force_root:
print "Continuing as commanded. You have been warned." print >> sys.stderr, "Continuing as commanded. You have been warned."
else: else:
print "Retry as unprivileged user." print >> sys.stderr, "Retry as unprivileged user."
print "... or use --force-root to continue anyway." print >> sys.stderr, "... or use --force-root to continue anyway."
exit(1) exit(1)
if there_are_conflicting_vms: if there_are_conflicting_vms:
print "*** There VMs with conflicting names on the host! ***" print >> sys.stderr, "*** There VMs with conflicting names on the host! ***"
if options.skip_conflicting: if options.skip_conflicting:
print "Those VMs will not be restored, the host VMs will not be overwritten!" print >> sys.stderr, "Those VMs will not be restored, the host VMs will not be overwritten!"
else: else:
print "Remove VMs with conflicting names from the host before proceeding." print >> sys.stderr, "Remove VMs with conflicting names from the host before proceeding."
print "... or use --skip-conflicting to restore only those VMs that do not exist on the host." print >> sys.stderr, "... or use --skip-conflicting to restore only those VMs that do not exist on the host."
exit (1) exit (1)
print "The above VMs will be copied and added to your system." print "The above VMs will be copied and added to your system."
print "Exisiting VMs will not be removed." print "Exisiting VMs will not be removed."
if there_are_missing_templates: if there_are_missing_templates:
print "*** One or more template VM is missing on the host! ***" print >> sys.stderr, "*** One or more template VM is missing on the host! ***"
if not (options.skip_broken or options.ignore_missing): if not (options.skip_broken or options.ignore_missing):
print "Install it first, before proceeding with backup restore." print >> sys.stderr, "Install it first, before proceeding with backup restore."
print "Or pass: --skip-broken or --ignore-missing switch." print >> sys.stderr, "Or pass: --skip-broken or --ignore-missing switch."
exit (1) exit (1)
elif options.skip_broken: elif options.skip_broken:
print "... VMs that depend on it will not be restored (--skip-broken used)" print >> sys.stderr, "... VMs that depend on it will not be restored (--skip-broken used)"
elif options.ignore_missing: elif options.ignore_missing:
print "... VMs that depend on it will be restored anyway (--ignore-missing used)" print >> sys.stderr, "... VMs that depend on it will be restored anyway (--ignore-missing used)"
else: else:
print "INTERNAL ERROR?!" print >> sys.stderr, "INTERNAL ERROR?!"
exit (1) exit (1)
if there_are_missing_netvms: if there_are_missing_netvms:
print "*** One or more network VM is missing on the host! ***" print >> sys.stderr, "*** One or more network VM is missing on the host! ***"
if not (options.skip_broken or options.ignore_missing): if not (options.skip_broken or options.ignore_missing):
print "Install it first, before proceeding with backup restore." print >> sys.stderr, "Install it first, before proceeding with backup restore."
print "Or pass: --skip_broken or --ignore_missing switch." print >> sys.stderr, "Or pass: --skip_broken or --ignore_missing switch."
exit (1) exit (1)
elif options.skip_broken: elif options.skip_broken:
print "... VMs that depend on it will not be restored (--skip-broken used)" print >> sys.stderr, "... VMs that depend on it will not be restored (--skip-broken used)"
elif options.ignore_missing: elif options.ignore_missing:
print "... VMs that depend on it be restored anyway (--ignore-missing used)" print >> sys.stderr, "... VMs that depend on it be restored anyway (--ignore-missing used)"
else: else:
print "INTERNAL ERROR?!" print >> sys.stderr, "INTERNAL ERROR?!"
exit (1) exit (1)
prompt = raw_input ("Do you want to proceed? [y/N] ") prompt = raw_input ("Do you want to proceed? [y/N] ")
@ -302,8 +302,8 @@ def main():
print "-> Restoring Template VM {0}...".format(vm.name) print "-> Restoring Template VM {0}...".format(vm.name)
retcode = subprocess.call (["mkdir", "-p", vm.dir_path]) retcode = subprocess.call (["mkdir", "-p", vm.dir_path])
if retcode != 0: if retcode != 0:
print ("*** Cannot create directory: {0}?!".format(dest_dir)) print >> sys.stderr, ("*** Cannot create directory: {0}?!".format(dest_dir))
print ("Skiping...") print >> sys.stderr, ("Skiping...")
continue continue
restore_vm_dir (backup_dir, vm.dir_path, qubes_templates_dir); restore_vm_dir (backup_dir, vm.dir_path, qubes_templates_dir);
@ -317,8 +317,8 @@ def main():
vm.updateable = updateable vm.updateable = updateable
vm.verify_files() vm.verify_files()
except Exception as err: except Exception as err:
print "ERROR: {0}".format(err) print >> sys.stderr, "ERROR: {0}".format(err)
print "*** Skiping VM: {0}".vm.name print >> sys.stderr, "*** Skiping VM: {0}".vm.name
if vm: if vm:
host_collection.pop(vm.qid) host_collection.pop(vm.qid)
continue continue
@ -326,8 +326,8 @@ def main():
try: try:
vm.create_appmenus(verbose=True) vm.create_appmenus(verbose=True)
except Exception as err: except Exception as err:
print "ERROR during appmenu restore: {0}".format(err) print >> sys.stderr, "ERROR during appmenu restore: {0}".format(err)
print "*** VM '{0}' will not have appmenus".format(vm.name) print >> sys.stderr, "*** VM '{0}' will not have appmenus".format(vm.name)
# ... then NetVMs... # ... then NetVMs...
for vm in [ vm for vm in vms_to_restore if vm.is_netvm()]: for vm in [ vm for vm in vms_to_restore if vm.is_netvm()]:
@ -335,8 +335,8 @@ def main():
print "-> Restoring {0} {1}...".format(vm.type, vm.name) print "-> Restoring {0} {1}...".format(vm.type, vm.name)
retcode = subprocess.call (["mkdir", "-p", vm.dir_path]) retcode = subprocess.call (["mkdir", "-p", vm.dir_path])
if retcode != 0: if retcode != 0:
print ("*** Cannot create directory: {0}?!".format(dest_dir)) print >> sys.stderr, ("*** Cannot create directory: {0}?!".format(dest_dir))
print ("Skiping...") print >> sys.stderr, ("Skiping...")
continue continue
restore_vm_dir (backup_dir, vm.dir_path, qubes_servicevms_dir); restore_vm_dir (backup_dir, vm.dir_path, qubes_servicevms_dir);
@ -368,8 +368,8 @@ def main():
updateable=updateable, updateable=updateable,
label=vm.label) label=vm.label)
except Exception as err: except Exception as err:
print "ERROR: {0}".format(err) print >> sys.stderr, "ERROR: {0}".format(err)
print "*** Skiping VM: {0}".format(vm.name) print >> sys.stderr, "*** Skiping VM: {0}".format(vm.name)
if vm: if vm:
host_collection.pop(vm.qid) host_collection.pop(vm.qid)
continue continue
@ -381,8 +381,8 @@ def main():
try: try:
vm.verify_files() vm.verify_files()
except Exception as err: except Exception as err:
print "ERROR: {0}".format(err) print >> sys.stderr, "ERROR: {0}".format(err)
print "*** Skiping VM: {0}".format(vm.name) print >> sys.stderr, "*** Skiping VM: {0}".format(vm.name)
host_collection.pop(vm.qid) host_collection.pop(vm.qid)
continue continue
@ -392,8 +392,8 @@ def main():
print "-> Restoring AppVM {0}...".format(vm.name) print "-> Restoring AppVM {0}...".format(vm.name)
retcode = subprocess.call (["mkdir", "-p", vm.dir_path]) retcode = subprocess.call (["mkdir", "-p", vm.dir_path])
if retcode != 0: if retcode != 0:
print ("*** Cannot create directory: {0}?!".format(dest_dir)) print >> sys.stderr, ("*** Cannot create directory: {0}?!".format(dest_dir))
print ("Skiping...") print >> sys.stderr, ("Skiping...")
continue continue
restore_vm_dir (backup_dir, vm.dir_path, qubes_appvms_dir); restore_vm_dir (backup_dir, vm.dir_path, qubes_appvms_dir);
@ -418,8 +418,8 @@ def main():
updateable=updateable, updateable=updateable,
label=vm.label) label=vm.label)
except Exception as err: except Exception as err:
print "ERROR: {0}".format(err) print >> sys.stderr, "ERROR: {0}".format(err)
print "*** Skiping VM: {0}".format(vm.name) print >> sys.stderr, "*** Skiping VM: {0}".format(vm.name)
if vm: if vm:
host_collection.pop(vm.qid) host_collection.pop(vm.qid)
continue continue
@ -431,14 +431,14 @@ def main():
try: try:
vm.create_appmenus(verbose=True) vm.create_appmenus(verbose=True)
except Exception as err: except Exception as err:
print "ERROR during appmenu restore: {0}".format(err) print >> sys.stderr, "ERROR during appmenu restore: {0}".format(err)
print "*** VM '{0}' will not have appmenus".format(vm.name) print >> sys.stderr, "*** VM '{0}' will not have appmenus".format(vm.name)
try: try:
vm.verify_files() vm.verify_files()
except Exception as err: except Exception as err:
print "ERROR: {0}".format(err) print >> sys.stderr, "ERROR: {0}".format(err)
print "*** Skiping VM: {0}".format(vm.name) print >> sys.stderr, "*** Skiping VM: {0}".format(vm.name)
host_collection.pop(vm.qid) host_collection.pop(vm.qid)
continue continue

View File

@ -49,7 +49,7 @@ def main():
(options, args) = parser.parse_args () (options, args) = parser.parse_args ()
if options.do_list + options.do_attach + options.do_detach > 1: if options.do_list + options.do_attach + options.do_detach > 1:
print "Only one of -l -a -d is allowed!" print >> sys.stderr, "Only one of -l -a -d is allowed!"
exit (1) exit (1)
if options.do_attach or options.do_detach: if options.do_attach or options.do_detach:

View File

@ -23,6 +23,7 @@
from qubes.qubes import QubesVmCollection from qubes.qubes import QubesVmCollection
from qubes.qubes import QubesException from qubes.qubes import QubesException
from optparse import OptionParser; from optparse import OptionParser;
import sys
def main(): def main():
usage = "usage: %prog [options] <src-template-name> <new-template-name>\n"\ usage = "usage: %prog [options] <src-template-name> <new-template-name>\n"\
@ -45,11 +46,11 @@ def main():
src_tvm = qvm_collection.get_vm_by_name(srcname) src_tvm = qvm_collection.get_vm_by_name(srcname)
if src_tvm is None: if src_tvm is None:
print "ERROR: A VM with the name '{0}' does not exist in the system.".format(srcname) print >> sys.stderr, "ERROR: A VM with the name '{0}' does not exist in the system.".format(srcname)
exit(1) exit(1)
if qvm_collection.get_vm_by_name(dstname) is not None: if qvm_collection.get_vm_by_name(dstname) is not None:
print "ERROR: A VM with the name '{0}' already exists in the system.".format(dstname) print >> sys.stderr, "ERROR: A VM with the name '{0}' already exists in the system.".format(dstname)
exit(1) exit(1)
dst_tvm = qvm_collection.clone_templatevm(src_template_vm=src_tvm, dst_tvm = qvm_collection.clone_templatevm(src_template_vm=src_tvm,
@ -59,7 +60,7 @@ def main():
try: try:
dst_tvm.clone_disk_files (src_template_vm=src_tvm, verbose=options.verbose) dst_tvm.clone_disk_files (src_template_vm=src_tvm, verbose=options.verbose)
except (IOError, OSError) as err: except (IOError, OSError) as err:
print "ERROR: {0}".format(err) print >> sys.stderr, "ERROR: {0}".format(err)
qvm_collection.pop(dst_tvm.qid) qvm_collection.pop(dst_tvm.qid)
exit (1) exit (1)

View File

@ -26,6 +26,7 @@ from optparse import OptionParser;
import subprocess import subprocess
import re import re
import os import os
import sys
def main(): def main():
usage = "usage: %prog [options] <vm-name>" usage = "usage: %prog [options] <vm-name>"
@ -59,25 +60,25 @@ def main():
parser.error ("You must specify at most one of --proxy and --net") parser.error ("You must specify at most one of --proxy and --net")
if os.geteuid() == 0: if os.geteuid() == 0:
print "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems." print >> sys.stderr, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems."
if options.force_root: if options.force_root:
print "Continuing as commanded. You have been warned." print >> sys.stderr, "Continuing as commanded. You have been warned."
else: else:
print "Retry as unprivileged user." print >> sys.stderr, "Retry as unprivileged user."
print "... or use --force-root to continue anyway." print >> sys.stderr, "... or use --force-root to continue anyway."
exit(1) exit(1)
if options.label is None: if options.label is None:
print "You must choose a label for the new VM by passing the --label option." print >> sys.stderr, "You must choose a label for the new VM by passing the --label option."
print "Possible values are:" print >> sys.stderr, "Possible values are:"
for l in QubesVmLabels.values(): for l in QubesVmLabels.values():
print "* {0}".format(l.name) print >> sys.stderr, "* {0}".format(l.name)
exit (1) exit (1)
if options.label not in QubesVmLabels: if options.label not in QubesVmLabels:
print "Wrong label name, supported values are the following:" print >> sys.stderr, "Wrong label name, supported values are the following:"
for l in QubesVmLabels.values(): for l in QubesVmLabels.values():
print "* {0}".format(l.name) print >> sys.stderr, "* {0}".format(l.name)
exit (1) exit (1)
label = QubesVmLabels[options.label] label = QubesVmLabels[options.label]
@ -86,23 +87,23 @@ def main():
qvm_collection.load() qvm_collection.load()
if qvm_collection.get_vm_by_name(vmname) is not None: if qvm_collection.get_vm_by_name(vmname) is not None:
print "A VM with the name '{0}' already exists in the system.".format(vmname) print >> sys.stderr, "A VM with the name '{0}' already exists in the system.".format(vmname)
exit(1) exit(1)
if options.template is not None: if options.template is not None:
template_vm = qvm_collection.get_vm_by_name(options.template) template_vm = qvm_collection.get_vm_by_name(options.template)
if template_vm is None: if template_vm is None:
print "There is no (Templete)VM with the name '{0}'".format(options.template) print >> sys.stderr, "There is no (Templete)VM with the name '{0}'".format(options.template)
exit (1) exit (1)
if not template_vm.is_template(): if not template_vm.is_template():
print "VM '{0}' is not a TemplateVM".format(options.template) print >> sys.stderr, "VM '{0}' is not a TemplateVM".format(options.template)
exit (1) exit (1)
if (options.verbose): if (options.verbose):
print "--> Using TemplateVM: {0}".format(template_vm.name) print "--> Using TemplateVM: {0}".format(template_vm.name)
else: else:
if qvm_collection.get_default_template_vm() is None: if qvm_collection.get_default_template_vm() is None:
print "No default TempleteVM defined!" print >> sys.stderr, "No default TempleteVM defined!"
exit (1) exit (1)
else: else:
template_vm = qvm_collection.get_default_template_vm() template_vm = qvm_collection.get_default_template_vm()
@ -135,7 +136,7 @@ def main():
vm.create_on_disk(verbose=options.verbose, source_template=template_vm) vm.create_on_disk(verbose=options.verbose, source_template=template_vm)
except (IOError, OSError) as err: except (IOError, OSError) as err:
print "ERROR: {0}".format(err) print >> sys.stderr, "ERROR: {0}".format(err)
exit (1) exit (1)

View File

@ -37,7 +37,7 @@ def get_netvm():
while netvm.netvm_vm is not None: while netvm.netvm_vm is not None:
netvm = netvm.netvm_vm netvm = netvm.netvm_vm
if netvm is None or netvm.name == 'dom0': if netvm is None or netvm.name == 'dom0':
print 'There seems to be no dedicated default netvm, aborting.' print >> sys.stderr, 'There seems to be no dedicated default netvm, aborting.'
sys.exit(1) sys.exit(1)
return netvm return netvm
@ -45,8 +45,8 @@ def vif_eth0_exists():
if not os.path.islink('/sys/class/net/eth0'): if not os.path.islink('/sys/class/net/eth0'):
return False return False
if not os.path.isdir('/sys/devices/xen/vif-0/net/eth0'): if not os.path.isdir('/sys/devices/xen/vif-0/net/eth0'):
print 'There is a dedicated netvm, but device eth0 is present' print >> sys.stderr, 'There is a dedicated netvm, but device eth0 is present'
print 'and it is not a Xen interface. Refusing to continue.' print >> sys.stderr, 'and it is not a Xen interface. Refusing to continue.'
sys.exit(1) sys.exit(1)
return True return True
@ -64,7 +64,7 @@ def netup():
if not vif_eth0_exists(): if not vif_eth0_exists():
cmd = 'modprobe xennet' cmd = 'modprobe xennet'
if os.system(cmd) != 0: if os.system(cmd) != 0:
print 'Error creating network device' print >> sys.stderr, 'Error creating network device'
sys.exit(1) sys.exit(1)
qvm_collection[0].attach_network(verbose=True, netvm=netvm, wait=True) qvm_collection[0].attach_network(verbose=True, netvm=netvm, wait=True)
if not bringup_eth0(netvm): if not bringup_eth0(netvm):
@ -73,20 +73,20 @@ def netup():
def netdown(): def netdown():
netvm = get_netvm() netvm = get_netvm()
if not vif_eth0_exists(): if not vif_eth0_exists():
print 'There is no eth0 that is a Xen vif device, aborting.' print >> sys.stderr, 'There is no eth0 that is a Xen vif device, aborting.'
sys.exit(1) sys.exit(1)
os.system('ifconfig eth0 down') os.system('ifconfig eth0 down')
os.system('xl network-detach 0 0') os.system('xl network-detach 0 0')
def usage(): def usage():
print 'Usage: qvm-dom0-network-via-netvm [up|down]' print >> sys.stderr, 'Usage: qvm-dom0-network-via-netvm [up|down]'
sys.exit(1) sys.exit(1)
def main(): def main():
if len(sys.argv) != 2: if len(sys.argv) != 2:
usage() usage()
if os.getuid() != 0: if os.getuid() != 0:
print 'This script must be run as root' print >> sys.stderr, 'This script must be run as root'
sys.exit(1) sys.exit(1)
if sys.argv[1] == 'up': if sys.argv[1] == 'up':
netup() netup()

View File

@ -26,6 +26,7 @@ from optparse import OptionParser
import subprocess import subprocess
import os import os
import re import re
import sys
qvm_run_path = "/usr/bin/qvm-run" qvm_run_path = "/usr/bin/qvm-run"
@ -44,7 +45,7 @@ def parse_size(size):
size = size[:-len(unit)].strip() size = size[:-len(unit)].strip()
return int(size)*multiplier return int(size)*multiplier
print "Invalid size: {0}.".format(size) print >> sys.stderr, "Invalid size: {0}.".format(size)
exit(1) exit(1)
def main(): def main():
@ -64,23 +65,23 @@ def main():
vm = qvm_collection.get_vm_by_name(vmname) vm = qvm_collection.get_vm_by_name(vmname)
if vm is None: if vm is None:
print "A VM with the name '{0}' does not exist in the system.".format(vmname) print >> sys.stderr, "A VM with the name '{0}' does not exist in the system.".format(vmname)
exit(1) exit(1)
if vm.is_running() and os.geteuid() != 0: if vm.is_running() and os.geteuid() != 0:
print "You must be root to grow private.img on running VM." print >> sys.stderr, "You must be root to grow private.img on running VM."
exit(1) exit(1)
size_bytes = parse_size(size) size_bytes = parse_size(size)
if size_bytes < vm.get_private_img_sz(): if size_bytes < vm.get_private_img_sz():
print "Cannot shrink private.img ({0} < {1})".format(size_bytes, vm.get_private_img_sz()) print >> sys.stderr, "Cannot shrink private.img ({0} < {1})".format(size_bytes, vm.get_private_img_sz())
exit(1) exit(1)
try: try:
vm.resize_private_img(size_bytes) vm.resize_private_img(size_bytes)
except (IOError, OSError, QubesException) as err: except (IOError, OSError, QubesException) as err:
print "ERROR: {0}".format(err) print >> sys.stderr, "ERROR: {0}".format(err)
exit (1) exit (1)
if vm.is_running(): if vm.is_running():
@ -90,7 +91,7 @@ def main():
result = p.communicate() result = p.communicate()
m = re.match(r"^(/dev/loop\d+):\s", result[0]) m = re.match(r"^(/dev/loop\d+):\s", result[0])
if m is None: if m is None:
print "ERROR: Cannot find loop device!" print >> sys.stderr, "ERROR: Cannot find loop device!"
exit(1) exit(1)
loop_dev = m.group(1) loop_dev = m.group(1)

View File

@ -21,11 +21,12 @@
# #
from qubes.qubes import QubesVmCollection from qubes.qubes import QubesVmCollection
import sys
def main(): def main():
qvm_collection = QubesVmCollection() qvm_collection = QubesVmCollection()
if qvm_collection.check_if_storage_exists(): if qvm_collection.check_if_storage_exists():
print "Storage exists, not overwriting." print >> sys.stderr, "Storage exists, not overwriting."
exit(1) exit(1)
qvm_collection.create_empty_storage() qvm_collection.create_empty_storage()

View File

@ -23,6 +23,7 @@
from qubes.qubes import QubesVmCollection from qubes.qubes import QubesVmCollection
from optparse import OptionParser; from optparse import OptionParser;
import subprocess import subprocess
import sys
qubes_guid_path = "/usr/bin/qubes_guid" qubes_guid_path = "/usr/bin/qubes_guid"
@ -41,13 +42,13 @@ def main():
vm = qvm_collection.get_vm_by_name(vmname) vm = qvm_collection.get_vm_by_name(vmname)
if vm is None: if vm is None:
print "A VM with the name '{0}' does not exist in the system.".format(vmname) print >> sys.stderr, "A VM with the name '{0}' does not exist in the system.".format(vmname)
exit(1) exit(1)
try: try:
vm.force_shutdown() vm.force_shutdown()
except (IOError, OSError) as err: except (IOError, OSError) as err:
print "ERROR: {0}".format(err) print >> sys.stderr, "ERROR: {0}".format(err)
exit (1) exit (1)

View File

@ -24,6 +24,7 @@ from qubes.qubes import QubesVmCollection
from qubes.qubes import QubesHost from qubes.qubes import QubesHost
from qubes.qubes import QubesException from qubes.qubes import QubesException
from optparse import OptionParser from optparse import OptionParser
import sys
fields = { fields = {
@ -201,6 +202,6 @@ def main():
try: try:
vm.verify_files() vm.verify_files()
except QubesException as err: except QubesException as err:
print "WARNING: VM '{0}' has corrupted files!".format(vm.name) print >> sys.stderr, "WARNING: VM '{0}' has corrupted files!".format(vm.name)
main() main()

View File

@ -24,6 +24,7 @@ from qubes.qubes import QubesVmCollection
from optparse import OptionParser from optparse import OptionParser
import subprocess import subprocess
import os import os
import sys
def main(): def main():
usage = "usage: %prog -l [options] <vm-name>\n"\ usage = "usage: %prog -l [options] <vm-name>\n"\
@ -43,7 +44,7 @@ def main():
vmname = args[0] vmname = args[0]
if options.do_list + options.do_add + options.do_delete > 1: if options.do_list + options.do_add + options.do_delete > 1:
print "Only one of -l -a -d is allowed!" print >> sys.stderr, "Only one of -l -a -d is allowed!"
exit (1) exit (1)
if options.do_add or options.do_delete: if options.do_add or options.do_delete:
@ -58,17 +59,17 @@ def main():
vm = qvm_collection.get_vm_by_name(vmname) vm = qvm_collection.get_vm_by_name(vmname)
if vm is None or vm.qid not in qvm_collection: if vm is None or vm.qid not in qvm_collection:
print "A VM with the name '{0}' does not exist in the system.".format(vmname) print >> sys.stderr, "A VM with the name '{0}' does not exist in the system.".format(vmname)
exit(1) exit(1)
if options.do_add: if options.do_add:
if len (args) < 2: if len (args) < 2:
print "You must specify the PCI device to add" print >> sys.stderr, "You must specify the PCI device to add"
exit (1) exit (1)
pci = args[1] pci = args[1]
if not os.path.exists('/sys/bus/pci/devices/0000:%s' % pci): if not os.path.exists('/sys/bus/pci/devices/0000:%s' % pci):
print "Invalid PCI device: %s" % pci print >> sys.stderr, "Invalid PCI device: %s" % pci
exit(1) exit(1)
if vm.pcidevs.count(pci) == 0: if vm.pcidevs.count(pci) == 0:
vm.pcidevs.append(pci) vm.pcidevs.append(pci)
@ -77,7 +78,7 @@ def main():
elif options.do_delete: elif options.do_delete:
if len (args) < 2: if len (args) < 2:
print "You must specify the PCI device to delete" print >> sys.stderr, "You must specify the PCI device to delete"
exit (1) exit (1)
pci = args[1] pci = args[1]

View File

@ -26,6 +26,7 @@ from qubes.qubes import qubes_kernels_base_dir
from optparse import OptionParser from optparse import OptionParser
import subprocess import subprocess
import os import os
import sys
def do_list(vm): def do_list(vm):
label_width = 18 label_width = 18
@ -69,13 +70,13 @@ def do_list(vm):
def set_label(vms, vm, args): def set_label(vms, vm, args):
if len (args) != 1: if len (args) != 1:
print "Missing label name argument!" print >> sys.stderr, "Missing label name argument!"
label = args[0] label = args[0]
if label not in QubesVmLabels: if label not in QubesVmLabels:
print "Wrong label name, supported values are the following:" print >> sys.stderr, "Wrong label name, supported values are the following:"
for l in QubesVmLabels.values(): for l in QubesVmLabels.values():
print "* {0}".format(l.name) print >> sys.stderr, "* {0}".format(l.name)
exit (1) exit (1)
vm.label = QubesVmLabels[label] vm.label = QubesVmLabels[label]
@ -83,29 +84,29 @@ def set_label(vms, vm, args):
def set_memory(vms, vm, args): def set_memory(vms, vm, args):
if len (args) != 1: if len (args) != 1:
print "Missing memory argument!" print >> sys.stderr, "Missing memory argument!"
vm.memory = int(args[0]) vm.memory = int(args[0])
def set_maxmem(vms, vm, args): def set_maxmem(vms, vm, args):
if len (args) != 1: if len (args) != 1:
print "Missing maxmem argument!" print >> sys.stderr, "Missing maxmem argument!"
vm.maxmem = int(args[0]) vm.maxmem = int(args[0])
def set_pcidevs(vms, vm, args): def set_pcidevs(vms, vm, args):
if len (args) != 1: if len (args) != 1:
print "Missing pcidevs argument!" print >> sys.stderr, "Missing pcidevs argument!"
vm.pcidevs = list(eval(args[0])) vm.pcidevs = list(eval(args[0]))
def set_netvm(vms, vm, args): def set_netvm(vms, vm, args):
if len (args) != 1: if len (args) != 1:
print "Missing netvm name argument!" print >> sys.stderr, "Missing netvm name argument!"
print "Possible values:" print >> sys.stderr, "Possible values:"
print "1) default" print >> sys.stderr, "1) default"
print "2) none" print >> sys.stderr, "2) none"
print "3) <vmaname>" print >> sys.stderr, "3) <vmaname>"
return return
netvm = args[0] netvm = args[0]
@ -118,10 +119,10 @@ def set_netvm(vms, vm, args):
else: else:
netvm_vm = vms.get_vm_by_name (netvm) netvm_vm = vms.get_vm_by_name (netvm)
if netvm_vm is None: if netvm_vm is None:
print "A VM with the name '{0}' does not exist in the system.".format(netvm) print >> sys.stderr, "A VM with the name '{0}' does not exist in the system.".format(netvm)
exit(1) exit(1)
if not netvm_vm.is_netvm(): if not netvm_vm.is_netvm():
print "VM '{0}' is not a NetVM".format(netvm) print >> sys.stderr, "VM '{0}' is not a NetVM".format(netvm)
exit (1) exit (1)
vm.uses_default_netvm = False vm.uses_default_netvm = False
@ -140,70 +141,70 @@ def set_netvm(vms, vm, args):
def set_updateable(vms, vm, args): def set_updateable(vms, vm, args):
if vm.is_updateable(): if vm.is_updateable():
print "VM '{0}' is already set 'updateable', no action required.".format(vm.name) print >> sys.stderr, "VM '{0}' is already set 'updateable', no action required.".format(vm.name)
return True return True
if vm.is_running(): if vm.is_running():
print "Cannot change 'updateable' attribute of a running VM. Shut it down first." print >> sys.stderr, "Cannot change 'updateable' attribute of a running VM. Shut it down first."
return False return False
if vm.is_appvm(): if vm.is_appvm():
# Check if the Template is *non* updateable... # Check if the Template is *non* updateable...
if not vm.template_vm.is_updateable(): if not vm.template_vm.is_updateable():
print "VM '{0}': Setting 'updateable' attribute to True.".format(vm.name) print >> sys.stderr, "VM '{0}': Setting 'updateable' attribute to True.".format(vm.name)
vm.set_updateable() vm.set_updateable()
else: else:
print "The Template VM ('{0}') is marked as 'updateable' itself!".format(vm.template_vm.name) print >> sys.stderr, "The Template VM ('{0}') is marked as 'updateable' itself!".format(vm.template_vm.name)
print "Cannot make the AppVM updateable too, as this might cause COW-backed storage incoherency." print >> sys.stderr, "Cannot make the AppVM updateable too, as this might cause COW-backed storage incoherency."
print "If you want to make this AppVM updateable, you must first make the Template VM nonupdateable." print >> sys.stderr, "If you want to make this AppVM updateable, you must first make the Template VM nonupdateable."
return False return False
if vm.is_template(): if vm.is_template():
# Make sure that all the AppVMs are non-updateable... # Make sure that all the AppVMs are non-updateable...
for appvm in vm.appvms.values(): for appvm in vm.appvms.values():
if appvm.is_updateable(): if appvm.is_updateable():
print "At least one of the AppVMs ('{0}') of this Template VM is also marked 'updateable'.".format(appvm.name) print >> sys.stderr, "At least one of the AppVMs ('{0}') of this Template VM is also marked 'updateable'.".format(appvm.name)
print "Cannot make the Template VM updateable too, as this might cause COW-backed storage incoherency." print >> sys.stderr, "Cannot make the Template VM updateable too, as this might cause COW-backed storage incoherency."
print "If you want to make this Template VM updateable, you must first make all its decedent AppVMs nonupdateable." print >> sys.stderr, "If you want to make this Template VM updateable, you must first make all its decedent AppVMs nonupdateable."
return False return False
print "VM '{0}': Setting 'updateable' attribute to True.".format(vm.name) print >> sys.stderr, "VM '{0}': Setting 'updateable' attribute to True.".format(vm.name)
vm.set_updateable() vm.set_updateable()
return True return True
def set_nonupdateable(vms, vm, args): def set_nonupdateable(vms, vm, args):
if not vm.is_updateable(): if not vm.is_updateable():
print "VM '{0}' is already set 'nonupdateable', no action required.".format(vm.name) print >> sys.stderr, "VM '{0}' is already set 'nonupdateable', no action required.".format(vm.name)
return True return True
if vm.is_running(): if vm.is_running():
print "Cannot change 'updateable' attribute of a running VM. Shut it down first." print >> sys.stderr, "Cannot change 'updateable' attribute of a running VM. Shut it down first."
return False return False
if vm.is_netvm(): if vm.is_netvm():
print "Why, on earth, would you want to make a NetVM 'nonupdateable'?" print >> sys.stderr, "Why, on earth, would you want to make a NetVM 'nonupdateable'?"
return False return False
print "VM '{0}': Setting 'updateable' attribute to False.".format(vm.name) print >> sys.stderr, "VM '{0}': Setting 'updateable' attribute to False.".format(vm.name)
vm.set_nonupdateable() vm.set_nonupdateable()
return True return True
def set_kernel(vms, vm, args): def set_kernel(vms, vm, args):
if vm.template_vm is not None: if vm.template_vm is not None:
print "Cannot set kernel for template-based VM. Set it for template instead." print >> sys.stderr, "Cannot set kernel for template-based VM. Set it for template instead."
return False return False
if len (args) != 1: if len (args) != 1:
print "Missing kernel version argument!" print >> sys.stderr, "Missing kernel version argument!"
print "Possible values:" print >> sys.stderr, "Possible values:"
print "1) default" print >> sys.stderr, "1) default"
print "2) none (kernels subdir in VM)" print >> sys.stderr, "2) none (kernels subdir in VM)"
print "3) <kernel version>, one of:" print >> sys.stderr, "3) <kernel version>, one of:"
for k in os.listdir(qubes_kernels_base_dir): for k in os.listdir(qubes_kernels_base_dir):
print " -", k print >> sys.stderr, " -", k
return return
kernel = args[0] kernel = args[0]
@ -215,7 +216,7 @@ def set_kernel(vms, vm, args):
vm.uses_default_kernel = False vm.uses_default_kernel = False
else: else:
if not os.path.exists(qubes_kernels_base_dir + '/' + kernel): if not os.path.exists(qubes_kernels_base_dir + '/' + kernel):
print "Kernel version {0} not installed.".format(kernel) print >> sys.stderr, "Kernel version {0} not installed.".format(kernel)
exit(1) exit(1)
vm.uses_default_kernel = False vm.uses_default_kernel = False
@ -223,48 +224,48 @@ def set_kernel(vms, vm, args):
def set_template(vms, vm, args): def set_template(vms, vm, args):
if len (args) != 1: if len (args) != 1:
print "Missing template name argument!" print >> sys.stderr, "Missing template name argument!"
return False return False
template_name = args[0]; template_name = args[0];
template_vm = vms.get_vm_by_name(template_name) template_vm = vms.get_vm_by_name(template_name)
if template_vm is None or template_vm.qid not in vms: if template_vm is None or template_vm.qid not in vms:
print "A VM with the name '{0}' does not exist in the system.".format(template_name) print >> sys.stderr, "A VM with the name '{0}' does not exist in the system.".format(template_name)
return False return False
if not template_vm.is_template(): if not template_vm.is_template():
print "VM '{0}' is not a TemplateVM".format(template_name) print >> sys.stderr, "VM '{0}' is not a TemplateVM".format(template_name)
return False return False
print "Setting template for VM '{0}' to '{1}'...".format (vm.name, template_name) print >> sys.stderr, "Setting template for VM '{0}' to '{1}'...".format (vm.name, template_name)
vm.template_vm = template_vm vm.template_vm = template_vm
return True return True
def set_vcpus(vms, vm, args): def set_vcpus(vms, vm, args):
if len (args) != 1: if len (args) != 1:
print "Missing vcpus count argument!" print >> sys.stderr, "Missing vcpus count argument!"
return False return False
vcpus = int(args[0]) vcpus = int(args[0])
if vcpus <= 0: if vcpus <= 0:
print "A vcpus count must be positive." print >> sys.stderr, "A vcpus count must be positive."
return False return False
qubes_host = QubesHost() qubes_host = QubesHost()
if vcpus > qubes_host.no_cpus: if vcpus > qubes_host.no_cpus:
print "This host has only {0} cpus".format(ubes_host.no_cpus) print >> sys.stderr, "This host has only {0} cpus".format(ubes_host.no_cpus)
return False return False
print "Setting vcpus count for VM '{0}' to '{1}'...".format (vm.name, vcpus) print >> sys.stderr, "Setting vcpus count for VM '{0}' to '{1}'...".format (vm.name, vcpus)
vm.vcpus = vcpus vm.vcpus = vcpus
return True return True
def set_kernelopts(vms, vm, args): def set_kernelopts(vms, vm, args):
if len (args) != 1: if len (args) != 1:
print "Missing kernel opts argument!" print >> sys.stderr, "Missing kernel opts argument!"
print "Possible values:" print >> sys.stderr, "Possible values:"
print "1) default" print >> sys.stderr, "1) default"
print "2) <opts>" print >> sys.stderr, "2) <opts>"
return False return False
if args[0] == 'default': if args[0] == 'default':
@ -292,7 +293,7 @@ properties = {
def do_set(vms, vm, property, args): def do_set(vms, vm, property, args):
if property not in properties.keys(): if property not in properties.keys():
print "ERROR: Wrong property name: '{0}'".format(property) print >> sys.stderr, "ERROR: Wrong property name: '{0}'".format(property)
return False return False
return properties[property](vms, vm, args) return properties[property](vms, vm, args)
@ -314,7 +315,7 @@ def main():
vmname = args[0] vmname = args[0]
if options.do_list and options.do_set: if options.do_list and options.do_set:
print "You cannot provide -l and -s at the same time!" print >> sys.stderr, "You cannot provide -l and -s at the same time!"
exit (1) exit (1)
@ -331,15 +332,15 @@ def main():
vm = qvm_collection.get_vm_by_name(vmname) vm = qvm_collection.get_vm_by_name(vmname)
if vm is None or vm.qid not in qvm_collection: if vm is None or vm.qid not in qvm_collection:
print "A VM with the name '{0}' does not exist in the system.".format(vmname) print >> sys.stderr, "A VM with the name '{0}' does not exist in the system.".format(vmname)
exit(1) exit(1)
if options.do_set: if options.do_set:
if len (args) < 2: if len (args) < 2:
print "You must specify the property you wish to set..." print >> sys.stderr, "You must specify the property you wish to set..."
print "Available properties:" print >> sys.stderr, "Available properties:"
for p in properties.keys(): for p in properties.keys():
print "--> '{0}'".format(p) print >> sys.stderr, "--> '{0}'".format(p)
exit (1) exit (1)
property = args[1] property = args[1]

View File

@ -23,6 +23,7 @@
from qubes.qubes import QubesVmCollection from qubes.qubes import QubesVmCollection
from optparse import OptionParser; from optparse import OptionParser;
import os import os
import sys
def main(): def main():
usage = "usage: %prog [options] <vm-name>" usage = "usage: %prog [options] <vm-name>"
@ -42,25 +43,25 @@ def main():
qvm_collection.load() qvm_collection.load()
vm = qvm_collection.get_vm_by_name(vmname) vm = qvm_collection.get_vm_by_name(vmname)
if vm is None or vm.qid not in qvm_collection: if vm is None or vm.qid not in qvm_collection:
print "A VM with the name '{0}' does not exist in the system.".format(vmname) print >> sys.stderr, "A VM with the name '{0}' does not exist in the system.".format(vmname)
exit(1) exit(1)
if os.geteuid() == 0: if os.geteuid() == 0:
print "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems." print >> sys.stderr, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems."
if options.force_root: if options.force_root:
print "Continuing as commanded. You have been warned." print >> sys.stderr, "Continuing as commanded. You have been warned."
else: else:
print "Retry as unprivileged user." print >> sys.stderr, "Retry as unprivileged user."
print "... or use --force-root to continue anyway." print >> sys.stderr, "... or use --force-root to continue anyway."
exit(1) exit(1)
if vm.is_template(): if vm.is_template():
dependent_vms = qvm_collection.get_vms_based_on(vm.qid) dependent_vms = qvm_collection.get_vms_based_on(vm.qid)
if len(dependent_vms) > 0: if len(dependent_vms) > 0:
print "The following AppVMs use '{0}' as a template:".format(vmname) print >> sys.stderr, "The following AppVMs use '{0}' as a template:".format(vmname)
for vm in dependent_vms: for vm in dependent_vms:
print "{name:<12} (qid={qid})".format(qid=vm.qid, name=vm.name) print >> sys.stderr, "{name:<12} (qid={qid})".format(qid=vm.qid, name=vm.name)
print "Please remove those VMs first." print >> sys.stderr, "Please remove those VMs first."
exit (1) exit (1)
if qvm_collection.default_template_qid == vm.qid: if qvm_collection.default_template_qid == vm.qid:
qvm_collection.default_template_qid = None qvm_collection.default_template_qid = None
@ -71,18 +72,18 @@ def main():
if vm.is_running(): if vm.is_running():
print "Cannot remove a running VM, stop it first" print >> sys.stderr, "Cannot remove a running VM, stop it first"
exit (1) exit (1)
if vm.installed_by_rpm and not options.remove_from_db_only: if vm.installed_by_rpm and not options.remove_from_db_only:
if options.verbose: if options.verbose:
print "This VM has been installed by RPM, use rpm -e <pkg name> to remove it!" print >> sys.stderr, "This VM has been installed by RPM, use rpm -e <pkg name> to remove it!"
exit (1) exit (1)
try: try:
if vm.installed_by_rpm: if vm.installed_by_rpm:
if options.verbose: if options.verbose:
print "--> VM installed by RPM, leaving all the files on disk" print >> sys.stderr, "--> VM installed by RPM, leaving all the files on disk"
else: else:
if options.verbose: if options.verbose:
print "--> Removing all the files on disk..." print "--> Removing all the files on disk..."
@ -92,7 +93,7 @@ def main():
except (IOError, OSError) as err: except (IOError, OSError) as err:
print "Warning: {0}".format(err) print >> sys.stderr, "Warning: {0}".format(err)
# Do not exit, perhaps the VM files were somehow removed # Do not exit, perhaps the VM files were somehow removed
# so just remove it from Qubes DB # so just remove it from Qubes DB

View File

@ -27,6 +27,7 @@ import subprocess
import os import os
import time import time
import glob import glob
import sys
def main(): def main():
usage = "usage: %prog [options] <template-name>" usage = "usage: %prog [options] <template-name>"
@ -40,7 +41,7 @@ def main():
vmname = args[0] vmname = args[0]
if os.geteuid() != 0: if os.geteuid() != 0:
print "ERROR: This tool must be run as root!" print >> sys.stderr, "ERROR: This tool must be run as root!"
exit(1) exit(1)
qvm_collection = QubesVmCollection() qvm_collection = QubesVmCollection()
@ -50,15 +51,15 @@ def main():
vm = qvm_collection.get_vm_by_name(vmname) vm = qvm_collection.get_vm_by_name(vmname)
if vm is None: if vm is None:
print "A VM with the name '{0}' does not exist in the system.".format(vmname) print >> sys.stderr, "A VM with the name '{0}' does not exist in the system.".format(vmname)
exit(1) exit(1)
if not vm.is_template(): if not vm.is_template():
print "A VM '{0}' is not template.".format(vmname) print >> sys.stderr, "A VM '{0}' is not template.".format(vmname)
exit(1) exit(1)
if vm.is_running(): if vm.is_running():
print "You must stop VM first." print >> sys.stderr, "You must stop VM first."
exit(1) exit(1)
oldcow_img = vm.rootcow_img + '.old' oldcow_img = vm.rootcow_img + '.old'
@ -76,7 +77,7 @@ def main():
if dev == old_dmdev: if dev == old_dmdev:
snapshot_present = True snapshot_present = True
else: else:
print "ERROR: You must shutdown all VMs running system older/newer than last good one." print >> sys.stderr, "ERROR: You must shutdown all VMs running system older/newer than last good one."
exit(1) exit(1)
root_blocks = os.path.getsize(vm.root_img)/512 root_blocks = os.path.getsize(vm.root_img)/512
@ -86,7 +87,7 @@ def main():
stdout=subprocess.PIPE) stdout=subprocess.PIPE)
result = p.communicate() result = p.communicate()
if result[0].strip() != old_dmdev: if result[0].strip() != old_dmdev:
print "ERROR: Cannot create snapshot device ({0} != {1})".format( print >> sys.stderr, "ERROR: Cannot create snapshot device ({0} != {1})".format(
result[0].strip(), old_dmdev) result[0].strip(), old_dmdev)
exit(1) exit(1)
@ -102,7 +103,7 @@ def main():
dm_table = result[0] dm_table = result[0]
dm_table_elements = dm_table.split(' ') dm_table_elements = dm_table.split(' ')
if dm_table_elements[2] != 'snapshot': if dm_table_elements[2] != 'snapshot':
print "ERROR: Unexpected device-mapper type ({0}). Template changes reverting already running".format(dm_table_elements[2]) print >> sys.stderr, "ERROR: Unexpected device-mapper type ({0}). Template changes reverting already running".format(dm_table_elements[2])
exit(1) exit(1)
dm_table_elements[2] = 'snapshot-merge' dm_table_elements[2] = 'snapshot-merge'

View File

@ -29,6 +29,7 @@ import socket
import errno import errno
import dbus import dbus
import time import time
import sys
import os import os
import os.path import os.path
@ -59,18 +60,18 @@ def actually_execute(domid, cmd, options):
def start_guid(vm, options): def start_guid(vm, options):
if options.verbose: if options.verbose:
print "--> Starting Qubes GUId..." print >> sys.stderr, "--> Starting Qubes GUId..."
xid = vm.get_xid() xid = vm.get_xid()
retcode = subprocess.call ([qubes_guid_path, "-d", str(xid), "-c", vm.label.color, "-i", vm.label.icon, "-l", str(vm.label.index)]) retcode = subprocess.call ([qubes_guid_path, "-d", str(xid), "-c", vm.label.color, "-i", vm.label.icon, "-l", str(vm.label.index)])
if (retcode != 0) : if (retcode != 0) :
print "ERROR: Cannot start qubes_guid!" print >> sys.stderr, "ERROR: Cannot start qubes_guid!"
if options.tray: if options.tray:
tray_notify_error ("ERROR: Cannot start qubes_guid!") tray_notify_error ("ERROR: Cannot start qubes_guid!")
exit (1) exit (1)
if options.verbose: if options.verbose:
print "--> Waiting for qubes-session..." print >> sys.stderr, "--> Waiting for qubes-session..."
subprocess.call([qrexec_client_path, "-d", str(xid), "user:echo $$ >> /tmp/qubes-session-waiter; [ ! -f /tmp/qubes-session-env ] && exec sleep 365d"]) subprocess.call([qrexec_client_path, "-d", str(xid), "user:echo $$ >> /tmp/qubes-session-waiter; [ ! -f /tmp/qubes-session-env ] && exec sleep 365d"])
@ -78,44 +79,44 @@ def start_guid(vm, options):
def vm_run_cmd(vm, cmd, options): def vm_run_cmd(vm, cmd, options):
if options.shutdown: if options.shutdown:
if options.verbose: if options.verbose:
print "Shutting down VM: '{0}'...".format(vm.name) print >> sys.stderr, "Shutting down VM: '{0}'...".format(vm.name)
subprocess.call (["/usr/sbin/xl", "shutdown", vm.name]) subprocess.call (["/usr/sbin/xl", "shutdown", vm.name])
return return
if options.pause: if options.pause:
if options.verbose: if options.verbose:
print "Pausing VM: '{0}'...".format(vm.name) print >> sys.stderr, "Pausing VM: '{0}'...".format(vm.name)
subprocess.call (["/usr/sbin/xl", "pause", vm.name]) subprocess.call (["/usr/sbin/xl", "pause", vm.name])
return return
if options.unpause: if options.unpause:
if options.verbose: if options.verbose:
print "UnPausing VM: '{0}'...".format(vm.name) print >> sys.stderr, "UnPausing VM: '{0}'...".format(vm.name)
subprocess.call (["/usr/sbin/xl", "unpause", vm.name]) subprocess.call (["/usr/sbin/xl", "unpause", vm.name])
return return
if options.verbose: if options.verbose:
print "Running command on VM: '{0}'...".format(vm.name) print >> sys.stderr, "Running command on VM: '{0}'...".format(vm.name)
if not vm.is_running(): if not vm.is_running():
if not options.auto: if not options.auto:
print "VM '{0}' is not running. Please start it first or use the '--auto' switch".format(vm.name) print >> sys.stderr, "VM '{0}' is not running. Please start it first or use the '--auto' switch".format(vm.name)
exit (1) exit (1)
try: try:
if options.verbose: if options.verbose:
print "Starting the VM '{0}'...".format(vm.name) print >> sys.stderr, "Starting the VM '{0}'...".format(vm.name)
if options.tray: if options.tray:
tray_notify ("Starting the '{0}' VM...".format(vm.name), label=vm.label) tray_notify ("Starting the '{0}' VM...".format(vm.name), label=vm.label)
xid = vm.start(verbose=options.verbose) xid = vm.start(verbose=options.verbose)
except (IOError, OSError, QubesException) as err: except (IOError, OSError, QubesException) as err:
print "ERROR: {0}".format(err) print >> sys.stderr, "ERROR: {0}".format(err)
if options.tray: if options.tray:
tray_notify_error ("Error while starting the '{0}' VM: {1}".format(vm.name, err)) tray_notify_error ("Error while starting the '{0}' VM: {1}".format(vm.name, err))
exit (1) exit (1)
except (MemoryError) as err: except (MemoryError) as err:
print "ERROR: {0}".format(err) print >> sys.stderr, "ERROR: {0}".format(err)
print "Close one or more running VMs and try again." print >> sys.stderr, "Close one or more running VMs and try again."
if options.tray: if options.tray:
subprocess.call(["kdialog", "--error", "Not enough memory to start '{0}' VM! Close one or more running VMs and try again.".format(vm.name)]) subprocess.call(["kdialog", "--error", "Not enough memory to start '{0}' VM! Close one or more running VMs and try again.".format(vm.name)])
exit (1) exit (1)
@ -218,7 +219,7 @@ def main():
else: else:
vm = qvm_collection.get_vm_by_name(vmname) vm = qvm_collection.get_vm_by_name(vmname)
if vm is None: if vm is None:
print "A VM with the name '{0}' does not exist in the system!".format(vmname) print >> sys.stderr, "A VM with the name '{0}' does not exist in the system!".format(vmname)
exit(1) exit(1)
vms_list.append(vm) vms_list.append(vm)
@ -226,9 +227,9 @@ def main():
if options.shutdown and vm.is_netvm(): if options.shutdown and vm.is_netvm():
connected_vms = [vm for vm in qvm_collection.get_vms_connected_to(vm.qid) if vm.is_running()] connected_vms = [vm for vm in qvm_collection.get_vms_connected_to(vm.qid) if vm.is_running()]
if connected_vms and not options.force: if connected_vms and not options.force:
print "ERROR: There are other VMs connected to this VM, " print >> sys.stderr, "ERROR: There are other VMs connected to this VM, "
print " shutdown them first or use --force option" print >> sys.stderr, " shutdown them first or use --force option"
print "VMs list: " + str([vm.name for vm in connected_vms]) print >> sys.stderr, "VMs list: " + str([vm.name for vm in connected_vms])
exit(1) exit(1)
if takes_cmd_argument: if takes_cmd_argument:
@ -242,19 +243,19 @@ def main():
if options.wait_for_shutdown: if options.wait_for_shutdown:
if options.verbose: if options.verbose:
print "Waiting for the VM(s) to shutdown..." print >> sys.stderr, "Waiting for the VM(s) to shutdown..."
shutdown_counter = 0 shutdown_counter = 0
while len (vms_list): while len (vms_list):
if options.verbose: if options.verbose:
print "Waiting for VMs: ", [vm.name for vm in vms_list] print >> sys.stderr, "Waiting for VMs: ", [vm.name for vm in vms_list]
for vm in vms_list: for vm in vms_list:
if not vm.is_running(): if not vm.is_running():
vms_list.remove (vm) vms_list.remove (vm)
if shutdown_counter > shutdown_counter_max: if shutdown_counter > shutdown_counter_max:
# kill the VM # kill the VM
if options.verbose: if options.verbose:
print "Killing the (apparently hanging) VM '{0}'...".format(vm.name) print >> sys.stderr, "Killing the (apparently hanging) VM '{0}'...".format(vm.name)
vm.force_shutdown() vm.force_shutdown()
#vms_list.remove(vm) #vms_list.remove(vm)
@ -264,7 +265,7 @@ def main():
retcode = subprocess.call([qubes_clipd_path]) retcode = subprocess.call([qubes_clipd_path])
if retcode != 0: if retcode != 0:
print "ERROR: Cannot start qclipd!" print >> sys.stderr, "ERROR: Cannot start qclipd!"
if options.tray: if options.tray:
tray_notify ("ERROR: Cannot start the Qubes Clipboard Notifier!") tray_notify ("ERROR: Cannot start the Qubes Clipboard Notifier!")

View File

@ -22,6 +22,7 @@
from qubes.qubes import QubesVmCollection from qubes.qubes import QubesVmCollection
from optparse import OptionParser; from optparse import OptionParser;
import sys
def main(): def main():
usage = "usage: %prog <vm-name>" usage = "usage: %prog <vm-name>"
@ -36,7 +37,7 @@ def main():
qvm_collection.load() qvm_collection.load()
vm = qvm_collection.get_vm_by_name(vmname) vm = qvm_collection.get_vm_by_name(vmname)
if vm is None or vm.qid not in qvm_collection: if vm is None or vm.qid not in qvm_collection:
print "A VM with the name '{0}' does not exist in the system.".format(vmname) print >> sys.stderr, "A VM with the name '{0}' does not exist in the system.".format(vmname)
exit(1) exit(1)
qvm_collection.set_clockvm_vm(vm) qvm_collection.set_clockvm_vm(vm)

View File

@ -23,6 +23,7 @@
from qubes.qubes import QubesVmCollection, qubes_kernels_base_dir from qubes.qubes import QubesVmCollection, qubes_kernels_base_dir
from optparse import OptionParser; from optparse import OptionParser;
import os import os
import sys
def main(): def main():
usage = "usage: %prog <kernel>" usage = "usage: %prog <kernel>"
@ -33,7 +34,7 @@ def main():
kernel = args[0] kernel = args[0]
if not os.path.exists(qubes_kernels_base_dir + "/" + kernel): if not os.path.exists(qubes_kernels_base_dir + "/" + kernel):
print "Kernel {0} not installed".format(kernel) print >> sys.stderr, "Kernel {0} not installed".format(kernel)
exit(1) exit(1)
qvm_collection = QubesVmCollection() qvm_collection = QubesVmCollection()

View File

@ -22,6 +22,7 @@
from qubes.qubes import QubesVmCollection from qubes.qubes import QubesVmCollection
from optparse import OptionParser; from optparse import OptionParser;
import sys
def main(): def main():
usage = "usage: %prog <netvm-name>" usage = "usage: %prog <netvm-name>"
@ -36,11 +37,11 @@ def main():
qvm_collection.load() qvm_collection.load()
vm = qvm_collection.get_vm_by_name(vmname) vm = qvm_collection.get_vm_by_name(vmname)
if vm is None or vm.qid not in qvm_collection: if vm is None or vm.qid not in qvm_collection:
print "A VM with the name '{0}' does not exist in the system.".format(vmname) print >> sys.stderr, "A VM with the name '{0}' does not exist in the system.".format(vmname)
exit(1) exit(1)
if not vm.is_netvm(): if not vm.is_netvm():
print "VM '{0}' is not a NetVM".format(vmname) print >> sys.stderr, "VM '{0}' is not a NetVM".format(vmname)
exit (1) exit (1)
qvm_collection.set_default_netvm_vm(vm) qvm_collection.set_default_netvm_vm(vm)

View File

@ -22,6 +22,7 @@
from qubes.qubes import QubesVmCollection from qubes.qubes import QubesVmCollection
from optparse import OptionParser; from optparse import OptionParser;
import sys
def main(): def main():
usage = "usage: %prog <template-vm-name>" usage = "usage: %prog <template-vm-name>"
@ -36,11 +37,11 @@ def main():
qvm_collection.load() qvm_collection.load()
vm = qvm_collection.get_vm_by_name(vmname) vm = qvm_collection.get_vm_by_name(vmname)
if vm is None or vm.qid not in qvm_collection: if vm is None or vm.qid not in qvm_collection:
print "A VM with the name '{0}' does not exist in the system.".format(vmname) print >> sys.stderr, "A VM with the name '{0}' does not exist in the system.".format(vmname)
exit(1) exit(1)
if not vm.is_template(): if not vm.is_template():
print "VM '{0}' is not a TemplateVM".format(vmname) print >> sys.stderr, "VM '{0}' is not a TemplateVM".format(vmname)
exit (1) exit (1)
qvm_collection.set_default_template_vm(vm) qvm_collection.set_default_template_vm(vm)

View File

@ -22,6 +22,7 @@
from qubes.qubes import QubesVmCollection from qubes.qubes import QubesVmCollection
from optparse import OptionParser; from optparse import OptionParser;
import sys
def main(): def main():
usage = "usage: %prog <vm-name>" usage = "usage: %prog <vm-name>"
@ -36,7 +37,7 @@ def main():
qvm_collection.load() qvm_collection.load()
vm = qvm_collection.get_vm_by_name(vmname) vm = qvm_collection.get_vm_by_name(vmname)
if vm is None or vm.qid not in qvm_collection: if vm is None or vm.qid not in qvm_collection:
print "A VM with the name '{0}' does not exist in the system.".format(vmname) print >> sys.stderr, "A VM with the name '{0}' does not exist in the system.".format(vmname)
exit(1) exit(1)
qvm_collection.set_updatevm_vm(vm) qvm_collection.set_updatevm_vm(vm)

View File

@ -25,6 +25,7 @@ from qubes.qubes import QubesException
from optparse import OptionParser from optparse import OptionParser
import subprocess import subprocess
import os import os
import sys
qubes_guid_path = "/usr/bin/qubes_guid" qubes_guid_path = "/usr/bin/qubes_guid"
@ -51,23 +52,23 @@ def main():
vm = qvm_collection.get_vm_by_name(vmname) vm = qvm_collection.get_vm_by_name(vmname)
if vm is None: if vm is None:
print "A VM with the name '{0}' does not exist in the system.".format(vmname) print >> sys.stderr, "A VM with the name '{0}' does not exist in the system.".format(vmname)
exit(1) exit(1)
try: try:
vm.verify_files() vm.verify_files()
xid = vm.start(debug_console=options.debug_console, verbose=options.verbose, preparing_dvm=options.preparing_dvm) xid = vm.start(debug_console=options.debug_console, verbose=options.verbose, preparing_dvm=options.preparing_dvm)
except (IOError, OSError, QubesException) as err: except (IOError, OSError, QubesException) as err:
print "ERROR: {0}".format(err) print >> sys.stderr, "ERROR: {0}".format(err)
exit (1) exit (1)
if not options.noguid and os.getenv("DISPLAY") is not None: if not options.noguid and os.getenv("DISPLAY") is not None:
if options.verbose: if options.verbose:
print "--> Starting Qubes GUId..." print >> sys.stderr, "--> Starting Qubes GUId..."
retcode = subprocess.call ([qubes_guid_path, "-d", str(xid), "-c", vm.label.color, "-i", vm.label.icon, "-l", str(vm.label.index)]) retcode = subprocess.call ([qubes_guid_path, "-d", str(xid), "-c", vm.label.color, "-i", vm.label.icon, "-l", str(vm.label.index)])
if (retcode != 0) : if (retcode != 0) :
print "ERROR: Cannot start qubes_guid!" print >> sys.stderr, "ERROR: Cannot start qubes_guid!"
exit (1) exit (1)

View File

@ -192,25 +192,25 @@ def main():
# Create new/update existing templates # Create new/update existing templates
if options.verbose: if options.verbose:
print "--> Got {0} appmenus, storing to disk".format(str(len(new_appmenus))) print >> sys.stderr, "--> Got {0} appmenus, storing to disk".format(str(len(new_appmenus)))
for appmenu_file in new_appmenus.keys(): for appmenu_file in new_appmenus.keys():
if options.verbose: if options.verbose:
if os.path.exists(vm.appmenus_templates_dir + '/' + appmenu_file): if os.path.exists(vm.appmenus_templates_dir + '/' + appmenu_file):
print "---> Updating {0}".format(appmenu_file) print >> sys.stderr, "---> Updating {0}".format(appmenu_file)
else: else:
print "---> Creating {0}".format(appmenu_file) print >> sys.stderr, "---> Creating {0}".format(appmenu_file)
create_template(vm.appmenus_templates_dir + '/' + appmenu_file, new_appmenus[appmenu_file]) create_template(vm.appmenus_templates_dir + '/' + appmenu_file, new_appmenus[appmenu_file])
# Delete appmenus of remove applications # Delete appmenus of remove applications
if options.verbose: if options.verbose:
print "--> Cleaning old files" print >> sys.stderr, "--> Cleaning old files"
for appmenu_file in os.listdir(vm.appmenus_templates_dir): for appmenu_file in os.listdir(vm.appmenus_templates_dir):
if not fnmatch.fnmatch(appmenu_file, '*.desktop'): if not fnmatch.fnmatch(appmenu_file, '*.desktop'):
continue continue
if not new_appmenus.has_key(appmenu_file): if not new_appmenus.has_key(appmenu_file):
if options.verbose: if options.verbose:
print "---> Removing {0}".format(appmenu_file) print >> sys.stderr, "---> Removing {0}".format(appmenu_file)
os.unlink(vm.appmenus_templates_dir + '/' + appmenu_file) os.unlink(vm.appmenus_templates_dir + '/' + appmenu_file)
main() main()

View File

@ -10,7 +10,7 @@ if [ -z "$CLOCK_VM" ]; then
fi fi
if ! xl domid "$CLOCK_VM" > /dev/null 2>&1; then if ! xl domid "$CLOCK_VM" > /dev/null 2>&1; then
echo "ClockVM not started, exiting!" echo "ClockVM not started, exiting!" >&2
exit 1 exit 1
fi fi
@ -27,8 +27,8 @@ CURRENT_TIME="$($QREXEC_CLIENT -d $CLOCK_VM 'user:date -u' |
if [ -n "$CURRENT_TIME" ] ; then if [ -n "$CURRENT_TIME" ] ; then
echo Syncing Dom0 clock: setting time "$CURRENT_TIME"... echo Syncing Dom0 clock: setting time "$CURRENT_TIME"...
sudo date -u -s "$CURRENT_TIME" ; sudo date -u -s "$CURRENT_TIME" ;
echo Done. echo Done. >&2
else else
echo "Error while parsing the time obtained from the ClockVM ($CLOCK_VM).." echo "Error while parsing the time obtained from the ClockVM ($CLOCK_VM).." >&2
fi fi

View File

@ -24,6 +24,7 @@ from qubes.qubes import QubesVmCollection
from qubes.qubes import QubesException from qubes.qubes import QubesException
from optparse import OptionParser from optparse import OptionParser
import subprocess import subprocess
import sys
qubes_guid_path = "/usr/bin/qubes_guid" qubes_guid_path = "/usr/bin/qubes_guid"
@ -43,22 +44,22 @@ def main():
vm = qvm_collection.get_vm_by_name(vmname) vm = qvm_collection.get_vm_by_name(vmname)
if vm is None: if vm is None:
print "A VM with the name '{0}' does not exist in the system.".format(vmname) print >> sys.stderr, "A VM with the name '{0}' does not exist in the system.".format(vmname)
exit(1) exit(1)
if not vm.is_template(): if not vm.is_template():
print "A VM '{0}' is not template.".format(vmname) print >> sys.stderr, "A VM '{0}' is not template.".format(vmname)
exit(1) exit(1)
if vm.is_running(): if vm.is_running():
print "You must stop VM first." print >> sys.stderr, "You must stop VM first."
exit(1) exit(1)
try: try:
vm.verify_files() vm.verify_files()
vm.commit_changes() vm.commit_changes()
except (IOError, OSError, QubesException) as err: except (IOError, OSError, QubesException) as err:
print "ERROR: {0}".format(err) print >> sys.stderr, "ERROR: {0}".format(err)
exit (1) exit (1)
exit (0) exit (0)