def check_prompt_root_pw():
if not cfg.opts.root_password:
if stdout.isatty():
# If have tty, prompt for pass
while True:
passwd = raw_input(c.CYAN("Enter root password for new VM or enter '") + c.BOLD("random") + c.CYAN("' or '") + c.BOLD("disabled") + c.CYAN("' or file path : "))
if passwd:
break
cfg.opts.root_password = ''
if passwd == 'random':
c.verbose("Password for root will be randomly generated")
elif passwd == 'disabled':
c.verbose("Password auth for root will be disabled")
elif os.path.isfile(os.path.expanduser(passwd)):
passwd = os.path.expanduser(passwd)
c.verbose("Password for root will be set by reading first line of file '{}'".format(passwd))
cfg.opts.root_password = 'file:'
else:
c.verbose("Password for root will be set to string '{}'".format(passwd))
cfg.opts.root_password = 'password:'
cfg.opts.root_password += passwd
save_passwd = raw_input(c.CYAN("Save password choice as default to '{}'? ".format(cfg.cfgfileUser)) + c.BOLD("[y]/n") + c.CYAN(" : "))
if save_passwd != 'n':
subprocess.call(['mkdir', '-p', os.path.dirname(os.path.expanduser(cfg.cfgfileUser))])
with open(os.path.expanduser(cfg.cfgfileUser), 'a+') as f:
f.write('# Added by {}:\nroot-password = {}\n'.format(cfg.prog, cfg.opts.root_password))
c.verbose("Wrote 'root-password = {}' to {}".format(cfg.opts.root_password, cfg.cfgfileUser))
else:
print(c.RED("No root password specified; aborting"))
print("Either run with stdin/stdout connected to tty to interactively enter password or\n"
" Use '--root-password password:PASSWORDSTRING' or\n"
" Use '--root-password file:PASSWORDFILE' or\n"
" Use '--root-password random'\n"
" Note that any of these can be specified in config file as well")
exit(1)
评论列表
文章目录