16
16
# You should have received a copy of the GNU General Public License
17
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
# Ensure this is aliased to a name not 'distros'
20
# since the module attribute 'distros'
21
# is a list of distros that are supported, not a sub-module
22
from cloudinit import distros as ds
19
24
from cloudinit.settings import PER_INSTANCE
21
26
frequency = PER_INSTANCE
24
def handle(name, cfg, cloud, log, _args):
28
for group in cfg['groups']:
29
if isinstance(group, dict):
30
for name, values in group.iteritems():
31
if isinstance(values, list):
32
cloud.distro.create_group(name, values)
33
elif isinstance(values, str):
34
cloud.distro.create_group(name, values.split(','))
36
cloud.distro.create_group(group, [])
41
for user_config in cfg['users']:
43
# Handle the default user creation
44
if 'default' in user_config:
45
log.info("Creating default user")
47
# Create the default user if so defined
49
cloud.distro.add_default_user()
52
user_zero = cloud.distro.get_default_user()
54
except NotImplementedError:
59
log.warn("Distro has not implemented default user "
60
"creation. No default user will be created")
62
elif isinstance(user_config, dict) and 'name' in user_config:
64
name = user_config['name']
68
# Make options friendly for distro.create_user
70
if isinstance(user_config, dict):
71
for opt in user_config:
72
new_opts[opt.replace('-', '_')] = user_config[opt]
74
cloud.distro.create_user(**new_opts)
77
# create user with no configuration
78
cloud.distro.create_user(user_config)
29
def handle(name, cfg, cloud, _log, _args):
30
(users, groups) = ds.normalize_users_groups(cfg, cloud.distro)
31
for (name, members) in groups.items():
32
cloud.distro.create_group(name, members)
33
for (user, config) in users.items():
34
cloud.distro.create_user(user, **config)