diff --git a/client/vif.go b/client/vif.go index 0486dc42..418023dd 100644 --- a/client/vif.go +++ b/client/vif.go @@ -74,7 +74,9 @@ func (c *Client) CreateVIF(vm *Vm, vif *VIF) (*VIF, error) { params := map[string]interface{}{ "network": vif.Network, "vm": vm.Id, - "mac": vif.MacAddress, + } + if vif.MacAddress != "" { + params["mac"] = vif.MacAddress } err := c.Call("vm.createInterface", params, &id) diff --git a/client/vm.go b/client/vm.go index a492e7cd..a3520f7b 100644 --- a/client/vm.go +++ b/client/vm.go @@ -95,7 +95,7 @@ type Vm struct { Boot Boot `json:"boot,omitempty"` Type string `json:"type,omitempty"` Id string `json:"id,omitempty"` - AffinityHost string `json:"affinityHost,omitempty"` + AffinityHost *string `json:"affinityHost,omitempty"` NameDescription string `json:"name_description"` NameLabel string `json:"name_label"` CPUs CPUs `json:"CPUs"` @@ -212,7 +212,6 @@ func (c *Client) CreateVm(vmReq Vm, createTime time.Duration) (*Vm, error) { } params := map[string]interface{}{ - "affinityHost": vmReq.AffinityHost, "bootAfterCreate": true, "name_label": vmReq.NameLabel, "name_description": vmReq.NameDescription, @@ -243,6 +242,11 @@ func (c *Client) CreateVm(vmReq Vm, createTime time.Duration) (*Vm, error) { params["hvmBootFirmware"] = firmware } + affinityHost := vmReq.AffinityHost + if affinityHost != nil { + params["affinityHost"] = affinityHost + } + vga := vmReq.Vga if vga != "" { params["vga"] = vga @@ -319,7 +323,6 @@ func createVdiMap(disk Disk) map[string]interface{} { func (c *Client) UpdateVm(vmReq Vm) (*Vm, error) { params := map[string]interface{}{ "id": vmReq.Id, - "affinityHost": vmReq.AffinityHost, "name_label": vmReq.NameLabel, "name_description": vmReq.NameDescription, "auto_poweron": vmReq.AutoPoweron, @@ -341,6 +344,15 @@ func (c *Client) UpdateVm(vmReq Vm) (*Vm, error) { // coresPerSocket is null or a number of cores per socket. Putting an invalid value doesn't seem to cause an error :( } + affinityHost := vmReq.AffinityHost + if affinityHost != nil { + if *affinityHost == "" { + params["affinityHost"] = nil + } else { + params["affinityHost"] = *affinityHost + } + } + videoram := vmReq.Videoram.Value if videoram != 0 { params["videoram"] = videoram diff --git a/xoa/resource_xenorchestra_vm.go b/xoa/resource_xenorchestra_vm.go index d9d77a85..3c716e08 100644 --- a/xoa/resource_xenorchestra_vm.go +++ b/xoa/resource_xenorchestra_vm.go @@ -407,8 +407,7 @@ func resourceVmCreate(d *schema.ResourceData, m interface{}) error { Id: rsId.(string), } } - vm, err := c.CreateVm(client.Vm{ - AffinityHost: d.Get("affinity_host").(string), + createVmParams := client.Vm{ BlockedOperations: blockedOperations, Boot: client.Boot{ Firmware: d.Get("hvm_boot_firmware").(string), @@ -442,9 +441,13 @@ func resourceVmCreate(d *schema.ResourceData, m interface{}) error { Value: d.Get("videoram").(int), }, Vga: d.Get("vga").(string), - }, - d.Timeout(schema.TimeoutCreate), - ) + } + + affinityHost := d.Get("affinity_host").(string) + if affinityHost != "" { + createVmParams.AffinityHost = &affinityHost + } + vm, err := c.CreateVm(createVmParams, d.Timeout(schema.TimeoutCreate)) if err != nil { return err @@ -780,7 +783,6 @@ func resourceVmUpdate(d *schema.ResourceData, m interface{}) error { HA: ha, ResourceSet: rs, AutoPoweron: autoPowerOn, - AffinityHost: affinityHost, BlockedOperations: blockOperations, ExpNestedHvm: d.Get("exp_nested_hvm").(bool), StartDelay: d.Get("start_delay").(int), @@ -794,6 +796,11 @@ func resourceVmUpdate(d *schema.ResourceData, m interface{}) error { Value: d.Get("videoram").(int), }, } + + if d.HasChange("affinity_host") { + vmReq.AffinityHost = &affinityHost + } + if haltForUpdates { err := c.HaltVm(id)