Change networks attribute type to TypeSet and fix compute resource state issue
This commit is contained in:
@@ -149,20 +149,15 @@ func parseBootDiskId(disks []DiskRecord) uint {
|
|||||||
|
|
||||||
// Parse the list of interfaces from compute/get response into a list of networks
|
// Parse the list of interfaces from compute/get response into a list of networks
|
||||||
// attached to this compute
|
// attached to this compute
|
||||||
func parseComputeInterfacesToNetworks(ifaces []InterfaceRecord) []interface{} {
|
func parseComputeInterfacesToNetworks(ifaces []InterfaceRecord) []map[string]interface{} {
|
||||||
// return value will be used to d.Set("network",) item of dataSourceCompute schema
|
// return value will be used to d.Set("network",) item of dataSourceCompute schema
|
||||||
length := len(ifaces)
|
length := len(ifaces)
|
||||||
log.Debugf("parseComputeInterfacesToNetworks: called for %d ifaces", length)
|
log.Debugf("parseComputeInterfacesToNetworks: called for %d ifaces", length)
|
||||||
|
|
||||||
result := make([]interface{}, length)
|
result := make([]map[string]interface{}, length, length)
|
||||||
|
|
||||||
if length == 0 {
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
elem := make(map[string]interface{})
|
|
||||||
|
|
||||||
for i, value := range ifaces {
|
for i, value := range ifaces {
|
||||||
|
elem := make(map[string]interface{})
|
||||||
// Keys in this map should correspond to the Schema definition
|
// Keys in this map should correspond to the Schema definition
|
||||||
// as returned by networkSubresourceSchemaMake()
|
// as returned by networkSubresourceSchemaMake()
|
||||||
elem["net_id"] = value.NetID
|
elem["net_id"] = value.NetID
|
||||||
@@ -170,30 +165,28 @@ func parseComputeInterfacesToNetworks(ifaces []InterfaceRecord) []interface{} {
|
|||||||
elem["ip_address"] = value.IPAddress
|
elem["ip_address"] = value.IPAddress
|
||||||
elem["mac"] = value.MAC
|
elem["mac"] = value.MAC
|
||||||
|
|
||||||
|
// log.Debugf(" element %d: net_id=%d, net_type=%s", i, value.NetID, value.NetType)
|
||||||
|
|
||||||
result[i] = elem
|
result[i] = elem
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseComputeInterfaces(ifaces []InterfaceRecord) []interface{} {
|
func parseComputeInterfaces(ifaces []InterfaceRecord) []map[string]interface{} {
|
||||||
// return value was designed to d.Set("interfaces",) item of dataSourceCompute schema
|
// return value was designed to d.Set("interfaces",) item of dataSourceCompute schema
|
||||||
// However, this item was excluded from the schema as it is not directly
|
// However, this item was excluded from the schema as it is not directly
|
||||||
// managed through Terraform
|
// managed through Terraform
|
||||||
length := len(ifaces)
|
length := len(ifaces)
|
||||||
log.Debugf("parseComputeInterfaces: called for %d ifaces", length)
|
log.Debugf("parseComputeInterfaces: called for %d ifaces", length)
|
||||||
|
|
||||||
result := make([]interface{}, length)
|
result := make([]map[string]interface{}, length, length)
|
||||||
|
|
||||||
if length == 0 {
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
elem := make(map[string]interface{})
|
|
||||||
|
|
||||||
for i, value := range ifaces {
|
for i, value := range ifaces {
|
||||||
// Keys in this map should correspond to the Schema definition
|
// Keys in this map should correspond to the Schema definition
|
||||||
// as returned by dataSourceInterfaceSchemaMake()
|
// as returned by dataSourceInterfaceSchemaMake()
|
||||||
|
elem := make(map[string]interface{})
|
||||||
|
|
||||||
elem["net_id"] = value.NetID
|
elem["net_id"] = value.NetID
|
||||||
elem["net_type"] = value.NetType
|
elem["net_type"] = value.NetType
|
||||||
elem["ip_address"] = value.IPAddress
|
elem["ip_address"] = value.IPAddress
|
||||||
@@ -225,7 +218,7 @@ func flattenCompute(d *schema.ResourceData, compFacts string) error {
|
|||||||
// NOTE: this function modifies ResourceData argument - as such it should never be called
|
// NOTE: this function modifies ResourceData argument - as such it should never be called
|
||||||
// from resourceComputeExists(...) method
|
// from resourceComputeExists(...) method
|
||||||
model := ComputeGetResp{}
|
model := ComputeGetResp{}
|
||||||
log.Debugf("flattenCompute: ready to unmarshal string %q", compFacts)
|
log.Debugf("flattenCompute: ready to unmarshal string %s", compFacts)
|
||||||
err := json.Unmarshal([]byte(compFacts), &model)
|
err := json.Unmarshal([]byte(compFacts), &model)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -248,8 +241,8 @@ func flattenCompute(d *schema.ResourceData, compFacts string) error {
|
|||||||
d.Set("boot_disk_id", parseBootDiskId(model.Disks)) // we may need boot disk ID in resize operations
|
d.Set("boot_disk_id", parseBootDiskId(model.Disks)) // we may need boot disk ID in resize operations
|
||||||
d.Set("image_id", model.ImageID)
|
d.Set("image_id", model.ImageID)
|
||||||
d.Set("description", model.Desc)
|
d.Set("description", model.Desc)
|
||||||
d.Set("status", model.Status)
|
// d.Set("status", model.Status)
|
||||||
d.Set("tech_status", model.TechStatus)
|
// d.Set("tech_status", model.TechStatus)
|
||||||
|
|
||||||
if len(model.Disks) > 0 {
|
if len(model.Disks) > 0 {
|
||||||
log.Debugf("flattenCompute: calling parseComputeDisksToExtraDisks for %d disks", len(model.Disks))
|
log.Debugf("flattenCompute: calling parseComputeDisksToExtraDisks for %d disks", len(model.Disks))
|
||||||
@@ -401,9 +394,9 @@ func dataSourceCompute() *schema.Resource {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
"network": {
|
"network": {
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeSet,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
MaxItems: MaxNetworksPerCompute,
|
// MaxItems: MaxNetworksPerCompute,
|
||||||
Elem: &schema.Resource{
|
Elem: &schema.Resource{
|
||||||
Schema: networkSubresourceSchemaMake(),
|
Schema: networkSubresourceSchemaMake(),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -356,7 +356,7 @@ type ComputeGetResp struct {
|
|||||||
ID uint `json:"id"`
|
ID uint `json:"id"`
|
||||||
ImageID int `json:"imageId"`
|
ImageID int `json:"imageId"`
|
||||||
ImageName string `json:"imageName"`
|
ImageName string `json:"imageName"`
|
||||||
Interfaces []InterfaceRecord `json:"interfaces`
|
Interfaces []InterfaceRecord `json:"interfaces"`
|
||||||
LockStatus string `json:"lockStatus"`
|
LockStatus string `json:"lockStatus"`
|
||||||
ManagerID int `json:"managerId"`
|
ManagerID int `json:"managerId"`
|
||||||
ManagerType string `json:"manageType"`
|
ManagerType string `json:"manageType"`
|
||||||
@@ -388,7 +388,7 @@ type ComputeGetResp struct {
|
|||||||
//
|
//
|
||||||
type ImageRecord struct {
|
type ImageRecord struct {
|
||||||
AccountID uint `json:"accountId"`
|
AccountID uint `json:"accountId"`
|
||||||
Arch string `json:"architecture`
|
Arch string `json:"architecture"`
|
||||||
BootType string `json:"bootType"`
|
BootType string `json:"bootType"`
|
||||||
IsBootable bool `json:"bootable"`
|
IsBootable bool `json:"bootable"`
|
||||||
IsCdrom bool `json:"cdrom"`
|
IsCdrom bool `json:"cdrom"`
|
||||||
@@ -445,7 +445,7 @@ type AccountsListResp []AccountRecord
|
|||||||
//
|
//
|
||||||
type PfwRecord struct {
|
type PfwRecord struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
LocalIP string `json:"localIp`
|
LocalIP string `json:"localIp"`
|
||||||
LocalPort int `json:"localPort"`
|
LocalPort int `json:"localPort"`
|
||||||
Protocol string `json:"protocol"`
|
Protocol string `json:"protocol"`
|
||||||
PublicPortEnd int `json:"publicPortEnd"`
|
PublicPortEnd int `json:"publicPortEnd"`
|
||||||
|
|||||||
@@ -380,9 +380,9 @@ func resourceCompute() *schema.Resource {
|
|||||||
},
|
},
|
||||||
|
|
||||||
"network": {
|
"network": {
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeSet,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
MaxItems: MaxNetworksPerCompute,
|
// MaxItems: MaxNetworksPerCompute,
|
||||||
Elem: &schema.Resource{
|
Elem: &schema.Resource{
|
||||||
Schema: networkSubresourceSchemaMake(),
|
Schema: networkSubresourceSchemaMake(),
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user