4.3.5
This commit is contained in:
@@ -260,6 +260,7 @@ func flattenComputeDisksDemo(disksList compute.ListComputeDisks, extraDisks []in
|
|||||||
sort.Slice(res, func(i, j int) bool {
|
sort.Slice(res, func(i, j int) bool {
|
||||||
return res[i]["disk_id"].(uint64) < res[j]["disk_id"].(uint64)
|
return res[i]["disk_id"].(uint64) < res[j]["disk_id"].(uint64)
|
||||||
})
|
})
|
||||||
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,7 +301,7 @@ func flattenCompute(d *schema.ResourceData, computeRec compute.RecordCompute) er
|
|||||||
|
|
||||||
//check extraDisks, ipa_type, is,
|
//check extraDisks, ipa_type, is,
|
||||||
d.SetId(strconv.FormatUint(computeRec.ID, 10))
|
d.SetId(strconv.FormatUint(computeRec.ID, 10))
|
||||||
d.Set("acl", flattenACL(computeRec.ACL))
|
// d.Set("acl", flattenACL(computeRec.ACL))
|
||||||
d.Set("account_id", computeRec.AccountID)
|
d.Set("account_id", computeRec.AccountID)
|
||||||
d.Set("account_name", computeRec.AccountName)
|
d.Set("account_name", computeRec.AccountName)
|
||||||
d.Set("affinity_weight", computeRec.AffinityWeight)
|
d.Set("affinity_weight", computeRec.AffinityWeight)
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
argVal, ok = d.GetOk("extra_disks")
|
argVal, ok = d.GetOk("extra_disks")
|
||||||
if ok && argVal.(*schema.Set).Len() > 0 {
|
if ok && argVal.(*schema.Set).Len() > 0 {
|
||||||
log.Debugf("resourceComputeCreate: calling utilityComputeExtraDisksConfigure to attach %d extra disk(s)", argVal.(*schema.Set).Len())
|
log.Debugf("resourceComputeCreate: calling utilityComputeExtraDisksConfigure to attach %d extra disk(s)", argVal.(*schema.Set).Len())
|
||||||
err = utilityComputeExtraDisksConfigure(ctx, d, m, false)
|
err = utilityComputeExtraDisksConfigure(ctx, d, m, false, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("resourceComputeCreate: error when attaching extra disk(s) to a new Compute ID %d: %v", computeId, err)
|
log.Errorf("resourceComputeCreate: error when attaching extra disk(s) to a new Compute ID %d: %v", computeId, err)
|
||||||
cleanup = true
|
cleanup = true
|
||||||
@@ -716,7 +716,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
}
|
}
|
||||||
|
|
||||||
if d.HasChange("extra_disks") {
|
if d.HasChange("extra_disks") {
|
||||||
err := utilityComputeExtraDisksConfigure(ctx, d, m, true) // pass do_delta = true to apply changes, if any
|
err := utilityComputeExtraDisksConfigure(ctx, d, m, true, computeRec.Disks) // pass do_delta = true to apply changes, if any
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -755,7 +755,23 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
|
|
||||||
for _, el := range oldConv {
|
for _, el := range oldConv {
|
||||||
if !isContainsDisk(newConv, el) {
|
if !isContainsDisk(newConv, el) {
|
||||||
|
flag := false
|
||||||
|
extraDisks := d.Get("extra_disks").(*schema.Set).List()
|
||||||
|
delDisk := el.(map[string]interface{})
|
||||||
|
delDiskId := delDisk["disk_id"].(int)
|
||||||
|
|
||||||
|
for _, extraDiskId := range extraDisks {
|
||||||
|
if extraDiskId.(int) == delDiskId {
|
||||||
|
flag = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !flag {
|
||||||
deletedDisks = append(deletedDisks, el)
|
deletedDisks = append(deletedDisks, el)
|
||||||
|
} else {
|
||||||
|
log.Debugf("disk %d will not be deleted because it is present in the extra_disks block", delDiskId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -792,6 +808,8 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
Permanently: diskConv["permanently"].(bool),
|
Permanently: diskConv["permanently"].(bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Debugf("trying to delete disk %d", req.DiskID)
|
||||||
|
|
||||||
_, err := c.CloudAPI().Compute().DiskDel(ctx, req)
|
_, err := c.CloudAPI().Compute().DiskDel(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
@@ -1759,6 +1777,7 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
|
|||||||
"extra_disks": {
|
"extra_disks": {
|
||||||
Type: schema.TypeSet,
|
Type: schema.TypeSet,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
MaxItems: constants.MaxExtraDisksPerCompute,
|
MaxItems: constants.MaxExtraDisksPerCompute,
|
||||||
Elem: &schema.Schema{
|
Elem: &schema.Schema{
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ func matchComputes(computeList *compute.ListComputes) *compute.ListComputes {
|
|||||||
return &result
|
return &result
|
||||||
}
|
}
|
||||||
|
|
||||||
func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceData, m interface{}, do_delta bool) error {
|
func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceData, m interface{}, do_delta bool, disks compute.ListComputeDisks) error {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
|
|
||||||
log.Debugf("utilityComputeExtraDisksConfigure: called for Compute ID %s with do_delta = %t", d.Id(), do_delta)
|
log.Debugf("utilityComputeExtraDisksConfigure: called for Compute ID %s with do_delta = %t", d.Id(), do_delta)
|
||||||
@@ -138,6 +138,22 @@ func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceDa
|
|||||||
DiskID: uint64(diskId.(int)),
|
DiskID: uint64(diskId.(int)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Debug("before attach HERE0")
|
||||||
|
|
||||||
|
flag := false
|
||||||
|
|
||||||
|
// check if there is an extra disk in the disks from the platform, so as not to attach it if it is already attached
|
||||||
|
for _, elem := range disks {
|
||||||
|
if elem.ID == uint64(diskId.(int)) {
|
||||||
|
flag = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if flag {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
_, err := c.CloudAPI().Compute().DiskAttach(ctx, req)
|
_, err := c.CloudAPI().Compute().DiskAttach(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("utilityComputeExtraDisksConfigure: failed to attach disk ID %d to Compute ID %s: %s", diskId.(int), d.Id(), err)
|
log.Errorf("utilityComputeExtraDisksConfigure: failed to attach disk ID %d to Compute ID %s: %s", diskId.(int), d.Id(), err)
|
||||||
|
|||||||
Reference in New Issue
Block a user