~ubuntu-branches/ubuntu/saucy/cloud-init/saucy

« back to all changes in this revision

Viewing changes to cloudinit/config/cc_ssh_import_id.py

  • Committer: Package Import Robot
  • Author(s): Scott Moser
  • Date: 2012-08-31 17:04:06 UTC
  • mto: (245.3.1 raring)
  • mto: This revision was merged to the branch mainline in revision 290.
  • Revision ID: package-import@ubuntu.com-20120831170406-0dbj84kjdfcn4ktr
* New upstream snapshot.
  * support using launch-index (ami-launch-index) (LP: #1023177)
  * usergroup related fixes (LP: #1041384, #1044044, #1044508)

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
    # import for cloudinit created users
42
42
    elist = []
43
 
    for user in cfg['users'].keys():
44
 
        if user == "default":
 
43
    for user_cfg in cfg['users']:
 
44
        user = None
 
45
        import_ids = []
 
46
 
 
47
        if isinstance(user_cfg, str) and user_cfg == "default":
45
48
            user = cloud.distro.get_default_user()
46
49
            if not user:
47
50
                continue
 
51
 
48
52
            import_ids = util.get_cfg_option_list(cfg, "ssh_import_id", [])
49
 
        else:
50
 
            if not isinstance(cfg['users'][user], dict):
51
 
                log.debug("cfg['users'][%s] not a dict, skipping ssh_import",
52
 
                          user)
53
 
            import_ids = util.get_cfg_option_list(cfg['users'][user],
54
 
                                                  "ssh_import_id", [])
 
53
 
 
54
        elif isinstance(user_cfg, dict):
 
55
            user = None
 
56
            import_ids = []
 
57
 
 
58
            try:
 
59
                user = user_cfg['name']
 
60
                import_ids = user_cfg['ssh_import_id']
 
61
 
 
62
                if import_ids and isinstance(import_ids, str):
 
63
                    import_ids = str(import_ids).split(',')
 
64
 
 
65
            except:
 
66
                log.debug("user %s is not configured for ssh_import" % user)
 
67
                continue
55
68
 
56
69
        if not len(import_ids):
57
70
            continue
59
72
        try:
60
73
            import_ssh_ids(import_ids, user, log)
61
74
        except Exception as exc:
62
 
            util.logexc(exc, "ssh-import-id failed for: %s %s" %
63
 
                        (user, import_ids))
 
75
            util.logexc(log, "ssh-import-id failed for: %s %s" %
 
76
                            (user, import_ids), exc)
64
77
            elist.append(exc)
65
78
 
66
79
    if len(elist):
68
81
 
69
82
 
70
83
def import_ssh_ids(ids, user, log):
 
84
 
71
85
    if not (user and ids):
72
86
        log.debug("empty user(%s) or ids(%s). not importing", user, ids)
73
87
        return