|
|
|
@ -40,26 +40,49 @@ import (
|
|
|
|
|
func flattenVins(d *schema.ResourceData, vins_facts string) error {
|
|
|
|
|
// NOTE: this function modifies ResourceData argument - as such it should never be called
|
|
|
|
|
// from resourceVinsExists(...) method
|
|
|
|
|
log.Debugf("flattenVins: ready to decode response body from API")
|
|
|
|
|
details := VinsGetResp{}
|
|
|
|
|
err := json.Unmarshal([]byte(vins_facts), &details)
|
|
|
|
|
log.Debugf("flattenVins: ready to decode response body from API %s", vins_facts)
|
|
|
|
|
vinsRecord := VinsRecord{}
|
|
|
|
|
err := json.Unmarshal([]byte(vins_facts), &vinsRecord)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Debugf("flattenVins: decoded ViNS name:ID %s:%d, account ID %d, RG ID %d",
|
|
|
|
|
details.Name, details.ID, details.AccountID, details.RgID)
|
|
|
|
|
|
|
|
|
|
d.SetId(fmt.Sprintf("%d", details.ID))
|
|
|
|
|
d.Set("rg_id", details.ID)
|
|
|
|
|
d.Set("name", details.Name)
|
|
|
|
|
d.Set("account_name", details.AccountName)
|
|
|
|
|
d.Set("account_id", details.AccountID)
|
|
|
|
|
d.Set("grid_id", details.GridID)
|
|
|
|
|
d.Set("description", details.Desc)
|
|
|
|
|
d.Set("status", details.Status)
|
|
|
|
|
d.Set("def_net_type", details.DefaultNetType)
|
|
|
|
|
d.Set("def_net_id", details.DefaultNetID)
|
|
|
|
|
vinsRecord.Name, vinsRecord.ID, vinsRecord.AccountID, vinsRecord.RgID)
|
|
|
|
|
|
|
|
|
|
d.SetId(fmt.Sprintf("%d", vinsRecord.ID))
|
|
|
|
|
d.Set("account_id", fmt.Sprintf("%d", vinsRecord.AccountID))
|
|
|
|
|
d.Set("account_name", vinsRecord.AccountName)
|
|
|
|
|
d.Set("rg_id", fmt.Sprintf("%d", vinsRecord.RgID))
|
|
|
|
|
d.Set("description", vinsRecord.Desc)
|
|
|
|
|
d.Set("ipcidr", vinsRecord.IPCidr)
|
|
|
|
|
|
|
|
|
|
for _, value := range vinsRecord.VNFs {
|
|
|
|
|
if value.Type == "GW" {
|
|
|
|
|
log.Debugf("flattenVins: discovered GW VNF ID %d in ViNS ID %d", value.ID, vinsRecord.ID)
|
|
|
|
|
extNetID, idOk := value.Config["ext_net_id"] // NOTE: unknown numbers are unmarshalled to float64. This is by design!
|
|
|
|
|
extNetIP, ipOk := value.Config["ext_net_ip"]
|
|
|
|
|
if idOk && ipOk {
|
|
|
|
|
d.Set("ext_ip_addr", extNetIP.(string))
|
|
|
|
|
d.Set("ext_net_id", fmt.Sprintf("%d", int(extNetID.(float64))))
|
|
|
|
|
log.Debugf("flattenVins: ViNS ext_net_id=%d, ext_net_ip=%s", int(extNetID.(float64)), extNetIP.(string))
|
|
|
|
|
} else {
|
|
|
|
|
return fmt.Errorf("Failed to unmarshal VNF GW Config - structure is invalid.")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* log.Debugf("flattenVins: ready to decode Config string %s", value.Config)
|
|
|
|
|
vnfRec := &VnfGwConfigRecord{}
|
|
|
|
|
err = json.Unmarshal([]byte(value.Config), vnfRec)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
d.Set("ext_ip_addr", vnfRec.ExtNetIP)
|
|
|
|
|
d.Set("ext_net_id", fmt.Sprintf("%d", vnfRec.ExtNetID))
|
|
|
|
|
log.Debugf("flattenVins: ViNS ext_net_id=%d, ext_net_ip=%s", vnfRec.ExtNetID, vnfRec.ExtNetIP)
|
|
|
|
|
*/
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
@ -142,7 +165,7 @@ func dataSourceVins() *schema.Resource {
|
|
|
|
|
"ipcidr": {
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Computed: true,
|
|
|
|
|
Description: "Network address used by this ViNS."
|
|
|
|
|
Description: "Network address used by this ViNS.",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|