From cf3dd1ba86d4ddde149f451e026c697c07b4d732 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Fri, 28 Sep 2012 13:53:56 -0700 Subject: Rework the rest of the locations that used the previous 'user' and make those locations go through the new distros functions to select the default user or the user list (depending on usage). Adjust the tests to check the new 'default' field that signifies the default user + test the new method to extract just the default user from a normalized user dictionary. --- cloudinit/config/cc_ssh.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'cloudinit/config/cc_ssh.py') diff --git a/cloudinit/config/cc_ssh.py b/cloudinit/config/cc_ssh.py index 0ded62ba..c2ee4635 100644 --- a/cloudinit/config/cc_ssh.py +++ b/cloudinit/config/cc_ssh.py @@ -21,6 +21,7 @@ import glob import os +from cloudinit import distros as ds from cloudinit import ssh_util from cloudinit import util @@ -102,16 +103,8 @@ def handle(_name, cfg, cloud, log, _args): " %s to file %s"), keytype, keyfile) try: - # TODO(utlemming): consolidate this stanza that occurs in: - # cc_ssh_import_id, cc_set_passwords, maybe cc_users_groups.py - user = cloud.distro.get_default_user() - - if 'users' in cfg: - user_zero = cfg['users'][0] - - if user_zero != "default": - user = user_zero - + (users, _groups) = ds.normalize_users_groups(cfg, cloud.distro) + (user, _user_config) = ds.extract_default(users) disable_root = util.get_cfg_option_bool(cfg, "disable_root", True) disable_root_opts = util.get_cfg_option_str(cfg, "disable_root_opts", DISABLE_ROOT_OPTS) -- cgit v1.2.3 From 7ab25c779433a614a6e4101ddfe852fc25f39c01 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Fri, 28 Sep 2012 14:06:22 -0700 Subject: Add a comment as to why distros can't be imported without being renamed due to previous usage of the attribute 'distros' --- cloudinit/config/cc_byobu.py | 4 ++++ cloudinit/config/cc_set_passwords.py | 4 ++++ cloudinit/config/cc_ssh.py | 4 ++++ cloudinit/config/cc_ssh_authkey_fingerprints.py | 8 ++++++-- cloudinit/config/cc_ssh_import_id.py | 4 ++++ cloudinit/config/cc_users_groups.py | 3 +++ 6 files changed, 25 insertions(+), 2 deletions(-) (limited to 'cloudinit/config/cc_ssh.py') diff --git a/cloudinit/config/cc_byobu.py b/cloudinit/config/cc_byobu.py index e1ec5af5..e38fccdd 100644 --- a/cloudinit/config/cc_byobu.py +++ b/cloudinit/config/cc_byobu.py @@ -18,7 +18,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# Ensure this is aliased to a name not 'distros' +# since the module attribute 'distros' +# is a list of distros that are supported, not a sub-module from cloudinit import distros as ds + from cloudinit import util distros = ['ubuntu', 'debian'] diff --git a/cloudinit/config/cc_set_passwords.py b/cloudinit/config/cc_set_passwords.py index bb95f948..26c558ad 100644 --- a/cloudinit/config/cc_set_passwords.py +++ b/cloudinit/config/cc_set_passwords.py @@ -20,7 +20,11 @@ import sys +# Ensure this is aliased to a name not 'distros' +# since the module attribute 'distros' +# is a list of distros that are supported, not a sub-module from cloudinit import distros as ds + from cloudinit import ssh_util from cloudinit import util diff --git a/cloudinit/config/cc_ssh.py b/cloudinit/config/cc_ssh.py index c2ee4635..32e48c30 100644 --- a/cloudinit/config/cc_ssh.py +++ b/cloudinit/config/cc_ssh.py @@ -21,7 +21,11 @@ import glob import os +# Ensure this is aliased to a name not 'distros' +# since the module attribute 'distros' +# is a list of distros that are supported, not a sub-module from cloudinit import distros as ds + from cloudinit import ssh_util from cloudinit import util diff --git a/cloudinit/config/cc_ssh_authkey_fingerprints.py b/cloudinit/config/cc_ssh_authkey_fingerprints.py index 32214fba..8c9a8806 100644 --- a/cloudinit/config/cc_ssh_authkey_fingerprints.py +++ b/cloudinit/config/cc_ssh_authkey_fingerprints.py @@ -21,7 +21,11 @@ import hashlib from prettytable import PrettyTable -from cloudinit import distros +# Ensure this is aliased to a name not 'distros' +# since the module attribute 'distros' +# is a list of distros that are supported, not a sub-module +from cloudinit import distros as ds + from cloudinit import ssh_util from cloudinit import util @@ -94,7 +98,7 @@ def handle(name, cfg, cloud, log, _args): hash_meth = util.get_cfg_option_str(cfg, "authkey_hash", "md5") extract_func = ssh_util.extract_authorized_keys - (users, _groups) = distros.normalize_users_groups(cfg, cloud.distro) + (users, _groups) = ds.normalize_users_groups(cfg, cloud.distro) for (user_name, _cfg) in users.items(): (auth_key_fn, auth_key_entries) = extract_func(user_name, cloud.paths) _pprint_key_entries(user_name, auth_key_fn, diff --git a/cloudinit/config/cc_ssh_import_id.py b/cloudinit/config/cc_ssh_import_id.py index a781cd7c..83af36e9 100644 --- a/cloudinit/config/cc_ssh_import_id.py +++ b/cloudinit/config/cc_ssh_import_id.py @@ -18,7 +18,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# Ensure this is aliased to a name not 'distros' +# since the module attribute 'distros' +# is a list of distros that are supported, not a sub-module from cloudinit import distros as ds + from cloudinit import util import pwd diff --git a/cloudinit/config/cc_users_groups.py b/cloudinit/config/cc_users_groups.py index da587fb3..bf5b4581 100644 --- a/cloudinit/config/cc_users_groups.py +++ b/cloudinit/config/cc_users_groups.py @@ -16,6 +16,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# Ensure this is aliased to a name not 'distros' +# since the module attribute 'distros' +# is a list of distros that are supported, not a sub-module from cloudinit import distros as ds from cloudinit.settings import PER_INSTANCE -- cgit v1.2.3