Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Migratable to pi_instance #2801

Merged
merged 2 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ibm/data_source_ibm_pi_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func dataSourceIBMPINetworksRead(d *schema.ResourceData, meta interface{}) error
networkC := instance.NewIBMPINetworkClient(sess, powerinstanceid)
networkdata, err := networkC.Get(d.Get(helpers.PINetworkName).(string), powerinstanceid, getTimeOut)

if err != nil {
if err != nil || networkdata == nil {
return err
}

Expand Down
7 changes: 2 additions & 5 deletions ibm/data_source_ibm_pi_public_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,8 @@ func dataSourceIBMPIPublicNetworksRead(d *schema.ResourceData, meta interface{})
networkC := instance.NewIBMPINetworkClient(sess, powerinstanceid)
networkdata, err := networkC.GetPublic(powerinstanceid, getTimeOut)

if err != nil {
return err
}
if len(networkdata.Networks) < 1 {
return fmt.Errorf("No Public Network Found in %s", powerinstanceid)
if err != nil || networkdata == nil || len(networkdata.Networks) < 1 {
return fmt.Errorf("Error getting public network or no public network found in %s", powerinstanceid)
}
d.SetId(*networkdata.Networks[0].NetworkID)
if networkdata.Networks[0].Type != nil {
Expand Down
20 changes: 18 additions & 2 deletions ibm/resource_ibm_pi_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,17 @@ func resourceIBMPIInstance() *schema.Resource {
Computed: true,
Description: "PI instance status",
},
"pi_migratable": {
Type: schema.TypeBool,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think as per desgin we added arguments starts with pi_...Should be add a new argument pi_migartable instead of migartable(may be we can mark this as derprecated)

Optional: true,
Computed: true,
Description: "set to true to enable migration of the PI instance",
},
"migratable": {
Type: schema.TypeBool,
Computed: true,
Description: "set to true to enable migration of the PI instance",
Deprecated: "This field is deprecated, Use pi_migratable instead.",
},
"min_processors": {
Type: schema.TypeFloat,
Expand Down Expand Up @@ -300,6 +307,10 @@ func resourceIBMPIInstanceCreate(d *schema.ResourceData, meta interface{}) error
if r, ok := d.GetOk(helpers.PIInstanceReplicationScheme); ok {
replicationNamingScheme = r.(string)
}
var migratable bool
if m, ok := d.GetOk("pi_migratable"); ok {
migratable = m.(bool)
}
imageid := d.Get(helpers.PIInstanceImageName).(string)
processortype := d.Get(helpers.PIInstanceProcType).(string)

Expand Down Expand Up @@ -340,6 +351,7 @@ func resourceIBMPIInstanceCreate(d *schema.ResourceData, meta interface{}) error
ReplicantNamingScheme: ptrToString(replicationNamingScheme),
ReplicantAffinityPolicy: ptrToString(replicationpolicy),
Networks: buildPVMNetworks(networks),
Migratable: &migratable,
}
if len(volids) > 0 {
body.VolumeIds = volids
Expand Down Expand Up @@ -413,7 +425,7 @@ func resourceIBMPIInstanceRead(d *schema.ResourceData, meta interface{}) error {
}
d.Set(helpers.PIInstanceProcType, powervmdata.ProcType)
if powervmdata.Migratable != nil {
d.Set("migratable", powervmdata.Migratable)
d.Set("pi_migratable", powervmdata.Migratable)
}
if &powervmdata.Minproc != nil {
d.Set("min_processors", powervmdata.Minproc)
Expand Down Expand Up @@ -608,7 +620,7 @@ func resourceIBMPIInstanceUpdate(d *schema.ResourceData, meta interface{}) error
}
}

if d.HasChange(helpers.PIInstanceMemory) || d.HasChange(helpers.PIInstanceProcessors) {
if d.HasChange(helpers.PIInstanceMemory) || d.HasChange(helpers.PIInstanceProcessors) || d.HasChange("pi_migratable") {

maxMemLpar := d.Get("max_memory").(float64)
maxCPULpar := d.Get("max_processors").(float64)
Expand Down Expand Up @@ -648,6 +660,10 @@ func resourceIBMPIInstanceUpdate(d *schema.ResourceData, meta interface{}) error
ServerName: name,
}
body.VirtualCores = &models.VirtualCores{Assigned: &assignedVirtualCores}
if m, ok := d.GetOk("pi_migratable"); ok {
migratable := m.(bool)
body.Migratable = &migratable
}

_, err = client.Update(parts[1], powerinstanceid, &p_cloud_p_vm_instances.PcloudPvminstancesPutParams{Body: body}, updateTimeOut)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/pi_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Review the argument references that you can specify for your resource.
- `pi_instance_name` - (Required, String) The name of the Power Systems Virtual Server instance.
- `pi_key_pair_name` - (Required, String) The name of the SSH key that you want to use to access your Power Systems Virtual Server instance. The SSH key must be uploaded to IBM Cloud.
- `pi_memory` - (Required, Float) The amount of memory that you want to assign to your instance in gigabytes.
- `pi_migratable`- (Optional, Bool) Indicates the VM is migrated or not.
- `pi_network_ids` - (Required, String) The list of network IDs that you want to assign to the instance.
- `pi_pin_policy` - (Optional, String) Select the pinning policy for your Power Systems Virtual Server instance. Supported values are `soft`, `hard`, and `none`. **Note** You can choose to soft pin (`soft`) or hard pin (`hard`) a virtual server to the physical host where it runs. When you soft pin an instance for high availability, the instance automatically migrates back to the original host once the host is back to its operating state. If the instance has a licensing restriction with the host, the hard pin option restricts the movement of the instance during remote restart, automated remote restart, DRO, and live partition migration. The default pinning policy is `none`.
- `pi_processors` - (Required, Float) The number of vCPUs to assign to the VM as visible within the guest Operating System.
Expand Down Expand Up @@ -89,9 +90,9 @@ In addition to all argument reference list, you can access the following attribu
- `health_status` - (String) The health status of the VM.
- `id` - (String) The unique identifier of the instance. The ID is composed of `<power_instance_id>/<instance_id>`.
- `instance_id` - (String) The unique identifier of the instance.
- `migratable`- (Bool) Indicates the VM is migrated or not.
- `max_processors`- Integer- The maximum number of processors that can be allocated to the instance with shutting down or rebooting the `LPAR`.
- `max_virtual_cores` - (Integer) The maximum number of virtual cores.
- `migratable` - (Bool) Indicates the VM is migrated or not.This attribute is Deprecated use `pi_migratable` instead
- `min_processors` - Float - The minimum number of processors that the instance can have.
- `min_memory` - (Integer) The minimum memory that was allocated to the instance.
- `max_memory`- (Integer) The maximum amount of memory that can be allocated to the instance without shut down or reboot the `LPAR`.
Expand Down