Add context to DecortAPICall method
This commit is contained in:
@@ -82,7 +82,7 @@ func flattenDisk(d *schema.ResourceData, disk_facts string) error {
|
||||
}
|
||||
|
||||
func dataSourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
disk_facts, err := utilityDiskCheckPresence(d, m)
|
||||
disk_facts, err := utilityDiskCheckPresence(ctx, d, m)
|
||||
if disk_facts == "" {
|
||||
// if empty string is returned from utilityDiskCheckPresence then there is no
|
||||
// such Disk and err tells so - just return it to the calling party
|
||||
|
||||
@@ -120,7 +120,7 @@ func flattendDiskSnapshotList(sl SnapshotRecordList) []interface{} {
|
||||
}
|
||||
|
||||
func dataSourceDiskListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
diskList, err := utilityDiskListCheckPresence(d, m)
|
||||
diskList, err := utilityDiskListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ func resourceDiskCreate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
urlValues.Add("description", argVal.(string))
|
||||
}
|
||||
|
||||
apiResp, err := c.DecortAPICall("POST", DisksCreateAPI, urlValues)
|
||||
apiResp, err := c.DecortAPICall(ctx, "POST", DisksCreateAPI, urlValues)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
@@ -91,7 +91,7 @@ func resourceDiskCreate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
}
|
||||
|
||||
func resourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
diskFacts, err := utilityDiskCheckPresence(d, m)
|
||||
diskFacts, err := utilityDiskCheckPresence(ctx, d, m)
|
||||
if diskFacts == "" {
|
||||
// if empty string is returned from utilityDiskCheckPresence then there is no
|
||||
// such Disk and err tells so - just return it to the calling party
|
||||
@@ -121,7 +121,7 @@ func resourceDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
sizeParams := &url.Values{}
|
||||
sizeParams.Add("diskId", d.Id())
|
||||
sizeParams.Add("size", fmt.Sprintf("%d", newSize.(int)))
|
||||
_, err := c.DecortAPICall("POST", DisksResizeAPI, sizeParams)
|
||||
_, err := c.DecortAPICall(ctx, "POST", DisksResizeAPI, sizeParams)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
@@ -137,7 +137,7 @@ func resourceDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
renameParams := &url.Values{}
|
||||
renameParams.Add("diskId", d.Id())
|
||||
renameParams.Add("name", newName.(string))
|
||||
_, err := c.DecortAPICall("POST", DisksRenameAPI, renameParams)
|
||||
_, err := c.DecortAPICall(ctx, "POST", DisksRenameAPI, renameParams)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
@@ -165,7 +165,7 @@ func resourceDiskDelete(ctx context.Context, d *schema.ResourceData, m interface
|
||||
log.Debugf("resourceDiskDelete: called for Disk ID / name %d / %s, Account ID %d",
|
||||
d.Get("disk_id").(int), d.Get("name").(string), d.Get("account_id").(int))
|
||||
|
||||
diskFacts, err := utilityDiskCheckPresence(d, m)
|
||||
diskFacts, err := utilityDiskCheckPresence(ctx, d, m)
|
||||
if diskFacts == "" {
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
@@ -187,7 +187,7 @@ func resourceDiskDelete(ctx context.Context, d *schema.ResourceData, m interface
|
||||
params.Add("permanently", "1")
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
_, err = c.DecortAPICall("POST", DisksDeleteAPI, params)
|
||||
_, err = c.DecortAPICall(ctx, "POST", DisksDeleteAPI, params)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
@@ -195,12 +195,12 @@ func resourceDiskDelete(ctx context.Context, d *schema.ResourceData, m interface
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceDiskExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
||||
func resourceDiskExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||
// Reminder: according to Terraform rules, this function should not modify its ResourceData argument
|
||||
log.Debugf("resourceDiskExists: called for Disk ID / name %d / %s, Account ID %d",
|
||||
d.Get("disk_id").(int), d.Get("name").(string), d.Get("account_id").(int))
|
||||
|
||||
diskFacts, err := utilityDiskCheckPresence(d, m)
|
||||
diskFacts, err := utilityDiskCheckPresence(ctx, d, m)
|
||||
if diskFacts == "" {
|
||||
if err != nil {
|
||||
return false, err
|
||||
@@ -320,7 +320,6 @@ func ResourceDisk() *schema.Resource {
|
||||
ReadContext: resourceDiskRead,
|
||||
UpdateContext: resourceDiskUpdate,
|
||||
DeleteContext: resourceDiskDelete,
|
||||
Exists: resourceDiskExists,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
State: schema.ImportStatePassthrough,
|
||||
|
||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
@@ -43,7 +44,7 @@ import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityDiskCheckPresence(d *schema.ResourceData, m interface{}) (string, error) {
|
||||
func utilityDiskCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
|
||||
// This function tries to locate Disk by one of the following algorithms depending on
|
||||
// the parameters passed:
|
||||
// - if disk ID is specified -> by disk ID
|
||||
@@ -81,7 +82,7 @@ func utilityDiskCheckPresence(d *schema.ResourceData, m interface{}) (string, er
|
||||
// disk ID is specified, try to get disk instance straight by this ID
|
||||
log.Debugf("utilityDiskCheckPresence: locating disk by its ID %d", theId)
|
||||
urlValues.Add("diskId", fmt.Sprintf("%d", theId))
|
||||
diskFacts, err := c.DecortAPICall("POST", DisksGetAPI, urlValues)
|
||||
diskFacts, err := c.DecortAPICall(ctx, "POST", DisksGetAPI, urlValues)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -100,7 +101,7 @@ func utilityDiskCheckPresence(d *schema.ResourceData, m interface{}) (string, er
|
||||
// obtain Account ID by account name - it should not be zero on success
|
||||
|
||||
urlValues.Add("accountId", fmt.Sprintf("%d", d.Get("account_id").(int)))
|
||||
diskFacts, err := c.DecortAPICall("POST", DisksListAPI, urlValues)
|
||||
diskFacts, err := c.DecortAPICall(ctx, "POST", DisksListAPI, urlValues)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@@ -43,7 +44,7 @@ import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityDiskListCheckPresence(d *schema.ResourceData, m interface{}) (DisksListResp, error) {
|
||||
func utilityDiskListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (DisksListResp, error) {
|
||||
diskList := DisksListResp{}
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
@@ -62,7 +63,7 @@ func utilityDiskListCheckPresence(d *schema.ResourceData, m interface{}) (DisksL
|
||||
}
|
||||
|
||||
log.Debugf("utilityDiskListCheckPresence: load grid list")
|
||||
diskListRaw, err := c.DecortAPICall("POST", DisksListAPI, urlValues)
|
||||
diskListRaw, err := c.DecortAPICall(ctx, "POST", DisksListAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user