Add an account vins list
This commit is contained in:
@@ -31,14 +31,14 @@ import (
|
|||||||
|
|
||||||
func flattenAccountDisksList(adl AccountDisksList) []map[string]interface{} {
|
func flattenAccountDisksList(adl AccountDisksList) []map[string]interface{} {
|
||||||
res := make([]map[string]interface{}, 0)
|
res := make([]map[string]interface{}, 0)
|
||||||
for _, acc := range adl {
|
for _, ad := range adl {
|
||||||
temp := map[string]interface{}{
|
temp := map[string]interface{}{
|
||||||
"disk_id": acc.ID,
|
"disk_id": ad.ID,
|
||||||
"disk_name": acc.Name,
|
"disk_name": ad.Name,
|
||||||
"pool": acc.Pool,
|
"pool": ad.Pool,
|
||||||
"sep_id": acc.SepId,
|
"sep_id": ad.SepId,
|
||||||
"size_max": acc.SizeMax,
|
"size_max": ad.SizeMax,
|
||||||
"type": acc.Type,
|
"type": ad.Type,
|
||||||
}
|
}
|
||||||
res = append(res, temp)
|
res = append(res, temp)
|
||||||
}
|
}
|
||||||
@@ -46,7 +46,7 @@ func flattenAccountDisksList(adl AccountDisksList) []map[string]interface{} {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceAccountDiskssListRead(d *schema.ResourceData, m interface{}) error {
|
func dataSourceAccountDisksListRead(d *schema.ResourceData, m interface{}) error {
|
||||||
accountDisksList, err := utilityAccountDisksListCheckPresence(d, m)
|
accountDisksList, err := utilityAccountDisksListCheckPresence(d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -107,7 +107,7 @@ func dataSourceAccountDisksList() *schema.Resource {
|
|||||||
return &schema.Resource{
|
return &schema.Resource{
|
||||||
SchemaVersion: 1,
|
SchemaVersion: 1,
|
||||||
|
|
||||||
Read: dataSourceAccountDiskssListRead,
|
Read: dataSourceAccountDisksListRead,
|
||||||
|
|
||||||
Timeouts: &schema.ResourceTimeout{
|
Timeouts: &schema.ResourceTimeout{
|
||||||
Read: &Timeout30s,
|
Read: &Timeout30s,
|
||||||
|
|||||||
174
decort/data_source_account_vins_list.go
Normal file
174
decort/data_source_account_vins_list.go
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
|
Author: Sergey Shubin, <sergey.shubin@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 flattenAccountVinsList(avl AccountVinsList) []map[string]interface{} {
|
||||||
|
res := make([]map[string]interface{}, 0)
|
||||||
|
for _, av := range avl {
|
||||||
|
temp := map[string]interface{}{
|
||||||
|
"account_id": av.AccountId,
|
||||||
|
"account_name": av.AccountName,
|
||||||
|
"computes": av.Computes,
|
||||||
|
"created_by": av.CreatedBy,
|
||||||
|
"created_time": av.CreatedTime,
|
||||||
|
"deleted_by": av.DeletedBy,
|
||||||
|
"deleted_time": av.DeletedTime,
|
||||||
|
"external_ip": av.ExternalIP,
|
||||||
|
"vin_id": av.ID,
|
||||||
|
"vin_name": av.Name,
|
||||||
|
"network": av.Network,
|
||||||
|
"pri_vnf_dev_id": av.PriVnfDevId,
|
||||||
|
"rg_id": av.RgId,
|
||||||
|
"rg_name": av.RgName,
|
||||||
|
"status": av.Status,
|
||||||
|
"updated_by": av.UpdatedBy,
|
||||||
|
"updated_time": av.UpdatedTime,
|
||||||
|
}
|
||||||
|
res = append(res, temp)
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func dataSourceAccountVinsListRead(d *schema.ResourceData, m interface{}) error {
|
||||||
|
accountVinsList, err := utilityAccountVinsListCheckPresence(d, m)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
id := uuid.New()
|
||||||
|
d.SetId(id.String())
|
||||||
|
d.Set("items", flattenAccountVinsList(accountVinsList))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func dataSourceAccountVinsListSchemaMake() map[string]*schema.Schema {
|
||||||
|
res := map[string]*schema.Schema{
|
||||||
|
"account_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Required: true,
|
||||||
|
Description: "ID of the account",
|
||||||
|
},
|
||||||
|
"items": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Search Result",
|
||||||
|
Elem: &schema.Resource{
|
||||||
|
Schema: map[string]*schema.Schema{
|
||||||
|
"account_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"account_name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"computes": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"created_by": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"created_time": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"deleted_by": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"deleted_time": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"external_ip": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"vin_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"vin_name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"network": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"pri_vnf_dev_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"rg_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"rg_name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"updated_by": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"updated_time": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func dataSourceAccountVinsList() *schema.Resource {
|
||||||
|
return &schema.Resource{
|
||||||
|
SchemaVersion: 1,
|
||||||
|
|
||||||
|
Read: dataSourceAccountVinsListRead,
|
||||||
|
|
||||||
|
Timeouts: &schema.ResourceTimeout{
|
||||||
|
Read: &Timeout30s,
|
||||||
|
Default: &Timeout60s,
|
||||||
|
},
|
||||||
|
|
||||||
|
Schema: dataSourceAccountVinsListSchemaMake(),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1021,7 +1021,9 @@ const accountListDisksAPI = "/restmachine/cloudbroker/account/listDisks"
|
|||||||
const accountListFlipGroupsAPI = "/cloudapi/account/listFlipGroups"
|
const accountListFlipGroupsAPI = "/cloudapi/account/listFlipGroups"
|
||||||
const accountListRGAPI = "/cloudapi/account/listRG"
|
const accountListRGAPI = "/cloudapi/account/listRG"
|
||||||
const accountListTemplatesAPI = "/cloudapi/account/listTemplates"
|
const accountListTemplatesAPI = "/cloudapi/account/listTemplates"
|
||||||
const accountListVinsAPI = "/cloudapi/account/listVins"
|
|
||||||
|
//const accountListVinsAPI = "/restmachine/cloudapi/account/listVins"
|
||||||
|
const accountListVinsAPI = "/restmachine/cloudbroker/account/listVins"
|
||||||
const accountListVMsAPI = "/cloudapi/account/listVMs"
|
const accountListVMsAPI = "/cloudapi/account/listVMs"
|
||||||
const accountRestoreAPI = "/cloudapi/account/restore"
|
const accountRestoreAPI = "/cloudapi/account/restore"
|
||||||
const accountUpdateAPI = "/cloudapi/account/update"
|
const accountUpdateAPI = "/cloudapi/account/update"
|
||||||
@@ -1110,3 +1112,25 @@ type AccountDisk struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AccountDisksList []AccountDisk
|
type AccountDisksList []AccountDisk
|
||||||
|
|
||||||
|
type AccountVin struct {
|
||||||
|
AccountId int `json:"accountId"`
|
||||||
|
AccountName string `json:"accountName"`
|
||||||
|
Computes int `json:"computes"`
|
||||||
|
CreatedBy string `json:"createdBy"`
|
||||||
|
CreatedTime int `json:"createdTime"`
|
||||||
|
DeletedBy string `json:"deletedBy"`
|
||||||
|
DeletedTime int `json:"deletedTime"`
|
||||||
|
ExternalIP string `json:"externalIP"`
|
||||||
|
ID int `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Network string `json:"network"`
|
||||||
|
PriVnfDevId int `json:"priVnfDevId"`
|
||||||
|
RgId int `json:"rgId"`
|
||||||
|
RgName string `json:"rgName"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
UpdatedBy string `json:"updatedBy"`
|
||||||
|
UpdatedTime int `json:"updatedTime"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AccountVinsList []AccountVin
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ func Provider() *schema.Provider {
|
|||||||
"decort_account_list": dataSourceAccountList(),
|
"decort_account_list": dataSourceAccountList(),
|
||||||
"decort_account_computes_list": dataSourceAccountComputesList(),
|
"decort_account_computes_list": dataSourceAccountComputesList(),
|
||||||
"decort_account_disks_list": dataSourceAccountDisksList(),
|
"decort_account_disks_list": dataSourceAccountDisksList(),
|
||||||
|
"decort_account_vins_list": dataSourceAccountVinsList(),
|
||||||
// "decort_pfw": dataSourcePfw(),
|
// "decort_pfw": dataSourcePfw(),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
56
decort/utility_account_vins_list.go
Normal file
56
decort/utility_account_vins_list.go
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
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 utilityAccountVinsListCheckPresence(d *schema.ResourceData, m interface{}) (AccountVinsList, error) {
|
||||||
|
accountVinsList := AccountVinsList{}
|
||||||
|
controller := m.(*ControllerCfg)
|
||||||
|
urlValues := &url.Values{}
|
||||||
|
|
||||||
|
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||||
|
|
||||||
|
log.Debugf("utilityAccountVinsListCheckPresence: load account list")
|
||||||
|
accountVinsListRaw, err := controller.decortAPICall("POST", accountListVinsAPI, urlValues)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(accountVinsListRaw), &accountVinsList)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return accountVinsList, nil
|
||||||
|
}
|
||||||
39
samples/data_account_vins_list/main.tf
Normal file
39
samples/data_account_vins_list/main.tf
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
Пример использования
|
||||||
|
Получение списка vins, используемых аккаунтом
|
||||||
|
|
||||||
|
*/
|
||||||
|
#Расскомментируйте этот код,
|
||||||
|
#и внесите необходимые правки в версию и путь,
|
||||||
|
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
|
||||||
|
/*
|
||||||
|
terraform {
|
||||||
|
required_providers {
|
||||||
|
decort = {
|
||||||
|
version = "1.1"
|
||||||
|
source = "digitalenergy.online/decort/decort"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
provider "decort" {
|
||||||
|
authenticator = "oauth2"
|
||||||
|
#controller_url = <DECORT_CONTROLLER_URL>
|
||||||
|
controller_url = "https://ds1.digitalenergy.online"
|
||||||
|
#oauth2_url = <DECORT_SSO_URL>
|
||||||
|
oauth2_url = "https://sso.digitalenergy.online"
|
||||||
|
allow_unverified_ssl = true
|
||||||
|
}
|
||||||
|
|
||||||
|
data "decort_account_vins_list" "avl" {
|
||||||
|
#id аккаунта
|
||||||
|
#обязательный параметр
|
||||||
|
#тип - число
|
||||||
|
account_id = 28096
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
output "test" {
|
||||||
|
value = data.decort_account_vins_list.avl
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user