summaryrefslogtreecommitdiff
path: root/libvirt/resource_libvirt_domain.go
diff options
context:
space:
mode:
Diffstat (limited to 'libvirt/resource_libvirt_domain.go')
-rw-r--r--libvirt/resource_libvirt_domain.go49
1 files changed, 42 insertions, 7 deletions
diff --git a/libvirt/resource_libvirt_domain.go b/libvirt/resource_libvirt_domain.go
index 64f1b914..fadc62a6 100644
--- a/libvirt/resource_libvirt_domain.go
+++ b/libvirt/resource_libvirt_domain.go
@@ -148,12 +148,14 @@ func resourceLibvirtDomain() *schema.Resource {
Required: false,
},
"machine": &schema.Schema{
- Type: schema.TypeString,
+ Type: schema.TypeString,
Optional: true,
+ Default: "pc",
},
"arch": &schema.Schema{
- Type: schema.TypeString,
+ Type: schema.TypeString,
Optional: true,
+ Default: "x86_64",
},
"boot_device": &schema.Schema{
Type: schema.TypeList,
@@ -163,6 +165,11 @@ func resourceLibvirtDomain() *schema.Resource {
Schema: bootDeviceSchema(),
},
},
+ "emulator": &schema.Schema{
+ Type: schema.TypeString,
+ Default: "/usr/bin/qemu-system-x86_64",
+ Optional: true,
+ },
},
}
}
@@ -208,8 +215,10 @@ func resourceLibvirtDomainCreate(d *schema.ResourceData, meta interface{}) error
return fmt.Errorf("The libvirt connection was nil.")
}
- domainDef := newDomainDef()
-
+ domainDef, err := newDomainDefForConnection(virConn)
+ if err != nil {
+ return err
+ }
if name, ok := d.GetOk("name"); ok {
domainDef.Name = name.(string)
}
@@ -270,7 +279,8 @@ func resourceLibvirtDomainCreate(d *schema.ResourceData, meta interface{}) error
domainDef.OS.Type.Arch = d.Get("arch").(string)
domainDef.OS.Type.Machine = d.Get("machine").(string)
-
+ domainDef.Devices.Emulator = d.Get("emulator").(string)
+
if firmware, ok := d.GetOk("firmware"); ok {
firmwareFile := firmware.(string)
if _, err := os.Stat(firmwareFile); os.IsNotExist(err) {
@@ -811,7 +821,11 @@ func resourceLibvirtDomainRead(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] read: obtained XML desc for domain:\n%s", xmlDesc)
- domainDef := newDomainDef()
+ domainDef, err := newDomainDefForConnection(virConn)
+ if err != nil {
+ return err
+ }
+
err = xml.Unmarshal([]byte(xmlDesc), &domainDef)
if err != nil {
return fmt.Errorf("Error reading libvirt domain XML description: %s", err)
@@ -828,7 +842,24 @@ func resourceLibvirtDomainRead(d *schema.ResourceData, meta interface{}) error {
d.Set("firmware", domainDef.OS.Loader)
d.Set("nvram", domainDef.OS.NVRam)
d.Set("cpu", domainDef.CPU)
+ d.Set("arch", domainDef.OS.Type.Arch)
d.Set("autostart", autostart)
+ d.Set("arch", domainDef.OS.Type.Arch)
+
+ caps, err := getHostCapabilities(virConn)
+ if err != nil {
+ return err
+ }
+ machine, err := getOriginalMachineName(caps, domainDef.OS.Type.Arch, domainDef.OS.Type.Type,
+ domainDef.OS.Type.Machine)
+ if err != nil {
+ return err
+ }
+ d.Set("machine", machine)
+
+ // Emulator is the same as the default don't set it in domainDef
+ // or it will show as changed
+ d.Set("emulator", domainDef.Devices.Emulator)
running, err := isDomainRunning(*domain)
if err != nil {
@@ -1009,7 +1040,11 @@ func resourceLibvirtDomainDelete(d *schema.ResourceData, meta interface{}) error
return fmt.Errorf("Error retrieving libvirt domain XML description: %s", err)
}
- domainDef := newDomainDef()
+ domainDef, err := newDomainDefForConnection(virConn)
+ if err != nil {
+ return err
+ }
+
err = xml.Unmarshal([]byte(xmlDesc), &domainDef)
if err != nil {
return fmt.Errorf("Error reading libvirt domain XML description: %s", err)