summaryrefslogtreecommitdiff
path: root/cloudinit/config
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-09-27 21:30:01 -0400
committerScott Moser <smoser@ubuntu.com>2012-09-27 21:30:01 -0400
commitec910564e00498f5c545a227bee56eb25233e270 (patch)
treea256e433675284c2ae2f61e1ddf642bf284d25b3 /cloudinit/config
parent317f442445fc40a666e9566e1f2739324cc99a2e (diff)
parent56d0585fd7d9804b82a1eb22faff8a6554b100b8 (diff)
downloadvyos-cloud-init-ec910564e00498f5c545a227bee56eb25233e270.tar.gz
vyos-cloud-init-ec910564e00498f5c545a227bee56eb25233e270.zip
cleanup the user/group lists
The primary utility here is normalize_user_groups, which would be called by config modules to get a list of users or groups. This centralizes what was copied code into this one location.
Diffstat (limited to 'cloudinit/config')
-rw-r--r--cloudinit/config/cc_ssh_authkey_fingerprints.py10
-rw-r--r--cloudinit/config/cc_users_groups.py62
2 files changed, 14 insertions, 58 deletions
diff --git a/cloudinit/config/cc_ssh_authkey_fingerprints.py b/cloudinit/config/cc_ssh_authkey_fingerprints.py
index 23f5755a..2b9a6e0e 100644
--- a/cloudinit/config/cc_ssh_authkey_fingerprints.py
+++ b/cloudinit/config/cc_ssh_authkey_fingerprints.py
@@ -21,6 +21,7 @@ import hashlib
from prettytable import PrettyTable
+from cloudinit import distros
from cloudinit import ssh_util
from cloudinit import util
@@ -89,8 +90,9 @@ def handle(name, cfg, cloud, log, _args):
log.debug(("Skipping module named %s, "
"logging of ssh fingerprints disabled"), name)
- user_name = util.get_cfg_option_str(cfg, "user", "ubuntu")
hash_meth = util.get_cfg_option_str(cfg, "authkey_hash", "md5")
- extract = ssh_util.extract_authorized_keys
- (auth_key_fn, auth_key_entries) = extract(user_name, cloud.paths)
- _pprint_key_entries(user_name, auth_key_fn, auth_key_entries, hash_meth)
+ extract_func = ssh_util.extract_authorized_keys
+ (users, _groups) = distros.normalize_users_groups(cfg, cloud.distro)
+ for (user_name, _cfg) in users.items():
+ (auth_key_fn, auth_key_entries) = extract_func(user_name, cloud.paths)
+ _pprint_key_entries(user_name, auth_key_fn, auth_key_entries, hash_meth)
diff --git a/cloudinit/config/cc_users_groups.py b/cloudinit/config/cc_users_groups.py
index 418f3330..464f55c3 100644
--- a/cloudinit/config/cc_users_groups.py
+++ b/cloudinit/config/cc_users_groups.py
@@ -16,63 +16,17 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+from cloudinit import distros
+from cloudinit import util
+
from cloudinit.settings import PER_INSTANCE
frequency = PER_INSTANCE
def handle(name, cfg, cloud, log, _args):
- user_zero = None
-
- if 'groups' in cfg:
- for group in cfg['groups']:
- if isinstance(group, dict):
- for name, values in group.iteritems():
- if isinstance(values, list):
- cloud.distro.create_group(name, values)
- elif isinstance(values, str):
- cloud.distro.create_group(name, values.split(','))
- else:
- cloud.distro.create_group(group, [])
-
- if 'users' in cfg:
- user_zero = None
-
- for user_config in cfg['users']:
-
- # Handle the default user creation
- if 'default' in user_config:
- log.info("Creating default user")
-
- # Create the default user if so defined
- try:
- cloud.distro.add_default_user()
-
- if not user_zero:
- user_zero = cloud.distro.get_default_user()
-
- except NotImplementedError:
-
- if user_zero == name:
- user_zero = None
-
- log.warn("Distro has not implemented default user "
- "creation. No default user will be created")
-
- elif isinstance(user_config, dict) and 'name' in user_config:
-
- name = user_config['name']
- if not user_zero:
- user_zero = name
-
- # Make options friendly for distro.create_user
- new_opts = {}
- if isinstance(user_config, dict):
- for opt in user_config:
- new_opts[opt.replace('-', '_')] = user_config[opt]
-
- cloud.distro.create_user(**new_opts)
-
- else:
- # create user with no configuration
- cloud.distro.create_user(user_config)
+ (users, groups) = distros.normalize_users_groups(cfg, cloud.distro)
+ for (name, members) in groups.items():
+ cloud.distro.create_group(name, members)
+ for (user, config) in users.items():
+ cloud.distro.create_user(user, **config)