Implement Import function for Compute resource

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

@ -112,8 +112,8 @@ func parseComputeDisks(disks []DiskRecord) []interface{} {
elem["sep_id"] = value.SepID
elem["sep_type"] = value.SepType
elem["pool"] = value.Pool
elem["status"] = value.Status
elem["tech_status"] = value.TechStatus
// elem["status"] = value.Status
// elem["tech_status"] = value.TechStatus
elem["compute_id"] = value.ComputeID
result[i] = elem
}
@ -417,6 +417,7 @@ func dataSourceCompute() *schema.Resource {
Description: "User-defined text description of this compute instance.",
},
/*
"status": {
Type: schema.TypeString,
Computed: true,
@ -429,7 +430,6 @@ func dataSourceCompute() *schema.Resource {
Description: "Current technical status of this compute instance.",
},
/*
"internal_ip": {
Type: schema.TypeString,
Computed: true,

@ -230,6 +230,10 @@ func resourceCompute() *schema.Resource {
Delete: resourceComputeDelete,
Exists: resourceComputeExists,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Timeouts: &schema.ResourceTimeout{
Create: &Timeout180s,
Read: &Timeout30s,
@ -369,7 +373,6 @@ func resourceCompute() *schema.Resource {
},
Description: "Specification for guest logins on this compute instance.",
},
*/
"status": {
Type: schema.TypeString,
@ -382,6 +385,7 @@ func resourceCompute() *schema.Resource {
Computed: true,
Description: "Current technical status of this compute instance.",
},
*/
},
}
}

@ -28,6 +28,7 @@ import (
"encoding/json"
"fmt"
"net/url"
"strconv"
log "github.com/sirupsen/logrus"
@ -197,11 +198,24 @@ func utilityComputeCheckPresence(d *schema.ResourceData, m interface{}) (string,
controller := m.(*ControllerCfg)
urlValues := &url.Values{}
// make it possible to use "read" & "check presence" functions with comptue ID set so
// that Import of Compute resource is possible
idSet := false
theId, err := strconv.Atoi(d.Id())
if err != nil || theId <= 0 {
computeId, argSet := d.GetOk("compute_id") // NB: compute_id is NOT present in computeResource schema!
if argSet {
theId = computeId.(int)
idSet = true
}
} else {
idSet = true
}
if idSet {
// compute ID is specified, try to get compute instance straight by this ID
log.Debugf("utilityComputeCheckPresence: locating compute by its ID %d", computeId.(int))
urlValues.Add("computeId", fmt.Sprintf("%d", computeId.(int)))
log.Debugf("utilityComputeCheckPresence: locating compute by its ID %d", theId)
urlValues.Add("computeId", fmt.Sprintf("%d", theId))
computeFacts, err := controller.decortAPICall("POST", ComputeGetAPI, urlValues)
if err != nil {
return "", err
@ -209,6 +223,8 @@ func utilityComputeCheckPresence(d *schema.ResourceData, m interface{}) (string,
return computeFacts, nil
}
// ID was not set in the schema upon entering this function - work through Compute name
// and RG ID
computeName, argSet := d.GetOk("name")
if !argSet {
return "", fmt.Errorf("Cannot locate compute instance if name is empty and no compute ID specified")
@ -251,5 +267,4 @@ func utilityComputeCheckPresence(d *schema.ResourceData, m interface{}) (string,
}
return "", nil // there should be no error if Compute does not exist
// return "", fmt.Errorf("Cannot find Compute name %q in resource group ID %d", name, rgid)
}

Loading…
Cancel
Save