diff options
author | Thomas Hipp <thipp@suse.de> | 2017-02-22 13:20:09 +0100 |
---|---|---|
committer | Thomas Hipp <thipp@suse.de> | 2017-03-15 13:59:59 +0100 |
commit | d6174cad42eef4d8d08bddb4d316620ae0a75f9b (patch) | |
tree | 1061566017c02c6d1aa31b7834914139ee246332 | |
parent | 7bcecfecfe90390ea14d27c324111a1224b86280 (diff) | |
download | terraform-provider-libvirt-d6174cad42eef4d8d08bddb4d316620ae0a75f9b.tar terraform-provider-libvirt-d6174cad42eef4d8d08bddb4d316620ae0a75f9b.tar.gz |
Exclude `graphics` block on s390x and ppc64
Since the `graphics` and `video` devices cause problems on s390x and
ppc64, they are ignored when creating a domain.
Signed-off-by: Thomas Hipp <thipp@suse.de>
-rw-r--r-- | docs/providers/libvirt/r/domain.html.markdown | 4 | ||||
-rw-r--r-- | libvirt/domain_def.go | 17 | ||||
-rw-r--r-- | libvirt/resource_libvirt_domain.go | 29 | ||||
-rw-r--r-- | libvirt/utils_libvirt.go | 24 |
4 files changed, 57 insertions, 17 deletions
diff --git a/docs/providers/libvirt/r/domain.html.markdown b/docs/providers/libvirt/r/domain.html.markdown index b9a5500e..99948e39 100644 --- a/docs/providers/libvirt/r/domain.html.markdown +++ b/docs/providers/libvirt/r/domain.html.markdown @@ -248,6 +248,10 @@ resource "libvirt_domain" "my_machine" { } ``` +Note the following: +* The `graphics` block is ignored for the architectures `s390x` and `ppc64`. + + The optional `console` block allows you to define a console for the domain. The block looks as follows: ``` diff --git a/libvirt/domain_def.go b/libvirt/domain_def.go index 3920c979..f41a88bd 100644 --- a/libvirt/domain_def.go +++ b/libvirt/domain_def.go @@ -25,13 +25,7 @@ type defDomain struct { Disks []defDisk `xml:"disk"` NetworkInterfaces []defNetworkInterface `xml:"interface"` Console []defConsole `xml:"console"` - Graphics struct { - Type string `xml:"type,attr"` - Autoport string `xml:"autoport,attr"` - Listen struct { - Type string `xml:"type,attr"` - } `xml:"listen"` - } `xml:"graphics"` + Graphics *defGraphics `xml:"graphics,omitempty"` // QEMU guest agent channel QemuGAChannel struct { Type string `xml:"type,attr"` @@ -56,6 +50,14 @@ type defDomain struct { } } +type defGraphics struct { + Type string `xml:"type,attr"` + Autoport string `xml:"autoport,attr"` + Listen struct { + Type string `xml:"type,attr"` + } `xml:"listen"` +} + type defMetadata struct { XMLName xml.Name `xml:"http://github.com/dmacvicar/terraform-provider-libvirt/ user_data"` Xml string `xml:",cdata"` @@ -130,6 +132,7 @@ func newDomainDef() defDomain { domainDef.VCpu.Placement = "static" domainDef.VCpu.Amount = 1 + domainDef.Devices.Graphics = &defGraphics{} domainDef.Devices.Graphics.Type = "spice" domainDef.Devices.Graphics.Autoport = "yes" domainDef.Devices.Graphics.Listen.Type = "none" diff --git a/libvirt/resource_libvirt_domain.go b/libvirt/resource_libvirt_domain.go index ffe32d43..3cf42740 100644 --- a/libvirt/resource_libvirt_domain.go +++ b/libvirt/resource_libvirt_domain.go @@ -191,16 +191,25 @@ func resourceLibvirtDomainCreate(d *schema.ResourceData, meta interface{}) error domainDef.Xmlns = "http://libvirt.org/schemas/domain/qemu/1.0" } - if graphics, ok := d.GetOk("graphics"); ok { - graphics_map := graphics.(map[string]interface{}) - if graphics_type, ok := graphics_map["type"]; ok { - domainDef.Devices.Graphics.Type = graphics_type.(string) - } - if autoport, ok := graphics_map["autoport"]; ok { - domainDef.Devices.Graphics.Type = autoport.(string) - } - if listen_type, ok := graphics_map["listen_type"]; ok { - domainDef.Devices.Graphics.Listen.Type = listen_type.(string) + arch, err := getHostArchitecture(virConn) + if err != nil { + return fmt.Errorf("Error retrieving host architecture: %s", err) + } + + if arch == "s390x" || arch == "ppc64" { + domainDef.Devices.Graphics = nil + } else { + if graphics, ok := d.GetOk("graphics"); ok { + graphics_map := graphics.(map[string]interface{}) + if graphics_type, ok := graphics_map["type"]; ok { + domainDef.Devices.Graphics.Type = graphics_type.(string) + } + if autoport, ok := graphics_map["autoport"]; ok { + domainDef.Devices.Graphics.Autoport = autoport.(string) + } + if listen_type, ok := graphics_map["listen_type"]; ok { + domainDef.Devices.Graphics.Listen.Type = listen_type.(string) + } } } diff --git a/libvirt/utils_libvirt.go b/libvirt/utils_libvirt.go index e14e9554..5b38a5ea 100644 --- a/libvirt/utils_libvirt.go +++ b/libvirt/utils_libvirt.go @@ -1,6 +1,7 @@ package libvirt import ( + "encoding/xml" "log" libvirt "github.com/dmacvicar/libvirt-go" @@ -39,3 +40,26 @@ func updateHost(n *libvirt.VirNetwork, ip, mac, name string) error { log.Printf("Updating host with XML:\n%s", xmlDesc) return n.UpdateXMLDesc(xmlDesc, libvirt.VIR_NETWORK_UPDATE_COMMAND_MODIFY, libvirt.VIR_NETWORK_SECTION_IP_DHCP_HOST) } + +func getHostArchitecture(virConn *libvirt.VirConnection) (string, error) { + type HostCapabilities struct { + XMLName xml.Name `xml:"capabilities"` + Host struct { + XMLName xml.Name `xml:"host"` + CPU struct { + XMLName xml.Name `xml:"cpu"` + Arch string `xml:"arch"` + } + } + } + + info, err := virConn.GetCapabilities() + if err != nil { + return "", err + } + + capabilities := HostCapabilities{} + xml.Unmarshal([]byte(info), &capabilities) + + return capabilities.Host.CPU.Arch, nil +} |