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

Proposed by Serg Lystopad
Status: Superseded
Proposed branch: ~slystopad/cloud-init:merge/chpasswd-data-as-list
Merge into: cloud-init:master
Diff against target: 81 lines (+43/-5) (has conflicts)
1 file modified
cloudinit/config/cc_set_passwords.py (+43/-5)
Conflict in cloudinit/config/cc_set_passwords.py
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Needs Fixing
cloud-init Commiters Pending
Review via email: mp+317774@code.launchpad.net

This proposal has been superseded by a proposal from 2017-03-09.

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 :
review: Needs Fixing (continuous-integration)
Revision history for this message
Scott Moser (smoser) wrote :

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

c9fc1f0... by Serg Lystopad

Fix syntax to pass flake8 tests

Unmerged commits

c9fc1f0... by Serg Lystopad

Fix syntax to pass flake8 tests

53655f7... by Serg Lystopad

Data for chpasswd in list 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

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..75bd381 100755
3--- a/cloudinit/config/cc_set_passwords.py
4+++ b/cloudinit/config/cc_set_passwords.py
5@@ -45,11 +45,28 @@ enabled, disabled, or left to system defaults using ``ssh_pwauth``.
6 expire: <true/false>
7
8 chpasswd:
9+<<<<<<< cloudinit/config/cc_set_passwords.py
10+=======
11+ list:
12+ - user1:password1
13+ - user2:Random
14+ - user3:password3
15+ - user4:R
16+
17+ ##
18+ # or as multiline string
19+ ##
20+ chpasswd:
21+>>>>>>> cloudinit/config/cc_set_passwords.py
22 list: |
23 user1:password1
24 user2:Random
25 user3:password3
26 user4:R
27+<<<<<<< cloudinit/config/cc_set_passwords.py
28+=======
29+
30+>>>>>>> cloudinit/config/cc_set_passwords.py
31 """
32
33 import sys
34@@ -79,7 +96,14 @@ def handle(_name, cfg, cloud, log, args):
35
36 if 'chpasswd' in cfg:
37 chfg = cfg['chpasswd']
38- plist = util.get_cfg_option_str(chfg, 'list', plist)
39+ if isinstance(chfg['list'], list):
40+ cfg_type = 'list'
41+ else:
42+ cfg_type = 'string'
43+ if cfg_type == 'list':
44+ plist = util.get_cfg_option_list(chfg, 'list', plist)
45+ else:
46+ plist = util.get_cfg_option_str(chfg, 'list', plist)
47 expire = util.get_cfg_option_bool(chfg, 'expire', expire)
48
49 if not plist and password:
50@@ -95,13 +119,27 @@ def handle(_name, cfg, cloud, log, args):
51 plist_in = []
52 randlist = []
53 users = []
54- for line in plist.splitlines():
55+
56+ def _prepare_credentials(line, **kwargs):
57 u, p = line.split(':', 1)
58 if p == "R" or p == "RANDOM":
59 p = rand_user_password()
60- randlist.append("%s:%s" % (u, p))
61- plist_in.append("%s:%s" % (u, p))
62- users.append(u)
63+ kwargs['randlist'].append("%s:%s" % (u, p))
64+ kwargs['plist_in'].append("%s:%s" % (u, p))
65+ kwargs['users'].append(u)
66+
67+ if cfg_type == 'list':
68+ log.warn("Handling input for chpasswd as list.")
69+ for line in plist:
70+ _prepare_credentials(line, randlist=randlist,
71+ plist_in=plist_in,
72+ users=users)
73+ else:
74+ log.warn("Handling input for chpasswd as multiline string.")
75+ for line in plist.splitlines():
76+ _prepare_credentials(line, randlist=randlist,
77+ plist_in=plist_in,
78+ users=users)
79
80 ch_in = '\n'.join(plist_in) + '\n'
81 try:

Subscribers

People subscribed via source and target branches