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.
55 lines
999 B
Plaintext
55 lines
999 B
Plaintext
# qemu-img create -b fedora-23.qcow2 -f qcow2 fedora-23-scratch.qcow2
|
|
|
|
import "fmt"
|
|
import "os"
|
|
import "strings"
|
|
import "example"
|
|
|
|
$input = example.str2int(strings.trim_space(os.readfile("/tmp/cpu-count")))
|
|
$count = if $input > 8 {
|
|
8
|
|
} else {
|
|
if $input < 1 {
|
|
1
|
|
} else {
|
|
$input
|
|
}
|
|
}
|
|
|
|
file "/tmp/output" {
|
|
state => "exists",
|
|
content => fmt.printf("requesting: %d cpus\n", $count),
|
|
}
|
|
|
|
virt "mgmt4" {
|
|
uri => "qemu:///session",
|
|
cpus => $count,
|
|
maxcpus => 8,
|
|
memory => 524288,
|
|
state => "running",
|
|
transient => false,
|
|
boot => ["hd", ],
|
|
# can't add this part until we fix the unification bug
|
|
#disk => [
|
|
# struct{
|
|
# source => "~/.local/share/libvirt/images/fedora-23-scratch.qcow2",
|
|
# type => "qcow2",
|
|
# },
|
|
#],
|
|
# add the rest for unification bug
|
|
#osinit => "",
|
|
#cdrom => [
|
|
#],
|
|
#network => [
|
|
#],
|
|
#filesystem => [
|
|
#],
|
|
#auth => struct{
|
|
# username => "",
|
|
# password => "",
|
|
#},
|
|
#hotcpus => true, # this is the default
|
|
#restartondiverge => "",
|
|
#restartonrefresh => false,
|
|
}
|