4.0.0
This commit is contained in:
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
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 kvmvm
|
||||
|
||||
const (
|
||||
KvmX86CreateAPI = "/restmachine/cloudapi/kvmx86/create"
|
||||
KvmPPCCreateAPI = "/restmachine/cloudapi/kvmppc/create"
|
||||
ComputeGetAPI = "/restmachine/cloudapi/compute/get"
|
||||
RgListComputesAPI = "/restmachine/cloudapi/rg/listComputes"
|
||||
ComputeNetAttachAPI = "/restmachine/cloudapi/compute/netAttach"
|
||||
ComputeNetDetachAPI = "/restmachine/cloudapi/compute/netDetach"
|
||||
ComputeDiskAttachAPI = "/restmachine/cloudapi/compute/diskAttach"
|
||||
ComputeDiskDetachAPI = "/restmachine/cloudapi/compute/diskDetach"
|
||||
ComputeStartAPI = "/restmachine/cloudapi/compute/start"
|
||||
ComputeStopAPI = "/restmachine/cloudapi/compute/stop"
|
||||
ComputeResizeAPI = "/restmachine/cloudapi/compute/resize"
|
||||
DisksResizeAPI = "/restmachine/cloudapi/disks/resize2"
|
||||
ComputeDeleteAPI = "/restmachine/cloudapi/compute/delete"
|
||||
ComputeUpdateAPI = "/restmachine/cloudapi/compute/update"
|
||||
ComputeDiskAddAPI = "/restmachine/cloudapi/compute/diskAdd"
|
||||
ComputeDiskDeleteAPI = "/restmachine/cloudapi/compute/diskDel"
|
||||
ComputeRestoreAPI = "/restmachine/cloudapi/compute/restore"
|
||||
ComputeEnableAPI = "/restmachine/cloudapi/compute/enable"
|
||||
ComputeDisableAPI = "/restmachine/cloudapi/compute/disable"
|
||||
ComputeAffinityLabelSetAPI = "/restmachine/cloudapi/compute/affinityLabelSet"
|
||||
ComputeAffinityLabelRemoveAPI = "/restmachine/cloudapi/compute/affinityLabelRemove"
|
||||
ComputeAffinityRuleAddAPI = "/restmachine/cloudapi/compute/affinityRuleAdd"
|
||||
ComputeAffinityRuleRemoveAPI = "/restmachine/cloudapi/compute/affinityRuleRemove"
|
||||
ComputeAffinityRulesClearAPI = "/restmachine/cloudapi/compute/affinityRulesClear"
|
||||
ComputeAntiAffinityRuleAddAPI = "/restmachine/cloudapi/compute/antiAffinityRuleAdd"
|
||||
ComputeAntiAffinityRuleRemoveAPI = "/restmachine/cloudapi/compute/antiAffinityRuleRemove"
|
||||
ComputeAntiAffinityRulesClearAPI = "/restmachine/cloudapi/compute/antiAffinityRulesClear"
|
||||
ComputeListAPI = "/restmachine/cloudapi/compute/list"
|
||||
ComputeAuditsAPI = "/restmachine/cloudapi/compute/audits"
|
||||
ComputeGetAuditsAPI = "/restmachine/cloudapi/compute/getAudits"
|
||||
ComputeGetConsoleUrlAPI = "/restmachine/cloudapi/compute/getConsoleUrl"
|
||||
ComputeGetLogAPI = "/restmachine/cloudapi/compute/getLog"
|
||||
ComputePfwListAPI = "/restmachine/cloudapi/compute/pfwList"
|
||||
ComputeUserListAPI = "/restmachine/cloudapi/compute/userList"
|
||||
ComputeTagAddAPI = "/restmachine/cloudapi/compute/tagAdd"
|
||||
ComputeTagRemoveAPI = "/restmachine/cloudapi/compute/tagRemove"
|
||||
ComputePinToStackAPI = "/restmachine/cloudapi/compute/pinToStack"
|
||||
ComputeUnpinFromStackAPI = "/restmachine/cloudapi/compute/unpinFromStack"
|
||||
ComputePfwAddAPI = "/restmachine/cloudapi/compute/pfwAdd"
|
||||
ComputePfwDelAPI = "/restmachine/cloudapi/compute/pfwDel"
|
||||
ComputeUserGrantAPI = "/restmachine/cloudapi/compute/userGrant"
|
||||
ComputeUserRevokeAPI = "/restmachine/cloudapi/compute/userRevoke"
|
||||
ComputeSnapshotCreateAPI = "/restmachine/cloudapi/compute/snapshotCreate"
|
||||
ComputeSnapshotDeleteAPI = "/restmachine/cloudapi/compute/snapshotCreate"
|
||||
ComputeSnapshotUsageAPI = "/restmachine/cloudapi/compute/snapshotUsage"
|
||||
ComputeSnapshotRollbackAPI = "/restmachine/cloudapi/compute/snapshotRollback"
|
||||
ComputePauseAPI = "/restmachine/cloudapi/compute/pause"
|
||||
ComputeResumeAPI = "/restmachine/cloudapi/compute/resume"
|
||||
ComputeCdInsertAPI = "/restmachine/cloudapi/compute/cdInsert"
|
||||
ComputeCdEjectAPI = "/restmachine/cloudapi/compute/cdEject"
|
||||
ComputeResetAPI = "/restmachine/cloudapi/compute/reset"
|
||||
ComputeRedeployAPI = "/restmachine/cloudapi/compute/redeploy"
|
||||
)
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func dataSourceComputeSnapshotUsageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
computeSnapshotUsage, err := utilityComputeSnapshotUasgeCheckPresence(ctx, d, m)
|
||||
computeSnapshotUsage, err := utilityComputeSnapshotUsageCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
@@ -39,10 +39,11 @@ import (
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
|
||||
)
|
||||
|
||||
func flattenDisks(disks []InfoDisk) []map[string]interface{} {
|
||||
func flattenDisks(disks []compute.InfoDisk) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, disk := range disks {
|
||||
temp := map[string]interface{}{
|
||||
@@ -53,7 +54,7 @@ func flattenDisks(disks []InfoDisk) []map[string]interface{} {
|
||||
}
|
||||
return res
|
||||
}
|
||||
func flattenQOS(qos QOS) []map[string]interface{} {
|
||||
func flattenQOS(qos compute.QOS) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"e_rate": qos.ERate,
|
||||
@@ -64,7 +65,7 @@ func flattenQOS(qos QOS) []map[string]interface{} {
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
func flattenInterfaces(interfaces ListInterfaces) []map[string]interface{} {
|
||||
func flattenInterfaces(interfaces compute.ListInterfaces) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, interfaceItem := range interfaces {
|
||||
temp := map[string]interface{}{
|
||||
@@ -90,7 +91,7 @@ func flattenInterfaces(interfaces ListInterfaces) []map[string]interface{} {
|
||||
}
|
||||
return res
|
||||
}
|
||||
func flattenSnapSets(snapSets ListSnapSets) []map[string]interface{} {
|
||||
func flattenSnapSets(snapSets compute.ListSnapSets) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, snapSet := range snapSets {
|
||||
temp := map[string]interface{}{
|
||||
@@ -115,7 +116,7 @@ func flattenTags(tags map[string]string) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenListRules(listRules ListRules) []map[string]interface{} {
|
||||
func flattenListRules(listRules compute.ListRules) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, rule := range listRules {
|
||||
temp := map[string]interface{}{
|
||||
@@ -130,18 +131,11 @@ func flattenListRules(listRules ListRules) []map[string]interface{} {
|
||||
}
|
||||
return res
|
||||
}
|
||||
func flattenListACL(listAcl ListACL) []map[string]interface{} {
|
||||
func flattenListACL(listAcl compute.ListACL) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, acl := range listAcl {
|
||||
var explicit interface{}
|
||||
switch acl.Explicit.(type) { //Платформенный хак
|
||||
case bool:
|
||||
explicit = acl.Explicit.(bool)
|
||||
case string:
|
||||
explicit, _ = strconv.ParseBool(acl.Explicit.(string))
|
||||
}
|
||||
temp := map[string]interface{}{
|
||||
"explicit": explicit,
|
||||
"explicit": acl.Explicit,
|
||||
"guid": acl.GUID,
|
||||
"right": acl.Right,
|
||||
"status": acl.Status,
|
||||
@@ -152,7 +146,8 @@ func flattenListACL(listAcl ListACL) []map[string]interface{} {
|
||||
}
|
||||
return res
|
||||
}
|
||||
func flattenComputeList(computes ListComputes) []map[string]interface{} {
|
||||
|
||||
func flattenComputeList(computes compute.ListComputes) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, compute := range computes {
|
||||
customFields, _ := json.Marshal(compute.CustomFields)
|
||||
@@ -219,7 +214,29 @@ func flattenComputeList(computes ListComputes) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenComputeDisksDemo(disksList ListComputeDisks, extraDisks []interface{}) []map[string]interface{} {
|
||||
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
|
||||
}
|
||||
|
||||
func flattenComputeDisksDemo(disksList compute.ListComputeDisks, extraDisks []interface{}) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(disksList))
|
||||
for _, disk := range disksList {
|
||||
if disk.Name == "bootdisk" || findInExtraDisks(uint(disk.ID), extraDisks) { //skip main bootdisk and extraDisks
|
||||
@@ -246,7 +263,7 @@ func flattenComputeDisksDemo(disksList ListComputeDisks, extraDisks []interface{
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenNetwork(interfaces ListInterfaces) []map[string]interface{} {
|
||||
func flattenNetwork(interfaces compute.ListInterfaces) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(interfaces))
|
||||
//index := 0
|
||||
for _, network := range interfaces {
|
||||
@@ -261,7 +278,7 @@ func flattenNetwork(interfaces ListInterfaces) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func findBootDisk(disks ListComputeDisks) *ItemComputeDisk {
|
||||
func findBootDisk(disks compute.ListComputeDisks) *compute.ItemComputeDisk {
|
||||
for _, disk := range disks {
|
||||
if disk.Name == "bootdisk" {
|
||||
return &disk
|
||||
@@ -270,139 +287,109 @@ func findBootDisk(disks ListComputeDisks) *ItemComputeDisk {
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenCompute(d *schema.ResourceData, compute RecordCompute) error {
|
||||
func flattenCompute(d *schema.ResourceData, computeRec compute.RecordCompute) error {
|
||||
// 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
|
||||
log.Debugf("flattenCompute: ID %d, RG ID %d", compute.ID, compute.RGID)
|
||||
log.Debugf("flattenCompute: ID %d, RG ID %d", computeRec.ID, computeRec.RGID)
|
||||
|
||||
devices, _ := json.Marshal(compute.Devices)
|
||||
userdata, _ := json.Marshal(compute.Userdata)
|
||||
devices, _ := json.Marshal(computeRec.Devices)
|
||||
userdata, _ := json.Marshal(computeRec.Userdata)
|
||||
bootDisk := findBootDisk(computeRec.Disks)
|
||||
|
||||
//check extraDisks, ipa_type, is,
|
||||
d.SetId(strconv.FormatUint(compute.ID, 10))
|
||||
d.Set("acl", flattenACL(compute.ACL))
|
||||
d.Set("account_id", compute.AccountID)
|
||||
d.Set("account_name", compute.AccountName)
|
||||
d.Set("affinity_weight", compute.AffinityWeight)
|
||||
d.Set("arch", compute.Architecture)
|
||||
d.Set("boot_order", compute.BootOrder)
|
||||
d.Set("boot_disk_size", compute.BootDiskSize)
|
||||
bootDisk := findBootDisk(compute.Disks)
|
||||
d.SetId(strconv.FormatUint(computeRec.ID, 10))
|
||||
d.Set("acl", flattenACL(computeRec.ACL))
|
||||
d.Set("account_id", computeRec.AccountID)
|
||||
d.Set("account_name", computeRec.AccountName)
|
||||
d.Set("affinity_weight", computeRec.AffinityWeight)
|
||||
d.Set("arch", computeRec.Architecture)
|
||||
d.Set("boot_order", computeRec.BootOrder)
|
||||
d.Set("boot_disk_size", computeRec.BootDiskSize)
|
||||
d.Set("boot_disk", flattenBootDisk(bootDisk))
|
||||
d.Set("boot_disk_id", bootDisk.ID)
|
||||
d.Set("sep_id", bootDisk.SepID)
|
||||
d.Set("pool", bootDisk.Pool)
|
||||
d.Set("clone_reference", compute.CloneReference)
|
||||
d.Set("clones", compute.Clones)
|
||||
d.Set("clone_reference", computeRec.CloneReference)
|
||||
d.Set("clones", computeRec.Clones)
|
||||
if string(userdata) != "{}" {
|
||||
d.Set("cloud_init", string(userdata))
|
||||
}
|
||||
d.Set("computeci_id", compute.ComputeCIID)
|
||||
d.Set("created_by", compute.CreatedBy)
|
||||
d.Set("created_time", compute.CreatedTime)
|
||||
d.Set("custom_fields", flattenCustomFields(compute.CustomFields))
|
||||
d.Set("deleted_by", compute.DeletedBy)
|
||||
d.Set("deleted_time", compute.DeletedTime)
|
||||
d.Set("description", compute.Description)
|
||||
d.Set("computeci_id", computeRec.ComputeCIID)
|
||||
d.Set("created_by", computeRec.CreatedBy)
|
||||
d.Set("created_time", computeRec.CreatedTime)
|
||||
d.Set("custom_fields", flattenCustomFields(computeRec.CustomFields))
|
||||
d.Set("deleted_by", computeRec.DeletedBy)
|
||||
d.Set("deleted_time", computeRec.DeletedTime)
|
||||
d.Set("description", computeRec.Description)
|
||||
d.Set("devices", string(devices))
|
||||
err := d.Set("disks", flattenComputeDisksDemo(compute.Disks, d.Get("extra_disks").(*schema.Set).List()))
|
||||
err := d.Set("disks", flattenComputeDisksDemo(computeRec.Disks, d.Get("extra_disks").(*schema.Set).List()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.Set("driver", compute.Driver)
|
||||
d.Set("cpu", compute.CPU)
|
||||
d.Set("gid", compute.GID)
|
||||
d.Set("guid", compute.GUID)
|
||||
d.Set("compute_id", compute.ID)
|
||||
if compute.VirtualImageID != 0 {
|
||||
d.Set("image_id", compute.VirtualImageID)
|
||||
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)
|
||||
} else {
|
||||
d.Set("image_id", compute.ImageID)
|
||||
d.Set("image_id", computeRec.ImageID)
|
||||
}
|
||||
d.Set("interfaces", flattenInterfaces(compute.Interfaces))
|
||||
d.Set("lock_status", compute.LockStatus)
|
||||
d.Set("manager_id", compute.ManagerID)
|
||||
d.Set("manager_type", compute.ManagerType)
|
||||
d.Set("migrationjob", compute.MigrationJob)
|
||||
d.Set("milestones", compute.Milestones)
|
||||
d.Set("name", compute.Name)
|
||||
d.Set("natable_vins_id", compute.NatableVINSID)
|
||||
d.Set("natable_vins_ip", compute.NatableVINSIP)
|
||||
d.Set("natable_vins_name", compute.NatableVINSName)
|
||||
d.Set("natable_vins_network", compute.NatableVINSNetwork)
|
||||
d.Set("natable_vins_network_name", compute.NatableVINSNetworkName)
|
||||
if err := d.Set("os_users", parseOsUsers(compute.OSUsers)); err != nil {
|
||||
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)
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
d.Set("pinned", compute.Pinned)
|
||||
d.Set("ram", compute.RAM)
|
||||
d.Set("reference_id", compute.ReferenceID)
|
||||
d.Set("registered", compute.Registered)
|
||||
d.Set("res_name", compute.ResName)
|
||||
d.Set("rg_id", compute.RGID)
|
||||
d.Set("rg_name", compute.RGName)
|
||||
d.Set("snap_sets", flattenSnapSets(compute.SnapSets))
|
||||
d.Set("stateless_sep_id", compute.StatelessSepID)
|
||||
d.Set("stateless_sep_type", compute.StatelessSepType)
|
||||
d.Set("status", compute.Status)
|
||||
d.Set("tags", flattenTags(compute.Tags))
|
||||
d.Set("tech_status", compute.TechStatus)
|
||||
d.Set("updated_by", compute.UpdatedBy)
|
||||
d.Set("updated_time", compute.UpdatedTime)
|
||||
d.Set("user_managed", compute.UserManaged)
|
||||
d.Set("vgpus", compute.VGPUs)
|
||||
d.Set("virtual_image_id", compute.VirtualImageID)
|
||||
d.Set("virtual_image_name", compute.VirtualImageName)
|
||||
d.Set("pinned", computeRec.Pinned)
|
||||
d.Set("ram", computeRec.RAM)
|
||||
d.Set("reference_id", computeRec.ReferenceID)
|
||||
d.Set("registered", computeRec.Registered)
|
||||
d.Set("res_name", computeRec.ResName)
|
||||
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", flattenTags(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)
|
||||
d.Set("vgpus", computeRec.VGPUs)
|
||||
d.Set("virtual_image_id", computeRec.VirtualImageID)
|
||||
d.Set("virtual_image_name", computeRec.VirtualImageName)
|
||||
|
||||
d.Set("enabled", false)
|
||||
if compute.Status == status.Enabled {
|
||||
if computeRec.Status == status.Enabled {
|
||||
d.Set("enabled", true)
|
||||
}
|
||||
|
||||
d.Set("started", false)
|
||||
if compute.TechStatus == "STARTED" {
|
||||
if computeRec.TechStatus == "STARTED" {
|
||||
d.Set("started", true)
|
||||
}
|
||||
|
||||
d.Set("network", flattenNetwork(compute.Interfaces))
|
||||
|
||||
//if len(model.Disks) > 0 {
|
||||
//log.Debugf("flattenCompute: calling parseComputeDisksToExtraDisks for %d disks", len(model.Disks))
|
||||
//if err = d.Set("extra_disks", parseComputeDisksToExtraDisks(model.Disks)); err != nil {
|
||||
//return err
|
||||
//}
|
||||
//}
|
||||
d.Set("network", flattenNetwork(computeRec.Interfaces))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenDataComputeDisksDemo(disksList ListComputeDisks, extraDisks []interface{}) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, disk := range disksList {
|
||||
if findInExtraDisks(uint(disk.ID), extraDisks) { //skip main bootdisk and extraDisks
|
||||
continue
|
||||
}
|
||||
temp := map[string]interface{}{
|
||||
"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,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenACL(acl RecordACL) []map[string]interface{} {
|
||||
func flattenACL(acl compute.RecordACL) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"account_acl": flattenListACL(acl.AccountACL),
|
||||
@@ -413,7 +400,7 @@ func flattenACL(acl RecordACL) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenAffinityRules(affinityRules ListRules) []map[string]interface{} {
|
||||
func flattenAffinityRules(affinityRules compute.ListRules) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, affinityRule := range affinityRules {
|
||||
temp := map[string]interface{}{
|
||||
@@ -430,7 +417,7 @@ func flattenAffinityRules(affinityRules ListRules) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenIotune(iotune IOTune) []map[string]interface{} {
|
||||
func flattenIotune(iotune compute.IOTune) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"read_bytes_sec": iotune.ReadBytesSec,
|
||||
@@ -452,7 +439,7 @@ func flattenIotune(iotune IOTune) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenSnapshots(snapshots SnapshotExtendList) []map[string]interface{} {
|
||||
func flattenSnapshots(snapshots compute.SnapshotExtendList) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, snapshot := range snapshots {
|
||||
temp := map[string]interface{}{
|
||||
@@ -469,7 +456,7 @@ func flattenSnapshots(snapshots SnapshotExtendList) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenListComputeDisks(disks ListComputeDisks) []map[string]interface{} {
|
||||
func flattenListComputeDisks(disks compute.ListComputeDisks) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, disk := range disks {
|
||||
acl, _ := json.Marshal(disk.ACL)
|
||||
@@ -532,7 +519,7 @@ func flattenCustomFields(customFileds map[string]interface{}) []map[string]inter
|
||||
}
|
||||
return res
|
||||
}
|
||||
func flattenOsUsers(osUsers ListOSUser) []map[string]interface{} {
|
||||
func flattenOsUsers(osUsers compute.ListOSUser) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, user := range osUsers {
|
||||
temp := map[string]interface{}{
|
||||
@@ -546,72 +533,72 @@ func flattenOsUsers(osUsers ListOSUser) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenDataCompute(d *schema.ResourceData, compute RecordCompute) {
|
||||
devices, _ := json.Marshal(compute.Devices)
|
||||
userdata, _ := json.Marshal(compute.Userdata)
|
||||
d.Set("acl", flattenACL(compute.ACL))
|
||||
d.Set("account_id", compute.AccountID)
|
||||
d.Set("account_name", compute.AccountName)
|
||||
d.Set("affinity_label", compute.AffinityLabel)
|
||||
d.Set("affinity_rules", flattenAffinityRules(compute.AffinityRules))
|
||||
d.Set("affinity_weight", compute.AffinityWeight)
|
||||
d.Set("anti_affinity_rules", flattenListRules(compute.AntiAffinityRules))
|
||||
d.Set("arch", compute.Architecture)
|
||||
d.Set("boot_order", compute.BootOrder)
|
||||
d.Set("bootdisk_size", compute.BootDiskSize)
|
||||
d.Set("clone_reference", compute.CloneReference)
|
||||
d.Set("clones", compute.Clones)
|
||||
d.Set("computeci_id", compute.ComputeCIID)
|
||||
d.Set("cpus", compute.CPU)
|
||||
d.Set("created_by", compute.CreatedBy)
|
||||
d.Set("created_time", compute.CreatedTime)
|
||||
d.Set("custom_fields", flattenCustomFields(compute.CustomFields))
|
||||
d.Set("deleted_by", compute.DeletedBy)
|
||||
d.Set("deleted_time", compute.DeletedTime)
|
||||
d.Set("desc", compute.Description)
|
||||
func flattenDataCompute(d *schema.ResourceData, computeRec compute.RecordCompute) {
|
||||
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))
|
||||
d.Set("arch", computeRec.Architecture)
|
||||
d.Set("boot_order", computeRec.BootOrder)
|
||||
d.Set("bootdisk_size", computeRec.BootDiskSize)
|
||||
d.Set("clone_reference", computeRec.CloneReference)
|
||||
d.Set("clones", computeRec.Clones)
|
||||
d.Set("computeci_id", computeRec.ComputeCIID)
|
||||
d.Set("cpus", computeRec.CPU)
|
||||
d.Set("created_by", computeRec.CreatedBy)
|
||||
d.Set("created_time", computeRec.CreatedTime)
|
||||
d.Set("custom_fields", flattenCustomFields(computeRec.CustomFields))
|
||||
d.Set("deleted_by", computeRec.DeletedBy)
|
||||
d.Set("deleted_time", computeRec.DeletedTime)
|
||||
d.Set("desc", computeRec.Description)
|
||||
d.Set("devices", string(devices))
|
||||
d.Set("disks", flattenListComputeDisks(compute.Disks))
|
||||
d.Set("driver", compute.Driver)
|
||||
d.Set("gid", compute.GID)
|
||||
d.Set("guid", compute.GUID)
|
||||
d.Set("compute_id", compute.ID)
|
||||
d.Set("image_id", compute.ImageID)
|
||||
d.Set("interfaces", flattenInterfaces(compute.Interfaces))
|
||||
d.Set("lock_status", compute.LockStatus)
|
||||
d.Set("manager_id", compute.ManagerID)
|
||||
d.Set("manager_type", compute.ManagerType)
|
||||
d.Set("migrationjob", compute.MigrationJob)
|
||||
d.Set("milestones", compute.Milestones)
|
||||
d.Set("name", compute.Name)
|
||||
d.Set("natable_vins_id", compute.NatableVINSID)
|
||||
d.Set("natable_vins_ip", compute.NatableVINSIP)
|
||||
d.Set("natable_vins_name", compute.NatableVINSName)
|
||||
d.Set("natable_vins_network", compute.NatableVINSNetwork)
|
||||
d.Set("natable_vins_network_name", compute.NatableVINSNetworkName)
|
||||
d.Set("os_users", flattenOsUsers(compute.OSUsers))
|
||||
d.Set("pinned", compute.Pinned)
|
||||
d.Set("ram", compute.RAM)
|
||||
d.Set("reference_id", compute.ReferenceID)
|
||||
d.Set("registered", compute.Registered)
|
||||
d.Set("res_name", compute.ResName)
|
||||
d.Set("rg_id", compute.RGID)
|
||||
d.Set("rg_name", compute.RGName)
|
||||
d.Set("snap_sets", flattenSnapSets(compute.SnapSets))
|
||||
d.Set("stateless_sep_id", compute.StatelessSepID)
|
||||
d.Set("stateless_sep_type", compute.StatelessSepType)
|
||||
d.Set("status", compute.Status)
|
||||
d.Set("tags", compute.Tags)
|
||||
d.Set("tech_status", compute.TechStatus)
|
||||
d.Set("updated_by", compute.UpdatedBy)
|
||||
d.Set("updated_time", compute.UpdatedTime)
|
||||
d.Set("user_managed", compute.UserManaged)
|
||||
d.Set("disks", flattenListComputeDisks(computeRec.Disks))
|
||||
d.Set("driver", computeRec.Driver)
|
||||
d.Set("gid", computeRec.GID)
|
||||
d.Set("guid", computeRec.GUID)
|
||||
d.Set("compute_id", computeRec.ID)
|
||||
d.Set("image_id", computeRec.ImageID)
|
||||
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)
|
||||
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)
|
||||
d.Set("ram", computeRec.RAM)
|
||||
d.Set("reference_id", computeRec.ReferenceID)
|
||||
d.Set("registered", computeRec.Registered)
|
||||
d.Set("res_name", computeRec.ResName)
|
||||
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)
|
||||
d.Set("userdata", string(userdata))
|
||||
d.Set("vgpus", compute.VGPUs)
|
||||
d.Set("virtual_image_id", compute.VirtualImageID)
|
||||
d.Set("virtual_image_name", compute.VirtualImageName)
|
||||
d.Set("vgpus", computeRec.VGPUs)
|
||||
d.Set("virtual_image_id", computeRec.VirtualImageID)
|
||||
d.Set("virtual_image_name", computeRec.VirtualImageName)
|
||||
}
|
||||
|
||||
func flattenComputeAudits(computeAudits ListAudits) []map[string]interface{} {
|
||||
func flattenComputeAudits(computeAudits compute.ListAudits) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, computeAudit := range computeAudits {
|
||||
temp := map[string]interface{}{
|
||||
@@ -626,7 +613,7 @@ func flattenComputeAudits(computeAudits ListAudits) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenPfwList(computePfws ListPFWs) []map[string]interface{} {
|
||||
func flattenPfwList(computePfws compute.ListPFWs) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, computePfw := range computePfws {
|
||||
temp := map[string]interface{}{
|
||||
@@ -643,13 +630,13 @@ func flattenPfwList(computePfws ListPFWs) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenUserList(d *schema.ResourceData, userList RecordACL) {
|
||||
func flattenUserList(d *schema.ResourceData, userList compute.RecordACL) {
|
||||
d.Set("account_acl", flattenListACL(userList.AccountACL))
|
||||
d.Set("compute_acl", flattenListACL(userList.ComputeACL))
|
||||
d.Set("rg_acl", flattenListACL(userList.RGACL))
|
||||
}
|
||||
|
||||
func flattenComputeGetAudits(computeAudits ListShortAudits) []map[string]interface{} {
|
||||
func flattenComputeGetAudits(computeAudits compute.ListShortAudits) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, computeAudit := range computeAudits {
|
||||
temp := map[string]interface{}{
|
||||
@@ -661,9 +648,9 @@ func flattenComputeGetAudits(computeAudits ListShortAudits) []map[string]interfa
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenSnapshotUsage(computeSnapshotUasges ListUsageSnapshots) []map[string]interface{} {
|
||||
func flattenSnapshotUsage(computeSnapshotUsages compute.ListUsageSnapshots) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, computeUsage := range computeSnapshotUasges {
|
||||
for _, computeUsage := range computeSnapshotUsages {
|
||||
temp := map[string]interface{}{
|
||||
"count": computeUsage.Count,
|
||||
"stored": computeUsage.Stored,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -34,11 +34,12 @@ package kvmvm
|
||||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func parseOsUsers(logins ListOSUser) []interface{} {
|
||||
func parseOsUsers(logins compute.ListOSUser) []interface{} {
|
||||
var result = make([]interface{}, len(logins))
|
||||
|
||||
for index, value := range logins {
|
||||
|
||||
@@ -34,89 +34,68 @@ package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/extnet"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/image"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/rg"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func existRgID(ctx context.Context, d *schema.ResourceData, m interface{}) bool {
|
||||
func existRgID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
rgList := []struct {
|
||||
ID int `json:"id"`
|
||||
}{}
|
||||
rgId := uint64(d.Get("rg_id").(int))
|
||||
req := rg.ListRequest{
|
||||
IncludeDeleted: false,
|
||||
}
|
||||
|
||||
rgListAPI := "/restmachine/cloudapi/rg/list"
|
||||
urlValues.Add("includedeleted", "false")
|
||||
rgListRaw, err := c.DecortAPICall(ctx, "POST", rgListAPI, urlValues)
|
||||
rgList, err := c.CloudAPI().RG().List(ctx, req)
|
||||
if err != nil {
|
||||
return false
|
||||
return false, err
|
||||
}
|
||||
err = json.Unmarshal([]byte(rgListRaw), &rgList)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
rgId := d.Get("rg_id").(int)
|
||||
for _, rg := range rgList {
|
||||
if rg.ID == rgId {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
||||
return len(rgList.FilterByID(rgId)) != 0, nil
|
||||
}
|
||||
|
||||
func existImageId(ctx context.Context, d *schema.ResourceData, m interface{}) bool {
|
||||
func existImageId(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
imageList := []struct {
|
||||
ID int `json:"id"`
|
||||
}{}
|
||||
imageListAPI := "/restmachine/cloudapi/image/list"
|
||||
imageListRaw, err := c.DecortAPICall(ctx, "POST", imageListAPI, urlValues)
|
||||
imageId := uint64(d.Get("image_id").(int))
|
||||
req := image.ListRequest{}
|
||||
|
||||
imageList, err := c.CloudAPI().Image().List(ctx, req)
|
||||
if err != nil {
|
||||
return false
|
||||
return false, err
|
||||
}
|
||||
err = json.Unmarshal([]byte(imageListRaw), &imageList)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
imageId := d.Get("image_id").(int)
|
||||
for _, image := range imageList {
|
||||
if image.ID == imageId {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
||||
return len(imageList.FilterByID(imageId)) != 0, nil
|
||||
}
|
||||
|
||||
func existVinsIdInList(vinsId int, vinsList []struct {
|
||||
ID int `json:"id"`
|
||||
}) bool {
|
||||
func existVinsIdInList(vinsId uint64, vinsList vins.ListVINS) bool {
|
||||
for _, vins := range vinsList {
|
||||
if vinsId == vins.ID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func existExtNetIdInList(extId uint64, extList extnet.ListExtNets) bool {
|
||||
for _, ext := range extList {
|
||||
if extId == ext.ID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func existVinsId(ctx context.Context, d *schema.ResourceData, m interface{}) (int, bool) {
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
req := vins.ListRequest{IncludeDeleted: false}
|
||||
|
||||
vinsListAPI := "/restmachine/cloudapi/vins/list"
|
||||
urlValues.Add("includeDeleted", "false")
|
||||
vinsList := []struct {
|
||||
ID int `json:"id"`
|
||||
}{}
|
||||
vinsListRaw, err := c.DecortAPICall(ctx, "POST", vinsListAPI, urlValues)
|
||||
if err != nil {
|
||||
return 0, false
|
||||
}
|
||||
err = json.Unmarshal([]byte(vinsListRaw), &vinsList)
|
||||
vinsList, err := c.CloudAPI().VINS().List(ctx, req)
|
||||
if err != nil {
|
||||
return 0, false
|
||||
}
|
||||
@@ -124,11 +103,32 @@ func existVinsId(ctx context.Context, d *schema.ResourceData, m interface{}) (in
|
||||
networks := d.Get("network").(*schema.Set).List()
|
||||
|
||||
for _, networkInterface := range networks {
|
||||
|
||||
networkItem := networkInterface.(map[string]interface{})
|
||||
if !existVinsIdInList(networkItem["net_id"].(int), vinsList) {
|
||||
if !existVinsIdInList(uint64(networkItem["net_id"].(int)), vinsList) {
|
||||
return networkItem["net_id"].(int), false
|
||||
}
|
||||
}
|
||||
|
||||
return 0, true
|
||||
}
|
||||
|
||||
func existExtNetId(ctx context.Context, d *schema.ResourceData, m interface{}) (int, bool) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := extnet.ListRequest{}
|
||||
|
||||
extNetList, err := c.CloudAPI().ExtNet().List(ctx, req)
|
||||
if err != nil {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
networks := d.Get("network").(*schema.Set).List()
|
||||
|
||||
for _, networkInterface := range networks {
|
||||
networkItem := networkInterface.(map[string]interface{})
|
||||
if !existExtNetIdInList(uint64(networkItem["net_id"].(int)), extNetList) {
|
||||
return networkItem["net_id"].(int), false
|
||||
}
|
||||
}
|
||||
|
||||
return 0, true
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -34,30 +34,20 @@ package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceData, m interface{}, do_delta bool) error {
|
||||
// d is filled with data according to computeResource schema, so extra disks config is retrieved via "extra_disks" key
|
||||
// If do_delta is true, this function will identify changes between new and existing specs for extra disks and try to
|
||||
// update compute configuration accordingly
|
||||
// Otherwise it will apply whatever is found in the new set of "extra_disks" right away.
|
||||
// Primary use of do_delta=false is when calling this function from compute Create handler.
|
||||
|
||||
// Note that this function will not abort on API errors, but will continue to configure (attach / detach) other individual
|
||||
// disks via atomic API calls. However, it will not retry failed manipulation on the same disk.
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
log.Debugf("utilityComputeExtraDisksConfigure: called for Compute ID %s with do_delta = %t", d.Id(), do_delta)
|
||||
|
||||
// NB: as of rc-1.25 "extra_disks" are TypeSet with the elem of TypeInt
|
||||
old_set, new_set := d.GetChange("extra_disks")
|
||||
|
||||
apiErrCount := 0
|
||||
@@ -69,12 +59,14 @@ func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceDa
|
||||
}
|
||||
|
||||
for _, disk := range new_set.(*schema.Set).List() {
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("computeId", d.Id())
|
||||
urlValues.Add("diskId", fmt.Sprintf("%d", disk.(int)))
|
||||
_, err := c.DecortAPICall(ctx, "POST", ComputeDiskAttachAPI, urlValues)
|
||||
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req := compute.DiskAttachRequest{
|
||||
ComputeID: computeId,
|
||||
DiskID: uint64(disk.(int)),
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().Compute().DiskAttach(ctx, req)
|
||||
if err != nil {
|
||||
// failed to attach extra disk - partial resource update
|
||||
apiErrCount++
|
||||
lastSavedError = err
|
||||
}
|
||||
@@ -93,29 +85,34 @@ func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceDa
|
||||
log.Debugf("utilityComputeExtraDisksConfigure: detach set has %d items for Compute ID %s", detach_set.Len(), d.Id())
|
||||
|
||||
if detach_set.Len() > 0 {
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("computeId", d.Id())
|
||||
urlValues.Add("force", "false")
|
||||
_, err := c.DecortAPICall(ctx, "POST", ComputeStopAPI, urlValues)
|
||||
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
stopReq := compute.StopRequest{
|
||||
ComputeID: computeId,
|
||||
Force: false,
|
||||
}
|
||||
_, err := c.CloudAPI().Compute().Stop(ctx, stopReq)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, diskId := range detach_set.List() {
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("computeId", d.Id())
|
||||
urlValues.Add("diskId", fmt.Sprintf("%d", diskId.(int)))
|
||||
_, err := c.DecortAPICall(ctx, "POST", ComputeDiskDetachAPI, urlValues)
|
||||
req := compute.DiskDetachRequest{
|
||||
ComputeID: computeId,
|
||||
DiskID: uint64(diskId.(int)),
|
||||
}
|
||||
_, err := c.CloudAPI().Compute().DiskDetach(ctx, req)
|
||||
if err != nil {
|
||||
// failed to detach disk - there will be partial resource update
|
||||
log.Errorf("utilityComputeExtraDisksConfigure: failed to detach disk ID %d from Compute ID %s: %s", diskId.(int), d.Id(), err)
|
||||
apiErrCount++
|
||||
lastSavedError = err
|
||||
}
|
||||
}
|
||||
urlValues = &url.Values{}
|
||||
urlValues.Add("computeId", d.Id())
|
||||
urlValues.Add("altBootId", "0")
|
||||
_, err = c.DecortAPICall(ctx, "POST", ComputeStartAPI, urlValues)
|
||||
|
||||
req := compute.StartRequest{
|
||||
ComputeID: computeId,
|
||||
AltBootID: 0,
|
||||
}
|
||||
_, err = c.CloudAPI().Compute().Start(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -124,12 +121,14 @@ func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceDa
|
||||
attach_set := new_set.(*schema.Set).Difference(old_set.(*schema.Set))
|
||||
log.Debugf("utilityComputeExtraDisksConfigure: attach set has %d items for Compute ID %s", attach_set.Len(), d.Id())
|
||||
for _, diskId := range attach_set.List() {
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("computeId", d.Id())
|
||||
urlValues.Add("diskId", fmt.Sprintf("%d", diskId.(int)))
|
||||
_, err := c.DecortAPICall(ctx, "POST", ComputeDiskAttachAPI, urlValues)
|
||||
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req := compute.DiskAttachRequest{
|
||||
ComputeID: computeId,
|
||||
DiskID: uint64(diskId.(int)),
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().Compute().DiskAttach(ctx, req)
|
||||
if err != nil {
|
||||
// failed to attach disk - there will be partial resource update
|
||||
log.Errorf("utilityComputeExtraDisksConfigure: failed to attach disk ID %d to Compute ID %s: %s", diskId.(int), d.Id(), err)
|
||||
apiErrCount++
|
||||
lastSavedError = err
|
||||
@@ -146,12 +145,6 @@ func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceDa
|
||||
}
|
||||
|
||||
func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData, m interface{}, do_delta bool, skip_zero bool) error {
|
||||
// "d" is filled with data according to computeResource schema, so extra networks config is retrieved via "network" key
|
||||
// If do_delta is true, this function will identify changes between new and existing specs for network and try to
|
||||
// update compute configuration accordingly
|
||||
// Otherwise it will apply whatever is found in the new set of "network" right away.
|
||||
// Primary use of do_delta=false is when calling this function from compute Create handler.
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
old_set, new_set := d.GetChange("network")
|
||||
@@ -168,18 +161,20 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
|
||||
if i == 0 && skip_zero {
|
||||
continue
|
||||
}
|
||||
urlValues := &url.Values{}
|
||||
net_data := runner.(map[string]interface{})
|
||||
urlValues.Add("computeId", d.Id())
|
||||
urlValues.Add("netType", net_data["net_type"].(string))
|
||||
urlValues.Add("netId", fmt.Sprintf("%d", net_data["net_id"].(int)))
|
||||
ipaddr, ipSet := net_data["ip_address"] // "ip_address" key is optional
|
||||
if ipSet {
|
||||
urlValues.Add("ipAddr", ipaddr.(string))
|
||||
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req := compute.NetAttachRequest{
|
||||
ComputeID: computeId,
|
||||
NetType: net_data["net_type"].(string),
|
||||
NetID: uint64(net_data["net_id"].(int)),
|
||||
}
|
||||
_, err := c.DecortAPICall(ctx, "POST", ComputeNetAttachAPI, urlValues)
|
||||
|
||||
ipaddr, ipSet := net_data["ip_address"]
|
||||
if ipSet {
|
||||
req.IPAddr = ipaddr.(string)
|
||||
}
|
||||
_, err := c.CloudAPI().Compute().NetAttach(ctx, req)
|
||||
if err != nil {
|
||||
// failed to attach network - partial resource update
|
||||
apiErrCount++
|
||||
lastSavedError = err
|
||||
}
|
||||
@@ -196,14 +191,16 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
|
||||
detach_set := old_set.(*schema.Set).Difference(new_set.(*schema.Set))
|
||||
log.Debugf("utilityComputeNetworksConfigure: detach set has %d items for Compute ID %s", detach_set.Len(), d.Id())
|
||||
for _, runner := range detach_set.List() {
|
||||
urlValues := &url.Values{}
|
||||
net_data := runner.(map[string]interface{})
|
||||
urlValues.Add("computeId", d.Id())
|
||||
urlValues.Add("ipAddr", net_data["ip_address"].(string))
|
||||
urlValues.Add("mac", net_data["mac"].(string))
|
||||
_, err := c.DecortAPICall(ctx, "POST", ComputeNetDetachAPI, urlValues)
|
||||
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req := compute.NetDetachRequest{
|
||||
ComputeID: computeId,
|
||||
IPAddr: net_data["ip_address"].(string),
|
||||
MAC: net_data["mac"].(string),
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().Compute().NetDetach(ctx, req)
|
||||
if err != nil {
|
||||
// failed to detach this network - there will be partial resource update
|
||||
log.Errorf("utilityComputeNetworksConfigure: failed to detach net ID %d of type %s from Compute ID %s: %s",
|
||||
net_data["net_id"].(int), net_data["net_type"].(string), d.Id(), err)
|
||||
apiErrCount++
|
||||
@@ -214,17 +211,20 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
|
||||
attach_set := new_set.(*schema.Set).Difference(old_set.(*schema.Set))
|
||||
log.Debugf("utilityComputeNetworksConfigure: attach set has %d items for Compute ID %s", attach_set.Len(), d.Id())
|
||||
for _, runner := range attach_set.List() {
|
||||
urlValues := &url.Values{}
|
||||
net_data := runner.(map[string]interface{})
|
||||
urlValues.Add("computeId", d.Id())
|
||||
urlValues.Add("netId", fmt.Sprintf("%d", net_data["net_id"].(int)))
|
||||
urlValues.Add("netType", net_data["net_type"].(string))
|
||||
if net_data["ip_address"].(string) != "" {
|
||||
urlValues.Add("ipAddr", net_data["ip_address"].(string))
|
||||
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req := compute.NetAttachRequest{
|
||||
ComputeID: computeId,
|
||||
NetType: net_data["net_type"].(string),
|
||||
NetID: uint64(net_data["net_id"].(int)),
|
||||
}
|
||||
_, err := c.DecortAPICall(ctx, "POST", ComputeNetAttachAPI, urlValues)
|
||||
|
||||
if net_data["ip_address"].(string) != "" {
|
||||
req.IPAddr = net_data["ip_address"].(string)
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().Compute().NetAttach(ctx, req)
|
||||
if err != nil {
|
||||
// failed to attach this network - there will be partial resource update
|
||||
log.Errorf("utilityComputeNetworksConfigure: failed to attach net ID %d of type %s to Compute ID %s: %s",
|
||||
net_data["net_id"].(int), net_data["net_type"].(string), d.Id(), err)
|
||||
apiErrCount++
|
||||
@@ -241,20 +241,17 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
|
||||
return nil
|
||||
}
|
||||
|
||||
func utilityComputeCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (RecordCompute, error) {
|
||||
func utilityComputeCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (compute.RecordCompute, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
compute := &RecordCompute{}
|
||||
|
||||
urlValues.Add("computeId", d.Id())
|
||||
computeRaw, err := c.DecortAPICall(ctx, "POST", ComputeGetAPI, urlValues)
|
||||
if err != nil {
|
||||
return *compute, err
|
||||
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req := compute.GetRequest{
|
||||
ComputeID: computeId,
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(computeRaw), &compute)
|
||||
computeRecord, err := c.CloudAPI().Compute().Get(ctx, req)
|
||||
if err != nil {
|
||||
return *compute, err
|
||||
return *computeRecord, err
|
||||
}
|
||||
return *compute, nil
|
||||
|
||||
return *computeRecord, nil
|
||||
}
|
||||
|
||||
@@ -34,28 +34,21 @@ package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityComputeAuditsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (ListAudits, error) {
|
||||
func utilityComputeAuditsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (compute.ListAudits, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
computeAudits := &ListAudits{}
|
||||
req := compute.AuditsRequest{
|
||||
ComputeID: uint64(d.Get("compute_id").(int)),
|
||||
}
|
||||
|
||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||
computeAuditsRaw, err := c.DecortAPICall(ctx, "POST", ComputeAuditsAPI, urlValues)
|
||||
computeAudits, err := c.CloudAPI().Compute().Audits(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(computeAuditsRaw), &computeAudits)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return *computeAudits, nil
|
||||
return computeAudits, nil
|
||||
}
|
||||
|
||||
@@ -36,16 +36,17 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
|
||||
)
|
||||
|
||||
func utilityComputeBootDiskCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*ItemComputeDisk, error) {
|
||||
compute, err := utilityComputeCheckPresence(ctx, d, m)
|
||||
func utilityComputeBootDiskCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.ItemComputeDisk, error) {
|
||||
computeRecord, err := utilityComputeCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bootDisk := &ItemComputeDisk{}
|
||||
for _, disk := range compute.Disks {
|
||||
bootDisk := &compute.ItemComputeDisk{}
|
||||
for _, disk := range computeRecord.Disks {
|
||||
if disk.Name == "bootdisk" {
|
||||
*bootDisk = disk
|
||||
break
|
||||
|
||||
@@ -34,28 +34,22 @@ package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityComputeGetAuditsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (ListShortAudits, error) {
|
||||
func utilityComputeGetAuditsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (compute.ListShortAudits, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
computeAudits := &ListShortAudits{}
|
||||
req := compute.GetAuditsRequest{
|
||||
ComputeID: uint64(d.Get("compute_id").(int)),
|
||||
}
|
||||
|
||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||
computeAuditsRaw, err := c.DecortAPICall(ctx, "POST", ComputeGetAuditsAPI, urlValues)
|
||||
computeAudits, err := c.CloudAPI().Compute().GetAudits(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(computeAuditsRaw), &computeAudits)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return *computeAudits, nil
|
||||
return computeAudits, nil
|
||||
}
|
||||
|
||||
@@ -34,22 +34,22 @@ package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityComputeGetConsoleUrlCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||
computeConsoleUrlRaw, err := c.DecortAPICall(ctx, "POST", ComputeGetConsoleUrlAPI, urlValues)
|
||||
req := compute.GetConsoleURLRequest{
|
||||
ComputeID: uint64(d.Get("compute_id").(int)),
|
||||
}
|
||||
computeConsoleUrl, err := c.CloudAPI().Compute().GetConsoleURL(ctx, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(computeConsoleUrlRaw), nil
|
||||
return computeConsoleUrl, nil
|
||||
}
|
||||
|
||||
@@ -34,23 +34,23 @@ package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityComputeGetLogCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
req := compute.GetLogRequest{
|
||||
ComputeID: uint64(d.Get("compute_id").(int)),
|
||||
Path: d.Get("path").(string),
|
||||
}
|
||||
|
||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||
urlValues.Add("path", d.Get("path").(string))
|
||||
computeGetLogRaw, err := c.DecortAPICall(ctx, "POST", ComputeGetLogAPI, urlValues)
|
||||
computeGetLog, err := c.CloudAPI().Compute().GetLog(ctx, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(computeGetLogRaw), nil
|
||||
return computeGetLog, nil
|
||||
}
|
||||
|
||||
@@ -34,38 +34,30 @@ package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityDataComputeListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (ListComputes, error) {
|
||||
func utilityDataComputeListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (compute.ListComputes, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
listComputes := &ListComputes{}
|
||||
req := compute.ListRequest{}
|
||||
|
||||
if includeDeleted, ok := d.GetOk("includedeleted"); ok {
|
||||
urlValues.Add("includeDeleted", strconv.FormatBool(includeDeleted.(bool)))
|
||||
req.IncludeDeleted = includeDeleted.(bool)
|
||||
}
|
||||
if page, ok := d.GetOk("page"); ok {
|
||||
urlValues.Add("page", strconv.Itoa(page.(int)))
|
||||
req.Page = uint64(page.(int))
|
||||
}
|
||||
if size, ok := d.GetOk("size"); ok {
|
||||
urlValues.Add("size", strconv.Itoa(size.(int)))
|
||||
req.Size = uint64(size.(int))
|
||||
}
|
||||
|
||||
listComputesRaw, err := c.DecortAPICall(ctx, "POST", ComputeListAPI, urlValues)
|
||||
listComputes, err := c.CloudAPI().Compute().List(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(listComputesRaw), &listComputes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return *listComputes, nil
|
||||
|
||||
return listComputes, nil
|
||||
}
|
||||
|
||||
@@ -34,29 +34,23 @@ package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityComputePfwListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (ListPFWs, error) {
|
||||
func utilityComputePfwListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (compute.ListPFWs, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
listPFWs := &ListPFWs{}
|
||||
req := compute.PFWListRequest{
|
||||
ComputeID: uint64(d.Get("compute_id").(int)),
|
||||
}
|
||||
|
||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||
computePfwListRaw, err := c.DecortAPICall(ctx, "POST", ComputePfwListAPI, urlValues)
|
||||
listPFWs, err := c.CloudAPI().Compute().PFWList(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(computePfwListRaw), &listPFWs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return *listPFWs, err
|
||||
return listPFWs, err
|
||||
|
||||
}
|
||||
|
||||
@@ -2,32 +2,27 @@ package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityComputeSnapshotUasgeCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (ListUsageSnapshots, error) {
|
||||
func utilityComputeSnapshotUsageCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (compute.ListUsageSnapshots, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
UsageSnapshotList := &ListUsageSnapshots{}
|
||||
req := compute.SnapshotUsageRequest{
|
||||
ComputeID: uint64(d.Get("compute_id").(int)),
|
||||
}
|
||||
|
||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||
if label, ok := d.GetOk("label"); ok {
|
||||
urlValues.Add("label", label.(string))
|
||||
req.Label = label.(string)
|
||||
}
|
||||
computeSnapshotUsage, err := c.DecortAPICall(ctx, "POST", ComputeSnapshotUsageAPI, urlValues)
|
||||
|
||||
computeSnapshotUsage, err := c.CloudAPI().Compute().SnapshotUsage(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(computeSnapshotUsage), &UsageSnapshotList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return *UsageSnapshotList, err
|
||||
return computeSnapshotUsage, err
|
||||
|
||||
}
|
||||
|
||||
@@ -34,27 +34,22 @@ package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityComputeUserListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (RecordACL, error) {
|
||||
func utilityComputeUserListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (compute.RecordACL, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
userList := &RecordACL{}
|
||||
req := compute.UserListRequest{
|
||||
ComputeID: uint64(d.Get("compute_id").(int)),
|
||||
}
|
||||
|
||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||
computeUserListRaw, err := c.DecortAPICall(ctx, "POST", ComputeUserListAPI, urlValues)
|
||||
computeUserList, err := c.CloudAPI().Compute().UserList(ctx, req)
|
||||
if err != nil {
|
||||
return *userList, err
|
||||
return *computeUserList, err
|
||||
}
|
||||
err = json.Unmarshal([]byte(computeUserListRaw), &userList)
|
||||
if err != nil {
|
||||
return *userList, err
|
||||
}
|
||||
return *userList, err
|
||||
|
||||
return *computeUserList, err
|
||||
}
|
||||
|
||||
@@ -34,28 +34,22 @@ package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityDataComputeCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (RecordCompute, error) {
|
||||
func utilityDataComputeCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (compute.RecordCompute, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
compute := &RecordCompute{}
|
||||
|
||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||
computeRaw, err := c.DecortAPICall(ctx, "POST", ComputeGetAPI, urlValues)
|
||||
if err != nil {
|
||||
return *compute, err
|
||||
req := compute.GetRequest{
|
||||
ComputeID: uint64(d.Get("compute_id").(int)),
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(computeRaw), &compute)
|
||||
computeRecord, err := c.CloudAPI().Compute().Get(ctx, req)
|
||||
if err != nil {
|
||||
return *compute, err
|
||||
return *computeRecord, err
|
||||
}
|
||||
return *compute, nil
|
||||
|
||||
return *computeRecord, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user