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:
parent
844d43b0ef
commit
8bdc5706f7
@ -251,6 +251,7 @@ class QubesVm(object):
|
|||||||
"include_in_backups": { "default": True },
|
"include_in_backups": { "default": True },
|
||||||
"services": { "default": {}, "eval": "eval(str(value))" },
|
"services": { "default": {}, "eval": "eval(str(value))" },
|
||||||
"debug": { "default": False },
|
"debug": { "default": False },
|
||||||
|
"default_user": { "default": "user" },
|
||||||
##### Internal attributes - will be overriden in __init__ regardless of args
|
##### Internal attributes - will be overriden in __init__ regardless of args
|
||||||
"appmenus_templates_dir": { "eval": \
|
"appmenus_templates_dir": { "eval": \
|
||||||
'self.dir_path + "/" + default_appmenus_templates_subdir if self.updateable else ' + \
|
'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',\
|
for prop in ['qid', 'name', 'dir_path', 'memory', 'maxmem', 'pcidevs', 'vcpus', 'internal',\
|
||||||
'uses_default_kernel', 'kernel', 'uses_default_kernelopts',\
|
'uses_default_kernel', 'kernel', 'uses_default_kernelopts',\
|
||||||
'kernelopts', 'services', 'installed_by_rpm',\
|
'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
|
attrs[prop]['save'] = 'str(self.%s)' % prop
|
||||||
# Simple paths
|
# Simple paths
|
||||||
for prop in ['conf_file', 'root_img', 'volatile_img', 'private_img']:
|
for prop in ['conf_file', 'root_img', 'volatile_img', 'private_img']:
|
||||||
@ -2540,7 +2542,7 @@ class QubesVmCollection(dict):
|
|||||||
"installed_by_rpm", "internal",
|
"installed_by_rpm", "internal",
|
||||||
"uses_default_netvm", "label", "memory", "vcpus", "pcidevs",
|
"uses_default_netvm", "label", "memory", "vcpus", "pcidevs",
|
||||||
"maxmem", "kernel", "uses_default_kernel", "kernelopts", "uses_default_kernelopts",
|
"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:
|
for attribute in common_attr_list:
|
||||||
kwargs[attribute] = element.get(attribute)
|
kwargs[attribute] = element.get(attribute)
|
||||||
|
@ -76,6 +76,9 @@ def do_list(vm):
|
|||||||
if hasattr(vm, 'debug'):
|
if hasattr(vm, 'debug'):
|
||||||
print fmt.format("debug", "on" if vm.debug else "off")
|
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):
|
def set_label(vms, vm, args):
|
||||||
if len (args) != 1:
|
if len (args) != 1:
|
||||||
print >> sys.stderr, "Missing label name argument!"
|
print >> sys.stderr, "Missing label name argument!"
|
||||||
@ -283,7 +286,14 @@ def set_debug(vms, vm, args):
|
|||||||
vm.debug = False
|
vm.debug = False
|
||||||
else:
|
else:
|
||||||
vm.debug = bool(eval(args[0].capitalize()))
|
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
|
return True
|
||||||
|
|
||||||
def set_include_in_backups(vms, vm, args):
|
def set_include_in_backups(vms, vm, args):
|
||||||
@ -308,6 +318,7 @@ properties = {
|
|||||||
"name": set_name,
|
"name": set_name,
|
||||||
"mac": set_mac,
|
"mac": set_mac,
|
||||||
"debug": set_debug,
|
"debug": set_debug,
|
||||||
|
"default_user": set_default_user,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ def main():
|
|||||||
parser.add_option ("-q", "--quiet", action="store_false", dest="verbose", default=True)
|
parser.add_option ("-q", "--quiet", action="store_false", dest="verbose", default=True)
|
||||||
parser.add_option ("-a", "--auto", action="store_true", dest="auto", default=False,
|
parser.add_option ("-a", "--auto", action="store_true", dest="auto", default=False,
|
||||||
help="Auto start the VM if not running")
|
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")
|
help="Run command in a VM as a specified user")
|
||||||
parser.add_option ("--tray", action="store_true", dest="tray", default=False,
|
parser.add_option ("--tray", action="store_true", dest="tray", default=False,
|
||||||
help="Use tray notifications instead of stdout" )
|
help="Use tray notifications instead of stdout" )
|
||||||
@ -188,12 +188,12 @@ def main():
|
|||||||
exit(1)
|
exit(1)
|
||||||
vms_list.append(vm)
|
vms_list.append(vm)
|
||||||
|
|
||||||
|
for vm in vms_list:
|
||||||
if takes_cmd_argument:
|
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:
|
else:
|
||||||
cmd = None
|
cmd = None
|
||||||
|
|
||||||
for vm in vms_list:
|
|
||||||
vm_run_cmd(vm, cmd, options)
|
vm_run_cmd(vm, cmd, options)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user