Ejemplo n.º 1
0
 def _download_pkg(self, context):
     """dowload url to context.package.dir
     """
     pkg_url = context.package.arg
     dst_file_path = context.package.full_path
     log.debug('downloading {0} to {1}'.format(pkg_url, dst_file_path))
     download_file(pkg_url, dst_file_path, context.package.get('timeout', 1))
Ejemplo n.º 2
0
 def _download_pkg(self, context):
     """dowload url to context.package.dir
     """
     pkg_url = context.package.arg
     dst_file_path = context.package.full_path
     log.debug('downloading {0} to {1}'.format(pkg_url, dst_file_path))
     download_file(pkg_url, dst_file_path, context.package.get('timeout', 1),
                   verify_https=context.get('verify_https', False))
Ejemplo n.º 3
0
    def provision(self):
        """
        overrides the base provision
          * store the chef JSON file information in the context
          * install chef from a URL if specified
          * call chef-solo
        """

        log.debug('Entering chroot at {0}'.format(self._mountpoint))

        context = self._config.context
        config = self._config
        context.package.dir = config.plugins[self.full_name].get('chef_dir', '/var/chef')

        # hold onto the JSON info as _stage_pkg mutates context.package.arg
        context.chef.setdefault('dir', context.package.dir)
        if context.package.arg.startswith('http://'):
            context.chef.setdefault('json', context.package.arg.split('/')[-1])
        else:
            context.chef.setdefault('json', context.package.arg)

        # copy the JSON file to chef_dir in the chroot.  mkdirs in case we've never installed chef
        full_chef_dir_path = self._mountpoint + context.chef.dir
        log.debug('prepping chef_dir {0}'.format(full_chef_dir_path))
        mkdirs(full_chef_dir_path)

        if not self._stage_pkg():
            log.critical('failed to stage {0}'.format(context.package.arg))
            return False

        with Chroot(self._mountpoint):
            log.debug('Inside chroot')

            # install chef if needed
            if 'chef_package_url' in context.chef:
                log.debug('chef install selected')
                # get the package name so we can dpkg -i on it
                if context.chef.chef_package_url.startswith('http://'):
                    chef_package_name = context.chef.chef_package_url.split('/')[-1]
                else:
                    chef_package_name = context.chef.chef_package_url

                local_chef_package_file = context.chef.dir + '/' + chef_package_name
                log.debug('preparing to download {0} to {1}'.format(context.chef.chef_package_url,
                                                                    local_chef_package_file))
                download_file(context.chef.chef_package_url, local_chef_package_file, context.package.get('timeout', 1))
                log.debug('preparing to do a dpkg -i {0}'.format(chef_package_name))
                dpkg_install(local_chef_package_file)

            log.debug('Preparing to run chef-solo')

            if 'recipe_url' in context.chef:
                result = chef_solo(context.chef.dir, context.chef.json, context.chef.recipe_url)
            else:
                result = chef_solo(context.chef.dir, context.chef.json, None)

            if not result.success:
                log.critical('chef-solo run failed: {0.std_err}'.format(result.result))
                return False

            self._store_package_metadata()

        log.debug('Exited chroot')

        log.info('Provisioning succeeded!')

        return True