You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
terraform-provider-decort/internal/service/cloudapi/kvmvm/flattens.go

824 lines
28 KiB

/*
2 years ago
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
*/
3 years ago
package kvmvm
import (
"encoding/json"
3 years ago
"sort"
"strconv"
3 years ago
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
3 years ago
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
3 years ago
)
3 years ago
func flattenDisks(disks []compute.InfoDisk) []map[string]interface{} {
3 years ago
res := make([]map[string]interface{}, 0)
3 years ago
for _, disk := range disks {
temp := map[string]interface{}{
1 year ago
"bus_number": disk.BusNumber,
"disk_id": disk.ID,
"pci_slot": disk.PCISlot,
3 years ago
}
res = append(res, temp)
}
return res
}
3 years ago
func flattenQOS(qos compute.QOS) []map[string]interface{} {
3 years ago
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"e_rate": qos.ERate,
"guid": qos.GUID,
"in_brust": qos.InBurst,
"in_rate": qos.InRate,
}
res = append(res, temp)
return res
}
3 years ago
func flattenInterfaces(interfaces compute.ListInterfaces) []map[string]interface{} {
2 years ago
res := make([]map[string]interface{}, 0, len(interfaces))
3 years ago
for _, interfaceItem := range interfaces {
temp := map[string]interface{}{
1 year ago
"bus_number": interfaceItem.BusNumber,
"conn_id": interfaceItem.ConnID,
"conn_type": interfaceItem.ConnType,
"def_gw": interfaceItem.DefGW,
"enabled": interfaceItem.Enabled,
"flip_group_id": interfaceItem.FLIPGroupID,
"guid": interfaceItem.GUID,
"ip_address": interfaceItem.IPAddress,
"listen_ssh": interfaceItem.ListenSSH,
"mac": interfaceItem.MAC,
"mtu": interfaceItem.MTU,
"name": interfaceItem.Name,
"net_id": interfaceItem.NetID,
"netmask": interfaceItem.NetMask,
"net_type": interfaceItem.NetType,
"node_id": interfaceItem.NodeID,
"pci_slot": interfaceItem.PCISlot,
"qos": flattenQOS(interfaceItem.QOS),
"target": interfaceItem.Target,
"type": interfaceItem.Type,
"vnfs": interfaceItem.VNFs,
"libvirt_settings": flattenLibvirtSettings(interfaceItem.LibvirtSettings),
3 years ago
}
res = append(res, temp)
}
return res
}
1 year ago
func flattenLibvirtSettings(libvirtSettings compute.LibvirtSettings) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"guid": libvirtSettings.GUID,
"txmode": libvirtSettings.TXMode,
"ioeventfd": libvirtSettings.IOEventFD,
"event_idx": libvirtSettings.EventIDx,
"queues": libvirtSettings.Queues,
"rx_queue_size": libvirtSettings.RXQueueSize,
"tx_queue_size": libvirtSettings.TXQueueSize,
}
res = append(res, temp)
return res
}
3 years ago
func flattenSnapSets(snapSets compute.ListSnapSets) []map[string]interface{} {
2 years ago
res := make([]map[string]interface{}, 0, len(snapSets))
3 years ago
for _, snapSet := range snapSets {
temp := map[string]interface{}{
"disks": snapSet.Disks,
"guid": snapSet.GUID,
"label": snapSet.Label,
"timestamp": snapSet.Timestamp,
}
res = append(res, temp)
}
return res
}
func flattenTags(tags map[string]string) []map[string]interface{} {
2 years ago
res := make([]map[string]interface{}, 0, len(tags))
3 years ago
for key, val := range tags {
temp := map[string]interface{}{
"key": key,
"val": val,
}
res = append(res, temp)
}
return res
}
3 years ago
func flattenListRules(listRules compute.ListRules) []map[string]interface{} {
2 years ago
res := make([]map[string]interface{}, 0, len(listRules))
3 years ago
for _, rule := range listRules {
temp := map[string]interface{}{
"guid": rule.GUID,
"key": rule.Key,
"mode": rule.Mode,
"policy": rule.Policy,
"topology": rule.Topology,
"value": rule.Value,
}
res = append(res, temp)
}
return res
}
3 years ago
func flattenListACL(listAcl compute.ListACL) []map[string]interface{} {
2 years ago
res := make([]map[string]interface{}, 0, len(listAcl))
3 years ago
for _, acl := range listAcl {
temp := map[string]interface{}{
3 years ago
"explicit": acl.Explicit,
3 years ago
"guid": acl.GUID,
"right": acl.Right,
"status": acl.Status,
"type": acl.Type,
"user_group_id": acl.UserGroupID,
}
res = append(res, temp)
}
return res
}
3 years ago
2 years ago
func flattenComputeList(computes *compute.ListComputes) []map[string]interface{} {
2 years ago
res := make([]map[string]interface{}, 0, len(computes.Data))
2 years ago
for _, compute := range computes.Data {
2 years ago
customFields, _ := json.Marshal(compute.CustomFields)
3 years ago
devices, _ := json.Marshal(compute.Devices)
temp := map[string]interface{}{
"acl": flattenListACL(compute.ACL),
"account_id": compute.AccountID,
"account_name": compute.AccountName,
"affinity_label": compute.AffinityLabel,
"affinity_rules": flattenListRules(compute.AffinityRules),
"affinity_weight": compute.AffinityWeight,
"anti_affinity_rules": flattenListRules(compute.AntiAffinityRules),
"arch": compute.Architecture,
12 months ago
"auto_start_w_node": compute.AutoStart,
3 years ago
"boot_order": compute.BootOrder,
2 years ago
"bootdisk_size": compute.BootDiskSize,
1 year ago
"chipset": compute.Chipset,
2 years ago
"cd_image_id": compute.CdImageId,
3 years ago
"clone_reference": compute.CloneReference,
"clones": compute.Clones,
"computeci_id": compute.ComputeCIID,
2 years ago
"cpu_pin": compute.CPUPin,
3 years ago
"cpus": compute.CPU,
"created_by": compute.CreatedBy,
"created_time": compute.CreatedTime,
2 years ago
"custom_fields": string(customFields),
"deleted_by": compute.DeletedBy,
"deleted_time": compute.DeletedTime,
"desc": compute.Description,
"devices": string(devices),
"disks": flattenDisks(compute.Disks),
"driver": compute.Driver,
"gid": compute.GID,
"guid": compute.GUID,
2 years ago
"hp_backed": compute.HPBacked,
2 years ago
"compute_id": compute.ID,
"image_id": compute.ImageID,
"interfaces": flattenInterfaces(compute.Interfaces),
"lock_status": compute.LockStatus,
"manager_id": compute.ManagerID,
"manager_type": compute.ManagerType,
"migrationjob": compute.MigrationJob,
"milestones": compute.Milestones,
"name": compute.Name,
2 years ago
"need_reboot": compute.NeedReboot,
2 years ago
"numa_affinity": compute.NumaAffinity,
"numa_node_id": compute.NumaNodeId,
2 years ago
"pinned": compute.Pinned,
10 months ago
"preferred_cpu": compute.PreferredCPU,
2 years ago
"ram": compute.RAM,
"reference_id": compute.ReferenceID,
"registered": compute.Registered,
"res_name": compute.ResName,
2 years ago
"reserved_node_cpus": compute.ReservedNodeCpus,
2 years ago
"rg_id": compute.RGID,
"rg_name": compute.RGName,
"snap_sets": flattenSnapSets(compute.SnapSets),
"stateless_sep_id": compute.StatelessSepID,
"stateless_sep_type": compute.StatelessSepType,
"status": compute.Status,
"tags": flattenTags(compute.Tags),
"tech_status": compute.TechStatus,
"total_disk_size": compute.TotalDiskSize,
"updated_by": compute.UpdatedBy,
"updated_time": compute.UpdatedTime,
"user_managed": compute.UserManaged,
"vgpus": compute.VGPUs,
"vins_connected": compute.VINSConnected,
"virtual_image_id": compute.VirtualImageID,
3 years ago
}
res = append(res, temp)
}
return res
}
3 years ago
func flattenBootDisk(bootDisk *compute.ItemComputeDisk) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"disk_name": bootDisk.Name,
"disk_id": bootDisk.ID,
"disk_type": bootDisk.Type,
"sep_id": bootDisk.SepID,
"shareable": bootDisk.Shareable,
"size_max": bootDisk.SizeMax,
"size_used": bootDisk.SizeUsed,
"pool": bootDisk.Pool,
"desc": bootDisk.Description,
"image_id": bootDisk.ImageID,
"size": bootDisk.SizeMax,
}
res = append(res, temp)
return res
}
2 years ago
func flattenComputeDisksDemo(disksList compute.ListComputeDisks, disksBlocks, extraDisks []interface{}, bootDiskId uint64) []map[string]interface{} {
3 years ago
res := make([]map[string]interface{}, 0, len(disksList))
2 years ago
if len(disksBlocks) == 0 {
return res
}
sort.Slice(disksList, func(i, j int) bool {
return disksList[i].ID < disksList[j].ID
})
indexDataDisks := 0
3 years ago
for _, disk := range disksList {
2 years ago
if disk.ID == bootDiskId || findInExtraDisks(uint(disk.ID), extraDisks) { //skip main bootdisk and extraDisks
3 years ago
continue
}
2 years ago
2 years ago
pernamentlyValue := disksBlocks[indexDataDisks].(map[string]interface{})["permanently"].(bool)
2 years ago
3 years ago
temp := map[string]interface{}{
2 years ago
"disk_name": disk.Name,
"disk_id": disk.ID,
"disk_type": disk.Type,
"sep_id": disk.SepID,
"shareable": disk.Shareable,
"size_max": disk.SizeMax,
"size_used": disk.SizeUsed,
"pool": disk.Pool,
"desc": disk.Description,
"image_id": disk.ImageID,
"size": disk.SizeMax,
2 years ago
"permanently": pernamentlyValue,
3 years ago
}
res = append(res, temp)
2 years ago
indexDataDisks++
3 years ago
}
2 years ago
3 years ago
return res
}
1 year ago
func flattenNetwork(networks []interface{}, interfaces compute.ListInterfaces) []map[string]interface{} {
3 years ago
res := make([]map[string]interface{}, 0, len(interfaces))
2 years ago
3 years ago
for _, network := range interfaces {
temp := map[string]interface{}{
"net_id": network.NetID,
"net_type": network.NetType,
"ip_address": network.IPAddress,
"mac": network.MAC,
1 year ago
"mtu": network.MTU,
1 year ago
"weight": flattenNetworkWeight(networks, network.NetID, network.NetType),
3 years ago
}
res = append(res, temp)
}
return res
}
1 year ago
func flattenNetworkWeight(networks []interface{}, netID uint64, netType string) int {
for _, network := range networks {
ns := network.(map[string]interface{})
if ns["net_id"].(int) == int(netID) && ns["net_type"].(string) == netType {
weight := ns["weight"].(int)
return weight
}
}
return 0
}
3 years ago
func findBootDisk(disks compute.ListComputeDisks) *compute.ItemComputeDisk {
3 years ago
for _, disk := range disks {
2 years ago
if disk.Type == "B" {
3 years ago
return &disk
}
}
2 years ago
return &compute.ItemComputeDisk{}
3 years ago
}
1 year ago
func flattenCompute(d *schema.ResourceData, computeRec compute.RecordCompute, pciList *compute.ListPCIDevices) error {
3 years ago
// This function expects that compFacts string contains response from API compute/get,
// i.e. detailed information about compute instance.
//
// NOTE: this function modifies ResourceData argument - as such it should never be called
// from resourceComputeExists(...) method
3 years ago
log.Debugf("flattenCompute: ID %d, RG ID %d", computeRec.ID, computeRec.RGID)
3 years ago
3 years ago
devices, _ := json.Marshal(computeRec.Devices)
bootDisk := findBootDisk(computeRec.Disks)
3 years ago
//check extraDisks, ipa_type, is,
3 years ago
d.SetId(strconv.FormatUint(computeRec.ID, 10))
2 years ago
// d.Set("acl", flattenACL(computeRec.ACL))
3 years ago
d.Set("account_id", computeRec.AccountID)
d.Set("account_name", computeRec.AccountName)
d.Set("affinity_weight", computeRec.AffinityWeight)
d.Set("arch", computeRec.Architecture)
12 months ago
d.Set("auto_start_w_node", computeRec.AutoStart)
3 years ago
d.Set("boot_order", computeRec.BootOrder)
2 years ago
// we intentionally use the SizeMax field, do not change it until the BootDiskSize field is fixed on the platform
3 years ago
d.Set("boot_disk_size", bootDisk.SizeMax)
3 years ago
d.Set("boot_disk", flattenBootDisk(bootDisk))
3 years ago
d.Set("boot_disk_id", bootDisk.ID)
2 years ago
d.Set("cd_image_id", computeRec.CdImageId)
3 years ago
d.Set("sep_id", bootDisk.SepID)
d.Set("pool", bootDisk.Pool)
1 year ago
d.Set("chipset", computeRec.Chipset)
3 years ago
d.Set("clone_reference", computeRec.CloneReference)
d.Set("clones", computeRec.Clones)
d.Set("computeci_id", computeRec.ComputeCIID)
d.Set("created_by", computeRec.CreatedBy)
d.Set("created_time", computeRec.CreatedTime)
2 years ago
// d.Set("custom_fields", flattenCustomFields(computeRec.CustomFields))
3 years ago
d.Set("deleted_by", computeRec.DeletedBy)
d.Set("deleted_time", computeRec.DeletedTime)
d.Set("description", computeRec.Description)
3 years ago
d.Set("devices", string(devices))
2 years ago
err := d.Set("disks", flattenComputeDisksDemo(computeRec.Disks, d.Get("disks").([]interface{}), d.Get("extra_disks").(*schema.Set).List(), bootDisk.ID))
3 years ago
if err != nil {
return err
}
3 years ago
d.Set("driver", computeRec.Driver)
d.Set("cpu", computeRec.CPU)
d.Set("gid", computeRec.GID)
d.Set("guid", computeRec.GUID)
d.Set("compute_id", computeRec.ID)
if computeRec.VirtualImageID != 0 {
d.Set("image_id", computeRec.VirtualImageID)
3 years ago
} else {
3 years ago
d.Set("image_id", computeRec.ImageID)
3 years ago
}
3 years ago
d.Set("interfaces", flattenInterfaces(computeRec.Interfaces))
d.Set("lock_status", computeRec.LockStatus)
d.Set("manager_id", computeRec.ManagerID)
d.Set("manager_type", computeRec.ManagerType)
d.Set("migrationjob", computeRec.MigrationJob)
d.Set("milestones", computeRec.Milestones)
d.Set("name", computeRec.Name)
2 years ago
d.Set("need_reboot", computeRec.NeedReboot)
2 years ago
d.Set("numa_node_id", computeRec.NumaNodeId)
3 years ago
d.Set("natable_vins_id", computeRec.NatableVINSID)
d.Set("natable_vins_ip", computeRec.NatableVINSIP)
d.Set("natable_vins_name", computeRec.NatableVINSName)
d.Set("natable_vins_network", computeRec.NatableVINSNetwork)
d.Set("natable_vins_network_name", computeRec.NatableVINSNetworkName)
if err := d.Set("os_users", parseOsUsers(computeRec.OSUsers)); err != nil {
3 years ago
return err
3 years ago
}
3 years ago
d.Set("pinned", computeRec.Pinned)
10 months ago
d.Set("preferred_cpu", computeRec.PreferredCPU)
3 years ago
d.Set("ram", computeRec.RAM)
d.Set("reference_id", computeRec.ReferenceID)
d.Set("registered", computeRec.Registered)
d.Set("res_name", computeRec.ResName)
2 years ago
d.Set("reserved_node_cpus", computeRec.ReservedNodeCpus)
3 years ago
d.Set("rg_id", computeRec.RGID)
d.Set("rg_name", computeRec.RGName)
d.Set("snap_sets", flattenSnapSets(computeRec.SnapSets))
d.Set("stateless_sep_id", computeRec.StatelessSepID)
d.Set("stateless_sep_type", computeRec.StatelessSepType)
d.Set("status", computeRec.Status)
2 years ago
// d.Set("tags", flattenTags(computeRec.Tags))
3 years ago
d.Set("tech_status", computeRec.TechStatus)
d.Set("updated_by", computeRec.UpdatedBy)
d.Set("updated_time", computeRec.UpdatedTime)
d.Set("user_managed", computeRec.UserManaged)
12 months ago
d.Set("vnc_password", computeRec.VNCPassword)
3 years ago
d.Set("vgpus", computeRec.VGPUs)
d.Set("virtual_image_id", computeRec.VirtualImageID)
d.Set("virtual_image_name", computeRec.VirtualImageName)
3 years ago
3 years ago
d.Set("enabled", false)
3 years ago
if computeRec.Status == status.Enabled {
3 years ago
d.Set("enabled", true)
}
d.Set("started", false)
3 years ago
if computeRec.TechStatus == "STARTED" {
3 years ago
d.Set("started", true)
}
1 year ago
d.Set("network", flattenNetwork(d.Get("network").(*schema.Set).List(), computeRec.Interfaces))
1 year ago
d.Set("pci_devices", flattenPCI(*pciList))
3 years ago
3 years ago
return nil
}
3 years ago
func flattenACL(acl compute.RecordACL) []map[string]interface{} {
3 years ago
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"account_acl": flattenListACL(acl.AccountACL),
"compute_acl": flattenListACL(acl.ComputeACL),
"rg_acl": flattenListACL(acl.RGACL),
}
res = append(res, temp)
return res
}
3 years ago
func flattenAffinityRules(affinityRules compute.ListRules) []map[string]interface{} {
2 years ago
res := make([]map[string]interface{}, 0, len(affinityRules))
3 years ago
for _, affinityRule := range affinityRules {
temp := map[string]interface{}{
"guid": affinityRule.GUID,
"key": affinityRule.Key,
"mode": affinityRule.Mode,
"policy": affinityRule.Policy,
"topology": affinityRule.Topology,
"value": affinityRule.Value,
3 years ago
}
3 years ago
res = append(res, temp)
3 years ago
}
3 years ago
return res
}
3 years ago
func flattenIotune(iotune compute.IOTune) []map[string]interface{} {
3 years ago
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"read_bytes_sec": iotune.ReadBytesSec,
"read_bytes_sec_max": iotune.ReadBytesSecMax,
"read_iops_sec": iotune.ReadIOPSSec,
"read_iops_sec_max": iotune.ReadIOPSSecMax,
"size_iops_sec": iotune.SizeIOPSSec,
"total_bytes_sec": iotune.TotalBytesSec,
"total_bytes_sec_max": iotune.TotalBytesSecMax,
"total_iops_sec": iotune.TotalIOPSSec,
"total_iops_sec_max": iotune.TotalIOPSSecMax,
"write_bytes_sec": iotune.WriteBytesSec,
"write_bytes_sec_max": iotune.WriteBytesSecMax,
"write_iops_sec": iotune.WriteIOPSSec,
"write_iops_sec_max": iotune.WriteIOPSSecMax,
}
res = append(res, temp)
return res
}
3 years ago
func flattenSnapshots(snapshots compute.SnapshotExtendList) []map[string]interface{} {
2 years ago
res := make([]map[string]interface{}, 0, len(snapshots))
3 years ago
for _, snapshot := range snapshots {
temp := map[string]interface{}{
"guid": snapshot.GUID,
"label": snapshot.Label,
"res_id": snapshot.ResID,
2 years ago
"reference_id": snapshot.ReferenceID,
3 years ago
"snap_set_guid": snapshot.SnapSetGUID,
"snap_set_time": snapshot.SnapSetTime,
"timestamp": snapshot.TimeStamp,
3 years ago
}
3 years ago
res = append(res, temp)
3 years ago
}
3 years ago
return res
}
3 years ago
func flattenListComputeDisks(disks compute.ListComputeDisks) []map[string]interface{} {
2 years ago
res := make([]map[string]interface{}, 0, len(disks))
3 years ago
for _, disk := range disks {
acl, _ := json.Marshal(disk.ACL)
temp := map[string]interface{}{
"_ckey": disk.CKey,
"acl": string(acl),
"account_id": disk.AccountID,
"boot_partition": disk.BootPartition,
1 year ago
"bus_number": disk.BusNumber,
3 years ago
"created_time": disk.CreatedTime,
"deleted_time": disk.DeletedTime,
"description": disk.Description,
"destruction_time": disk.DestructionTime,
"disk_path": disk.DiskPath,
"gid": disk.GID,
"guid": disk.GUID,
"disk_id": disk.ID,
"image_id": disk.ImageID,
"images": disk.Images,
"iotune": flattenIotune(disk.IOTune),
"iqn": disk.IQN,
"login": disk.Login,
"milestones": disk.Milestones,
"name": disk.Name,
"order": disk.Order,
"params": disk.Params,
"parent_id": disk.ParentID,
"passwd": disk.Passwd,
"pci_slot": disk.PCISlot,
"pool": disk.Pool,
"present_to": disk.PresentTo,
"purge_time": disk.PurgeTime,
2 years ago
"replication": flattenDiskReplication(disk.Replication),
3 years ago
"reality_device_number": disk.RealityDeviceNumber,
"res_id": disk.ResID,
"role": disk.Role,
"sep_id": disk.SepID,
"shareable": disk.Shareable,
"size_max": disk.SizeMax,
"size_used": disk.SizeUsed,
"snapshots": flattenSnapshots(disk.Snapshots),
"status": disk.Status,
"tech_status": disk.TechStatus,
"type": disk.Type,
"vmid": disk.VMID,
}
res = append(res, temp)
3 years ago
}
3 years ago
return res
}
2 years ago
func flattenDiskReplication(rep compute.ItemReplication) []map[string]interface{} {
res := []map[string]interface{}{
{
"disk_id": rep.DiskID,
"pool_id": rep.PoolID,
"role": rep.Role,
"self_volume_id": rep.SelfVolumeID,
"storage_id": rep.StorageID,
"volume_id": rep.VolumeID,
},
}
return res
}
2 years ago
func flattenCustomFields(customFields map[string]interface{}) string {
encoded, _ := json.Marshal(customFields)
return string(encoded)
3 years ago
}
2 years ago
3 years ago
func flattenOsUsers(osUsers compute.ListOSUser) []map[string]interface{} {
2 years ago
res := make([]map[string]interface{}, 0, len(osUsers))
3 years ago
for _, user := range osUsers {
temp := map[string]interface{}{
"guid": user.GUID,
"login": user.Login,
"password": user.Password,
"public_key": user.PubKey,
}
res = append(res, temp)
}
return res
}
1 year ago
func flattenDataCompute(d *schema.ResourceData, computeRec compute.RecordCompute, pciList *compute.ListPCIDevices) {
3 years ago
devices, _ := json.Marshal(computeRec.Devices)
userdata, _ := json.Marshal(computeRec.Userdata)
d.Set("acl", flattenACL(computeRec.ACL))
d.Set("account_id", computeRec.AccountID)
d.Set("account_name", computeRec.AccountName)
d.Set("affinity_label", computeRec.AffinityLabel)
d.Set("affinity_rules", flattenAffinityRules(computeRec.AffinityRules))
d.Set("affinity_weight", computeRec.AffinityWeight)
d.Set("anti_affinity_rules", flattenListRules(computeRec.AntiAffinityRules))
12 months ago
d.Set("auto_start_w_node", computeRec.AutoStart)
3 years ago
d.Set("arch", computeRec.Architecture)
1 year ago
d.Set("chipset", computeRec.Chipset)
3 years ago
d.Set("boot_order", computeRec.BootOrder)
2 years ago
d.Set("bootdisk_size", computeRec.BootDiskSize)
d.Set("cd_image_id", computeRec.CdImageId)
3 years ago
d.Set("clone_reference", computeRec.CloneReference)
d.Set("clones", computeRec.Clones)
d.Set("computeci_id", computeRec.ComputeCIID)
2 years ago
d.Set("cpu_pin", computeRec.CPUPin)
3 years ago
d.Set("cpus", computeRec.CPU)
d.Set("created_by", computeRec.CreatedBy)
d.Set("created_time", computeRec.CreatedTime)
2 years ago
d.Set("custom_fields", flattenCustomFields(computeRec.CustomFields))
3 years ago
d.Set("deleted_by", computeRec.DeletedBy)
d.Set("deleted_time", computeRec.DeletedTime)
d.Set("desc", computeRec.Description)
3 years ago
d.Set("devices", string(devices))
3 years ago
d.Set("disks", flattenListComputeDisks(computeRec.Disks))
d.Set("driver", computeRec.Driver)
d.Set("gid", computeRec.GID)
d.Set("guid", computeRec.GUID)
2 years ago
d.Set("hp_backed", computeRec.HPBacked)
3 years ago
d.Set("compute_id", computeRec.ID)
d.Set("image_id", computeRec.ImageID)
2 years ago
d.Set("image_name", computeRec.ImageName)
3 years ago
d.Set("interfaces", flattenInterfaces(computeRec.Interfaces))
d.Set("lock_status", computeRec.LockStatus)
d.Set("manager_id", computeRec.ManagerID)
d.Set("manager_type", computeRec.ManagerType)
d.Set("migrationjob", computeRec.MigrationJob)
d.Set("milestones", computeRec.Milestones)
d.Set("name", computeRec.Name)
2 years ago
d.Set("need_reboot", computeRec.NeedReboot)
2 years ago
d.Set("numa_affinity", computeRec.NumaAffinity)
d.Set("numa_node_id", computeRec.NumaNodeId)
3 years ago
d.Set("natable_vins_id", computeRec.NatableVINSID)
d.Set("natable_vins_ip", computeRec.NatableVINSIP)
d.Set("natable_vins_name", computeRec.NatableVINSName)
d.Set("natable_vins_network", computeRec.NatableVINSNetwork)
d.Set("natable_vins_network_name", computeRec.NatableVINSNetworkName)
d.Set("os_users", flattenOsUsers(computeRec.OSUsers))
d.Set("pinned", computeRec.Pinned)
10 months ago
d.Set("preferred_CPU", computeRec.PreferredCPU)
3 years ago
d.Set("ram", computeRec.RAM)
d.Set("reference_id", computeRec.ReferenceID)
d.Set("registered", computeRec.Registered)
d.Set("res_name", computeRec.ResName)
2 years ago
d.Set("reserved_node_cpus", computeRec.ReservedNodeCpus)
3 years ago
d.Set("rg_id", computeRec.RGID)
d.Set("rg_name", computeRec.RGName)
d.Set("snap_sets", flattenSnapSets(computeRec.SnapSets))
d.Set("stateless_sep_id", computeRec.StatelessSepID)
d.Set("stateless_sep_type", computeRec.StatelessSepType)
d.Set("status", computeRec.Status)
d.Set("tags", computeRec.Tags)
d.Set("tech_status", computeRec.TechStatus)
d.Set("updated_by", computeRec.UpdatedBy)
d.Set("updated_time", computeRec.UpdatedTime)
d.Set("user_managed", computeRec.UserManaged)
3 years ago
d.Set("userdata", string(userdata))
12 months ago
d.Set("vnc_password", computeRec.VNCPassword)
3 years ago
d.Set("vgpus", computeRec.VGPUs)
d.Set("virtual_image_id", computeRec.VirtualImageID)
d.Set("virtual_image_name", computeRec.VirtualImageName)
1 year ago
d.Set("pci_devices", flattenPCI(*pciList))
}
func flattenPCI(pciList compute.ListPCIDevices) []uint64 {
res := make([]uint64, 0, len(pciList.Data))
for _, v := range pciList.Data {
res = append(res, v.ID)
}
return res
3 years ago
}
3 years ago
func flattenComputeAudits(computeAudits compute.ListAudits) []map[string]interface{} {
2 years ago
res := make([]map[string]interface{}, 0, len(computeAudits))
3 years ago
for _, computeAudit := range computeAudits {
temp := map[string]interface{}{
"call": computeAudit.Call,
"responsetime": computeAudit.ResponseTime,
"statuscode": computeAudit.StatusCode,
"timestamp": computeAudit.Timestamp,
"user": computeAudit.User,
}
res = append(res, temp)
}
return res
}
2 years ago
func flattenPfwList(computePfws *compute.ListPFWs) []map[string]interface{} {
2 years ago
res := make([]map[string]interface{}, 0, len(computePfws.Data))
2 years ago
for _, computePfw := range computePfws.Data {
3 years ago
temp := map[string]interface{}{
"pfw_id": computePfw.ID,
"local_ip": computePfw.LocalIP,
"local_port": computePfw.LocalPort,
"protocol": computePfw.Protocol,
"public_port_end": computePfw.PublicPortEnd,
"public_port_start": computePfw.PublicPortStart,
"vm_id": computePfw.VMID,
}
res = append(res, temp)
}
return res
}
2 years ago
func flattenUserList(d *schema.ResourceData, userList *compute.ListUsers) {
d.Set("account_acl", flattenListACL(userList.Data.AccountACL))
d.Set("compute_acl", flattenListACL(userList.Data.ComputeACL))
d.Set("rg_acl", flattenListACL(userList.Data.RGACL))
3 years ago
}
3 years ago
func flattenComputeGetAudits(computeAudits compute.ListShortAudits) []map[string]interface{} {
2 years ago
res := make([]map[string]interface{}, 0, len(computeAudits))
3 years ago
for _, computeAudit := range computeAudits {
temp := map[string]interface{}{
"epoch": computeAudit.Epoch,
"message": computeAudit.Message,
}
res = append(res, temp)
}
return res
3 years ago
}
3 years ago
3 years ago
func flattenSnapshotUsage(computeSnapshotUsages compute.ListUsageSnapshots) []map[string]interface{} {
2 years ago
res := make([]map[string]interface{}, 0, len(computeSnapshotUsages))
3 years ago
for _, computeUsage := range computeSnapshotUsages {
3 years ago
temp := map[string]interface{}{
"count": computeUsage.Count,
"stored": computeUsage.Stored,
"label": computeUsage.Label,
"timestamp": computeUsage.Timestamp,
}
res = append(res, temp)
}
return res
}
2 years ago
2 years ago
// func flattenSnapshotList(computeSnapshotUsages *compute.ListSnapShots) []map[string]interface{} {
// res := make([]map[string]interface{}, 0, len(computeSnapshotUsages.Data))
// for _, computeUsage := range computeSnapshotUsages.Data {
// temp := map[string]interface{}{
// "disks": computeUsage.Disks,
// "guid": computeUsage.GUID,
// "label": computeUsage.Label,
// "timestamp": computeUsage.Timestamp,
// }
// res = append(res, temp)
// }
// return res
// }
2 years ago
2 years ago
func flattenVGPU(vgpuList []compute.ItemVGPU) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(vgpuList))
for _, dev := range vgpuList {
temp := map[string]interface{}{
"account_id": dev.AccountID,
"created_time": dev.CreatedTime,
"deleted_time": dev.DeletedTime,
"gid": dev.GID,
"guid": dev.GUID,
"vgpu_id": dev.ID,
"last_claimed_by": dev.LastClaimedBy,
"last_update_time": dev.LastUpdateTime,
"mode": dev.Mode,
"pci_slot": dev.PCISlot,
"pgpuid": dev.PGPUID,
"profile_id": dev.ProfileID,
"ram": dev.RAM,
"reference_id": dev.ReferenceID,
"rg_id": dev.RGID,
"status": dev.Status,
"type": dev.Type,
"vm_id": dev.VMID,
2 years ago
}
2 years ago
res = append(res, temp)
2 years ago
}
2 years ago
return res
2 years ago
}
2 years ago
func flattenPCIDevice(deviceList []compute.ItemPCIDevice) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(deviceList))
for _, dev := range deviceList {
temp := map[string]interface{}{
"compute_id": dev.ComputeID,
"description": dev.Description,
"guid": dev.GUID,
"hwpath": dev.HwPath,
"device_id": dev.ID,
"name": dev.Name,
"rg_id": dev.RGID,
"stack_id": dev.StackID,
"status": dev.Status,
"system_name": dev.SystemName,
2 years ago
}
2 years ago
res = append(res, temp)
2 years ago
}
2 years ago
return res
2 years ago
}