-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
defaults.go
82 lines (69 loc) · 1.64 KB
/
defaults.go
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
package api
const (
DefaultProtocol = "TCP"
DefaultVMCIDR = "10.0.2.0/24"
DefaultVMIpv6CIDR = "fd10:0:2::/120"
DefaultBridgeName = "k6t-eth0"
)
func NewDefaulter(arch string) *Defaulter {
return &Defaulter{Architecture: arch}
}
type Defaulter struct {
Architecture string
}
func (d *Defaulter) IsPPC64() bool {
if d.Architecture == "ppc64le" {
return true
}
return false
}
func (d *Defaulter) IsARM64() bool {
if d.Architecture == "arm64" {
return true
}
return false
}
func (d *Defaulter) SetDefaults_Devices(devices *Devices) {
}
func (d *Defaulter) SetDefaults_OSType(ostype *OSType) {
ostype.OS = "hvm"
if ostype.Arch == "" {
if d.IsPPC64() {
ostype.Arch = "ppc64le"
} else if d.IsARM64() {
ostype.Arch = "aarch64"
} else {
ostype.Arch = "x86_64"
}
}
// q35 is an alias of the newest q35 machine type.
// TODO: we probably want to select concrete type in the future for "future-backwards" compatibility.
if ostype.Machine == "" {
if d.IsPPC64() {
ostype.Machine = "pseries"
} else if d.IsARM64() {
ostype.Machine = "virt"
} else {
ostype.Machine = "q35"
}
}
}
func (d *Defaulter) SetDefaults_DomainSpec(spec *DomainSpec) {
spec.XmlNS = "http://libvirt.org/schemas/domain/qemu/1.0"
if spec.Type == "" {
spec.Type = "kvm"
}
}
func (d *Defaulter) SetDefaults_SysInfo(sysinfo *SysInfo) {
if sysinfo.Type == "" {
sysinfo.Type = "smbios"
}
}
func (d *Defaulter) SetObjectDefaults_Domain(in *Domain) {
d.SetDefaults_DomainSpec(&in.Spec)
d.SetDefaults_OSType(&in.Spec.OS.Type)
if in.Spec.SysInfo != nil {
d.SetDefaults_SysInfo(in.Spec.SysInfo)
}
d.SetDefaults_Devices(&in.Spec.Devices)
}