This commit is contained in:
KasimBaybikov committed 2023-05-04 10:08:25 +03:00
1 parent 9bad8a6947
commit 8ca233dd32
288 files changed
+6645 -11464

No files matched your search

@@ -37,15 +37,16 @@ import (
"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/decort-golang-sdk/pkg/cloudbroker/compute"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func flattenSnapshotList(gl SnapshotList) []map[string]interface{} {
func flattenSnapshotList(gl compute.ListSnapshots) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, item := range gl {
temp := map[string]interface{}{
"label": item.Label,
"guid": item.Guid,
"guid": item.GUID,
"disks": item.Disks,
"timestamp": item.Timestamp,
}
@@ -1,41 +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>
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 snapshot
type Snapshot struct {
Disks []int `json:"disks"`
Guid string `json:"guid"`
Label string `json:"label"`
Timestamp uint64 `json:"timestamp"`
}
type SnapshotList []Snapshot
@@ -33,26 +33,26 @@ package snapshot
import (
"context"
"net/url"
"strconv"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
log "github.com/sirupsen/logrus"
)
func resourceSnapshotCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceSnapshotCreate: called for snapshot %s", d.Get("label").(string))
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
urlValues.Add("label", d.Get("label").(string))
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
req := compute.SnapshotCreateRequest{
Label: d.Get("label").(string),
ComputeID: uint64(d.Get("compute_id").(int)),
}
snapshotId, err := c.DecortAPICall(ctx, "POST", snapshotCreateAPI, urlValues)
snapshotId, err := c.CloudBroker().Compute().SnapshotCreate(ctx, req)
if err != nil {
return diag.FromErr(err)
}
@@ -62,12 +62,7 @@ func resourceSnapshotCreate(ctx context.Context, d *schema.ResourceData, m inter
d.SetId(snapshotId)
d.Set("guid", snapshotId)
diagnostics := resourceSnapshotRead(ctx, d, m)
if diagnostics != nil {
return diagnostics
}
return nil
return resourceSnapshotRead(ctx, d, m)
}
func resourceSnapshotRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
@@ -77,7 +72,7 @@ func resourceSnapshotRead(ctx context.Context, d *schema.ResourceData, m interfa
}
d.Set("timestamp", snapshot.Timestamp)
d.Set("guid", snapshot.Guid)
d.Set("guid", snapshot.GUID)
d.Set("disks", snapshot.Disks)
d.Set("label", snapshot.Label)
@@ -88,20 +83,22 @@ func resourceSnapshotDelete(ctx context.Context, d *schema.ResourceData, m inter
log.Debugf("resourceSnapshotDelete: called for %s, id: %s", d.Get("label").(string), d.Id())
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
urlValues.Add("label", d.Get("label").(string))
req := compute.SnapshotDeleteRequest{
ComputeID: uint64(d.Get("compute_id").(int)),
Label: d.Get("label").(string),
}
_, err := c.DecortAPICall(ctx, "POST", snapshotDeleteAPI, urlValues)
_, err := c.CloudBroker().Compute().SnapshotDelete(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func resourceSnapshotEdit(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func resourceSnapshotUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
if d.HasChange("rollback") {
if d.Get("rollback").(bool) {
err := resourceSnapshotRollback(ctx, d, m)
@@ -116,12 +113,12 @@ func resourceSnapshotEdit(ctx context.Context, d *schema.ResourceData, m interfa
func resourceSnapshotRollback(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
req := compute.SnapshotRollbackRequest{
ComputeID: uint64(d.Get("compute_id").(int)),
Label: d.Get("label").(string),
}
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
urlValues.Add("label", d.Get("label").(string))
_, err := c.DecortAPICall(ctx, "POST", snapshotRollbackAPI, urlValues)
_, err := c.CloudBroker().Compute().SnapshotRollback(ctx, req)
if err != nil {
return err
}
@@ -174,7 +171,7 @@ func ResourceSnapshot() *schema.Resource {
CreateContext: resourceSnapshotCreate,
ReadContext: resourceSnapshotRead,
UpdateContext: resourceSnapshotEdit,
UpdateContext: resourceSnapshotUpdate,
DeleteContext: resourceSnapshotDelete,
Importer: &schema.ResourceImporter{
@@ -36,9 +36,10 @@ import (
"errors"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute"
)
func utilitySnapshotCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*Snapshot, error) {
func utilitySnapshotCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.ItemSnapshot, error) {
snapShotList, err := utilitySnapshotListCheckPresence(ctx, d, m)
if err != nil {
return nil, err
@@ -53,7 +54,7 @@ func utilitySnapshotCheckPresence(ctx context.Context, d *schema.ResourceData, m
}
for _, s := range snapShotList {
if s.Guid == findId {
if s.GUID == findId {
return &s, nil
}
}
@@ -33,33 +33,22 @@ package snapshot
import (
"context"
"encoding/json"
"net/url"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilitySnapshotListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (SnapshotList, error) {
func utilitySnapshotListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (compute.ListSnapshots, error) {
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
req := compute.SnapshotListRequest{
ComputeID: uint64(d.Get("compute_id").(int)),
}
resp, err := c.DecortAPICall(ctx, "POST", snapshotListAPI, urlValues)
snapshotList, err := c.CloudBroker().Compute().SnapshotList(ctx, req)
if err != nil {
return nil, err
}
if resp == "" {
return nil, nil
}
snapshotList := SnapshotList{}
if err := json.Unmarshal([]byte(resp), &snapshotList); err != nil {
return nil, err
}
return snapshotList, nil
}