4.13.0
This commit is contained in:
@@ -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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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(),
|
||||
}
|
||||
}
|
||||
@@ -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(),
|
||||
}
|
||||
}
|
||||
@@ -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(),
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user