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
diff --git a/cloudinit/config/cc_set_passwords.py b/cloudinit/config/cc_set_passwords.py
index af6704c..75bd381 100755
--- a/cloudinit/config/cc_set_passwords.py
+++ b/cloudinit/config/cc_set_passwords.py
@@ -45,11 +45,28 @@ enabled, disabled, or left to system defaults using ``ssh_pwauth``.
45 expire: <true/false>45 expire: <true/false>
4646
47 chpasswd:47 chpasswd:
48<<<<<<< cloudinit/config/cc_set_passwords.py
49=======
50 list:
51 - user1:password1
52 - user2:Random
53 - user3:password3
54 - user4:R
55
56 ##
57 # or as multiline string
58 ##
59 chpasswd:
60>>>>>>> cloudinit/config/cc_set_passwords.py
48 list: |61 list: |
49 user1:password162 user1:password1
50 user2:Random63 user2:Random
51 user3:password364 user3:password3
52 user4:R65 user4:R
66<<<<<<< cloudinit/config/cc_set_passwords.py
67=======
68
69>>>>>>> cloudinit/config/cc_set_passwords.py
53"""70"""
5471
55import sys72import sys
@@ -79,7 +96,14 @@ def handle(_name, cfg, cloud, log, args):
7996
80 if 'chpasswd' in cfg:97 if 'chpasswd' in cfg:
81 chfg = cfg['chpasswd']98 chfg = cfg['chpasswd']
82 plist = util.get_cfg_option_str(chfg, 'list', plist)99 if isinstance(chfg['list'], list):
100 cfg_type = 'list'
101 else:
102 cfg_type = 'string'
103 if cfg_type == 'list':
104 plist = util.get_cfg_option_list(chfg, 'list', plist)
105 else:
106 plist = util.get_cfg_option_str(chfg, 'list', plist)
83 expire = util.get_cfg_option_bool(chfg, 'expire', expire)107 expire = util.get_cfg_option_bool(chfg, 'expire', expire)
84108
85 if not plist and password:109 if not plist and password:
@@ -95,13 +119,27 @@ def handle(_name, cfg, cloud, log, args):
95 plist_in = []119 plist_in = []
96 randlist = []120 randlist = []
97 users = []121 users = []
98 for line in plist.splitlines():122
123 def _prepare_credentials(line, **kwargs):
99 u, p = line.split(':', 1)124 u, p = line.split(':', 1)
100 if p == "R" or p == "RANDOM":125 if p == "R" or p == "RANDOM":
101 p = rand_user_password()126 p = rand_user_password()
102 randlist.append("%s:%s" % (u, p))127 kwargs['randlist'].append("%s:%s" % (u, p))
103 plist_in.append("%s:%s" % (u, p))128 kwargs['plist_in'].append("%s:%s" % (u, p))
104 users.append(u)129 kwargs['users'].append(u)
130
131 if cfg_type == 'list':
132 log.warn("Handling input for chpasswd as list.")
133 for line in plist:
134 _prepare_credentials(line, randlist=randlist,
135 plist_in=plist_in,
136 users=users)
137 else:
138 log.warn("Handling input for chpasswd as multiline string.")
139 for line in plist.splitlines():
140 _prepare_credentials(line, randlist=randlist,
141 plist_in=plist_in,
142 users=users)
105143
106 ch_in = '\n'.join(plist_in) + '\n'144 ch_in = '\n'.join(plist_in) + '\n'
107 try:145 try:

Subscribers

People subscribed via source and target branches