diff options
author | Ben Howard <ben.howard@canonical.com> | 2012-08-22 16:32:18 -0600 |
---|---|---|
committer | Ben Howard <ben.howard@canonical.com> | 2012-08-22 16:32:18 -0600 |
commit | a6752e739a0bb9052585b9b043ce1964bd77bb42 (patch) | |
tree | f470b737de191b8fce315021f922f62bbea3daa0 /cloudinit | |
parent | 3f4a556e59b127d2fb6ebb57a8a42f6a71248b59 (diff) | |
download | vyos-cloud-init-a6752e739a0bb9052585b9b043ce1964bd77bb42.tar.gz vyos-cloud-init-a6752e739a0bb9052585b9b043ce1964bd77bb42.zip |
Simplified users[0] detection, and ensured compatability with previous user password control code
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/config/cc_set_passwords.py | 12 | ||||
-rw-r--r-- | cloudinit/config/cc_ssh_import_id.py | 11 | ||||
-rw-r--r-- | cloudinit/config/cc_users_groups.py | 4 | ||||
-rw-r--r-- | cloudinit/distros/__init__.py | 21 |
4 files changed, 24 insertions, 24 deletions
diff --git a/cloudinit/config/cc_set_passwords.py b/cloudinit/config/cc_set_passwords.py index ab266741..4bf62aa9 100644 --- a/cloudinit/config/cc_set_passwords.py +++ b/cloudinit/config/cc_set_passwords.py @@ -50,8 +50,16 @@ def handle(_name, cfg, cloud, log, args): expire = util.get_cfg_option_bool(chfg, 'expire', expire) if not plist and password: - user = util.get_cfg_option_str(cfg, "user", "ubuntu") - plist = "%s:%s" % (user, password) + user = cloud.distro.get_default_user() + + if 'users' in cfg: + user_zero = cfg['users'].keys()[0] + + if user_zero != "default": + user = user_zero + + if user: + plist = "%s:%s" % (user, password) errors = [] if plist: diff --git a/cloudinit/config/cc_ssh_import_id.py b/cloudinit/config/cc_ssh_import_id.py index e733d14a..9aee2166 100644 --- a/cloudinit/config/cc_ssh_import_id.py +++ b/cloudinit/config/cc_ssh_import_id.py @@ -32,12 +32,13 @@ def handle(name, cfg, cloud, log, args): if len(args) > 1: ids = args[1:] else: - user = None + user = cloud.distro.get_default_user() - try: - user = cloud.distro.get_configured_user() - except NotImplementedError: - pass + if 'users' in cfg: + user_zero = cfg['users'].keys()[0] + + if user_zero != "default": + user = user_zero ids = util.get_cfg_option_list(cfg, "ssh_import_id", []) diff --git a/cloudinit/config/cc_users_groups.py b/cloudinit/config/cc_users_groups.py index 828b0d94..7e5ecc7b 100644 --- a/cloudinit/config/cc_users_groups.py +++ b/cloudinit/config/cc_users_groups.py @@ -78,7 +78,3 @@ def handle(name, cfg, cloud, log, _args): new_opts[opt.replace('-', '')] = user_config[opt] cloud.distro.create_user(name, **new_opts) - - if user_zero: - cloud.distro.set_configured_user(user_zero) - log.info("Set configured user for this instance to %s" % user_zero) diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py index 776a2417..614545f2 100644 --- a/cloudinit/distros/__init__.py +++ b/cloudinit/distros/__init__.py @@ -49,16 +49,13 @@ class Distro(object): self._paths = paths self._cfg = cfg self.name = name + self.default_user = None @abc.abstractmethod def add_default_user(self): raise NotImplementedError() @abc.abstractmethod - def get_default_user(self): - raise NotImplementedError() - - @abc.abstractmethod def install_packages(self, pkglist): raise NotImplementedError() @@ -172,11 +169,9 @@ class Distro(object): def set_configured_user(self, name): self.default_user = name - def get_configured_user(self): - try: - return getattr(self, 'default_user') - except: - return None + def get_default_user(self): + return None + def create_user(self, name, **kwargs): """ @@ -241,7 +236,7 @@ class Distro(object): util.subp(adduser_cmd, logstring=x_adduser_cmd) except Exception as e: util.logexc(LOG, "Failed to create user %s due to error.", e) - return False + raise e # Set password if plain-text password provided if 'plain_text_passwd' in kwargs and kwargs['plain_text_passwd']: @@ -256,7 +251,7 @@ class Distro(object): except Exception as e: util.logexc(LOG, ("Failed to disable password logins for" "user %s" % name), e) - return False + raise e # Configure sudo access if 'sudo' in kwargs: @@ -280,7 +275,7 @@ class Distro(object): util.subp(cmd, pass_string, logstring="chpasswd for %s" % user) except Exception as e: util.logexc(LOG, "Failed to set password for %s" % user) - return False + raise e return True @@ -306,9 +301,9 @@ class Distro(object): try: with open(sudo_file, 'a') as f: f.write(content) - f.close() except IOError as e: util.logexc(LOG, "Failed to write %s" % sudo_file, e) + raise e def isgroup(self, name): try: |