Implement compute update for CPU/RAM capacity and extra disks

rc-1.0
Sergey Shubin svs1370 4 years ago
parent ba19e7f975
commit 44bed84716

@ -43,18 +43,14 @@ func parseComputeDisksToExtraDisks(disks []DiskRecord) []interface{} {
length := len(disks) length := len(disks)
log.Debugf("parseComputeDisksToExtraDisks: called for %d disks", length) log.Debugf("parseComputeDisksToExtraDisks: called for %d disks", length)
if length == 1 && disks[0].Type == "B" { if length == 0 || ( length == 1 && disks[0].Type == "B" ) {
// the disk list is empty (which is kind of strange - diskless compute?), or
// there is only one disk in the list and it is a boot disk; // there is only one disk in the list and it is a boot disk;
// as we skip boot disks, the result will be of 0 length // as we skip boot disks, the result will be of 0 length anyway
length = 0 return make([]interface{}, 0)
} }
result := make([]interface{}, length-1) result := make([]interface{}, length-1)
if length == 0 {
return result
}
idx := 0 idx := 0
for _, value := range disks { for _, value := range disks {
if value.Type == "B" { if value.Type == "B" {

@ -119,7 +119,7 @@ func resourceDiskUpdate(d *schema.ResourceData, m interface{}) error {
} }
func resourceDiskDelete(d *schema.ResourceData, m interface{}) error { func resourceDiskDelete(d *schema.ResourceData, m interface{}) error {
// NOTE: this function tries to destroy target Disk "permanently", so // NOTE: this function tries to detach and destroy target Disk "permanently", so
// there is no way to restore it. // there is no way to restore it.
// If, however, the disk is attached to a compute, the method will // If, however, the disk is attached to a compute, the method will
// fail (by failing the underpinning DECORt API call, which is issued with detach=false) // fail (by failing the underpinning DECORt API call, which is issued with detach=false)
@ -135,6 +135,12 @@ func resourceDiskDelete(d *schema.ResourceData, m interface{}) error {
params := &url.Values{} params := &url.Values{}
params.Add("diskId", d.Id()) params.Add("diskId", d.Id())
// NOTE: we are not force-detaching disk from a compute (if attached) this protecting
// data that may be on that disk from destruction.
// However, this may change in the future, as TF state management logic may want
// to delete disk resource BEFORE it is detached from compute instance, and, while
// perfectly OK from data preservation viewpoint, this is breaking expected TF workflow
// in the eyes of an experienced TF user
params.Add("detach", "false") params.Add("detach", "false")
params.Add("permanently", "true") params.Add("permanently", "true")

@ -86,10 +86,7 @@ func (ctrl *ControllerCfg) utilityComputeExtraDisksConfigure(d *schema.ResourceD
return nil return nil
} }
attach_list := make([]int, 0, MaxExtraDisksPerCompute) var attach_list, detach_list []int
detach_list := make([]int, 0, MaxExtraDisksPerCompute)
attIdx := 0
detIdx := 0
match := false match := false
for _, oDisk := range old_disks { for _, oDisk := range old_disks {
@ -101,8 +98,7 @@ func (ctrl *ControllerCfg) utilityComputeExtraDisksConfigure(d *schema.ResourceD
} }
} }
if !match { if !match {
detach_list[detIdx] = oDisk.(int) detach_list = append(detach_list, oDisk.(int))
detIdx++
} }
} }
log.Debugf("utilityComputeExtraDisksConfigure: detach list has %d items for Compute ID %s", len(detach_list), d.Id()) log.Debugf("utilityComputeExtraDisksConfigure: detach list has %d items for Compute ID %s", len(detach_list), d.Id())
@ -116,8 +112,7 @@ func (ctrl *ControllerCfg) utilityComputeExtraDisksConfigure(d *schema.ResourceD
} }
} }
if !match { if !match {
attach_list[attIdx] = nDisk.(int) attach_list = append(attach_list, nDisk.(int))
attIdx++
} }
} }
log.Debugf("utilityComputeExtraDisksConfigure: attach list has %d items for Compute ID %s", len(attach_list), d.Id()) log.Debugf("utilityComputeExtraDisksConfigure: attach list has %d items for Compute ID %s", len(attach_list), d.Id())
@ -213,10 +208,7 @@ func (ctrl *ControllerCfg) utilityComputeNetworksConfigure(d *schema.ResourceDat
return nil return nil
} }
attachList := make([]ComputeNetMgmtRecord, 0, MaxNetworksPerCompute) var attachList, detachList []ComputeNetMgmtRecord
detachList := make([]ComputeNetMgmtRecord, 0, MaxNetworksPerCompute)
attIdx := 0
detIdx := 0
match := false match := false
for _, oRunner := range oldNets { for _, oRunner := range oldNets {
@ -230,11 +222,13 @@ func (ctrl *ControllerCfg) utilityComputeNetworksConfigure(d *schema.ResourceDat
} }
} }
if !match { if !match {
detachList[attIdx].ID = oSpecs["net_id"].(int) newItem := ComputeNetMgmtRecord{
detachList[detIdx].Type = oSpecs["net_type"].(string) ID: oSpecs["net_id"].(int),
detachList[detIdx].IPAddress = oSpecs["ip_address"].(string) Type: oSpecs["net_type"].(string),
detachList[detIdx].MAC = oSpecs["mac"].(string) IPAddress: oSpecs["ip_address"].(string),
detIdx++ MAC: oSpecs["mac"].(string),
}
detachList = append(detachList, newItem)
} }
} }
log.Debugf("utilityComputeNetworksConfigure: detach list has %d items for Compute ID %s", len(detachList), d.Id()) log.Debugf("utilityComputeNetworksConfigure: detach list has %d items for Compute ID %s", len(detachList), d.Id())
@ -250,14 +244,16 @@ func (ctrl *ControllerCfg) utilityComputeNetworksConfigure(d *schema.ResourceDat
} }
} }
if !match { if !match {
attachList[attIdx].ID = nSpecs["net_id"].(int) newItem := ComputeNetMgmtRecord{
attachList[detIdx].Type = nSpecs["net_type"].(string) ID: nSpecs["net_id"].(int),
Type: nSpecs["net_type"].(string),
}
if nSpecs["ip_address"] != nil { if nSpecs["ip_address"] != nil {
attachList[detIdx].IPAddress = nSpecs["ip_address"].(string) newItem.IPAddress = nSpecs["ip_address"].(string)
} else { } else {
attachList[detIdx].IPAddress = "" // make sure it is empty, if not coming from the schema newItem.IPAddress = "" // make sure it is empty, if not coming from the schema
} }
attIdx++ attachList = append(attachList, newItem)
} }
} }
log.Debugf("utilityComputeNetworksConfigure: attach list has %d items for Compute ID %s", len(attachList), d.Id()) log.Debugf("utilityComputeNetworksConfigure: attach list has %d items for Compute ID %s", len(attachList), d.Id())

Loading…
Cancel
Save