|
|
|
|
@@ -248,6 +248,16 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
|
|
|
|
|
createReqX86.HPBacked = d.Get("hp_backed").(bool)
|
|
|
|
|
createReqX86.Chipset = d.Get("chipset").(string)
|
|
|
|
|
|
|
|
|
|
if preferredCPU, ok := d.GetOk("preferred_cpu"); ok {
|
|
|
|
|
preferredList := preferredCPU.([]interface{})
|
|
|
|
|
if len(preferredList) > 0 {
|
|
|
|
|
for _, v := range preferredList {
|
|
|
|
|
cpuNum := v.(int)
|
|
|
|
|
createReqX86.PreferredCPU = append(createReqX86.PreferredCPU, int64(cpuNum))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Debugf("resourceComputeCreate: creating Compute of type KVM VM x86")
|
|
|
|
|
apiResp, err := c.CloudAPI().KVMX86().Create(ctx, createReqX86)
|
|
|
|
|
if err != nil {
|
|
|
|
|
@@ -307,6 +317,17 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if d.Get("pin_to_stack").(bool) {
|
|
|
|
|
req := compute.PinToStackRequest{
|
|
|
|
|
ComputeID: computeId,
|
|
|
|
|
}
|
|
|
|
|
req.AutoStart = d.Get("auto_start_w_node").(bool)
|
|
|
|
|
_, err := c.CloudAPI().Compute().PinToStack(ctx, req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
warnings.Add(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Note bene: we created compute in a STOPPED state (this is required to properly attach 1st network interface),
|
|
|
|
|
// now we need to start it before we report the sequence complete
|
|
|
|
|
if start, ok := d.GetOk("started"); ok {
|
|
|
|
|
@@ -487,17 +508,6 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if d.Get("pin_to_stack").(bool) {
|
|
|
|
|
req := compute.PinToStackRequest{
|
|
|
|
|
ComputeID: computeId,
|
|
|
|
|
}
|
|
|
|
|
req.AutoStart = d.Get("auto_start_w_node").(bool)
|
|
|
|
|
_, err := c.CloudAPI().Compute().PinToStack(ctx, req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
warnings.Add(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !d.Get("pin_to_stack").(bool) && d.Get("auto_start_w_node").(bool) {
|
|
|
|
|
req := compute.UpdateRequest{
|
|
|
|
|
ComputeID: computeId,
|
|
|
|
|
@@ -816,6 +826,22 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
|
|
|
|
resizeReq.CPU = 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if resizeReq.CPU != 0 {
|
|
|
|
|
if preferredCPU, ok := d.GetOk("preferred_cpu"); ok {
|
|
|
|
|
preferredList := preferredCPU.([]interface{})
|
|
|
|
|
if len(preferredList) > 0 {
|
|
|
|
|
for _, v := range preferredList {
|
|
|
|
|
cpuNum := v.(int)
|
|
|
|
|
resizeReq.PreferredCPU = append(resizeReq.PreferredCPU, int64(cpuNum))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
oldPCPU, newPCPU := d.GetChange("preferred_cpu")
|
|
|
|
|
if len(oldPCPU.([]interface{})) != 0 && len(newPCPU.([]interface{})) == 0 {
|
|
|
|
|
resizeReq.PreferredCPU = []int64{-1}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
oldRam, newRam := d.GetChange("ram")
|
|
|
|
|
if oldRam.(int) != newRam.(int) {
|
|
|
|
|
resizeReq.RAM = uint64(newRam.(int))
|
|
|
|
|
@@ -869,14 +895,31 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if d.HasChange("network") {
|
|
|
|
|
err = utilityComputeNetworksConfigure(ctx, d, m)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return diag.FromErr(err)
|
|
|
|
|
if d.HasChange("pin_to_stack") {
|
|
|
|
|
oldPin, newPin := d.GetChange("pin_to_stack")
|
|
|
|
|
if !newPin.(bool) {
|
|
|
|
|
req := compute.UnpinFromStackRequest{
|
|
|
|
|
ComputeID: computeRec.ID,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := c.CloudAPI().Compute().UnpinFromStack(ctx, req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return diag.FromErr(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if !oldPin.(bool) {
|
|
|
|
|
req := compute.PinToStackRequest{
|
|
|
|
|
ComputeID: computeRec.ID,
|
|
|
|
|
}
|
|
|
|
|
req.AutoStart = d.Get("auto_start_w_node").(bool)
|
|
|
|
|
_, err := c.CloudAPI().Compute().PinToStack(ctx, req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return diag.FromErr(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if d.HasChanges("description", "name", "numa_affinity", "cpu_pin", "hp_backed", "chipset", "auto_start_w_node") {
|
|
|
|
|
if d.HasChanges("description", "name", "numa_affinity", "cpu_pin", "hp_backed", "chipset", "auto_start_w_node", "preferred_cpu") {
|
|
|
|
|
req := compute.UpdateRequest{
|
|
|
|
|
ComputeID: computeRec.ID,
|
|
|
|
|
}
|
|
|
|
|
@@ -893,6 +936,21 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
|
|
|
|
if d.HasChange("chipset") {
|
|
|
|
|
req.Chipset = d.Get("chipset").(string)
|
|
|
|
|
}
|
|
|
|
|
if d.HasChange("preferred_cpu") {
|
|
|
|
|
if preferredCPU, ok := d.GetOk("preferred_cpu"); ok {
|
|
|
|
|
preferredList := preferredCPU.([]interface{})
|
|
|
|
|
if len(preferredList) > 0 {
|
|
|
|
|
for _, v := range preferredList {
|
|
|
|
|
cpuNum := v.(int)
|
|
|
|
|
req.PreferredCPU = append(req.PreferredCPU, int64(cpuNum))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
oldPCPU, newPCPU := d.GetChange("preferred_cpu")
|
|
|
|
|
if len(oldPCPU.([]interface{})) != 0 && len(newPCPU.([]interface{})) == 0 {
|
|
|
|
|
req.PreferredCPU = []int64{-1}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
req.CPUPin = d.Get("cpu_pin").(bool)
|
|
|
|
|
req.HPBacked = d.Get("hp_backed").(bool)
|
|
|
|
|
req.AutoStart = d.Get("auto_start_w_node").(bool)
|
|
|
|
|
@@ -900,7 +958,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
|
|
|
|
// 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 isStopRequired bool
|
|
|
|
|
if d.HasChanges("numa_affinity", "cpu_pin", "hp_backed", "chipset") && d.Get("started").(bool) {
|
|
|
|
|
if d.HasChanges("numa_affinity", "cpu_pin", "hp_backed", "chipset", "preferred_cpu") && d.Get("started").(bool) {
|
|
|
|
|
isStopRequired = true
|
|
|
|
|
}
|
|
|
|
|
if isStopRequired {
|
|
|
|
|
@@ -922,6 +980,13 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if d.HasChange("network") {
|
|
|
|
|
err = utilityComputeNetworksConfigure(ctx, d, m)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return diag.FromErr(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if d.HasChange("disks") {
|
|
|
|
|
deletedDisks := make([]interface{}, 0)
|
|
|
|
|
addedDisks := make([]interface{}, 0)
|
|
|
|
|
@@ -1475,30 +1540,6 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if d.HasChange("pin_to_stack") {
|
|
|
|
|
oldPin, newPin := d.GetChange("pin_to_stack")
|
|
|
|
|
if !newPin.(bool) {
|
|
|
|
|
req := compute.UnpinFromStackRequest{
|
|
|
|
|
ComputeID: computeRec.ID,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := c.CloudAPI().Compute().UnpinFromStack(ctx, req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return diag.FromErr(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if !oldPin.(bool) {
|
|
|
|
|
req := compute.PinToStackRequest{
|
|
|
|
|
ComputeID: computeRec.ID,
|
|
|
|
|
}
|
|
|
|
|
req.AutoStart = d.Get("auto_start_w_node").(bool)
|
|
|
|
|
_, err := c.CloudAPI().Compute().PinToStack(ctx, req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return diag.FromErr(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if d.HasChange("pause") {
|
|
|
|
|
oldPause, newPause := d.GetChange("pause")
|
|
|
|
|
if !newPause.(bool) {
|
|
|
|
|
@@ -2209,6 +2250,15 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
|
|
|
|
|
Default: false,
|
|
|
|
|
Description: "Use Huge Pages to allocate RAM of the virtual machine. The system must be pre-configured by allocating Huge Pages on the physical node.",
|
|
|
|
|
},
|
|
|
|
|
"preferred_cpu": {
|
|
|
|
|
Type: schema.TypeList,
|
|
|
|
|
Optional: true,
|
|
|
|
|
Computed: true,
|
|
|
|
|
Elem: &schema.Schema{
|
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
|
},
|
|
|
|
|
Description: "Recommended isolated CPUs. Field is ignored if compute.cpupin=False or compute.pinned=False",
|
|
|
|
|
},
|
|
|
|
|
"pci_devices": {
|
|
|
|
|
Type: schema.TypeSet,
|
|
|
|
|
Optional: true,
|
|
|
|
|
@@ -2465,7 +2515,7 @@ func ResourceCompute() *schema.Resource {
|
|
|
|
|
|
|
|
|
|
CustomizeDiff: func(ctx context.Context, diff *schema.ResourceDiff, i interface{}) error {
|
|
|
|
|
if diff.HasChanges() || diff.HasChanges("chipset", "pin_to_stack", "auto_start_w_node", "network", "affinity_rules", "anti_affinity_rules",
|
|
|
|
|
"disks", "extra_disks", "tags", "port_forwarding", "user_access", "snapshot", "pci_devices") {
|
|
|
|
|
"disks", "extra_disks", "tags", "port_forwarding", "user_access", "snapshot", "pci_devices", "preferred_cpu") {
|
|
|
|
|
diff.SetNewComputed("updated_time")
|
|
|
|
|
diff.SetNewComputed("updated_by")
|
|
|
|
|
}
|
|
|
|
|
|