4.0.0
This commit is contained in:
@@ -1,38 +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 pcidevice
|
||||
|
||||
const pcideviceListAPI = "/restmachine/cloudbroker/pcidevice/list"
|
||||
const pcideviceDisableAPI = "/restmachine/cloudbroker/pcidevice/disable"
|
||||
const pcideviceEnableAPI = "/restmachine/cloudbroker/pcidevice/enable"
|
||||
const pcideviceCreateAPI = "/restmachine/cloudbroker/pcidevice/create"
|
||||
const pcideviceDeleteAPI = "/restmachine/cloudbroker/pcidevice/delete"
|
||||
@@ -49,11 +49,11 @@ func dataSourcePcideviceRead(ctx context.Context, d *schema.ResourceData, m inte
|
||||
|
||||
d.Set("ckey", pcidevice.CKey)
|
||||
d.Set("meta", flattens.FlattenMeta(pcidevice.Meta))
|
||||
d.Set("compute_id", pcidevice.Computeid)
|
||||
d.Set("compute_id", pcidevice.ComputeID)
|
||||
d.Set("description", pcidevice.Description)
|
||||
d.Set("guid", pcidevice.Guid)
|
||||
d.Set("guid", pcidevice.GUID)
|
||||
d.Set("hw_path", pcidevice.HwPath)
|
||||
d.Set("rg_id", pcidevice.RgID)
|
||||
d.Set("rg_id", pcidevice.RGID)
|
||||
d.Set("name", pcidevice.Name)
|
||||
d.Set("stack_id", pcidevice.StackID)
|
||||
d.Set("status", pcidevice.Status)
|
||||
|
||||
@@ -37,22 +37,23 @@ 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/pcidevice"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
|
||||
)
|
||||
|
||||
func flattenPcideviceList(pl PcideviceList) []map[string]interface{} {
|
||||
func flattenPcideviceList(pl pcidevice.ListPCIDevices) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, item := range pl {
|
||||
temp := map[string]interface{}{
|
||||
"ckey": item.CKey,
|
||||
"meta": flattens.FlattenMeta(item.Meta),
|
||||
"compute_id": item.Computeid,
|
||||
"compute_id": item.ComputeID,
|
||||
"description": item.Description,
|
||||
"guid": item.Guid,
|
||||
"guid": item.GUID,
|
||||
"hw_path": item.HwPath,
|
||||
"device_id": item.ID,
|
||||
"rg_id": item.RgID,
|
||||
"rg_id": item.RGID,
|
||||
"name": item.Name,
|
||||
"stack_id": item.StackID,
|
||||
"status": item.Status,
|
||||
|
||||
@@ -1,49 +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 pcidevice
|
||||
|
||||
type Pcidevice struct {
|
||||
CKey string `json:"_ckey"`
|
||||
Meta []interface{} `json:"_meta"`
|
||||
Computeid int `json:"computeId"`
|
||||
Description string `json:"description"`
|
||||
Guid int `json:"guid"`
|
||||
HwPath string `json:"hwPath"`
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
RgID int `json:"rgId"`
|
||||
StackID int `json:"stackId"`
|
||||
Status string `json:"status"`
|
||||
SystemName string `json:"systemName"`
|
||||
}
|
||||
|
||||
type PcideviceList []Pcidevice
|
||||
@@ -33,45 +33,41 @@ package pcidevice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"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/pcidevice"
|
||||
"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"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
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)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("name", d.Get("name").(string))
|
||||
urlValues.Add("hwPath", d.Get("hw_path").(string))
|
||||
urlValues.Add("rgId", strconv.Itoa(d.Get("rg_id").(int)))
|
||||
urlValues.Add("stackId", strconv.Itoa(d.Get("stack_id").(int)))
|
||||
|
||||
if description, ok := d.GetOk("description"); ok {
|
||||
urlValues.Add("description", description.(string))
|
||||
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)),
|
||||
}
|
||||
|
||||
pcideviceId, err := c.DecortAPICall(ctx, "POST", pcideviceCreateAPI, urlValues)
|
||||
if description, ok := d.GetOk("description"); ok {
|
||||
req.Description = description.(string)
|
||||
}
|
||||
|
||||
pcideviceId, err := c.CloudBroker().PCIDevice().Create(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(pcideviceId)
|
||||
d.SetId(strconv.FormatUint(pcideviceId, 10))
|
||||
d.Set("device_id", pcideviceId)
|
||||
|
||||
diagnostics := resourcePcideviceRead(ctx, d, m)
|
||||
if diagnostics != nil {
|
||||
return diagnostics
|
||||
}
|
||||
|
||||
return nil
|
||||
return resourcePcideviceRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourcePcideviceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
@@ -80,15 +76,14 @@ func resourcePcideviceRead(ctx context.Context, d *schema.ResourceData, m interf
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(strconv.Itoa(pcidevice.ID))
|
||||
d.Set("ckey", pcidevice.CKey)
|
||||
d.Set("meta", flattens.FlattenMeta(pcidevice.Meta))
|
||||
d.Set("compute_id", pcidevice.Computeid)
|
||||
d.Set("compute_id", pcidevice.ComputeID)
|
||||
d.Set("description", pcidevice.Description)
|
||||
d.Set("guid", pcidevice.Guid)
|
||||
d.Set("guid", pcidevice.GUID)
|
||||
d.Set("hw_path", pcidevice.HwPath)
|
||||
d.Set("device_id", pcidevice.ID)
|
||||
d.Set("rg_id", pcidevice.RgID)
|
||||
d.Set("rg_id", pcidevice.RGID)
|
||||
d.Set("name", pcidevice.Name)
|
||||
d.Set("stack_id", pcidevice.StackID)
|
||||
d.Set("status", pcidevice.Status)
|
||||
@@ -101,11 +96,13 @@ func resourcePcideviceDelete(ctx context.Context, d *schema.ResourceData, m inte
|
||||
log.Debugf("resourcePcideviceDelete: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("deviceId", d.Id())
|
||||
urlValues.Add("force", strconv.FormatBool(d.Get("force").(bool)))
|
||||
deviceID, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req := pcidevice.DeleteRequest{
|
||||
DeviceID: deviceID,
|
||||
Force: d.Get("force").(bool),
|
||||
}
|
||||
|
||||
_, err := c.DecortAPICall(ctx, "POST", pcideviceDeleteAPI, urlValues)
|
||||
_, err := c.CloudBroker().PCIDevice().Delete(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
@@ -115,33 +112,33 @@ func resourcePcideviceDelete(ctx context.Context, d *schema.ResourceData, m inte
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourcePcideviceEdit(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
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)
|
||||
urlValues := &url.Values{}
|
||||
api := ""
|
||||
|
||||
urlValues.Add("deviceId", strconv.Itoa(d.Get("device_id").(int)))
|
||||
|
||||
if state {
|
||||
api = pcideviceEnableAPI
|
||||
req := pcidevice.EnableRequest{
|
||||
DeviceID: uint64(d.Get("device_id").(int)),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().PCIDevice().Enable(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
} else {
|
||||
api = pcideviceDisableAPI
|
||||
}
|
||||
req := pcidevice.DisableRequest{
|
||||
DeviceID: uint64(d.Get("device_id").(int)),
|
||||
}
|
||||
|
||||
_, err := c.DecortAPICall(ctx, "POST", api, urlValues)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
_, err := c.CloudBroker().PCIDevice().Disable(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
diagnostics := resourcePcideviceRead(ctx, d, m)
|
||||
if diagnostics != nil {
|
||||
return diagnostics
|
||||
}
|
||||
|
||||
return nil
|
||||
return resourcePcideviceRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourcePcideviceSchemaMake() map[string]*schema.Schema {
|
||||
@@ -225,7 +222,7 @@ func ResourcePcidevice() *schema.Resource {
|
||||
|
||||
CreateContext: resourcePcideviceCreate,
|
||||
ReadContext: resourcePcideviceRead,
|
||||
UpdateContext: resourcePcideviceEdit,
|
||||
UpdateContext: resourcePcideviceUpdate,
|
||||
DeleteContext: resourcePcideviceDelete,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
|
||||
@@ -36,19 +36,20 @@ import (
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/pcidevice"
|
||||
)
|
||||
|
||||
func utilityPcideviceCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*Pcidevice, error) {
|
||||
func utilityPcideviceCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*pcidevice.ItemPCIDevice, error) {
|
||||
pcideviceList, err := utilityPcideviceListCheckPresence(ctx, m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pcideviceId := 0
|
||||
var pcideviceId uint64
|
||||
if (d.Get("device_id").(int)) != 0 {
|
||||
pcideviceId = d.Get("device_id").(int)
|
||||
pcideviceId = uint64(d.Get("device_id").(int))
|
||||
} else {
|
||||
id, _ := strconv.Atoi(d.Id())
|
||||
id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
pcideviceId = id
|
||||
}
|
||||
|
||||
|
||||
@@ -33,23 +33,15 @@ package pcidevice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/pcidevice"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityPcideviceListCheckPresence(ctx context.Context, m interface{}) (PcideviceList, error) {
|
||||
pcideviceList := PcideviceList{}
|
||||
func utilityPcideviceListCheckPresence(ctx context.Context, m interface{}) (pcidevice.ListPCIDevices, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
pcideviceListRaw, err := c.DecortAPICall(ctx, "POST", pcideviceListAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(pcideviceListRaw), &pcideviceList)
|
||||
pcideviceList, err := c.CloudBroker().PCIDevice().List(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user