Fix schema updates for Image and ViNS data sources

rc-1.0
Sergey Shubin svs1370 4 years ago
parent b08d688c0d
commit d60048b88b

@ -38,19 +38,19 @@ import (
func dataSourceImageRead(d *schema.ResourceData, m interface{}) error { func dataSourceImageRead(d *schema.ResourceData, m interface{}) error {
name := d.Get("name").(string) name := d.Get("name").(string)
// rg_id, rgid_set := d.GetOk("rg_id") // rg_id, rgid_set := d.GetOk("rg_id")
account_id, account_set := d.GetOk("account_id") accId, accSet := d.GetOk("account_id")
controller := m.(*ControllerCfg) controller := m.(*ControllerCfg)
url_values := &url.Values{} url_values := &url.Values{}
if account_set { if accSet {
url_values.Add("accountId", fmt.Sprintf("%d", account_id.(int))) url_values.Add("accountId", fmt.Sprintf("%d", accId.(int)))
} }
body_string, err := controller.decortAPICall("POST", ImagesListAPI, url_values) body_string, err := controller.decortAPICall("POST", ImagesListAPI, url_values)
if err != nil { if err != nil {
return err return err
} }
log.Debugf("dataSourceImageRead: ready to decode response body from %q", ImagesListAPI) log.Debugf("dataSourceImageRead: ready to decode response body from %s", ImagesListAPI)
model := ImagesListResp{} model := ImagesListResp{}
err = json.Unmarshal([]byte(body_string), &model) err = json.Unmarshal([]byte(body_string), &model)
if err != nil { if err != nil {
@ -62,7 +62,7 @@ func dataSourceImageRead(d *schema.ResourceData, m interface{}) error {
for index, item := range model { for index, item := range model {
// need to match Image by name // need to match Image by name
if item.Name == name { if item.Name == name {
log.Printf("dataSourceImageRead: index %d, matched name %q", index, item.Name) log.Printf("dataSourceImageRead: index %d, matched name %s", index, item.Name)
d.SetId(fmt.Sprintf("%d", item.ID)) d.SetId(fmt.Sprintf("%d", item.ID))
d.Set("account_id", item.AccountID) d.Set("account_id", item.AccountID)
d.Set("arch", item.Arch) d.Set("arch", item.Arch)
@ -75,7 +75,7 @@ func dataSourceImageRead(d *schema.ResourceData, m interface{}) error {
} }
} }
return fmt.Errorf("Cannot find OS Image name %q", name) return fmt.Errorf("Cannot find Image name %s", name)
} }
func dataSourceImage() *schema.Resource { func dataSourceImage() *schema.Resource {
@ -93,7 +93,7 @@ func dataSourceImage() *schema.Resource {
"name": { "name": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
Description: "Name of the OS image to locate. This parameter is case sensitive.", Description: "Name of the image to locate. This parameter is case sensitive.",
}, },
"account_id": { "account_id": {
@ -106,11 +106,11 @@ func dataSourceImage() *schema.Resource {
"arch": { "arch": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
Description: "Binary architecture this image is created for.", Description: "Binary architecture of this image.",
}, },
"sep_id": { "sep_id": {
Type: schema.TypeString, Type: schema.TypeInt,
Computed: true, Computed: true,
Description: "Storage end-point provider serving this image.", Description: "Storage end-point provider serving this image.",
}, },
@ -138,7 +138,7 @@ func dataSourceImage() *schema.Resource {
"status": { "status": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
Description: "Current model status of this disk.", Description: "Current model status of this image.",
}, },
}, },
} }

@ -40,7 +40,7 @@ import (
func flattenVins(d *schema.ResourceData, vins_facts string) error { func flattenVins(d *schema.ResourceData, vins_facts 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 resourceVinsExists(...) method // from resourceVinsExists(...) method
log.Debugf("flattenVins: ready to decode response body from API %s", vins_facts) // log.Debugf("flattenVins: ready to decode response body from API %s", vins_facts)
vinsRecord := VinsRecord{} vinsRecord := VinsRecord{}
err := json.Unmarshal([]byte(vins_facts), &vinsRecord) err := json.Unmarshal([]byte(vins_facts), &vinsRecord)
if err != nil { if err != nil {
@ -51,9 +51,9 @@ func flattenVins(d *schema.ResourceData, vins_facts string) error {
vinsRecord.Name, vinsRecord.ID, vinsRecord.AccountID, vinsRecord.RgID) vinsRecord.Name, vinsRecord.ID, vinsRecord.AccountID, vinsRecord.RgID)
d.SetId(fmt.Sprintf("%d", vinsRecord.ID)) d.SetId(fmt.Sprintf("%d", vinsRecord.ID))
d.Set("account_id", fmt.Sprintf("%d", vinsRecord.AccountID)) d.Set("account_id", vinsRecord.AccountID)
d.Set("account_name", vinsRecord.AccountName) d.Set("account_name", vinsRecord.AccountName)
d.Set("rg_id", fmt.Sprintf("%d", vinsRecord.RgID)) err = d.Set("rg_id", vinsRecord.RgID)
d.Set("description", vinsRecord.Desc) d.Set("description", vinsRecord.Desc)
d.Set("ipcidr", vinsRecord.IPCidr) d.Set("ipcidr", vinsRecord.IPCidr)
@ -63,27 +63,18 @@ func flattenVins(d *schema.ResourceData, vins_facts string) error {
extNetID, idOk := value.Config["ext_net_id"] // NOTE: unknown numbers are unmarshalled to float64. This is by design! 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"] extNetIP, ipOk := value.Config["ext_net_ip"]
if idOk && ipOk { 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)) log.Debugf("flattenVins: ViNS ext_net_id=%d, ext_net_ip=%s", int(extNetID.(float64)), extNetIP.(string))
d.Set("ext_ip_addr", extNetIP.(string))
d.Set("ext_net_id", int(extNetID.(float64)))
} else { } else {
return fmt.Errorf("Failed to unmarshal VNF GW Config - structure is invalid.") 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 break
} }
} }
log.Debugf("flattenVins: EXTRA CHECK - schema rg_id=%d, ext_net_id=%d", d.Get("rg_id").(int), d.Get("ext_net_id").(int))
return nil return nil
} }

Loading…
Cancel
Save