summaryrefslogtreecommitdiff
path: root/libvirt/domain_def.go
blob: 97485a6b925e4c6f3bc32f4df67cf3ce17084a59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package libvirt

import (
	"encoding/xml"
)

type defDomain struct {
	XMLName  xml.Name  `xml:"domain"`
	Name     string    `xml:"name"`
	Type     string    `xml:"type,attr"`
	Os       defOs     `xml:"os"`
	Memory   defMemory `xml:"memory"`
	VCpu     defVCpu   `xml:"vcpu"`
	Metadata struct {
		XMLName          xml.Name `xml:"metadata"`
		TerraformLibvirt defMetadata
	}
	Features struct {
		Acpi string `xml:"acpi"`
		Apic string `xml:"apic"`
		Pae  string `xml:"pae"`
	} `xml:"features"`
	Devices struct {
		Disks             []defDisk             `xml:"disk"`
		NetworkInterfaces []defNetworkInterface `xml:"interface"`
		Graphics struct {
			Type   string `xml:"type,attr"`
			Listen struct {
				Type string `xml:"type,attr"`
			} `xml:"listen"`
		} `xml:"graphics"`
		// QEMU guest agent channel
		QemuGAChannel struct {
			Type   string `xml:"type,attr"`
			Source struct {
				Mode string `xml:"mode,attr"`
			} `xml:"source"`
			Target struct {
				Type string `xml:"type,attr"`
				Name string `xml:"name,attr"`
			} `xml:"target"`
		} `xml:"channel"`
		Rng struct {
			Model   string `xml:"model,attr"`
			Backend struct {
				Model string `xml:"model,attr"`
			} `xml:"backend"`
		} `xml:"rng"`
	} `xml:"devices"`
}

type defMetadata struct {
	XMLName xml.Name `xml:"http://github.com/dmacvicar/terraform-provider-libvirt/ user_data"`
	Xml     string   `xml:",cdata"`
}

type defOs struct {
	Type   defOsType  `xml:"type"`
	Loader *defLoader `xml:"loader,omitempty"`
	NvRam  *defNvRam  `xml:"nvram,omitempty"`
}

type defOsType struct {
	Arch    string `xml:"arch,attr,omitempty"`
	Machine string `xml:"machine,attr,omitempty"`
	Name    string `xml:",chardata"`
}

type defMemory struct {
	Unit   string `xml:"unit,attr"`
	Amount int    `xml:",chardata"`
}

type defVCpu struct {
	Placement string `xml:"unit,attr"`
	Amount    int    `xml:",chardata"`
}

type defLoader struct {
	ReadOnly string `xml:"readonly,attr,omitempty"`
	Type     string `xml:"type,attr,omitempty"`
	File     string `xml:",chardata"`
}

// <nvram>/var/lib/libvirt/qemu/nvram/sled12sp1_VARS.fd</nvram>
type defNvRam struct {
	File string `xml:",chardata"`
}

// Creates a domain definition with the defaults
// the provider uses
func newDomainDef() defDomain {
	// libvirt domain definition
	domainDef := defDomain{}
	domainDef.Type = "kvm"

	domainDef.Os = defOs{}
	domainDef.Os.Type = defOsType{}
	domainDef.Os.Type.Name = "hvm"

	domainDef.Memory = defMemory{}
	domainDef.Memory.Unit = "MiB"
	domainDef.Memory.Amount = 512

	domainDef.VCpu = defVCpu{}
	domainDef.VCpu.Placement = "static"
	domainDef.VCpu.Amount = 1

	domainDef.Devices.Graphics.Type = "spice"
	domainDef.Devices.Graphics.Listen.Type = "none"

	domainDef.Devices.QemuGAChannel.Type = "unix"
	domainDef.Devices.QemuGAChannel.Source.Mode = "bind"
	domainDef.Devices.QemuGAChannel.Target.Type = "virtio"
	domainDef.Devices.QemuGAChannel.Target.Name = "org.qemu.guest_agent.0"

	domainDef.Devices.Rng.Model = "virtio"
	domainDef.Devices.Rng.Backend.Model = "random"

	return domainDef
}