Skip to content

Commit

Permalink
fix for issue nutanix#119 - timeout issue and categories reboot
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickstruyf3 committed May 12, 2020
1 parent db00fdb commit ef83c71
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions nutanix/resource_nutanix_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ func resourceNutanixVirtualMachine() *schema.Resource {
func resourceNutanixVirtualMachineCreate(d *schema.ResourceData, meta interface{}) error {
// Get client connection
conn := meta.(*Client).API
setVMTimeout(meta)
// Prepare request
request := &v3.VMIntentInput{}
spec := &v3.VM{}
Expand Down Expand Up @@ -857,7 +858,7 @@ func resourceNutanixVirtualMachineCreate(d *schema.ResourceData, meta interface{
func resourceNutanixVirtualMachineRead(d *schema.ResourceData, meta interface{}) error {
// Get client connection
conn := meta.(*Client).API

setVMTimeout(meta)
// Make request to the API
resp, err := conn.V3.GetVM(d.Id())

Expand Down Expand Up @@ -1003,6 +1004,7 @@ func resourceNutanixVirtualMachineRead(d *schema.ResourceData, meta interface{})

func resourceNutanixVirtualMachineUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*Client).API
setVMTimeout(meta)
var hotPlugChange = true

log.Printf("[Debug] Updating VM values %s", d.Id())
Expand Down Expand Up @@ -1037,7 +1039,6 @@ func resourceNutanixVirtualMachineUpdate(d *schema.ResourceData, meta interface{

if d.HasChange("categories") {
metadata.Categories = expandCategories(d.Get("categories"))
hotPlugChange = false
}
metadata.OwnerReference = response.Metadata.OwnerReference
if d.HasChange("owner_reference") {
Expand Down Expand Up @@ -1417,7 +1418,7 @@ func taskVMStateRefreshFunc(client *v3.Client, vmUUID string, powerState string)

func resourceNutanixVirtualMachineDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*Client).API

setVMTimeout(meta)
log.Printf("[DEBUG] Deleting Virtual Machine: %s, %s", d.Get("name").(string), d.Id())
resp, err := conn.V3.DeleteVM(d.Id())
if err != nil {
Expand Down Expand Up @@ -1978,6 +1979,13 @@ func resourceVirtualMachineInstanceStateUpgradeV0(is map[string]interface{}, met
return resourceNutanixCategoriesMigrateState(is, meta)
}

func setVMTimeout(meta interface{}) {
client := meta.(*Client)
if client.WaitTimeout != 0 {
vmTimeout = time.Duration(client.WaitTimeout) * time.Minute
}
}

func resourceNutanixVirtualMachineInstanceResourceV0() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down

0 comments on commit ef83c71

Please sign in to comment.