Add models, data source

2.2
stSolo 3 years ago
parent 8a716edac3
commit c110239225

@ -0,0 +1,196 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
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.
*/
/*
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
Technology platfom.
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
*/
package decort
import (
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
func flattenSepList(sl SepList) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, item := range sl {
temp := map[string]interface{}{
"ckey": item.Ckey,
"meta": 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,
}
res = append(res, temp)
}
return res
}
func dataSourceSepListRead(d *schema.ResourceData, m interface{}) error {
sepList, err := utilitySepListCheckPresence(d, m)
if err != nil {
return err
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenSepList(sepList))
return nil
}
func dataSourceSepDesSchemaMake(sh map[string]*schema.Schema) map[string]*schema.Schema {
sh["config"] = &schema.Schema{
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"api_ips": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"protocol": {
Type: schema.TypeString,
Computed: true,
},
"decs3o_app_secret": {
Type: schema.TypeString,
Computed: true,
},
"format": {
Type: schema.TypeString,
Computed: true,
},
"edgeuser_password": {
Type: schema.TypeString,
Computed: true,
},
"edgeuser_name": {
Type: schema.TypeString,
Computed: true,
},
"decs3o_app_id": {
Type: schema.TypeString,
Computed: true,
},
"transport": {
Type: schema.TypeString,
Computed: true,
},
},
},
}
return sh
}
func dataSourceSepCommonSchemaMake() 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,
},
}
}
func dataSourceSepDes() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
Read: dataSourceSepDesRead,
Timeouts: &schema.ResourceTimeout{
Read: &Timeout30s,
Default: &Timeout60s,
},
Schema: dataSourceSepDesSchemaMake(),
}
}

@ -0,0 +1,172 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
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.
*/
/*
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
Technology platfom.
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
*/
package decort
import (
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
func flattenSepList(sl SepList) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, item := range sl {
temp := map[string]interface{}{
"ckey": item.Ckey,
"meta": 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,
}
res = append(res, temp)
}
return res
}
func dataSourceSepListRead(d *schema.ResourceData, m interface{}) error {
sepList, err := utilitySepListCheckPresence(d, m)
if err != nil {
return 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,
},
}
}
func dataSourceSepList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
Read: dataSourceSepListRead,
Timeouts: &schema.ResourceTimeout{
Read: &Timeout30s,
Default: &Timeout60s,
},
Schema: dataSourceSepListSchemaMake(),
}
}

@ -835,3 +835,220 @@ type Snapshot struct {
}
type SnapshotList []Snapshot
///////////////////
///// SEP API /////
///////////////////
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 sepDislListAPI = "/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"
///Sep Configs
///////DES config
type DesDiskDelQueue struct {
PurgatoryId int `json:"purgatory_id"`
}
type DesHousekeepingSettings struct {
DiskDelQueue DesDiskDelQueue `json:"disk_del_queue"`
}
type URI struct {
IP string `json:"ip"`
Port int `json:"port"`
}
type DesConfigPool struct {
Types []string `json:"types"`
ReferenceId string `json:"referenceId"`
Name string `json:"name"`
PagecacheRatio int `json:"pagecache_ratio"`
URIS []URI `json:"uris"`
}
type DesConfigSep struct {
ApiIps []string `json:"API_IPs"`
Protocol string `json:"protocol"`
Desc3oAppSecret string `json:"decs3o_app_secret"`
Desc3oAppId string `json:"decs3o_app_id"`
Format string `json:"format"`
EdgeuserName string `json:"edgeuser_name"`
EdgeuserPassword string `json:"edgeuser_password"`
HousekeepingSettings DesHousekeepingSettings `json:"housekeeping_settings"`
Pools []DesConfigPool `json:"pools"`
Transport string `json:"transport"`
}
///////Hitachi config
type HitachiConfigPool struct {
CloneTechnology string `json:"clone_technology"`
Id int `json:"id"`
MaxLdevId int `json:"maxLdevId"`
MinLdevId int `json:"minLdevId"`
Name string `json:"name"`
SnapshotPoolId int `json:"snapshot_pool_id"`
Snapshotable bool `json:"snapshotable"`
Types []string `json:"types"`
UsageLimit int `json:"usage_limit"`
}
type HitachiConfigSep struct {
ApiUrls []string `json:"API_URLs"`
SN int `json:"SN"`
DiskMaxSize int `json:"disk_max_size"`
Format string `json:"format"`
HostGroupNumMax int `json:"hostGroupNumMax"`
HostGroupNumMin int `json:"hostGroupNumMin"`
HostGroupNumber int `json:"hostGroupNumber"`
HousekeepingSettings HousekeepingSettings `json:"housekeeping_settings"`
MGMTPassword string `json:"mgmt_password"`
MGMTUser string `json:"mgmt_user"`
Model string `json:"model"`
NamePrefix string `json:"name_prefix"`
Pools []HitachiConfigPool `json:"pools"`
Ports []string `json:"ports"`
Protocol string `json:"protocol"`
SSLVerify bool `json:"ssl_verify"`
}
///////Tatlin Config
type TatlinPort struct {
IPS []string `json:"ips"`
IQN string `json:"iqn"`
Name string `json:"name"`
}
type Pool struct {
Name string `json:"name"`
Types []string `json:"types"`
UsageLimit int `json:"usage_limit"`
}
type TatlinTechDisk struct {
Name string `json:"name"`
Size int `json:"size"`
Pool string `json:"pool"`
WWID string `json:"wwid"`
}
type DiskDelQueue struct {
PurgeAttemptsThreshold int `json:"purge_attempts_threshold"`
}
type HousekeepingSettings struct {
DiskDelQueue DiskDelQueue `json:"disk_del_queue"`
}
type TatlinConfigSep struct {
ApiUrls []string `json:"API_URLs"`
DiskMaxSize int `json:"disk_max_size"`
Format string `json:"format"`
EdgeuserName string `json:"edgeuser_name"`
EdgeuserPassword string `json:"edgeuser_password"`
MGMTPassword string `json:"mgmt_password"`
MGMTUser string `json:"mgmt_user"`
HostGroupName string `json:"hostGroupName"`
Model string `json:"model"`
NamePrefix string `json:"name_prefix"`
Ports []TatlinPort `json:"ports"`
Pools []Pool `json:"pools"`
Protocol string `json:"protocol"`
TechDisk TatlinTechDisk `json:"techDisk"`
HousekeepingSettings HousekeepingSettings `json:"housekeeping_settings"`
}
//////Huawei Dorado
type HuaweiDoradoPort struct {
IP string `json:"ip"`
Name string `json:"name"`
}
type HuaweiDoradoGroup struct {
HostGroup []string `json:"hostgroup"`
LungGroup []string `json:"lungroup"`
PortGroup []string `json:"portgroup"`
}
type HuaweiDoradoConfigSep struct {
ApiUrls []string `json:"API_URLs"`
DiskMaxSize int `json:"disk_max_size"`
Format string `json:"format"`
EdgeuserName string `json:"edgeuser_name"`
EdgeuserPassword string `json:"edgeuser_password"`
MGMTPassword string `json:"mgmt_password"`
MGMTUser string `json:"mgmt_user"`
HostGroupName string `json:"hostGroupName"`
Model string `json:"model"`
NamePrefix string `json:"name_prefix"`
Pools []Pool `json:"pools"`
Protocol string `json:"protocol"`
Ports []HuaweiDoradoPort `json:"ports"`
Groups []HuaweiDoradoGroup `json:"groups"`
HousekeepingSettings HousekeepingSettings `json:"housekeeping_settings"`
}
////////////SEP
type SepCommon 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"`
}
type SepList []SepCommon
type DesSep struct {
SepCommon
Config DesConfigSep `json:"config"`
}
type HitachiSep struct {
SepCommon
Config HitachiConfigSep `json:"config"`
}
type TatlinSep struct {
SepCommon
Config TatlinConfigSep `json:"config"`
}
type HuaweiDoradoSep struct {
SepCommon
Config HuaweiDoradoConfigSep `json:"config"`
}

@ -0,0 +1,61 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
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.
*/
/*
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
Technology platfom.
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
*/
package decort
import (
"encoding/json"
"net/url"
"strconv"
log "github.com/sirupsen/logrus"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
func utilitySepListCheckPresence(d *schema.ResourceData, m interface{}) (SepList, error) {
sepList := SepList{}
controller := m.(*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 := controller.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
}
Loading…
Cancel
Save