This commit is contained in:
2024-05-31 14:05:21 +03:00
parent 84b7a80e1b
commit db1760cb72
815 changed files with 58194 additions and 11049 deletions

View File

@@ -0,0 +1,70 @@
/*
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"
"strconv"
"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 dataSourceNodeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
nodeRec, err := utilityNodeCheckPresence(ctx, d, m)
if err != nil {
d.SetId("") // ensure ID is empty in this case
return diag.FromErr(err)
}
flattenNode(d, nodeRec)
d.SetId(strconv.Itoa(d.Get("node_id").(int)))
return nil
}
func DataSourceNode() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceNodeRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceNodeSchemaMake(),
}
}

View File

@@ -0,0 +1,72 @@
/*
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/terraform-provider-decort/internal/constants"
)
func dataSourceNodeListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
nodeList, err := utilityNodeListCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenNodeList(nodeList))
d.Set("entry_count", nodeList.EntryCount)
return nil
}
func DataSourceNodeList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceNodeListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceNodeListSchemaMake(),
}
}

View File

@@ -0,0 +1,239 @@
/*
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 (
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/node"
)
func flattenNode(d *schema.ResourceData, item *node.RecordNode) {
log.Debugf("flattenNode: decoded node id %d", d.Get("node_id").(int))
d.Set("consumption", flattenConsumption(item.Consumption))
d.Set("cpu_info", flattenCpuInfo(item.CpuInfo))
d.Set("cpu_allocation_ratio", item.CPUAllocationRatio)
d.Set("gid", item.GID)
d.Set("ipaddr", item.IPAddr)
d.Set("isolated_cpus", flattenNodeItem(item.IsolatedCpus))
d.Set("name", item.Name)
d.Set("need_reboot", item.NeedReboot)
d.Set("nic_info", flattenNicInfo(item.NicInfo))
d.Set("numa_topology", flattenNumaTopology(item.NumaTopology))
d.Set("reserved_cpus", flattenNodeItem(item.ReservedCPUs))
d.Set("roles", item.Roles)
d.Set("sriov_enabled", item.SriovEnabled)
d.Set("stack_id", item.StackID)
d.Set("status", item.Status)
d.Set("version", item.Version)
}
func flattenConsumption(info node.ConsumptionInfo) []map[string]interface{} {
res := make([]map[string]interface{}, 1)
tempRes := map[string]interface{}{
"hostname": info.Hostname,
}
tempConsumed := map[string]interface{}{
"ram": info.Consumed.RAM,
"computes": info.Consumed.Computes,
"routers": info.Consumed.Routers,
"vcpu": info.Consumed.VCPU,
}
tempRes["consumed"] = []map[string]interface{}{
tempConsumed,
}
tempFree := map[string]interface{}{
"ram": info.Free.RAM,
}
tempRes["free"] = []map[string]interface{}{
tempFree,
}
tempReserved := map[string]interface{}{
"ram": info.Reserved.RAM,
}
tempRes["reserved"] = []map[string]interface{}{
tempReserved,
}
tempTotal := map[string]interface{}{
"ram": info.Total.RAM,
}
tempRes["total"] = []map[string]interface{}{
tempTotal,
}
res[0] = tempRes
return res
}
func flattenNodeList(nodes *node.ListNodes) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(nodes.Data))
for _, item := range nodes.Data {
temp := map[string]interface{}{
"additional_pkgs": flattenNodeItem(item.AdditionalPkgs),
"cpu_info": flattenCpuInfo(item.CpuInfo),
"description": item.Description,
"gid": item.GID,
"guid": item.GUID,
"hostkey": item.HostKey,
"node_id": item.ID,
"ipaddr": item.IPAddr,
"isolated_cpus": flattenNodeItem(item.IsolatedCpus),
"lastcheck": item.LastCheck,
"machine_guid": item.MachineGUID,
"mainboard_sn": item.MainboardSN,
"memory": item.Memory,
"milestones": item.Milestones,
"model": item.Model,
"name": item.Name,
"need_reboot": item.NeedReboot,
"net_addr": flattenNetAddr(item.NetAddr),
"network_mode": item.NetworkMode,
"nic_info": flattenNicInfo(item.NicInfo),
"node_uuid": item.NodeUUID,
"numa_topology": flattenNumaTopology(item.NumaTopology),
"peer_backup": item.PeerBackup,
"peer_log": item.PeerLog,
"peer_stats": item.PeerStats,
"pgpus": item.Pgpus,
"public_keys": item.PublicKeys,
"release": item.Release,
"reserved_cpus": flattenNodeItem(item.ReservedCPUs),
"roles": item.Roles,
"seps": item.Seps,
"serial_num": item.SerialNum,
"sriov_enabled": item.SriovEnabled,
"stack_id": item.StackID,
"status": item.Status,
"tags": item.Tags,
"type": item.Type,
"version": item.Version,
}
res = append(res, temp)
}
return res
}
func flattenNumaTopology(info node.NumaTopologyInfo) []map[string]interface{} {
res := make([]map[string]interface{}, 1)
tempRes := map[string]interface{}{
"node_num": info.NodeNum,
}
resNodes := make([]map[string]interface{}, 0, len(info.Nodes))
for _, item := range info.Nodes {
memoryTemp := []map[string]interface{}{
{
"one_g": item.Memory.OneG,
"two_m": item.Memory.TwoM,
"total": item.Memory.Total,
},
}
temp := map[string]interface{}{
"cpu_list": item.CPUList,
"memory": memoryTemp,
}
resNodes = append(resNodes, temp)
}
tempRes["nodes"] = resNodes
res[0] = tempRes
return res
}
func flattenNicInfo(infos node.ListNicInfo) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(infos))
for _, item := range infos {
temp := map[string]interface{}{
"driver": item.Driver,
"max_vfs": item.MaxVFS,
"numa_node": item.NumaNode,
"num_vfs": item.NumVFS,
"os_name": item.OSName,
"pci_slot": item.PCISlot,
"vf_list": flattenNodeItem(item.VFList),
}
res = append(res, temp)
}
return res
}
func flattenNetAddr(adresses node.ListNetAddr) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(adresses))
for _, item := range adresses {
temp := map[string]interface{}{
"cidr": item.CIDR,
"index": item.Index,
"ip": item.IP,
"mac": item.Mac,
"mtu": item.MTU,
"name": item.Name,
}
res = append(res, temp)
}
return res
}
func flattenCpuInfo(info node.CpuInfo) []map[string]interface{} {
res := make([]map[string]interface{}, 1)
temp := map[string]interface{}{
"clock_speed": info.ClockSpeed,
"core_count": info.CoreCount,
"phys_count": info.PhysCount,
}
res[0] = temp
return res
}
func flattenNodeItem(m []interface{}) []string {
output := []string{}
for _, item := range m {
switch d := item.(type) {
case string:
output = append(output, d)
case int:
output = append(output, strconv.Itoa(d))
case int64:
output = append(output, strconv.FormatInt(d, 10))
case float64:
output = append(output, strconv.FormatInt(int64(d), 10))
default:
output = append(output, "")
}
}
return output
}

View File

@@ -0,0 +1,629 @@
package node
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
func dataSourceNodeSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"node_id": {
Type: schema.TypeInt,
Required: true,
Description: "node id",
},
"consumption": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"consumed": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ram": {
Type: schema.TypeInt,
Computed: true,
},
"computes": {
Type: schema.TypeInt,
Computed: true,
},
"routers": {
Type: schema.TypeInt,
Computed: true,
},
"vcpu": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"free": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ram": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"reserved": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ram": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"total": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ram": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"hostname": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"cpu_info": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"clock_speed": {
Type: schema.TypeInt,
Computed: true,
},
"core_count": {
Type: schema.TypeInt,
Computed: true,
},
"phys_count": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"cpu_allocation_ratio": {
Type: schema.TypeInt,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"ipaddr": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"isolated_cpus": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"need_reboot": {
Type: schema.TypeBool,
Computed: true,
},
"nic_info": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"driver": {
Type: schema.TypeString,
Computed: true,
},
"max_vfs": {
Type: schema.TypeInt,
Computed: true,
},
"numa_node": {
Type: schema.TypeInt,
Computed: true,
},
"num_vfs": {
Type: schema.TypeInt,
Computed: true,
},
"os_name": {
Type: schema.TypeString,
Computed: true,
},
"pci_slot": {
Type: schema.TypeString,
Computed: true,
},
"vf_list": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"numa_topology": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"node_num": {
Type: schema.TypeInt,
Computed: true,
},
"nodes": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cpu_list": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"memory": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"one_g": {
Type: schema.TypeInt,
Computed: true,
},
"two_m": {
Type: schema.TypeInt,
Computed: true,
},
"total": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
},
},
},
},
},
},
"reserved_cpus": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"roles": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"sriov_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"stack_id": {
Type: schema.TypeInt,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"version": {
Type: schema.TypeString,
Computed: true,
},
}
}
func dataSourceNodeListSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "find node by id",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "find node by name",
},
"version": {
Type: schema.TypeString,
Optional: true,
Description: "find node by version",
},
"release": {
Type: schema.TypeString,
Optional: true,
Description: "find node by release",
},
"sep_id": {
Type: schema.TypeInt,
Optional: true,
Description: "find node by sepId",
},
"role": {
Type: schema.TypeString,
Optional: true,
Description: "find node by role",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "find node by status",
},
"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{
"additional_pkgs": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"cpu_info": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"clock_speed": {
Type: schema.TypeFloat,
Computed: true,
},
"core_count": {
Type: schema.TypeInt,
Computed: true,
},
"phys_count": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"hostkey": {
Type: schema.TypeString,
Computed: true,
},
"node_id": {
Type: schema.TypeInt,
Computed: true,
},
"ipaddr": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"isolated_cpus": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"lastcheck": {
Type: schema.TypeInt,
Computed: true,
},
"machine_guid": {
Type: schema.TypeString,
Computed: true,
},
"mainboard_sn": {
Type: schema.TypeString,
Computed: true,
},
"memory": {
Type: schema.TypeInt,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"model": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"need_reboot": {
Type: schema.TypeBool,
Computed: true,
},
"net_addr": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cidr": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"index": {
Type: schema.TypeInt,
Computed: true,
},
"ip": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"mac": {
Type: schema.TypeString,
Computed: true,
},
"mtu": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"network_mode": {
Type: schema.TypeString,
Computed: true,
},
"nic_info": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"driver": {
Type: schema.TypeString,
Computed: true,
},
"max_vfs": {
Type: schema.TypeInt,
Computed: true,
},
"numa_node": {
Type: schema.TypeInt,
Computed: true,
},
"num_vfs": {
Type: schema.TypeInt,
Computed: true,
},
"os_name": {
Type: schema.TypeString,
Computed: true,
},
"pci_slot": {
Type: schema.TypeString,
Computed: true,
},
"vf_list": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"node_uuid": {
Type: schema.TypeString,
Computed: true,
},
"numa_topology": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"node_num": {
Type: schema.TypeInt,
Computed: true,
},
"nodes": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cpu_list": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"memory": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"one_g": {
Type: schema.TypeInt,
Computed: true,
},
"two_m": {
Type: schema.TypeInt,
Computed: true,
},
"total": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
},
},
},
},
},
},
"peer_backup": {
Type: schema.TypeInt,
Computed: true,
},
"peer_log": {
Type: schema.TypeInt,
Computed: true,
},
"peer_stats": {
Type: schema.TypeInt,
Computed: true,
},
"pgpus": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"public_keys": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"release": {
Type: schema.TypeString,
Computed: true,
},
"reserved_cpus": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"roles": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"seps": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"serial_num": {
Type: schema.TypeString,
Computed: true,
},
"sriov_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"stack_id": {
Type: schema.TypeInt,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tags": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"version": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
Description: "entry count",
},
}
}

View File

@@ -0,0 +1,56 @@
/*
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"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/node"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityNodeCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*node.RecordNode, error) {
c := m.(*controller.ControllerCfg)
req := node.GetRequest{NID: uint64(d.Get("node_id").(int))}
log.Debugf("utilityNodeCheckPresence: load node")
nodeInfo, err := c.CloudBroker().Node().Get(ctx, req)
if err != nil {
return nil, err
}
return nodeInfo, nil
}

View File

@@ -0,0 +1,87 @@
/*
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"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/node"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityNodeListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*node.ListNodes, error) {
c := m.(*controller.ControllerCfg)
req := node.ListRequest{}
if byId, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(byId.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if version, ok := d.GetOk("version"); ok {
req.Version = version.(string)
}
if release, ok := d.GetOk("release"); ok {
req.Release = release.(string)
}
if sepId, ok := d.GetOk("sep_id"); ok {
req.SepID = uint64(sepId.(int))
}
if role, ok := d.GetOk("role"); ok {
req.Role = role.(string)
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(string)
}
if Page, ok := d.GetOk("page"); ok {
req.Page = uint64(Page.(int))
}
if Size, ok := d.GetOk("size"); ok {
req.Size = uint64(Size.(int))
}
log.Debugf("utilityNodeListCheckPresence: load node list")
nodeList, err := c.CloudBroker().Node().List(ctx, req)
if err != nil {
return nil, err
}
return nodeList, nil
}