examples: Improve dynamic cpus virt example
This commit is contained in:
53
examples/lang/virt2.mcl
Normal file
53
examples/lang/virt2.mcl
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
# 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" {
|
||||||
|
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,
|
||||||
|
}
|
||||||
@@ -7,28 +7,8 @@ count=1 # initial count
|
|||||||
factor=3
|
factor=3
|
||||||
function output() {
|
function output() {
|
||||||
count=$1 # arg!
|
count=$1 # arg!
|
||||||
cat << EOF > ~/code/mgmt/examples/yaml/virt4.yaml
|
cat << EOF > /tmp/cpu-count
|
||||||
---
|
$count
|
||||||
graph: mygraph
|
|
||||||
resources:
|
|
||||||
virt:
|
|
||||||
- name: mgmt4
|
|
||||||
meta:
|
|
||||||
limit: .inf
|
|
||||||
burst: 0
|
|
||||||
uri: 'qemu:///session'
|
|
||||||
cpus: $count
|
|
||||||
maxcpus: $maximum
|
|
||||||
memory: 524288
|
|
||||||
boot:
|
|
||||||
- hd
|
|
||||||
disk:
|
|
||||||
- type: qcow2
|
|
||||||
source: "~/.local/share/libvirt/images/fedora-23-scratch.qcow2"
|
|
||||||
state: running
|
|
||||||
transient: false
|
|
||||||
edges: []
|
|
||||||
comment: "qemu-img create -b fedora-23.qcow2 -f qcow2 fedora-23-scratch.qcow2"
|
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
#tput cuu 1 && tput el # remove last line
|
#tput cuu 1 && tput el # remove last line
|
||||||
|
|||||||
Reference in New Issue
Block a user