This commit is contained in:
2026-06-02 11:28:16 +03:00
parent af79f6ab3e
commit c734dcfff7
254 changed files with 10439 additions and 3751 deletions

View File

@@ -29,6 +29,7 @@ func flattenResourceAccount(d *schema.ResourceData, acc *account.RecordAccount)
d.Set("send_access_emails", acc.SendAccessEmails)
d.Set("status", acc.Status)
d.Set("uniq_pools", acc.UniqPools)
d.Set("updated_by", acc.UpdatedBy)
d.Set("updated_time", acc.UpdatedTime)
d.Set("version", acc.Version)
d.Set("vins", acc.VINS)
@@ -61,6 +62,7 @@ func flattenDataAccount(d *schema.ResourceData, acc *account.RecordAccount) {
d.Set("storage_policy_ids", acc.StoragePolicyIDs)
d.Set("uniq_pools", acc.UniqPools)
d.Set("zone_ids", flattenZones(acc.ZoneIDs))
d.Set("updated_by", acc.UpdatedBy)
d.Set("updated_time", acc.UpdatedTime)
d.Set("version", acc.Version)
d.Set("vins", acc.VINS)
@@ -253,6 +255,7 @@ func flattenListDeleted(al *account.ListAccounts) []map[string]interface{} {
"uniq_pools": acc.UniqPools,
"default_zone_id": acc.DefaultZoneID,
"zone_ids": acc.ZoneIDs,
"updated_by": acc.UpdatedBy,
"updated_time": acc.UpdatedTime,
"version": acc.Version,
"vins": acc.VINS,
@@ -291,6 +294,7 @@ func flattenAccountList(al *account.ListAccounts) []map[string]interface{} {
"uniq_pools": acc.UniqPools,
"default_zone_id": acc.DefaultZoneID,
"zone_ids": acc.ZoneIDs,
"updated_by": acc.UpdatedBy,
"updated_time": acc.UpdatedTime,
"version": acc.Version,
"vins": acc.VINS,

View File

@@ -282,6 +282,10 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
@@ -723,6 +727,10 @@ func dataSourceAccountListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
@@ -1465,6 +1473,10 @@ func dataSourceAccountListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
@@ -2331,6 +2343,10 @@ func dataSourceAccountSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
},
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,

View File

@@ -1,39 +0,0 @@
package disks
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 dataSourceDiskListTypesRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
listTypes, err := utilityDiskListTypesCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", listTypes.Data)
d.Set("entry_count", listTypes.EntryCount)
return nil
}
func DataSourceDiskListTypes() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceDiskListTypesRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceDiskListTypesSchemaMake(),
}
}

View File

@@ -1,38 +0,0 @@
package disks
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 dataSourceDiskListTypesDetailedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
listTypesDetailed, err := utilityDiskListTypesDetailedCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenDiskListTypesDetailed(listTypesDetailed))
d.Set("entry_count", listTypesDetailed.EntryCount)
return nil
}
func DataSourceDiskListTypesDetailed() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceDiskListTypesDetailedRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceDiskListTypesDetailedSchemaMake(),
}
}

View File

@@ -14,6 +14,7 @@ func flattenDisk(d *schema.ResourceData, disk *disks.RecordDisk) {
d.Set("account_name", disk.AccountName)
d.Set("acl", string(diskAcl))
d.Set("blk_discard", disk.BLKDiscard)
d.Set("block_size", disk.BlockSize)
d.Set("boot_partition", disk.BootPartition)
d.Set("computes", flattenDiskComputes(disk.Computes))
d.Set("created_by", disk.CreatedBy)
@@ -29,6 +30,7 @@ func flattenDisk(d *schema.ResourceData, disk *disks.RecordDisk) {
d.Set("disk_id", disk.ID)
d.Set("image_id", disk.ImageID)
d.Set("images", disk.Images)
d.Set("independent", disk.Independent)
d.Set("iotune", flattenIOTune(disk.IOTune))
d.Set("iqn", disk.IQN)
d.Set("login", disk.Login)
@@ -44,6 +46,7 @@ func flattenDisk(d *schema.ResourceData, disk *disks.RecordDisk) {
d.Set("pool", disk.Pool)
d.Set("purge_attempts", disk.PurgeAttempts)
d.Set("present_to", disk.PresentTo)
d.Set("provision", disk.Provision)
d.Set("purge_time", disk.PurgeTime)
d.Set("replication", flattenDiskReplication(disk.Replication))
d.Set("reality_device_number", disk.RealityDeviceNumber)
@@ -62,7 +65,6 @@ func flattenDisk(d *schema.ResourceData, disk *disks.RecordDisk) {
d.Set("status", disk.Status)
d.Set("storage_policy_id", disk.StoragePolicyID)
d.Set("tech_status", disk.TechStatus)
d.Set("type", disk.Type)
d.Set("vmid", disk.VMID)
d.Set("updated_by", disk.UpdatedBy)
d.Set("updated_time", disk.UpdatedTime)
@@ -117,7 +119,6 @@ func flattenDiskReplica(d *schema.ResourceData, disk *disks.RecordDisk, statusRe
d.Set("status", disk.Status)
d.Set("status_replication", statusReplication)
d.Set("tech_status", disk.TechStatus)
d.Set("type", disk.Type)
d.Set("vmid", disk.VMID)
}
@@ -187,6 +188,7 @@ func flattenDiskList(dl *disks.ListDisks) []map[string]interface{} {
"account_name": disk.AccountName,
"acl": string(diskAcl),
"blk_discard": disk.BLKDiscard,
"block_size": disk.BlockSize,
"boot_partition": disk.BootPartition,
"computes": flattenDiskComputes(disk.Computes),
"created_by": disk.CreatedBy,
@@ -202,6 +204,7 @@ func flattenDiskList(dl *disks.ListDisks) []map[string]interface{} {
"disk_id": disk.ID,
"image_id": disk.ImageID,
"images": disk.Images,
"independent": disk.Independent,
"iotune": flattenIOTune(disk.IOTune),
"iqn": disk.IQN,
"login": disk.Login,
@@ -217,6 +220,8 @@ func flattenDiskList(dl *disks.ListDisks) []map[string]interface{} {
"pool": disk.Pool,
"purge_attempts": disk.PurgeAttempts,
"purge_time": disk.PurgeTime,
"present_to": disk.PresentTo,
"provision": disk.Provision,
"replication": flattenDiskReplication(disk.Replication),
"reality_device_number": disk.RealityDeviceNumber,
"reference_id": disk.ReferenceID,
@@ -234,7 +239,6 @@ func flattenDiskList(dl *disks.ListDisks) []map[string]interface{} {
"status": disk.Status,
"storage_policy_id": disk.StoragePolicyID,
"tech_status": disk.TechStatus,
"type": disk.Type,
"vmid": disk.VMID,
"updated_by": disk.UpdatedBy,
"updated_time": disk.UpdatedTime,
@@ -243,7 +247,6 @@ func flattenDiskList(dl *disks.ListDisks) []map[string]interface{} {
res = append(res, temp)
}
return res
}
func flattendDiskSnapshotList(sl disks.ListSnapshots) []interface{} {
@@ -261,36 +264,6 @@ func flattendDiskSnapshotList(sl disks.ListSnapshots) []interface{} {
res = append(res, temp)
}
return res
}
func flattenDiskListTypesDetailed(tld *disks.ListTypes) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, typeListDetailed := range tld.Data {
toMap := typeListDetailed.(map[string]interface{})
temp := map[string]interface{}{
"pools": flattenListTypesDetailedPools(toMap["pools"].([]interface{})),
"sep_id": toMap["sepId"].(float64),
"sep_name": toMap["sepName"].(string),
}
res = append(res, temp)
}
return res
}
func flattenListTypesDetailedPools(pools []interface{}) []interface{} {
res := make([]interface{}, 0)
for _, pool := range pools {
toMap := pool.(map[string]interface{})
temp := map[string]interface{}{
"name": toMap["name"].(string),
"system": toMap["system"].(string),
"types": toMap["types"].([]interface{}),
}
res = append(res, temp)
}
return res
}
@@ -304,6 +277,7 @@ func flattenDiskListUnattached(ul *disks.ListUnattachedDisks) []map[string]inter
"account_name": unattachedDisk.AccountName,
"acl": string(unattachedDiskAcl),
"blk_discard": unattachedDisk.BLKDiscard,
"block_size": unattachedDisk.BlockSize,
"boot_partition": unattachedDisk.BootPartition,
"created_time": unattachedDisk.CreatedTime,
"deleted_time": unattachedDisk.DeletedTime,
@@ -327,6 +301,7 @@ func flattenDiskListUnattached(ul *disks.ListUnattachedDisks) []map[string]inter
"pci_slot": unattachedDisk.PCISlot,
"pool": unattachedDisk.Pool,
"present_to": unattachedDisk.PresentTo,
"provision": unattachedDisk.Provision,
"purge_attempts": unattachedDisk.PurgeAttempts,
"purge_time": unattachedDisk.PurgeTime,
"reality_device_number": unattachedDisk.RealityDeviceNumber,
@@ -342,7 +317,7 @@ func flattenDiskListUnattached(ul *disks.ListUnattachedDisks) []map[string]inter
"snapshots": flattenDiskSnapshotList(unattachedDisk.Snapshots),
"status": unattachedDisk.Status,
"tech_status": unattachedDisk.TechStatus,
"type": unattachedDisk.Type,
"to_clean": unattachedDisk.ToClean,
"vmid": unattachedDisk.VMID,
}
res = append(res, tmp)

View File

@@ -102,6 +102,12 @@ func resourceDiskCreate(ctx context.Context, d *schema.ResourceData, m interface
log.Debugf("resourceDiskCreate: finished present for disk %d", d.Get("disk_id"))
}
if _, ok := d.GetOk("block_size"); ok {
if err := resourceDiskChangeBlockSize(ctx, d, m); err != nil {
w.Add(err)
}
}
if _, ok := d.GetOk("iotune"); ok {
if err := resourceDiskChangeIotune(ctx, d, m); err != nil {
w.Add(err)
@@ -244,14 +250,20 @@ func resourceDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface
}
}
if d.HasChange("cache") {
if err := resourceDiskChangeCache(ctx, d, m); err != nil {
return diag.FromErr(err)
if d.HasChanges("cache", "blk_discard", "block_size") {
updateReq := disks.UpdateRequest{
DiskID: uint64(d.Get("disk_id").(int)),
}
}
if d.HasChange("blk_discard") {
if err := resourceDiskChangeBLKDiscard(ctx, d, m); err != nil {
if d.HasChange("cache") {
updateReq.Cache = d.Get("cache").(string)
}
if d.HasChange("blk_discard") {
updateReq.BLKDiscard = d.Get("blk_discard").(bool)
}
if d.HasChange("block_size") {
updateReq.BlockSize = d.Get("block_size").(string)
}
if _, err := c.CloudBroker().Disks().Update(ctx, updateReq); err != nil {
return diag.FromErr(err)
}
}
@@ -382,22 +394,12 @@ func resourceDiskChangeStoragePolicyID(ctx context.Context, d *schema.ResourceDa
return err
}
func resourceDiskChangeCache(ctx context.Context, d *schema.ResourceData, m interface{}) error {
func resourceDiskChangeBlockSize(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
_, err := c.CloudBroker().Disks().Update(ctx, disks.UpdateRequest{
DiskID: uint64(d.Get("disk_id").(int)),
Cache: d.Get("cache").(string),
})
return err
}
func resourceDiskChangeBLKDiscard(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
_, err := c.CloudBroker().Disks().Update(ctx, disks.UpdateRequest{
DiskID: uint64(d.Get("disk_id").(int)),
BLKDiscard: d.Get("blk_discard").(bool),
DiskID: uint64(d.Get("disk_id").(int)),
BlockSize: d.Get("block_size").(string),
})
return err
}

View File

@@ -2,6 +2,7 @@ package disks
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func dataSourceDiskSchemaMake() map[string]*schema.Schema {
@@ -26,6 +27,10 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"block_size": {
Type: schema.TypeString,
Computed: true,
},
"boot_partition": {
Type: schema.TypeInt,
Computed: true,
@@ -97,6 +102,10 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"independent": {
Type: schema.TypeBool,
Computed: true,
},
"iotune": {
Type: schema.TypeList,
Computed: true,
@@ -212,6 +221,10 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"provision": {
Type: schema.TypeString,
Computed: true,
},
"purge_attempts": {
Type: schema.TypeInt,
Computed: true,
@@ -350,10 +363,6 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"vmid": {
Type: schema.TypeInt,
Computed: true,
@@ -412,11 +421,6 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "ID of the account the disks belong to",
},
"type": {
Type: schema.TypeString,
Optional: true,
Description: "type of the disks",
},
"sep_id": {
Type: schema.TypeInt,
Optional: true,
@@ -447,6 +451,16 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "storage policy ID ",
},
"rg_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by rg id",
},
"compute_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by compute id",
},
"items": {
Type: schema.TypeList,
Computed: true,
@@ -468,6 +482,10 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"block_size": {
Type: schema.TypeString,
Computed: true,
},
"boot_partition": {
Type: schema.TypeInt,
Computed: true,
@@ -543,6 +561,10 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"independent": {
Type: schema.TypeBool,
Computed: true,
},
"iotune": {
Type: schema.TypeList,
Computed: true,
@@ -658,6 +680,10 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"provision": {
Type: schema.TypeString,
Computed: true,
},
"purge_attempts": {
Type: schema.TypeInt,
Computed: true,
@@ -796,10 +822,6 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"vmid": {
Type: schema.TypeInt,
Computed: true,
@@ -859,11 +881,6 @@ func dataSourceDiskListDeletedSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "ID of the account the disks belong to",
},
"type": {
Type: schema.TypeString,
Optional: true,
Description: "type of the disks",
},
"sort_by": {
Type: schema.TypeString,
Optional: true,
@@ -900,6 +917,10 @@ func dataSourceDiskListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"block_size": {
Type: schema.TypeString,
Computed: true,
},
"boot_partition": {
Type: schema.TypeInt,
Computed: true,
@@ -975,6 +996,10 @@ func dataSourceDiskListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"independent": {
Type: schema.TypeBool,
Computed: true,
},
"iotune": {
Type: schema.TypeList,
Computed: true,
@@ -1090,6 +1115,10 @@ func dataSourceDiskListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"provision": {
Type: schema.TypeString,
Computed: true,
},
"purge_attempts": {
Type: schema.TypeInt,
Computed: true,
@@ -1228,10 +1257,6 @@ func dataSourceDiskListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"vmid": {
Type: schema.TypeInt,
Computed: true,
@@ -1259,105 +1284,6 @@ func dataSourceDiskListDeletedSchemaMake() map[string]*schema.Schema {
return res
}
func dataSourceDiskListTypesSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"sort_by": {
Type: schema.TypeString,
Optional: true,
Description: "sort by one of supported fields, format +|-(field)",
},
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "page size",
},
"items": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "The types of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'",
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}
func dataSourceDiskListTypesDetailedSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"sort_by": {
Type: schema.TypeString,
Optional: true,
Description: "sort by one of supported fields, format +|-(field)",
},
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "page size",
},
"items": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"pools": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Pool name",
},
"system": {
Type: schema.TypeString,
Computed: true,
},
"types": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "The types of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'",
},
},
},
},
"sep_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Storage endpoint provider ID to create disk",
},
"sep_name": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
}
func dataSourceDiskListUnattachedSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"by_id": {
@@ -1380,11 +1306,6 @@ func dataSourceDiskListUnattachedSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Find by status",
},
"type": {
Type: schema.TypeString,
Optional: true,
Description: "type of the disks",
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
@@ -1450,6 +1371,10 @@ func dataSourceDiskListUnattachedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"block_size": {
Type: schema.TypeString,
Computed: true,
},
"boot_partition": {
Type: schema.TypeInt,
Computed: true,
@@ -1638,6 +1563,10 @@ func dataSourceDiskListUnattachedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"provision": {
Type: schema.TypeString,
Computed: true,
},
"purge_attempts": {
Type: schema.TypeInt,
Computed: true,
@@ -1748,10 +1677,9 @@ func dataSourceDiskListUnattachedSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Technical status of the disk",
},
"type": {
Type: schema.TypeString,
Computed: true,
Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'",
"to_clean": {
Type: schema.TypeBool,
Computed: true,
},
"vmid": {
Type: schema.TypeInt,
@@ -1952,11 +1880,6 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Required: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'",
},
"sep_id": {
Type: schema.TypeInt,
Optional: true,
@@ -2008,6 +1931,12 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
Optional: true,
Default: false,
},
"block_size": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{"512", "512e", "4k"}, false),
},
"account_name": {
Type: schema.TypeString,
Computed: true,
@@ -2079,6 +2008,10 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"independent": {
Type: schema.TypeBool,
Computed: true,
},
"iotune": {
Type: schema.TypeList,
Optional: true,
@@ -2201,6 +2134,10 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"provision": {
Type: schema.TypeString,
Computed: true,
},
"purge_attempts": {
Type: schema.TypeInt,
Computed: true,

View File

@@ -33,7 +33,6 @@ package disks
import (
"context"
"strings"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/disks"
@@ -67,9 +66,6 @@ func utilityDiskListCheckPresence(ctx context.Context, d *schema.ResourceData, m
if accountId, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(accountId.(int))
}
if diskType, ok := d.GetOk("type"); ok {
req.Type = strings.ToUpper(diskType.(string))
}
if pool, ok := d.GetOk("pool"); ok {
req.Pool = pool.(string)
}
@@ -88,6 +84,12 @@ func utilityDiskListCheckPresence(ctx context.Context, d *schema.ResourceData, m
if storagePolicyID, ok := d.GetOk("storage_policy_id"); ok {
req.StoragePolicyID = uint64(storagePolicyID.(int))
}
if rgID, ok := d.GetOk("rg_id"); ok {
req.RGID = uint64(rgID.(int))
}
if computeID, ok := d.GetOk("compute_id"); ok {
req.ComputeID = uint64(computeID.(int))
}
log.Debugf("utilityDiskListCheckPresence: load disk list")
diskList, err := c.CloudBroker().Disks().List(ctx, req)

View File

@@ -65,9 +65,6 @@ func utilityDiskListDeletedCheckPresence(ctx context.Context, d *schema.Resource
if account_id, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(account_id.(int))
}
if typev, ok := d.GetOk("type"); ok {
req.Type = typev.(string)
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(string)
}

View File

@@ -1,35 +0,0 @@
package disks
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/disks"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityDiskListTypesCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListTypes, error) {
c := m.(*controller.ControllerCfg)
req := disks.ListTypesRequest{
Detailed: false,
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(string)
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
log.Debugf("utilityDiskListTypesCheckPresence: load disk list Types Detailed")
typesList, err := c.CloudBroker().Disks().ListTypes(ctx, req)
if err != nil {
return nil, err
}
return typesList, nil
}

View File

@@ -1,38 +0,0 @@
package disks
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/disks"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityDiskListTypesDetailedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListTypes, error) {
c := m.(*controller.ControllerCfg)
req := disks.ListTypesRequest{
Detailed: true,
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(string)
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
log.Debugf("utilityDiskListTypesDetailedCheckPresence: load disk list Types Detailed")
listTypesDetailed, err := c.CloudBroker().Disks().ListTypes(ctx, req)
log.Debugf("%+v", listTypesDetailed.Data[0].(map[string]interface{}))
if err != nil {
return nil, err
}
return listTypesDetailed, nil
}

View File

@@ -25,9 +25,6 @@ func utilityDiskListUnattachedCheckPresence(ctx context.Context, d *schema.Resou
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if diskType, ok := d.GetOk("type"); ok {
req.Type = diskType.(string)
}
if accountId, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(accountId.(int))
}

View File

@@ -78,6 +78,8 @@ func resourceDPDKNetCreate(ctx context.Context, d *schema.ResourceData, m interf
}
}
req.EnableSecGroups = d.Get("enable_secgroups").(bool)
dpdkID, err := c.CloudBroker().DPDKNet().Create(ctx, req)
if err != nil {
d.SetId("")
@@ -93,17 +95,6 @@ func resourceDPDKNetCreate(ctx context.Context, d *schema.ResourceData, m interf
warnings.Add(err)
}
if d.Get("enable_secgroups").(bool) {
req := dpdk.UpdateRequest{
DPDKID: dpdkID,
EnableSecGroups: true,
}
_, err := c.CloudBroker().DPDKNet().Update(ctx, req)
if err != nil {
warnings.Add(err)
}
}
return append(warnings.Get(), resourceDPDKNetRead(ctx, d, m)...)
}

View File

@@ -136,6 +136,8 @@ func resourceExtnetCreate(ctx context.Context, d *schema.ResourceData, m interfa
req.MTU = uint(mtu.(int))
}
req.EnableSecGroups = d.Get("enable_secgroups").(bool)
log.Debugf("cloudbroker: Sent create request")
netID, err := c.CloudBroker().ExtNet().Create(ctx, req)
if err != nil {
@@ -234,18 +236,6 @@ func resourceExtnetCreate(ctx context.Context, d *schema.ResourceData, m interfa
}
}
if d.Get("enable_secgroups").(bool) {
log.Debugf("resourceExtnetCreate: trying to enable secgroups for extnet with ID %d", netID)
req := extnet.UpdateRequest{
NetID: netID,
EnableSecGroups: true,
}
_, err := c.CloudBroker().ExtNet().Update(ctx, req)
if err != nil {
w.Add(err)
}
}
return resourceExtnetRead(ctx, d, m)
}

View File

@@ -68,6 +68,34 @@ func flattenFlipgroup(d *schema.ResourceData, flip *flipgroup.RecordFLIPGroup) {
d.Set("updated_time", flip.UpdatedTime)
}
func flattenFlipgroupResource(d *schema.ResourceData, flip *flipgroup.RecordFLIPGroup) {
d.Set("flipgroup_id", flip.ID)
d.Set("account_id", flip.AccountID)
d.Set("account_name", flip.AccountName)
d.Set("client_ids", flip.ClientIDs)
d.Set("client_names", flip.ClientNames)
d.Set("client_type", flip.ClientType)
d.Set("conn_id", flip.ConnID)
d.Set("conn_type", flip.ConnType)
d.Set("created_by", flip.CreatedBy)
d.Set("created_time", flip.CreatedTime)
d.Set("default_gw", flip.DefaultGW)
d.Set("deleted_by", flip.DeletedBy)
d.Set("deleted_time", flip.DeletedTime)
d.Set("desc", flip.Description)
d.Set("gid", flip.GID)
d.Set("guid", flip.GUID)
d.Set("ip", flip.IP)
d.Set("milestones", flip.Milestones)
d.Set("name", flip.Name)
d.Set("net_id", flip.NetID)
d.Set("net_type", flip.NetType)
d.Set("network", flip.Network)
d.Set("status", flip.Status)
d.Set("updated_by", flip.UpdatedBy)
d.Set("updated_time", flip.UpdatedTime)
}
func flattenFlipgroupsList(fg *flipgroup.ListFLIPGroups) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(fg.Data))
for _, flip := range fg.Data {

View File

@@ -110,9 +110,9 @@ func resourceFlipgroupRead(ctx context.Context, d *schema.ResourceData, m interf
return diag.Errorf("The flipgroup status is destroyed and cannot be read.")
}
flattenFlipgroup(d, fg)
flattenFlipgroupResource(d, fg)
log.Debugf("resourceFlipgroupRead: after flattenFlipgroup: flipgroup_id %s, name %s",
log.Debugf("resourceFlipgroupRead: after flattenFlipgroupResource: flipgroup_id %s, name %s",
d.Id(), d.Get("name").(string))
return nil

View File

@@ -27,16 +27,17 @@ func flattenGridList(gl *grid.ListGrids) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(gl.Data))
for _, item := range gl.Data {
temp := map[string]interface{}{
"resources": flattenGridResources(item.Resources),
"name": item.Name,
"auth_broker": flattens.FlattenMeta(item.AuthBroker),
"flag": item.Flag,
"gid": item.GID,
"guid": item.GUID,
"location_code": item.LocationCode,
"id": item.ID,
"network_modes": item.NetworkModes,
"sdn_support": item.SDNSupport,
"resources": flattenGridResources(item.Resources),
"name": item.Name,
"auth_broker": flattens.FlattenMeta(item.AuthBroker),
"flag": item.Flag,
"gid": item.GID,
"guid": item.GUID,
"location_code": item.LocationCode,
"id": item.ID,
"network_modes": item.NetworkModes,
"sdn_support": item.SDNSupport,
"zero_access_enabled": item.ZeroAccessEnabled,
}
res = append(res, temp)
}

View File

@@ -260,6 +260,10 @@ func dataSourceGridListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"zero_access_enabled": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},

View File

@@ -20,6 +20,7 @@ import (
cb_trunk "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/trunk"
cb_vfpool "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vfpool"
cb_vins "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/logicalports"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
@@ -595,14 +596,21 @@ func ExistK8s(ctx context.Context, k8sId uint64, c *controller.ControllerCfg) er
return nil
}
func IsMoreThanOneDisksTypeB(ctx context.Context, disks interface{}) error {
func IsMoreThanOneDisksTypeB(ctx context.Context, disks interface{}, chipset string) error {
count := 0
key := "bus_number"
if chipset == "i440fx" {
key = "pci_slot"
}
for _, elem := range disks.([]interface{}) {
diskVal := elem.(map[string]interface{})
if diskVal["disk_type"].(string) == "B" {
if val, ok := diskVal[key].(int); ok && val == 6 {
count++
}
if count > 1 {
return fmt.Errorf("block disks have more 1 disk type 'B'")
}
@@ -648,9 +656,16 @@ func ExistBlankCompute(ctx context.Context, computeId uint64, m interface{}) err
computeImageId := computeRecord.ImageID
bootImageId := -1
for _, d := range computeRecord.Disks {
if d.Type == "B" {
bootImageId = int(d.ImageID)
break
if computeRecord.Chipset == "i440fx" {
if d.PCISlot == 6 {
bootImageId = int(d.ImageID)
break
}
} else {
if d.BusNumber == 6 {
bootImageId = int(d.ImageID)
break
}
}
}
@@ -679,3 +694,20 @@ func ExistPlatformDisk(ctx context.Context, diskId uint64, m interface{}) error
return nil
}
func ExistSDNNet(ctx context.Context, sdnIds []string, c *controller.ControllerCfg) []error {
var errs []error
for _, uniqueIdentifier := range sdnIds {
if uniqueIdentifier == "" {
continue
}
req := logicalports.GetByUniqueIdentifierRequest{ID: uniqueIdentifier}
_, err := c.SDN().LogicalPorts().GetByUniqueIdentifier(ctx, req)
if err != nil {
errs = append(errs, fmt.Errorf("SDN logical port with unique identifier %q not found", uniqueIdentifier))
}
}
return errs
}

View File

@@ -30,8 +30,10 @@ func flattenImage(d *schema.ResourceData, img *image.RecordImage) {
d.Set("guid", img.GUID)
d.Set("history", flattenHistory(img.History))
d.Set("hot_resize", img.HotResize)
d.Set("independent", img.Independent)
d.Set("last_modified", img.LastModified)
d.Set("link_to", img.LinkTo)
d.Set("links_to", img.LinksTo)
d.Set("milestones", img.Milestones)
d.Set("name", img.Name)
d.Set("network_interface_naming", img.NetworkInterfaceNaming)
@@ -52,6 +54,7 @@ func flattenImage(d *schema.ResourceData, img *image.RecordImage) {
d.Set("storage_policy_id", img.StoragePolicyID)
d.Set("tech_status", img.TechStatus)
d.Set("to_clean", img.ToClean)
d.Set("target_ids", img.LinksTo)
d.Set("image_type", img.Type)
d.Set("url", img.URL)
d.Set("username", img.Username)
@@ -111,8 +114,10 @@ func flattenImageList(il *image.ListImages) []map[string]interface{} {
"guid": item.GUID,
"history": flattenHistory(item.History),
"hot_resize": item.HotResize,
"independent": item.Independent,
"last_modified": item.LastModified,
"link_to": item.LinkTo,
"links_to": item.LinksTo,
"milestones": item.Milestones,
"name": item.Name,
"network_interface_naming": item.NetworkInterfaceNaming,

View File

@@ -59,10 +59,11 @@ func resourceImageFromBlankComputeCreate(ctx context.Context, d *schema.Resource
}
req := compute.CreateTemplateFromBlankRequest{
ComputeID: uint64(d.Get("compute_id").(int)),
Name: d.Get("name").(string),
BootType: d.Get("boot_type").(string),
ImageType: d.Get("image_type").(string),
ComputeID: uint64(d.Get("compute_id").(int)),
Name: d.Get("name").(string),
BootType: d.Get("boot_type").(string),
ImageType: d.Get("image_type").(string),
StoragePolicyID: uint64(d.Get("storage_policy_id").(int)),
}
if username, ok := d.GetOk("username"); ok {

View File

@@ -0,0 +1,274 @@
package image
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/image"
"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"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
)
func resourceMultiImageCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceMultiImageCreate: called for image %s", d.Get("name").(string))
c := m.(*controller.ControllerCfg)
targetIDsRaw := d.Get("target_ids").([]interface{})
targetIDs := make([]uint64, 0, len(targetIDsRaw))
for _, id := range targetIDsRaw {
targetIDs = append(targetIDs, uint64(id.(int)))
}
req := image.CreateMultiImageRequest{
Name: d.Get("name").(string),
TargetIDs: targetIDs,
AccountID: uint64(d.Get("account_id").(int)),
}
imageId, err := c.CloudBroker().Image().CreateMultiImage(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId(strconv.FormatUint(imageId, 10))
d.Set("image_id", imageId)
var w dc.Warnings
if !d.Get("enabled").(bool) {
if err := resourceImageChangeEnabled(ctx, d, m); err != nil {
w.Add(err)
}
}
if _, ok := d.GetOk("shared_with"); ok {
if err := resourceImageShare(ctx, d, m); err != nil {
w.Add(err)
}
}
if _, ok := d.GetOk("computeci_id"); ok {
if err := resourceImageChangeComputeci(ctx, d, m); err != nil {
w.Add(err)
}
}
updReq := image.EditRequest{}
updReq.ImageID = uint64(d.Get("image_id").(int))
if _, ok := d.GetOk("username"); ok {
updReq.Username = d.Get("username").(string)
}
if _, ok := d.GetOk("password"); ok {
updReq.Password = d.Get("password").(string)
}
if _, ok := d.GetOk("account_id"); ok {
updReq.AccountID = uint64(d.Get("account_id").(int))
}
if _, ok := d.GetOkExists("bootable"); ok {
updReq.Bootable = d.Get("bootable").(bool)
}
if _, ok := d.GetOkExists("hot_resize"); ok {
updReq.HotResize = d.Get("hot_resize").(bool)
}
if _, ok := d.GetOk("network_interface_naming"); ok {
updReq.NetworkInterfaceNaming = d.Get("network_interface_naming").(string)
}
_, err = c.CloudBroker().Image().Edit(ctx, updReq)
if err != nil {
w.Add(err)
}
return append(resourceMultiImageRead(ctx, d, m), w.Get()...)
}
func resourceMultiImageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceMultiImageRead: called for %s id: %s", d.Get("name").(string), d.Id())
img, err := utilityImageCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
switch img.Status {
case status.Modeled:
return diag.Errorf("The image is in status: %s, please, contact support for more information", img.Status)
case status.Destroyed, status.Purged:
d.SetId("")
return diag.Errorf("The resource cannot be updated because it has been destroyed")
}
flattenImage(d, img)
return nil
}
func resourceMultiImageDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceMultiImageDelete: called for %s, id: %s", d.Get("name").(string), d.Id())
_, err := utilityImageCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
c := m.(*controller.ControllerCfg)
req := image.DeleteRequest{
ImageID: uint64(d.Get("image_id").(int)),
}
_, err = c.CloudBroker().Image().Delete(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func resourceMultiImageUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceMultiImageUpdate: called for %s, id: %s", d.Get("name").(string), d.Id())
img, err := utilityImageCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
switch img.Status {
case status.Modeled:
return diag.Errorf("The image is in status: %s, please, contact support for more information", img.Status)
case status.Destroyed, status.Purged:
d.SetId("")
return diag.Errorf("The resource cannot be updated because it has been destroyed")
}
if d.HasChange("enabled") {
err := resourceImageChangeEnabled(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("shared_with") {
err := resourceImageShare(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("computeci_id") {
err := resourceImageChangeComputeci(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
}
if d.HasChanges("name", "username", "password", "account_id", "bootable", "hot_resize") {
err := resourceImageEdit(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("target_ids") {
err := resourceMultiImageUpdateLinks(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
}
return resourceMultiImageRead(ctx, d, m)
}
func resourceMultiImageUpdateLinks(ctx context.Context, d *schema.ResourceData, m interface{}) error {
log.Debugf("resourceMultiImageUpdateLinks: called for %s, id: %s", d.Get("name").(string), d.Id())
c := m.(*controller.ControllerCfg)
imageID := uint64(d.Get("image_id").(int))
oldRaw, newRaw := d.GetChange("target_ids")
oldIDs := oldRaw.([]interface{})
newIDs := newRaw.([]interface{})
oldSet := make(map[uint64]bool)
for _, id := range oldIDs {
oldSet[uint64(id.(int))] = true
}
newSet := make(map[uint64]bool)
for _, id := range newIDs {
newSet[uint64(id.(int))] = true
}
toAdd := make([]uint64, 0)
for id := range newSet {
if !oldSet[id] {
toAdd = append(toAdd, id)
}
}
toRemove := make([]uint64, 0)
for id := range oldSet {
if !newSet[id] {
toRemove = append(toRemove, id)
}
}
if len(toAdd) > 0 {
req := image.MultiImageAddLinksRequest{
ImageID: imageID,
TargetIDs: toAdd,
}
_, err := c.CloudBroker().Image().MultiImageAddLinks(ctx, req)
if err != nil {
return err
}
}
if len(toRemove) > 0 {
req := image.MultiImageDelLinksRequest{
ImageID: imageID,
TargetIDs: toRemove,
}
_, err := c.CloudBroker().Image().MultiImageDelLinks(ctx, req)
if err != nil {
return err
}
}
return nil
}
func ResourceMultiImage() *schema.Resource {
return &schema.Resource{
SchemaVersion: 2,
CreateContext: resourceMultiImageCreate,
ReadContext: resourceMultiImageRead,
UpdateContext: resourceMultiImageUpdate,
DeleteContext: resourceMultiImageDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout600s,
Read: &constants.Timeout300s,
Update: &constants.Timeout300s,
Delete: &constants.Timeout300s,
Default: &constants.Timeout300s,
},
Schema: resourceMultiImageSchemaMake(),
}
}

View File

@@ -252,6 +252,10 @@ func dataSourceImageListSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "image id",
},
"independent": {
Type: schema.TypeBool,
Computed: true,
},
"last_modified": {
Type: schema.TypeInt,
Computed: true,
@@ -260,6 +264,13 @@ func dataSourceImageListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"links_to": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
@@ -518,6 +529,10 @@ func dataSourceImageSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Does this machine supports hot resize",
},
"independent": {
Type: schema.TypeBool,
Computed: true,
},
"last_modified": {
Type: schema.TypeInt,
Computed: true,
@@ -526,6 +541,13 @@ func dataSourceImageSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"links_to": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
@@ -751,10 +773,12 @@ func resourceCDROMImageSchemaMake() map[string]*schema.Schema {
},
"status": {
Type: schema.TypeString,
Computed: true},
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true},
Computed: true,
},
"user_group_id": {
Type: schema.TypeString,
Computed: true,
@@ -1037,10 +1061,12 @@ func resourceImageSchemaMake() map[string]*schema.Schema {
},
"status": {
Type: schema.TypeString,
Computed: true},
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true},
Computed: true,
},
"user_group_id": {
Type: schema.TypeString,
Computed: true,
@@ -1072,11 +1098,22 @@ func resourceImageSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "image id",
},
"independent": {
Type: schema.TypeBool,
Computed: true,
},
"link_to": {
Type: schema.TypeInt,
Computed: true,
Description: "",
},
"links_to": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
@@ -1334,6 +1371,10 @@ func resourceVirtualImageSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Image id",
},
"independent": {
Type: schema.TypeBool,
Computed: true,
},
"last_modified": {
Type: schema.TypeInt,
Computed: true,
@@ -1425,6 +1466,259 @@ func resourceVirtualImageSchemaMake() map[string]*schema.Schema {
}
}
func resourceMultiImageSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"target_ids": {
Type: schema.TypeList,
Required: true,
Description: "IDs of real images to link this multi image to",
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"name": {
Type: schema.TypeString,
Required: true,
Description: "Name of the multi image",
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Account id to make the image exclusive",
},
"bootable": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Does this image boot OS",
},
"computeci_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"enabled": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"hot_resize": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Does this machine supports hot resize",
},
"password": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Optional password for the image",
},
"username": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: "Optional username for the image",
},
"shared_with": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"unc_path": {
Type: schema.TypeString,
Computed: true,
Description: "unc path",
},
"acl": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"explicit": {
Type: schema.TypeBool,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"right": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"user_group_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"architecture": {
Type: schema.TypeString,
Computed: true,
},
"boot_type": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"desc": {
Type: schema.TypeString,
Computed: true,
},
"drivers": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"history": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"guid": {
Type: schema.TypeString,
Computed: true,
},
"id": {
Type: schema.TypeInt,
Computed: true,
},
"timestamp": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"image_id": {
Type: schema.TypeInt,
Computed: true,
},
"independent": {
Type: schema.TypeBool,
Computed: true,
},
"last_modified": {
Type: schema.TypeInt,
Computed: true,
},
"link_to": {
Type: schema.TypeInt,
Computed: true,
},
"links_to": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"pool_name": {
Type: schema.TypeString,
Computed: true,
},
"present_to": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"provider_name": {
Type: schema.TypeString,
Computed: true,
},
"purge_attempts": {
Type: schema.TypeInt,
Computed: true,
},
"reference_id": {
Type: schema.TypeString,
Computed: true,
},
"res_id": {
Type: schema.TypeString,
Computed: true,
},
"res_name": {
Type: schema.TypeString,
Computed: true,
},
"rescuecd": {
Type: schema.TypeBool,
Computed: true,
},
"sep_id": {
Type: schema.TypeInt,
Computed: true,
},
"size": {
Type: schema.TypeInt,
Computed: true,
},
"snapshot_id": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
},
"to_clean": {
Type: schema.TypeBool,
Computed: true,
},
"image_type": {
Type: schema.TypeString,
Computed: true,
},
"url": {
Type: schema.TypeString,
Computed: true,
},
"version": {
Type: schema.TypeString,
Computed: true,
},
}
}
func resourceImageFromBlankComputeSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"compute_id": {
@@ -1437,6 +1731,11 @@ func resourceImageFromBlankComputeSchemaMake() map[string]*schema.Schema {
Required: true,
Description: "Name of the rescue disk",
},
"storage_policy_id": {
Type: schema.TypeInt,
Required: true,
Description: "Storage policy ID",
},
"boot_type": {
Type: schema.TypeString,
Required: true,
@@ -1550,10 +1849,12 @@ func resourceImageFromBlankComputeSchemaMake() map[string]*schema.Schema {
},
"status": {
Type: schema.TypeString,
Computed: true},
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true},
Computed: true,
},
"user_group_id": {
Type: schema.TypeString,
Computed: true,
@@ -1620,6 +1921,13 @@ func resourceImageFromBlankComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"links_to": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
@@ -1815,10 +2123,12 @@ func resourceImageFromPlatformDiskSchemaMake() map[string]*schema.Schema {
},
"status": {
Type: schema.TypeString,
Computed: true},
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true},
Computed: true,
},
"user_group_id": {
Type: schema.TypeString,
Computed: true,
@@ -1881,6 +2191,13 @@ func resourceImageFromPlatformDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"links_to": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"milestones": {
Type: schema.TypeInt,
Computed: true,

View File

@@ -1466,14 +1466,14 @@ func resourceK8sCPSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "insert ssl certificate in x509 pem format",
},
"chipset": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"Q35", "i440fx"}, false),
Default: "Q35",
Description: "Type of the emulated system. Possible values: i440fx, Q35. Default: Q35",
},
"lb_sysctl_params": {
"chipset": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"Q35", "i440fx"}, false),
Default: "Q35",
Description: "Type of the emulated system. Possible values: i440fx, Q35. Default: Q35",
},
"lb_sysctl_params": {
Type: schema.TypeList,
Optional: true,
Description: "Custom sysctl values for Load Balancer instance. Applied on boot.",
@@ -1810,19 +1810,19 @@ func resourceK8sWgSchemaMake() map[string]*schema.Schema {
),
Description: "Node RAM in MB.",
},
"chipset": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"Q35", "i440fx"}, false),
Default: "Q35",
Description: "Type of the emulated system. Possible values: i440fx, Q35. Default: Q35",
},
"disk": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Worker node boot disk size. If unspecified or 0, size is defined by OS image size.",
},
"chipset": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"Q35", "i440fx"}, false),
Default: "Q35",
Description: "Type of the emulated system. Possible values: i440fx, Q35. Default: Q35",
},
"disk": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Worker node boot disk size. If unspecified or 0, size is defined by OS image size.",
},
"labels": {
Type: schema.TypeList,
Computed: true,

View File

@@ -18,7 +18,7 @@ func flattenCompute(d *schema.ResourceData, computeRec *compute.RecordCompute, p
customFields, _ := json.Marshal(computeRec.CustomFields)
devices, _ := json.Marshal(computeRec.Devices)
userData, _ := json.Marshal(computeRec.Userdata)
bootDisk := findBootDisk(computeRec.Disks)
bootDisk := findBootDisk(computeRec.Disks, computeRec.Chipset)
if len(computeRec.Interfaces) > 0 {
log.Debugf("flattenCompute: calling parseComputeInterfacesToNetworks for %d interfaces", len(computeRec.Interfaces))
@@ -113,6 +113,7 @@ func flattenCompute(d *schema.ResourceData, computeRec *compute.RecordCompute, p
d.Set("cpu_pin", computeRec.CPUPin)
d.Set("numa_affinity", computeRec.NumaAffinity)
d.Set("hp_backed", computeRec.HPBacked)
d.Set("weight", computeRec.Weight)
return nil
}
@@ -269,10 +270,12 @@ func flattenComputeDisks(disksList compute.ListDisks, disksBlocks, extraDisks []
"node_ids": nodeIds,
"size": disk.SizeMax,
"sep_id": disk.SEPID,
"disk_type": disk.Type,
"pci_slot": disk.PCISlot,
"bus_number": disk.BusNumber,
"pool": disk.Pool,
"desc": disk.Description,
"image_id": disk.ImageID,
"independent": disk.Independent,
"disk_id": disk.ID,
"shareable": disk.Shareable,
"size_used": disk.SizeUsed,
@@ -289,6 +292,8 @@ func flattenComputeDisks(disksList compute.ListDisks, disksBlocks, extraDisks []
"update_time": disk.UpdatedTime,
"cache": disk.Cache,
"blk_discard": disk.BLKDiscard,
"block_size": disk.BlockSize,
"provision": disk.Provision,
"iotune": flattenIOTune(disk.IOTune),
}
res = append(res, temp)
@@ -408,6 +413,7 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
"hot_resize": computeItem.HotResize,
"network_interface_naming": computeItem.NetworkInterfaceNaming,
"zone_id": computeItem.ZoneID,
"weight": computeItem.Weight,
}
res = append(res, temp)
}
@@ -495,6 +501,7 @@ func flattenDeletedComputeList(computes *compute.ListDeletedComputes) []map[stri
"hot_resize": computeItem.HotResize,
"network_interface_naming": computeItem.NetworkInterfaceNaming,
"zone_id": computeItem.ZoneID,
"weight": computeItem.Weight,
}
res = append(res, temp)
}
@@ -842,8 +849,9 @@ func flattenDataCompute(d *schema.ResourceData, compFacts *compute.RecordCompute
d.Set("zone_id", compFacts.ZoneID)
d.Set("loader_meta_iso", flattenLoaderMetaIso(compFacts.LoaderMetaIso))
d.Set("os_version", compFacts.OSVersion)
d.Set("weight", compFacts.Weight)
//extra fields setting
bootDisk := findBootDisk(compFacts.Disks)
bootDisk := findBootDisk(compFacts.Disks, compFacts.Chipset)
if bootDisk != nil {
d.Set("boot_disk_size", bootDisk.SizeMax)
d.Set("boot_disk_id", bootDisk.ID) // we may need boot disk ID in resize operations
@@ -900,6 +908,7 @@ func flattenDisk(diskList compute.ListDisks) []map[string]interface{} {
"meta": flattens.FlattenMeta(disk.Meta),
"account_id": disk.AccountID,
"blk_discard": disk.BLKDiscard,
"block_size": disk.BlockSize,
"boot_partition": disk.BootPartition,
"bus_number": disk.BusNumber,
"created_time": disk.CreatedTime,
@@ -915,6 +924,7 @@ func flattenDisk(diskList compute.ListDisks) []map[string]interface{} {
"disk_id": disk.ID,
"image_id": disk.ImageID,
"images": disk.Images,
"independent": disk.Independent,
"iotune": flattenIOTune(disk.IOTune),
"iqn": disk.IQN,
"login": disk.Login,
@@ -945,6 +955,7 @@ func flattenDisk(diskList compute.ListDisks) []map[string]interface{} {
"tech_status": disk.TechStatus,
"type": disk.Type,
"to_clean": disk.ToClean,
"provision": disk.Provision,
"updated_time": disk.UpdatedTime,
}
res = append(res, temp)

View File

@@ -17,8 +17,10 @@ func checkParamsExistence(ctx context.Context, d *schema.ResourceData, c *contro
errs = append(errs, err)
}
if err := ic.ExistImage(ctx, uint64(d.Get("image_id").(int)), c); err != nil {
errs = append(errs, err)
if !d.Get("create_blank").(bool) {
if err := ic.ExistImage(ctx, uint64(d.Get("image_id").(int)), c); err != nil {
errs = append(errs, err)
}
}
if netErrs := existNetworks(ctx, d, c); errs != nil {
@@ -26,7 +28,7 @@ func checkParamsExistence(ctx context.Context, d *schema.ResourceData, c *contro
}
if disks, ok := d.GetOk("disks"); ok {
if err := ic.IsMoreThanOneDisksTypeB(ctx, disks); err != nil {
if err := ic.IsMoreThanOneDisksTypeB(ctx, disks, d.Get("chipset").(string)); err != nil {
errs = append(errs, err)
}
}
@@ -37,8 +39,7 @@ func checkParamsExistence(ctx context.Context, d *schema.ResourceData, c *contro
func existNetworks(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg) []error {
var errs []error
var vinsIds, extNetIds, vfpoolIds, dpdkIds, trunkIds []uint64
//TODO
//var sdnIds []string
var sdnIds []string
networksIface, ok := d.GetOk("network")
if !ok {
@@ -60,10 +61,8 @@ func existNetworks(ctx context.Context, d *schema.ResourceData, c *controller.Co
dpdkIds = append(dpdkIds, uint64(network["net_id"].(int)))
case "TRUNK":
trunkIds = append(trunkIds, uint64(network["net_id"].(int)))
//TODO
//case "SDN": sdnIds = append(sdnIds, network["sdn_interface_id"].(string))
case "SDN":
sdnIds = append(sdnIds, network["sdn_interface_id"].(string))
default:
continue
}
@@ -89,10 +88,9 @@ func existNetworks(ctx context.Context, d *schema.ResourceData, c *controller.Co
errs = append(errs, trunkErrs...)
}
//TODO
//if sdnErrs := ic.ExistSDNNet(ctx, sdnIds, c); sdnErrs != nil {
// errs = append(errs, sdnErrs...)
//}
if sdnErrs := ic.ExistSDNNet(ctx, sdnIds, c); sdnErrs != nil {
errs = append(errs, sdnErrs...)
}
return errs
}

View File

@@ -77,10 +77,6 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
createReqX86.NodeID = uint64(nodeID.(int))
}
if ipaType, ok := d.GetOk("ipa_type"); ok {
createReqX86.IPAType = ipaType.(string)
}
if bootSize, ok := d.GetOk("boot_disk_size"); ok {
createReqX86.BootDisk = uint64(bootSize.(int))
}
@@ -89,10 +85,6 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
createReqX86.BootDiskCache = bootDiskCache.(string)
}
if IS, ok := d.GetOk("is"); ok {
createReqX86.IS = IS.(string)
}
if zoneID, ok := d.GetOk("zone_id"); ok {
createReqX86.ZoneID = uint64(zoneID.(int))
}
@@ -130,7 +122,7 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
reqInterface.Enabled = netInterfaceVal["enabled"].(bool)
}
if reqInterface.NetType == "DPDK" || reqInterface.NetType == "EXTNET" {
if reqInterface.NetType == "DPDK" || reqInterface.NetType == "EXTNET" || reqInterface.NetType == "TRUNK" {
reqInterface.MTU = uint64(netInterfaceVal["mtu"].(int))
}
@@ -251,7 +243,33 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
}
log.Debugf("resourceComputeCreate: creating Compute of type KVM VM x86")
apiResp, err := c.CloudBroker().KVMX86().Create(ctx, createReqX86)
var apiResp uint64
var err error
if d.Get("create_blank").(bool) {
log.Debugf("resourceComputeCreate: using createBlank endpoint")
createBlankReq := kvmx86.CreateBlankRequest{
RGID: createReqX86.RGID,
Name: createReqX86.Name,
CPU: createReqX86.CPU,
RAM: createReqX86.RAM,
StoragePolicyID: createReqX86.StoragePolicyID,
WithoutBootDisk: createReqX86.WithoutBootDisk,
BootDisk: createReqX86.BootDisk,
SEPID: createReqX86.SEPID,
Pool: createReqX86.Pool,
DataDisks: createReqX86.DataDisks,
Interfaces: createReqX86.Interfaces,
Description: createReqX86.Description,
Chipset: createReqX86.Chipset,
PreferredCPU: createReqX86.PreferredCPU,
ZoneID: createReqX86.ZoneID,
OSVersion: createReqX86.OSVersion,
}
apiResp, err = c.CloudBroker().KVMX86().CreateBlank(ctx, createBlankReq)
} else {
apiResp, err = c.CloudBroker().KVMX86().Create(ctx, createReqX86)
}
if err != nil {
return diag.FromErr(err)
}
@@ -291,6 +309,7 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
bootType, bootTypeOk := d.GetOk("boot_type")
hotResize, hotResizeOk := d.GetOkExists("hot_resize")
networkInterfaceNaming, networkInterfaceNamingOk := d.GetOk("network_interface_naming")
weight, weightOk := d.GetOk("weight")
if loaderTypeOk {
updateReq.LoaderType = loaderType.(string)
@@ -308,8 +327,12 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
updateReq.NetworkInterfaceNaming = networkInterfaceNaming.(string)
}
if loaderTypeOk || bootTypeOk || hotResizeOk || networkInterfaceNamingOk {
log.Debugf("resourceComputeCreate: change loaderType or bootType or hotResize or networkInterfaceNaming on ComputeID: %d", computeId)
if weightOk {
updateReq.Weight = uint64(weight.(int))
}
if loaderTypeOk || bootTypeOk || hotResizeOk || networkInterfaceNamingOk || weightOk {
log.Debugf("resourceComputeCreate: change loaderType or bootType or hotResize or networkInterfaceNaming or weight on ComputeID: %d", computeId)
updateReq.ComputeID = computeId
_, err := c.CloudBroker().Compute().Update(ctx, updateReq)
if err != nil {
@@ -381,7 +404,7 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if mac == "" {
warnings.Add(errors.New(fmt.Sprintf("add libvirt virtio: Network with type %s and id %d is not connected to the compute %d", netType, netId, computeId)))
warnings.Add(fmt.Errorf("add libvirt virtio: Network with type %s and id %d is not connected to the compute %d", netType, netId, computeId))
continue
}
log.Debugf("resourceComputeCreate: Configure libvirt virtio interface parameters on Network with type %s and id %d", netType, netId)
@@ -420,7 +443,7 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if mac == "" {
warnings.Add(errors.New(fmt.Sprintf("add security groups: Network with type %s and id %d is not connected to the compute %d", netType, netId, computeId)))
warnings.Add(fmt.Errorf("add security groups: Network with type %s and id %d is not connected to the compute %d", netType, netId, computeId))
continue
}
secGroupsIDs := make([]uint64, 0)
@@ -448,6 +471,9 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
if nodeID, ok := d.GetOk("node_id"); ok {
req.NodeID = uint64(nodeID.(int))
}
if altBootID, ok := d.Get("alt_boot_id").(int); ok {
req.AltBootID = uint64(altBootID)
}
log.Debugf("resourceComputeCreate: starting Compute ID %d after completing its resource configuration", computeId)
if _, err := c.CloudBroker().Compute().Start(ctx, req); err != nil {
warnings.Add(err)
@@ -677,6 +703,9 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
if err != nil {
warnings.Add(err)
}
if err := utilityComputeCreateBlockSize(ctx, d, m); err != nil {
warnings.Add(err)
}
if err := utilityComputeCreateIOTune(ctx, d, m); err != nil {
warnings.Add(err)
}
@@ -874,7 +903,8 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
"boot_type",
"hot_resize",
"network_interface_naming",
"os_version") {
"os_version",
"weight") {
if err := utilityComputeUpdate(ctx, d, m); err != nil {
return diag.FromErr(err)
}

View File

@@ -232,6 +232,14 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"block_size": {
Type: schema.TypeString,
Computed: true,
},
"provision": {
Type: schema.TypeString,
Computed: true,
},
"boot_partition": {
Type: schema.TypeInt,
Computed: true,
@@ -287,6 +295,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"independent": {
Type: schema.TypeBool,
Computed: true,
},
"iotune": {
Type: schema.TypeList,
Optional: true,
@@ -588,6 +600,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"independent": {
Type: schema.TypeBool,
Computed: true,
},
"interfaces": {
Type: schema.TypeList,
Computed: true,
@@ -1150,6 +1166,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"weight": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}
@@ -1931,6 +1951,10 @@ func dataSourceComputeListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"weight": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
@@ -2221,6 +2245,10 @@ func dataSourceComputeListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"sep_id": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
@@ -2639,6 +2667,10 @@ func dataSourceComputeListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"weight": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
@@ -3409,6 +3441,12 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Optional: true,
Default: false,
},
"create_blank": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "If True, the compute is created via kvmx86/createBlank endpoint (without OS image). The image_id field is not required in this case.",
},
"boot_disk_size": {
Type: schema.TypeInt,
Optional: true,
@@ -3463,16 +3501,6 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "ID of node to start compute",
},
"is": {
Type: schema.TypeString,
Optional: true,
Description: "system name",
},
"ipa_type": {
Type: schema.TypeString,
Optional: true,
Description: "compute purpose",
},
"custom_fields": {
Type: schema.TypeString,
Optional: true,
@@ -3521,8 +3549,8 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Optional: true,
Computed: true,
//Default: 1500,
ValidateFunc: validation.IntBetween(1, 9216),
Description: "Maximum transmission unit, used only for DPDK type, must be 1-9216",
ValidateFunc: validation.IntBetween(1500, 9216),
Description: "Maximum transmission unit, used only for DPDK type, must be 1500-9216",
},
"sdn_interface_id": {
Type: schema.TypeString,
@@ -3531,22 +3559,22 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
DiffSuppressFunc: networkSubresIPAddreDiffSupperss,
Description: "unique_identifier of LogicalPort on SDN side",
},
"enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "network enable flag",
},
"net_mask": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Subnet mask, used only for DPDK and VFNIC network types",
"enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "network enable flag",
},
"net_mask": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Subnet mask, used only for DPDK and VFNIC network types",
},
},
},
Description: "Optional network connection(s) for this compute. You may specify several network blocks, one for each connection.",
},
Description: "Optional network connection(s) for this compute. You may specify several network blocks, one for each connection.",
},
"libvirt_settings": {
Type: schema.TypeSet,
@@ -3609,7 +3637,7 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Required: true,
StateFunc: statefuncs.StateFuncToUpper,
ValidateFunc: validation.StringInSlice([]string{"VINS", "EXTNET", "VFNIC", "DPDK", "SDN", "TRUNK"}, false), // observe case while validating
ValidateFunc: validation.StringInSlice([]string{"VINS", "EXTNET", "DPDK"}, false), // observe case while validating
Description: "Type of the network",
},
"net_id": {
@@ -3750,18 +3778,31 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Optional: true,
Default: false,
},
"block_size": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Disk block size",
},
"provision": {
Type: schema.TypeString,
Computed: true,
},
"sep_id": {
Type: schema.TypeInt,
Computed: true,
Optional: true,
Description: "Storage endpoint provider ID; by default the same with boot disk",
},
"disk_type": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"B", "D"}, false),
Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data'",
"pci_slot": {
Type: schema.TypeInt,
Computed: true,
Description: "PCI slot number of the disk",
},
"bus_number": {
Type: schema.TypeInt,
Computed: true,
Description: "Bus number of the disk on virtual bus (6 = boot disk)",
},
"pool": {
Type: schema.TypeString,
@@ -3788,11 +3829,67 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Specify image id for create disk from template",
},
"independent": {
Type: schema.TypeBool,
Computed: true,
},
"permanently": {
Type: schema.TypeBool,
Optional: true,
Description: "Disk deletion status",
},
"disk_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Disk ID",
},
"present_to": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"shareable": {
Type: schema.TypeBool,
Computed: true,
},
"size_max": {
Type: schema.TypeInt,
Computed: true,
},
"size_used": {
Type: schema.TypeInt,
Computed: true,
},
"to_clean": {
Type: schema.TypeBool,
Computed: true,
},
"devicename": {
Type: schema.TypeString,
Computed: true,
},
"create_by": {
Type: schema.TypeString,
Computed: true,
},
"create_time": {
Type: schema.TypeInt,
Computed: true,
},
"delete_by": {
Type: schema.TypeString,
Computed: true,
},
"delete_time": {
Type: schema.TypeInt,
Computed: true,
},
"update_time": {
Type: schema.TypeInt,
Computed: true,
},
"iotune": {
Type: schema.TypeList,
Optional: true,
@@ -3868,58 +3965,6 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
},
},
},
"disk_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Disk ID",
},
"present_to": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"shareable": {
Type: schema.TypeBool,
Computed: true,
},
"size_max": {
Type: schema.TypeInt,
Computed: true,
},
"size_used": {
Type: schema.TypeInt,
Computed: true,
},
"to_clean": {
Type: schema.TypeBool,
Computed: true,
},
"devicename": {
Type: schema.TypeString,
Computed: true,
},
"create_by": {
Type: schema.TypeString,
Computed: true,
},
"create_time": {
Type: schema.TypeInt,
Computed: true,
},
"delete_by": {
Type: schema.TypeString,
Computed: true,
},
"delete_time": {
Type: schema.TypeInt,
Computed: true,
},
"update_time": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
@@ -4159,6 +4204,13 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "the OS version installed on the VM",
},
"weight": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validation.IntAtLeast(1),
Description: "Priority weight of the compute. Higher value means higher priority and later migration.",
},
// Computed properties
"account_id": {
Type: schema.TypeInt,

View File

@@ -209,7 +209,11 @@ func utilityComputeResize(ctx context.Context, d *schema.ResourceData, m interfa
}
if isStopRequired {
if _, err := c.CloudBroker().Compute().Start(ctx, compute.StartRequest{ComputeID: computeId}); err != nil {
req := compute.StartRequest{ComputeID: computeId}
if altBootID, ok := d.Get("alt_boot_id").(int); ok {
req.AltBootID = uint64(altBootID)
}
if _, err := c.CloudBroker().Compute().Start(ctx, req); err != nil {
return err
}
}
@@ -262,11 +266,14 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
changeStoragePolicyDisks := make([]interface{}, 0)
cacheUpdatedDisks := make([]interface{}, 0)
blkDiscardUpdatedDisks := make([]interface{}, 0)
blockSizeUpdatedDisks := make([]interface{}, 0)
iotuneUpdatedDisks := make([]interface{}, 0)
migratedDisks := make([]interface{}, 0)
presentNewDisks := make([]interface{}, 0)
presentOldDisks := make([]interface{}, 0)
chipset := d.Get("chipset").(string)
oldDisks, newDisks := d.GetChange("disks")
oldConv := oldDisks.([]interface{})
newConv := newDisks.([]interface{})
@@ -322,6 +329,10 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
blkDiscardUpdatedDisks = append(blkDiscardUpdatedDisks, el)
}
if isChangeBlockSizeDisk(oldConv, el) {
blockSizeUpdatedDisks = append(blockSizeUpdatedDisks, el)
}
if isChangeIOTuneDisk(oldConv, el) {
iotuneUpdatedDisks = append(iotuneUpdatedDisks, el)
}
@@ -330,7 +341,7 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
if len(deletedDisks) > 0 {
for _, disk := range deletedDisks {
diskConv := disk.(map[string]interface{})
if diskConv["disk_type"].(string) == "B" {
if isBootDisk(diskConv, chipset) {
continue
}
@@ -350,9 +361,6 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
if len(addedDisks) > 0 {
for _, disk := range addedDisks {
diskConv := disk.(map[string]interface{})
if diskConv["disk_type"].(string) == "B" {
continue
}
req := compute.DiskAddRequest{
ComputeID: computeId,
DiskName: diskConv["disk_name"].(string),
@@ -362,9 +370,6 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
if diskConv["sep_id"].(int) != 0 {
req.SepID = uint64(diskConv["sep_id"].(int))
}
if diskConv["disk_type"].(string) != "" {
req.DiskType = diskConv["disk_type"].(string)
}
if diskConv["pool"].(string) != "" {
req.Pool = diskConv["pool"].(string)
}
@@ -381,6 +386,16 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
if err != nil {
return err
}
if blockSize, ok := diskConv["block_size"].(string); ok && blockSize != "" {
updateReq := disks.UpdateRequest{
DiskID: diskID,
BlockSize: blockSize,
}
_, err := c.CloudBroker().Disks().Update(ctx, updateReq)
if err != nil {
return err
}
}
if nodeIDs, ok := diskConv["node_ids"]; ok {
presentIDs := nodeIDs.(*schema.Set).List()
if len(presentIDs) > 0 {
@@ -421,14 +436,16 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
return err
}
}
if err != nil {
return err
}
}
}
if len(resizedDisks) > 0 {
for _, disk := range resizedDisks {
diskConv := disk.(map[string]interface{})
if diskConv["disk_type"].(string) == "B" {
if isBootDisk(diskConv, chipset) {
continue
}
req := compute.DiskResizeRequest{
@@ -478,7 +495,7 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
if len(cacheUpdatedDisks) > 0 {
for _, disk := range cacheUpdatedDisks {
diskConv := disk.(map[string]interface{})
if diskConv["disk_type"].(string) == "B" {
if isBootDisk(diskConv, chipset) {
continue
}
@@ -501,7 +518,7 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
if len(blkDiscardUpdatedDisks) > 0 {
for _, disk := range blkDiscardUpdatedDisks {
diskConv := disk.(map[string]interface{})
if diskConv["disk_type"].(string) == "B" {
if isBootDisk(diskConv, chipset) {
continue
}
@@ -521,18 +538,43 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
}
}
if len(iotuneUpdatedDisks) > 0 {
for _, disk := range iotuneUpdatedDisks {
if len(blockSizeUpdatedDisks) > 0 {
for _, disk := range blockSizeUpdatedDisks {
diskConv := disk.(map[string]interface{})
if diskConv["disk_type"].(string) == "B" {
if isBootDisk(diskConv, chipset) {
continue
}
diskID := uint64(diskConv["disk_id"].(int))
if diskID == 0 {
continue
}
iotuneRaw, ok := diskConv["iotune"].([]interface{})
if !ok || len(iotuneRaw) == 0 {
req := disks.UpdateRequest{
DiskID: diskID,
BlockSize: diskConv["block_size"].(string),
}
_, err := c.CloudBroker().Disks().Update(ctx, req)
if err != nil {
return err
}
}
}
if len(iotuneUpdatedDisks) > 0 {
for _, disk := range iotuneUpdatedDisks {
diskConv := disk.(map[string]interface{})
if isBootDisk(diskConv, chipset) {
continue
}
diskID := uint64(diskConv["disk_id"].(int))
if diskID == 0 {
continue
}
iotuneRaw := diskConv["iotune"].([]interface{})
if len(iotuneRaw) == 0 {
continue
}
iotuneMap := iotuneRaw[0].(map[string]interface{})
@@ -778,10 +820,23 @@ func utilityComputePCIDevicesList(ctx context.Context, d *schema.ResourceData, m
return res, nil
}
func findBootDisk(disks compute.ListDisks) *compute.ItemDisk {
func isBootDisk(diskConv map[string]interface{}, chipset string) bool {
if chipset == "i440fx" {
return diskConv["pci_slot"].(int) == 6
}
return diskConv["bus_number"].(int) == 6
}
func findBootDisk(disks compute.ListDisks, chipset string) *compute.ItemDisk {
for _, disk := range disks {
if disk.Type == "B" {
return &disk
if chipset == "i440fx" {
if disk.PCISlot == 6 {
return &disk
}
} else {
if disk.BusNumber == 6 {
return &disk
}
}
}
return &compute.ItemDisk{}
@@ -981,7 +1036,13 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
if needStart {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
if numErr, err := utilityComputeStart(ctx, computeId, m); err != nil {
var altBootID uint64
if altBootIDRaw, ok := d.Get("alt_boot_id").(int); ok {
altBootID = uint64(altBootIDRaw)
} else {
altBootID = 0
}
if numErr, err := utilityComputeStart(ctx, computeId, altBootID, m); err != nil {
apiErrCount += numErr
lastSavedError = err
}
@@ -1264,6 +1325,10 @@ func utilityComputeUpdate(ctx context.Context, d *schema.ResourceData, m interfa
req.OSVersion = d.Get("os_version").(string)
}
if d.HasChange("weight") {
req.Weight = uint64(d.Get("weight").(int))
}
req.CPUPin = d.Get("cpu_pin").(bool)
req.HPBacked = d.Get("hp_backed").(bool)
req.AutoStart = d.Get("auto_start_w_node").(bool)
@@ -1308,7 +1373,11 @@ func utilityComputeUpdate(ctx context.Context, d *schema.ResourceData, m interfa
// If used to be STARTED, we need to start it after update
if isStopRequired {
if _, err := c.CloudBroker().Compute().Start(ctx, compute.StartRequest{ComputeID: computeId}); err != nil {
req := compute.StartRequest{ComputeID: computeId}
if altBootID, ok := d.Get("alt_boot_id").(int); ok {
req.AltBootID = uint64(altBootID)
}
if _, err := c.CloudBroker().Compute().Start(ctx, req); err != nil {
return err
}
}
@@ -1779,6 +1848,9 @@ func utilityComputeRollback(ctx context.Context, d *schema.ResourceData, m inter
}
startReq := compute.StartRequest{ComputeID: computeId}
if altBootID, ok := d.Get("alt_boot_id").(int); ok {
startReq.AltBootID = uint64(altBootID)
}
log.Debugf("utilityComputeRollback: starting compute %d", computeId)
@@ -2036,10 +2108,14 @@ func utilityComputeStop(ctx context.Context, d *schema.ResourceData, m interface
return nil
}
func utilityComputeStart(ctx context.Context, computeID uint64, m interface{}) (int, error) {
func utilityComputeStart(ctx context.Context, computeID uint64, altBootID uint64, m interface{}) (int, error) {
c := m.(*controller.ControllerCfg)
startReq := compute.StartRequest{ComputeID: computeID}
if altBootID != 0 {
startReq.AltBootID = altBootID
}
log.Debugf("utilityComputeStart: starting compute %d", computeID)
_, err := c.CloudBroker().Compute().Start(ctx, startReq)
if err != nil {
@@ -2048,6 +2124,109 @@ func utilityComputeStart(ctx context.Context, computeID uint64, m interface{}) (
return 0, nil
}
func utilityComputeCreateBlockSize(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
diskList := d.Get("disks").([]interface{})
blockSizeArr := make([]string, 0, len(diskList))
hasAny := false
for _, elem := range diskList {
diskVal := elem.(map[string]interface{})
bs := diskVal["block_size"].(string)
blockSizeArr = append(blockSizeArr, bs)
if bs != "" {
hasAny = true
}
}
if !hasAny {
return nil
}
computeRec, err := utilityComputeCheckPresence(ctx, d, m)
if err != nil {
return err
}
bootDisk := findBootDisk(computeRec.Disks, computeRec.Chipset)
computeDisksIDs := getComputeDiskIDs(computeRec.Disks, diskList, d.Get("extra_disks").(*schema.Set).List(), bootDisk.ID)
for i, diskID := range computeDisksIDs {
if i >= len(blockSizeArr) || blockSizeArr[i] == "" {
continue
}
req := disks.UpdateRequest{
DiskID: diskID.(uint64),
BlockSize: blockSizeArr[i],
}
_, err := c.CloudBroker().Disks().Update(ctx, req)
if err != nil {
return err
}
}
return nil
}
func utilityComputeCreateIOTune(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
diskList := d.Get("disks").([]interface{})
iotuneArr := make([]interface{}, 0, len(diskList))
hasAny := false
for _, elem := range diskList {
diskVal := elem.(map[string]interface{})
iotune := diskVal["iotune"].([]interface{})
iotuneArr = append(iotuneArr, iotune)
if len(iotune) > 0 {
hasAny = true
}
}
if !hasAny {
return nil
}
computeRec, err := utilityComputeCheckPresence(ctx, d, m)
if err != nil {
return err
}
bootDisk := findBootDisk(computeRec.Disks, computeRec.Chipset)
computeDisksIDs := getComputeDiskIDs(computeRec.Disks, diskList, d.Get("extra_disks").(*schema.Set).List(), bootDisk.ID)
for i, diskID := range computeDisksIDs {
if i >= len(iotuneArr) {
continue
}
iotune, ok := iotuneArr[i].([]interface{})
if !ok || len(iotune) == 0 {
continue
}
iotuneMap := iotune[0].(map[string]interface{})
req := disks.LimitIORequest{
DiskID: diskID.(uint64),
ReadBytesSec: uint64(iotuneMap["read_bytes_sec"].(int)),
ReadBytesSecMax: uint64(iotuneMap["read_bytes_sec_max"].(int)),
ReadIOPSSec: uint64(iotuneMap["read_iops_sec"].(int)),
ReadIOPSSecMax: uint64(iotuneMap["read_iops_sec_max"].(int)),
SizeIOPSSec: uint64(iotuneMap["size_iops_sec"].(int)),
TotalBytesSec: uint64(iotuneMap["total_bytes_sec"].(int)),
TotalBytesSecMax: uint64(iotuneMap["total_bytes_sec_max"].(int)),
TotalIOPSSec: uint64(iotuneMap["total_iops_sec"].(int)),
TotalIOPSSecMax: uint64(iotuneMap["total_iops_sec_max"].(int)),
WriteBytesSec: uint64(iotuneMap["write_bytes_sec"].(int)),
WriteBytesSecMax: uint64(iotuneMap["write_bytes_sec_max"].(int)),
WriteIOPSSec: uint64(iotuneMap["write_iops_sec"].(int)),
WriteIOPSSecMax: uint64(iotuneMap["write_iops_sec_max"].(int)),
}
_, err := c.CloudBroker().Disks().LimitIO(ctx, req)
if err != nil {
return err
}
}
return nil
}
func utilityComputeCreatePresentDisk(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
var errs error
@@ -2059,7 +2238,7 @@ func utilityComputeCreatePresentDisk(ctx context.Context, d *schema.ResourceData
}
computeRec, err := utilityComputeCheckPresence(ctx, d, m)
bootDisk := findBootDisk(computeRec.Disks)
bootDisk := findBootDisk(computeRec.Disks, computeRec.Chipset)
if err != nil {
errs = errors.Join(err)
}
@@ -2141,6 +2320,18 @@ func isChangeBLKDiscardDisk(els []interface{}, el interface{}) bool {
return false
}
func isChangeBlockSizeDisk(els []interface{}, el interface{}) bool {
for _, elOld := range els {
elOldConv := elOld.(map[string]interface{})
elConv := el.(map[string]interface{})
if elOldConv["disk_id"].(int) == elConv["disk_id"].(int) &&
elOldConv["block_size"].(string) != elConv["block_size"].(string) {
return true
}
}
return false
}
func isChangeIOTuneDisk(els []interface{}, el interface{}) bool {
for _, elOld := range els {
elOldConv := elOld.(map[string]interface{})
@@ -2175,66 +2366,6 @@ func isChangeIOTuneDisk(els []interface{}, el interface{}) bool {
return false
}
func utilityComputeCreateIOTune(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
diskList := d.Get("disks").([]interface{})
iotuneArr := make([]interface{}, 0, len(diskList))
hasAny := false
for _, elem := range diskList {
diskVal := elem.(map[string]interface{})
iotune := diskVal["iotune"].([]interface{})
iotuneArr = append(iotuneArr, iotune)
if len(iotune) > 0 {
hasAny = true
}
}
if !hasAny {
return nil
}
computeRec, err := utilityComputeCheckPresence(ctx, d, m)
if err != nil {
return err
}
bootDisk := findBootDisk(computeRec.Disks)
computeDisksIDs := getComputeDiskIDs(computeRec.Disks, diskList, d.Get("extra_disks").(*schema.Set).List(), bootDisk.ID)
for i, diskID := range computeDisksIDs {
if i >= len(iotuneArr) {
continue
}
iotune, ok := iotuneArr[i].([]interface{})
if !ok || len(iotune) == 0 {
continue
}
iotuneMap := iotune[0].(map[string]interface{})
req := disks.LimitIORequest{
DiskID: diskID.(uint64),
ReadBytesSec: uint64(iotuneMap["read_bytes_sec"].(int)),
ReadBytesSecMax: uint64(iotuneMap["read_bytes_sec_max"].(int)),
ReadIOPSSec: uint64(iotuneMap["read_iops_sec"].(int)),
ReadIOPSSecMax: uint64(iotuneMap["read_iops_sec_max"].(int)),
SizeIOPSSec: uint64(iotuneMap["size_iops_sec"].(int)),
TotalBytesSec: uint64(iotuneMap["total_bytes_sec"].(int)),
TotalBytesSecMax: uint64(iotuneMap["total_bytes_sec_max"].(int)),
TotalIOPSSec: uint64(iotuneMap["total_iops_sec"].(int)),
TotalIOPSSecMax: uint64(iotuneMap["total_iops_sec_max"].(int)),
WriteBytesSec: uint64(iotuneMap["write_bytes_sec"].(int)),
WriteBytesSecMax: uint64(iotuneMap["write_bytes_sec_max"].(int)),
WriteIOPSSec: uint64(iotuneMap["write_iops_sec"].(int)),
WriteIOPSSecMax: uint64(iotuneMap["write_iops_sec_max"].(int)),
}
_, err := c.CloudBroker().Disks().LimitIO(ctx, req)
if err != nil {
return err
}
}
return nil
}
func isChangeStoragePolicy(els []interface{}, el interface{}) bool {
for _, elOld := range els {
elOldConv := elOld.(map[string]interface{})

View File

@@ -263,11 +263,12 @@ func flattenGetNetAddr(address node.NetAddr) []map[string]interface{} {
func flattenCpuInfo(info node.CpuInfo) []map[string]interface{} {
res := make([]map[string]interface{}, 1)
temp := map[string]interface{}{
"clock_speed": info.ClockSpeed,
"core_count": info.CoreCount,
"phys_count": info.PhysCount,
"flags": info.Flags,
"model_name": info.ModelName,
"clock_speed": info.ClockSpeed,
"core_count": info.CoreCount,
"phys_count": info.PhysCount,
"flags": info.Flags,
"model_name": info.ModelName,
"thread_count": info.ThreadCount,
}
res[0] = temp
return res

View File

@@ -52,7 +52,7 @@ func dataSourceNodeSchemaMake() map[string]*schema.Schema {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"vcpu": {
Type: schema.TypeInt,
Type: schema.TypeFloat,
Computed: true,
},
"ram": {
@@ -121,6 +121,10 @@ func dataSourceNodeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"thread_count": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
@@ -498,6 +502,11 @@ func dataSourceNodeListSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "find node by status",
},
"zone_id": {
Type: schema.TypeInt,
Optional: true,
Description: "find node by zone id",
},
"sort_by": {
Type: schema.TypeString,
Optional: true,
@@ -570,6 +579,10 @@ func dataSourceNodeListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"thread_count": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},

View File

@@ -76,6 +76,9 @@ func utilityNodeListCheckPresence(ctx context.Context, d *schema.ResourceData, m
if Size, ok := d.GetOk("size"); ok {
req.Size = uint64(Size.(int))
}
if zoneId, ok := d.GetOk("zone_id"); ok {
req.ZoneID = uint64(zoneId.(int))
}
log.Debugf("utilityNodeListCheckPresence: load node list")
nodeList, err := c.CloudBroker().Node().List(ctx, req)

View File

@@ -48,6 +48,7 @@ func flattenRgAcl(rgACLs rg.ListACL) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(rgACLs))
for _, acl := range rgACLs {
temp := map[string]interface{}{
"email": acl.Email,
"explicit": acl.Explicit,
"guid": acl.GUID,
"right": acl.Right,

View File

@@ -107,6 +107,9 @@ func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m inter
if _, ok := d.GetOk("def_net"); !ok {
if defNetType, ok := d.GetOk("def_net_type"); ok {
if defNetType.(string) == "PRIVATE" {
return diag.Errorf("resourceResgroupCreate: cannot create RG with def_net_type=\"PRIVATE\": no ViNSes exist in a newly created RG. Use def_net_type=\"PRIVATE\" only when updating an existing RG that already contains a ViNS")
}
req.DefNet = defNetType.(string)
}
} else {
@@ -186,7 +189,14 @@ func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m inter
}
}
if _, ok := d.GetOk("def_net"); ok {
if defNet, ok := d.GetOk("def_net"); ok {
if defNet.(*schema.Set).Len() > 0 {
defNetList := defNet.(*schema.Set).List()
defNetItem := defNetList[0].(map[string]interface{})
if defNetItem["net_type"].(string) == "PRIVATE" {
return diag.Errorf("resourceResgroupCreate: cannot create RG with def_net net_type=\"PRIVATE\": no ViNSes exist in a newly created RG. Use net_type=\"PRIVATE\" in def_net block only when updating an existing RG that already contains a ViNS")
}
}
if err := resourceRGSetDefNet(ctx, d, m); err != nil {
w.Add(err)
}
@@ -483,7 +493,32 @@ func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m inter
}
if d.HasChange("def_net") {
oldDefNet, _ := d.GetChange("def_net")
oldDefNet, newDefNet := d.GetChange("def_net")
if newDefNet.(*schema.Set).Len() > 0 {
defNetList := newDefNet.(*schema.Set).List()
defNetItem := defNetList[0].(map[string]interface{})
netType := defNetItem["net_type"].(string)
netID := uint64(defNetItem["net_id"].(int))
if netType == "PRIVATE" {
if netID == 0 {
if len(rgData.VINS) == 0 {
return diag.Errorf("resourceResgroupUpdate: cannot set def_net net_type=\"PRIVATE\" for RG ID %d: no ViNSes exist in this RG", rgData.ID)
}
} else {
found := false
for _, vinsID := range rgData.VINS {
if vinsID == netID {
found = true
break
}
}
if !found {
return diag.Errorf("resourceResgroupUpdate: cannot set def_net net_type=\"PRIVATE\" for RG ID %d: ViNS ID %d is not found in this RG", rgData.ID, netID)
}
}
}
}
if oldDefNet.(*schema.Set).Len() > 0 {
_, err := c.CloudBroker().RG().RemoveDefNet(ctx, rg.RemoveDefNetRequest{RGID: rgData.ID})
if err != nil {

View File

@@ -25,6 +25,10 @@ func dataSourceRgSchemaMake() map[string]*schema.Schema {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"email": {
Type: schema.TypeString,
Computed: true,
},
"explicit": {
Type: schema.TypeBool,
Computed: true,
@@ -2461,6 +2465,10 @@ func resourceRgSchemaMake() map[string]*schema.Schema {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"email": {
Type: schema.TypeString,
Computed: true,
},
"explicit": {
Type: schema.TypeBool,
Computed: true,

View File

@@ -338,7 +338,6 @@ func resourceSepChangePools(ctx context.Context, d *schema.ResourceData, m inter
log.Debugf(string(marshalPool))
addPoolReq := sep.AddPoolRequest{
SEPID: uint64(d.Get("sep_id").(int)),
Sync: true,
Pool: string(marshalPool),
}

View File

@@ -6,7 +6,6 @@ import (
)
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)
@@ -62,13 +61,28 @@ func flattenStoragePolicyList(storagePolicyList *stpolicy.ListStoragePolicies) [
return res
}
func flattenAccessSEPPoolsResource(accessSEPPools stpolicy.ListAccessSEPPools) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, asp := range accessSEPPools {
for _, poolName := range asp.PoolNames {
temp := map[string]interface{}{
"sep_id": asp.SEPID,
"sep_name": asp.Name,
"pool_name": poolName,
"sep_tech_status": asp.SepTechStatus,
}
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("access_seps_pools", flattenAccessSEPPoolsResource(storagePolicy.AccessSEPPools))
d.Set("usage", flattenUsage(storagePolicy.Usage))
}

View File

@@ -61,7 +61,6 @@ func resourceStoragePolicyCreate(ctx context.Context, d *schema.ResourceData, m
}
d.SetId(strconv.FormatUint(storagePolicyID, 10))
d.Set("storage_policy_id", storagePolicyID)
if enabled, ok := d.GetOk("enabled"); ok {
isToEnable := enabled.(bool)

View File

@@ -7,10 +7,6 @@ import (
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,
@@ -32,6 +28,10 @@ func resourceStoragePolicySchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Required: true,
},
"sep_tech_status": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
@@ -129,6 +129,10 @@ func dataSourceStoragePolicySchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"sep_tech_status": {
Type: schema.TypeString,
Computed: true,
},
},
},
},

View File

@@ -15,11 +15,11 @@ func flattenTrunkResource(d *schema.ResourceData, details *trunk.ItemTrunk) {
d.Set("name", details.Name)
d.Set("mac", details.MAC)
d.Set("description", details.Description)
d.Set("accountIds", details.AccountIDs)
d.Set("ovsBridge", details.OVSBridge)
d.Set("nativeVlanId", details.NativeVLANID)
d.Set("account_ids", details.AccountIDs)
d.Set("ovs_bridge", details.OVSBridge)
d.Set("native_vlan_id", details.NativeVLANID)
d.Set("status", details.Status)
d.Set("trunkTags", details.TrunkTags)
d.Set("trunk_tags", details.TrunkTags)
d.Set("created_at", details.CreatedAt)
d.Set("created_by", details.CreatedBy)
d.Set("updated_at", details.UpdatedAt)

View File

@@ -33,6 +33,7 @@ package vfpool
import (
"context"
"fmt"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
@@ -85,6 +86,12 @@ func resourceVFPoolCreate(ctx context.Context, d *schema.ResourceData, m interfa
}
config, configOk := d.GetOk("config")
enableVal := d.Get("enable").(bool)
if enableVal && !configOk {
return diag.FromErr(fmt.Errorf("enable requires config to be set"))
}
if configOk {
configArray := config.(*schema.Set).List()
req.Config = make([]vfpool.Config, 0, len(configArray))
@@ -117,10 +124,8 @@ func resourceVFPoolCreate(ctx context.Context, d *schema.ResourceData, m interfa
warnings := dc.Warnings{}
if enable, ok := d.GetOk("enable"); ok {
if err := utilityVFPoolEnabled(ctx, m, enable.(bool), vfPoolID, configOk); err != nil {
warnings.Add(err)
}
if err := utilityVFPoolEnabled(ctx, m, enableVal, vfPoolID); err != nil {
warnings.Add(err)
}
log.Debugf("resourceVFPoolCreate: create VFPool with ID: %d, complete", vfPoolID)
@@ -147,20 +152,12 @@ func resourceVFPoolUpdate(ctx context.Context, d *schema.ResourceData, m interfa
log.Debugf("resourceVFPoolUpdate: called VFPool with id %d", vfPoolID)
_, ok := d.GetOk("config")
if d.HasChanges("name,", "description", "account_access", "rg_access,", "config") {
if d.HasChanges("name", "description", "account_access", "rg_access", "config", "enable") {
if err := utilityVFPoolUpdate(ctx, d, m, vfPoolID); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("enable") {
if err := utilityVFPoolEnabled(ctx, m, d.Get("enable").(bool), vfPoolID, ok); err != nil {
return diag.FromErr(err)
}
}
log.Debugf("resourceVFPoolUpdate: update VFPool with id %d, complete", vfPoolID)
return resourceVFPoolRead(ctx, d, m)

View File

@@ -64,37 +64,26 @@ func utilityVFpoolCheckPresence(ctx context.Context, d *schema.ResourceData, m i
return vfpoolData, nil
}
func utilityVFPoolEnabled(ctx context.Context, m interface{}, enable bool, vfPoolID uint64, configOk bool) error {
func utilityVFPoolEnabled(ctx context.Context, m interface{}, enable bool, vfPoolID uint64) error {
c := m.(*controller.ControllerCfg)
if enable && configOk {
req := vfpool.EnableRequest{
VFPoolID: vfPoolID,
}
_, err := c.CloudBroker().VFPool().Enable(ctx, req)
if err != nil {
return err
}
}
if enable && !configOk {
return fmt.Errorf("you must provide configuration for this resource, after enabling it")
}
if !enable {
req := vfpool.DisableRequest{
VFPoolID: vfPoolID,
}
_, err := c.CloudBroker().VFPool().Disable(ctx, req)
if err != nil {
return err
}
var err error
if enable {
_, err = c.CloudBroker().VFPool().Enable(ctx, vfpool.EnableRequest{VFPoolID: vfPoolID})
} else {
_, err = c.CloudBroker().VFPool().Disable(ctx, vfpool.DisableRequest{VFPoolID: vfPoolID})
}
log.Debugf("utilityVFPoolEnabled: enable=%v vfPool ID %d after completing its resource configuration", enable, vfPoolID)
return nil
return err
}
func utilityVFPoolUpdate(ctx context.Context, d *schema.ResourceData, m interface{}, vfPoolID uint64) error {
hasConfig := len(d.Get("config").(*schema.Set).List()) > 0
if d.Get("enable").(bool) && !hasConfig {
return fmt.Errorf("enable requires config to be set")
}
c := m.(*controller.ControllerCfg)
vfPool, err := utilityVFpoolCheckPresence(ctx, d, m)
@@ -190,7 +179,7 @@ func utilityVFPoolUpdate(ctx context.Context, d *schema.ResourceData, m interfac
}
log.Debugf("utilityVFPoolUpdate: update vfPool with ID: %d, complete with params=%v", vfPoolID, req)
if len(d.Get("config").(*schema.Set).List()) > 0 && d.Get("enable").(bool) {
if hasConfig && d.Get("enable").(bool) {
reqEnable := vfpool.EnableRequest{
VFPoolID: vfPoolID,
}
@@ -201,8 +190,6 @@ func utilityVFPoolUpdate(ctx context.Context, d *schema.ResourceData, m interfac
return err
}
log.Debugf("utilityVFPoolUpdate: enable vfPool with ID: %d, complete", vfPoolID)
} else {
return (fmt.Errorf("the vfPool is not enabled after update, you must provide configuration for this resource, after enabling it"))
}
return nil

View File

@@ -1,34 +0,0 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package vgpu
const VGPU_LIST_API = "/restmachine/cloudbroker/vgpu/list"

View File

@@ -1,120 +0,0 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package vgpu
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceVGPURead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
vgpu, err := utilityVGPUCheckPresence(ctx, d, m)
if vgpu == nil {
d.SetId("")
return diag.FromErr(err)
}
d.SetId(strconv.FormatUint(vgpu.ID, 10))
d.Set("vgpu_id", vgpu.ID)
d.Set("account_id", vgpu.AccountID)
d.Set("mode", vgpu.Mode)
d.Set("pgpu", vgpu.PGPUID)
d.Set("profile_id", vgpu.ProfileID)
d.Set("ram", vgpu.RAM)
d.Set("status", vgpu.Status)
d.Set("type", vgpu.Type)
d.Set("vm_id", vgpu.VMID)
return nil
}
func dataSourceVGPUSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"vgpu_id": {
Type: schema.TypeInt,
Required: true,
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"mode": {
Type: schema.TypeString,
Computed: true,
},
"pgpu": {
Type: schema.TypeInt,
Computed: true,
},
"profile_id": {
Type: schema.TypeInt,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"vm_id": {
Type: schema.TypeInt,
Computed: true,
},
}
}
func DataSourceVGPU() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceVGPURead,
Schema: dataSourceVGPUSchemaMake(),
}
}

View File

@@ -1,74 +0,0 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package vgpu
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vgpu"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityVGPUCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vgpu.ItemVGPU, error) {
c := m.(*controller.ControllerCfg)
req := vgpu.ListRequest{
Size: 50,
}
var vgpuId uint64
var err error
if vId, ok := d.GetOk("vgpu_id"); ok {
vgpuId = uint64(vId.(int))
} else {
vgpuId, err = strconv.ParseUint(d.Id(), 10, 64)
if err != nil {
return nil, err
}
}
for page := 1; ; page++ {
req.Page = uint64(page)
vgpus, err := c.CloudBroker().VGPU().List(ctx, req)
if err != nil {
return nil, err
}
for _, vgpu := range vgpus.Data {
if vgpu.ID == vgpuId {
return &vgpu, nil
}
}
}
}

View File

@@ -88,6 +88,8 @@ func createVinsInAcc(ctx context.Context, d *schema.ResourceData, m interface{},
req.ZoneID = uint64(zoneID.(int))
}
req.EnableSecGroups = d.Get("enable_secgroups").(bool)
return req, nil
}
@@ -143,6 +145,8 @@ func createVinsInRG(ctx context.Context, d *schema.ResourceData, m interface{},
req.ZoneID = uint64(zoneID.(int))
}
req.EnableSecGroups = d.Get("enable_secgroups").(bool)
return req, nil
}

View File

@@ -115,12 +115,6 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface
}
}
if d.Get("enable_secgroups").(bool) {
if err := resourceVinsEnableSecgroups(ctx, d, m, vinsID); err != nil {
warnings.Add(err)
}
}
return append(warnings.Get(), resourceVinsRead(ctx, d, m)...)
}
@@ -437,21 +431,6 @@ func resourceVinsIpReserve(ctx context.Context, d *schema.ResourceData, m interf
return errs
}
func resourceVinsEnableSecgroups(ctx context.Context, d *schema.ResourceData, m interface{}, vinsID uint64) error {
c := m.(*controller.ControllerCfg)
req := vins.UpdateRequest{
VINSID: vinsID,
EnableSecGroups: true,
}
_, err := c.CloudBroker().VINS().Update(ctx, req)
if err != nil {
return err
}
return nil
}
func resourceVinsNatRuleAdd(ctx context.Context, d *schema.ResourceData, m interface{}, vinsId uint64) []error {
var errs []error
c := m.(*controller.ControllerCfg)

View File

@@ -150,6 +150,50 @@ func dataSourceZoneSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"drs": {
Type: schema.TypeBool,
Computed: true,
},
"drs_uid": {
Type: schema.TypeString,
Computed: true,
},
"drs_name": {
Type: schema.TypeString,
Computed: true,
},
"sso_url": {
Type: schema.TypeString,
Computed: true,
},
"app_id": {
Type: schema.TypeString,
Computed: true,
},
"decort_url": {
Type: schema.TypeString,
Computed: true,
},
"domain": {
Type: schema.TypeString,
Computed: true,
},
"ping_addr": {
Type: schema.TypeString,
Computed: true,
},
"broadcast_addr": {
Type: schema.TypeString,
Computed: true,
},
"ssl_skip_verify": {
Type: schema.TypeBool,
Computed: true,
},
"sso_type": {
Type: schema.TypeString,
Computed: true,
},
}
}

View File

@@ -158,6 +158,50 @@ func dataSourceZoneListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"drs": {
Type: schema.TypeBool,
Computed: true,
},
"drs_uid": {
Type: schema.TypeString,
Computed: true,
},
"drs_name": {
Type: schema.TypeString,
Computed: true,
},
"sso_url": {
Type: schema.TypeString,
Computed: true,
},
"app_id": {
Type: schema.TypeString,
Computed: true,
},
"decort_url": {
Type: schema.TypeString,
Computed: true,
},
"domain": {
Type: schema.TypeString,
Computed: true,
},
"ping_addr": {
Type: schema.TypeString,
Computed: true,
},
"broadcast_addr": {
Type: schema.TypeString,
Computed: true,
},
"ssl_skip_verify": {
Type: schema.TypeBool,
Computed: true,
},
"sso_type": {
Type: schema.TypeString,
Computed: true,
},
},
},
},

View File

@@ -60,6 +60,17 @@ func flattenZone(d *schema.ResourceData, item *zone.RecordZone) error {
d.Set("bservice_ids", item.BserviceIDs)
d.Set("k8s_ids", item.K8SIDs)
d.Set("auto_start", item.AutoStart)
d.Set("drs", item.DRS)
d.Set("drs_uid", item.DRSUID)
d.Set("drs_name", item.DRSName)
d.Set("sso_url", item.SSOURL)
d.Set("app_id", item.AppID)
d.Set("decort_url", item.DecortURL)
d.Set("ping_addr", item.PingAddr)
d.Set("broadcast_addr", item.BroadcastAddr)
d.Set("ssl_skip_verify", item.SSLSkipVerify)
d.Set("domain", item.Domain)
d.Set("sso_type", item.SSOType)
log.Debugf("flattenZone: decoded RecordZone name %q / ID %d, complete",
item.Name, item.ID)
@@ -71,17 +82,28 @@ func flattenZoneList(zone *zone.ListZones) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(zone.Data))
for _, zone := range zone.Data {
temp := map[string]interface{}{
"zone_id": int(zone.ID),
"guid": int(zone.GUID),
"gid": int(zone.GID),
"name": zone.Name,
"description": zone.Description,
"deletable": zone.Deletable,
"status": zone.Status,
"created_time": zone.CreatedTime,
"updated_time": zone.UpdatedTime,
"node_ids": zone.NodeIDs,
"auto_start": zone.AutoStart,
"zone_id": int(zone.ID),
"guid": int(zone.GUID),
"gid": int(zone.GID),
"name": zone.Name,
"description": zone.Description,
"deletable": zone.Deletable,
"status": zone.Status,
"created_time": zone.CreatedTime,
"updated_time": zone.UpdatedTime,
"node_ids": zone.NodeIDs,
"auto_start": zone.AutoStart,
"drs": zone.DRS,
"drs_uid": zone.DRSUID,
"drs_name": zone.DRSName,
"sso_url": zone.SSOURL,
"app_id": zone.AppID,
"decort_url": zone.DecortURL,
"ping_addr": zone.PingAddr,
"broadcast_addr": zone.BroadcastAddr,
"ssl_skip_verify": zone.SSLSkipVerify,
"domain": zone.Domain,
"sso_type": zone.SSOType,
}
res = append(res, temp)
}

View File

@@ -64,6 +64,10 @@ func resourceZoneCreate(ctx context.Context, d *schema.ResourceData, m interface
req.Description = desc.(string)
}
if drs, ok := d.GetOkExists("drs"); ok {
req.DRS = drs.(bool)
}
zoneID, err := c.CloudBroker().Zone().Create(ctx, req)
if err != nil {
return diag.FromErr(err)
@@ -202,6 +206,51 @@ func resourceZoneSchemaMake() map[string]*schema.Schema {
Optional: true,
Default: false,
},
"drs": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"drs_uid": {
Type: schema.TypeString,
Computed: true,
},
"drs_name": {
Type: schema.TypeString,
Computed: true,
},
"sso_url": {
Type: schema.TypeString,
Computed: true,
},
"app_id": {
Type: schema.TypeString,
Computed: true,
},
"decort_url": {
Type: schema.TypeString,
Computed: true,
},
"domain": {
Type: schema.TypeString,
Computed: true,
},
"ping_addr": {
Type: schema.TypeString,
Computed: true,
},
"broadcast_addr": {
Type: schema.TypeString,
Computed: true,
},
"ssl_skip_verify": {
Type: schema.TypeBool,
Computed: true,
},
"sso_type": {
Type: schema.TypeString,
Computed: true,
},
"zone_id": {
Type: schema.TypeInt,
Computed: true,

View File

@@ -1,159 +1,159 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package zone
import (
"context"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/zone"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
)
func utilityZoneCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*zone.RecordZone, error) {
c := m.(*controller.ControllerCfg)
req := zone.GetRequest{}
if d.Id() != "" {
zoneId, _ := strconv.ParseUint(d.Id(), 10, 64)
req.ID = zoneId
} else {
req.ID = uint64(d.Get("zone_id").(int))
}
zoneData, err := c.CloudBroker().Zone().Get(ctx, req)
if err != nil {
return nil, err
}
return zoneData, nil
}
func utilityZoneUpdate(ctx context.Context, d *schema.ResourceData, m interface{}, zoneID uint64) error {
c := m.(*controller.ControllerCfg)
if d.HasChanges("name", "description", "auto_start") {
req := zone.UpdateRequest{
ID: zoneID,
}
if d.HasChange("name") {
req.Name = d.Get("name").(string)
}
if d.HasChange("description") {
req.Description = d.Get("description").(string)
}
if d.HasChange("auto_start") {
req.AutoStart = d.Get("auto_start").(bool)
}
_, err := c.CloudBroker().Zone().Update(ctx, req)
if err != nil {
return err
}
log.Debugf("utilityZoneUpdate: update zone with ID: %d, complete with params=%v", zoneID, req)
}
addedNodes := make([]interface{}, 0)
removedNodes := make([]interface{}, 0)
old_set, new_set := d.GetChange("node_ids")
oldSlice := old_set.([]interface{})
newSlice := new_set.([]interface{})
for _, oldElem := range oldSlice {
if !containsNodes(newSlice, oldElem) {
removedNodes = append(removedNodes, oldElem)
}
}
for _, newElem := range newSlice {
if !containsNodes(oldSlice, newElem) {
addedNodes = append(addedNodes, newElem)
}
}
log.Debugf("Found node_ids change with %v deletion(s) and %v addition(s) [zoneID=%v]", len(removedNodes), len(addedNodes), zoneID)
if len(addedNodes) > 0 {
addedUint := make([]uint64, len(addedNodes))
for i, v := range addedNodes {
addedUint[i] = uint64(v.(int))
}
req := zone.AddNodeRequest{
ID: zoneID,
NodeIDs: addedUint,
}
if _, err := c.CloudBroker().Zone().AddNode(ctx, req); err != nil {
return err
}
}
if len(removedNodes) > 0 {
removedUint := make([]uint64, len(removedNodes))
for i, v := range removedNodes {
removedUint[i] = uint64(v.(int))
}
req := zone.DelNodeRequest{
ID: zoneID,
NodeIDs: removedUint,
}
log.Debug("del")
log.Debug(req.NodeIDs)
if _, err := c.CloudBroker().Zone().DelNode(ctx, req); err != nil {
return err
}
}
return nil
}
func containsNodes(set []interface{}, check interface{}) bool {
for _, elem := range set {
elemConv := elem.(int)
checkConv := check.(int)
if elemConv == checkConv {
return true
}
}
return false
}
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package zone
import (
"context"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/zone"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
)
func utilityZoneCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*zone.RecordZone, error) {
c := m.(*controller.ControllerCfg)
req := zone.GetRequest{}
if d.Id() != "" {
zoneId, _ := strconv.ParseUint(d.Id(), 10, 64)
req.ID = zoneId
} else {
req.ID = uint64(d.Get("zone_id").(int))
}
zoneData, err := c.CloudBroker().Zone().Get(ctx, req)
if err != nil {
return nil, err
}
return zoneData, nil
}
func utilityZoneUpdate(ctx context.Context, d *schema.ResourceData, m interface{}, zoneID uint64) error {
c := m.(*controller.ControllerCfg)
if d.HasChanges("name", "description", "auto_start") {
req := zone.UpdateRequest{
ID: zoneID,
}
if d.HasChange("name") {
req.Name = d.Get("name").(string)
}
if d.HasChange("description") {
req.Description = d.Get("description").(string)
}
if d.HasChange("auto_start") {
req.AutoStart = d.Get("auto_start").(bool)
}
_, err := c.CloudBroker().Zone().Update(ctx, req)
if err != nil {
return err
}
log.Debugf("utilityZoneUpdate: update zone with ID: %d, complete with params=%v", zoneID, req)
}
addedNodes := make([]interface{}, 0)
removedNodes := make([]interface{}, 0)
old_set, new_set := d.GetChange("node_ids")
oldSlice := old_set.([]interface{})
newSlice := new_set.([]interface{})
for _, oldElem := range oldSlice {
if !containsNodes(newSlice, oldElem) {
removedNodes = append(removedNodes, oldElem)
}
}
for _, newElem := range newSlice {
if !containsNodes(oldSlice, newElem) {
addedNodes = append(addedNodes, newElem)
}
}
log.Debugf("Found node_ids change with %v deletion(s) and %v addition(s) [zoneID=%v]", len(removedNodes), len(addedNodes), zoneID)
if len(addedNodes) > 0 {
addedUint := make([]uint64, len(addedNodes))
for i, v := range addedNodes {
addedUint[i] = uint64(v.(int))
}
req := zone.AddNodeRequest{
ID: zoneID,
NodeIDs: addedUint,
}
if _, err := c.CloudBroker().Zone().AddNode(ctx, req); err != nil {
return err
}
}
if len(removedNodes) > 0 {
removedUint := make([]uint64, len(removedNodes))
for i, v := range removedNodes {
removedUint[i] = uint64(v.(int))
}
req := zone.DelNodeRequest{
ID: zoneID,
NodeIDs: removedUint,
}
log.Debug("del")
log.Debug(req.NodeIDs)
if _, err := c.CloudBroker().Zone().DelNode(ctx, req); err != nil {
return err
}
}
return nil
}
func containsNodes(set []interface{}, check interface{}) bool {
for _, elem := range set {
elemConv := elem.(int)
checkConv := check.(int)
if elemConv == checkConv {
return true
}
}
return false
}

View File

@@ -1,85 +1,85 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package zone
import (
"context"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/zone"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityZoneListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*zone.ListZones, error) {
c := m.(*controller.ControllerCfg)
req := zone.ListRequest{}
if byId, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(byId.(int))
}
if gid, ok := d.GetOk("gid"); ok {
req.GID = uint64(gid.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if description, ok := d.GetOk("description"); ok {
req.Description = description.(string)
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if deletable, ok := d.GetOk("deletable"); ok {
req.Deletable = deletable.(bool)
}
if nodeID, ok := d.GetOk("nodeId"); ok {
req.NodeID = uint64(nodeID.(int))
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(string)
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
zoneList, err := c.CloudBroker().Zone().List(ctx, req)
if err != nil {
return nil, err
}
return zoneList, nil
}
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package zone
import (
"context"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/zone"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityZoneListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*zone.ListZones, error) {
c := m.(*controller.ControllerCfg)
req := zone.ListRequest{}
if byId, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(byId.(int))
}
if gid, ok := d.GetOk("gid"); ok {
req.GID = uint64(gid.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if description, ok := d.GetOk("description"); ok {
req.Description = description.(string)
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if deletable, ok := d.GetOk("deletable"); ok {
req.Deletable = deletable.(bool)
}
if nodeID, ok := d.GetOk("nodeId"); ok {
req.NodeID = uint64(nodeID.(int))
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(string)
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
zoneList, err := c.CloudBroker().Zone().List(ctx, req)
if err != nil {
return nil, err
}
return zoneList, nil
}