4.6.3
This commit is contained in:
@@ -22,7 +22,7 @@ func flattenCompute(d *schema.ResourceData, computeRec *compute.RecordCompute, p
|
||||
|
||||
if len(computeRec.Interfaces) > 0 {
|
||||
log.Debugf("flattenCompute: calling parseComputeInterfacesToNetworks for %d interfaces", len(computeRec.Interfaces))
|
||||
if err := d.Set("network", parseComputeInterfacesToNetworks(computeRec.Interfaces)); err != nil {
|
||||
if err := d.Set("network", parseComputeInterfacesToNetworks(d.Get("network").(*schema.Set).List(), computeRec.Interfaces)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -667,7 +667,7 @@ func flattenDataCompute(d *schema.ResourceData, compFacts *compute.RecordCompute
|
||||
|
||||
// Parse the list of interfaces from compute/get response into a list of networks
|
||||
// attached to this compute
|
||||
func parseComputeInterfacesToNetworks(ifaces compute.ListInterfaces) []interface{} {
|
||||
func parseComputeInterfacesToNetworks(networks []interface{}, ifaces compute.ListInterfaces) []interface{} {
|
||||
// return value will be used to d.Set("network") item of dataSourceCompute schema
|
||||
length := len(ifaces)
|
||||
log.Debugf("parseComputeInterfacesToNetworks: called for %d ifaces", length)
|
||||
@@ -681,6 +681,7 @@ func parseComputeInterfacesToNetworks(ifaces compute.ListInterfaces) []interface
|
||||
elem["net_type"] = value.NetType
|
||||
elem["ip_address"] = value.IPAddress
|
||||
elem["mac"] = value.MAC
|
||||
elem["weight"] = flattenNetworkWeight(networks, value.NetID, value.NetType)
|
||||
|
||||
result = append(result, elem)
|
||||
}
|
||||
@@ -688,6 +689,17 @@ func parseComputeInterfacesToNetworks(ifaces compute.ListInterfaces) []interface
|
||||
return result
|
||||
}
|
||||
|
||||
func flattenNetworkWeight(networks []interface{}, netID uint64, netType string) int {
|
||||
for _, network := range networks {
|
||||
ns := network.(map[string]interface{})
|
||||
if ns["net_id"].(int) == int(netID) && ns["net_type"].(string) == netType {
|
||||
weight := ns["weight"].(int)
|
||||
return weight
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func flattenDisk(diskList compute.ListDisks) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(diskList))
|
||||
for _, disk := range diskList {
|
||||
|
||||
Reference in New Issue
Block a user