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 844d43b0ef
commit 8bdc5706f7
3 changed files with 21 additions and 8 deletions

View File

@ -251,6 +251,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 ' + \
@ -267,7 +268,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']:
@ -2540,7 +2542,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" )
"mac", "services", "include_in_backups", "debug", "default_user" )
for attribute in common_attr_list:
kwargs[attribute] = element.get(attribute)

View File

@ -76,6 +76,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))
def set_label(vms, vm, args):
if len (args) != 1:
print >> sys.stderr, "Missing label name argument!"
@ -283,7 +286,14 @@ def set_debug(vms, vm, args):
vm.debug = False
else:
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_include_in_backups(vms, vm, args):
@ -308,6 +318,7 @@ properties = {
"name": set_name,
"mac": set_mac,
"debug": set_debug,
"default_user": set_default_user,
}

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)
for vm in vms_list:
if takes_cmd_argument:
cmd = "{user}:{cmd}".format(user=options.user, cmd=cmdstr)
cmd = "{user}:{cmd}".format(user=options.user if options.user else vm.default_user, cmd=cmdstr)
else:
cmd = None
for vm in vms_list:
vm_run_cmd(vm, cmd, options)