diff options
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/config/cc_chef.py | 2 | ||||
-rw-r--r-- | cloudinit/config/cc_disk_setup.py | 6 | ||||
-rw-r--r-- | cloudinit/config/cc_write_files.py | 4 | ||||
-rw-r--r-- | cloudinit/distros/__init__.py | 7 | ||||
-rw-r--r-- | cloudinit/distros/freebsd.py | 50 | ||||
-rw-r--r-- | cloudinit/sources/DataSourceCloudStack.py | 6 | ||||
-rw-r--r-- | cloudinit/sources/DataSourceEc2.py | 4 | ||||
-rw-r--r-- | cloudinit/sources/DataSourceOpenStack.py | 2 | ||||
-rw-r--r-- | cloudinit/sources/__init__.py | 3 |
9 files changed, 57 insertions, 27 deletions
diff --git a/cloudinit/config/cc_chef.py b/cloudinit/config/cc_chef.py index e18c5405..28711a59 100644 --- a/cloudinit/config/cc_chef.py +++ b/cloudinit/config/cc_chef.py @@ -285,7 +285,7 @@ def install_chef(cloud, chef_cfg, log): chef_version = util.get_cfg_option_str(chef_cfg, 'version', None) ruby_version = util.get_cfg_option_str(chef_cfg, 'ruby_version', RUBY_VERSION_DEFAULT) - install_chef_from_gems(cloud.distro, ruby_version, chef_version) + install_chef_from_gems(ruby_version, chef_version, cloud.distro) # Retain backwards compat, by preferring True instead of False # when not provided/overriden... run = util.get_cfg_option_bool(chef_cfg, 'exec', default=True) diff --git a/cloudinit/config/cc_disk_setup.py b/cloudinit/config/cc_disk_setup.py index 0ecc2e4c..bbaf9646 100644 --- a/cloudinit/config/cc_disk_setup.py +++ b/cloudinit/config/cc_disk_setup.py @@ -847,9 +847,9 @@ def mkfs(fs_cfg): if label: fs_cmd.extend(["-L", label]) - # File systems that support the -F flag - if not fs_cmd and (overwrite or device_type(device) == "disk"): - fs_cmd.append(lookup_force_flag(fs_type)) + # File systems that support the -F flag + if overwrite or device_type(device) == "disk": + fs_cmd.append(lookup_force_flag(fs_type)) # Add the extends FS options if fs_opts: diff --git a/cloudinit/config/cc_write_files.py b/cloudinit/config/cc_write_files.py index 4b03ea91..351cfc8c 100644 --- a/cloudinit/config/cc_write_files.py +++ b/cloudinit/config/cc_write_files.py @@ -92,10 +92,10 @@ def decode_perms(perm, default, log): def extract_contents(contents, extraction_types): - result = str(contents) + result = contents for t in extraction_types: if t == 'application/x-gzip': - result = util.decomp_gzip(result, quiet=False) + result = util.decomp_gzip(result, quiet=False, decode=False) elif t == 'application/base64': result = base64.b64decode(result) elif t == UNKNOWN_ENC: diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py index 71da7ec5..5879dabf 100644 --- a/cloudinit/distros/__init__.py +++ b/cloudinit/distros/__init__.py @@ -371,7 +371,7 @@ class Distro(object): kwargs['groups'] = ",".join(groups) else: groups = groups.split(",") - + primary_group = kwargs.get('primary_group') if primary_group: groups.append(primary_group) @@ -940,7 +940,10 @@ def set_etc_timezone(tz, tz_file=None, tz_conf="/etc/timezone", # This ensures that the correct tz will be used for the system if tz_local and tz_file: # use a symlink if there exists a symlink or tz_local is not present - if os.path.islink(tz_local) or not os.path.exists(tz_local): + islink = os.path.islink(tz_local) + if islink or not os.path.exists(tz_local): + if islink: + util.del_file(tz_local) os.symlink(tz_file, tz_local) else: util.copy(tz_file, tz_local) diff --git a/cloudinit/distros/freebsd.py b/cloudinit/distros/freebsd.py index 72012056..91bf4a4e 100644 --- a/cloudinit/distros/freebsd.py +++ b/cloudinit/distros/freebsd.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +import os import six from six import StringIO @@ -30,6 +31,8 @@ from cloudinit import util from cloudinit.distros import net_util from cloudinit.distros.parsers.resolv_conf import ResolvConf +from cloudinit.settings import PER_INSTANCE + LOG = logging.getLogger(__name__) @@ -236,9 +239,21 @@ class Distro(distros.Distro): util.logexc(LOG, "Failed to create user %s", name) raise e - # TODO: def set_passwd(self, user, passwd, hashed=False): - return False + cmd = ['pw', 'usermod', user] + + if hashed: + cmd.append('-H') + else: + cmd.append('-h') + + cmd.append('0') + + try: + util.subp(cmd, passwd, logstring="chpasswd for %s" % user) + except Exception as e: + util.logexc(LOG, "Failed to set password for %s", user) + raise e def lock_passwd(self, name): try: @@ -369,13 +384,34 @@ class Distro(distros.Distro): LOG.warn("Error running %s: %s", cmd, err) def install_packages(self, pkglist): - return + self.update_package_sources() + self.package_command('install', pkgs=pkglist) + + def package_command(self, command, args=None, pkgs=None): + if pkgs is None: + pkgs = [] + + e = os.environ.copy() + e['ASSUME_ALWAYS_YES'] = 'YES' + + cmd = ['pkg'] + if args and isinstance(args, str): + cmd.append(args) + elif args and isinstance(args, list): + cmd.extend(args) + + if command: + cmd.append(command) + + pkglist = util.expand_package_list('%s-%s', pkgs) + cmd.extend(pkglist) - def package_command(self, cmd, args=None, pkgs=None): - return + # Allow the output of this to flow outwards (ie not be captured) + util.subp(cmd, env=e, capture=False) def set_timezone(self, tz): - return + distros.set_etc_timezone(tz=tz, tz_file=self._find_tz_file(tz)) def update_package_sources(self): - return + self._runner.run("update-sources", self.package_command, + ["update"], freq=PER_INSTANCE) diff --git a/cloudinit/sources/DataSourceCloudStack.py b/cloudinit/sources/DataSourceCloudStack.py index 64595020..455a4652 100644 --- a/cloudinit/sources/DataSourceCloudStack.py +++ b/cloudinit/sources/DataSourceCloudStack.py @@ -89,8 +89,6 @@ class DataSourceCloudStack(sources.DataSource): def _get_url_settings(self): mcfg = self.ds_cfg - if not mcfg: - mcfg = {} max_wait = 120 try: max_wait = int(mcfg.get("max_wait", max_wait)) @@ -109,10 +107,6 @@ class DataSourceCloudStack(sources.DataSource): return (max_wait, timeout) def wait_for_metadata_service(self): - mcfg = self.ds_cfg - if not mcfg: - mcfg = {} - (max_wait, timeout) = self._get_url_settings() urls = [uhelp.combine_url(self.metadata_address, diff --git a/cloudinit/sources/DataSourceEc2.py b/cloudinit/sources/DataSourceEc2.py index 3ef2c6af..6fe2a0bb 100644 --- a/cloudinit/sources/DataSourceEc2.py +++ b/cloudinit/sources/DataSourceEc2.py @@ -84,8 +84,6 @@ class DataSourceEc2(sources.DataSource): def _get_url_settings(self): mcfg = self.ds_cfg - if not mcfg: - mcfg = {} max_wait = 120 try: max_wait = int(mcfg.get("max_wait", max_wait)) @@ -102,8 +100,6 @@ class DataSourceEc2(sources.DataSource): def wait_for_metadata_service(self): mcfg = self.ds_cfg - if not mcfg: - mcfg = {} (max_wait, timeout) = self._get_url_settings() if max_wait <= 0: diff --git a/cloudinit/sources/DataSourceOpenStack.py b/cloudinit/sources/DataSourceOpenStack.py index f7f4590b..3af17b10 100644 --- a/cloudinit/sources/DataSourceOpenStack.py +++ b/cloudinit/sources/DataSourceOpenStack.py @@ -45,8 +45,6 @@ class DataSourceOpenStack(openstack.SourceMixin, sources.DataSource): self.version = None self.files = {} self.ec2_metadata = None - if not self.ds_cfg: - self.ds_cfg = {} def __str__(self): root = sources.DataSource.__str__(self) diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py index 82cd3553..6bf2c33b 100644 --- a/cloudinit/sources/__init__.py +++ b/cloudinit/sources/__init__.py @@ -70,6 +70,9 @@ class DataSource(object): self.ds_cfg = util.get_cfg_by_path(self.sys_cfg, ("datasource", name), {}) + if not self.ds_cfg: + self.ds_cfg = {} + if not ud_proc: self.ud_proc = ud.UserDataProcessor(self.paths) else: |