1#
2# Management of KVM/QEMU virtual machines
3# Assumes you already have a disk image (with an OS installed) for the machine on creation
4#
5
6
7body common control
8{
9      bundlesequence => { "kvm_create" };
10}
11
12
13bundle agent kvm_create
14{
15
16  guest_environments:
17      "my_host_machine"
18      environment_resources => mykvm("my_host_machine", "x86_64", "1", "1048576", "/var/lib/libvirt/images/ubuntu104-64-clone.img"),
19      environment_type      => "kvm",
20      environment_state     => "create",
21      environment_host      => "ubuntu";
22}
23
24
25bundle agent kvm_suspend
26{
27  guest_environments:
28      "my_host_machine"
29      environment_type      => "kvm",
30      environment_state     => "suspended",
31      environment_host      => "ubuntu";
32}
33
34
35bundle agent kvm_run
36{
37  guest_environments:
38      "my_host_machine"
39      environment_type      => "kvm",
40      environment_state     => "running",
41      environment_host      => "ubuntu";
42}
43
44
45bundle agent kvm_delete
46{
47  guest_environments:
48      "my_host_machine"
49      environment_type      => "kvm",
50      environment_state     => "delete",
51      environment_host      => "ubuntu";
52}
53
54
55body environment_resources mykvm(name, arch, cpu_count, mem_kb, disk_file)
56{
57      env_spec =>
58      "<domain type='kvm'>
59  <name>$(name)</name>
60  <memory>$(mem_kb)</memory>
61  <currentMemory>$(mem_kb)</currentMemory>
62  <vcpu>$(cpu_count)</vcpu>
63  <os>
64    <type arch='$(arch)'>hvm</type>
65  </os>
66  <features>
67    <acpi/>
68    <apic/>
69    <pae/>
70  </features>
71  <on_poweroff>destroy</on_poweroff>
72  <on_reboot>restart</on_reboot>
73  <on_crash>restart</on_crash>
74  <devices>
75    <emulator>/usr/bin/kvm</emulator>
76    <disk type='file' device='disk'>
77      <source file='$(disk_file)'/>
78      <target dev='vda' bus='virtio'/>
79    </disk>
80    <interface type='network'>
81      <source network='default'/>
82    </interface>
83    <input type='mouse' bus='ps2'/>
84    <graphics type='vnc' port='-1' autoport='yes'/>
85  </devices>
86</domain>";
87}
88
89