mirror of
https://github.com/valitydev/salt.git
synced 2024-11-06 16:45:27 +00:00
Add to file.managed docstring, rename static_contents to contents
This commit is contained in:
parent
6176129fbc
commit
61e955e4fe
@ -1326,7 +1326,7 @@ def check_managed(
|
||||
context,
|
||||
defaults,
|
||||
env,
|
||||
static_contents=None,
|
||||
contents=None,
|
||||
**kwargs):
|
||||
'''
|
||||
Check to see what changes need to be made for a file
|
||||
@ -1340,7 +1340,7 @@ def check_managed(
|
||||
|
||||
sfn, source_sum, comment = '', None, ''
|
||||
|
||||
if static_contents is None:
|
||||
if contents is None:
|
||||
# Gather the source file from the server
|
||||
sfn, source_sum, comment = get_managed(
|
||||
name,
|
||||
@ -1358,7 +1358,7 @@ def check_managed(
|
||||
__clean_tmp(sfn)
|
||||
return False, comment
|
||||
changes = check_file_meta(name, sfn, source, source_sum, user,
|
||||
group, mode, env, template, static_contents)
|
||||
group, mode, env, template, contents)
|
||||
__clean_tmp(sfn)
|
||||
if changes:
|
||||
comment = 'The following values are set to be changed:\n'
|
||||
@ -1378,7 +1378,7 @@ def check_file_meta(
|
||||
mode,
|
||||
env,
|
||||
template=None,
|
||||
static_contents=None):
|
||||
contents=None):
|
||||
'''
|
||||
Check for the changes in the file metadata.
|
||||
|
||||
@ -1412,11 +1412,11 @@ def check_file_meta(
|
||||
''.join(difflib.unified_diff(nlines, slines)))
|
||||
else:
|
||||
changes['sum'] = 'Checksum differs'
|
||||
if not static_contents is None:
|
||||
if not contents is None:
|
||||
# Write a tempfile with the static contents
|
||||
tmp = salt.utils.mkstemp(text=True)
|
||||
with salt.utils.fopen(tmp, 'w') as tmp_:
|
||||
tmp_.write(static_contents)
|
||||
tmp_.write(contents)
|
||||
# Compare the static contents with the named file
|
||||
with contextlib.nested(
|
||||
salt.utils.fopen(tmp, 'rb'),
|
||||
@ -1486,7 +1486,7 @@ def manage_file(name,
|
||||
backup,
|
||||
template=None,
|
||||
show_diff=True,
|
||||
static_contents=None):
|
||||
contents=None):
|
||||
'''
|
||||
Checks the destination against what was retrieved with get_managed and
|
||||
makes the appropriate modifications (if necessary).
|
||||
@ -1557,11 +1557,11 @@ def manage_file(name,
|
||||
return _error(
|
||||
ret, 'Failed to commit change, permission error')
|
||||
|
||||
if not static_contents is None:
|
||||
if not contents is None:
|
||||
# Write the static contents to a temporary file
|
||||
tmp = salt.utils.mkstemp(text=True)
|
||||
with salt.utils.fopen(tmp, 'w') as tmp_:
|
||||
tmp_.write(static_contents)
|
||||
tmp_.write(contents)
|
||||
|
||||
# Compare contents of files to know if we need to replace
|
||||
with contextlib.nested(
|
||||
@ -1647,7 +1647,7 @@ def manage_file(name,
|
||||
current_umask = os.umask(63)
|
||||
|
||||
# Create a new file when test is False and source is None
|
||||
if static_contents is None:
|
||||
if contents is None:
|
||||
if not __opts__['test']:
|
||||
if __salt__['file.touch'](name):
|
||||
ret['changes']['new'] = 'file {0} created'.format(name)
|
||||
@ -1668,11 +1668,11 @@ def manage_file(name,
|
||||
if mode:
|
||||
os.umask(current_umask)
|
||||
|
||||
if not static_contents is None:
|
||||
if not contents is None:
|
||||
# Write the static contents to a temporary file
|
||||
tmp = salt.utils.mkstemp(text=True)
|
||||
with salt.utils.fopen(tmp, 'w') as tmp_:
|
||||
tmp_.write(static_contents)
|
||||
tmp_.write(contents)
|
||||
# Copy into place
|
||||
salt.utils.copyfile(
|
||||
tmp,
|
||||
|
@ -612,7 +612,7 @@ def managed(name,
|
||||
backup='',
|
||||
show_diff=True,
|
||||
create=True,
|
||||
static_contents=None,
|
||||
contents=None,
|
||||
**kwargs):
|
||||
'''
|
||||
Manage a given file, this function allows for a file to be downloaded from
|
||||
@ -690,6 +690,11 @@ def managed(name,
|
||||
create
|
||||
Default is True, if create is set to False then the file will only be
|
||||
managed if the file already exists on the system.
|
||||
|
||||
contents
|
||||
Default is None. If specified, will use the given string as the
|
||||
contents of the file. Should not be used in conjunction with a source
|
||||
file of any kind. Ignores hashes and does not use a templating engine.
|
||||
'''
|
||||
user = _test_owner(kwargs, user=user)
|
||||
# Initial set up
|
||||
@ -760,7 +765,7 @@ def managed(name,
|
||||
context,
|
||||
defaults,
|
||||
env,
|
||||
static_contents,
|
||||
contents,
|
||||
**kwargs
|
||||
)
|
||||
return ret
|
||||
@ -786,7 +791,7 @@ def managed(name,
|
||||
defaults,
|
||||
**kwargs
|
||||
)
|
||||
if comment and not static_contents is None:
|
||||
if comment and not contents is None:
|
||||
return _error(ret, comment)
|
||||
else:
|
||||
return __salt__['file.manage_file'](name,
|
||||
@ -801,7 +806,7 @@ def managed(name,
|
||||
backup,
|
||||
template,
|
||||
show_diff,
|
||||
static_contents)
|
||||
contents)
|
||||
|
||||
|
||||
def directory(name,
|
||||
|
Loading…
Reference in New Issue
Block a user