This commit is contained in:
2026-06-19 17:45:18 +03:00
parent c00c608ce9
commit 89c77ddcbe
1324 changed files with 199523 additions and 1 deletions

View File

@@ -0,0 +1,213 @@
/*
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 dataSourceZoneRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
zone, err := utilityZoneCheckPresence(ctx, d, m)
if err != nil {
d.SetId("") // ensure ID is empty in this case
return diag.FromErr(err)
}
d.SetId(strconv.Itoa(d.Get("zone_id").(int)))
flattenZone(d, zone)
return nil
}
func dataSourceZoneSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"zone_id": {
Type: schema.TypeInt,
Required: true,
},
"auto_start": {
Type: schema.TypeBool,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"deletable": {
Type: schema.TypeBool,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
"node_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"account_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"compute_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"extnet_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"vins_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"lb_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"bservice_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"k8s_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"drs": {
Type: schema.TypeBool,
Computed: true,
},
"drs_uid": {
Type: schema.TypeString,
Computed: true,
},
"drs_name": {
Type: schema.TypeString,
Computed: true,
},
"sso_url": {
Type: schema.TypeString,
Computed: true,
},
"app_id": {
Type: schema.TypeString,
Computed: true,
},
"decort_url": {
Type: schema.TypeString,
Computed: true,
},
"domain": {
Type: schema.TypeString,
Computed: true,
},
"ping_addr": {
Type: schema.TypeString,
Computed: true,
},
"broadcast_addr": {
Type: schema.TypeString,
Computed: true,
},
"ssl_skip_verify": {
Type: schema.TypeBool,
Computed: true,
},
"sso_type": {
Type: schema.TypeString,
Computed: true,
},
}
}
func DataSourceZone() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceZoneRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceZoneSchemaMake(),
}
}

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

@@ -0,0 +1,230 @@
/*
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 dataSourceZoneListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
zoneList, err := utilityZoneListCheckPresence(ctx, d, m)
if err != nil {
d.SetId("") // ensure ID is empty in this case
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenZoneList(zoneList))
d.Set("entry_count", zoneList.EntryCount)
return nil
}
func dataSourceZoneListSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by ID",
},
"gid": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by Grid ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Find by name",
},
"description": {
Type: schema.TypeString,
Optional: true,
Description: "Find by description",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Find by status",
},
"deletable": {
Type: schema.TypeBool,
Optional: true,
Description: "Find by deletable",
},
"node_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by nodeId",
},
"sort_by": {
Type: schema.TypeString,
Optional: true,
Description: "sort by one of supported fields, format +|-(field)",
},
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "Page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "Page size",
},
"items": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"zone_id": {
Type: schema.TypeInt,
Required: true,
},
"auto_start": {
Type: schema.TypeBool,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"deletable": {
Type: schema.TypeBool,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
"node_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"drs": {
Type: schema.TypeBool,
Computed: true,
},
"drs_uid": {
Type: schema.TypeString,
Computed: true,
},
"drs_name": {
Type: schema.TypeString,
Computed: true,
},
"sso_url": {
Type: schema.TypeString,
Computed: true,
},
"app_id": {
Type: schema.TypeString,
Computed: true,
},
"decort_url": {
Type: schema.TypeString,
Computed: true,
},
"domain": {
Type: schema.TypeString,
Computed: true,
},
"ping_addr": {
Type: schema.TypeString,
Computed: true,
},
"broadcast_addr": {
Type: schema.TypeString,
Computed: true,
},
"ssl_skip_verify": {
Type: schema.TypeBool,
Computed: true,
},
"sso_type": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}
func DataSourceZoneList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceZoneListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceZoneListSchemaMake(),
}
}

View File

@@ -0,0 +1,165 @@
/*
Copyright (c) 2019-2024 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package zone
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/zone"
)
func flattenZone(d *schema.ResourceData, item *zone.RecordZone) error {
log.Debugf("flattenZone: start decoding RecordZone name %q / ID %d",
item.Name, item.ID)
d.Set("zone_id", int(item.ID))
d.Set("guid", int(item.GUID))
d.Set("gid", int(item.GID))
d.Set("name", item.Name)
d.Set("description", item.Description)
d.Set("deletable", item.Deletable)
d.Set("status", item.Status)
d.Set("created_time", item.CreatedTime)
d.Set("updated_time", item.UpdatedTime)
d.Set("node_ids", item.NodeIDs)
d.Set("account_ids", item.AccountIDs)
d.Set("compute_ids", item.ComputeIDs)
d.Set("extnet_ids", item.ExtnetIDs)
d.Set("vins_ids", item.VinsIDs)
d.Set("lb_ids", item.LBIDs)
d.Set("bservice_ids", item.BserviceIDs)
d.Set("k8s_ids", item.K8SIDs)
d.Set("auto_start", item.AutoStart)
d.Set("drs", item.DRS)
d.Set("drs_uid", item.DRSUID)
d.Set("drs_name", item.DRSName)
d.Set("sso_url", item.SSOURL)
d.Set("app_id", item.AppID)
d.Set("decort_url", item.DecortURL)
d.Set("ping_addr", item.PingAddr)
d.Set("broadcast_addr", item.BroadcastAddr)
d.Set("ssl_skip_verify", item.SSLSkipVerify)
d.Set("domain", item.Domain)
d.Set("sso_type", item.SSOType)
d.Set("cpu_alignment_profiles", flattenCPUAlignmentProfiles(item.CpuAlignmentProfiles))
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 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 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,
}
res = append(res, temp)
}
log.Debugf("flattenZoneList end")
return res
}

View File

@@ -0,0 +1,325 @@
/*
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"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/zone"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
)
func resourceZoneCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
zoneName := d.Get("name").(string)
log.Debugf("resourceZoneCreate: called Zone with name %s", zoneName)
c := m.(*controller.ControllerCfg)
req := zone.CreateRequest{
Name: zoneName,
}
if aS, ok := d.GetOk("auto_start"); ok {
req.AutoStart = aS.(bool)
}
if desc, ok := d.GetOk("description"); ok {
req.Description = desc.(string)
}
if drs, ok := d.GetOkExists("drs"); ok {
req.DRS = drs.(bool)
}
zoneID, err := c.CloudBroker().Zone().Create(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId(strconv.FormatUint(zoneID, 10))
warnings := dc.Warnings{}
if nodeIDs, ok := d.GetOk("node_ids"); ok {
nodeIDsArr := nodeIDs.([]interface{})
if len(nodeIDsArr) > 0 {
addedUint := make([]uint64, len(nodeIDsArr))
for i, v := range nodeIDsArr {
addedUint[i] = uint64(v.(int))
}
req := zone.AddNodeRequest{
ID: zoneID,
NodeIDs: addedUint,
}
if _, err := c.CloudBroker().Zone().AddNode(ctx, req); err != nil {
warnings.Add(err)
}
}
}
if similarity, ok := d.GetOk("hypervisor_similarity_in_percentage"); ok {
if s := similarity.(int); s > 0 {
if err := utilityZoneCPUAlignmentProfileUpdate(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()...)
}
func resourceZoneRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceZoneRead: called Zone with id %s", d.Id())
zone, err := utilityZoneCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
flattenZone(d, zone)
log.Debugf("resourceZoneRead: read Zone with id %s, complete", d.Id())
return nil
}
func resourceZoneUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
zoneID, _ := strconv.ParseUint(d.Id(), 10, 64)
log.Debugf("resourceZoneUpdate: called Zone with id %d", zoneID)
if d.HasChanges("name", "description", "node_ids", "auto_start") {
if err := utilityZoneUpdate(ctx, d, m, zoneID); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("hypervisor_similarity_in_percentage") {
if err := utilityZoneCPUAlignmentProfileUpdate(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)
}
func resourceZoneDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceZoneDelete: called Zone with id %s", d.Id())
zoneItem, err := utilityZoneCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
c := m.(*controller.ControllerCfg)
req := zone.DeleteRequest{
ID: zoneItem.ID,
}
_, err = c.CloudBroker().Zone().Delete(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func ResourceZone() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceZoneCreate,
ReadContext: resourceZoneRead,
UpdateContext: resourceZoneUpdate,
DeleteContext: resourceZoneDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout20m,
Read: &constants.Timeout20m,
Update: &constants.Timeout20m,
Delete: &constants.Timeout20m,
Default: &constants.Timeout20m,
},
Schema: resourceZoneSchemaMake(),
}
}
func resourceZoneSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"node_ids": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"auto_start": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"drs": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"drs_uid": {
Type: schema.TypeString,
Computed: true,
},
"drs_name": {
Type: schema.TypeString,
Computed: true,
},
"sso_url": {
Type: schema.TypeString,
Computed: true,
},
"app_id": {
Type: schema.TypeString,
Computed: true,
},
"decort_url": {
Type: schema.TypeString,
Computed: true,
},
"domain": {
Type: schema.TypeString,
Computed: true,
},
"ping_addr": {
Type: schema.TypeString,
Computed: true,
},
"broadcast_addr": {
Type: schema.TypeString,
Computed: true,
},
"ssl_skip_verify": {
Type: schema.TypeBool,
Computed: true,
},
"sso_type": {
Type: schema.TypeString,
Computed: true,
},
"zone_id": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"deletable": {
Type: schema.TypeBool,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
"hypervisor_similarity_in_percentage": {
Type: schema.TypeInt,
Optional: 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,
},
},
},
},
"id": {
Type: schema.TypeString,
Computed: true,
},
}
}

View File

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

View File

@@ -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)
}

View File

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