diff options
author | Scott Moser <smoser@ubuntu.com> | 2016-03-11 10:35:54 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2016-03-11 10:35:54 -0500 |
commit | ff47d211d507359ad508caafdb413ab9071cd165 (patch) | |
tree | 42acc467709c822b0502f819162a82cfc9321755 /cloudinit | |
parent | 781ded8127deefb49a8806e49bdb7bb6e4d4b245 (diff) | |
parent | 41470d29f5888baf7ec78e170cc0d6d981dcf63e (diff) | |
download | vyos-cloud-init-ff47d211d507359ad508caafdb413ab9071cd165.tar.gz vyos-cloud-init-ff47d211d507359ad508caafdb413ab9071cd165.zip |
merge with trunk
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/distros/__init__.py | 24 | ||||
-rw-r--r-- | cloudinit/util.py | 12 |
2 files changed, 31 insertions, 5 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py index 461253a7..74b484a7 100644 --- a/cloudinit/distros/__init__.py +++ b/cloudinit/distros/__init__.py @@ -330,6 +330,11 @@ class Distro(object): LOG.info("User %s already exists, skipping." % name) return + if 'create_groups' in kwargs: + create_groups = kwargs.pop('create_groups') + else: + create_groups = True + adduser_cmd = ['useradd', name] log_adduser_cmd = ['useradd', name] @@ -357,6 +362,19 @@ class Distro(object): redact_opts = ['passwd'] + groups = kwargs.get('groups') + if groups: + if isinstance(groups, (list, tuple)): + kwargs['groups'] = ",".join(groups) + else: + groups = groups.split(",") + + if create_groups: + for group in kwargs.get('groups').split(","): + if not util.is_group(group): + self.create_group(group) + LOG.debug("created group %s for user %s", name, group) + # Check the values and create the command for key, val in kwargs.items(): @@ -545,8 +563,10 @@ class Distro(object): util.logexc(LOG, "Failed to append sudoers file %s", sudo_file) raise e - def create_group(self, name, members): + def create_group(self, name, members=None): group_add_cmd = ['groupadd', name] + if not members: + members = [] # Check if group exists, and then add it doesn't if util.is_group(name): @@ -556,7 +576,7 @@ class Distro(object): util.subp(group_add_cmd) LOG.info("Created new group %s" % name) except Exception: - util.logexc("Failed to create group %s", name) + util.logexc(LOG, "Failed to create group %s", name) # Add members to the group, if so defined if len(members) > 0: diff --git a/cloudinit/util.py b/cloudinit/util.py index e7407ea4..01dc7751 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -2140,13 +2140,19 @@ def _read_dmi_syspath(key): LOG.debug("did not find %s", dmi_key_path) return None - key_data = load_file(dmi_key_path) + key_data = load_file(dmi_key_path, decode=False) if not key_data: LOG.debug("%s did not return any data", dmi_key_path) return None - LOG.debug("dmi data %s returned %s", dmi_key_path, key_data) - return key_data.strip() + # uninitialized dmi values show as all \xff and /sys appends a '\n'. + # in that event, return a string of '.' in the same length. + if key_data == b'\xff' * (len(key_data) - 1) + b'\n': + key_data = b'.' * (len(key_data) - 1) + b'\n' + + str_data = key_data.decode('utf8').strip() + LOG.debug("dmi data %s returned %s", dmi_key_path, str_data) + return str_data except Exception: logexc(LOG, "failed read of %s", dmi_key_path) |