This adds the first reversible resource (file) and the necessary engine API hooks to make it all work. This allows a special "reversed" resource to be added to the subsequent graph in the stream when an earlier version "disappears". This disappearance can happen if it was previously in an if statement that then becomes false. It might be wise to combine the use of this meta parameter with the use of the `realize` meta parameter to ensure that your reversed resource actually runs at least once, if there's a chance that it might be gone for a while. This patch also adds a new test harness for testing resources. It doesn't test the "live" aspect of resources, as it doesn't run Watch, but it was designed to ensure CheckApply works as intended, and it runs very quickly with a simplified timeline of happenings.
26 lines
524 B
Plaintext
26 lines
524 B
Plaintext
import "datetime"
|
|
import "math"
|
|
|
|
$now = datetime.now()
|
|
|
|
# alternate every four seconds
|
|
$mod0 = math.mod($now, 8) == 0
|
|
$mod1 = math.mod($now, 8) == 1
|
|
$mod2 = math.mod($now, 8) == 2
|
|
$mod3 = math.mod($now, 8) == 3
|
|
$mod = $mod0 || $mod1 || $mod2 || $mod3
|
|
|
|
file "/tmp/mgmt/" {
|
|
state => "exists",
|
|
}
|
|
|
|
# file should re-appear and disappear every four seconds
|
|
# it will even preserve and then restore the pre-existing content!
|
|
if $mod {
|
|
file "/tmp/mgmt/hello" {
|
|
state => "absent", # delete the file
|
|
|
|
Meta:reverse => true,
|
|
}
|
|
}
|