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.
This commit is contained in:
Joshua Harlow 2012-09-20 17:26:42 -07:00
parent 8e6993d9dc
commit dc7b504aeb
4 changed files with 22 additions and 15 deletions

View File

@ -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):
"""

View File

@ -28,5 +28,4 @@ LOG = logging.getLogger(__name__)
class Distro(rhel.Distro):
distro_name = 'fedora'
default_user = 'ec2-user'
pass

View File

@ -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")

View File

@ -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/