Skip to content

Commit

Permalink
removing wait for ip and ip_address from the vm ds and rs since not e…
Browse files Browse the repository at this point in the history
…very vm would have an ip early on, and because the ip can be accessed as well from the nic_list attribute
  • Loading branch information
crizstian committed Jun 1, 2018
1 parent 889e887 commit 5315889
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 53 deletions.
7 changes: 1 addition & 6 deletions nutanix/data_source_nutanix_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func dataSourceNutanixVirtualMachineRead(d *schema.ResourceData, meta interface{
}

m, c := setRSEntityMetadata(resp.Metadata)
n, i := setNicList(resp.Status.Resources.NicList)
n := setNicList(resp.Status.Resources.NicList)

if err := d.Set("metadata", m); err != nil {
return err
Expand Down Expand Up @@ -137,7 +137,6 @@ func dataSourceNutanixVirtualMachineRead(d *schema.ResourceData, meta interface{
d.Set("description", utils.StringValue(resp.Status.Description))
d.Set("state", utils.StringValue(resp.Status.State))
d.Set("num_vnuma_nodes", utils.Int64Value(resp.Status.Resources.VnumaConfig.NumVnumaNodes))
d.Set("ip_address", i)
d.Set("guest_os_id", utils.StringValue(resp.Status.Resources.GuestOsID))
d.Set("power_state", utils.StringValue(resp.Status.Resources.PowerState))
d.Set("num_vcpus_per_socket", utils.Int64Value(resp.Status.Resources.NumVcpusPerSocket))
Expand Down Expand Up @@ -329,10 +328,6 @@ func getDataSourceVMSchema() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"ip_address": {
Type: schema.TypeString,
Computed: true,
},
"host_reference": {
Type: schema.TypeMap,
Computed: true,
Expand Down
12 changes: 3 additions & 9 deletions nutanix/data_source_nutanix_virtual_machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func dataSourceNutanixVirtualMachinesRead(d *schema.ResourceData, meta interface
entity["cluster_reference_name"] = utils.StringValue(v.Status.ClusterReference.Name)
entity["state"] = utils.StringValue(v.Status.State)
entity["num_vnuma_nodes"] = utils.Int64Value(v.Status.Resources.VnumaConfig.NumVnumaNodes)
entity["nic_list"], entity["ip_address"] = setNicList(v.Status.Resources.NicList)
entity["nic_list"] = setNicList(v.Status.Resources.NicList)
entity["host_reference"] = getReferenceValues(v.Status.Resources.HostReference)
entity["guest_os_id"] = utils.StringValue(v.Status.Resources.GuestOsID)
entity["power_state"] = utils.StringValue(v.Status.Resources.PowerState)
Expand Down Expand Up @@ -205,9 +205,8 @@ func setNutanixGuestTools(guest *v3.GuestToolsStatus) map[string]interface{} {
return nutanixGuestTools
}

func setNicList(nics []*v3.VMNicOutputStatus) ([]map[string]interface{}, string) {
func setNicList(nics []*v3.VMNicOutputStatus) []map[string]interface{} {
nicLists := make([]map[string]interface{}, 0)
ip := ""
if nics != nil {
nicLists = make([]map[string]interface{}, len(nics))
for k, v := range nics {
Expand All @@ -218,7 +217,6 @@ func setNicList(nics []*v3.VMNicOutputStatus) ([]map[string]interface{}, string)
nic["network_function_nic_type"] = utils.StringValue(v.NetworkFunctionNicType)
nic["mac_address"] = utils.StringValue(v.MacAddress)
nic["model"] = utils.StringValue(v.Model)
ip = utils.StringValue(v.IPEndpointList[0].IP)
ipEndpointList := make([]map[string]interface{}, len(v.IPEndpointList))
for k1, v1 := range v.IPEndpointList {
ipEndpoint := make(map[string]interface{})
Expand All @@ -234,7 +232,7 @@ func setNicList(nics []*v3.VMNicOutputStatus) ([]map[string]interface{}, string)
}
}

return nicLists, ip
return nicLists
}

func getDataSourceVMSSchema() map[string]*schema.Schema {
Expand Down Expand Up @@ -451,10 +449,6 @@ func getDataSourceVMSSchema() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"ip_address": {
Type: schema.TypeString,
Computed: true,
},
"host_reference": {
Type: schema.TypeMap,
Computed: true,
Expand Down
39 changes: 1 addition & 38 deletions nutanix/resource_nutanix_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,6 @@ func resourceNutanixVirtualMachineCreate(d *schema.ResourceData, meta interface{
"Error waiting for vm (%s) to create: %s", d.Id(), err)
}

// Read the ip
if resp.Spec.Resources.NicList != nil && *resp.Spec.Resources.PowerState == "ON" {
log.Printf("[DEBUG] Polling for IP\n")
err := waitForIP(conn, uuid, d)
if err != nil {
return err
}
}

return resourceNutanixVirtualMachineRead(d, meta)
}

Expand All @@ -138,7 +129,7 @@ func resourceNutanixVirtualMachineRead(d *schema.ResourceData, meta interface{})
}

m, c := setRSEntityMetadata(resp.Metadata)
n, i := setNicList(resp.Status.Resources.NicList)
n := setNicList(resp.Status.Resources.NicList)

if err := d.Set("metadata", m); err != nil {
return err
Expand Down Expand Up @@ -240,7 +231,6 @@ func resourceNutanixVirtualMachineRead(d *schema.ResourceData, meta interface{})
d.Set("description", utils.StringValue(resp.Status.Description))
d.Set("state", utils.StringValue(resp.Status.State))
d.Set("num_vnuma_nodes", utils.Int64Value(resp.Status.Resources.VnumaConfig.NumVnumaNodes))
d.Set("ip_address", i)
d.Set("guest_os_id", utils.StringValue(resp.Status.Resources.GuestOsID))
d.Set("power_state", utils.StringValue(resp.Status.Resources.PowerState))
d.Set("num_vcpus_per_socket", utils.Int64Value(resp.Status.Resources.NumVcpusPerSocket))
Expand Down Expand Up @@ -936,29 +926,6 @@ func vmStateRefreshFunc(client *v3.Client, uuid string) resource.StateRefreshFun
}
}

func waitForIP(conn *v3.Client, uuid string, d *schema.ResourceData) error {
for {
resp, err := conn.V3.GetVM(uuid)
if err != nil {
return err
}

if len(resp.Status.Resources.NicList) != 0 {
for i := range resp.Status.Resources.NicList {
if len(resp.Status.Resources.NicList[i].IPEndpointList) != 0 {
if ip := resp.Status.Resources.NicList[i].IPEndpointList[0].IP; ip != nil {
// TODO set ip address
d.Set("ip_address", *ip)
return nil
}
}
}
}
time.Sleep(3000 * time.Millisecond)
}
// return nil
}

func preFillResUpdateRequest(res *v3.VMResources, response *v3.VMIntentResponse) {
res.ParentReference = response.Status.Resources.ParentReference
res.VMVnumaConfig = &v3.VMVnumaConfig{NumVnumaNodes: response.Status.Resources.VnumaConfig.NumVnumaNodes}
Expand Down Expand Up @@ -1198,10 +1165,6 @@ func getVMSchema() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"ip_address": {
Type: schema.TypeString,
Computed: true,
},
"host_reference": {
Type: schema.TypeMap,
Computed: true,
Expand Down

0 comments on commit 5315889

Please sign in to comment.