summaryrefslogtreecommitdiff
path: root/cloudinit/distros/__init__.py
diff options
context:
space:
mode:
authorharlowja <harlowja@virtualbox.rhel>2013-01-19 17:51:24 -0800
committerharlowja <harlowja@virtualbox.rhel>2013-01-19 17:51:24 -0800
commit06ca24c39289f2d1f0f3f810abf155043a36d2f2 (patch)
tree70ef1c745d0535d05ea8053e613e2a204c69aa02 /cloudinit/distros/__init__.py
parentbaefd17a9d997e11f85bf89d9337c2d40748bc37 (diff)
downloadvyos-cloud-init-06ca24c39289f2d1f0f3f810abf155043a36d2f2.tar.gz
vyos-cloud-init-06ca24c39289f2d1f0f3f810abf155043a36d2f2.zip
Merge the old user style with the distro provided config.
When the old user: style entry is found, don't forget that we need to use the distro settings that are provided but override the name with the new name, this is now accomplished by merging them together in the correct order (using the standard cloud-init merging algo).
Diffstat (limited to 'cloudinit/distros/__init__.py')
-rw-r--r--cloudinit/distros/__init__.py42
1 files changed, 23 insertions, 19 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index c74be4e2..ddea8417 100644
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -714,7 +714,7 @@ def normalize_users_groups(cfg, distro):
# Handle the previous style of doing this where the first user
# overrides the concept of the default user if provided in the user: XYZ
# format.
- old_user = None
+ old_user = {}
if 'user' in cfg and cfg['user']:
old_user = cfg['user']
# Translate it into the format that is more useful
@@ -724,28 +724,32 @@ def normalize_users_groups(cfg, distro):
'name': old_user,
}
if not isinstance(old_user, (dict)):
- LOG.warn(("Format for 'user:' key must be a string or "
+ LOG.warn(("Format for 'user' key must be a string or "
"dictionary and not %s"), util.obj_name(old_user))
- old_user = None
-
- default_user_config = None
- if not old_user:
- # If no old user format, then assume the distro
- # provides what the 'default' user maps to, but notice
- # that if this is provided, we won't automatically inject
- # a 'default' user into the users list, while if a old user
- # format is provided we will.
- try:
- default_user_config = distro.get_default_user()
- except NotImplementedError:
- LOG.warn(("Distro has not implemented default user "
- "access. No default user will be normalized."))
- else:
- default_user_config = dict(old_user)
+ old_user = {}
+
+ # If no old user format, then assume the distro
+ # provides what the 'default' user maps to, but notice
+ # that if this is provided, we won't automatically inject
+ # a 'default' user into the users list, while if a old user
+ # format is provided we will.
+ distro_user_config = {}
+ try:
+ distro_user_config = distro.get_default_user()
+ except NotImplementedError:
+ LOG.warn(("Distro has not implemented default user "
+ "access. No distribution provided default user"
+ " will be normalized."))
+
+ # Merge the old user (which may just be an empty dict when not
+ # present with the distro provided default user configuration so
+ # that the old user style picks up all the distribution specific
+ # attributes (if any)
+ default_user_config = util.mergemanydict([old_user, distro_user_config])
base_users = cfg.get('users', [])
if not isinstance(base_users, (list, dict, str, basestring)):
- LOG.warn(("Format for 'users:' key must be a comma separated string"
+ LOG.warn(("Format for 'users' key must be a comma separated string"
" or a dictionary or a list and not %s"),
util.obj_name(base_users))
base_users = []