Merge ~slystopad/cloud-init:merge/chpasswd-data-as-list into cloud-init:master

Proposed by Serg Lystopad
Status: Merged
Merged at revision: 7f2b51054a5defec4c04fc40026bda7dd29f69fe
Proposed branch: ~slystopad/cloud-init:merge/chpasswd-data-as-list
Merge into: cloud-init:master
Diff against target: 69 lines (+36/-5)
1 file modified
cloudinit/config/cc_set_passwords.py (+36/-5)
Reviewer Review Type Date Requested Status
Scott Moser Approve
Serg Lystopad (community) Needs Resubmitting
Server Team CI bot continuous-integration Approve
Review via email: mp+319433@code.launchpad.net

This proposal supersedes a proposal from 2017-02-20.

Commit message

Support data for chpasswd in list or string format.

By default cc_set_passwords supports list of pairs specified as multiline
string:

  chpasswd:
    list: |
      user:pass1
      user015:R

This patch adds support for user/pairs as yaml list:

chpasswd:
  list:
    - user:pass1
    - user015:R

LP: #1665773
LP: #1665694

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Scott Moser (smoser) wrote : Posted in a previous version of this proposal

Some minor cleanups suggested. Largely looks good.

In order for me to accept this, you will have to sign the contributors agreement. See HACKING.rst for more information, and please feel free to ping me in irc or email if I can help out at all.

I'll put this into 'Work in progress' state. Just move it to Resubmit when you've done that.

Thanks.
Scott

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Serg Lystopad (slystopad) wrote :

Scott, I've fixed CI complains and signed the contributors agreement.

review: Needs Resubmitting
Revision history for this message
Scott Moser (smoser) wrote :

Thanks! merged with some small changes here.

review: Approve

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/config/cc_set_passwords.py b/cloudinit/config/cc_set_passwords.py
2index af6704c..301d5e9 100755
3--- a/cloudinit/config/cc_set_passwords.py
4+++ b/cloudinit/config/cc_set_passwords.py
5@@ -50,6 +50,16 @@ enabled, disabled, or left to system defaults using ``ssh_pwauth``.
6 user2:Random
7 user3:password3
8 user4:R
9+
10+ ##
11+ # or as yaml list
12+ ##
13+ chpasswd:
14+ list:
15+ - user1:password1
16+ - user2:Random
17+ - user3:password3
18+ - user4:R
19 """
20
21 import sys
22@@ -79,7 +89,14 @@ def handle(_name, cfg, cloud, log, args):
23
24 if 'chpasswd' in cfg:
25 chfg = cfg['chpasswd']
26- plist = util.get_cfg_option_str(chfg, 'list', plist)
27+ if isinstance(chfg['list'], list):
28+ cfg_type = 'list'
29+ else:
30+ cfg_type = 'string'
31+ if cfg_type == 'list':
32+ plist = util.get_cfg_option_list(chfg, 'list', plist)
33+ else:
34+ plist = util.get_cfg_option_str(chfg, 'list', plist)
35 expire = util.get_cfg_option_bool(chfg, 'expire', expire)
36
37 if not plist and password:
38@@ -95,13 +112,27 @@ def handle(_name, cfg, cloud, log, args):
39 plist_in = []
40 randlist = []
41 users = []
42- for line in plist.splitlines():
43+
44+ def _prepare_credentials(line, **kwargs):
45 u, p = line.split(':', 1)
46 if p == "R" or p == "RANDOM":
47 p = rand_user_password()
48- randlist.append("%s:%s" % (u, p))
49- plist_in.append("%s:%s" % (u, p))
50- users.append(u)
51+ kwargs['randlist'].append("%s:%s" % (u, p))
52+ kwargs['plist_in'].append("%s:%s" % (u, p))
53+ kwargs['users'].append(u)
54+
55+ if cfg_type == 'list':
56+ log.warn("Handling input for chpasswd as list.")
57+ for line in plist:
58+ _prepare_credentials(line, randlist=randlist,
59+ plist_in=plist_in,
60+ users=users)
61+ else:
62+ log.warn("Handling input for chpasswd as multiline string.")
63+ for line in plist.splitlines():
64+ _prepare_credentials(line, randlist=randlist,
65+ plist_in=plist_in,
66+ users=users)
67
68 ch_in = '\n'.join(plist_in) + '\n'
69 try:

Subscribers

People subscribed via source and target branches