1.2.1
This commit is contained in:
@@ -191,6 +191,15 @@ func CreateResourceCompute(ctx context.Context, plan *models.ResourceComputeMode
|
||||
createReqX86.HPBacked = true
|
||||
}
|
||||
|
||||
if !plan.PreferredCPU.IsUnknown() {
|
||||
preferredCPUList := plan.PreferredCPU.Elements()
|
||||
preferredCPU := make([]int64, 0, len(preferredCPUList))
|
||||
for _, elem := range preferredCPUList {
|
||||
preferredCPU = append(preferredCPU, elem.(types.Int64).ValueInt64())
|
||||
}
|
||||
createReqX86.PreferredCPU = preferredCPU
|
||||
}
|
||||
|
||||
tflog.Info(ctx, fmt.Sprintf("CreateResourceCompute: creating Compute of type KVM VM x86"))
|
||||
id, err := c.CloudAPI().KVMX86().Create(ctx, createReqX86)
|
||||
if err != nil {
|
||||
|
||||
@@ -47,6 +47,20 @@ func ComputeResourceResize(ctx context.Context, state *models.ResourceComputeMod
|
||||
resizeReq.CPU = uint64(plan.CPU.ValueInt64())
|
||||
}
|
||||
|
||||
if resizeReq.CPU != 0 {
|
||||
if !plan.PreferredCPU.IsUnknown() {
|
||||
preferredCPUList := plan.PreferredCPU.Elements()
|
||||
preferredCPU := make([]int64, 0, len(preferredCPUList))
|
||||
for _, elem := range preferredCPUList {
|
||||
preferredCPU = append(preferredCPU, elem.(types.Int64).ValueInt64())
|
||||
}
|
||||
resizeReq.PreferredCPU = preferredCPU
|
||||
}
|
||||
if len(state.PreferredCPU.Elements()) != 0 && len(resizeReq.PreferredCPU) == 0 {
|
||||
resizeReq.PreferredCPU = []int64{-1}
|
||||
}
|
||||
}
|
||||
|
||||
if !plan.RAM.Equal(state.RAM) {
|
||||
resizeReq.RAM = uint64(plan.RAM.ValueInt64())
|
||||
}
|
||||
@@ -288,7 +302,7 @@ func ComputeResourceNetworkUpdate(ctx context.Context, state *models.ResourceCom
|
||||
|
||||
needStart := false
|
||||
// need stop to attach first network
|
||||
if len(detachMap) == len(state.Network.Elements()) || (len(state.Network.Elements()) < 1) && len(attachMap) > 0 || hasDPDKnetwork(attachMap) {
|
||||
if len(detachMap) == len(state.Network.Elements()) || (len(state.Network.Elements()) < 1) && len(attachMap) > 0 {
|
||||
tflog.Info(ctx, "ComputeResourceNetworkUpdate: stop compute", map[string]any{"compute_id": computeId})
|
||||
_, err = c.CloudAPI().Compute().Stop(ctx, compute.StopRequest{ComputeID: computeId})
|
||||
if err != nil {
|
||||
@@ -336,6 +350,10 @@ func ComputeResourceNetworkUpdate(ctx context.Context, state *models.ResourceCom
|
||||
}
|
||||
}
|
||||
|
||||
if diags.HasError() {
|
||||
return diags
|
||||
}
|
||||
|
||||
if needStart {
|
||||
diags = ComputeResourceStartStop(ctx, plan, c)
|
||||
}
|
||||
@@ -349,15 +367,6 @@ func ComputeResourceNetworkUpdate(ctx context.Context, state *models.ResourceCom
|
||||
return nil
|
||||
}
|
||||
|
||||
func hasDPDKnetwork(networkAttachMap []map[string]attr.Value) bool {
|
||||
for _, elem := range networkAttachMap {
|
||||
if elem["net_type"].(types.String).ValueString() == "DPDK" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func ComputeResourceComputeUpdate(ctx context.Context, state *models.ResourceComputeModel, plan *models.ResourceComputeModel, c *client.Client) diag.Diagnostics {
|
||||
tflog.Info(ctx, "ComputeResourceComputeUpdate: start update compute parameters", map[string]any{"compute_id": plan.ID.ValueString()})
|
||||
diags := diag.Diagnostics{}
|
||||
@@ -392,11 +401,23 @@ func ComputeResourceComputeUpdate(ctx context.Context, state *models.ResourceCom
|
||||
req.Chipset = plan.Chipset.ValueString()
|
||||
}
|
||||
|
||||
if !plan.PreferredCPU.IsUnknown() {
|
||||
preferredCPUList := plan.PreferredCPU.Elements()
|
||||
preferredCPU := make([]int64, 0, len(preferredCPUList))
|
||||
for _, elem := range preferredCPUList {
|
||||
preferredCPU = append(preferredCPU, elem.(types.Int64).ValueInt64())
|
||||
}
|
||||
req.PreferredCPU = preferredCPU
|
||||
}
|
||||
if len(state.PreferredCPU.Elements()) != 0 && len(req.PreferredCPU) == 0 {
|
||||
req.PreferredCPU = []int64{-1}
|
||||
}
|
||||
|
||||
// Note bene: numa_affinity, cpu_pin and hp_backed are not allowed to be changed for compute in STARTED tech status.
|
||||
// If STARTED, we need to stop it before update
|
||||
|
||||
var isStopRequred bool
|
||||
if !plan.NumaAffinity.Equal(state.NumaAffinity) || !plan.CPUPin.Equal(state.CPUPin) || !plan.HPBacked.Equal(state.HPBacked) || !plan.Chipset.Equal(state.Chipset) {
|
||||
if !plan.NumaAffinity.Equal(state.NumaAffinity) || !plan.CPUPin.Equal(state.CPUPin) || !plan.HPBacked.Equal(state.HPBacked) || !plan.Chipset.Equal(state.Chipset) || (len(req.PreferredCPU) != 0) {
|
||||
isStopRequred = true
|
||||
tflog.Info(ctx, "ComputeResourceComputeUpdate: stop compute", map[string]any{"compute_id": computeId})
|
||||
_, err = c.CloudAPI().Compute().Stop(ctx, compute.StopRequest{ComputeID: computeId})
|
||||
|
||||
Reference in New Issue
Block a user