This might be slightly controversial, in that you must specify the state if a file would need to be created to perform the action. We no longer implicitly assume that just specifying content is enough. As it turns out, I believe this is safer and more correct. The code to implement this turns out to be much more logical and simplified, and does this removes an ambiguous corner case from the reversed resource code. Some discussion in: https://github.com/purpleidea/mgmt/issues/540 This patch also does a bit of related cleanup.
35 lines
767 B
Plaintext
35 lines
767 B
Plaintext
import "sys"
|
|
|
|
file "/tmp/mgmt/systemload" {
|
|
state => "exists",
|
|
content => template("load average: {{ .load }} threshold: {{ .threshold }}\n", $tmplvalues),
|
|
}
|
|
|
|
$tmplvalues = struct{load => $theload, threshold => $threshold,}
|
|
|
|
$theload = structlookup(sys.load(), "x1")
|
|
$threshold = 1.5 # change me if you like
|
|
|
|
# simple hysteresis implementation
|
|
$h1 = $theload > $threshold
|
|
$h2 = $theload{1} > $threshold
|
|
$h3 = $theload{2} > $threshold
|
|
$unload = $h1 || $h2 || $h3
|
|
|
|
virt "mgmt1" {
|
|
uri => "qemu:///session",
|
|
cpus => 1,
|
|
memory => 524288,
|
|
state => "running",
|
|
transient => true,
|
|
}
|
|
|
|
# this vm shuts down under load...
|
|
virt "mgmt2" {
|
|
uri => "qemu:///session",
|
|
cpus => 1,
|
|
memory => 524288,
|
|
state => if $unload { "shutoff" } else { "running" },
|
|
transient => true,
|
|
}
|