dom0/core: allow to change default user for qvm-run (#577)

This doesn't make all dom0 code VM-username independent, still 'user' is
hardcoded in many places. This only change behavior of qvm-run, especially for use in HVM.
This commit is contained in:
Marek Marczykowski 2012-06-13 17:16:12 +02:00
parent e6a75c732e
commit 6bd988bf81
3 changed files with 22 additions and 8 deletions

View File

@ -259,6 +259,7 @@ class QubesVm(object):
"include_in_backups": { "default": True },
"services": { "default": {}, "eval": "eval(str(value))" },
"debug": { "default": False },
"default_user": { "default": "user" },
##### Internal attributes - will be overriden in __init__ regardless of args
"appmenus_templates_dir": { "eval": \
'self.dir_path + "/" + default_appmenus_templates_subdir if self.updateable else ' + \
@ -276,7 +277,8 @@ class QubesVm(object):
for prop in ['qid', 'name', 'dir_path', 'memory', 'maxmem', 'pcidevs', 'vcpus', 'internal',\
'uses_default_kernel', 'kernel', 'uses_default_kernelopts',\
'kernelopts', 'services', 'installed_by_rpm',\
'uses_default_netvm', 'include_in_backups', 'debug' ]:
'uses_default_netvm', 'include_in_backups', 'debug',\
'default_user' ]:
attrs[prop]['save'] = 'str(self.%s)' % prop
# Simple paths
for prop in ['conf_file', 'root_img', 'volatile_img', 'private_img']:
@ -2815,7 +2817,7 @@ class QubesVmCollection(dict):
"installed_by_rpm", "internal",
"uses_default_netvm", "label", "memory", "vcpus", "pcidevs",
"maxmem", "kernel", "uses_default_kernel", "kernelopts", "uses_default_kernelopts",
"mac", "services", "include_in_backups", "debug", "qrexec_installed", "drive" )
"mac", "services", "include_in_backups", "debug", "default_user", "qrexec_installed", "drive" )
for attribute in common_attr_list:
kwargs[attribute] = element.get(attribute)

View File

@ -78,6 +78,9 @@ def do_list(vm):
if hasattr(vm, 'debug'):
print fmt.format("debug", "on" if vm.debug else "off")
if hasattr(vm, 'default_user'):
print fmt.format("default user", str(vm.default_user))
if hasattr(vm, 'qrexec_installed'):
print fmt.format("qrexec_installed", str(vm.qrexec_installed))
@ -314,6 +317,14 @@ def set_debug(vms, vm, args):
vm.debug = bool(eval(args[0].capitalize()))
return True
def set_default_user(vms, vm, args):
if len (args) != 1:
print >> sys.stderr, "Missing user name!"
return False
vm.default_user = args[0]
return True
def set_qrexec_installed(vms, vm, args):
if len (args) != 1:
print >> sys.stderr, "Missing value (True/False)!"
@ -349,6 +360,7 @@ properties = {
"drive": set_drive,
"mac": set_mac,
"debug": set_debug,
"default_user": set_default_user,
"qrexec_installed": set_qrexec_installed,
"timezone": set_timezone,
}

View File

@ -98,7 +98,7 @@ def main():
parser.add_option ("-q", "--quiet", action="store_false", dest="verbose", default=True)
parser.add_option ("-a", "--auto", action="store_true", dest="auto", default=False,
help="Auto start the VM if not running")
parser.add_option ("-u", "--user", action="store", dest="user", default="user",
parser.add_option ("-u", "--user", action="store", dest="user", default=None,
help="Run command in a VM as a specified user")
parser.add_option ("--tray", action="store_true", dest="tray", default=False,
help="Use tray notifications instead of stdout" )
@ -188,12 +188,12 @@ def main():
exit(1)
vms_list.append(vm)
if takes_cmd_argument:
cmd = "{user}:{cmd}".format(user=options.user, cmd=cmdstr)
else:
cmd = None
for vm in vms_list:
if takes_cmd_argument:
cmd = "{user}:{cmd}".format(user=options.user if options.user else vm.default_user, cmd=cmdstr)
else:
cmd = None
vm_run_cmd(vm, cmd, options)