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

Support storage pool and affinity for instance and volume #3270

Merged
merged 1 commit into from
Nov 3, 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
7 changes: 7 additions & 0 deletions ibm/data_source_ibm_pi_catalog_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func dataSourceIBMPICatalogImages() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"storage_pool": {
Type: schema.TypeString,
Computed: true,
},
"creation_date": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -137,6 +141,9 @@ func dataSourceIBMPICatalogImagesRead(d *schema.ResourceData, meta interface{})
if i.StorageType != nil {
image["storage_type"] = *i.StorageType
}
if i.StoragePool != nil {
image["storage_pool"] = *i.StoragePool
}
if i.CreationDate != nil {
image["creation_date"] = i.CreationDate.String()
}
Expand Down
5 changes: 5 additions & 0 deletions ibm/data_source_ibm_pi_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func dataSourceIBMPIImage() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"storage_pool": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -82,6 +86,7 @@ func dataSourceIBMPIImagesRead(d *schema.ResourceData, meta interface{}) error {
d.Set("hypervisor", imagedata.Specifications.HypervisorType)
d.Set("operatingsystem", imagedata.Specifications.OperatingSystem)
d.Set("storage_type", imagedata.StorageType)
d.Set("storage_pool", imagedata.StoragePool)

return nil

Expand Down
5 changes: 5 additions & 0 deletions ibm/data_source_ibm_pi_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func dataSourceIBMPIImages() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"storage_pool": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -107,6 +111,7 @@ func flattenStockImages(list []*models.ImageReference) []map[string]interface{}
"href": *i.Href,
"name": *i.Name,
"storage_type": *i.StorageType,
"storage_pool": *i.StoragePool,
}

result = append(result, l)
Expand Down
10 changes: 10 additions & 0 deletions ibm/data_source_ibm_pi_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ func dataSourceIBMPIInstance() *schema.Resource {
Type: schema.TypeInt,
Computed: true,
},
"storage_type": {
Type: schema.TypeString,
Computed: true,
},
"storage_pool": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -162,6 +170,8 @@ func dataSourceIBMPIInstancesRead(d *schema.ResourceData, meta interface{}) erro
d.Set("virtual_cores_assigned", powervmdata.VirtualCores.Assigned)
d.Set("max_virtual_cores", powervmdata.VirtualCores.Max)
d.Set("min_virtual_cores", powervmdata.VirtualCores.Min)
d.Set("storage_type", powervmdata.StorageType)
d.Set("storage_pool", powervmdata.StoragePool)

if powervmdata.Addresses != nil {
pvmaddress := make([]map[string]interface{}, len(powervmdata.Addresses))
Expand Down
5 changes: 5 additions & 0 deletions ibm/data_source_ibm_pi_instance_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ func dataSourceIBMPIInstanceVolumes() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"pool": {
Type: schema.TypeString,
Computed: true,
},
"shareable": {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -117,6 +121,7 @@ func flattenVolumesInstances(list []*models.VolumeReference) []map[string]interf
"name": *i.Name,
"size": *i.Size,
"type": *i.DiskType,
"pool": i.VolumePool,
"shareable": *i.Shareable,
"bootable": *i.Bootable,
}
Expand Down
32 changes: 9 additions & 23 deletions ibm/data_source_ibm_pi_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,15 @@ func dataSourceIBMPIVolume() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},

"bootable": {
Type: schema.TypeBool,
Computed: true,
},
"creation_date": {
"disk_type": {
Type: schema.TypeString,
Computed: true,
},

"disk_type": {
"volume_pool": {
Type: schema.TypeString,
Computed: true,
},
Expand All @@ -86,21 +80,13 @@ func dataSourceIBMPIVolumeRead(d *schema.ResourceData, meta interface{}) error {
}

d.SetId(*volumedata.VolumeID)
if volumedata.Size != nil {
d.Set("size", volumedata.Size)
}
if &volumedata.DiskType != nil {
d.Set("disk_type", volumedata.DiskType)
}
if &volumedata.Bootable != nil {
d.Set("bootable", volumedata.Bootable)
}
if &volumedata.State != nil {
d.Set("state", volumedata.State)
}
if &volumedata.Wwn != nil {
d.Set("wwn", volumedata.Wwn)
}
d.Set("size", volumedata.Size)
d.Set("state", volumedata.State)
d.Set("shareable", volumedata.Shareable)
d.Set("bootable", volumedata.Bootable)
d.Set("disk_type", volumedata.DiskType)
d.Set("volume_pool", volumedata.VolumePool)
d.Set("wwn", volumedata.Wwn)
return nil

}
75 changes: 73 additions & 2 deletions ibm/resource_ibm_pi_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ const (
warningTimeOut = 30 * time.Second
activeTimeOut = 2 * time.Minute
// power service instance capabilities
CUSTOM_VIRTUAL_CORES = "custom-virtualcores"
PIInstanceNetwork = "pi_network"
CUSTOM_VIRTUAL_CORES = "custom-virtualcores"
PIInstanceNetwork = "pi_network"
PIInstanceStoragePool = "pi_storage_pool"
)

func resourceIBMPIInstance() *schema.Resource {
Expand Down Expand Up @@ -125,6 +126,44 @@ func resourceIBMPIInstance() *schema.Resource {
Computed: true,
Description: "Storage type for server deployment",
},
PIInstanceStoragePool: {
yussufsh marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Storage Pool for server deployment; if provided then pi_affinity_policy and pi_storage_type will be ignored",
},
PIAffinityPolicy: {
Type: schema.TypeString,
Optional: true,
Description: "Affinity policy for pvm instance being created; ignored if pi_storage_pool provided; for policy affinity requires one of pi_affinity_instance or pi_affinity_volume to be specified; for policy anti-affinity requires one of pi_anti_affinity_instances or pi_anti_affinity_volumes to be specified",
ValidateFunc: validateAllowedStringValue([]string{"affinity", "anti-affinity"}),
},
PIAffinityVolume: {
Type: schema.TypeString,
Optional: true,
yussufsh marked this conversation as resolved.
Show resolved Hide resolved
Description: "Volume (ID or Name) to base storage affinity policy against; required if requesting affinity and pi_affinity_instance is not provided",
ConflictsWith: []string{PIAffinityInstance},
},
PIAffinityInstance: {
Type: schema.TypeString,
Optional: true,
Description: "PVM Instance (ID or Name) to base storage affinity policy against; required if requesting storage affinity and pi_affinity_volume is not provided",
ConflictsWith: []string{PIAffinityVolume},
},
PIAntiAffinityVolumes: {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "List of volumes to base storage anti-affinity policy against; required if requesting anti-affinity and pi_anti_affinity_instances is not provided",
ConflictsWith: []string{PIAntiAffinityInstances},
},
PIAntiAffinityInstances: {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "List of pvmInstances to base storage anti-affinity policy against; required if requesting anti-affinity and pi_anti_affinity_volumes is not provided",
ConflictsWith: []string{PIAntiAffinityVolumes},
},

helpers.PIInstanceStorageConnection: {
Type: schema.TypeString,
Expand Down Expand Up @@ -441,6 +480,37 @@ func resourceIBMPIInstanceCreate(d *schema.ResourceData, meta interface{}) error
if st, ok := d.GetOk(helpers.PIInstanceStorageType); ok {
body.StorageType = st.(string)
}
if sp, ok := d.GetOk(PIInstanceStoragePool); ok {
body.StoragePool = sp.(string)
}

if ap, ok := d.GetOk(PIAffinityPolicy); ok {
policy := ap.(string)
affinity := &models.StorageAffinity{
AffinityPolicy: &policy,
}

if policy == "affinity" {
if av, ok := d.GetOk(PIAffinityVolume); ok {
afvol := av.(string)
affinity.AffinityVolume = &afvol
}
if ai, ok := d.GetOk(PIAffinityInstance); ok {
afins := ai.(string)
affinity.AffinityPVMInstance = &afins
}
} else {
if avs, ok := d.GetOk(PIAntiAffinityVolumes); ok {
afvols := expandStringList(avs.([]interface{}))
affinity.AntiAffinityVolumes = afvols
}
if ais, ok := d.GetOk(PIAntiAffinityInstances); ok {
afinss := expandStringList(ais.([]interface{}))
affinity.AntiAffinityPVMInstances = afinss
}
}
body.StorageAffinity = affinity
}

if sc, ok := d.GetOk(helpers.PIInstanceStorageConnection); ok {
body.StorageConnection = sc.(string)
Expand Down Expand Up @@ -512,6 +582,7 @@ func resourceIBMPIInstanceRead(d *schema.ResourceData, meta interface{}) error {
if powervmdata.StorageType != nil {
d.Set(helpers.PIInstanceStorageType, powervmdata.StorageType)
}
d.Set(helpers.PIInstanceStoragePool, powervmdata.StoragePool)
d.Set(helpers.PICloudInstanceId, powerinstanceid)
d.Set("instance_id", powervmdata.PvmInstanceID)
d.Set(helpers.PIInstanceName, powervmdata.ServerName)
Expand Down
Loading