From 7c52d4c28c4e63c7bc9ab38b92f08918cc8e0188 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Tue, 1 Oct 2019 08:15:01 +0200 Subject: [PATCH] Align with shell type: implement onchange --- cdist/conf/type/__file/__init__.py | 11 ++++++++++- cdist/conf/type/__file_py | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) create mode 120000 cdist/conf/type/__file_py diff --git a/cdist/conf/type/__file/__init__.py b/cdist/conf/type/__file/__init__.py index 3397b417..bcb525fc 100644 --- a/cdist/conf/type/__file/__init__.py +++ b/cdist/conf/type/__file/__init__.py @@ -52,6 +52,7 @@ class FileType(PythonType): create_file = False upload_file = False set_attributes = False + fire_onchange = False code = [] if state_should == 'present' or state_should == 'exists': if source is None: @@ -72,6 +73,7 @@ class FileType(PythonType): self.die('Source {} does not exist'.format(source)) if create_file or upload_file: set_attributes = True + fire_onchange = True tempfile_template = '{}.cdist.XXXXXXXXXX'.format(destination) destination_upload = self.run_remote( ["mktemp", tempfile_template, ]) @@ -90,6 +92,7 @@ class FileType(PythonType): value_is = self.get_attribute(stat_file, attribute, value_should) if set_attributes or value_should != value_is: + fire_onchange = True code.append(self.set_attribute(attribute, value_should, destination)) @@ -97,9 +100,15 @@ class FileType(PythonType): if typeis == 'file': code.append('rm -f {}'.format(destination)) self.send_message('remove') + fire_onchange = True else: self.die('Unknown state {}'.format(state_should)) + if fire_onchange: + onchange = self.get_parameter('onchange') + if onchange: + code.append(onchange) + return "\n".join(code) def get_args_parser(self): @@ -107,7 +116,7 @@ class FileType(PythonType): argument_default=argparse.SUPPRESS) parser.add_argument('--state', dest='state', action='store', required=False, default='present') - for param in ('group', 'mode', 'owner', 'source'): + for param in ('group', 'mode', 'owner', 'source', 'onchange'): parser.add_argument('--' + param, dest=param, action='store', required=False, default=None) diff --git a/cdist/conf/type/__file_py b/cdist/conf/type/__file_py new file mode 120000 index 00000000..efa910bd --- /dev/null +++ b/cdist/conf/type/__file_py @@ -0,0 +1 @@ +__file \ No newline at end of file