mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Added cache_file option
This commit is contained in:
parent
d3ba23e304
commit
407f6a738c
@ -466,11 +466,6 @@ def install(name=None, refresh=False, pkgs=None, saltenv='base', **kwargs):
|
||||
install. (no spaces after the commas)
|
||||
:type name: str, list, or None
|
||||
|
||||
:param str version:
|
||||
The specific version to install. If omitted, the latest version will be
|
||||
installed. If passed with multiple install, the version will apply to
|
||||
all packages. Recommended for single installation only.
|
||||
|
||||
:param bool refresh: Boolean value representing whether or not to refresh
|
||||
the winrepo db
|
||||
|
||||
@ -481,8 +476,24 @@ def install(name=None, refresh=False, pkgs=None, saltenv='base', **kwargs):
|
||||
|
||||
:param str saltenv: The salt environment to use. Default is ``base``.
|
||||
|
||||
:param dict kwargs: Any additional argument that may be passed from the
|
||||
state module. If they don't apply, they are ignored.
|
||||
*Keyword Arguments (kwargs)*
|
||||
|
||||
:param str version:
|
||||
The specific version to install. If omitted, the latest version will be
|
||||
installed. If passed with multiple install, the version will apply to
|
||||
all packages. Recommended for single installation only.
|
||||
|
||||
:param str cache_file:
|
||||
A single file to copy down for use with the installer. Copied to the
|
||||
same location as the installer. Use this over ``cache_dir`` if there
|
||||
are many files in the directory and you only need a specific file and
|
||||
don't want to cache additional files that may reside in the installer
|
||||
directory. Only applies to files on ``salt://``
|
||||
|
||||
:param bool cache_dir:
|
||||
True will copy the contents of the installer directory. This is useful
|
||||
for installations that are not a single file. Only applies to
|
||||
directories on ``salt://``
|
||||
|
||||
:return: Return a dict containing the new package names and versions::
|
||||
:rtype: dict
|
||||
@ -512,6 +523,40 @@ def install(name=None, refresh=False, pkgs=None, saltenv='base', **kwargs):
|
||||
salt '*' pkg.install 7zip
|
||||
salt '*' pkg.install 7zip,filezilla
|
||||
salt '*' pkg.install pkgs='["7zip","filezilla"]'
|
||||
|
||||
WinRepo Definition File Examples:
|
||||
|
||||
The following example demonstrates the use of ``cache_file``. This would be
|
||||
used if you have multiple installers in the same directory that use the same
|
||||
``install.ini`` file and you don't want to download the additional
|
||||
installers.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
ntp:
|
||||
4.2.8:
|
||||
installer: 'salt://win/repo/ntp/ntp-4.2.8-win32-setup.exe'
|
||||
full_name: Meinberg NTP Windows Client
|
||||
locale: en_US
|
||||
reboot: False
|
||||
cache_file: 'salt://win/repo/ntp/install.ini'
|
||||
install_flags: '/USEFILE=C:\salt\var\cache\salt\minion\files\base\win\repo\ntp\install.ini'
|
||||
uninstaller: 'NTP/uninst.exe'
|
||||
|
||||
The following example demonstrates the use of ``cache_dir``. It assumes a
|
||||
file named ``install.ini`` resides in the same directory as the installer.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
ntp:
|
||||
4.2.8:
|
||||
installer: 'salt://win/repo/ntp/ntp-4.2.8-win32-setup.exe'
|
||||
full_name: Meinberg NTP Windows Client
|
||||
locale: en_US
|
||||
reboot: False
|
||||
cache_dir: True
|
||||
install_flags: '/USEFILE=C:\salt\var\cache\salt\minion\files\base\win\repo\ntp\install.ini'
|
||||
uninstaller: 'NTP/uninst.exe'
|
||||
'''
|
||||
ret = {}
|
||||
if refresh:
|
||||
@ -573,8 +618,10 @@ def install(name=None, refresh=False, pkgs=None, saltenv='base', **kwargs):
|
||||
ret[pkg_name] = {'not found': version_num}
|
||||
continue
|
||||
|
||||
# Get the installer
|
||||
installer = pkginfo[version_num].get('installer')
|
||||
# Get the installer settings from winrepo.p
|
||||
installer = pkginfo[version_num].get('installer', False)
|
||||
cache_dir = pkginfo[version_num].get('cache_dir', False)
|
||||
cache_file = pkginfo[version_num].get('cache_file', False)
|
||||
|
||||
# Is there an installer configured?
|
||||
if not installer:
|
||||
@ -590,11 +637,29 @@ def install(name=None, refresh=False, pkgs=None, saltenv='base', **kwargs):
|
||||
# If true, the entire directory will be cached instead of the
|
||||
# individual file. This is useful for installations that are not
|
||||
# single files
|
||||
cache_dir = pkginfo[version_num].get('cache_dir')
|
||||
if cache_dir and installer.startswith('salt:'):
|
||||
path, _ = os.path.split(installer)
|
||||
__salt__['cp.cache_dir'](path, saltenv, False, None, 'E@init.sls$')
|
||||
|
||||
# Check to see if the cache_file is cached... if passed
|
||||
if cache_file and cache_file.startswith('salt:'):
|
||||
|
||||
# Check to see if the file is cached
|
||||
cached_file = __salt__['cp.is_cached'](cache_file, saltenv)
|
||||
if not cached_file:
|
||||
cached_file = __salt__{'cp.cache_file'}(cache_file, saltenv)
|
||||
|
||||
# Make sure the cached file is the same as the source
|
||||
if __salt__['cp.hash_file'](cache_file, saltenv) != \
|
||||
__salt__['cp.hash_file'](cached_file):
|
||||
cached_file = __salt__['cp.cache_file'](cache_file, saltenv)
|
||||
|
||||
# Check if the cache_file was cached successfully
|
||||
if not cached_file:
|
||||
log.error('Unable to cache {0}'.format(cache_file))
|
||||
ret[pkg_name] = {'failed to cache cache_file': cache_file}
|
||||
continue
|
||||
|
||||
# Check to see if the installer is cached
|
||||
cached_pkg = __salt__['cp.is_cached'](installer, saltenv)
|
||||
if not cached_pkg:
|
||||
|
Loading…
Reference in New Issue
Block a user