4.10.1
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package stpolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceStoragePolicyRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
storagePolicy, err := utilityStoragePolicyCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
flattenStoragePolicyData(d, storagePolicy)
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceStoragePolicy() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceStoragePolicyRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceStoragePolicySchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package stpolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceStoragePolicyListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
storagePolicyList, err := utilityStoragePolicyListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenStoragePolicyList(storagePolicyList))
|
||||
d.Set("entry_count", storagePolicyList.EntryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceStoragePolicyList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceStoragePolicyListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceStoragePolicyListSchemaMake(),
|
||||
}
|
||||
}
|
||||
74
internal/service/cloudbroker/stpolicy/flattens.go
Normal file
74
internal/service/cloudbroker/stpolicy/flattens.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package stpolicy
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/stpolicy"
|
||||
)
|
||||
|
||||
func flattenStoragePolicyData(d *schema.ResourceData, storagePolicy *stpolicy.InfoStoragePolicy) {
|
||||
d.Set("storage_policy_id", storagePolicy.ID)
|
||||
d.Set("description", storagePolicy.Description)
|
||||
d.Set("guid", storagePolicy.GUID)
|
||||
d.Set("limit_iops", storagePolicy.LimitIOPS)
|
||||
d.Set("name", storagePolicy.Name)
|
||||
d.Set("status", storagePolicy.Status)
|
||||
d.Set("access_seps_pools", flattenAccessSEPPools(storagePolicy.AccessSEPPools))
|
||||
d.Set("usage", flattenUsage(storagePolicy.Usage))
|
||||
}
|
||||
|
||||
func flattenAccessSEPPools(accessSEPPools stpolicy.ListAccessSEPPools) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(accessSEPPools))
|
||||
for _, asp := range accessSEPPools {
|
||||
temp := map[string]interface{}{
|
||||
"sep_id": asp.SEPID,
|
||||
//TODO
|
||||
//"name": asp.Name,
|
||||
"pool_names": asp.PoolNames,
|
||||
}
|
||||
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenUsage(usage stpolicy.Usage) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
|
||||
temp := map[string]interface{}{
|
||||
"accounts": usage.Accounts,
|
||||
"resgroups": usage.Resgroups,
|
||||
}
|
||||
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenStoragePolicyList(storagePolicyList *stpolicy.ListStoragePolicies) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(storagePolicyList.Data))
|
||||
for _, v := range storagePolicyList.Data {
|
||||
temp := map[string]interface{}{
|
||||
"storage_policy_id": v.ID,
|
||||
"description": v.Description,
|
||||
"guid": v.GUID,
|
||||
"limit_iops": v.LimitIOPS,
|
||||
"name": v.Name,
|
||||
"status": v.Status,
|
||||
"access_seps_pools": flattenAccessSEPPools(v.AccessSEPPools),
|
||||
"usage": flattenUsage(v.Usage),
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenStoragePolicyResource(d *schema.ResourceData, storagePolicy *stpolicy.InfoStoragePolicy) {
|
||||
d.Set("storage_policy_id", storagePolicy.ID)
|
||||
d.Set("description", storagePolicy.Description)
|
||||
d.Set("guid", storagePolicy.GUID)
|
||||
d.Set("limit_iops", storagePolicy.LimitIOPS)
|
||||
d.Set("name", storagePolicy.Name)
|
||||
d.Set("status", storagePolicy.Status)
|
||||
d.Set("access_seps_pools", flattenAccessSEPPools(storagePolicy.AccessSEPPools))
|
||||
d.Set("usage", flattenUsage(storagePolicy.Usage))
|
||||
}
|
||||
182
internal/service/cloudbroker/stpolicy/resource_storage_policy.go
Normal file
182
internal/service/cloudbroker/stpolicy/resource_storage_policy.go
Normal file
@@ -0,0 +1,182 @@
|
||||
package stpolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/stpolicy"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
|
||||
)
|
||||
|
||||
func resourceStoragePolicyCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceTrunkCreate: called with name %s", d.Get("name").(string))
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
warnings := dc.Warnings{}
|
||||
|
||||
name := d.Get("name").(string)
|
||||
aspRaw := d.Get("access_seps_pools")
|
||||
aspFromMan := aspRaw.(*schema.Set).List()
|
||||
aspArray := make([]stpolicy.AccessSEPsPool, 0, len(aspFromMan))
|
||||
aspMap := make(map[uint64][]string)
|
||||
for _, aspfm := range aspFromMan {
|
||||
temp := aspfm.(map[string]interface{})
|
||||
sepID := uint64(temp["sep_id"].(int))
|
||||
_, ok := aspMap[sepID]
|
||||
poolName := temp["pool_name"].(string)
|
||||
if !ok {
|
||||
aspMap[sepID] = []string{}
|
||||
}
|
||||
aspMap[sepID] = append(aspMap[sepID], poolName)
|
||||
}
|
||||
|
||||
for key, value := range aspMap {
|
||||
asp := stpolicy.AccessSEPsPool{}
|
||||
asp.SEPID = key
|
||||
asp.PoolNames = value
|
||||
aspArray = append(aspArray, asp)
|
||||
}
|
||||
|
||||
req := stpolicy.CreateRequest{
|
||||
Name: name,
|
||||
AccessSEPsPools: aspArray,
|
||||
}
|
||||
|
||||
if description, ok := d.GetOk("description"); ok {
|
||||
req.Description = description.(string)
|
||||
}
|
||||
|
||||
if limitIOPS, ok := d.GetOk("limit_iops"); ok {
|
||||
req.LimitIOPS = uint64(limitIOPS.(int))
|
||||
}
|
||||
|
||||
storagePolicyID, err := c.CloudBroker().StPolicy().Create(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(strconv.FormatUint(storagePolicyID, 10))
|
||||
d.Set("storage_policy_id", storagePolicyID)
|
||||
|
||||
if enabled, ok := d.GetOk("enabled"); ok {
|
||||
isToEnable := enabled.(bool)
|
||||
if err := handleStoragePolicyEnabling(ctx, d, c, storagePolicyID, isToEnable); err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
return append(warnings.Get(), resourceStoragePolicyRead(ctx, d, m)...)
|
||||
}
|
||||
|
||||
func resourceStoragePolicyRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceStoragePolicyRead: called with name %s", d.Get("name").(string))
|
||||
|
||||
w := dc.Warnings{}
|
||||
storagePolicyItem, err := utilityStoragePolicyCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
flattenStoragePolicyResource(d, storagePolicyItem)
|
||||
|
||||
return w.Get()
|
||||
}
|
||||
|
||||
func resourceStoragePolicyUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
storagePolicyID, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
|
||||
log.Debugf("resourceStoragePolicyUpdate: called storage policy with id %d", storagePolicyID)
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
_, err := utilityStoragePolicyCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
_, err = strconv.ParseInt(d.Id(), 10, 64)
|
||||
if err != nil {
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if d.HasChanges("name", "limit_iops", "description") {
|
||||
if err := utilityStoragePolicyHandleHasChanges(ctx, d, c, storagePolicyID); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("enabled") {
|
||||
enabled := d.Get("enabled")
|
||||
isToEnable := enabled.(bool)
|
||||
if err := handleStoragePolicyEnabling(ctx, d, c, storagePolicyID, isToEnable); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("access_seps_pools") {
|
||||
if err := utilityStoragePolicyUpdateAccessSEPsPools(ctx, d, c, storagePolicyID); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
return resourceStoragePolicyRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourceStoragePolicyDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceStoragePolicyDelete: called with id %s", d.Id())
|
||||
|
||||
storagePolicyItem, err := utilityStoragePolicyCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := stpolicy.DeleteRequest{
|
||||
StoragePolicyID: storagePolicyItem.ID,
|
||||
}
|
||||
if _, err := c.CloudBroker().StPolicy().Delete(ctx, req); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ResourceStoragePolicy() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
CreateContext: resourceStoragePolicyCreate,
|
||||
ReadContext: resourceStoragePolicyRead,
|
||||
UpdateContext: resourceStoragePolicyUpdate,
|
||||
DeleteContext: resourceStoragePolicyDelete,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
StateContext: schema.ImportStatePassthroughContext,
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &constants.Timeout600s,
|
||||
Read: &constants.Timeout600s,
|
||||
Update: &constants.Timeout600s,
|
||||
Delete: &constants.Timeout600s,
|
||||
Default: &constants.Timeout600s,
|
||||
},
|
||||
|
||||
Schema: resourceStoragePolicySchemaMake(),
|
||||
}
|
||||
}
|
||||
281
internal/service/cloudbroker/stpolicy/schema.go
Normal file
281
internal/service/cloudbroker/stpolicy/schema.go
Normal file
@@ -0,0 +1,281 @@
|
||||
package stpolicy
|
||||
|
||||
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
|
||||
func resourceStoragePolicySchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"storage_policy_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"access_seps_pools": {
|
||||
Type: schema.TypeSet,
|
||||
Required: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"pool_name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"limit_iops": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Default: true,
|
||||
Optional: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"usage": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"accounts": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"resgroups": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func dataSourceStoragePolicySchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"storage_policy_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"limit_iops": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"access_seps_pools": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"pool_names": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"usage": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"accounts": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"resgroups": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func dataSourceStoragePolicyListSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
"page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
"size": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
"by_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"limit_iops": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
"sort_by": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"resgroup_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
"pool_name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"storage_policy_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"limit_iops": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"access_seps_pools": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"pool_names": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"usage": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"accounts": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"resgroups": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
115
internal/service/cloudbroker/stpolicy/utility_storage_policy.go
Normal file
115
internal/service/cloudbroker/stpolicy/utility_storage_policy.go
Normal file
@@ -0,0 +1,115 @@
|
||||
package stpolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/stpolicy"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityStoragePolicyCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*stpolicy.InfoStoragePolicy, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := stpolicy.GetRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
storagePolicyID, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.StoragePolicyID = storagePolicyID
|
||||
} else {
|
||||
req.StoragePolicyID = uint64(d.Get("storage_policy_id").(int))
|
||||
}
|
||||
|
||||
storagePolicyData, err := c.CloudBroker().StPolicy().Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return storagePolicyData, nil
|
||||
}
|
||||
|
||||
func handleStoragePolicyEnabling(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, storagePolicyID uint64, enable bool) error {
|
||||
if enable {
|
||||
req := stpolicy.EnableRequest{
|
||||
StoragePolicyID: storagePolicyID,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().StPolicy().Enable(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
req := stpolicy.DisableRequest{
|
||||
StoragePolicyID: storagePolicyID,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().StPolicy().Disable(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func utilityStoragePolicyHandleHasChanges(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, storagePolicyID uint64) error {
|
||||
req := stpolicy.UpdateRequest{
|
||||
StoragePolicyID: storagePolicyID,
|
||||
}
|
||||
|
||||
if d.HasChange("name") {
|
||||
name := d.Get("name").(string)
|
||||
req.Name = name
|
||||
}
|
||||
|
||||
if d.HasChange("limit_iops") {
|
||||
limitIOPS := uint64(d.Get("limit_iops").(int))
|
||||
req.LimitIOPS = limitIOPS
|
||||
}
|
||||
|
||||
if d.HasChange("description") {
|
||||
description := d.Get("description").(string)
|
||||
req.Description = description
|
||||
}
|
||||
|
||||
if _, err := c.CloudBroker().StPolicy().Update(ctx, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func utilityStoragePolicyUpdateAccessSEPsPools(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, storagePolicyID uint64) error {
|
||||
oldSet, newSet := d.GetChange("access_seps_pools")
|
||||
deletedASP := (oldSet.(*schema.Set).Difference(newSet.(*schema.Set))).List()
|
||||
for _, deletedInterface := range deletedASP {
|
||||
deletedItem := deletedInterface.(map[string]interface{})
|
||||
SEPID := uint64(deletedItem["sep_id"].(int))
|
||||
poolName := deletedItem["pool_name"].(string)
|
||||
req := stpolicy.DeletePoolRequest{
|
||||
StoragePolicyID: storagePolicyID,
|
||||
SEPID: SEPID,
|
||||
PoolName: poolName,
|
||||
}
|
||||
if _, err := c.CloudBroker().StPolicy().DeletePool(ctx, req); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
addedASP := (newSet.(*schema.Set).Difference(oldSet.(*schema.Set))).List()
|
||||
for _, addedInterface := range addedASP {
|
||||
addedItem := addedInterface.(map[string]interface{})
|
||||
SEPID := uint64(addedItem["sep_id"].(int))
|
||||
poolName := addedItem["pool_name"].(string)
|
||||
req := stpolicy.AddPoolRequest{
|
||||
StoragePolicyID: storagePolicyID,
|
||||
SEPID: SEPID,
|
||||
PoolName: poolName,
|
||||
}
|
||||
if _, err := c.CloudBroker().StPolicy().AddPool(ctx, req); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package stpolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/stpolicy"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityStoragePolicyListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*stpolicy.ListStoragePolicies, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := stpolicy.ListRequest{}
|
||||
|
||||
if accountID, ok := d.GetOk("account_id"); ok {
|
||||
req.AccountID = uint64(accountID.(int))
|
||||
}
|
||||
if size, ok := d.GetOk("size"); ok {
|
||||
req.Size = uint64(size.(int))
|
||||
}
|
||||
if page, ok := d.GetOk("page"); ok {
|
||||
req.Page = uint64(page.(int))
|
||||
}
|
||||
|
||||
if byID, ok := d.GetOk("by_id"); ok {
|
||||
req.ByID = uint64(byID.(int))
|
||||
}
|
||||
|
||||
if name, ok := d.GetOk("name"); ok {
|
||||
req.Name = name.(string)
|
||||
}
|
||||
|
||||
if status, ok := d.GetOk("status"); ok {
|
||||
req.Status = status.(string)
|
||||
}
|
||||
|
||||
if desc, ok := d.GetOk("desc"); ok {
|
||||
req.Desc = desc.(string)
|
||||
}
|
||||
|
||||
if limitIOPS, ok := d.GetOk("limit_iops"); ok {
|
||||
req.LimitIOPS = uint64(limitIOPS.(int))
|
||||
}
|
||||
|
||||
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||
req.SortBy = sortBy.(string)
|
||||
}
|
||||
|
||||
if resgroupID, ok := d.GetOk("resgroup_id"); ok {
|
||||
req.ResgroupID = uint64(resgroupID.(int))
|
||||
}
|
||||
|
||||
if SEPID, ok := d.GetOk("sep_id"); ok {
|
||||
req.SepID = uint64(SEPID.(int))
|
||||
}
|
||||
|
||||
if poolName, ok := d.GetOk("pool_name"); ok {
|
||||
req.PoolName = poolName.(string)
|
||||
}
|
||||
|
||||
log.Debugf("utilityStoragePolicyListCheckPresence: load storage policy list")
|
||||
|
||||
storagePolicyList, err := c.CloudBroker().StPolicy().List(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return storagePolicyList, nil
|
||||
}
|
||||
Reference in New Issue
Block a user