def _install(self, bootstrap_url, bootstrap_file = 'bootstrap.sh'):
        """ Installs saltstack using bootstrap url
        """

        tmp_dir = mkdtemp()
        bootstrap_file = tmp_dir + '/' + bootstrap_file
        ecm.download_file(bootstrap_url, bootstrap_file)

        # wget -O - http://bootstrap.saltstack.org | sudo sh

        # Options:
        #-h  Display this message
        #-v  Display script version
        #-n  No colours.
        #-D  Show debug output.
        #-c  Temporary configuration directory
        #-g  Salt repository URL. (default: git://github.com/saltstack/salt.git)
        #-k  Temporary directory holding the minion keys which will pre-seed the master.
        #-M  Also install salt-master
        #-S  Also install salt-syndic
        #-N  Do not install salt-minion
        #-X  Do not start daemons after installation
        #-C  Only run the configuration function. This option automatically bypasses any installation.
        #-P  Allow pip based installations. On some distributions the required salt packages or its dependencies are not available as a package for that distribution. Using this flag allows the script to use pip as a last resort method. NOTE: This works for functions which actually implement pip based installations.
        #-F  Allow copied files to overwrite existing(config, init.d, etc)
        #-U  If set, fully upgrade the system prior to bootstrapping salt
        #-K  If set, keep the temporary files in the temporary directories specified with -c and -k.

        if ecm.file_read(bootstrap_file):
            envars = {'DEBIAN_FRONTEND': 'noninteractive'}
            ecm.run_file(bootstrap_file, args=['-n', '-P', '-X'], envars=envars)

        rmtree(tmp_dir)
        return bool(self._is_available())
    def _install(self, bootstrap_url, bootstrap_file = 'bootstrap.sh'):
        """ Installs puppet using bootstrap url
        """
        tmp_dir = mkdtemp()
        bootstrap_file = tmp_dir + '/' + bootstrap_file
        ecm.download_file(bootstrap_url, bootstrap_file)

        # wget -O - http://bootstrap.ecmanaged.com/puppet/linux/ | sudo sh

        if ecm.file_read(bootstrap_file):
            envars = {'DEBIAN_FRONTEND': 'noninteractive'}
            ecm.run_file(bootstrap_file, envars=envars)

        rmtree(tmp_dir)
        return bool(self._is_available())
    def clone(self, branch, envars, url, username, password, private_key):
        """ Downloads a file from a remote url and decompress it
        """
        file_name = 'downloaded.file'
        tmp_dir = mkdtemp()

        file_downloaded = ecm.download_file(
            url=url,
            filename=tmp_dir + '/' + file_name,
            user=username,
            passwd=password
        )

        if file_downloaded:
            extract = self._extract(file_downloaded)
            if extract:
                extract['head'] = ''
                if extract.get('stdout', None):
                    extract['head'] = ecm.output("Source deployed successfully to '%s'" % self.working_dir)

                if extract.get('stdout', None) and self.old_dir:
                    extract['head'] += ecm.output("Old source files moved to '%s'" % self.old_dir)

        else:
            rmtree(tmp_dir, ignore_errors=True)
            raise Exception("Unable to download file")

        # Clean and output
        rmtree(tmp_dir, ignore_errors=True)
        ret = {
            'stdout': extract.get('head', '') + extract.get('stdout', ''),
            'stderr': extract.get('stderr', 'Unable to download file'),
            'out': extract.get('out', 1)
        }
        return ret
    def cmd_puppet_apply_file(self, *argv, **kwargs):
        """
        Syntax: puppet.apply_file[recipe_url,envars,facts]
        """
        recipe_url = kwargs.get('recipe_url', None)
        envars = kwargs.get('envars', None)
        facts = kwargs.get('facts', None)

        if not recipe_url:
            raise ecm.InvalidParameters(self.cmd_puppet_apply.__doc__)

        recipe_file = None
        recipe_path = None
        module_path = MODULES_PATH
        if ecm.is_windows(): module_path = MODULES_PATH_WINDOWS
        module_path = kwargs.get('module_path', module_path)

        # Set environment variables before execution
        envars = ecm.envars_decode(envars)
        facts = ecm.envars_decode(facts)

        # Update envars and facts file
        ecm.write_envars_facts(envars, facts)

        try:
            # Download recipe url
            recipe_path = mkdtemp()
            tmp_file = recipe_path + '/recipe.tar.gz'

            if ecm.download_file(recipe_url, tmp_file):
                if tarfile.is_tarfile(tmp_file):
                    tar = tarfile.open(tmp_file)
                    tar.extractall(path=recipe_path)

                    for file_name in tar.getnames():
                        if file_name.endswith('.catalog.pson'):
                            recipe_file = file_name
                    tar.close()

                    # Apply puppet catalog
                    return self._run_catalog(recipe_file, recipe_path, module_path=module_path, envars=envars)
                else:
                    raise Exception("Invalid recipe tgz file")
            else:
                raise Exception("Unable to download file")

        except:
            raise Exception("Unable to get recipe")

        finally:
            rmtree(recipe_path, ignore_errors=True)