This commit is contained in:
2026-09-21 11:51:12 +03:00
parent 9cd93e4277
commit 2b229a84fb
240 changed files with 7735 additions and 3166 deletions

View File

@@ -58,6 +58,8 @@ func DataSourceAccountAuditsList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
DeprecationMessage: "This data source is deprecated and will be removed in version 4.14.0; use decort_cb_audit_list instead.",
ReadContext: dataSourceAccountAuditsListRead,
Timeouts: &schema.ResourceTimeout{

View File

@@ -0,0 +1,309 @@
package account
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func resourceAccountV1() *schema.Resource {
return &schema.Resource{Schema: resourceAccountSchemaMakeV1()}
}
func resourceAccountSchemaMakeV1() map[string]*schema.Schema {
return map[string]*schema.Schema{
"account_name": {
Type: schema.TypeString,
Required: true,
Description: "account name",
},
"username": {
Type: schema.TypeString,
Required: true,
Description: "username of owner the account",
},
"desc": {
Type: schema.TypeString,
Optional: true,
Description: "description",
},
"emailaddress": {
Type: schema.TypeString,
Optional: true,
Description: "email",
},
"default_zone_id": {
Type: schema.TypeInt,
Optional: true,
Description: "email",
},
"send_access_emails": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "if true send emails when a user is granted access to resources",
},
"zone_ids": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"uniq_pools": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"users": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"user_id": {
Type: schema.TypeString,
Required: true,
},
"access_type": {
Type: schema.TypeString,
Required: true,
},
},
},
},
"cpu_allocation_parameter": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "set cpu allocation parameter",
},
"cpu_allocation_ratio": {
Type: schema.TypeFloat,
Optional: true,
Computed: true,
Description: "set cpu allocation ratio",
},
"available_templates": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
Description: "Share images with account",
},
"restore": {
Type: schema.TypeBool,
Optional: true,
Description: "restore a deleted account",
},
"permanently": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "whether to completely delete the account",
},
"enable": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "enable/disable account",
},
"resource_limits": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cu_c": {
Type: schema.TypeFloat,
Optional: true,
Computed: true,
},
"cu_d": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_dm": {
Type: schema.TypeFloat,
Optional: true,
Computed: true,
},
"cu_i": {
Type: schema.TypeFloat,
Optional: true,
Computed: true,
},
"cu_m": {
Type: schema.TypeFloat,
Optional: true,
Computed: true,
},
"gpu_units": {
Type: schema.TypeFloat,
Optional: true,
Computed: true,
},
"storage_policy": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
},
"limit": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
},
},
},
"storage_policy": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Required: true,
},
"limit": {
Type: schema.TypeInt,
Required: true,
},
},
},
},
"compute_features": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{"hugepages", "numa", "cpupin", "vfnic", "dpdk", "changemac", "trunk"}, true),
},
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"dc_location": {
Type: schema.TypeString,
Computed: true,
},
"acl": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"emails": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"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,
},
},
},
},
"company": {
Type: schema.TypeString,
Computed: true,
},
"companyurl": {
Type: schema.TypeString,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"deactivation_time": {
Type: schema.TypeFloat,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"displayname": {
Type: schema.TypeString,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"resource_types": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
"version": {
Type: schema.TypeInt,
Computed: true,
},
"vins": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
}
}

View File

@@ -209,7 +209,7 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interf
}
if cpuAllocationRatio, ok := d.GetOk("cpu_allocation_ratio"); ok {
cpuAllocationRatio := cpuAllocationRatio.(float64)
cpuAllocationRatio := uint64(cpuAllocationRatio.(int))
req := account.SetCPUAllocationRatioRequest{
AccountID: accountId,
@@ -450,7 +450,7 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
func ResourceAccount() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
SchemaVersion: 2,
CreateContext: resourceAccountCreate,
ReadContext: resourceAccountRead,
@@ -470,5 +470,12 @@ func ResourceAccount() *schema.Resource {
},
Schema: resourceAccountSchemaMake(),
StateUpgraders: []schema.StateUpgrader{
{
Type: resourceAccountV1().CoreConfigSchema().ImpliedType(),
Upgrade: resourceAccountStateUpgradeV1,
Version: 1,
},
},
}
}

View File

@@ -77,7 +77,7 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
Description: "set cpu allocation parameter",
},
"cpu_allocation_ratio": {
Type: schema.TypeFloat,
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "set cpu allocation ratio",
@@ -596,7 +596,7 @@ func dataSourceAccountListDeletedSchemaMake() map[string]*schema.Schema {
Computed: true,
},
"cpu_allocation_ratio": {
Type: schema.TypeFloat,
Type: schema.TypeInt,
Computed: true,
},
"created_by": {
@@ -1342,7 +1342,7 @@ func dataSourceAccountListSchemaMake() map[string]*schema.Schema {
Computed: true,
},
"cpu_allocation_ratio": {
Type: schema.TypeFloat,
Type: schema.TypeInt,
Computed: true,
},
"created_by": {
@@ -2234,7 +2234,7 @@ func dataSourceAccountSchemaMake() map[string]*schema.Schema {
Computed: true,
},
"cpu_allocation_ratio": {
Type: schema.TypeFloat,
Type: schema.TypeInt,
Computed: true,
},
"created_by": {

View File

@@ -0,0 +1,15 @@
package account
import (
"context"
log "github.com/sirupsen/logrus"
)
func resourceAccountStateUpgradeV1(ctx context.Context, rawState map[string]interface{}, meta any) (map[string]interface{}, error) {
log.Debug("resourceAccountStateUpgradeV1: upgrading state")
if v, ok := rawState["cpu_allocation_ratio"]; ok && v != nil {
rawState["cpu_allocation_ratio"] = int(v.(float64))
}
return rawState, nil
}

View File

@@ -117,7 +117,7 @@ func utilityAccountCPURatioUpdate(ctx context.Context, d *schema.ResourceData, m
accountId, _ := strconv.ParseUint(d.Id(), 10, 64)
cpuAllocacationRatio := d.Get("cpu_allocation_ratio").(float64)
cpuAllocacationRatio := uint64(d.Get("cpu_allocation_ratio").(int))
_, err := c.CloudBroker().Account().SetCPUAllocationRatio(ctx, account.SetCPUAllocationRatioRequest{
AccountID: accountId,

View File

@@ -13,10 +13,11 @@ func flattenDisk(d *schema.ResourceData, disk *disks.RecordDisk) {
d.Set("account_id", disk.AccountID)
d.Set("account_name", disk.AccountName)
d.Set("acl", string(diskAcl))
d.Set("blk_discard", disk.BLKDiscard)
d.Set("discard", disk.Discard)
d.Set("block_size", disk.BlockSize)
d.Set("boot_partition", disk.BootPartition)
d.Set("computes", flattenDiskComputes(disk.Computes))
d.Set("computes_read_only", flattenDiskComputesReadOnly(disk.ComputesReadOnly))
d.Set("created_by", disk.CreatedBy)
d.Set("created_time", disk.CreatedTime)
d.Set("deleted_by", disk.DeletedBy)
@@ -157,6 +158,18 @@ func flattenDiskComputes(computes map[string]string) []map[string]interface{} {
return res
}
func flattenDiskComputesReadOnly(computesReadOnly map[string]bool) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(computesReadOnly))
for computeID, readOnly := range computesReadOnly {
tmp := map[string]interface{}{
"compute_id": computeID,
"read_only": readOnly,
}
res = append(res, tmp)
}
return res
}
func flattenIOTune(iot disks.IOTune) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
@@ -187,10 +200,11 @@ func flattenDiskList(dl *disks.ListDisks) []map[string]interface{} {
"account_id": disk.AccountID,
"account_name": disk.AccountName,
"acl": string(diskAcl),
"blk_discard": disk.BLKDiscard,
"discard": disk.Discard,
"block_size": disk.BlockSize,
"boot_partition": disk.BootPartition,
"computes": flattenDiskComputes(disk.Computes),
"computes_read_only": flattenDiskComputesReadOnly(disk.ComputesReadOnly),
"created_by": disk.CreatedBy,
"created_time": disk.CreatedTime,
"deleted_by": disk.DeletedBy,
@@ -255,6 +269,7 @@ func flattendDiskSnapshotList(sl disks.ListSnapshots) []interface{} {
temp := map[string]interface{}{
"guid": snapshot.GUID,
"label": snapshot.Label,
"pool_name": snapshot.PoolName,
"reference_id": snapshot.ReferenceID,
"res_id": snapshot.ResID,
"snap_set_guid": snapshot.SnapSetGUID,
@@ -276,7 +291,7 @@ func flattenDiskListUnattached(ul *disks.ListUnattachedDisks) []map[string]inter
"account_id": unattachedDisk.AccountID,
"account_name": unattachedDisk.AccountName,
"acl": string(unattachedDiskAcl),
"blk_discard": unattachedDisk.BLKDiscard,
"discard": unattachedDisk.Discard,
"block_size": unattachedDisk.BlockSize,
"boot_partition": unattachedDisk.BootPartition,
"created_time": unattachedDisk.CreatedTime,

View File

@@ -5,6 +5,16 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func resourceDiskV2() *schema.Resource {
s := resourceDiskSchemaMake()
s["blk_discard"] = &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
}
return &schema.Resource{Schema: s}
}
func resourceDiskV1() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{

View File

@@ -79,8 +79,8 @@ func resourceDiskCreate(ctx context.Context, d *schema.ResourceData, m interface
req.Cache = cache.(string)
}
if blkDiscard, ok := d.GetOk("blk_discard"); ok {
req.BLKDiscard = blkDiscard.(bool)
if discard, ok := d.GetOk("discard"); ok {
req.Discard = discard.(string)
}
diskID, err := c.CloudBroker().Disks().Create(ctx, req)
@@ -250,15 +250,15 @@ func resourceDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface
}
}
if d.HasChanges("cache", "blk_discard", "block_size") {
if d.HasChanges("cache", "discard", "block_size") {
updateReq := disks.UpdateRequest{
DiskID: uint64(d.Get("disk_id").(int)),
}
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("discard") {
updateReq.Discard = d.Get("discard").(string)
}
if d.HasChange("block_size") {
updateReq.BlockSize = d.Get("block_size").(string)
@@ -460,7 +460,7 @@ func resourceDiskChangeNodes(ctx context.Context, d *schema.ResourceData, m inte
func ResourceDisk() *schema.Resource {
return &schema.Resource{
SchemaVersion: 2,
SchemaVersion: 3,
CreateContext: resourceDiskCreate,
ReadContext: resourceDiskRead,
@@ -486,6 +486,11 @@ func ResourceDisk() *schema.Resource {
Upgrade: resourceDiskUpgradeV1,
Version: 1,
},
{
Type: resourceDiskV2().CoreConfigSchema().ImpliedType(),
Upgrade: resourceDiskUpgradeV2,
Version: 2,
},
},
}
}

View File

@@ -23,8 +23,8 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"blk_discard": {
Type: schema.TypeBool,
"discard": {
Type: schema.TypeString,
Computed: true,
},
"block_size": {
@@ -51,6 +51,22 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
},
},
},
"computes_read_only": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compute_id": {
Type: schema.TypeString,
Computed: true,
},
"read_only": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
"created_by": {
Type: schema.TypeString,
Computed: true,
@@ -327,6 +343,10 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"pool_name": {
Type: schema.TypeString,
Computed: true,
},
"reference_id": {
Type: schema.TypeString,
Computed: true,
@@ -478,8 +498,8 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"blk_discard": {
Type: schema.TypeBool,
"discard": {
Type: schema.TypeString,
Computed: true,
},
"block_size": {
@@ -506,6 +526,22 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
},
},
},
"computes_read_only": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compute_id": {
Type: schema.TypeString,
Computed: true,
},
"read_only": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
"created_by": {
Type: schema.TypeString,
Computed: true,
@@ -786,6 +822,10 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"pool_name": {
Type: schema.TypeString,
Computed: true,
},
"reference_id": {
Type: schema.TypeString,
Computed: true,
@@ -913,8 +953,8 @@ func dataSourceDiskListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"blk_discard": {
Type: schema.TypeBool,
"discard": {
Type: schema.TypeString,
Computed: true,
},
"block_size": {
@@ -941,6 +981,22 @@ func dataSourceDiskListDeletedSchemaMake() map[string]*schema.Schema {
},
},
},
"computes_read_only": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compute_id": {
Type: schema.TypeString,
Computed: true,
},
"read_only": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
"created_by": {
Type: schema.TypeString,
Computed: true,
@@ -1221,6 +1277,10 @@ func dataSourceDiskListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"pool_name": {
Type: schema.TypeString,
Computed: true,
},
"reference_id": {
Type: schema.TypeString,
Computed: true,
@@ -1367,8 +1427,8 @@ func dataSourceDiskListUnattachedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"blk_discard": {
Type: schema.TypeBool,
"discard": {
Type: schema.TypeString,
Computed: true,
},
"block_size": {
@@ -1926,10 +1986,11 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
Default: false,
Description: "restore deleting disk",
},
"blk_discard": {
Type: schema.TypeBool,
Optional: true,
Default: false,
"discard": {
Type: schema.TypeString,
Optional: true,
Default: "ignore",
ValidateFunc: validation.StringInSlice([]string{"unmap", "ignore"}, false),
},
"block_size": {
Type: schema.TypeString,
@@ -1965,6 +2026,22 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
},
},
},
"computes_read_only": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compute_id": {
Type: schema.TypeString,
Computed: true,
},
"read_only": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
@@ -2220,6 +2297,10 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"pool_name": {
Type: schema.TypeString,
Computed: true,
},
"reference_id": {
Type: schema.TypeString,
Computed: true,
@@ -2569,6 +2650,10 @@ func dataSourceDiskReplicationSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"pool_name": {
Type: schema.TypeString,
Computed: true,
},
"reference_id": {
Type: schema.TypeString,
Computed: true,

View File

@@ -12,3 +12,17 @@ func resourceDiskUpgradeV1(ctx context.Context, rawState map[string]interface{},
return rawState, nil
}
func resourceDiskUpgradeV2(ctx context.Context, rawState map[string]interface{}, meta any) (map[string]interface{}, error) {
log.Debug("resourceDiskUpgradeV2: upgrading state")
if v, ok := rawState["blk_discard"].(bool); ok {
if v {
rawState["discard"] = "unmap"
} else {
rawState["discard"] = "ignore"
}
}
delete(rawState, "blk_discard")
return rawState, nil
}

View File

@@ -37,6 +37,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
)
func flattenListExtnet(extList *extnet.ListExtNet) []map[string]interface{} {
@@ -129,8 +130,10 @@ func flattenRecordExtnetResource(d *schema.ResourceData, recNet *extnet.RecordEx
d.Set("ovs_bridge", recNet.OVSBridge)
d.Set("pre_reservations_num", recNet.PreReservationsNum)
d.Set("pri_vnfdev_id", recNet.PriVNFDevID)
d.Set("sec_vnfdev_id", recNet.SecVNFDevID)
d.Set("shared_with", recNet.SharedWith)
d.Set("status", recNet.Status)
d.Set("enable", recNet.Status == status.Enabled)
d.Set("vlan_id", recNet.VLANID)
d.Set("check_ips", recNet.CheckIPs)
d.Set("dns", recNet.DNS)
@@ -146,9 +149,8 @@ func flattenRecordExtnetResource(d *schema.ResourceData, recNet *extnet.RecordEx
d.Set("routes", flattenStaticRouteList(staticRouteList))
d.Set("zone_id", recNet.ZoneID)
d.Set("enable_secgroups", recNet.EnableSecGroups)
d.Set("sec_vnfdev_id", recNet.SecVNFDevID)
d.Set("highly_available", recNet.Redundant)
d.Set("mtu", recNet.MTU)
d.Set("highly_available", recNet.Redundant)
}
func flattenExtnetExcluded(ers extnet.ListReservations) []map[string]interface{} {

View File

@@ -93,15 +93,6 @@ func resourceExtnetCreate(ctx context.Context, d *schema.ResourceData, m interfa
req.DNS = res
}
if ntp, ok := d.GetOk("ntp"); ok {
res := make([]string, 0)
for _, elem := range ntp.([]interface{}) {
res = append(res, elem.(string))
}
req.NTP = res
}
if check_ips, ok := d.GetOk("check_ips"); ok {
res := make([]string, 0)
for _, elem := range check_ips.([]interface{}) {
@@ -111,9 +102,7 @@ func resourceExtnetCreate(ctx context.Context, d *schema.ResourceData, m interfa
req.CheckIPs = res
}
if virtual, ok := d.GetOk("virtual"); ok {
req.Virtual = virtual.(bool)
}
req.Virtual = d.Get("virtual").(bool)
if zoneID, ok := d.GetOk("zone_id"); ok {
req.ZoneID = uint64(zoneID.(int))
@@ -139,9 +128,7 @@ func resourceExtnetCreate(ctx context.Context, d *schema.ResourceData, m interfa
req.OVSBridge = ovs_bridge.(string)
}
if highly_available, ok := d.GetOk("highly_available"); ok {
req.HAMode = highly_available.(bool)
}
req.HAMode = d.Get("highly_available").(bool)
if sec_vnfdev_ip, ok := d.GetOk("sec_vnfdev_ip"); ok {
req.SecVNFDevIP = sec_vnfdev_ip.(string)
@@ -227,6 +214,12 @@ func resourceExtnetCreate(ctx context.Context, d *schema.ResourceData, m interfa
}
}
if _, ok := d.GetOk("ntp"); ok {
if err := handleNTPUpdate(ctx, d, c, &extnet.RecordExtNet{ID: netID}); err != nil {
w.Add(err)
}
}
if qos, ok := d.GetOk("default_qos"); ok && len(qos.([]interface{})) > 0 {
if err := handleDefaultQOSUpdate(ctx, d, c, &extnet.RecordExtNet{ID: netID}); err != nil {
w.Add(err)

View File

@@ -686,12 +686,12 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
"gid": {
Type: schema.TypeInt,
Required: true,
Description: "Grid (platform) ID",
Description: "Grid platform ID",
},
"ipcidr": {
Type: schema.TypeString,
Required: true,
// ForceNew: true,
// ForceNew: true,?
Description: "IP network CIDR",
ValidateFunc: validation.IsCIDR,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
@@ -724,7 +724,7 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "enable security groups",
Description: "Enable security groups",
},
"dns": {
Type: schema.TypeList,
@@ -754,12 +754,12 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
ValidateFunc: validation.IsIPAddress,
},
Description: "IPs to check network availability",
Description: "IPs checking network availability",
},
"virtual": {
Type: schema.TypeBool,
Optional: true,
Description: "If true - platform DHCP server will not be created",
Description: "True disables platform DHCP server creation",
},
"desc": {
Type: schema.TypeString,
@@ -770,44 +770,44 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
"start_ip": {
Type: schema.TypeString,
Optional: true,
Description: "Start of IP range to be explicitly included",
Description: "Explicitly included IP range start",
ValidateFunc: validation.IsIPAddress,
},
"end_ip": {
Type: schema.TypeString,
Optional: true,
Description: "End of IP range to be explicitly included",
Description: "Explicitly included IP range end",
ValidateFunc: validation.IsIPAddress,
},
"vnfdev_ip": {
Type: schema.TypeString,
Optional: true,
Description: "IP to create VNFDev with",
Description: "VNFDev creation IP",
ValidateFunc: validation.IsIPAddress,
},
"pre_reservations_num": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Number of pre created reservations",
Description: "Number of pre-created reservations",
},
"ovs_bridge": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "OpenvSwith bridge name for ExtNet connection",
Description: "OpenvSwitch bridge name ExtNet connection",
},
"enable": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Disable/Enable extnet",
Description: "Toggle extnet status",
},
"set_default": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Set current extnet as default (can not be undone)",
Description: "Set current extnet as default permanent action",
},
"excluded_ips": {
Type: schema.TypeSet,
@@ -816,7 +816,7 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
ValidateFunc: validation.IsIPAddress,
},
Description: "IPs to exclude in current extnet pool",
Description: "IPs excluded extnet pool",
},
"excluded_ips_range": {
Type: schema.TypeSet,
@@ -835,7 +835,7 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
},
},
},
Description: "Range of IPs to exclude in current extnet pool",
Description: "Range of IPs excluded extnet pool",
},
"default_qos": {
Type: schema.TypeList,
@@ -869,7 +869,7 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
"restart": {
Type: schema.TypeBool,
Optional: true,
Description: "restart extnet vnf device",
Description: "Restart extnet vnf device",
},
"migrate": {
Type: schema.TypeInt,
@@ -920,9 +920,10 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
ValidateFunc: validation.IsIPAddress,
},
"mtu": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validation.IntBetween(1500, 9216),
},
"ckey": {
Type: schema.TypeString,
@@ -934,7 +935,7 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "meta",
Description: "Meta information",
},
"default": {
Type: schema.TypeBool,
@@ -1044,7 +1045,42 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"pre_reservations": {
"routes": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compute_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"destination": {
Type: schema.TypeString,
Computed: true,
},
"gateway": {
Type: schema.TypeString,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"netmask": {
Type: schema.TypeString,
Computed: true,
},
"route_id": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"reservations": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
@@ -1088,42 +1124,7 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
},
},
},
"routes": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compute_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"destination": {
Type: schema.TypeString,
Computed: true,
},
"gateway": {
Type: schema.TypeString,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"netmask": {
Type: schema.TypeString,
Computed: true,
},
"route_id": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"reservations": {
"pre_reservations": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{

View File

@@ -122,19 +122,32 @@ func handleBasicUpdate(ctx context.Context, d *schema.ResourceData, c *controlle
basiUpdateReq.MTU = uint64(d.Get("mtu").(int))
doBasicUpdate = true
}
if d.HasChange("enable_secgroups") {
changingSecGroups := d.HasChange("enable_secgroups")
if changingSecGroups {
basiUpdateReq.EnableSecGroups = d.Get("enable_secgroups").(bool)
doBasicUpdate = true
}
if doBasicUpdate {
_, err := c.CloudBroker().ExtNet().Update(ctx, basiUpdateReq)
if err != nil {
if !doBasicUpdate {
return nil
}
wasEnabled := changingSecGroups && recNet.Status == status.Enabled
if wasEnabled {
if _, err := c.CloudBroker().ExtNet().Disable(ctx, extnet.DisableRequest{NetID: recNet.ID}); err != nil {
return err
}
}
return nil
_, err := c.CloudBroker().ExtNet().Update(ctx, basiUpdateReq)
if wasEnabled {
if _, enableErr := c.CloudBroker().ExtNet().Enable(ctx, extnet.EnableRequest{NetID: recNet.ID}); enableErr != nil {
return errors.Join(err, enableErr)
}
}
return err
}
func handleEnableUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {

View File

@@ -58,6 +58,8 @@ func DataSourceGridListEmails() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
DeprecationMessage: "This data source is deprecated and will be removed in version 4.14.0.",
ReadContext: dataSourceGridListEmailsRead,
Timeouts: &schema.ResourceTimeout{

View File

@@ -9,8 +9,6 @@ import (
)
func flattenGrid(d *schema.ResourceData, grid *grid.RecordGrid) {
d.Set("ckey", grid.CKey)
d.Set("meta", flattens.FlattenMeta(grid.Meta))
d.Set("auth_broker", flattens.FlattenMeta(grid.AuthBroker))
d.Set("name", grid.Name)
d.Set("flag", grid.Flag)
@@ -19,8 +17,10 @@ func flattenGrid(d *schema.ResourceData, grid *grid.RecordGrid) {
d.Set("location_code", grid.LocationCode)
d.Set("id", grid.ID)
d.Set("network_modes", grid.NetworkModes)
d.Set("reserved_cpu", grid.ReservedCPU)
d.Set("reserved_ram", grid.ReservedRAM)
d.Set("sdn_support", grid.SDNSupport)
d.Set("zero_access_enabled", grid.ZeroAccessEnabled)
}
func flattenGridList(gl *grid.ListGrids) []map[string]interface{} {
@@ -36,8 +36,11 @@ func flattenGridList(gl *grid.ListGrids) []map[string]interface{} {
"location_code": item.LocationCode,
"id": item.ID,
"network_modes": item.NetworkModes,
"reserved_cpu": item.ReservedCPU,
"reserved_ram": item.ReservedRAM,
"sdn_support": item.SDNSupport,
"zero_access_enabled": item.ZeroAccessEnabled,
"bro_enabled": item.BROEnabled,
}
res = append(res, temp)
}
@@ -77,11 +80,26 @@ func flattenGridRecordResource(rr grid.RecordResource) []map[string]interface{}
"gpu": rr.GPU,
"ram": rr.RAM,
"seps": flattenGridSeps(rr.SEPs),
"policies": flattenGridPolicies(rr.Policies),
}
res = append(res, temp)
return res
}
func flattenGridPolicies(policies map[string]grid.PolicyUsage) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(policies))
for policyID, policy := range policies {
temp := map[string]interface{}{
"policy_id": policyID,
"disk_size": policy.DiskSize,
"disk_size_max": policy.DiskSizeMax,
"seps": flattenGridSeps(policy.SEPs),
}
res = append(res, temp)
}
return res
}
func flattenGridSeps(seps map[string]map[string]grid.DiskUsage) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for sepKey, sepVal := range seps {
@@ -106,11 +124,14 @@ func flattenGridSettings(d *schema.ResourceData, gridSettings *grid.RecordSettin
d.Set("enable_uptime_monitor", gridSettings.EnableUptimeMonitor)
d.Set("extnet_max_pre_reservations_num", gridSettings.ExtnetMaxPreReservationsNum)
d.Set("healthcheck_notifications", flattenHealthcheckNotifications(gridSettings.HealthcheckNotifications))
d.Set("interface_generation_scheme", gridSettings.InterfaceGenerationScheme)
d.Set("k8s_cleanup_enabled", gridSettings.K8sCleanupEnabled)
d.Set("limits", string(limits))
d.Set("location_url", gridSettings.LocationURL)
d.Set("mac_address_prefix", gridSettings.MACAddressPrefix)
d.Set("net_qos", flattenNetQOS(gridSettings.NetQOS))
d.Set("networks", gridSettings.Networks)
d.Set("node_self_stop_timer_uptime_monitor", gridSettings.NodeSelfStopTimerUptimeMonitor)
d.Set("node_self_stop_uptime_monitor", gridSettings.NodeSelfStopUptimeMonitor)
d.Set("prometheus", flattenPrometheus(gridSettings.Prometheus))
d.Set("vins_max_pre_reservations_num", gridSettings.VinsMaxPreReservationsNum)
d.Set("vnfdev_mgmt_net_range", gridSettings.VnfdevMgmtNetRange)

View File

@@ -8,18 +8,6 @@ func dataSourceGetGridSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Required: true,
},
"ckey": {
Type: schema.TypeString,
Computed: true,
},
"meta": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "meta",
},
"auth_broker": {
Type: schema.TypeList,
Computed: true,
@@ -58,10 +46,22 @@ func dataSourceGetGridSchemaMake() map[string]*schema.Schema {
},
Computed: true,
},
"reserved_cpu": {
Type: schema.TypeInt,
Computed: true,
},
"reserved_ram": {
Type: schema.TypeInt,
Computed: true,
},
"sdn_support": {
Type: schema.TypeBool,
Computed: true,
},
"zero_access_enabled": {
Type: schema.TypeBool,
Computed: true,
},
}
}
@@ -156,6 +156,7 @@ func dataSourceGridListSchemaMake() map[string]*schema.Schema {
},
},
},
"policies": gridPoliciesSchemaMake(),
},
},
},
@@ -212,6 +213,7 @@ func dataSourceGridListSchemaMake() map[string]*schema.Schema {
},
},
},
"policies": gridPoliciesSchemaMake(),
},
},
},
@@ -256,6 +258,14 @@ func dataSourceGridListSchemaMake() map[string]*schema.Schema {
},
Computed: true,
},
"reserved_cpu": {
Type: schema.TypeInt,
Computed: true,
},
"reserved_ram": {
Type: schema.TypeInt,
Computed: true,
},
"sdn_support": {
Type: schema.TypeBool,
Computed: true,
@@ -264,6 +274,10 @@ func dataSourceGridListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"bro_enabled": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
@@ -307,6 +321,53 @@ func dataSourceGridListEmailsSchemaMake() map[string]*schema.Schema {
return rets
}
func gridPoliciesSchemaMake() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"policy_id": {
Type: schema.TypeString,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeFloat,
Computed: true,
},
"seps": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeString,
Computed: true,
},
"data_name": {
Type: schema.TypeString,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
},
},
}
}
func dataSourceGridGetConsumptionSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"grid_id": {
@@ -366,6 +427,7 @@ func dataSourceGridGetConsumptionSchemaMake() map[string]*schema.Schema {
},
},
},
"policies": gridPoliciesSchemaMake(),
},
},
},
@@ -422,6 +484,7 @@ func dataSourceGridGetConsumptionSchemaMake() map[string]*schema.Schema {
},
},
},
"policies": gridPoliciesSchemaMake(),
},
},
},
@@ -489,6 +552,7 @@ func dataSourceGridListConsumptionSchemaMake() map[string]*schema.Schema {
},
},
},
"policies": gridPoliciesSchemaMake(),
},
},
},
@@ -545,6 +609,7 @@ func dataSourceGridListConsumptionSchemaMake() map[string]*schema.Schema {
},
},
},
"policies": gridPoliciesSchemaMake(),
},
},
},
@@ -725,10 +790,6 @@ func dataSourceGridGetSettingsSchemaMake() map[string]*schema.Schema {
},
},
},
"networks": {
Type: schema.TypeString,
Computed: true,
},
"prometheus": {
Type: schema.TypeList,
Computed: true,
@@ -749,5 +810,21 @@ func dataSourceGridGetSettingsSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"interface_generation_scheme": {
Type: schema.TypeString,
Computed: true,
},
"mac_address_prefix": {
Type: schema.TypeString,
Computed: true,
},
"node_self_stop_timer_uptime_monitor": {
Type: schema.TypeInt,
Computed: true,
},
"node_self_stop_uptime_monitor": {
Type: schema.TypeBool,
Computed: true,
},
}
}

View File

@@ -138,7 +138,7 @@ func flattenImageList(il *image.ListImages) []map[string]interface{} {
"storage_policy_id": item.StoragePolicyID,
"tech_status": item.TechStatus,
"to_clean": item.ToClean,
"image_type": item.Type,
"type_image": item.Type,
"url": item.URL,
"username": item.Username,
"version": item.Version,

View File

@@ -64,9 +64,10 @@ func dataSourceImageListSchemaMake() map[string]*schema.Schema {
Description: "find by architecture",
},
"type_image": {
Type: schema.TypeString,
Type: schema.TypeList,
Optional: true,
Description: "find by type",
Elem: &schema.Schema{Type: schema.TypeString},
},
"image_size": {
Type: schema.TypeInt,
@@ -366,7 +367,7 @@ func dataSourceImageListSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "tech atatus",
},
"image_type": {
"type_image": {
Type: schema.TypeString,
Computed: true,
Description: "Image type linux, windows or other",
@@ -737,9 +738,10 @@ func resourceCDROMImageSchemaMake() map[string]*schema.Schema {
Computed: true,
},
"computeci_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Type: schema.TypeInt,
Optional: true,
Computed: true,
Deprecated: "\"computeci_id\" is deprecated and will be removed in version 4.14.0",
},
"shared_with": {
Type: schema.TypeList,
@@ -1019,9 +1021,10 @@ func resourceImageSchemaMake() map[string]*schema.Schema {
Computed: true,
},
"computeci_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Type: schema.TypeInt,
Optional: true,
Computed: true,
Deprecated: "\"computeci_id\" is deprecated and will be removed in version 4.14.0",
},
"sync_mode": {
Type: schema.TypeBool,
@@ -1238,9 +1241,10 @@ func resourceVirtualImageSchemaMake() map[string]*schema.Schema {
Description: "Does this image boot OS",
},
"computeci_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Type: schema.TypeInt,
Optional: true,
Computed: true,
Deprecated: "\"computeci_id\" is deprecated and will be removed in version 4.14.0",
},
"enabled": {
Type: schema.TypeBool,
@@ -1494,9 +1498,10 @@ func resourceMultiImageSchemaMake() map[string]*schema.Schema {
Description: "Does this image boot OS",
},
"computeci_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Type: schema.TypeInt,
Optional: true,
Computed: true,
Deprecated: "\"computeci_id\" is deprecated and will be removed in version 4.14.0",
},
"enabled": {
Type: schema.TypeBool,
@@ -1802,9 +1807,10 @@ func resourceImageFromBlankComputeSchemaMake() map[string]*schema.Schema {
Computed: true,
},
"computeci_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Type: schema.TypeInt,
Optional: true,
Computed: true,
Deprecated: "\"computeci_id\" is deprecated and will be removed in version 4.14.0",
},
"shared_with": {
Type: schema.TypeList,
@@ -2076,9 +2082,10 @@ func resourceImageFromPlatformDiskSchemaMake() map[string]*schema.Schema {
Computed: true,
},
"computeci_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Type: schema.TypeInt,
Optional: true,
Computed: true,
Deprecated: "\"computeci_id\" is deprecated and will be removed in version 4.14.0",
},
"shared_with": {
Type: schema.TypeList,

View File

@@ -58,7 +58,9 @@ func utilityImageListCheckPresence(ctx context.Context, d *schema.ResourceData,
req.Status = status.(string)
}
if typeImage, ok := d.GetOk("type_image"); ok {
req.TypeImage = typeImage.(string)
for _, v := range typeImage.([]interface{}) {
req.TypeImage = append(req.TypeImage, v.(string))
}
}
if imageSize, ok := d.GetOk("image_size"); ok {
req.ImageSize = uint64(imageSize.(int))

View File

@@ -1352,7 +1352,7 @@ func resourceK8sCPSchemaMake() map[string]*schema.Schema {
"k8sci_id": {
Type: schema.TypeInt,
Required: true,
Description: "ID of the k8s catalog item to base this instance on.",
Description: "ID of the k8s catalog item to base this instance on. The maximum supported Kubernetes version is < 1.29.",
},
"network_plugin": {
Type: schema.TypeString,
@@ -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

@@ -58,6 +58,8 @@ func DataSourceComputeAudits() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
DeprecationMessage: "This data source is deprecated and will be removed in version 4.14.0; use decort_cb_audit_list instead.",
ReadContext: dataSourceComputeAuditsRead,
Timeouts: &schema.ResourceTimeout{

View File

@@ -0,0 +1,98 @@
/*
Copyright (c) 2019-2023 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 kvmvm
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 dataSourceComputeCPUAlignmentProfileRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
profile, err := utilityComputeGetCPUAlignmentProfile(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("model", profile.Model)
d.Set("name", profile.Name)
d.Set("vendor", profile.Vendor)
return nil
}
func dataSourceComputeCPUAlignmentProfileSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"compute_id": {
Type: schema.TypeInt,
Required: true,
Description: "ID of the compute instance",
},
"model": {
Type: schema.TypeString,
Computed: true,
Description: "CPU model of the alignment profile",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the CPU alignment profile",
},
"vendor": {
Type: schema.TypeString,
Computed: true,
Description: "CPU vendor of the alignment profile",
},
}
}
func DataSourceComputeCPUAlignmentProfile() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceComputeCPUAlignmentProfileRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceComputeCPUAlignmentProfileSchemaMake(),
}
}

View File

@@ -57,6 +57,8 @@ func DataSourceComputeGetAudits() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
DeprecationMessage: "This data source is deprecated and will be removed in version 4.14.0; use decort_cb_audit_list instead.",
ReadContext: dataSourceComputeGetAuditsRead,
Timeouts: &schema.ResourceTimeout{

View File

@@ -59,6 +59,8 @@ func DataSourceComputeGetLog() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
DeprecationMessage: "This data source is deprecated and will be removed in version 4.14.0.",
ReadContext: dataSourceComputeGetLogRead,
Timeouts: &schema.ResourceTimeout{

View File

@@ -34,6 +34,7 @@ package kvmvm
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -49,7 +50,7 @@ func dataSourceComputeMigrateStorageInfoRead(ctx context.Context, d *schema.Reso
id := uuid.New()
d.SetId(id.String())
d.Set("migrate_storage_info", result)
flattenMigrateStorageInfo(d, result)
return nil
}

View File

@@ -39,8 +39,10 @@ func flattenCompute(d *schema.ResourceData, computeRec *compute.RecordCompute, p
d.Set("boot_disk_id", bootDisk.ID)
// we intentionally use the SizeMax field, do not change it until the BootDiskSize field is fixed on the platform
d.Set("boot_disk_size", bootDisk.SizeMax)
d.Set("boot_disk_discard", bootDisk.Discard)
d.Set("boot_image_id", bootDisk.ImageID)
d.Set("chipset", computeRec.Chipset)
d.Set("clock", computeRec.Clock)
d.Set("cd_image_id", computeRec.CdImageId)
d.Set("clone_reference", computeRec.CloneReference)
d.Set("clones", computeRec.Clones)
@@ -85,6 +87,7 @@ func flattenCompute(d *schema.ResourceData, computeRec *compute.RecordCompute, p
d.Set("registered", computeRec.Registered)
d.Set("res_name", computeRec.ResName)
d.Set("reserved_node_cpus", computeRec.ReservedNodeCpus)
d.Set("resized_online", computeRec.ResizedOnline)
d.Set("rg_name", computeRec.RGName)
d.Set("rg_id", computeRec.RGID)
d.Set("snap_sets", flattenSnapSets(computeRec.SnapSets))
@@ -111,12 +114,26 @@ func flattenCompute(d *schema.ResourceData, computeRec *compute.RecordCompute, p
d.Set("zone_id", computeRec.ZoneID)
d.Set("os_version", computeRec.OSVersion)
d.Set("cpu_pin", computeRec.CPUPin)
d.Set("cpu_alignment_profile", computeRec.CPUAlignmentProfile.Name)
d.Set("numa_affinity", computeRec.NumaAffinity)
d.Set("hp_backed", computeRec.HPBacked)
d.Set("weight", computeRec.Weight)
return nil
}
func flattenCPUAlignmentProfile(profile compute.CPUAlignmentProfile) []map[string]interface{} {
if profile.Name == "" && profile.Model == "" && profile.Vendor == "" {
return nil
}
return []map[string]interface{}{
{
"name": profile.Name,
"model": profile.Model,
"vendor": profile.Vendor,
},
}
}
func flattenPCI(pciList compute.ListPCIDevices) []uint64 {
res := make([]uint64, 0, len(pciList.Data))
@@ -145,10 +162,11 @@ func flattenSnapSets(snaps compute.ListSnapshots) []map[string]interface{} {
for _, snap := range snaps {
res = append(res, map[string]interface{}{
"disks": snap.Disks,
"guid": snap.GUID,
"label": snap.Label,
"timestamp": snap.Timestamp,
"disks": snap.Disks,
"guid": snap.GUID,
"label": snap.Label,
"timestamp": snap.Timestamp,
"memory_dump_image": snap.MemoryDumpImage,
})
}
@@ -174,32 +192,33 @@ func flattenInterfaces(ifaces compute.ListInterfaces) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(ifaces))
for _, iface := range ifaces {
res = append(res, map[string]interface{}{
"bus_number": iface.BusNumber,
"conn_id": iface.ConnID,
"conn_type": iface.ConnType,
"def_gw": iface.DefGW,
"enabled": iface.Enabled,
"enable_secgroups": iface.EnableSecGroups,
"flip_group_id": iface.FLIPGroupID,
"guid": iface.GUID,
"ip_address": iface.IPAddress,
"listen_ssh": iface.ListenSSH,
"mac": iface.MAC,
"mtu": iface.MTU,
"name": iface.Name,
"net_id": iface.NetID,
"netmask": iface.NetMask,
"net_type": iface.NetType,
"node_id": iface.NodeID,
"pci_slot": iface.PCISlot,
"qos": flattenQOS(iface.QOS),
"sdn_interface_id": iface.SDNInterfaceID,
"security_groups": iface.SecGroups,
"target": iface.Target,
"type": iface.Type,
"trunk_tags": iface.TrunkTags,
"vnfs": iface.VNFs,
"libvirt_settings": flattenLibvirtSettings(iface.LibvirtSettings),
"bus_number": iface.BusNumber,
"conn_id": iface.ConnID,
"conn_type": iface.ConnType,
"def_gw": iface.DefGW,
"enabled": iface.Enabled,
"enable_secgroups": iface.EnableSecGroups,
"enable_default_gateway": iface.EnableDefaultGateway,
"flip_group_id": iface.FLIPGroupID,
"guid": iface.GUID,
"ip_address": iface.IPAddress,
"listen_ssh": iface.ListenSSH,
"mac": iface.MAC,
"mtu": iface.MTU,
"name": iface.Name,
"net_id": iface.NetID,
"netmask": iface.NetMask,
"net_type": iface.NetType,
"node_id": iface.NodeID,
"pci_slot": iface.PCISlot,
"qos": flattenQOS(iface.QOS),
"sdn_interface_id": iface.SDNInterfaceID,
"security_groups": iface.SecGroups,
"target": iface.Target,
"type": iface.Type,
"trunk_tags": iface.TrunkTags,
"vnfs": iface.VNFs,
"libvirt_settings": flattenLibvirtSettings(iface.LibvirtSettings),
})
}
return res
@@ -273,6 +292,7 @@ func flattenComputeDisks(disksList compute.ListDisks, disksBlocks, extraDisks []
"pci_slot": disk.PCISlot,
"bus_number": disk.BusNumber,
"pool": disk.Pool,
"read_only": disk.ReadOnly,
"desc": disk.Description,
"image_id": disk.ImageID,
"independent": disk.Independent,
@@ -291,7 +311,7 @@ func flattenComputeDisks(disksList compute.ListDisks, disksBlocks, extraDisks []
"delete_time": disk.DeletedTime,
"update_time": disk.UpdatedTime,
"cache": disk.Cache,
"blk_discard": disk.BLKDiscard,
"discard": disk.Discard,
"block_size": disk.BlockSize,
"provision": disk.Provision,
"iotune": flattenIOTune(disk.IOTune),
@@ -346,6 +366,7 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
"arch": computeItem.Arch,
"auto_start_w_node": computeItem.AutoStart,
"chipset": computeItem.Chipset,
"clock": computeItem.Clock,
"cd_image_id": computeItem.CdImageId,
"boot_order": computeItem.BootOrder,
"boot_image_id": computeItem.BootImageID,
@@ -367,6 +388,7 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
"guid": computeItem.GUID,
"hp_backed": computeItem.HPBacked,
"compute_id": computeItem.ID,
"cpu_alignment_profiles": flattenCPUAlignmentProfile(computeItem.CPUAlignmentProfile),
"cpu_pin": computeItem.CPUPin,
"interfaces": flattenInterfaces(computeItem.Interfaces),
"live_migration_job_id": computeItem.LiveMigrationJobID,
@@ -390,6 +412,7 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
"registered": computeItem.Registered,
"res_name": computeItem.ResName,
"reserved_node_cpus": computeItem.ReservedNodeCpus,
"resized_online": computeItem.ResizedOnline,
"rg_id": computeItem.RGID,
"rg_name": computeItem.RGName,
"snap_sets": flattenSnapSets(computeItem.SnapSets),
@@ -438,6 +461,7 @@ func flattenDeletedComputeList(computes *compute.ListDeletedComputes) []map[stri
"arch": computeItem.Arch,
"auto_start_w_node": computeItem.AutoStart,
"chipset": computeItem.Chipset,
"clock": computeItem.Clock,
"cd_image_id": computeItem.CdImageId,
"boot_order": computeItem.BootOrder,
"bootdisk_size": computeItem.BootDiskSize,
@@ -459,6 +483,7 @@ func flattenDeletedComputeList(computes *compute.ListDeletedComputes) []map[stri
"guid": computeItem.GUID,
"hp_backed": computeItem.HPBacked,
"compute_id": computeItem.ID,
"cpu_alignment_profiles": flattenCPUAlignmentProfile(computeItem.CPUAlignmentProfile),
"cpu_pin": computeItem.CPUPin,
"interfaces": flattenInterfaces(computeItem.Interfaces),
"lock_status": computeItem.LockStatus,
@@ -479,6 +504,7 @@ func flattenDeletedComputeList(computes *compute.ListDeletedComputes) []map[stri
"registered": computeItem.Registered,
"res_name": computeItem.ResName,
"reserved_node_cpus": computeItem.ReservedNodeCpus,
"resized_online": computeItem.ResizedOnline,
"rg_id": computeItem.RGID,
"rg_name": computeItem.RGName,
"snap_sets": flattenSnapSets(computeItem.SnapSets),
@@ -580,7 +606,8 @@ func flattenDisks(disks []compute.InfoDisk) []map[string]interface{} {
// "bus_number": disk.BusNumber,
"disk_id": disk.ID,
// "pci_slot": disk.PCISlot,
"sep_id": disk.SepID,
"sep_id": disk.SepID,
"read_only": disk.ReadOnly,
}
res = append(res, temp)
}
@@ -779,10 +806,12 @@ func flattenDataCompute(d *schema.ResourceData, compFacts *compute.RecordCompute
d.Set("boot_order", compFacts.BootOrder)
d.Set("boot_image_id", compFacts.ImageID)
d.Set("chipset", compFacts.Chipset)
d.Set("clock", compFacts.Clock)
d.Set("cd_image_id", compFacts.CdImageId)
d.Set("clone_reference", compFacts.CloneReference)
d.Set("clones", compFacts.Clones)
d.Set("computeci_id", compFacts.ComputeCIID)
d.Set("cpu_alignment_profiles", flattenCPUAlignmentProfile(compFacts.CPUAlignmentProfile))
d.Set("cpu_pin", compFacts.CPUPin)
d.Set("cpus", compFacts.CPUs)
d.Set("created_by", compFacts.CreatedBy)
@@ -824,6 +853,7 @@ func flattenDataCompute(d *schema.ResourceData, compFacts *compute.RecordCompute
d.Set("registered", compFacts.Registered)
d.Set("res_name", compFacts.ResName)
d.Set("reserved_node_cpus", compFacts.ReservedNodeCpus)
d.Set("resized_online", compFacts.ResizedOnline)
d.Set("rg_id", compFacts.RGID)
d.Set("rg_name", compFacts.RGName)
d.Set("snap_sets", flattenSnapSets(compFacts.SnapSets))
@@ -882,6 +912,7 @@ func parseComputeInterfacesToNetworks(networks []interface{}, ifaces compute.Lis
elem["sdn_interface_id"] = value.SDNInterfaceID
elem["weight"] = flattenNetworkWeight(networks, value.NetID, value.NetType)
elem["enabled"] = value.Enabled
elem["enable_default_gateway"] = value.EnableDefaultGateway
result = append(result, elem)
}
@@ -907,7 +938,7 @@ func flattenDisk(diskList compute.ListDisks) []map[string]interface{} {
"ckey": disk.CKey,
"meta": flattens.FlattenMeta(disk.Meta),
"account_id": disk.AccountID,
"blk_discard": disk.BLKDiscard,
"discard": disk.Discard,
"block_size": disk.BlockSize,
"boot_partition": disk.BootPartition,
"bus_number": disk.BusNumber,
@@ -957,6 +988,7 @@ func flattenDisk(diskList compute.ListDisks) []map[string]interface{} {
"to_clean": disk.ToClean,
"provision": disk.Provision,
"updated_time": disk.UpdatedTime,
"read_only": disk.ReadOnly,
}
res = append(res, temp)
}
@@ -1005,6 +1037,7 @@ func flattendDiskSnapshotList(sl compute.ListDetailedSnapshots) []interface{} {
temp := map[string]interface{}{
"guid": snapshot.GUID,
"label": snapshot.Label,
"pool_name": snapshot.PoolName,
"res_id": snapshot.ResID,
"snap_set_guid": snapshot.SnapSetGUID,
"snap_set_time": snapshot.SnapSetTime,
@@ -1063,3 +1096,193 @@ func flattenQemuQuest(qemuQuest compute.QemuQuest) []map[string]interface{} {
return res
}
func flattenMigrateStorageInfo(d *schema.ResourceData, info *compute.RecordMigrateStorageInfo) {
d.Set("completed", info.Completed)
d.Set("cpu_set", info.CPUSet)
d.Set("daemon_addr", info.DaemonAddr)
d.Set("domain_name", info.DomainName)
d.Set("domain_uuid", info.DomainUUID)
d.Set("elapsed_time", info.ElapsedTime)
d.Set("gid", info.GID)
d.Set("guid", info.GUID)
d.Set("migration_id", info.ID)
d.Set("interfaces", flattenShadowComputeInterfaces(info.Interfaces))
d.Set("log", info.Log)
d.Set("new_disk_xmls", info.NewDiskXmls)
d.Set("new_disks", info.NewDisks)
d.Set("old_disks", info.OldDisks)
d.Set("pid", info.PID)
d.Set("source_node_id", info.SourceNodeID)
d.Set("source_numa_node_id", info.SourceNumaNodeID)
d.Set("source_reserved_node_cpus", info.SourceReservedNodeCpus)
d.Set("source_url", info.SourceURL)
d.Set("status", info.Status)
d.Set("target_shadow_compute", flattenShadowCompute(info.TargetShadowCompute))
d.Set("target_node_id", info.TargetNodeID)
d.Set("target_url", info.TargetURL)
d.Set("vmlog_dir", info.VMLogDir)
}
func flattenShadowCompute(sc compute.ShadowCompute) []map[string]interface{} {
customFields, _ := json.Marshal(sc.CustomFields)
devices, _ := json.Marshal(sc.Devices)
userData, _ := json.Marshal(sc.Userdata)
return []map[string]interface{}{
{
"account_id": sc.AccountID,
"acl": flattenListACLInterface(sc.ACL),
"affinity_label": sc.AffinityLabel,
"affinity_rules": flattenShadowComputeRules(sc.AffinityRules),
"affinity_weight": sc.AffinityWeight,
"anti_affinity_rules": flattenShadowComputeRules(sc.AntiAffinityRules),
"arch": sc.Arch,
"auto_start": sc.AutoStart,
"boot_image_id": sc.BootImageID,
"boot_order": sc.BootOrder,
"boot_type": sc.BootType,
"bootdisk_size": sc.BootDiskSize,
"cd_image_id": sc.CDImageID,
"chipset": sc.Chipset,
"clock": sc.Clock,
"clone_reference": sc.CloneReference,
"clones": sc.Clones,
"computeci_id": sc.ComputeCIID,
"cpu_alignment_profile": flattenCPUAlignmentProfile(sc.CPUAlignmentProfile),
"cpupin": sc.CPUPin,
"cpus": sc.CPUs,
"custom_fields": string(customFields),
"desc": sc.Description,
"devices": string(devices),
"disks": flattenShadowComputeDisks(sc.Disks),
"driver": sc.Driver,
"gid": sc.GID,
"guid": sc.GUID,
"hp_backed": sc.HPBacked,
"hot_resize": sc.HotResize,
"id": sc.ID,
"interfaces": flattenShadowComputeInterfaces(sc.Interfaces),
"live_migration_job_id": sc.LiveMigrationJobID,
"loader_type": sc.LoaderType,
"lock_status": sc.LockStatus,
"manager_id": sc.ManagerID,
"manager_type": sc.ManagerType,
"migrationjob": sc.MigrationJob,
"milestones": sc.Milestones,
"name": sc.Name,
"need_reboot": sc.NeedReboot,
"network_interface_naming": sc.NetworkInterfaceNaming,
"node_id": sc.NodeID,
"numa_affinity": sc.NumaAffinity,
"numa_node_id": sc.NumaNodeID,
"os_users": flattenOSUsers(sc.OSUsers),
"os_version": sc.OSVersion,
"pinned_to_node": sc.PinnedToNode,
"preferred_cpu": sc.PreferredCPU,
"qemu_guest": flattenQemuQuest(sc.QemuGuest),
"read_only": sc.ReadOnly,
"ram": sc.RAM,
"reference_id": sc.ReferenceID,
"reserved_node_cpus": sc.ReservedNodeCpus,
"resized_online": sc.ResizedOnline,
"res_name": sc.ResName,
"rg_id": sc.RGID,
"snap_sets": flattenShadowComputeSnapshots(sc.SnapSets),
"stateless_sep_id": sc.StatelessSEPID,
"stateless_sep_type": sc.StatelessSEPType,
"status": sc.Status,
"tags": flattenTags(sc.Tags),
"tech_status": sc.TechStatus,
"user_managed": sc.UserManaged,
"userdata": string(userData),
"vgpus": sc.VGPUs,
"vnc_passwd": sc.VNCPassword,
"weight": sc.Weight,
"zone_id": sc.ZoneID,
},
}
}
func flattenShadowComputeDisks(disks []compute.ItemShadowComputeDisk) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(disks))
for _, disk := range disks {
res = append(res, map[string]interface{}{
"id": disk.ID,
})
}
return res
}
func flattenShadowComputeInterfaces(ifaces []compute.ItemShadowComputeInterface) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(ifaces))
for _, iface := range ifaces {
res = append(res, map[string]interface{}{
"name": iface.Name,
"target": iface.Target,
"pci_slot": iface.PCISlot,
"bus_number": iface.BusNumber,
"mac": iface.MAC,
"mtu": iface.MTU,
"type": iface.Type,
"conn_type": iface.ConnType,
"conn_id": iface.ConnID,
"flip_group_id": iface.FLIPGroupID,
"net_type": iface.NetType,
"net_id": iface.NetID,
"ip_address": iface.IPAddress,
"net_mask": iface.NetMask,
"def_gw": iface.DefGW,
"vnfs": iface.VNFs,
"qos": flattenQOS(iface.QOS),
"libvirt_settings": flattenLibvirtSettings(iface.LibvirtSettings),
"guid": iface.GUID,
"listen_ssh": iface.ListenSSH,
"enabled": iface.Enabled,
"enable_default_gateway": iface.EnableDefaultGateway,
"node_id": iface.NodeID,
"sdn_interface_id": iface.SDNInterfaceID,
"security_groups": iface.SecGroups,
"enable_secgroups": iface.EnableSecGroups,
"trunk_tags": iface.TrunkTags,
})
}
return res
}
// no guid
func flattenShadowComputeRules(rules compute.ListShadowComputeRules) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(rules))
for _, rule := range rules {
res = append(res, map[string]interface{}{
"key": rule.Key,
"mode": rule.Mode,
"policy": rule.Policy,
"topology": rule.Topology,
"value": rule.Value,
})
}
return res
}
// no compute/memory_dump_image
func flattenShadowComputeSnapshots(snaps compute.ListShadowComputeSnapshots) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(snaps))
for _, snap := range snaps {
res = append(res, map[string]interface{}{
"disks": snap.Disks,
"guid": snap.GUID,
"label": snap.Label,
"timestamp": snap.Timestamp,
})
}
return res
}

View File

@@ -1058,3 +1058,20 @@ func resourceComputeResourceV1() *schema.Resource {
},
}
}
func resourceComputeResourceV2() *schema.Resource {
s := resourceComputeSchemaMake()
// Add blk_discard
s["disks"].Elem.(*schema.Resource).Schema["blk_discard"] = &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
}
// Add boot_disk_blk_discard
s["boot_disk_blk_discard"] = &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
}
return &schema.Resource{Schema: s}
}

View File

@@ -89,12 +89,10 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
createReqX86.ZoneID = uint64(zoneID.(int))
}
if bootDiskBLKDiscard, ok := d.GetOk("boot_disk_blk_discard"); ok {
createReqX86.BootDiskBLKDiscard = bootDiskBLKDiscard.(bool)
if bootDiskDiscard, ok := d.GetOk("boot_disk_discard"); ok {
createReqX86.BootDiskDiscard = bootDiskDiscard.(string)
}
createReqX86.Interfaces = make([]kvmx86.Interface, 0)
if networks, ok := d.GetOk("network"); ok {
if networks.(*schema.Set).Len() > 0 {
ns := networks.(*schema.Set).List()
@@ -122,6 +120,10 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
reqInterface.Enabled = netInterfaceVal["enabled"].(bool)
}
if reqInterface.NetType == "VINS" {
reqInterface.EnableDefaultGateway = netInterfaceVal["enable_default_gateway"].(bool)
}
if reqInterface.NetType == "DPDK" || reqInterface.NetType == "EXTNET" || reqInterface.NetType == "TRUNK" {
reqInterface.MTU = uint64(netInterfaceVal["mtu"].(int))
}
@@ -179,8 +181,8 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
if cache, ok := diskVal["cache"]; ok {
reqDataDisk.Cache = cache.(string)
}
if blkDiscard, ok := diskVal["blk_discard"]; ok {
reqDataDisk.BLKDiscard = blkDiscard.(bool)
if discard, ok := diskVal["discard"]; ok {
reqDataDisk.Discard = discard.(string)
}
disksX86 = append(disksX86, reqDataDisk)
}
@@ -227,6 +229,9 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
createReqX86.CPUPin = d.Get("cpu_pin").(bool)
createReqX86.HPBacked = d.Get("hp_backed").(bool)
createReqX86.Chipset = d.Get("chipset").(string)
if clock, ok := d.GetOk("clock"); ok {
createReqX86.Clock = clock.(string)
}
if preferredCPU, ok := d.GetOk("preferred_cpu"); ok {
preferredList := preferredCPU.([]interface{})
@@ -527,6 +532,17 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if profileName, ok := d.GetOk("cpu_alignment_profile"); ok {
req := compute.SetCPUAlignmentProfileRequest{
ComputeIDs: []int64{int64(computeId)},
CPUAlignmentProfile: profileName.(string),
}
_, err := c.CloudBroker().Compute().SetCPUAlignmentProfile(ctx, req)
if err != nil {
warnings.Add(err)
}
}
if ars, ok := d.GetOk("affinity_rules"); ok {
log.Debugf("resourceComputeCreate: Create affinity rules on ComputeID: %d", computeId)
addedAR := ars.([]interface{})
@@ -872,8 +888,8 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if d.HasChange("boot_disk_blk_discard") {
if err := utilityComputeUpdateBootDiskBLKDiscard(ctx, d, m); err != nil {
if d.HasChange("boot_disk_discard") {
if err := utilityComputeUpdateBootDiskDiscard(ctx, d, m); err != nil {
return diag.FromErr(err)
}
}
@@ -893,6 +909,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
if d.HasChanges("description",
"name",
"clock",
"numa_affinity",
"cpu_pin",
"hp_backed",
@@ -1026,6 +1043,12 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if d.HasChange("cpu_alignment_profile") {
if err := utilityComputeUpdateCPUAlignmentProfile(ctx, d, m); err != nil {
return diag.FromErr(err)
}
}
return append(resourceComputeRead(ctx, d, m), warnings.Get()...)
}
@@ -1057,7 +1080,7 @@ func resourceComputeDelete(ctx context.Context, d *schema.ResourceData, m interf
func ResourceCompute() *schema.Resource {
return &schema.Resource{
SchemaVersion: 2,
SchemaVersion: 3,
CustomizeDiff: func(ctx context.Context, diff *schema.ResourceDiff, i interface{}) error {
if diff.HasChanges() || diff.HasChanges("chipset", "pin_to_node", "auto_start_w_node", "libvirt_settings", "network", "affinity_rules", "anti_affinity_rules",
@@ -1100,6 +1123,11 @@ func ResourceCompute() *schema.Resource {
Upgrade: resourceCompueteStateUpgradeV1,
Version: 1,
},
{
Type: resourceComputeResourceV2().CoreConfigSchema().ImpliedType(),
Upgrade: resourceComputeStateUpgradeV2,
Version: 2,
},
},
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -18,3 +18,33 @@ func resourceCompueteStateUpgradeV1(ctx context.Context, rawState map[string]int
return rawState, nil
}
func resourceComputeStateUpgradeV2(ctx context.Context, rawState map[string]interface{}, meta any) (map[string]interface{}, error) {
log.Debug("resourceComputeStateUpgradeV2: upgrading state")
if v, ok := rawState["boot_disk_blk_discard"].(bool); ok {
if v {
rawState["boot_disk_discard"] = "unmap"
} else {
rawState["boot_disk_discard"] = "ignore"
}
}
delete(rawState, "boot_disk_blk_discard")
if disks, ok := rawState["disks"].([]interface{}); ok {
for _, d := range disks {
if disk, ok := d.(map[string]interface{}); ok {
if v, ok := disk["blk_discard"].(bool); ok {
if v {
disk["discard"] = "unmap"
} else {
disk["discard"] = "ignore"
}
}
delete(disk, "blk_discard")
}
}
}
return rawState, nil
}

View File

@@ -265,7 +265,7 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
renamedDisks := make([]interface{}, 0)
changeStoragePolicyDisks := make([]interface{}, 0)
cacheUpdatedDisks := make([]interface{}, 0)
blkDiscardUpdatedDisks := make([]interface{}, 0)
discardUpdatedDisks := make([]interface{}, 0)
blockSizeUpdatedDisks := make([]interface{}, 0)
iotuneUpdatedDisks := make([]interface{}, 0)
migratedDisks := make([]interface{}, 0)
@@ -325,8 +325,8 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
cacheUpdatedDisks = append(cacheUpdatedDisks, el)
}
if isChangeBLKDiscardDisk(oldConv, el) {
blkDiscardUpdatedDisks = append(blkDiscardUpdatedDisks, el)
if isChangeDiscardDisk(oldConv, el) {
discardUpdatedDisks = append(discardUpdatedDisks, el)
}
if isChangeBlockSizeDisk(oldConv, el) {
@@ -382,6 +382,9 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
if cacheVal, ok := diskConv["cache"].(string); ok {
req.Cache = cacheVal
}
if readOnly, ok := diskConv["read_only"].(bool); ok {
req.ReadOnly = readOnly
}
diskID, err := c.CloudBroker().Compute().DiskAdd(ctx, req)
if err != nil {
return err
@@ -515,8 +518,8 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
}
}
if len(blkDiscardUpdatedDisks) > 0 {
for _, disk := range blkDiscardUpdatedDisks {
if len(discardUpdatedDisks) > 0 {
for _, disk := range discardUpdatedDisks {
diskConv := disk.(map[string]interface{})
if isBootDisk(diskConv, chipset) {
continue
@@ -528,8 +531,8 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
}
req := disks.UpdateRequest{
DiskID: diskID,
BLKDiscard: diskConv["blk_discard"].(bool),
DiskID: diskID,
Discard: diskConv["discard"].(string),
}
_, err := c.CloudBroker().Disks().Update(ctx, req)
if err != nil {
@@ -672,10 +675,10 @@ func utilityComputeUpdateBootDiskCache(ctx context.Context, d *schema.ResourceDa
return err
}
func utilityComputeUpdateBootDiskBLKDiscard(ctx context.Context, d *schema.ResourceData, m interface{}) error {
func utilityComputeUpdateBootDiskDiscard(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
newBLKDiscard := d.Get("boot_disk_blk_discard").(bool)
newDiscard := d.Get("boot_disk_discard").(string)
var bootDiskID uint64
if v, ok := d.GetOk("boot_disk_id"); ok {
@@ -685,12 +688,12 @@ func utilityComputeUpdateBootDiskBLKDiscard(ctx context.Context, d *schema.Resou
}
if bootDiskID == 0 {
return fmt.Errorf("cannot update boot_disk_cache: boot disk ID is unknown for compute %s", d.Id())
return fmt.Errorf("cannot update boot_disk_discard: boot disk ID is unknown for compute %s", d.Id())
}
req := disks.UpdateRequest{
DiskID: bootDiskID,
BLKDiscard: newBLKDiscard,
DiskID: bootDiskID,
Discard: newDiscard,
}
_, err := c.CloudBroker().Disks().Update(ctx, req)
@@ -980,6 +983,10 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
req.SDNInterfaceID = netData["sdn_interface_id"].(string)
}
if req.NetType == "VINS" {
req.EnableDefaultGateway = netData["enable_default_gateway"].(bool)
}
_, err := c.CloudBroker().Compute().NetAttach(ctx, req)
if err != nil {
log.Errorf("utilityComputeNetworksConfigure: failed to attach net ID %d of type %s to Compute ID %s: %s",
@@ -1304,6 +1311,9 @@ func utilityComputeUpdate(ctx context.Context, d *schema.ResourceData, m interfa
if d.HasChange("chipset") {
req.Chipset = d.Get("chipset").(string)
}
if d.HasChange("clock") {
req.Clock = d.Get("clock").(string)
}
if d.HasChange("loader_type") {
req.LoaderType = d.Get("loader_type").(string)
@@ -1349,10 +1359,10 @@ func utilityComputeUpdate(ctx context.Context, d *schema.ResourceData, m interfa
}
}
// Note bene: numa_affinity, cpu_pin and hp_backed are not allowed to be changed for compute in STARTED tech status.
// Note bene: numa_affinity, cpu_pin, hp_backed and clock are not allowed to be changed for compute in STARTED tech status.
// If STARTED, we need to stop it before update
var isStopRequired bool
if d.HasChanges("numa_affinity", "cpu_pin", "hp_backed", "chipset", "preferred_cpu", "hot_resize") && d.Get("started").(bool) {
if d.HasChanges("numa_affinity", "cpu_pin", "hp_backed", "chipset", "preferred_cpu", "hot_resize", "clock") && d.Get("started").(bool) {
isStopRequired = true
}
if isStopRequired {
@@ -2308,12 +2318,12 @@ func isChangeCacheDisk(els []interface{}, el interface{}) bool {
return false
}
func isChangeBLKDiscardDisk(els []interface{}, el interface{}) bool {
func isChangeDiscardDisk(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["blk_discard"].(bool) != elConv["blk_discard"].(bool) {
elOldConv["discard"].(string) != elConv["discard"].(string) {
return true
}
}

View File

@@ -0,0 +1,71 @@
/*
Copyright (c) 2019-2023 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 kvmvm
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityComputeUpdateCPUAlignmentProfile(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
profileName := d.Get("cpu_alignment_profile").(string)
if profileName == "" {
req := compute.DeleteCPUAlignmentProfileRequest{
ComputeIDs: []uint64{computeId},
}
_, err := c.CloudBroker().Compute().DeleteCPUAlignmentProfile(ctx, req)
return err
}
req := compute.SetCPUAlignmentProfileRequest{
ComputeIDs: []int64{int64(computeId)},
CPUAlignmentProfile: profileName,
}
_, err := c.CloudBroker().Compute().SetCPUAlignmentProfile(ctx, req)
return err
}
func utilityComputeGetCPUAlignmentProfile(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.CPUAlignmentProfile, error) {
c := m.(*controller.ControllerCfg)
req := compute.GetCPUAlignmentProfileRequest{
ComputeID: uint64(d.Get("compute_id").(int)),
}
return c.CloudBroker().Compute().GetCPUAlignmentProfile(ctx, req)
}

View File

@@ -40,16 +40,11 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityComputeMigrateStorageInfoCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
func utilityComputeMigrateStorageInfoCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.RecordMigrateStorageInfo, error) {
c := m.(*controller.ControllerCfg)
req := compute.MigrateStorageInfoRequest{
ComputeID: uint64(d.Get("compute_id").(int)),
}
result, err := c.CloudBroker().Compute().MigrateStorageInfo(ctx, req)
if err != nil {
return "", err
}
return result, nil
return c.CloudBroker().Compute().MigrateStorageInfo(ctx, req)
}

View File

@@ -0,0 +1,355 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Sergey Kisil, <svkisil@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 node
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/decort-golang-sdk/pkg/cloudbroker/node"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func dataSourceNodeNetworkInfoRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*controller.ControllerCfg)
req := node.GetNetworkInfoRequest{
NodeID: uint64(d.Get("node_id").(int)),
}
info, err := c.CloudBroker().Node().GetNetworkInfo(ctx, req)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("system_networks_info", flattenSystemNetworksInfo(info.SystemNetworksInfo))
d.Set("ovs_networks_info", flattenOVSNetworksInfo(info.OVSNetworksInfo))
d.Set("libvirt_networks_info", flattenLibvirtNetworksInfo(info.LibvirtNetworksInfo))
d.Set("topology", flattenNetworkTopology(info.Topology))
return nil
}
func dataSourceNodeNetworkInfoSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"node_id": {
Type: schema.TypeInt,
Required: true,
Description: "Node ID",
},
"system_networks_info": {
Type: schema.TypeList,
Computed: true,
Description: "System-level information about all network interfaces on the node",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Interface name",
},
"mtu": {
Type: schema.TypeInt,
Computed: true,
Description: "MTU value",
},
"speed": {
Type: schema.TypeInt,
Computed: true,
Description: "Interface link speed",
},
"bridge_id": {
Type: schema.TypeString,
Computed: true,
Description: "Linux bridge ID",
},
"bport_id": {
Type: schema.TypeString,
Computed: true,
Description: "Bridge port ID",
},
"mac": {
Type: schema.TypeString,
Computed: true,
Description: "MAC address",
},
},
},
},
"ovs_networks_info": {
Type: schema.TypeList,
Computed: true,
Description: "Raw OVS ports data",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"bridge_name": {
Type: schema.TypeString,
Computed: true,
Description: "Bridge name",
},
"bridge_tag": {
Type: schema.TypeString,
Computed: true,
Description: "Bridge tag",
},
"interface_uuid": {
Type: schema.TypeString,
Computed: true,
Description: "Interface UUID",
},
"interface_type": {
Type: schema.TypeString,
Computed: true,
Description: "Interface type",
},
"interface_name": {
Type: schema.TypeString,
Computed: true,
Description: "Interface name",
},
"interface_mtu": {
Type: schema.TypeInt,
Computed: true,
Description: "Interface MTU value",
},
"interface_ip": {
Type: schema.TypeString,
Computed: true,
Description: "Interface IP address",
},
"interface_mac": {
Type: schema.TypeString,
Computed: true,
Description: "Interface MAC address",
},
"interface_peer": {
Type: schema.TypeString,
Computed: true,
Description: "Interface peer name",
},
},
},
},
"libvirt_networks_info": {
Type: schema.TypeList,
Computed: true,
Description: "VM network interface connections",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"vm_name": {
Type: schema.TypeString,
Computed: true,
Description: "VM name",
},
"interface": {
Type: schema.TypeString,
Computed: true,
Description: "Host-side interface name used by the VM",
},
"interface_type": {
Type: schema.TypeString,
Computed: true,
Description: "Interface type",
},
"interface_source": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the bridge the VM interface is attached to",
},
},
},
},
"topology": {
Type: schema.TypeList,
Computed: true,
Description: "Assembled network topology of the node",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"interfaces": {
Type: schema.TypeList,
Computed: true,
Description: "Network interfaces and their topology details",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Interface name",
},
"type": {
Type: schema.TypeString,
Computed: true,
Description: "Interface type",
},
"mtu": {
Type: schema.TypeInt,
Computed: true,
Description: "Interface MTU value",
},
"speed": {
Type: schema.TypeInt,
Computed: true,
Description: "Interface link speed",
},
"vlans": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "VLANs associated with the interface",
},
"bridge_id": {
Type: schema.TypeString,
Computed: true,
Description: "Linux bridge ID",
},
"peer": {
Type: schema.TypeString,
Computed: true,
Description: "Peer interface name",
},
"uuid": {
Type: schema.TypeString,
Computed: true,
Description: "OVS UUID",
},
"connected_interfaces": {
Type: schema.TypeList,
Computed: true, Elem: &schema.Schema{Type: schema.TypeString},
Description: "Names of interfaces attached to this bridge as ports",
},
"connections": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"vms": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {Type: schema.TypeString, Computed: true},
"vm_interface": {Type: schema.TypeString, Computed: true},
"vm_interface_type": {Type: schema.TypeString, Computed: true},
"connection_type": {Type: schema.TypeString, Computed: true},
"via_bridge": {Type: schema.TypeString, Computed: true},
},
},
},
"bridges": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {Type: schema.TypeString, Computed: true},
"type": {Type: schema.TypeString, Computed: true},
"via": {Type: schema.TypeString, Computed: true},
"bport_id": {Type: schema.TypeString, Computed: true},
"port_info": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {Type: schema.TypeString, Computed: true},
"type": {Type: schema.TypeString, Computed: true},
"mtu": {Type: schema.TypeInt, Computed: true},
"vlan": {Type: schema.TypeString, Computed: true},
"uuid": {Type: schema.TypeString, Computed: true},
},
},
},
},
},
},
},
},
},
"bridge_info": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {Type: schema.TypeString, Computed: true},
"ports": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {Type: schema.TypeString, Computed: true},
"type": {Type: schema.TypeString, Computed: true},
"mtu": {Type: schema.TypeInt, Computed: true},
"vlan": {Type: schema.TypeString, Computed: true},
"uuid": {Type: schema.TypeString, Computed: true},
"ip": {Type: schema.TypeString, Computed: true},
"mac": {Type: schema.TypeString, Computed: true},
},
},
},
},
},
},
"bridge_connections": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {Type: schema.TypeString, Computed: true},
"via": {Type: schema.TypeString, Computed: true},
"vlan": {Type: schema.TypeString, Computed: true},
},
},
},
},
},
},
},
},
},
}
}
func DataSourceNodeNetworkInfo() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceNodeNetworkInfoRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceNodeNetworkInfoSchemaMake(),
}
}

View File

@@ -0,0 +1,172 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Sergey Kisil, <svkisil@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 node
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
sdknode "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/node"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func dataSourceNodePCIDevicesRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*controller.ControllerCfg)
req := sdknode.GetPCIDevicesRequest{
NodeID: uint64(d.Get("node_id").(int)),
}
if v, ok := d.GetOk("search"); ok {
req.Search = v.(string)
}
if v, ok := d.GetOk("sort_by"); ok {
req.SortBy = v.(string)
}
if v, ok := d.GetOk("page"); ok {
req.Page = uint64(v.(int))
}
if v, ok := d.GetOk("size"); ok {
req.Size = uint64(v.(int))
}
list, err := c.CloudBroker().Node().GetPCIDevices(ctx, req)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenNodePCIDevices(list.Data))
d.Set("entry_count", list.EntryCount)
return nil
}
func dataSourceNodePCIDevicesSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"node_id": {
Type: schema.TypeInt,
Required: true,
Description: "Node ID",
},
"search": {
Type: schema.TypeString,
Optional: true,
Description: "Search string",
},
"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",
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
Description: "Total number of PCI devices",
},
"items": {
Type: schema.TypeList,
Computed: true,
Description: "List of PCI devices",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"hw_path": {
Type: schema.TypeString,
Computed: true,
Description: "Hardware path",
},
"current_driver": {
Type: schema.TypeString,
Computed: true,
Description: "Current driver",
},
"numa_node": {
Type: schema.TypeInt,
Computed: true,
Description: "NUMA node",
},
"product_id": {
Type: schema.TypeString,
Computed: true,
Description: "Product ID",
},
"product_name": {
Type: schema.TypeString,
Computed: true,
Description: "Product name",
},
"vendor_id": {
Type: schema.TypeString,
Computed: true,
Description: "Vendor ID",
},
"vendor_name": {
Type: schema.TypeString,
Computed: true,
Description: "Vendor name",
},
"iommu_group": {
Type: schema.TypeInt,
Computed: true,
Description: "IOMMU group",
},
},
},
},
}
}
func DataSourceNodePCIDevices() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceNodePCIDevicesRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceNodePCIDevicesSchemaMake(),
}
}

View File

@@ -62,6 +62,8 @@ func flattenNode(d *schema.ResourceData, item *node.RecordNode) {
d.Set("nic_info", flattenNicInfo(item.NicInfo))
d.Set("numa_topology", flattenNumaTopology(item.NumaTopology))
d.Set("reserved_cpus", flattenNodeItem(item.ReservedCPUs))
d.Set("reserved_cpu", item.ReservedCPU)
d.Set("reserved_ram", item.ReservedRAM)
d.Set("roles", item.Roles)
d.Set("sdn_hypervisor_name", item.SDNHypervisorName)
d.Set("sriov_enabled", item.SriovEnabled)
@@ -135,6 +137,7 @@ func flattenNodeList(nodes *node.ListNodes) []map[string]interface{} {
"ipaddr": item.IPAddr,
"isolated_cpus": flattenNodeItem(item.IsolatedCpus),
"lastcheck": item.LastCheck,
"machine_id": item.MachineID,
"machine_guid": item.MachineGUID,
"mainboard_sn": item.MainboardSN,
"memory": item.Memory,
@@ -154,6 +157,8 @@ func flattenNodeList(nodes *node.ListNodes) []map[string]interface{} {
"public_keys": item.PublicKeys,
"release": item.Release,
"reserved_cpus": flattenNodeItem(item.ReservedCPUs),
"reserved_cpu": int(item.ReservedCPU),
"reserved_ram": int(item.ReservedRAM),
"roles": item.Roles,
"sdn_hypervisor_name": item.SDNHypervisorName,
"seps": item.Seps,
@@ -173,6 +178,7 @@ func flattenNodeList(nodes *node.ListNodes) []map[string]interface{} {
"cpu_allocation_ratio": item.CPUAllocationRatio,
"mem_allocation_ratio": item.MemAllocationRatio,
"packages": flattenPackages(item.Packages),
"pci_devices": flattenNodePCIDevices(item.PCIDevices),
}
res = append(res, temp)
}
@@ -188,9 +194,18 @@ func flattenNumaTopology(info node.NumaTopologyInfo) []map[string]interface{} {
for _, item := range info.Nodes {
memoryTemp := []map[string]interface{}{
{
"one_g": item.Memory.OneG,
"two_m": item.Memory.TwoM,
"total": item.Memory.Total,
"one_g": item.Memory.OneG,
"one_g_free": item.Memory.OneGFree,
"one_g_reserved": item.Memory.OneGReserved,
"one_g_available": item.Memory.OneGAvailable,
"one_g_used": item.Memory.OneGUsed,
"one_g_dpdk_reserved": item.Memory.OneGDPDKReserved,
"two_m": item.Memory.TwoM,
"two_m_free": item.Memory.TwoMFree,
"two_m_reserved": item.Memory.TwoMReserved,
"two_m_available": item.Memory.TwoMAvailable,
"two_m_used": item.Memory.TwoMUsed,
"total": item.Memory.Total,
},
}
temp := map[string]interface{}{
@@ -321,9 +336,9 @@ func flattenDPDKItem(dpdk node.DPDK) []map[string]interface{} {
}
res[0] = map[string]interface{}{
"bridges": bridges,
"hp_memory": dpdk.HPMemory,
"pmd_cpu": dpdk.PMDCPU,
"bridges": bridges,
"ovs_dpdk_cores": dpdk.OVSDPDKCores,
"hp_memory": dpdk.HPMemory,
}
return res
@@ -339,3 +354,178 @@ func flattenRole(role node.Role) []map[string]interface{} {
res[0] = temp
return res
}
func flattenSystemNetworksInfo(m map[string]node.SystemNetworkInfo) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(m))
for name, info := range m {
res = append(res, map[string]interface{}{
"name": name,
"mtu": info.MTU,
"speed": info.Speed,
"bridge_id": info.BridgeID,
"bport_id": info.BPortID,
"mac": info.MAC,
})
}
return res
}
func flattenOVSNetworksInfo(items []node.OVSNetworkInfo) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(items))
for _, item := range items {
res = append(res, map[string]interface{}{
"bridge_name": item.BridgeName,
"bridge_tag": item.BridgeTag,
"interface_uuid": item.InterfaceUUID,
"interface_type": item.InterfaceType,
"interface_name": item.InterfaceName,
"interface_mtu": item.InterfaceMTU,
"interface_ip": item.InterfaceIP,
"interface_mac": item.InterfaceMAC,
"interface_peer": item.InterfacePeer,
})
}
return res
}
func flattenLibvirtNetworksInfo(items []node.LibvirtNetworkInfo) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(items))
for _, item := range items {
res = append(res, map[string]interface{}{
"vm_name": item.VMName,
"interface": item.Interface,
"interface_type": item.InterfaceType,
"interface_source": item.InterfaceSource,
})
}
return res
}
func flattenNetworkTopology(t node.NetworkTopology) []map[string]interface{} {
return []map[string]interface{}{
{
"interfaces": flattenTopologyInterfaces(t.Interfaces),
},
}
}
func flattenTopologyInterfaces(m map[string]node.TopologyInterface) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(m))
for name, iface := range m {
res = append(res, map[string]interface{}{
"name": name,
"type": iface.Type,
"mtu": iface.MTU,
"speed": iface.Speed,
"vlans": iface.VLANs,
"bridge_id": iface.BridgeID,
"peer": iface.Peer,
"uuid": iface.UUID,
"connected_interfaces": iface.ConnectedInterfaces,
"connections": flattenTopologyConnections(iface.Connections),
"bridge_info": flattenTopologyBridgeInfo(iface.BridgeInfo),
"bridge_connections": flattenTopologyBridgeRefs(iface.BridgeConnections),
})
}
return res
}
func flattenTopologyConnections(c node.TopologyInterfaceConnections) []map[string]interface{} {
vms := make([]map[string]interface{}, 0, len(c.VMs))
for _, vm := range c.VMs {
vms = append(vms, map[string]interface{}{
"name": vm.Name,
"vm_interface": vm.VMInterface,
"vm_interface_type": vm.VMInterfaceType,
"connection_type": vm.ConnectionType,
"via_bridge": vm.ViaBridge,
})
}
bridges := make([]map[string]interface{}, 0, len(c.Bridges))
for _, b := range c.Bridges {
portInfo := flattenTopologyPortInfo(b.PortInfo)
bridges = append(bridges, map[string]interface{}{
"name": b.Name,
"type": b.Type,
"via": b.Via,
"bport_id": b.BPortID,
"port_info": portInfo,
})
}
return []map[string]interface{}{
{
"vms": vms,
"bridges": bridges,
},
}
}
func flattenTopologyPortInfo(p *node.TopologyPortInfo) []map[string]interface{} {
if p == nil {
return nil
}
return []map[string]interface{}{
{
"name": p.Name,
"type": p.Type,
"mtu": p.MTU,
"vlan": p.VLAN,
"uuid": p.UUID,
},
}
}
func flattenTopologyBridgeInfo(b *node.TopologyBridgeInfo) []map[string]interface{} {
if b == nil {
return nil
}
ports := make([]map[string]interface{}, 0, len(b.Ports))
for _, p := range b.Ports {
ports = append(ports, map[string]interface{}{
"name": p.Name,
"type": p.Type,
"mtu": p.MTU,
"vlan": p.VLAN,
"uuid": p.UUID,
"ip": p.IP,
"mac": p.MAC,
})
}
return []map[string]interface{}{
{
"type": b.Type,
"ports": ports,
},
}
}
func flattenTopologyBridgeRefs(refs []node.TopologyBridgeRef) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(refs))
for _, r := range refs {
res = append(res, map[string]interface{}{
"name": r.Name,
"via": r.Via,
"vlan": r.VLAN,
})
}
return res
}
func flattenNodePCIDevices(items []node.ItemPCIDevice) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(items))
for _, item := range items {
res = append(res, map[string]interface{}{
"hw_path": item.HWPath,
"current_driver": item.CurrentDriver,
"numa_node": item.NUMANode,
"product_id": item.ProductID,
"product_name": item.ProductName,
"vendor_id": item.VendorID,
"vendor_name": item.VendorName,
"iommu_group": item.IOMMUGroup,
})
}
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.TypeFloat,
Type: schema.TypeInt,
Computed: true,
},
"ram": {
@@ -129,11 +129,11 @@ func dataSourceNodeSchemaMake() map[string]*schema.Schema {
},
},
"cpu_allocation_ratio": {
Type: schema.TypeFloat,
Type: schema.TypeInt,
Computed: true,
},
"mem_allocation_ratio": {
Type: schema.TypeFloat,
Type: schema.TypeInt,
Computed: true,
},
"description": {
@@ -172,15 +172,15 @@ func dataSourceNodeSchemaMake() map[string]*schema.Schema {
},
},
},
"hp_memory": {
Type: schema.TypeMap,
"ovs_dpdk_cores": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"pmd_cpu": {
Type: schema.TypeList,
"hp_memory": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
@@ -331,10 +331,46 @@ func dataSourceNodeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"one_g_free": {
Type: schema.TypeInt,
Computed: true,
},
"one_g_reserved": {
Type: schema.TypeInt,
Computed: true,
},
"one_g_available": {
Type: schema.TypeInt,
Computed: true,
},
"one_g_used": {
Type: schema.TypeInt,
Computed: true,
},
"one_g_dpdk_reserved": {
Type: schema.TypeInt,
Computed: true,
},
"two_m": {
Type: schema.TypeInt,
Computed: true,
},
"two_m_free": {
Type: schema.TypeInt,
Computed: true,
},
"two_m_reserved": {
Type: schema.TypeInt,
Computed: true,
},
"two_m_available": {
Type: schema.TypeInt,
Computed: true,
},
"two_m_used": {
Type: schema.TypeInt,
Computed: true,
},
"total": {
Type: schema.TypeInt,
Computed: true,
@@ -355,6 +391,14 @@ func dataSourceNodeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
},
},
"reserved_cpu": {
Type: schema.TypeInt,
Computed: true,
},
"reserved_ram": {
Type: schema.TypeInt,
Computed: true,
},
"roles": {
Type: schema.TypeList,
Computed: true,
@@ -548,7 +592,7 @@ func dataSourceNodeListSchemaMake() map[string]*schema.Schema {
Computed: true,
},
"cpu_allocation_ratio": {
Type: schema.TypeFloat,
Type: schema.TypeInt,
Computed: true,
},
"cpu_info": {
@@ -629,15 +673,15 @@ func dataSourceNodeListSchemaMake() map[string]*schema.Schema {
},
},
},
"hp_memory": {
Type: schema.TypeMap,
"ovs_dpdk_cores": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"pmd_cpu": {
Type: schema.TypeList,
"hp_memory": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
@@ -680,6 +724,10 @@ func dataSourceNodeListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"machine_id": {
Type: schema.TypeString,
Computed: true,
},
"machine_guid": {
Type: schema.TypeString,
Computed: true,
@@ -689,7 +737,7 @@ func dataSourceNodeListSchemaMake() map[string]*schema.Schema {
Computed: true,
},
"mem_allocation_ratio": {
Type: schema.TypeFloat,
Type: schema.TypeInt,
Computed: true,
},
"memory": {
@@ -848,10 +896,46 @@ func dataSourceNodeListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"one_g_free": {
Type: schema.TypeInt,
Computed: true,
},
"one_g_reserved": {
Type: schema.TypeInt,
Computed: true,
},
"one_g_available": {
Type: schema.TypeInt,
Computed: true,
},
"one_g_used": {
Type: schema.TypeInt,
Computed: true,
},
"one_g_dpdk_reserved": {
Type: schema.TypeInt,
Computed: true,
},
"two_m": {
Type: schema.TypeInt,
Computed: true,
},
"two_m_free": {
Type: schema.TypeInt,
Computed: true,
},
"two_m_reserved": {
Type: schema.TypeInt,
Computed: true,
},
"two_m_available": {
Type: schema.TypeInt,
Computed: true,
},
"two_m_used": {
Type: schema.TypeInt,
Computed: true,
},
"total": {
Type: schema.TypeInt,
Computed: true,
@@ -918,6 +1002,14 @@ func dataSourceNodeListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
},
},
"reserved_cpu": {
Type: schema.TypeInt,
Computed: true,
},
"reserved_ram": {
Type: schema.TypeInt,
Computed: true,
},
"roles": {
Type: schema.TypeList,
Computed: true,
@@ -978,6 +1070,46 @@ func dataSourceNodeListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"pci_devices": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"hw_path": {
Type: schema.TypeString,
Computed: true,
},
"current_driver": {
Type: schema.TypeString,
Computed: true,
},
"numa_node": {
Type: schema.TypeInt,
Computed: true,
},
"product_id": {
Type: schema.TypeString,
Computed: true,
},
"product_name": {
Type: schema.TypeString,
Computed: true,
},
"vendor_id": {
Type: schema.TypeString,
Computed: true,
},
"vendor_name": {
Type: schema.TypeString,
Computed: true,
},
"iommu_group": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
},
},
},

View File

@@ -25,6 +25,8 @@ func DataSourceRgAudits() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
DeprecationMessage: "This data source is deprecated and will be removed in version 4.14.0; use decort_cb_audit_list instead.",
ReadContext: dataSourceRgAuditsRead,
Timeouts: &schema.ResourceTimeout{

View File

@@ -0,0 +1,386 @@
package rg
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func resourceRGV1() *schema.Resource {
return &schema.Resource{Schema: resourceRgSchemaMakeV1()}
}
func resourceRgSchemaMakeV1() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"account_id": {
Type: schema.TypeInt,
Required: true,
ValidateFunc: validation.IntAtLeast(1),
Description: "Unique ID of the account, which this resource group belongs to.",
},
"gid": {
Type: schema.TypeInt,
Required: true,
Description: "Unique ID of the grid, where this resource group is deployed.",
},
"rg_name": {
Type: schema.TypeString,
Required: true,
Description: "Name of this resource group. Names are case sensitive and unique within the context of a account.",
},
"resource_limits": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cu_c": {
Type: schema.TypeFloat,
Optional: true,
Computed: true,
Description: "MaxCPUCapacity",
},
"cu_d": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_dm": {
Type: schema.TypeFloat,
Optional: true,
Computed: true,
Description: "MaxVDiskCapacity",
},
"cu_i": {
Type: schema.TypeFloat,
Optional: true,
Computed: true,
Description: "MaxNumPublicIP",
},
"cu_m": {
Type: schema.TypeFloat,
Optional: true,
Computed: true,
Description: "MaxMemoryCapacity",
},
"gpu_units": {
Type: schema.TypeFloat,
Computed: true,
},
"storage_policy": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
},
"limit": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
},
},
},
"owner": {
Type: schema.TypeString,
Optional: true,
Description: "username - owner of this RG. Leave blank to set current user as owner",
},
"def_net_type": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"PRIVATE", "PUBLIC", "NONE"}, false),
Description: "Type of the network, which this resource group will use as default for its computes - PRIVATE or PUBLIC or NONE.",
},
"ipcidr": {
Type: schema.TypeString,
Optional: true,
Description: "Address of the netowrk inside the private network segment (aka ViNS) if def_net_type=PRIVATE",
},
"description": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "User-defined text description of this resource group.",
},
"ext_net_id": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Description: "ID of the external network for default ViNS. Pass 0 if def_net_type=PUBLIC or no external connection required for the defult ViNS when def_net_type=PRIVATE",
},
"ext_ip": {
Type: schema.TypeString,
Optional: true,
Description: "IP address on the external netowrk to request when def_net_type=PRIVATE and ext_net_id is not 0",
},
"uniq_pools": {
Type: schema.TypeList,
Computed: true,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"access": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"user": {
Type: schema.TypeString,
Required: true,
Description: "User or group name to grant access",
},
"right": {
Type: schema.TypeString,
Required: true,
Description: "Access rights to set, one of 'R', 'RCX' or 'ARCXDU'",
},
},
},
},
"def_net": {
Type: schema.TypeSet,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"net_type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"PRIVATE", "PUBLIC"}, false),
Description: "Network type to set. Must be on of 'PRIVATE' or 'PUBLIC'.",
},
"net_id": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Description: "Network segment ID. If netType is PUBLIC and netId is 0 then default external network segment will be selected. If netType is PRIVATE and netId=0, the first ViNS defined for this RG will be selected. Otherwise, netId identifies either existing external network segment or ViNS.",
},
},
},
},
"cpu_allocation_parameter": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "set cpu allocation parameter",
},
"cpu_allocation_ratio": {
Type: schema.TypeFloat,
Optional: true,
Computed: true,
Description: "set cpu allocation ratio",
},
"enable": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "enable/disable rg",
},
"restore": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "restore deleted rg",
},
"force": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "flag to force deleting resource group",
},
"permanently": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "flag to permanently delete resource group",
},
"compute_features": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{"hugepages", "numa", "cpupin", "vfnic", "dpdk", "changemac", "trunk"}, true),
},
},
"sdn_access_group_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "ID of the SDN access group",
},
"storage_policy": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Required: true,
},
"limit": {
Type: schema.TypeInt,
Optional: true,
Default: -1,
},
},
},
},
"acl": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"email": {
Type: schema.TypeString,
Computed: true,
},
"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,
},
},
},
},
"account_name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the account, which this resource group belongs to.",
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"def_net_id": {
Type: schema.TypeInt,
Computed: true,
Description: "ID of the default network for this resource group (if any).",
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
},
"lock_status": {
Type: schema.TypeString,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"resource_types": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"secret": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "Current status of this resource group.",
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
"vins": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
Description: "List of VINs deployed in this resource group.",
},
"vms": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
Description: "List of VM ids in this resource group.",
},
"storage_policy_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
}
return res
}

View File

@@ -105,6 +105,10 @@ func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m inter
req.Owner = owner.(string)
}
if enableDefaultGateway, ok := d.GetOkExists("enable_default_gateway"); ok {
req.EnableDefaultGateway = enableDefaultGateway.(bool)
}
if _, ok := d.GetOk("def_net"); !ok {
if defNetType, ok := d.GetOk("def_net_type"); ok {
if defNetType.(string) == "PRIVATE" {
@@ -667,14 +671,14 @@ func resourceRGSetCPUAllocationParameter(ctx context.Context, d *schema.Resource
}
func resourceRGSetCPUAllocationRatio(ctx context.Context, d *schema.ResourceData, m interface{}) error {
cpuAllocationRatio := d.Get("cpu_allocation_ratio").(float64)
log.Debugf("resourceRGSetCPUAllocationRatio: cpuAllocationRatio %s for rg id %d", cpuAllocationRatio, uint64(d.Get("rg_id").(int)))
cpuAllocationRatio := uint64(d.Get("cpu_allocation_ratio").(int))
log.Debugf("resourceRGSetCPUAllocationRatio: cpuAllocationRatio %d for rg id %d", cpuAllocationRatio, uint64(d.Get("rg_id").(int)))
c := m.(*controller.ControllerCfg)
req := rg.SetCPUAllocationRatioRequest{
RGID: uint64(d.Get("rg_id").(int)),
Ratio: cpuAllocationRatio,
Ratio: uint64(d.Get("cpu_allocation_ratio").(int)),
}
_, err := c.CloudBroker().RG().SetCPUAllocationRatio(ctx, req)
@@ -777,7 +781,7 @@ func resourceRGChangeComputeFeatures(ctx context.Context, d *schema.ResourceData
func ResourceResgroup() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
SchemaVersion: 2,
CreateContext: resourceResgroupCreate,
ReadContext: resourceResgroupRead,
@@ -812,5 +816,12 @@ func ResourceResgroup() *schema.Resource {
},
Schema: resourceRgSchemaMake(),
StateUpgraders: []schema.StateUpgrader{
{
Type: resourceRGV1().CoreConfigSchema().ImpliedType(),
Upgrade: resourceRGStateUpgradeV1,
Version: 1,
},
},
}
}

View File

@@ -68,7 +68,7 @@ func dataSourceRgSchemaMake() map[string]*schema.Schema {
Computed: true,
},
"cpu_allocation_ratio": {
Type: schema.TypeFloat,
Type: schema.TypeInt,
Computed: true,
},
"created_by": {
@@ -1518,6 +1518,10 @@ func dataSourceRgListDeletedSchemaMake() 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,
@@ -1557,7 +1561,7 @@ func dataSourceRgListDeletedSchemaMake() map[string]*schema.Schema {
Computed: true,
},
"cpu_allocation_ratio": {
Type: schema.TypeFloat,
Type: schema.TypeInt,
Computed: true,
},
"created_by": {
@@ -1812,6 +1816,10 @@ func dataSourceRgListSchemaMake() 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,
@@ -1851,7 +1859,7 @@ func dataSourceRgListSchemaMake() map[string]*schema.Schema {
Computed: true,
},
"cpu_allocation_ratio": {
Type: schema.TypeFloat,
Type: schema.TypeInt,
Computed: true,
},
"created_by": {
@@ -2238,6 +2246,10 @@ func resourceRgSchemaMake() map[string]*schema.Schema {
Description: "Name of this resource group. Names are case sensitive and unique within the context of a account.",
},
"enable_default_gateway": {
Type: schema.TypeBool,
Optional: true,
},
"resource_limits": {
Type: schema.TypeList,
Optional: true,
@@ -2395,7 +2407,7 @@ func resourceRgSchemaMake() map[string]*schema.Schema {
},
"cpu_allocation_ratio": {
Type: schema.TypeFloat,
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "set cpu allocation ratio",

View File

@@ -0,0 +1,15 @@
package rg
import (
"context"
log "github.com/sirupsen/logrus"
)
func resourceRGStateUpgradeV1(ctx context.Context, rawState map[string]interface{}, meta any) (map[string]interface{}, error) {
log.Debug("resourceRGStateUpgradeV1: upgrading state")
if v, ok := rawState["cpu_allocation_ratio"]; ok && v != nil {
rawState["cpu_allocation_ratio"] = int(v.(float64))
}
return rawState, nil
}

View File

@@ -50,7 +50,7 @@ func dataSourceSepConsumptionRead(ctx context.Context, d *schema.ResourceData, m
id := uuid.New()
d.SetId(id.String())
flattenSepConsumption(d, sepCons)
flattenSepConsumptionList(d, sepCons)
return nil
}

View File

@@ -110,15 +110,28 @@ func flattenSepPoolUris(rp *sep.RecordPool) []map[string]interface{} {
return res
}
func flattenSepConsumption(d *schema.ResourceData, sepCons *sep.RecordConsumption) {
d.Set("type", sepCons.Type)
d.Set("total", flattenSepConsumptionTotal(sepCons.Total))
d.Set("by_pool", flattenSepConsumptionPools(sepCons))
func flattenSepConsumptionList(d *schema.ResourceData, list *sep.ListConsumption) {
d.Set("entry_count", list.EntryCount)
d.Set("items", flattenSepConsumptionItems(list.Data))
}
func flattenSepConsumptionItems(records []sep.RecordConsumption) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(records))
for _, r := range records {
res = append(res, map[string]interface{}{
"sep_id": r.ID,
"name": r.Name,
"type": r.Type,
"consumed_by": r.ConsumedBy,
"total": flattenSepConsumptionTotal(r.Total),
"by_pool": flattenSepConsumptionPools(r.ByPool),
})
}
return res
}
func flattenSepConsumptionTotal(sc sep.Total) []map[string]interface{} {
sh := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
return []map[string]interface{}{{
"capacity_limit": sc.CapacityLimit,
"disk_count": sc.DiskCount,
"disk_usage": sc.DiskUsage,
@@ -126,15 +139,13 @@ func flattenSepConsumptionTotal(sc sep.Total) []map[string]interface{} {
"snapshot_usage": sc.SnapshotUsage,
"usage": sc.Usage,
"usage_limit": sc.UsageLimit,
}
sh = append(sh, temp)
return sh
}}
}
func flattenSepConsumptionPools(bp *sep.RecordConsumption) []map[string]interface{} {
sh := make([]map[string]interface{}, 0)
for key, value := range bp.ByPool {
temp := map[string]interface{}{
func flattenSepConsumptionPools(byPool map[string]sep.ByPool) []map[string]interface{} {
sh := make([]map[string]interface{}, 0, len(byPool))
for key, value := range byPool {
sh = append(sh, map[string]interface{}{
"name": key,
"disk_count": value.DiskCount,
"disk_usage": value.DiskUsage,
@@ -142,8 +153,7 @@ func flattenSepConsumptionPools(bp *sep.RecordConsumption) []map[string]interfac
"snapshot_usage": value.SnapshotUsage,
"usage": value.Usage,
"usage_limit": value.UsageLimit,
}
sh = append(sh, temp)
})
}
return sh
}

View File

@@ -129,102 +129,134 @@ func dataSourceSepConsumptionSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeInt,
Required: true,
Optional: true,
Description: "sep id",
},
"by_pool": {
"entry_count": {
Type: schema.TypeInt,
Computed: true,
Description: "number of entries",
},
"items": {
Type: schema.TypeList,
Computed: true,
Description: "consumption divided by pool",
Description: "list of sep consumption records",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeInt,
Computed: true,
Description: "sep id",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "pool name",
Description: "sep name",
},
"disk_count": {
Type: schema.TypeInt,
"type": {
Type: schema.TypeString,
Computed: true,
Description: "number of disks",
Description: "sep type",
},
"disk_usage": {
Type: schema.TypeInt,
"consumed_by": {
Type: schema.TypeList,
Computed: true,
Description: "disk usage",
Description: "list of consumer node IDs",
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"snapshot_count": {
Type: schema.TypeInt,
"by_pool": {
Type: schema.TypeList,
Computed: true,
Description: "number of snapshots",
Description: "consumption divided by pool",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
Description: "pool name",
},
"disk_count": {
Type: schema.TypeInt,
Computed: true,
Description: "number of disks",
},
"disk_usage": {
Type: schema.TypeInt,
Computed: true,
Description: "disk usage",
},
"snapshot_count": {
Type: schema.TypeInt,
Computed: true,
Description: "number of snapshots",
},
"snapshot_usage": {
Type: schema.TypeInt,
Computed: true,
Description: "snapshot usage",
},
"usage": {
Type: schema.TypeInt,
Computed: true,
Description: "usage",
},
"usage_limit": {
Type: schema.TypeInt,
Computed: true,
Description: "usage limit",
},
},
},
},
"snapshot_usage": {
Type: schema.TypeInt,
"total": {
Type: schema.TypeList,
Computed: true,
Description: "snapshot usage",
},
"usage": {
Type: schema.TypeInt,
Computed: true,
Description: "usage",
},
"usage_limit": {
Type: schema.TypeInt,
Computed: true,
Description: "usage limit",
Description: "total consumption",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"capacity_limit": {
Type: schema.TypeInt,
Computed: true,
Description: "capacity limit",
},
"disk_count": {
Type: schema.TypeInt,
Computed: true,
Description: "number of disks",
},
"disk_usage": {
Type: schema.TypeInt,
Computed: true,
Description: "disk usage",
},
"snapshot_count": {
Type: schema.TypeInt,
Computed: true,
Description: "number of snapshots",
},
"snapshot_usage": {
Type: schema.TypeInt,
Computed: true,
Description: "snapshot usage",
},
"usage": {
Type: schema.TypeInt,
Computed: true,
Description: "usage",
},
"usage_limit": {
Type: schema.TypeInt,
Computed: true,
Description: "usage limit",
},
},
},
},
},
},
},
"total": {
Type: schema.TypeList,
Computed: true,
Description: "total consumption",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"capacity_limit": {
Type: schema.TypeInt,
Computed: true,
Description: "capacity limit",
},
"disk_count": {
Type: schema.TypeInt,
Computed: true,
Description: "number of disks",
},
"disk_usage": {
Type: schema.TypeInt,
Computed: true,
Description: "disk usage",
},
"snapshot_count": {
Type: schema.TypeInt,
Computed: true,
Description: "number of snapshots",
},
"snapshot_usage": {
Type: schema.TypeInt,
Computed: true,
Description: "snapshot usage",
},
"usage": {
Type: schema.TypeInt,
Computed: true,
Description: "usage",
},
"usage_limit": {
Type: schema.TypeInt,
Computed: true,
Description: "usage limit",
},
},
},
},
"type": {
Type: schema.TypeString,
Computed: true,
Description: "sep type",
},
}
}
@@ -522,6 +554,7 @@ func resourceSepSchemaMake() map[string]*schema.Schema {
Optional: true,
Computed: true,
Description: "grant or revoke access to pool",
Deprecated: "\"access_to_pool\" is deprecated and will be removed in version 4.14.0",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"pool_name": {
@@ -546,6 +579,7 @@ func resourceSepSchemaMake() map[string]*schema.Schema {
Type: schema.TypeSet,
Optional: true,
Description: "lift of account ids to have access to sep",
Deprecated: "\"account_ids\" is deprecated and will be removed in version 4.14.0",
Elem: &schema.Schema{
Type: schema.TypeInt,
},

View File

@@ -39,16 +39,16 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilitySepConsumptionCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*sep.RecordConsumption, error) {
func utilitySepConsumptionCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*sep.ListConsumption, error) {
c := m.(*controller.ControllerCfg)
req := sep.ConsumptionRequest{
SEPID: uint64(d.Get("sep_id").(int)),
}
sepCons, err := c.CloudBroker().SEP().Consumption(ctx, req)
result, err := c.CloudBroker().SEP().Consumption(ctx, req)
if err != nil {
return nil, err
}
return sepCons, nil
return result, nil
}

View File

@@ -59,6 +59,8 @@ func DataSourceUserGetAudit() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
DeprecationMessage: "This data source is deprecated and will be removed in version 4.14.0.",
ReadContext: dataSourceUserGetAuditRead,
Timeouts: &schema.ResourceTimeout{

View File

@@ -63,7 +63,6 @@ func flattenUserDataSource(d *schema.ResourceData, details *user.ItemUser) {
d.Set("guid", details.GUID)
d.Set("last_check", details.LastCheck)
d.Set("mobile", flattenItemUser(details.Mobile))
d.Set("password", details.Password)
d.Set("protected", details.Protected)
d.Set("roles", flattenItemUser(details.Roles))
d.Set("service_account", details.ServiceAccount)
@@ -157,7 +156,6 @@ func flattenUserList(users *user.ListUsers) []map[string]interface{} {
"user_id": item.ID,
"last_check": item.LastCheck,
"mobile": flattenItemUser(item.Mobile),
"password": item.Password,
"protected": item.Protected,
"roles": flattenItemUser(item.Roles),
"service_account": item.ServiceAccount,

View File

@@ -13,7 +13,7 @@ import (
func resourceUserCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceUserCreate: called with username %s, emailaddress %v", d.Get("username").(string), d.Get("emailaddress").([]interface{}))
log.Debugf("resourceUserCreate: called with username %s, emailaddress %v", d.Get("username").(string), d.Get("emailaddress").(string))
c := m.(*controller.ControllerCfg)
@@ -26,10 +26,7 @@ func resourceUserCreate(ctx context.Context, d *schema.ResourceData, m interface
EmailAddress: email,
}
if passwd, ok := d.GetOk("password"); ok {
createReq.Password = passwd.(string)
}
createReq.Password = d.Get("password").(string)
if provider, ok := d.GetOk("provider_name"); ok {
createReq.Provider = provider.(string)

View File

@@ -111,11 +111,6 @@ func dataSourceUserSchemaMake() map[string]*schema.Schema {
},
Description: "mobile",
},
"password": {
Type: schema.TypeString,
Computed: true,
Description: "password",
},
"protected": {
Type: schema.TypeBool,
Computed: true,
@@ -370,11 +365,6 @@ func dataSourceUserListSchemaMake() map[string]*schema.Schema {
},
Description: "mobile",
},
"password": {
Type: schema.TypeString,
Computed: true,
Description: "password",
},
"protected": {
Type: schema.TypeBool,
Computed: true,
@@ -427,8 +417,8 @@ func resourceUserSchemaMake() map[string]*schema.Schema {
},
"password": {
Type: schema.TypeString,
Default: "strongpassword",
Optional: true,
Required: true,
Sensitive: true,
Description: "password of user",
},
"provider_name": {

View File

@@ -59,6 +59,8 @@ func DataSourceVinsAudits() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
DeprecationMessage: "This data source is deprecated and will be removed in version 4.14.0; use decort_cb_audit_list instead.",
ReadContext: dataSourceVinsAuditsRead,
Timeouts: &schema.ResourceTimeout{

View File

@@ -46,6 +46,7 @@ func flattenVins(d *schema.ResourceData, vinsRecord *vins.RecordVINS) {
d.Set("created_by", vinsRecord.CreatedBy)
d.Set("created_time", vinsRecord.CreatedTime)
d.Set("default_gw", vinsRecord.DefaultGW)
d.Set("enable_default_gateway", vinsRecord.EnableDefaultGateway)
d.Set("default_qos", flattenVinsQOS(vinsRecord.DefaultQOS))
d.Set("deleted_by", vinsRecord.DeletedBy)
d.Set("deleted_time", vinsRecord.DeletedTime)
@@ -86,6 +87,7 @@ func flattenVinsData(d *schema.ResourceData, vinsRecord *vins.RecordVINS) {
d.Set("created_by", vinsRecord.CreatedBy)
d.Set("created_time", vinsRecord.CreatedTime)
d.Set("default_gw", vinsRecord.DefaultGW)
d.Set("enable_default_gateway", vinsRecord.EnableDefaultGateway)
d.Set("default_qos", flattenVinsQOS(vinsRecord.DefaultQOS))
d.Set("deleted_by", vinsRecord.DeletedBy)
d.Set("deleted_time", vinsRecord.DeletedTime)
@@ -464,42 +466,43 @@ func flattenVinsList(vl *vins.ListVINS) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(vl.Data))
for _, v := range vl.Data {
temp := map[string]interface{}{
"account_id": v.AccountID,
"account_name": v.AccountName,
"created_by": v.CreatedBy,
"created_time": v.CreatedTime,
"default_gw": v.DefaultGW,
"default_qos": flattenVinsQOS(v.DefaultQOS),
"deleted_by": v.DeletedBy,
"deleted_time": v.DeletedTime,
"description": v.Description,
"enable_secgroups": v.EnableSecGroups,
"external_ip": v.ExternalIP,
"extnet_id": v.ExtnetId,
"free_ips": v.FreeIPs,
"gid": v.GID,
"guid": v.GUID,
"vins_id": v.ID,
"name": v.Name,
"lock_status": v.LockStatus,
"manager_id": v.ManagerID,
"manager_type": v.ManagerType,
"milestones": v.Milestones,
"netmask": v.NetMask,
"network": v.Network,
"pre_reservations_num": v.PreReservationsNum,
"pri_vnf_dev_id": v.PriVNFDevID,
"redundant": v.Redundant,
"rg_id": v.RGID,
"rg_name": v.RGName,
"sec_vnf_dev_id": v.SecVNFDevID,
"status": v.Status,
"updated_by": v.UpdatedBy,
"updated_time": v.UpdatedTime,
"user_managed": v.UserManaged,
"vnfs": flattenVinsVNFs(v.VNFs),
"vxlan_id": v.VXLANID,
"zone_id": v.ZoneID,
"account_id": v.AccountID,
"account_name": v.AccountName,
"created_by": v.CreatedBy,
"created_time": v.CreatedTime,
"default_gw": v.DefaultGW,
"enable_default_gateway": v.EnableDefaultGateway,
"default_qos": flattenVinsQOS(v.DefaultQOS),
"deleted_by": v.DeletedBy,
"deleted_time": v.DeletedTime,
"description": v.Description,
"enable_secgroups": v.EnableSecGroups,
"external_ip": v.ExternalIP,
"extnet_id": v.ExtnetId,
"free_ips": v.FreeIPs,
"gid": v.GID,
"guid": v.GUID,
"vins_id": v.ID,
"name": v.Name,
"lock_status": v.LockStatus,
"manager_id": v.ManagerID,
"manager_type": v.ManagerType,
"milestones": v.Milestones,
"netmask": v.NetMask,
"network": v.Network,
"pre_reservations_num": v.PreReservationsNum,
"pri_vnf_dev_id": v.PriVNFDevID,
"redundant": v.Redundant,
"rg_id": v.RGID,
"rg_name": v.RGName,
"sec_vnf_dev_id": v.SecVNFDevID,
"status": v.Status,
"updated_by": v.UpdatedBy,
"updated_time": v.UpdatedTime,
"user_managed": v.UserManaged,
"vnfs": flattenVinsVNFs(v.VNFs),
"vxlan_id": v.VXLANID,
"zone_id": v.ZoneID,
}
res = append(res, temp)
}
@@ -510,39 +513,40 @@ func flattenVinsListDeleted(vl *vins.ListVINS) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(vl.Data))
for _, v := range vl.Data {
temp := map[string]interface{}{
"account_id": v.AccountID,
"account_name": v.AccountName,
"created_by": v.CreatedBy,
"created_time": v.CreatedTime,
"default_gw": v.DefaultGW,
"default_qos": flattenVinsQOS(v.DefaultQOS),
"deleted_by": v.DeletedBy,
"deleted_time": v.DeletedTime,
"description": v.Description,
"external_ip": v.ExternalIP,
"gid": v.GID,
"guid": v.GUID,
"vins_id": v.ID,
"name": v.Name,
"lock_status": v.LockStatus,
"manager_id": v.ManagerID,
"manager_type": v.ManagerType,
"milestones": v.Milestones,
"netmask": v.NetMask,
"network": v.Network,
"pre_reservations_num": v.PreReservationsNum,
"pri_vnf_dev_id": v.PriVNFDevID,
"redundant": v.Redundant,
"rg_id": v.RGID,
"rg_name": v.RGName,
"sec_vnf_dev_id": v.SecVNFDevID,
"status": v.Status,
"updated_by": v.UpdatedBy,
"updated_time": v.UpdatedTime,
"user_managed": v.UserManaged,
"vnfs": flattenVinsVNFs(v.VNFs),
"vxlan_id": v.VXLANID,
"zone_id": v.ZoneID,
"account_id": v.AccountID,
"account_name": v.AccountName,
"created_by": v.CreatedBy,
"created_time": v.CreatedTime,
"default_gw": v.DefaultGW,
"enable_default_gateway": v.EnableDefaultGateway,
"default_qos": flattenVinsQOS(v.DefaultQOS),
"deleted_by": v.DeletedBy,
"deleted_time": v.DeletedTime,
"description": v.Description,
"external_ip": v.ExternalIP,
"gid": v.GID,
"guid": v.GUID,
"vins_id": v.ID,
"name": v.Name,
"lock_status": v.LockStatus,
"manager_id": v.ManagerID,
"manager_type": v.ManagerType,
"milestones": v.Milestones,
"netmask": v.NetMask,
"network": v.Network,
"pre_reservations_num": v.PreReservationsNum,
"pri_vnf_dev_id": v.PriVNFDevID,
"redundant": v.Redundant,
"rg_id": v.RGID,
"rg_name": v.RGName,
"sec_vnf_dev_id": v.SecVNFDevID,
"status": v.Status,
"updated_by": v.UpdatedBy,
"updated_time": v.UpdatedTime,
"user_managed": v.UserManaged,
"vnfs": flattenVinsVNFs(v.VNFs),
"vxlan_id": v.VXLANID,
"zone_id": v.ZoneID,
}
res = append(res, temp)
}

View File

@@ -89,6 +89,7 @@ func createVinsInAcc(ctx context.Context, d *schema.ResourceData, m interface{},
}
req.EnableSecGroups = d.Get("enable_secgroups").(bool)
req.EnableDefaultGateway = d.Get("enable_default_gateway").(bool)
return req, nil
}
@@ -146,6 +147,7 @@ func createVinsInRG(ctx context.Context, d *schema.ResourceData, m interface{},
}
req.EnableSecGroups = d.Get("enable_secgroups").(bool)
req.EnableDefaultGateway = d.Get("enable_default_gateway").(bool)
return req, nil
}

View File

@@ -115,6 +115,12 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface
}
}
if start, ok := d.GetOkExists("vnfdev_start"); ok && !start.(bool) {
if err := resourceVinsVnfDevStop(ctx, m, vinsID); err != nil {
warnings.Add(err)
}
}
return append(warnings.Get(), resourceVinsRead(ctx, d, m)...)
}
@@ -257,7 +263,7 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
}
}
if d.HasChanges("name", "desc", "enable_secgroups") {
if d.HasChanges("name", "desc", "enable_secgroups", "enable_default_gateway") {
vinsID := uint64(d.Get("vins_id").(int))
if err := utilityUpdateVINS(ctx, d, m, vinsID); err != nil {
return diag.FromErr(err)
@@ -366,7 +372,7 @@ func resourceVinsDelete(ctx context.Context, d *schema.ResourceData, m interface
return nil
}
func resourceVinsEnable(ctx context.Context, d *schema.ResourceData, m interface{}, vinsId uint64) error {
func resourceVinsEnable(ctx context.Context, _ *schema.ResourceData, m interface{}, vinsId uint64) error {
c := m.(*controller.ControllerCfg)
req := vins.EnableRequest{
@@ -377,7 +383,7 @@ func resourceVinsEnable(ctx context.Context, d *schema.ResourceData, m interface
return err
}
func resourceVinsDisable(ctx context.Context, d *schema.ResourceData, m interface{}, vinsId uint64) error {
func resourceVinsDisable(ctx context.Context, _ *schema.ResourceData, m interface{}, vinsId uint64) error {
c := m.(*controller.ControllerCfg)
req := vins.DisableRequest{
@@ -388,7 +394,7 @@ func resourceVinsDisable(ctx context.Context, d *schema.ResourceData, m interfac
return err
}
func resourceVinsRestore(ctx context.Context, d *schema.ResourceData, m interface{}, vinsId uint64) error {
func resourceVinsRestore(ctx context.Context, _ *schema.ResourceData, m interface{}, vinsId uint64) error {
c := m.(*controller.ControllerCfg)
req := vins.RestoreRequest{
@@ -765,20 +771,27 @@ func resourceVinsChangeVnfReset(ctx context.Context, d *schema.ResourceData, m i
}
func resourceVinsChangeVnfStartStop(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
vinsId := uint64(d.Get("vins_id").(int))
_, newStart := d.GetChange("vnfdev_start")
if newStart.(bool) {
req := vins.VNFDevStartRequest{VINSID: vinsId}
_, err := c.CloudBroker().VINS().VNFDevStart(ctx, req)
if err != nil {
return err
}
if d.Get("vnfdev_start").(bool) {
return resourceVinsVnfDevStart(ctx, m, vinsId)
}
return resourceVinsVnfDevStop(ctx, m, vinsId)
}
func resourceVinsVnfDevStart(ctx context.Context, m interface{}, vinsId uint64) error {
c := m.(*controller.ControllerCfg)
req := vins.VNFDevStartRequest{VINSID: vinsId}
_, err := c.CloudBroker().VINS().VNFDevStart(ctx, req)
return err
}
func resourceVinsVnfDevStop(ctx context.Context, m interface{}, vinsId uint64) error {
c := m.(*controller.ControllerCfg)
req := vins.VNFDevStopRequest{VINSID: vinsId}
_, err := c.CloudBroker().VINS().VNFDevStop(ctx, req)

View File

@@ -404,6 +404,10 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "default gw",
},
"enable_default_gateway": {
Type: schema.TypeBool,
Computed: true,
},
"default_qos": {
Type: schema.TypeList,
Computed: true,
@@ -1321,6 +1325,10 @@ func dataSourceVinsListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"enable_default_gateway": {
Type: schema.TypeBool,
Computed: true,
},
"default_qos": {
Type: schema.TypeList,
Computed: true,
@@ -1577,6 +1585,10 @@ func dataSourceVinsListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"enable_default_gateway": {
Type: schema.TypeBool,
Computed: true,
},
"default_qos": {
Type: schema.TypeList,
Computed: true,
@@ -2177,7 +2189,6 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
"vnfdev_start": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "true to start vnfdev, false to stop vnfdev",
},
"vnfdev_reset": {
@@ -2627,6 +2638,12 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "default gw",
},
"enable_default_gateway": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Flag indicating whether default gateway is enabled for this VINS",
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,

View File

@@ -80,6 +80,9 @@ func utilityUpdateVINS(ctx context.Context, d *schema.ResourceData, m interface{
if d.HasChange("enable_secgroups") {
req.EnableSecGroups = d.Get("enable_secgroups").(bool)
}
if d.HasChange("enable_default_gateway") {
req.EnableDefaultGateway = d.Get("enable_default_gateway").(bool)
}
_, err := c.CloudBroker().VINS().Update(ctx, req)
if err != nil {

View File

@@ -194,6 +194,34 @@ func dataSourceZoneSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"cpu_alignment_profiles": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"vendor": {
Type: schema.TypeString,
Computed: true,
},
"model": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"reserved_cpu": {
Type: schema.TypeInt,
Computed: true,
},
"reserved_ram": {
Type: schema.TypeInt,
Computed: true,
},
}
}

View File

@@ -0,0 +1,97 @@
/*
Copyright (c) 2019-2024 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 zone
import (
"context"
"strconv"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceZoneCPUAlignmentProfileRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
profiles, err := utilityZoneCPUAlignmentProfileCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
d.SetId(strconv.Itoa(d.Get("zone_id").(int)))
d.Set("profiles", flattenCPUAlignmentProfiles(profiles))
return nil
}
func dataSourceZoneCPUAlignmentProfileSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"zone_id": {
Type: schema.TypeInt,
Required: true,
},
"profiles": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"vendor": {
Type: schema.TypeString,
Computed: true,
},
"model": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
}
}
func DataSourceZoneCPUAlignmentProfile() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceZoneCPUAlignmentProfileRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceZoneCPUAlignmentProfileSchemaMake(),
}
}

View File

@@ -0,0 +1,115 @@
/*
Copyright (c) 2019-2024 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 zone
import (
"context"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceZoneCPUAlignmentProfileListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
list, err := utilityZoneCPUAlignmentProfileListCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenZoneCPUAlignmentProfileList(list))
d.Set("entry_count", list.EntryCount)
return nil
}
func dataSourceZoneCPUAlignmentProfileListSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"zone_id": {
Type: schema.TypeInt,
Optional: true,
},
"items": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"zone_id": {
Type: schema.TypeInt,
Computed: true,
},
"cpu_alignment_profiles": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"vendor": {
Type: schema.TypeString,
Computed: true,
},
"model": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
}
func DataSourceZoneCPUAlignmentProfileList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceZoneCPUAlignmentProfileListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceZoneCPUAlignmentProfileListSchemaMake(),
}
}

View File

@@ -0,0 +1,159 @@
/*
Copyright (c) 2019-2024 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 zone
import (
"context"
"strconv"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceZoneCPUAlignmentProfileTestRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
result, err := utilityZoneCPUAlignmentProfileTestCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
d.SetId(strconv.Itoa(d.Get("zone_id").(int)))
d.Set("profiles", flattenCPUAlignmentProfiles(result.Profiles))
d.Set("candidates", flattenCPUAlignmentProfileCandidates(result.Candidates))
d.Set("supported_cpu_models", flattenSupportedCpuModels(result.SupportedCpuModels))
return nil
}
func dataSourceZoneCPUAlignmentProfileTestSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"zone_id": {
Type: schema.TypeInt,
Required: true,
},
"hypervisor_similarity_in_percentage": {
Type: schema.TypeInt,
Optional: true,
},
"profiles": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"vendor": {
Type: schema.TypeString,
Computed: true,
},
"model": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"candidates": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"vendor": {
Type: schema.TypeString,
Computed: true,
},
"model": {
Type: schema.TypeString,
Computed: true,
},
"count": {
Type: schema.TypeInt,
Computed: true,
},
"percentage": {
Type: schema.TypeFloat,
Computed: true,
},
"required_count": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"supported_cpu_models": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"vendor": {
Type: schema.TypeString,
Computed: true,
},
"model": {
Type: schema.TypeString,
Computed: true,
},
"count": {
Type: schema.TypeInt,
Computed: true,
},
"percentage": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
}
}
func DataSourceZoneCPUAlignmentProfileTest() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceZoneCPUAlignmentProfileTestRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceZoneCPUAlignmentProfileTestSchemaMake(),
}
}

View File

@@ -202,6 +202,34 @@ func dataSourceZoneListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"cpu_alignment_profiles": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"vendor": {
Type: schema.TypeString,
Computed: true,
},
"model": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"reserved_cpu": {
Type: schema.TypeInt,
Computed: true,
},
"reserved_ram": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},

View File

@@ -38,6 +38,19 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/zone"
)
func flattenSupportedCpuModels(models []zone.SupportedCpuModel) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(models))
for _, m := range models {
res = append(res, map[string]interface{}{
"vendor": m.Vendor,
"model": m.Model,
"count": int(m.Count),
"percentage": m.Percentage,
})
}
return res
}
func flattenZone(d *schema.ResourceData, item *zone.RecordZone) error {
log.Debugf("flattenZone: start decoding RecordZone name %q / ID %d",
item.Name, item.ID)
@@ -71,39 +84,83 @@ func flattenZone(d *schema.ResourceData, item *zone.RecordZone) error {
d.Set("ssl_skip_verify", item.SSLSkipVerify)
d.Set("domain", item.Domain)
d.Set("sso_type", item.SSOType)
d.Set("cpu_alignment_profiles", flattenCPUAlignmentProfiles(item.CpuAlignmentProfiles))
d.Set("reserved_cpu", item.ReservedCPU)
d.Set("reserved_ram", item.ReservedRAM)
log.Debugf("flattenZone: decoded RecordZone name %q / ID %d, complete",
item.Name, item.ID)
return nil
}
func flattenCPUAlignmentProfiles(profiles []zone.CpuAlignmentProfile) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(profiles))
for _, p := range profiles {
res = append(res, map[string]interface{}{
"name": p.Name,
"vendor": p.Vendor,
"model": p.Model,
})
}
return res
}
func flattenCPUAlignmentProfileCandidates(candidates []zone.CpuAlignmentProfileCandidate) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(candidates))
for _, c := range candidates {
res = append(res, map[string]interface{}{
"name": c.Name,
"vendor": c.Vendor,
"model": c.Model,
"count": int(c.Count),
"percentage": c.Percentage,
"required_count": int(c.RequiredCount),
})
}
return res
}
func flattenZoneCPUAlignmentProfileList(list *zone.ListCPUAlignmentProfiles) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(list.Data))
for _, item := range list.Data {
res = append(res, map[string]interface{}{
"zone_id": int(item.ZoneID),
"cpu_alignment_profiles": flattenCPUAlignmentProfiles(item.CpuAlignmentProfiles),
})
}
return res
}
func flattenZoneList(zone *zone.ListZones) []map[string]interface{} {
log.Debugf("flattenZoneList start")
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,
"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,
"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,
"cpu_alignment_profiles": flattenCPUAlignmentProfiles(zone.CpuAlignmentProfiles),
"reserved_cpu": int(zone.ReservedCPU),
"reserved_ram": int(zone.ReservedRAM),
}
res = append(res, temp)
}

View File

@@ -97,6 +97,22 @@ func resourceZoneCreate(ctx context.Context, d *schema.ResourceData, m interface
}
}
if similarity, ok := d.GetOk("hypervisor_similarity_in_percentage"); ok {
if s := similarity.(int); s > 0 {
if err := utilityZoneCPUAlignmentProfileAdd(ctx, m, zoneID, uint64(s)); err != nil {
warnings.Add(err)
}
}
}
if _, cpuOk := d.GetOk("reserved_cpu"); cpuOk {
if _, ramOk := d.GetOk("reserved_ram"); ramOk {
if err := utilityZoneSetResourcesLimit(ctx, d, m, zoneID); err != nil {
warnings.Add(err)
}
}
}
log.Debugf("resourceZoneCreate: create Zone with ID: %d, complete", zoneID)
return append(resourceZoneRead(ctx, d, m), warnings.Get()...)
}
@@ -127,6 +143,18 @@ func resourceZoneUpdate(ctx context.Context, d *schema.ResourceData, m interface
}
}
if d.HasChange("hypervisor_similarity_in_percentage") {
if err := utilityZoneCPUAlignmentProfileUpdate(ctx, d, m, zoneID); err != nil {
return diag.FromErr(err)
}
}
if d.HasChanges("reserved_cpu", "reserved_ram") {
if err := utilityZoneSetResourcesLimit(ctx, d, m, zoneID); err != nil {
return diag.FromErr(err)
}
}
log.Debugf("resourceZoneUpdate: update Zone with id %d, complete", zoneID)
return resourceZoneRead(ctx, d, m)
@@ -279,6 +307,40 @@ func resourceZoneSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"hypervisor_similarity_in_percentage": {
Type: schema.TypeInt,
Optional: true,
},
"reserved_cpu": {
Type: schema.TypeInt,
Optional: true,
RequiredWith: []string{"reserved_ram"},
},
"reserved_ram": {
Type: schema.TypeInt,
Optional: true,
RequiredWith: []string{"reserved_cpu"},
},
"cpu_alignment_profiles": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"vendor": {
Type: schema.TypeString,
Computed: true,
},
"model": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"id": {
Type: schema.TypeString,
Computed: true,

View File

@@ -146,6 +146,73 @@ func utilityZoneUpdate(ctx context.Context, d *schema.ResourceData, m interface{
return nil
}
func utilityZoneCPUAlignmentProfileAdd(ctx context.Context, m interface{}, zoneID uint64, similarity uint64) error {
c := m.(*controller.ControllerCfg)
req := zone.AddCPUAlignmentProfileRequest{
ZoneID: zoneID,
HypervisorSimilarityInPercentage: similarity,
}
if _, err := c.CloudBroker().Zone().AddCPUAlignmentProfile(ctx, req); err != nil {
return err
}
log.Debugf("utilityZoneCPUAlignmentProfileAdd: added CPU alignment profile for zone %d with similarity %d%%", zoneID, similarity)
return nil
}
func utilityZoneCPUAlignmentProfileUpdate(ctx context.Context, d *schema.ResourceData, m interface{}, zoneID uint64) error {
c := m.(*controller.ControllerCfg)
oldRaw, newRaw := d.GetChange("hypervisor_similarity_in_percentage")
oldVal := oldRaw.(int)
newVal := newRaw.(int)
if newVal == 0 {
req := zone.DeleteCPUAlignmentProfileRequest{
ZoneID: zoneID,
}
if _, err := c.CloudBroker().Zone().DeleteCPUAlignmentProfile(ctx, req); err != nil {
return err
}
log.Debugf("utilityZoneCPUAlignmentProfileUpdate: deleted CPU alignment profile for zone %d", zoneID)
return nil
}
if oldVal == 0 {
if err := utilityZoneCPUAlignmentProfileAdd(ctx, m, zoneID, uint64(newVal)); err != nil {
return err
}
} else {
req := zone.UpdateCPUAlignmentProfileRequest{
ZoneID: zoneID,
HypervisorSimilarityInPercentage: uint64(newVal),
}
if _, err := c.CloudBroker().Zone().UpdateCPUAlignmentProfile(ctx, req); err != nil {
return err
}
log.Debugf("utilityZoneCPUAlignmentProfileUpdate: updated CPU alignment profile for zone %d with similarity %d%%", zoneID, newVal)
}
return nil
}
func utilityZoneSetResourcesLimit(ctx context.Context, d *schema.ResourceData, m interface{}, zoneID uint64) error {
c := m.(*controller.ControllerCfg)
req := zone.SetResourcesLimitRequest{
ZoneID: zoneID,
ReservedCPU: uint64(d.Get("reserved_cpu").(int)),
ReservedRAM: uint64(d.Get("reserved_ram").(int)),
}
if _, err := c.CloudBroker().Zone().SetResourcesLimit(ctx, req); err != nil {
return err
}
log.Debugf("utilityZoneSetResourcesLimit: set resources limit for zone %d (cpu=%d, ram=%d)", zoneID, req.ReservedCPU, req.ReservedRAM)
return nil
}
func containsNodes(set []interface{}, check interface{}) bool {
for _, elem := range set {
elemConv := elem.(int)

View File

@@ -0,0 +1,77 @@
/*
Copyright (c) 2019-2024 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 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 utilityZoneCPUAlignmentProfileCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) ([]zone.CpuAlignmentProfile, error) {
c := m.(*controller.ControllerCfg)
req := zone.GetCPUAlignmentProfileRequest{
ZoneID: uint64(d.Get("zone_id").(int)),
}
return c.CloudBroker().Zone().GetCPUAlignmentProfile(ctx, req)
}
func utilityZoneCPUAlignmentProfileListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*zone.ListCPUAlignmentProfiles, error) {
c := m.(*controller.ControllerCfg)
req := zone.ListCPUAlignmentProfileRequest{}
if zoneID, ok := d.GetOk("zone_id"); ok {
req.ZoneID = uint64(zoneID.(int))
}
return c.CloudBroker().Zone().ListCPUAlignmentProfile(ctx, req)
}
func utilityZoneCPUAlignmentProfileTestCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*zone.TestCPUAlignmentProfileResult, error) {
c := m.(*controller.ControllerCfg)
req := zone.TestCPUAlignmentProfileRequest{
ZoneID: uint64(d.Get("zone_id").(int)),
}
if similarity, ok := d.GetOk("hypervisor_similarity_in_percentage"); ok {
req.HypervisorSimilarityInPercentage = uint64(similarity.(int))
}
return c.CloudBroker().Zone().TestCPUAlignmentProfile(ctx, req)
}