summaryrefslogtreecommitdiff
path: root/cloudinit/config/cc_ssh_import_id.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-09-28 13:53:56 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-09-28 13:53:56 -0700
commitcf3dd1ba86d4ddde149f451e026c697c07b4d732 (patch)
tree29092b201054ca6af61c0c2f4ba61a8f28f051b0 /cloudinit/config/cc_ssh_import_id.py
parentdfa62e70bd9942fd3c82d77217d48615a78bbcfc (diff)
downloadvyos-cloud-init-cf3dd1ba86d4ddde149f451e026c697c07b4d732.tar.gz
vyos-cloud-init-cf3dd1ba86d4ddde149f451e026c697c07b4d732.zip
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.
Diffstat (limited to 'cloudinit/config/cc_ssh_import_id.py')
-rw-r--r--cloudinit/config/cc_ssh_import_id.py33
1 files changed, 14 insertions, 19 deletions
diff --git a/cloudinit/config/cc_ssh_import_id.py b/cloudinit/config/cc_ssh_import_id.py
index 08fb63c6..a781cd7c 100644
--- a/cloudinit/config/cc_ssh_import_id.py
+++ b/cloudinit/config/cc_ssh_import_id.py
@@ -18,6 +18,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+from cloudinit import distros as ds
from cloudinit import util
import pwd
@@ -39,33 +40,27 @@ def handle(_name, cfg, cloud, log, args):
return
# import for cloudinit created users
+ (users, _groups) = ds.normalize_users_groups(cfg, cloud.distro)
elist = []
- for user_cfg in cfg['users']:
- user = None
+ for (user, user_cfg) in users.items():
import_ids = []
-
- if isinstance(user_cfg, str) and user_cfg == "default":
- user = cloud.distro.get_default_user()
- if not user:
- continue
-
+ if user_cfg['default']:
import_ids = util.get_cfg_option_list(cfg, "ssh_import_id", [])
-
- elif isinstance(user_cfg, dict):
- user = None
- import_ids = []
-
+ else:
try:
- user = user_cfg['name']
import_ids = user_cfg['ssh_import_id']
-
- if import_ids and isinstance(import_ids, str):
- import_ids = str(import_ids).split(',')
-
except:
- log.debug("user %s is not configured for ssh_import" % user)
+ log.debug("User %s is not configured for ssh_import_id", user)
continue
+ try:
+ import_ids = util.uniq_merge(import_ids)
+ import_ids = [str(i) for i in import_ids]
+ except:
+ log.debug("User %s is not correctly configured for ssh_import_id",
+ user)
+ continue
+
if not len(import_ids):
continue