Migrate to sdkv2 and project structure refactoring

This commit is contained in:
stSolo
2022-06-29 11:34:14 +03:00
parent 3c2eb0407c
commit 3613bbea28
164 changed files with 5947 additions and 3928 deletions

View File

@@ -0,0 +1,59 @@
/*
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package sep
const sepAddConsumerNodesAPI = "/restmachine/cloudbroker/sep/addConsumerNodes"
const sepDelConsumerNodesAPI = "/restmachine/cloudbroker/sep/delConsumerNodes"
const sepAddProviderNodesAPI = "/restmachine/cloudbroker/sep/addProviderNodes"
const sepConfigFieldEditAPI = "/restmachine/cloudbroker/sep/configFieldEdit"
const sepConfigInsertAPI = "/restmachine/cloudbroker/sep/configInsert"
const sepConfigValidateAPI = "/restmachine/cloudbroker/sep/configValidate"
const sepConsumptionAPI = "/restmachine/cloudbroker/sep/consumption"
const sepDecommissionAPI = "/restmachine/cloudbroker/sep/decommission"
const sepEnableAPI = "/restmachine/cloudbroker/sep/enable"
const sepDisableAPI = "/restmachine/cloudbroker/sep/disable"
const sepDiskListAPI = "/restmachine/cloudbroker/sep/diskList"
const sepGetAPI = "/restmachine/cloudbroker/sep/get"
const sepGetConfigAPI = "/restmachine/cloudbroker/sep/getConfig"
const sepGetPoolAPI = "/restmachine/cloudbroker/sep/getPool"
const sepCreateAPI = "/restmachine/cloudbroker/sep/create"
const sepDeleteAPI = "/restmachine/cloudbroker/sep/delete"
const sepListAPI = "/restmachine/cloudbroker/sep/list"
const sepUpdateCapacityLimitAPI = "/restmachine/cloudbroker/sep/updateCapacityLimit"

View File

@@ -0,0 +1,156 @@
/*
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package sep
import (
"context"
"encoding/json"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/rudecs/terraform-provider-decort/internal/constants"
"github.com/rudecs/terraform-provider-decort/internal/flattens"
)
func dataSourceSepRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
desSep, err := utilitySepCheckPresence(d, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("ckey", desSep.Ckey)
d.Set("meta", flattens.FlattenMeta(desSep.Meta))
d.Set("consumed_by", desSep.ConsumedBy)
d.Set("desc", desSep.Desc)
d.Set("gid", desSep.Gid)
d.Set("guid", desSep.Guid)
d.Set("sep_id", desSep.Id)
d.Set("milestones", desSep.Milestones)
d.Set("name", desSep.Name)
d.Set("obj_status", desSep.ObjStatus)
d.Set("provided_by", desSep.ProvidedBy)
d.Set("tech_status", desSep.TechStatus)
d.Set("type", desSep.Type)
data, _ := json.Marshal(desSep.Config)
d.Set("config", string(data))
return nil
}
func dataSourceSepCSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeInt,
Required: true,
Description: "sep type des id",
},
"ckey": {
Type: schema.TypeString,
Computed: true,
},
"meta": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"consumed_by": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"desc": {
Type: schema.TypeString,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"obj_status": {
Type: schema.TypeString,
Computed: true,
},
"provided_by": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"config": {
Type: schema.TypeString,
Computed: true,
},
}
}
func DataSourceSep() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceSepRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceSepCSchemaMake(),
}
}

View File

@@ -0,0 +1,87 @@
/*
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package sep
import (
"context"
"encoding/json"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/rudecs/terraform-provider-decort/internal/constants"
)
func dataSourceSepConfigRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
sepConfig, err := utilitySepConfigCheckPresence(d, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
data, _ := json.Marshal(sepConfig)
d.Set("config", string(data))
return nil
}
func dataSourceSepConfigSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeInt,
Required: true,
Description: "storage endpoint provider ID",
},
"config": {
Type: schema.TypeString,
Computed: true,
Description: "sep config json string",
},
}
}
func DataSourceSepConfig() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceSepConfigRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceSepConfigSchemaMake(),
}
}

View File

@@ -0,0 +1,206 @@
/*
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package sep
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/rudecs/terraform-provider-decort/internal/constants"
)
func dataSourceSepConsumptionRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
sepCons, err := utilitySepConsumptionCheckPresence(d, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("type", sepCons.Type)
d.Set("total", flattenSepConsumption(sepCons.Total))
d.Set("by_pool", flattenSepConsumptionPools(sepCons.ByPool))
return nil
}
func flattenSepConsumptionPools(mp map[string]SepConsumptionInd) []map[string]interface{} {
sh := make([]map[string]interface{}, 0)
for k, v := range mp {
temp := map[string]interface{}{
"name": k,
"disk_count": v.DiskCount,
"disk_usage": v.DiskUsage,
"snapshot_count": v.SnapshotCount,
"snapshot_usage": v.SnapshotUsage,
"usage": v.Usage,
"usage_limit": v.UsageLimit,
}
sh = append(sh, temp)
}
return sh
}
func flattenSepConsumption(sc SepConsumptionTotal) []map[string]interface{} {
sh := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"capacity_limit": sc.CapacityLimit,
"disk_count": sc.DiskCount,
"disk_usage": sc.DiskUsage,
"snapshot_count": sc.SnapshotCount,
"snapshot_usage": sc.SnapshotUsage,
"usage": sc.Usage,
"usage_limit": sc.UsageLimit,
}
sh = append(sh, temp)
return sh
}
func dataSourceSepConsumptionSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeInt,
Required: true,
Description: "sep id",
},
"by_pool": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
Description: "pool name",
},
"disk_count": {
Type: schema.TypeInt,
Computed: true,
Description: "number of disks",
},
"disk_usage": {
Type: schema.TypeInt,
Computed: true,
Description: "disk usage",
},
"snapshot_count": {
Type: schema.TypeInt,
Computed: true,
Description: "number of snapshots",
},
"snapshot_usage": {
Type: schema.TypeInt,
Computed: true,
Description: "snapshot usage",
},
"usage": {
Type: schema.TypeInt,
Computed: true,
Description: "usage",
},
"usage_limit": {
Type: schema.TypeInt,
Computed: true,
Description: "usage limit",
},
},
},
Description: "consumption divided by pool",
},
"total": {
Type: schema.TypeList,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"capacity_limit": {
Type: schema.TypeInt,
Computed: true,
},
"disk_count": {
Type: schema.TypeInt,
Computed: true,
Description: "number of disks",
},
"disk_usage": {
Type: schema.TypeInt,
Computed: true,
Description: "disk usage",
},
"snapshot_count": {
Type: schema.TypeInt,
Computed: true,
Description: "number of snapshots",
},
"snapshot_usage": {
Type: schema.TypeInt,
Computed: true,
Description: "snapshot usage",
},
"usage": {
Type: schema.TypeInt,
Computed: true,
Description: "usage",
},
"usage_limit": {
Type: schema.TypeInt,
Computed: true,
Description: "usage limit",
},
},
},
Description: "total consumption",
},
"type": {
Type: schema.TypeString,
Computed: true,
Description: "sep type",
},
}
}
func DataSourceSepConsumption() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceSepConsumptionRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceSepConsumptionSchemaMake(),
}
}

View File

@@ -0,0 +1,93 @@
/*
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package sep
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/rudecs/terraform-provider-decort/internal/constants"
)
func dataSourceSepDiskListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
sepDiskList, err := utilitySepDiskListCheckPresence(d, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", sepDiskList)
return nil
}
func dataSourceSepDiskListSchemaMake() map[string]*schema.Schema {
rets := map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeInt,
Required: true,
Description: "storage endpoint provider ID",
},
"pool_name": {
Type: schema.TypeString,
Optional: true,
Description: "pool name",
},
"items": {
Type: schema.TypeList,
Computed: true,
Description: "sep disk list",
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
}
return rets
}
func DataSourceSepDiskList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceSepDiskListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceSepDiskListSchemaMake(),
}
}

View File

@@ -0,0 +1,191 @@
/*
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package sep
import (
"context"
"encoding/json"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/rudecs/terraform-provider-decort/internal/constants"
"github.com/rudecs/terraform-provider-decort/internal/flattens"
)
func flattenSepList(sl SepList) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, item := range sl {
data, _ := json.Marshal(item.Config)
temp := map[string]interface{}{
"ckey": item.Ckey,
"meta": flattens.FlattenMeta(item.Meta),
"consumed_by": item.ConsumedBy,
"desc": item.Desc,
"gid": item.Gid,
"guid": item.Guid,
"sep_id": item.Id,
"milestones": item.Milestones,
"name": item.Name,
"obj_status": item.ObjStatus,
"provided_by": item.ProvidedBy,
"tech_status": item.TechStatus,
"type": item.Type,
"config": string(data),
}
res = append(res, temp)
}
return res
}
func dataSourceSepListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
sepList, err := utilitySepListCheckPresence(d, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenSepList(sepList))
return nil
}
func dataSourceSepListSchemaMake() map[string]*schema.Schema {
rets := map[string]*schema.Schema{
"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: "sep list",
Elem: &schema.Resource{
Schema: dataSourceSepShortSchemaMake(),
},
},
}
return rets
}
func dataSourceSepShortSchemaMake() 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,
},
},
"consumed_by": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"desc": {
Type: schema.TypeString,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"sep_id": {
Type: schema.TypeInt,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"obj_status": {
Type: schema.TypeString,
Computed: true,
},
"provided_by": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"config": {
Type: schema.TypeString,
Computed: true,
},
}
}
func DataSourceSepList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceSepListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceSepListSchemaMake(),
}
}

View File

@@ -0,0 +1,90 @@
/*
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package sep
import (
"context"
"encoding/json"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/rudecs/terraform-provider-decort/internal/constants"
)
func dataSourceSepPoolRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
sepPool, err := utilitySepPoolCheckPresence(d, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
data, _ := json.Marshal(sepPool)
d.Set("pool", string(data))
return nil
}
func dataSourceSepPoolSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeInt,
Required: true,
Description: "storage endpoint provider ID",
},
"pool_name": {
Type: schema.TypeString,
Required: true,
Description: "pool name",
},
"pool": {
Type: schema.TypeString,
Computed: true,
},
}
}
func DataSourceSepPool() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceSepPoolRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceSepPoolSchemaMake(),
}
}

View File

@@ -0,0 +1,77 @@
/*
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package sep
///Sep Models
type SepConsumptionInd struct {
DiskCount int `json:"disk_count"`
DiskUsage int `json:"disk_usage"`
SnapshotCount int `json:"snapshot_count"`
SnapshotUsage int `json:"snapshot_usage"`
Usage int `json:"usage"`
UsageLimit int `json:"usage_limit"`
}
type SepConsumptionTotal struct {
CapacityLimit int `json:"capacity_limit"`
SepConsumptionInd
}
type SepConsumption struct {
Total SepConsumptionTotal `json:"total"`
Type string `json:"type"`
ByPool map[string]SepConsumptionInd `json:"byPool"`
}
type SepDiskList []int
type Sep struct {
Ckey string `json:"_ckey"`
Meta []interface{} `json:"_meta"`
ConsumedBy []int `json:"consumedBy"`
Desc string `json:"desc"`
Gid int `json:"gid"`
Guid int `json:"guid"`
Id int `json:"id"`
Milestones int `json:"milestones"`
Name string `json:"name"`
ObjStatus string `json:"objStatus"`
ProvidedBy []int `json:"providedBy"`
TechStatus string `json:"techStatus"`
Type string `json:"type"`
Config SepConfig `json:"config"`
}
type SepConfig map[string]interface{}
type SepList []Sep
type SepPool map[string]interface{}

View File

@@ -0,0 +1,543 @@
/*
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package sep
import (
"context"
"encoding/json"
"errors"
"net/url"
"strconv"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/rudecs/terraform-provider-decort/internal/constants"
"github.com/rudecs/terraform-provider-decort/internal/controller"
"github.com/rudecs/terraform-provider-decort/internal/flattens"
log "github.com/sirupsen/logrus"
)
func resourceSepCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceSepCreate: called for sep %s", d.Get("name").(string))
if sepId, ok := d.GetOk("sep_id"); ok {
if exists, err := resourceSepExists(d, m); exists {
if err != nil {
return diag.FromErr(err)
}
d.SetId(strconv.Itoa(sepId.(int)))
diagnostics := resourceSepRead(ctx, d, m)
if diagnostics != nil {
return diagnostics
}
return nil
}
return diag.Errorf("provided sep id does not exist")
}
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
urlValues.Add("name", d.Get("name").(string))
urlValues.Add("gid", strconv.Itoa(d.Get("gid").(int)))
urlValues.Add("sep_type", d.Get("type").(string))
if desc, ok := d.GetOk("desc"); ok {
urlValues.Add("description", desc.(string))
}
if configString, ok := d.GetOk("config"); ok {
urlValues.Add("config", configString.(string))
}
if enable, ok := d.GetOk("enable"); ok {
urlValues.Add("enable", strconv.FormatBool(enable.(bool)))
}
tstr := d.Get("consumed_by").([]interface{})
temp := ""
l := len(tstr)
for i, str := range tstr {
s := "\"" + str.(string) + "\""
if i != (l - 1) {
s += ","
}
temp = temp + s
}
temp = "[" + temp + "]"
urlValues.Add("consumer_nids", temp)
tstr = d.Get("provided_by").([]interface{})
temp = ""
l = len(tstr)
for i, str := range tstr {
s := "\"" + str.(string) + "\""
if i != (l - 1) {
s += ","
}
temp = temp + s
}
temp = "[" + temp + "]"
urlValues.Add("provider_nids", temp)
sepId, err := c.DecortAPICall("POST", sepCreateAPI, urlValues)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(sepId)
d.Set("sep_id", sepId)
diagnostics := resourceSepRead(ctx, d, m)
if diagnostics != nil {
return diagnostics
}
d.SetId(id.String())
return nil
}
func resourceSepRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceSepRead: called for %s id: %d", d.Get("name").(string), d.Get("sep_id").(int))
sep, err := utilitySepCheckPresence(d, m)
if sep == nil {
d.SetId("")
return diag.FromErr(err)
}
d.Set("ckey", sep.Ckey)
d.Set("meta", flattens.FlattenMeta(sep.Meta))
d.Set("consumed_by", sep.ConsumedBy)
d.Set("desc", sep.Desc)
d.Set("gid", sep.Gid)
d.Set("guid", sep.Guid)
d.Set("sep_id", sep.Id)
d.Set("milestones", sep.Milestones)
d.Set("name", sep.Name)
d.Set("obj_status", sep.ObjStatus)
d.Set("provided_by", sep.ProvidedBy)
d.Set("tech_status", sep.TechStatus)
d.Set("type", sep.Type)
data, _ := json.Marshal(sep.Config)
d.Set("config", string(data))
return nil
}
func resourceSepDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceSepDelete: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int))
sepDes, err := utilitySepCheckPresence(d, m)
if sepDes == nil {
if err != nil {
return diag.FromErr(err)
}
return nil
}
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
_, err = c.DecortAPICall("POST", sepDeleteAPI, urlValues)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func resourceSepExists(d *schema.ResourceData, m interface{}) (bool, error) {
log.Debugf("resourceSepExists: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int))
sepDes, err := utilitySepCheckPresence(d, m)
if sepDes == nil {
if err != nil {
return false, err
}
return false, nil
}
return true, nil
}
func resourceSepEdit(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceSepEdit: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int))
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
if d.HasChange("decommission") {
decommission := d.Get("decommission").(bool)
if decommission {
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
urlValues.Add("clear_physically", strconv.FormatBool(d.Get("clear_physically").(bool)))
_, err := c.DecortAPICall("POST", sepDecommissionAPI, urlValues)
if err != nil {
return diag.FromErr(err)
}
}
}
urlValues = &url.Values{}
if d.HasChange("upd_capacity_limit") {
updCapacityLimit := d.Get("upd_capacity_limit").(bool)
if updCapacityLimit {
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
_, err := c.DecortAPICall("POST", sepUpdateCapacityLimitAPI, urlValues)
if err != nil {
return diag.FromErr(err)
}
}
}
urlValues = &url.Values{}
if d.HasChange("config") {
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
urlValues.Add("config", d.Get("config").(string))
_, err := c.DecortAPICall("POST", sepConfigValidateAPI, urlValues)
if err != nil {
return diag.FromErr(err)
}
_, err = c.DecortAPICall("POST", sepConfigInsertAPI, urlValues)
if err != nil {
return diag.FromErr(err)
}
}
urlValues = &url.Values{}
if d.HasChange("field_edit") {
fieldConfig := d.Get("field_edit").([]interface{})
field := fieldConfig[0].(map[string]interface{})
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
urlValues.Add("field_name", field["field_name"].(string))
urlValues.Add("field_value", field["field_value"].(string))
urlValues.Add("field_type", field["field_type"].(string))
_, err := c.DecortAPICall("POST", sepConfigFieldEditAPI, urlValues)
if err != nil {
return diag.FromErr(err)
}
}
urlValues = &url.Values{}
if d.HasChange("enable") {
err := resourceSepChangeEnabled(d, m)
if err != nil {
return diag.FromErr(err)
}
}
urlValues = &url.Values{}
if d.HasChange("consumed_by") {
err := resourceSepUpdateNodes(d, m)
if err != nil {
return diag.FromErr(err)
}
}
urlValues = &url.Values{}
if d.HasChange("provided_by") {
err := resourceSepUpdateProviders(d, m)
if err != nil {
return diag.FromErr(err)
}
}
urlValues = &url.Values{}
if diagnostics := resourceSepRead(ctx, d, m); diagnostics != nil {
return diagnostics
}
return nil
}
func resourceSepChangeEnabled(d *schema.ResourceData, m interface{}) error {
var api string
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
if d.Get("enable").(bool) {
api = sepEnableAPI
} else {
api = sepDisableAPI
}
resp, err := c.DecortAPICall("POST", api, urlValues)
if err != nil {
return err
}
res, err := strconv.ParseBool(resp)
if err != nil {
return err
}
if !res {
return errors.New("Cannot enable/disable")
}
return nil
}
func resourceSepUpdateNodes(d *schema.ResourceData, m interface{}) error {
log.Debugf("resourceSepUpdateNodes: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int))
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
t1, t2 := d.GetChange("consumed_by")
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
consumedIds := make([]interface{}, 0)
temp := ""
api := ""
if d1, d2 := t1.([]interface{}), t2.([]interface{}); len(d1) > len(d2) {
for _, n := range d2 {
if !findElInt(d1, n) {
consumedIds = append(consumedIds, n)
}
}
api = sepDelConsumerNodesAPI
} else {
consumedIds = d.Get("consumed_by").([]interface{})
api = sepAddConsumerNodesAPI
}
l := len(consumedIds)
for i, consumedId := range consumedIds {
s := strconv.Itoa(consumedId.(int))
if i != (l - 1) {
s += ","
}
temp = temp + s
}
temp = "[" + temp + "]"
urlValues.Add("consumer_nids", temp)
_, err := c.DecortAPICall("POST", api, urlValues)
if err != nil {
return err
}
return nil
}
func findElInt(sl []interface{}, el interface{}) bool {
for _, e := range sl {
if e.(int) == el.(int) {
return true
}
}
return false
}
func resourceSepUpdateProviders(d *schema.ResourceData, m interface{}) error {
log.Debugf("resourceSepUpdateProviders: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int))
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
providerIds := d.Get("provided_by").([]interface{})
temp := ""
l := len(providerIds)
for i, providerId := range providerIds {
s := strconv.Itoa(providerId.(int))
if i != (l - 1) {
s += ","
}
temp = temp + s
}
temp = "[" + temp + "]"
urlValues.Add("provider_nids", temp)
_, err := c.DecortAPICall("POST", sepAddProviderNodesAPI, urlValues)
if err != nil {
return err
}
return nil
}
func resourceSepSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "sep type des id",
},
"upd_capacity_limit": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Update SEP capacity limit",
},
"decommission": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "unlink everything that exists from SEP",
},
"clear_physically": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "clear disks and images physically",
},
"config": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "sep config string",
},
"ckey": {
Type: schema.TypeString,
Computed: true,
},
"meta": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"consumed_by": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
Description: "list of consumer nodes IDs",
},
"desc": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: "sep description",
},
"gid": {
Type: schema.TypeInt,
Required: true,
Description: "grid (platform) ID",
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Required: true,
Description: "SEP name",
},
"obj_status": {
Type: schema.TypeString,
Computed: true,
},
"provided_by": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
Description: "list of provider nodes IDs",
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Required: true,
Description: "type of storage",
},
"enable": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "enable SEP after creation",
},
"field_edit": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"field_name": {
Type: schema.TypeString,
Required: true,
},
"field_value": {
Type: schema.TypeString,
Required: true,
},
"field_type": {
Type: schema.TypeString,
Required: true,
},
},
},
},
}
}
func ResourceSep() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceSepCreate,
ReadContext: resourceSepRead,
UpdateContext: resourceSepEdit,
DeleteContext: resourceSepDelete,
Exists: resourceSepExists,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout60s,
Read: &constants.Timeout30s,
Update: &constants.Timeout60s,
Delete: &constants.Timeout60s,
Default: &constants.Timeout60s,
},
Schema: resourceSepSchemaMake(),
}
}

View File

@@ -0,0 +1,205 @@
/*
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package sep
import (
"context"
"encoding/json"
"net/url"
"strconv"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/rudecs/terraform-provider-decort/internal/constants"
"github.com/rudecs/terraform-provider-decort/internal/controller"
log "github.com/sirupsen/logrus"
)
func resourceSepConfigCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceSepConfigCreate: called for sep id %d", d.Get("sep_id").(int))
if _, ok := d.GetOk("sep_id"); ok {
if exists, err := resourceSepConfigExists(d, m); exists {
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
diagnostics := resourceSepConfigRead(ctx, d, m)
if diagnostics != nil {
return diagnostics
}
return nil
}
return diag.Errorf("provided sep id config does not exist")
}
return resourceSepConfigRead(ctx, d, m)
}
func resourceSepConfigRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceSepConfigRead: called for sep id: %d", d.Get("sep_id").(int))
sepConfig, err := utilitySepConfigCheckPresence(d, m)
if sepConfig == nil {
d.SetId("")
return diag.FromErr(err)
}
data, _ := json.Marshal(sepConfig)
d.Set("config", string(data))
return nil
}
func resourceSepConfigDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
d.SetId("")
return nil
}
func resourceSepConfigExists(d *schema.ResourceData, m interface{}) (bool, error) {
log.Debugf("resourceSepConfigExists: called for sep id: %d", d.Get("sep_id").(int))
sepDesConfig, err := utilitySepConfigCheckPresence(d, m)
if sepDesConfig == nil {
if err != nil {
return false, err
}
return false, nil
}
return true, nil
}
func resourceSepConfigEdit(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceSepConfigEdit: called for sep id: %d", d.Get("sep_id").(int))
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
if d.HasChange("config") {
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
urlValues.Add("config", d.Get("config").(string))
_, err := c.DecortAPICall("POST", sepConfigValidateAPI, urlValues)
if err != nil {
return diag.FromErr(err)
}
_, err = c.DecortAPICall("POST", sepConfigInsertAPI, urlValues)
if err != nil {
return diag.FromErr(err)
}
}
urlValues = &url.Values{}
if d.HasChange("field_edit") {
fieldConfig := d.Get("field_edit").([]interface{})
field := fieldConfig[0].(map[string]interface{})
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
urlValues.Add("field_name", field["field_name"].(string))
urlValues.Add("field_value", field["field_value"].(string))
urlValues.Add("field_type", field["field_type"].(string))
_, err := c.DecortAPICall("POST", sepConfigFieldEditAPI, urlValues)
if err != nil {
return diag.FromErr(err)
}
}
diagnostics := resourceSepConfigRead(ctx, d, m)
if diagnostics != nil {
return diagnostics
}
return nil
}
func resourceSepConfigSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeInt,
Required: true,
},
"config": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"field_edit": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"field_name": {
Type: schema.TypeString,
Required: true,
},
"field_value": {
Type: schema.TypeString,
Required: true,
},
"field_type": {
Type: schema.TypeString,
Required: true,
},
},
},
},
}
}
func ResourceSepConfig() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceSepConfigCreate,
ReadContext: resourceSepConfigRead,
UpdateContext: resourceSepConfigEdit,
DeleteContext: resourceSepConfigDelete,
Exists: resourceSepConfigExists,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout60s,
Read: &constants.Timeout30s,
Update: &constants.Timeout60s,
Delete: &constants.Timeout60s,
Default: &constants.Timeout60s,
},
Schema: resourceSepConfigSchemaMake(),
}
}

View File

@@ -0,0 +1,69 @@
/*
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package sep
import (
"encoding/json"
"net/url"
"strconv"
"github.com/rudecs/terraform-provider-decort/internal/controller"
log "github.com/sirupsen/logrus"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilitySepCheckPresence(d *schema.ResourceData, m interface{}) (*Sep, error) {
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
sep := &Sep{}
if d.Get("sep_id").(int) == 0 {
urlValues.Add("sep_id", d.Id())
} else {
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
}
log.Debugf("utilitySepCheckPresence: load sep")
sepRaw, err := c.DecortAPICall("POST", sepGetAPI, urlValues)
if err != nil {
return nil, err
}
err = json.Unmarshal([]byte(sepRaw), sep)
if err != nil {
return nil, err
}
return sep, nil
}

View File

@@ -0,0 +1,65 @@
/*
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package sep
import (
"encoding/json"
"net/url"
"strconv"
"github.com/rudecs/terraform-provider-decort/internal/controller"
log "github.com/sirupsen/logrus"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilitySepConfigCheckPresence(d *schema.ResourceData, m interface{}) (SepConfig, error) {
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
sepConfig := SepConfig{}
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
log.Debugf("utilitySepConfigCheckPresence: load sep config")
sepConfigRaw, err := c.DecortAPICall("POST", sepGetConfigAPI, urlValues)
if err != nil {
return nil, err
}
err = json.Unmarshal([]byte(sepConfigRaw), &sepConfig)
if err != nil {
return nil, err
}
return sepConfig, nil
}

View File

@@ -0,0 +1,62 @@
/*
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package sep
import (
"encoding/json"
"net/url"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/rudecs/terraform-provider-decort/internal/controller"
)
func utilitySepConsumptionCheckPresence(d *schema.ResourceData, m interface{}) (*SepConsumption, error) {
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
sepCons := &SepConsumption{}
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
sepConsRaw, err := c.DecortAPICall("POST", sepConsumptionAPI, urlValues)
if err != nil {
return nil, err
}
err = json.Unmarshal([]byte(sepConsRaw), sepCons)
if err != nil {
return nil, err
}
return sepCons, nil
}

View File

@@ -0,0 +1,69 @@
/*
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package sep
import (
"encoding/json"
"net/url"
"strconv"
"github.com/rudecs/terraform-provider-decort/internal/controller"
log "github.com/sirupsen/logrus"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilitySepDiskListCheckPresence(d *schema.ResourceData, m interface{}) ([]int, error) {
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
sepDiskList := SepDiskList{}
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
if poolName, ok := d.GetOk("pool_name"); ok {
urlValues.Add("pool_name", poolName.(string))
}
log.Debugf("utilitySepDiskListCheckPresence: load sep")
sepDiskListRaw, err := c.DecortAPICall("POST", sepDiskListAPI, urlValues)
if err != nil {
return nil, err
}
err = json.Unmarshal([]byte(sepDiskListRaw), &sepDiskList)
if err != nil {
return nil, err
}
return sepDiskList, nil
}

View File

@@ -0,0 +1,69 @@
/*
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package sep
import (
"encoding/json"
"net/url"
"strconv"
"github.com/rudecs/terraform-provider-decort/internal/controller"
log "github.com/sirupsen/logrus"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilitySepListCheckPresence(d *schema.ResourceData, m interface{}) (SepList, error) {
sepList := SepList{}
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
if page, ok := d.GetOk("page"); ok {
urlValues.Add("page", strconv.Itoa(page.(int)))
}
if size, ok := d.GetOk("size"); ok {
urlValues.Add("size", strconv.Itoa(size.(int)))
}
log.Debugf("utilitySepListCheckPresence: load image list")
sepListRaw, err := c.DecortAPICall("POST", sepListAPI, urlValues)
if err != nil {
return nil, err
}
err = json.Unmarshal([]byte(sepListRaw), &sepList)
if err != nil {
return nil, err
}
return sepList, nil
}

View File

@@ -0,0 +1,66 @@
/*
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package sep
import (
"encoding/json"
"net/url"
"strconv"
"github.com/rudecs/terraform-provider-decort/internal/controller"
log "github.com/sirupsen/logrus"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilitySepPoolCheckPresence(d *schema.ResourceData, m interface{}) (SepPool, error) {
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
sepPool := SepPool{}
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
urlValues.Add("pool_name", d.Get("pool_name").(string))
log.Debugf("utilitySepDesPoolCheckPresence: load sep")
sepPoolRaw, err := c.DecortAPICall("POST", sepGetPoolAPI, urlValues)
if err != nil {
return nil, err
}
err = json.Unmarshal([]byte(sepPoolRaw), &sepPool)
if err != nil {
return nil, err
}
return sepPool, nil
}