diff options
Diffstat (limited to 'cloudinit/CloudConfig/cc_set_passwords.py')
-rw-r--r-- | cloudinit/CloudConfig/cc_set_passwords.py | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/cloudinit/CloudConfig/cc_set_passwords.py b/cloudinit/CloudConfig/cc_set_passwords.py index 07e3ca1b..15533460 100644 --- a/cloudinit/CloudConfig/cc_set_passwords.py +++ b/cloudinit/CloudConfig/cc_set_passwords.py @@ -21,14 +21,14 @@ import sys import random import string -def handle(_name,cfg,_cloud,log,args): +def handle(_name, cfg, _cloud, log, args): if len(args) != 0: # if run from command line, and give args, wipe the chpasswd['list'] password = args[0] if 'chpasswd' in cfg and 'list' in cfg['chpasswd']: del cfg['chpasswd']['list'] else: - password = util.get_cfg_option_str(cfg,"password",None) + password = util.get_cfg_option_str(cfg, "password", None) expire = True pw_auth = "no" @@ -37,11 +37,11 @@ def handle(_name,cfg,_cloud,log,args): if 'chpasswd' in cfg: chfg = cfg['chpasswd'] - plist = util.get_cfg_option_str(chfg,'list',plist) - expire = util.get_cfg_option_bool(chfg,'expire', expire) + plist = util.get_cfg_option_str(chfg, 'list', plist) + expire = util.get_cfg_option_bool(chfg, 'expire', expire) if not plist and password: - user = util.get_cfg_option_str(cfg,"user","ubuntu") + user = util.get_cfg_option_str(cfg, "user", "ubuntu") plist = "%s:%s" % (user, password) errors = [] @@ -50,11 +50,11 @@ def handle(_name,cfg,_cloud,log,args): randlist = [] users = [] for line in plist.splitlines(): - u,p = line.split(':',1) + u, p = line.split(':', 1) if p == "R" or p == "RANDOM": p = rand_user_password() - randlist.append("%s:%s" % (u,p)) - plist_in.append("%s:%s" % (u,p)) + randlist.append("%s:%s" % (u, p)) + plist_in.append("%s:%s" % (u, p)) users.append(u) ch_in = '\n'.join(plist_in) @@ -70,7 +70,7 @@ def handle(_name,cfg,_cloud,log,args): '\n'.join(randlist) )) if expire: - enum=len(errors) + enum = len(errors) for u in users: try: util.subp(['passwd', '--expire', u]) @@ -83,13 +83,13 @@ def handle(_name,cfg,_cloud,log,args): if 'ssh_pwauth' in cfg: val = str(cfg['ssh_pwauth']).lower() if val in ( "true", "1", "yes"): - pw_auth="yes" - change_pwauth=True + pw_auth = "yes" + change_pwauth = True elif val in ( "false", "0", "no"): - pw_auth="no" - change_pwauth=True + pw_auth = "no" + change_pwauth = True else: - change_pwauth=False + change_pwauth = False if change_pwauth: pa_s = "\(#*\)\(PasswordAuthentication[[:space:]]\+\)\(yes\|no\)" @@ -118,7 +118,7 @@ def rand_str(strlen=32, select_from=string.letters+string.digits): return("".join([random.choice(select_from) for _x in range(0, strlen)])) def rand_user_password(pwlen=9): - selfrom=(string.letters.translate(None,'loLOI') + - string.digits.translate(None,'01')) - return(rand_str(pwlen,select_from=selfrom)) + selfrom = (string.letters.translate(None, 'loLOI') + + string.digits.translate(None, '01')) + return(rand_str(pwlen, select_from=selfrom)) |