3.4.0
This commit is contained in:
@@ -47,4 +47,6 @@ const (
|
||||
|
||||
disksSnapshotDeleteAPI = "/restmachine/cloudapi/disks/snapshotDelete"
|
||||
disksSnapshotRollbackAPI = "/restmachine/cloudapi/disks/snapshotRollback"
|
||||
disksShareAPI = "/restmachine/cloudapi/disks/share"
|
||||
disksUnshareAPI = "/restmachine/cloudapi/disks/unshare"
|
||||
)
|
||||
|
||||
@@ -60,8 +60,7 @@ func dataSourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface
|
||||
d.Set("account_name", disk.AccountName)
|
||||
d.Set("acl", string(diskAcl))
|
||||
d.Set("boot_partition", disk.BootPartition)
|
||||
d.Set("compute_id", disk.ComputeID)
|
||||
d.Set("compute_name", disk.ComputeName)
|
||||
d.Set("computes", flattenDiskComputes(disk.Computes))
|
||||
d.Set("created_time", disk.CreatedTime)
|
||||
d.Set("deleted_time", disk.DeletedTime)
|
||||
d.Set("desc", disk.Desc)
|
||||
@@ -84,6 +83,7 @@ func dataSourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface
|
||||
d.Set("passwd", disk.Passwd)
|
||||
d.Set("pci_slot", disk.PciSlot)
|
||||
d.Set("pool", disk.Pool)
|
||||
d.Set("present_to", disk.PresentTo)
|
||||
d.Set("purge_attempts", disk.PurgeAttempts)
|
||||
d.Set("purge_time", disk.PurgeTime)
|
||||
d.Set("reality_device_number", disk.RealityDeviceNumber)
|
||||
@@ -93,6 +93,7 @@ func dataSourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface
|
||||
d.Set("role", disk.Role)
|
||||
d.Set("sep_id", disk.SepID)
|
||||
d.Set("sep_type", disk.SepType)
|
||||
d.Set("shareable", disk.Shareable)
|
||||
d.Set("size_max", disk.SizeMax)
|
||||
d.Set("size_used", disk.SizeUsed)
|
||||
d.Set("snapshots", flattenDiskSnapshotList(disk.Snapshots))
|
||||
@@ -130,15 +131,21 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
|
||||
Computed: true,
|
||||
Description: "Number of disk partitions",
|
||||
},
|
||||
"compute_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Compute ID",
|
||||
},
|
||||
"compute_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Compute name",
|
||||
"computes": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"compute_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"compute_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"created_time": {
|
||||
Type: schema.TypeInt,
|
||||
@@ -316,6 +323,13 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
|
||||
Computed: true,
|
||||
Description: "Pool for disk location",
|
||||
},
|
||||
"present_to": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"purge_attempts": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
@@ -361,6 +375,10 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
|
||||
Computed: true,
|
||||
Description: "Type SEP. Defines the type of storage system and contains one of the values set in the cloud platform",
|
||||
},
|
||||
"shareable": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"size_max": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
|
||||
@@ -42,6 +42,18 @@ import (
|
||||
"github.com/rudecs/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func flattenDiskComputes(computes map[string]string) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for computeKey, computeVal := range computes {
|
||||
temp := map[string]interface{}{
|
||||
"compute_id": computeKey,
|
||||
"compute_name": computeVal,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenIOTune(iot IOTune) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
@@ -72,9 +84,8 @@ func flattenDiskList(dl DisksList) []map[string]interface{} {
|
||||
"account_id": disk.AccountID,
|
||||
"account_name": disk.AccountName,
|
||||
"acl": string(diskAcl),
|
||||
"computes": flattenDiskComputes(disk.Computes),
|
||||
"boot_partition": disk.BootPartition,
|
||||
"compute_id": disk.ComputeID,
|
||||
"compute_name": disk.ComputeName,
|
||||
"created_time": disk.CreatedTime,
|
||||
"deleted_time": disk.DeletedTime,
|
||||
"desc": disk.Desc,
|
||||
@@ -99,6 +110,7 @@ func flattenDiskList(dl DisksList) []map[string]interface{} {
|
||||
"passwd": disk.Passwd,
|
||||
"pci_slot": disk.PciSlot,
|
||||
"pool": disk.Pool,
|
||||
"present_to": disk.PresentTo,
|
||||
"purge_attempts": disk.PurgeAttempts,
|
||||
"purge_time": disk.PurgeTime,
|
||||
"reality_device_number": disk.RealityDeviceNumber,
|
||||
@@ -108,6 +120,7 @@ func flattenDiskList(dl DisksList) []map[string]interface{} {
|
||||
"role": disk.Role,
|
||||
"sep_id": disk.SepID,
|
||||
"sep_type": disk.SepType,
|
||||
"shareable": disk.Shareable,
|
||||
"size_max": disk.SizeMax,
|
||||
"size_used": disk.SizeUsed,
|
||||
"snapshots": flattenDiskSnapshotList(disk.Snapshots),
|
||||
@@ -199,15 +212,21 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
|
||||
Computed: true,
|
||||
Description: "Number of disk partitions",
|
||||
},
|
||||
"compute_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Compute ID",
|
||||
},
|
||||
"compute_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Compute name",
|
||||
"computes": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"compute_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"compute_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"created_time": {
|
||||
Type: schema.TypeInt,
|
||||
@@ -400,6 +419,13 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
|
||||
Computed: true,
|
||||
Description: "Pool for disk location",
|
||||
},
|
||||
"present_to": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"purge_attempts": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
@@ -445,6 +471,10 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
|
||||
Computed: true,
|
||||
Description: "Type SEP. Defines the type of storage system and contains one of the values set in the cloud platform",
|
||||
},
|
||||
"shareable": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"size_max": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
|
||||
@@ -37,9 +37,8 @@ type Disk struct {
|
||||
AccountID int `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
BootPartition int `json:"bootPartition"`
|
||||
Computes map[string]string `json:"computes"`
|
||||
CreatedTime uint64 `json:"creationTime"`
|
||||
ComputeID int `json:"computeId"`
|
||||
ComputeName string `json:"computeName"`
|
||||
DeletedTime uint64 `json:"deletionTime"`
|
||||
DeviceName string `json:"devicename"`
|
||||
Desc string `json:"desc"`
|
||||
@@ -63,6 +62,7 @@ type Disk struct {
|
||||
ParentId int `json:"parentId"`
|
||||
PciSlot int `json:"pciSlot"`
|
||||
Pool string `json:"pool"`
|
||||
PresentTo []int `json:"presentTo"`
|
||||
PurgeTime uint64 `json:"purgeTime"`
|
||||
PurgeAttempts uint64 `json:"purgeAttempts"`
|
||||
RealityDeviceNumber int `json:"realityDeviceNumber"`
|
||||
@@ -71,6 +71,7 @@ type Disk struct {
|
||||
ResName string `json:"resName"`
|
||||
Role string `json:"role"`
|
||||
SepType string `json:"sepType"`
|
||||
Shareable bool `json:"shareable"`
|
||||
SepID int `json:"sepId"` // NOTE: absent from compute/get output
|
||||
SizeMax int `json:"sizeMax"`
|
||||
SizeUsed int `json:"sizeUsed"` // sum over all snapshots of this disk to report total consumed space
|
||||
|
||||
@@ -113,6 +113,15 @@ func resourceDiskCreate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
urlValues = &url.Values{}
|
||||
}
|
||||
|
||||
if shareable := d.Get("shareable"); shareable.(bool) == true {
|
||||
urlValues.Add("diskId", diskId)
|
||||
_, err := c.DecortAPICall(ctx, "POST", disksShareAPI, urlValues)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
urlValues = &url.Values{}
|
||||
}
|
||||
|
||||
dgn := resourceDiskRead(ctx, d, m)
|
||||
if dgn != nil {
|
||||
return dgn
|
||||
@@ -167,8 +176,7 @@ func resourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}
|
||||
d.Set("account_name", disk.AccountName)
|
||||
d.Set("acl", string(diskAcl))
|
||||
d.Set("boot_partition", disk.BootPartition)
|
||||
d.Set("compute_id", disk.ComputeID)
|
||||
d.Set("compute_name", disk.ComputeName)
|
||||
d.Set("computes", flattenDiskComputes(disk.Computes))
|
||||
d.Set("created_time", disk.CreatedTime)
|
||||
d.Set("deleted_time", disk.DeletedTime)
|
||||
d.Set("desc", disk.Desc)
|
||||
@@ -191,6 +199,7 @@ func resourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}
|
||||
d.Set("passwd", disk.Passwd)
|
||||
d.Set("pci_slot", disk.PciSlot)
|
||||
d.Set("pool", disk.Pool)
|
||||
d.Set("present_to", disk.PresentTo)
|
||||
d.Set("purge_attempts", disk.PurgeAttempts)
|
||||
d.Set("purge_time", disk.PurgeTime)
|
||||
d.Set("reality_device_number", disk.RealityDeviceNumber)
|
||||
@@ -202,6 +211,7 @@ func resourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}
|
||||
d.Set("sep_type", disk.SepType)
|
||||
d.Set("size_max", disk.SizeMax)
|
||||
d.Set("size_used", disk.SizeUsed)
|
||||
d.Set("shareable", disk.Shareable)
|
||||
d.Set("snapshots", flattenDiskSnapshotList(disk.Snapshots))
|
||||
d.Set("status", disk.Status)
|
||||
d.Set("tech_status", disk.TechStatus)
|
||||
@@ -277,6 +287,24 @@ func resourceDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
urlValues = &url.Values{}
|
||||
}
|
||||
|
||||
if d.HasChange("shareable") {
|
||||
oldShare, newShare := d.GetChange("shareable")
|
||||
urlValues = &url.Values{}
|
||||
urlValues.Add("diskId", d.Id())
|
||||
if oldShare.(bool) == false && newShare.(bool) == true {
|
||||
_, err := c.DecortAPICall(ctx, "POST", disksShareAPI, urlValues)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
if oldShare.(bool) == true && newShare.(bool) == false {
|
||||
_, err := c.DecortAPICall(ctx, "POST", disksUnshareAPI, urlValues)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resourceDiskRead(ctx, d, m)
|
||||
}
|
||||
|
||||
@@ -335,6 +363,13 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
|
||||
Computed: true,
|
||||
Description: "Pool for disk location",
|
||||
},
|
||||
"present_to": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
@@ -354,7 +389,6 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
|
||||
ValidateFunc: validation.StringInSlice([]string{"D", "B", "T"}, false),
|
||||
Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'",
|
||||
},
|
||||
|
||||
"detach": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
@@ -373,6 +407,12 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
|
||||
Default: "",
|
||||
Description: "Reason for deletion",
|
||||
},
|
||||
"shareable": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Default: false,
|
||||
},
|
||||
|
||||
"disk_id": {
|
||||
Type: schema.TypeInt,
|
||||
@@ -393,15 +433,21 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
|
||||
Computed: true,
|
||||
Description: "Number of disk partitions",
|
||||
},
|
||||
"compute_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Compute ID",
|
||||
},
|
||||
"compute_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Compute name",
|
||||
"computes": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"compute_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"compute_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"created_time": {
|
||||
Type: schema.TypeInt,
|
||||
|
||||
Reference in New Issue
Block a user