4.5.0-alpha
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -53,8 +53,9 @@ func dataSourcePcideviceRead(ctx context.Context, d *schema.ResourceData, m inte
|
||||
d.Set("description", pcidevice.Description)
|
||||
d.Set("guid", pcidevice.GUID)
|
||||
d.Set("hw_path", pcidevice.HwPath)
|
||||
d.Set("rg_id", pcidevice.RGID)
|
||||
d.Set("device_id",pcidevice.ID)
|
||||
d.Set("name", pcidevice.Name)
|
||||
d.Set("rg_id", pcidevice.RGID)
|
||||
d.Set("stack_id", pcidevice.StackID)
|
||||
d.Set("status", pcidevice.Status)
|
||||
d.Set("system_name", pcidevice.SystemName)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -43,7 +43,7 @@ import (
|
||||
)
|
||||
|
||||
func flattenPcideviceList(pl *pcidevice.ListPCIDevices) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
res := make([]map[string]interface{}, 0, len(pl.Data))
|
||||
for _, item := range pl.Data {
|
||||
temp := map[string]interface{}{
|
||||
"ckey": item.CKey,
|
||||
@@ -71,6 +71,7 @@ func dataSourcePcideviceListRead(ctx context.Context, d *schema.ResourceData, m
|
||||
}
|
||||
|
||||
d.Set("items", flattenPcideviceList(pcideviceList))
|
||||
d.Set("entry_count", pcideviceList.EntryCount)
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
@@ -78,74 +79,57 @@ func dataSourcePcideviceListRead(ctx context.Context, d *schema.ResourceData, m
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourcePcideviceItem() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"ckey": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"meta": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"compute_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"hw_path": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"device_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"rg_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"stack_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"system_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourcePcideviceListSchemaMake() map[string]*schema.Schema {
|
||||
rets := map[string]*schema.Schema{
|
||||
"by_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "by_id",
|
||||
},
|
||||
"compute_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "compute_id",
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "name",
|
||||
},
|
||||
"rg_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "rg_id",
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "status",
|
||||
},
|
||||
"page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "page number",
|
||||
},
|
||||
"size": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "page size",
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "pcidevice list",
|
||||
Elem: &schema.Resource{
|
||||
Schema: dataSourcePcideviceItem(),
|
||||
Schema: dataSourcePcideviceSchemaMake(),
|
||||
},
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "entry count",
|
||||
},
|
||||
}
|
||||
|
||||
return rets
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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 pcidevice
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func existStackID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
StackID := uint64(d.Get("stack_id").(int))
|
||||
RGID := uint64(d.Get("rg_id").(int))
|
||||
|
||||
req := rg.ListRequest{
|
||||
IncludeDeleted: false,
|
||||
}
|
||||
|
||||
rgList, err := c.CloudBroker().RG().List(ctx, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
for _, v := range rgList.FilterByID(RGID).Data {
|
||||
for _, idVM := range v.VMs {
|
||||
req := compute.GetRequest{
|
||||
ComputeID: idVM,
|
||||
}
|
||||
checkStackID, err := c.CloudBroker().Compute().Get(ctx, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if checkStackID.StackID == StackID {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false, err
|
||||
}
|
||||
|
||||
func existRGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
RGID := uint64(d.Get("rg_id").(int))
|
||||
req := rg.ListRequest{
|
||||
IncludeDeleted: false,
|
||||
}
|
||||
|
||||
rgList, err := c.CloudBroker().RG().List(ctx, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return len(rgList.FilterByID(RGID).Data) != 0, nil
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -42,18 +42,36 @@ import (
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
|
||||
|
||||
)
|
||||
|
||||
func resourcePcideviceCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourcePcideviceCreate: called for pcidevice %s", d.Get("name").(string))
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := pcidevice.CreateRequest{
|
||||
Name: d.Get("name").(string),
|
||||
HWPath: d.Get("hw_path").(string),
|
||||
RGID: uint64(d.Get("rg_id").(int)),
|
||||
StackID: uint64(d.Get("stack_id").(int)),
|
||||
req := pcidevice.CreateRequest{}
|
||||
|
||||
haveRGID, err := existRGID(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
if !haveRGID {
|
||||
return diag.Errorf("resourcePcideviceCreate: can't create Pcidevice because RGID %d is not allowed or does not exist", d.Get("rg_id").(int))
|
||||
}
|
||||
|
||||
haveStackID, err := existStackID(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
if !haveStackID {
|
||||
return diag.Errorf("resourcePcideviceCreate: can't create Pcidevice because StackID %d is not allowed or does not exist", d.Get("stack_id").(int))
|
||||
}
|
||||
|
||||
req.StackID = uint64(d.Get("stack_id").(int))
|
||||
req.RGID = uint64(d.Get("rg_id").(int))
|
||||
req.Name = d.Get("name").(string)
|
||||
req.HWPath = d.Get("hw_path").(string)
|
||||
|
||||
if description, ok := d.GetOk("description"); ok {
|
||||
req.Description = description.(string)
|
||||
@@ -92,27 +110,24 @@ func resourcePcideviceRead(ctx context.Context, d *schema.ResourceData, m interf
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourcePcideviceDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourcePcideviceDelete: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||
func resourcePcideviceUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
deviceID, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req := pcidevice.DeleteRequest{
|
||||
DeviceID: deviceID,
|
||||
Force: d.Get("force").(bool),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().PCIDevice().Delete(ctx, req)
|
||||
haveRGID, err := existRGID(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
if !haveRGID {
|
||||
return diag.Errorf("resourcePcideviceCreate: can't update Pcidevice because RGID %d is not allowed or does not exist", d.Get("rg_id").(int))
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
haveStackID, err := existStackID(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
if !haveStackID {
|
||||
return diag.Errorf("resourcePcideviceCreate: can't update Pcidevice because StackID %d is not allowed or does not exist", d.Get("stack_id").(int))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourcePcideviceUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
if d.HasChange("enable") {
|
||||
state := d.Get("enable").(bool)
|
||||
c := m.(*controller.ControllerCfg)
|
||||
@@ -130,6 +145,9 @@ func resourcePcideviceUpdate(ctx context.Context, d *schema.ResourceData, m inte
|
||||
req := pcidevice.DisableRequest{
|
||||
DeviceID: uint64(d.Get("device_id").(int)),
|
||||
}
|
||||
if force, ok := d.GetOk("force"); ok {
|
||||
req.Force = force.(bool)
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().PCIDevice().Disable(ctx, req)
|
||||
if err != nil {
|
||||
@@ -141,6 +159,38 @@ func resourcePcideviceUpdate(ctx context.Context, d *schema.ResourceData, m inte
|
||||
return resourcePcideviceRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourcePcideviceDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourcePcideviceDelete: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||
|
||||
pciDevice, err := utilityPcideviceCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
if pciDevice.Status == status.Destroyed || pciDevice.Status == status.Purged {
|
||||
return nil
|
||||
}
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := pcidevice.DeleteRequest{
|
||||
DeviceID: pciDevice.ID,
|
||||
}
|
||||
|
||||
if force, ok := d.GetOk("force"); ok {
|
||||
req.Force = force.(bool)
|
||||
}
|
||||
|
||||
_, err = c.CloudBroker().PCIDevice().Delete(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourcePcideviceSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"ckey": {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -33,6 +33,7 @@ package pcidevice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
@@ -46,11 +47,12 @@ func utilityPcideviceCheckPresence(ctx context.Context, d *schema.ResourceData,
|
||||
}
|
||||
|
||||
var pcideviceId uint64
|
||||
if (d.Get("device_id").(int)) != 0 {
|
||||
pcideviceId = uint64(d.Get("device_id").(int))
|
||||
} else {
|
||||
|
||||
if d.Id() != "" {
|
||||
id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
pcideviceId = id
|
||||
} else {
|
||||
pcideviceId = uint64(d.Get("device_id").(int))
|
||||
}
|
||||
|
||||
for _, pd := range pcideviceList.Data {
|
||||
@@ -59,5 +61,5 @@ func utilityPcideviceCheckPresence(ctx context.Context, d *schema.ResourceData,
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
return nil, fmt.Errorf("dataPcideviceRead: can't find Pcidevice because Device_id %d is not allowed or does not exist", d.Get("device_id").(int))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
|
||||
Reference in New Issue
Block a user