diff options
author | Zbigniew Kostrzewa <kostrzewa@9livesdata.com> | 2017-06-15 11:06:52 +0200 |
---|---|---|
committer | localghost <zkostrzewa@gmail.com> | 2017-06-15 22:33:50 +0200 |
commit | c658e4449c0f47f013b0db17a72889e7237b7210 (patch) | |
tree | 037e12f32b1a6465bf64880fc13e66ec99051525 /libvirt | |
parent | 919ee121eb8230f479d72ebd1fe527f532c1de48 (diff) | |
download | terraform-provider-libvirt-c658e4449c0f47f013b0db17a72889e7237b7210.tar terraform-provider-libvirt-c658e4449c0f47f013b0db17a72889e7237b7210.tar.gz |
Add support for setting CPU mode.
Diffstat (limited to 'libvirt')
-rw-r--r-- | libvirt/domain_def.go | 3 | ||||
-rw-r--r-- | libvirt/resource_libvirt_domain.go | 14 | ||||
-rw-r--r-- | libvirt/resource_libvirt_domain_test.go | 28 |
3 files changed, 45 insertions, 0 deletions
diff --git a/libvirt/domain_def.go b/libvirt/domain_def.go index 3ac2bedb..407183b5 100644 --- a/libvirt/domain_def.go +++ b/libvirt/domain_def.go @@ -50,6 +50,9 @@ type defDomain struct { XMLName xml.Name `xml:"qemu:commandline"` Cmd []defCmd `xml:"qemu:arg"` } + Cpu struct { + Mode string `xml:"mode,attr,omitempty"` + } `xml:"cpu,omitempty"` } type defGraphics struct { diff --git a/libvirt/resource_libvirt_domain.go b/libvirt/resource_libvirt_domain.go index 106f5fed..56b99ba8 100644 --- a/libvirt/resource_libvirt_domain.go +++ b/libvirt/resource_libvirt_domain.go @@ -125,6 +125,12 @@ func resourceLibvirtDomain() *schema.Resource { Schema: consoleSchema(), }, }, + "cpu": &schema.Schema{ + Type: schema.TypeMap, + Optional: true, + Required: false, + ForceNew: true, + }, }, } } @@ -194,6 +200,13 @@ func resourceLibvirtDomainCreate(d *schema.ResourceData, meta interface{}) error } } + if cpu, ok := d.GetOk("cpu"); ok { + cpu_map := cpu.(map[string]interface{}) + if cpu_mode, ok := cpu_map["mode"]; ok { + domainDef.Cpu.Mode = cpu_mode.(string) + } + } + if firmware, ok := d.GetOk("firmware"); ok { firmwareFile := firmware.(string) if _, err := os.Stat(firmwareFile); os.IsNotExist(err) { @@ -646,6 +659,7 @@ func resourceLibvirtDomainRead(d *schema.ResourceData, meta interface{}) error { d.Set("memory", domainDef.Memory) d.Set("firmware", domainDef.Os.Loader) d.Set("nvram", domainDef.Os.NvRam) + d.Set("cpu", domainDef.Cpu) running, err := isDomainRunning(domain) if err != nil { diff --git a/libvirt/resource_libvirt_domain_test.go b/libvirt/resource_libvirt_domain_test.go index 4e584c5a..942770d8 100644 --- a/libvirt/resource_libvirt_domain_test.go +++ b/libvirt/resource_libvirt_domain_test.go @@ -323,6 +323,34 @@ func TestAccLibvirtDomain_IgnitionObject(t *testing.T) { }) } +func TestAccLibvirtDomain_Cpu(t *testing.T) { + var domain libvirt.VirDomain + + var config = fmt.Sprintf(` + resource "libvirt_domain" "acceptance-test-domain" { + name = "terraform-test" + cpu { + mode = "host-passthrough" + } + }`) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckLibvirtDomainDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: config, + Check: resource.ComposeTestCheckFunc( + testAccCheckLibvirtDomainExists("libvirt_domain.acceptance-test-domain", &domain), + resource.TestCheckResourceAttr( + "libvirt_domain.acceptance-test-domain", "cpu.mode", "host-passthrough"), + ), + }, + }, + }) +} + func testAccCheckLibvirtDomainDestroy(s *terraform.State) error { virtConn := testAccProvider.Meta().(*Client).libvirt |