summaryrefslogtreecommitdiff
path: root/libvirt/domain_def.go
diff options
context:
space:
mode:
authorDean Smith <dean@zelotus.com>2017-09-08 12:49:37 +0100
committerDean Smith <dean@zelotus.com>2017-09-19 18:17:24 +0100
commit4d165b1838e4281d3a9847bc9a14d1ffe07a773c (patch)
tree952ce7015ca20e955e6746f13764106a73fa4e0f /libvirt/domain_def.go
parenta605a9eb1332875feb9175563c7778d909ef5514 (diff)
downloadterraform-provider-libvirt-4d165b1838e4281d3a9847bc9a14d1ffe07a773c.tar
terraform-provider-libvirt-4d165b1838e4281d3a9847bc9a14d1ffe07a773c.tar.gz
Full support for arch,machine & emulator settings
Add emulator setting support Completes support from arch and machine when reading current status Adds a new function newDomainDefForConnection that takes a domainDef and populates with defaults from the current host which is more sensible than guessing across distributions Maps canonical machine types <> actual to avoid changes Due to the way libvirt works if you specific machine types like pc,isapc or q35 these get translated into 'canonical' forms, ie. the latest version When quering terraform will notice a change, as it would still be looking for pc and will get something like pc-i440fx-2.9. Code has been added to assume that if we see 'pc-i440fx-2.9' and it is canonical for pc then we translate back to pc for terraform. This could cause issues if you are specifically using pc-i440fx-2.9 as the machine type in your terraform file.
Diffstat (limited to 'libvirt/domain_def.go')
-rw-r--r--libvirt/domain_def.go29
1 files changed, 26 insertions, 3 deletions
diff --git a/libvirt/domain_def.go b/libvirt/domain_def.go
index 250fc642..1ade1f5a 100644
--- a/libvirt/domain_def.go
+++ b/libvirt/domain_def.go
@@ -1,9 +1,9 @@
package libvirt
import (
+ libvirt "github.com/libvirt/libvirt-go"
+ libvirtxml "github.com/libvirt/libvirt-go-xml"
"os"
-
- "github.com/libvirt/libvirt-go-xml"
)
func newFilesystemDef() libvirtxml.DomainFilesystem {
@@ -20,7 +20,9 @@ func newDomainDef() libvirtxml.Domain {
domainDef := libvirtxml.Domain{
OS: &libvirtxml.DomainOS{
Type: &libvirtxml.DomainOSType{
- Type: "hvm",
+ Type: "hvm",
+ Arch: "x86_64",
+ Machine: "pc",
},
},
Memory: &libvirtxml.DomainMemory{
@@ -75,3 +77,24 @@ func newDomainDef() libvirtxml.Domain {
return domainDef
}
+
+func newDomainDefForConnection(virConn *libvirt.Connect) (libvirtxml.Domain, error) {
+ d := newDomainDef()
+ caps, err := getHostCapabilities(virConn)
+ if err != nil {
+ return d, err
+ }
+ guest, err := getGuestForArchType(caps, d.OS.Type.Arch, d.OS.Type.Type)
+ if err != nil {
+ return d, err
+ }
+
+ d.Devices.Emulator = guest.Arch.Emulator
+
+ canonicalmachine, err := getCanonicalMachineName(caps, d.OS.Type.Arch, d.OS.Type.Type, d.OS.Type.Machine)
+ if err != nil {
+ return d, err
+ }
+ d.OS.Type.Machine = canonicalmachine
+ return d, nil
+}