From 0049b6e7bc7f52fd442f1b8902294ca8c379df5c Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Thu, 20 Sep 2012 17:26:42 -0700 Subject: Remove the need to have 'default_user' and 'default_user_groups' groups be hard coded into the distro class, instead let that set of configuration be located in the config file where it should be specified instead. --- cloudinit/distros/__init__.py | 12 ++++-------- cloudinit/distros/fedora.py | 3 +-- cloudinit/distros/ubuntu.py | 5 +---- config/cloud.cfg | 17 ++++++++++++++++- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py index 3e9d934d..cdb72b5a 100644 --- a/cloudinit/distros/__init__.py +++ b/cloudinit/distros/__init__.py @@ -44,10 +44,7 @@ LOG = logging.getLogger(__name__) class Distro(object): - __metaclass__ = abc.ABCMeta - default_user = None - default_user_groups = None def __init__(self, name, cfg, paths): self._paths = paths @@ -61,7 +58,6 @@ class Distro(object): user = self.get_default_user() groups = self.get_default_user_groups() - if not user: raise NotImplementedError("No Default user") @@ -71,12 +67,12 @@ class Distro(object): 'home': "/home/%s" % user, 'shell': "/bin/bash", 'lock_passwd': True, - 'gecos': "%s%s" % (user[0:1].upper(), user[1:]), + 'gecos': user.title(), 'sudo': "ALL=(ALL) NOPASSWD:ALL", } if groups: - user_dict['groups'] = groups + user_dict['groups'] = ",".join(groups) self.create_user(**user_dict) @@ -212,10 +208,10 @@ class Distro(object): return False def get_default_user(self): - return self.default_user + return self.get_option('default_user') def get_default_user_groups(self): - return self.default_user_groups + return self.get_option('default_user_groups') def create_user(self, name, **kwargs): """ diff --git a/cloudinit/distros/fedora.py b/cloudinit/distros/fedora.py index 9f76a116..c777845d 100644 --- a/cloudinit/distros/fedora.py +++ b/cloudinit/distros/fedora.py @@ -28,5 +28,4 @@ LOG = logging.getLogger(__name__) class Distro(rhel.Distro): - distro_name = 'fedora' - default_user = 'ec2-user' + pass diff --git a/cloudinit/distros/ubuntu.py b/cloudinit/distros/ubuntu.py index 22f8c2c5..428db6ad 100644 --- a/cloudinit/distros/ubuntu.py +++ b/cloudinit/distros/ubuntu.py @@ -28,8 +28,5 @@ LOG = logging.getLogger(__name__) class Distro(debian.Distro): + pass - distro_name = 'ubuntu' - default_user = 'ubuntu' - default_user_groups = ("adm,audio,cdrom,dialout,floppy,video," - "plugdev,dip,netdev,sudo") diff --git a/config/cloud.cfg b/config/cloud.cfg index b3411d11..fbf53bd5 100644 --- a/config/cloud.cfg +++ b/config/cloud.cfg @@ -1,7 +1,9 @@ # The top level settings are used as module # and system configuration. -# Implement for Ubuntu only: create the default 'ubuntu' user +# A set of users which may be applied and/or used by various modules +# when a 'default' entry is found it will reference the 'default_user' +# from the distro configuration specified below users: - default @@ -71,6 +73,19 @@ cloud_final_modules: system_info: # This will affect which distro class gets used distro: ubuntu + # Default user name + that default users groups (if added/used) + default_user: ubuntu + default_user_groups: + - adm + - audio + - cdrom + - dialout + - floppy + - video + - plugdev + - dip + - netdev + - sudo # Other config here will be given to the distro class and/or path classes paths: cloud_dir: /var/lib/cloud/ -- cgit v1.2.3