4.0.0
This commit is contained in:
@@ -1,58 +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>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
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 vins
|
||||
|
||||
const (
|
||||
VinsAuditsAPI = "/restmachine/cloudapi/vins/audits"
|
||||
VinsCreateInAccountAPI = "/restmachine/cloudapi/vins/createInAccount"
|
||||
VinsCreateInRgAPI = "/restmachine/cloudapi/vins/createInRG"
|
||||
VinsDeleteAPI = "/restmachine/cloudapi/vins/delete"
|
||||
VinsDisableAPI = "/restmachine/cloudapi/vins/disable"
|
||||
VinsEnableAPI = "/restmachine/cloudapi/vins/enable"
|
||||
VinsExtNetConnectAPI = "/restmachine/cloudapi/vins/extNetConnect"
|
||||
VinsExtNetDisconnectAPI = "/restmachine/cloudapi/vins/extNetDisconnect"
|
||||
VinsExtNetListAPI = "/restmachine/cloudapi/vins/extNetList"
|
||||
VinsGetAPI = "/restmachine/cloudapi/vins/get"
|
||||
VinsIpListAPI = "/restmachine/cloudapi/vins/ipList"
|
||||
VinsIpReleaseAPI = "/restmachine/cloudapi/vins/ipRelease"
|
||||
VinsIpReserveAPI = "/restmachine/cloudapi/vins/ipReserve"
|
||||
VinsListAPI = "/restmachine/cloudapi/vins/list"
|
||||
VinsListDeletedAPI = "/restmachine/cloudapi/vins/listDeleted"
|
||||
VinsNatRuleAddAPI = "/restmachine/cloudapi/vins/natRuleAdd"
|
||||
VinsNatRuleDelAPI = "/restmachine/cloudapi/vins/natRuleDel"
|
||||
VinsNatRuleListAPI = "/restmachine/cloudapi/vins/natRuleList"
|
||||
VinsRestoreAPI = "/restmachine/cloudapi/vins/restore"
|
||||
VinsSearchAPI = "/restmachine/cloudapi/vins/search"
|
||||
VinsVnfdevRedeployAPI = "/restmachine/cloudapi/vins/vnfdevRedeploy"
|
||||
VinsVnfdevRestartAPI = "/restmachine/cloudapi/vins/vnfdevRestart"
|
||||
)
|
||||
@@ -57,7 +57,7 @@ func DataSourceVinsIpListSchemaMake() map[string]*schema.Schema {
|
||||
"vins_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "Unique ID of the ViNS. If ViNS ID is specified, then ViNS name, rg_id and account_id are ignored.",
|
||||
Description: "Unique ID of the ViNS",
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
|
||||
@@ -32,12 +32,15 @@ Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/w
|
||||
|
||||
package vins
|
||||
|
||||
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
|
||||
)
|
||||
|
||||
func flattenMGMT(mgmt *VNFConfigMGMT) []map[string]interface{} {
|
||||
func flattenMGMT(mgmt vins.RecordMGMT) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"ip_addr": mgmt.IPAddr,
|
||||
"ip_addr": mgmt.IPAddress,
|
||||
"password": mgmt.Password,
|
||||
"ssh_key": mgmt.SSHKey,
|
||||
"user": mgmt.User,
|
||||
@@ -46,7 +49,7 @@ func flattenMGMT(mgmt *VNFConfigMGMT) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenResources(resources *VNFConfigResources) []map[string]interface{} {
|
||||
func flattenResources(resources *vins.RecordResources) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"cpu": resources.CPU,
|
||||
@@ -58,17 +61,17 @@ func flattenResources(resources *VNFConfigResources) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenConfig(config VNFConfig) []map[string]interface{} {
|
||||
func flattenConfig(config vins.RecordVNFConfig) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"mgmt": flattenMGMT(&config.MGMT),
|
||||
"mgmt": flattenMGMT(config.MGMT),
|
||||
"resources": flattenResources(&config.Resources),
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenQOS(qos QOS) []map[string]interface{} {
|
||||
func flattenQOS(qos vins.QOS) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"e_rate": qos.ERate,
|
||||
@@ -80,7 +83,7 @@ func flattenQOS(qos QOS) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenInterfaces(interfaces VNFInterfaceList) []map[string]interface{} {
|
||||
func flattenInterfaces(interfaces []vins.ItemVNFInterface) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
|
||||
for _, vnfInterface := range interfaces {
|
||||
@@ -88,7 +91,7 @@ func flattenInterfaces(interfaces VNFInterfaceList) []map[string]interface{} {
|
||||
"conn_id": vnfInterface.ConnID,
|
||||
"conn_type": vnfInterface.ConnType,
|
||||
"def_gw": vnfInterface.DefGW,
|
||||
"flipgroup_id": vnfInterface.FlipGroupID,
|
||||
"flipgroup_id": vnfInterface.FLIPGroupID,
|
||||
"guid": vnfInterface.GUID,
|
||||
"ip_address": vnfInterface.IPAddress,
|
||||
"listen_ssh": vnfInterface.ListenSSH,
|
||||
@@ -101,7 +104,7 @@ func flattenInterfaces(interfaces VNFInterfaceList) []map[string]interface{} {
|
||||
"qos": flattenQOS(vnfInterface.QOS),
|
||||
"target": vnfInterface.Target,
|
||||
"type": vnfInterface.Type,
|
||||
"vnfs": vnfInterface.VNFS,
|
||||
"vnfs": vnfInterface.VNFs,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
@@ -109,7 +112,7 @@ func flattenInterfaces(interfaces VNFInterfaceList) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVNFDev(vnfDev VNFDev) []map[string]interface{} {
|
||||
func flattenVNFDev(vnfDev vins.RecordVNFDev) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"_ckey": vnfDev.CKey,
|
||||
@@ -137,7 +140,7 @@ func flattenVNFDev(vnfDev VNFDev) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenComputes(computes VINSComputeList) []map[string]interface{} {
|
||||
func flattenComputes(computes vins.ListVINSComputes) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, compute := range computes {
|
||||
temp := map[string]interface{}{
|
||||
@@ -150,14 +153,14 @@ func flattenComputes(computes VINSComputeList) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenReservations(reservations ReservationList) []map[string]interface{} {
|
||||
func flattenReservations(reservations vins.ListReservations) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, reservation := range reservations {
|
||||
temp := map[string]interface{}{
|
||||
"client_type": reservation.ClientType,
|
||||
"desc": reservation.Description,
|
||||
"domainname": reservation.DomainName,
|
||||
"hostname": reservation.HostName,
|
||||
"hostname": reservation.Hostname,
|
||||
"ip": reservation.IP,
|
||||
"mac": reservation.MAC,
|
||||
"type": reservation.Type,
|
||||
@@ -169,7 +172,7 @@ func flattenReservations(reservations ReservationList) []map[string]interface{}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenDHCPConfig(config DHCPConfig) []map[string]interface{} {
|
||||
func flattenDHCPConfig(config vins.RecordDHCPConfig) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"default_gw": config.DefaultGW,
|
||||
@@ -177,7 +180,7 @@ func flattenDHCPConfig(config DHCPConfig) []map[string]interface{} {
|
||||
"ip_end": config.IPEnd,
|
||||
"ip_start": config.IPStart,
|
||||
"lease": config.Lease,
|
||||
"netmask": config.Netmask,
|
||||
"netmask": config.NetMask,
|
||||
"network": config.Network,
|
||||
"reservations": flattenReservations(config.Reservations),
|
||||
}
|
||||
@@ -186,7 +189,7 @@ func flattenDHCPConfig(config DHCPConfig) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenPrimary(primary DevicePrimary) []map[string]interface{} {
|
||||
func flattenPrimary(primary vins.RecordPrimary) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"dev_id": primary.DevID,
|
||||
@@ -198,7 +201,7 @@ func flattenPrimary(primary DevicePrimary) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenDevices(devices Devices) []map[string]interface{} {
|
||||
func flattenDevices(devices vins.RecordDevices) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"primary": flattenPrimary(devices.Primary),
|
||||
@@ -208,7 +211,7 @@ func flattenDevices(devices Devices) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenDHCP(dhcp DHCP) []map[string]interface{} {
|
||||
func flattenDHCP(dhcp vins.RecordDHCP) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"_ckey": dhcp.CKey,
|
||||
@@ -233,7 +236,7 @@ func flattenDHCP(dhcp DHCP) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenGWConfig(config GWConfig) []map[string]interface{} {
|
||||
func flattenGWConfig(config vins.RecordGWConfig) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"default_gw": config.DefaultGW,
|
||||
@@ -247,7 +250,7 @@ func flattenGWConfig(config GWConfig) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenGW(gw GW) []map[string]interface{} {
|
||||
func flattenGW(gw vins.RecordGW) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"_ckey": gw.CKey,
|
||||
@@ -272,7 +275,7 @@ func flattenGW(gw GW) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenRules(rules ListNATRules) []map[string]interface{} {
|
||||
func flattenRules(rules vins.ListNATRules) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, rule := range rules {
|
||||
tmp := map[string]interface{}{
|
||||
@@ -290,7 +293,7 @@ func flattenRules(rules ListNATRules) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenNATConfig(config NATConfig) []map[string]interface{} {
|
||||
func flattenNATConfig(config vins.NATConfig) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"net_mask": config.NetMask,
|
||||
@@ -303,7 +306,7 @@ func flattenNATConfig(config NATConfig) []map[string]interface{} {
|
||||
|
||||
}
|
||||
|
||||
func flattenNAT(nat NAT) []map[string]interface{} {
|
||||
func flattenNAT(nat vins.RecordNAT) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"_ckey": nat.CKey,
|
||||
@@ -328,7 +331,7 @@ func flattenNAT(nat NAT) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVNFS(vnfs VNFS) []map[string]interface{} {
|
||||
func flattenVNFS(vnfs vins.RecordVNFs) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"dhcp": flattenDHCP(vnfs.DHCP),
|
||||
@@ -340,7 +343,7 @@ func flattenVNFS(vnfs VNFS) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenRuleBlock(rules ListNATRules) []map[string]interface{} {
|
||||
func flattenRuleBlock(rules vins.ListNATRules) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, rule := range rules {
|
||||
tmp := map[string]interface{}{
|
||||
@@ -356,7 +359,7 @@ func flattenRuleBlock(rules ListNATRules) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVins(d *schema.ResourceData, vins VINSDetailed) {
|
||||
func flattenVins(d *schema.ResourceData, vins vins.RecordVINS) {
|
||||
d.Set("vins_id", vins.ID)
|
||||
d.Set("vnf_dev", flattenVNFDev(vins.VNFDev))
|
||||
d.Set("_ckey", vins.CKey)
|
||||
@@ -382,12 +385,12 @@ func flattenVins(d *schema.ResourceData, vins VINSDetailed) {
|
||||
d.Set("sec_vnf_dev_id", vins.SecVNFDevID)
|
||||
d.Set("status", vins.Status)
|
||||
d.Set("user_managed", vins.UserManaged)
|
||||
d.Set("vnfs", flattenVNFS(vins.VNFS))
|
||||
d.Set("vxlan_id", vins.VXLanID)
|
||||
d.Set("nat_rule", flattenRuleBlock(vins.VNFS.NAT.Config.Rules))
|
||||
d.Set("vnfs", flattenVNFS(vins.VNFs))
|
||||
d.Set("vxlan_id", vins.VXLANID)
|
||||
d.Set("nat_rule", flattenRuleBlock(vins.VNFs.NAT.Config.Rules))
|
||||
}
|
||||
|
||||
func flattenVinsData(d *schema.ResourceData, vins VINSDetailed) {
|
||||
func flattenVinsData(d *schema.ResourceData, vins vins.RecordVINS) {
|
||||
d.Set("vins_id", vins.ID)
|
||||
d.Set("vnf_dev", flattenVNFDev(vins.VNFDev))
|
||||
d.Set("_ckey", vins.CKey)
|
||||
@@ -413,11 +416,11 @@ func flattenVinsData(d *schema.ResourceData, vins VINSDetailed) {
|
||||
d.Set("sec_vnf_dev_id", vins.SecVNFDevID)
|
||||
d.Set("status", vins.Status)
|
||||
d.Set("user_managed", vins.UserManaged)
|
||||
d.Set("vnfs", flattenVNFS(vins.VNFS))
|
||||
d.Set("vxlan_id", vins.VXLanID)
|
||||
d.Set("vnfs", flattenVNFS(vins.VNFs))
|
||||
d.Set("vxlan_id", vins.VXLANID)
|
||||
}
|
||||
|
||||
func flattenVinsAudits(auidts VINSAuditsList) []map[string]interface{} {
|
||||
func flattenVinsAudits(auidts vins.ListAudits) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, audit := range auidts {
|
||||
temp := map[string]interface{}{
|
||||
@@ -433,7 +436,7 @@ func flattenVinsAudits(auidts VINSAuditsList) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsExtNetList(extNetList ExtNetList) []map[string]interface{} {
|
||||
func flattenVinsExtNetList(extNetList vins.ListExtNets) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, extNet := range extNetList {
|
||||
temp := map[string]interface{}{
|
||||
@@ -450,13 +453,13 @@ func flattenVinsExtNetList(extNetList ExtNetList) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsIpList(ips IPList) []map[string]interface{} {
|
||||
func flattenVinsIpList(ips vins.ListIPs) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, ip := range ips {
|
||||
temp := map[string]interface{}{
|
||||
"client_type": ip.ClientType,
|
||||
"domainname": ip.DomainName,
|
||||
"hostname": ip.HostName,
|
||||
"hostname": ip.Hostname,
|
||||
"ip": ip.IP,
|
||||
"mac": ip.MAC,
|
||||
"type": ip.Type,
|
||||
@@ -468,7 +471,7 @@ func flattenVinsIpList(ips IPList) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsList(vl VINSList) []map[string]interface{} {
|
||||
func flattenVinsList(vl vins.ListVINS) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, v := range vl {
|
||||
temp := map[string]interface{}{
|
||||
@@ -494,7 +497,7 @@ func flattenVinsList(vl VINSList) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsNatRuleList(natRules NATRuleList) []map[string]interface{} {
|
||||
func flattenVinsNatRuleList(natRules vins.ListNATRules) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, natRule := range natRules {
|
||||
temp := map[string]interface{}{
|
||||
|
||||
@@ -1,330 +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>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
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 vins
|
||||
|
||||
type VINSRecord struct {
|
||||
AccountID uint64 `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
ExternalIP string `json:"externalIP"`
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Network string `json:"network"`
|
||||
RGID uint64 `json:"rgId"`
|
||||
RGName string `json:"rgName"`
|
||||
Status string `json:"status"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
VXLANID uint64 `json:"vxlanId"`
|
||||
}
|
||||
|
||||
type VINSList []VINSRecord
|
||||
|
||||
type VINSAudits struct {
|
||||
Call string `json:"call"`
|
||||
ResponseTime float64 `json:"responsetime"`
|
||||
StatusCode uint64 `json:"statuscode"`
|
||||
Timestamp float64 `json:"timestamp"`
|
||||
User string `json:"user"`
|
||||
}
|
||||
|
||||
type VINSAuditsList []VINSAudits
|
||||
|
||||
type VINSExtNet struct {
|
||||
DefaultGW string `json:"default_gw"`
|
||||
ExtNetID uint64 `json:"ext_net_id"`
|
||||
IP string `json:"ip"`
|
||||
PrefixLen uint64 `json:"prefixlen"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
}
|
||||
|
||||
type ExtNetList []VINSExtNet
|
||||
|
||||
type IP struct {
|
||||
ClientType string `json:"clientType"`
|
||||
DomainName string `json:"domainname"`
|
||||
HostName string `json:"hostname"`
|
||||
IP string `json:"ip"`
|
||||
MAC string `json:"mac"`
|
||||
Type string `json:"type"`
|
||||
VMID uint64 `json:"vmId"`
|
||||
}
|
||||
|
||||
type IPList []IP
|
||||
|
||||
type VNFDev struct {
|
||||
CKey string `json:"_ckey"`
|
||||
AccountID uint64 `json:"accountId"`
|
||||
Capabilities []string `json:"capabilities"`
|
||||
Config VNFConfig `json:"config"`
|
||||
ConfigSaved bool `json:"configSaved"`
|
||||
CustomPreConfig bool `json:"customPrecfg"`
|
||||
Description string `json:"desc"`
|
||||
GID uint64 `json:"gid"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
Interfaces VNFInterfaceList `json:"interfaces"`
|
||||
LockStatus string `json:"lockStatus"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
Type string `json:"type"`
|
||||
VINS []uint64 `json:"vins"`
|
||||
}
|
||||
|
||||
type VNFConfig struct {
|
||||
MGMT VNFConfigMGMT `json:"mgmt"`
|
||||
Resources VNFConfigResources `json:"resources"`
|
||||
}
|
||||
|
||||
type VNFConfigMGMT struct {
|
||||
IPAddr string `json:"ipaddr"`
|
||||
Password string `json:"password"`
|
||||
SSHKey string `json:"sshkey"`
|
||||
User string `json:"user"`
|
||||
}
|
||||
|
||||
type VNFConfigResources struct {
|
||||
CPU uint64 `json:"cpu"`
|
||||
RAM uint64 `json:"ram"`
|
||||
StackID uint64 `json:"stackId"`
|
||||
UUID string `json:"uuid"`
|
||||
}
|
||||
|
||||
type VNFInterface struct {
|
||||
ConnID uint64 `json:"connId"`
|
||||
ConnType string `json:"connType"`
|
||||
DefGW string `json:"defGw"`
|
||||
FlipGroupID uint64 `json:"flipgroupId"`
|
||||
GUID string `json:"guid"`
|
||||
IPAddress string `json:"ipAddress"`
|
||||
ListenSSH bool `json:"listenSsh"`
|
||||
MAC string `json:"mac"`
|
||||
Name string `json:"name"`
|
||||
NetID uint64 `json:"netId"`
|
||||
NetMask uint64 `json:"netMask"`
|
||||
NetType string `json:"netType"`
|
||||
PCISlot uint64 `json:"pciSlot"`
|
||||
QOS QOS `json:"qos"`
|
||||
Target string `json:"target"`
|
||||
Type string `json:"type"`
|
||||
VNFS []uint64 `json:"vnfs"`
|
||||
}
|
||||
|
||||
type QOS struct {
|
||||
ERate uint64 `json:"eRate"`
|
||||
GUID string `json:"guid"`
|
||||
InBurst uint64 `json:"inBurst"`
|
||||
InRate uint64 `json:"inRate"`
|
||||
}
|
||||
|
||||
type VNFInterfaceList []VNFInterface
|
||||
|
||||
type VINSCompute struct {
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type VINSComputeList []VINSCompute
|
||||
|
||||
type VNFS struct {
|
||||
DHCP DHCP `json:"DHCP"`
|
||||
GW GW `json:"GW"`
|
||||
NAT NAT `json:"NAT"`
|
||||
}
|
||||
|
||||
type NAT struct {
|
||||
CKey string `json:"_ckey"`
|
||||
AccountID uint64 `json:"accountId"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
Config NATConfig `json:"config"`
|
||||
Devices Devices `json:"devices"`
|
||||
GID uint64 `json:"gid"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
LockStatus string `json:"lockStatus"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
OwnerID uint64 `json:"ownerId"`
|
||||
OwnerType string `json:"ownerType"`
|
||||
PureVirtual bool `json:"pureVirtual"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type NATConfig struct {
|
||||
NetMask uint64 `json:"netmask"`
|
||||
Network string `json:"network"`
|
||||
Rules ListNATRules `json:"rules"`
|
||||
}
|
||||
|
||||
type ItemNATRule struct {
|
||||
ID uint64 `json:"id"`
|
||||
LocalIP string `json:"localIp"`
|
||||
LocalPort uint64 `json:"localPort"`
|
||||
Protocol string `json:"protocol"`
|
||||
PublicPortEnd uint64 `json:"publicPortEnd"`
|
||||
PublicPortStart uint64 `json:"publicPortStart"`
|
||||
VMID uint64 `json:"vmId"`
|
||||
VMName string `json:"vmName"`
|
||||
}
|
||||
|
||||
type ListNATRules []ItemNATRule
|
||||
|
||||
type GW struct {
|
||||
CKey string `json:"_ckey"`
|
||||
AccountID uint64 `json:"accountId"`
|
||||
Config GWConfig `json:"config"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
Devices Devices `json:"devices"`
|
||||
GID uint64 `json:"gid"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
LockStatus string `json:"lockStatus"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
OwnerID uint64 `json:"ownerId"`
|
||||
OwnerType string `json:"ownerType"`
|
||||
PureVirtual bool `json:"pureVirtual"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type GWConfig struct {
|
||||
DefaultGW string `json:"default_gw"`
|
||||
ExtNetID uint64 `json:"ext_net_id"`
|
||||
ExtNetIP string `json:"ext_net_ip"`
|
||||
ExtNetMask uint64 `json:"ext_netmask"`
|
||||
QOS QOS `json:"qos"`
|
||||
}
|
||||
|
||||
type Devices struct {
|
||||
Primary DevicePrimary `json:"primary"`
|
||||
}
|
||||
|
||||
type DevicePrimary struct {
|
||||
DevID uint64 `json:"devId"`
|
||||
IFace01 string `json:"iface01"`
|
||||
IFace02 string `json:"iface02"`
|
||||
}
|
||||
|
||||
type DHCP struct {
|
||||
CKey string `json:"_ckey"`
|
||||
AccountID uint64 `json:"accountId"`
|
||||
Config DHCPConfig `json:"config"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
Devices Devices `json:"devices"`
|
||||
GID uint64 `json:"gid"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
LockStatus string `json:"lockStatus"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
OwnerID uint64 `json:"ownerId"`
|
||||
OwnerType string `json:"ownerType"`
|
||||
PureVirtual bool `json:"pureVirtual"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type DHCPConfig struct {
|
||||
DefaultGW string `json:"default_gw"`
|
||||
DNS []string `json:"dns"`
|
||||
IPEnd string `json:"ip_end"`
|
||||
IPStart string `json:"ip_start"`
|
||||
Lease uint64 `json:"lease"`
|
||||
Netmask uint64 `json:"netmask"`
|
||||
Network string `json:"network"`
|
||||
Reservations ReservationList `json:"reservations"`
|
||||
}
|
||||
|
||||
type VINSDetailed struct {
|
||||
VNFDev VNFDev `json:"VNFDev"`
|
||||
CKey string `json:"_ckey"`
|
||||
AccountID uint64 `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
Computes VINSComputeList `json:"computes"`
|
||||
DefaultGW string `json:"defaultGW"`
|
||||
DefaultQOS QOS `json:"defaultQos"`
|
||||
Description string `json:"desc"`
|
||||
GID uint64 `json:"gid"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
LockStatus string `json:"lockStatus"`
|
||||
ManagerID uint64 `json:"managerId"`
|
||||
ManagerType string `json:"managerType"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
NetMask uint64 `json:"netMask"`
|
||||
Network string `json:"network"`
|
||||
PreReservaionsNum uint64 `json:"preReservationsNum"`
|
||||
Redundant bool `json:"redundant"`
|
||||
RGID uint64 `json:"rgId"`
|
||||
RGName string `json:"rgName"`
|
||||
SecVNFDevID uint64 `json:"secVnfDevId"`
|
||||
Status string `json:"status"`
|
||||
UserManaged bool `json:"userManaged"`
|
||||
VNFS VNFS `json:"vnfs"`
|
||||
VXLanID uint64 `json:"vxlanId"`
|
||||
}
|
||||
|
||||
type Reservation struct {
|
||||
ClientType string `json:"clientType"`
|
||||
Description string `json:"desc"`
|
||||
DomainName string `json:"domainname"`
|
||||
HostName string `json:"hostname"`
|
||||
IP string `json:"ip"`
|
||||
MAC string `json:"mac"`
|
||||
Type string `json:"type"`
|
||||
VMID int `json:"vmId"`
|
||||
}
|
||||
|
||||
type ReservationList []Reservation
|
||||
|
||||
type NATRule struct {
|
||||
ID uint64 `json:"id"`
|
||||
LocalIP string `json:"localIp"`
|
||||
LocalPort uint64 `json:"localPort"`
|
||||
Protocol string `json:"protocol"`
|
||||
PublicPortEnd uint64 `json:"publicPortEnd"`
|
||||
PublicPortStart uint64 `json:"publicPortStart"`
|
||||
VMID uint64 `json:"vmId"`
|
||||
VMName string `json:"vmName"`
|
||||
}
|
||||
|
||||
type NATRuleList []NATRule
|
||||
@@ -2,43 +2,26 @@ package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/extnet"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/locations"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/rg"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func existRGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
rgId := uint64(d.Get("rg_id").(int))
|
||||
req := rg.ListRequest{}
|
||||
|
||||
rgList := []struct {
|
||||
ID int `json:"id"`
|
||||
}{}
|
||||
|
||||
rgListAPI := "/restmachine/cloudapi/rg/list"
|
||||
|
||||
rgListRaw, err := c.DecortAPICall(ctx, "POST", rgListAPI, urlValues)
|
||||
rgList, err := c.CloudAPI().RG().List(ctx, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(rgListRaw), &rgList)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
haveRG := false
|
||||
rgId := d.Get("rg_id").(int)
|
||||
for _, rg := range rgList {
|
||||
if rg.ID == rgId {
|
||||
haveRG = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return haveRG, nil
|
||||
return len(rgList.FilterByID(rgId)) != 0, nil
|
||||
}
|
||||
|
||||
func existExtNetID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||
@@ -49,98 +32,39 @@ func existExtNetID(ctx context.Context, d *schema.ResourceData, m interface{}) (
|
||||
}
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
extNetIDParsed := uint64(extNetID)
|
||||
req := extnet.ListRequest{}
|
||||
|
||||
extNetList := []struct {
|
||||
ID int `json:"id"`
|
||||
}{}
|
||||
|
||||
extNetListAPI := "/restmachine/cloudapi/extnet/list"
|
||||
|
||||
extNetListRaw, err := c.DecortAPICall(ctx, "POST", extNetListAPI, urlValues)
|
||||
extNetList, err := c.CloudAPI().ExtNet().List(ctx, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(extNetListRaw), &extNetList)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
haveExtNet := false
|
||||
for _, extNet := range extNetList {
|
||||
if extNet.ID == extNetID {
|
||||
haveExtNet = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return haveExtNet, nil
|
||||
return len(extNetList.FilterByID(extNetIDParsed)) != 0, nil
|
||||
}
|
||||
|
||||
func existAccountID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
accountId := uint64(d.Get("account_id").(int))
|
||||
req := account.ListRequest{}
|
||||
|
||||
urlValues := &url.Values{}
|
||||
|
||||
accountList := []struct {
|
||||
ID int `json:"id"`
|
||||
}{}
|
||||
|
||||
accountListAPI := "/restmachine/cloudapi/account/list"
|
||||
|
||||
accountListRaw, err := c.DecortAPICall(ctx, "POST", accountListAPI, urlValues)
|
||||
accountList, err := c.CloudAPI().Account().List(ctx, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(accountListRaw), &accountList)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
haveAccount := false
|
||||
|
||||
myAccount := d.Get("account_id").(int)
|
||||
for _, account := range accountList {
|
||||
if account.ID == myAccount {
|
||||
haveAccount = true
|
||||
break
|
||||
}
|
||||
}
|
||||
return haveAccount, nil
|
||||
return len(accountList.FilterByID(accountId)) != 0, nil
|
||||
}
|
||||
|
||||
func existGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
gid := uint64(d.Get("gid").(int))
|
||||
req := locations.ListRequest{}
|
||||
|
||||
urlValues := &url.Values{}
|
||||
|
||||
locationList := []struct {
|
||||
GID int `json:"gid"`
|
||||
}{}
|
||||
|
||||
locationsListAPI := "/restmachine/cloudapi/locations/list"
|
||||
|
||||
locationListRaw, err := c.DecortAPICall(ctx, "POST", locationsListAPI, urlValues)
|
||||
locationList, err := c.CloudAPI().Locations().List(ctx, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(locationListRaw), &locationList)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
haveGID := false
|
||||
|
||||
gid := d.Get("gid").(int)
|
||||
for _, location := range locationList {
|
||||
if location.GID == gid {
|
||||
haveGID = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return haveGID, nil
|
||||
return len(locationList.FilterByGID(gid)) != 0, nil
|
||||
}
|
||||
|
||||
@@ -34,11 +34,10 @@ package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
|
||||
"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/dc"
|
||||
@@ -51,7 +50,6 @@ import (
|
||||
|
||||
func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
if _, ok := d.GetOk("rg_id"); ok {
|
||||
haveRGID, err := existRGID(ctx, d, m)
|
||||
@@ -104,97 +102,111 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
}
|
||||
|
||||
if rgOk {
|
||||
urlValues.Add("name", d.Get("name").(string))
|
||||
urlValues.Add("rgId", strconv.Itoa(rgId.(int)))
|
||||
req := vins.CreateInRGRequest{
|
||||
Name: d.Get("name").(string),
|
||||
RGID: uint64(rgId.(int)),
|
||||
}
|
||||
|
||||
if ipcidr, ok := d.GetOk("ipcidr"); ok {
|
||||
urlValues.Add("ipcidr", ipcidr.(string))
|
||||
req.IPCIDR = ipcidr.(string)
|
||||
}
|
||||
|
||||
//extnet v1
|
||||
urlValues.Add("extNetId", strconv.Itoa(d.Get("ext_net_id").(int)))
|
||||
req.ExtNetID = uint64(d.Get("ext_net_id").(int))
|
||||
if extIp, ok := d.GetOk("ext_ip_addr"); ok {
|
||||
urlValues.Add("extIp", extIp.(string))
|
||||
req.ExtIP = extIp.(string)
|
||||
}
|
||||
|
||||
//extnet v2
|
||||
if extNetResp, ok := d.GetOk("ext_net"); ok {
|
||||
extNetSl := extNetResp.([]interface{})
|
||||
extNet := extNetSl[0].(map[string]interface{})
|
||||
urlValues.Add("vinsId", d.Id())
|
||||
urlValues.Add("netId", strconv.Itoa(extNet["ext_net_id"].(int)))
|
||||
urlValues.Add("extIp", extNet["ext_net_ip"].(string))
|
||||
|
||||
req.ExtNetID = uint64(extNet["ext_net_id"].(int))
|
||||
req.ExtIP = extNet["ext_net_ip"].(string)
|
||||
}
|
||||
|
||||
if desc, ok := d.GetOk("desc"); ok {
|
||||
urlValues.Add("desc", desc.(string))
|
||||
req.Description = desc.(string)
|
||||
}
|
||||
urlValues.Add("preReservationsNum", strconv.Itoa(d.Get("pre_reservations_num").(int)))
|
||||
id, err := c.DecortAPICall(ctx, "POST", VinsCreateInRgAPI, urlValues)
|
||||
req.PreReservationsNum = uint(d.Get("pre_reservations_num").(int))
|
||||
|
||||
id, err := c.CloudAPI().VINS().CreateInRG(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
d.SetId(id)
|
||||
|
||||
d.SetId(strconv.FormatUint(id, 10))
|
||||
} else if accountIdOk {
|
||||
urlValues.Add("name", d.Get("name").(string))
|
||||
urlValues.Add("accountId", strconv.Itoa(accountId.(int)))
|
||||
req := vins.CreateInAccountRequest{
|
||||
Name: d.Get("name").(string),
|
||||
AccountID: uint64(accountId.(int)),
|
||||
PreReservationsNum: uint64(d.Get("pre_reservations_num").(int)),
|
||||
}
|
||||
|
||||
if gid, ok := d.GetOk("gid"); ok {
|
||||
urlValues.Add("gid", strconv.Itoa(gid.(int)))
|
||||
req.GID = uint64(gid.(int))
|
||||
}
|
||||
if ipcidr, ok := d.GetOk("ipcidr"); ok {
|
||||
urlValues.Add("ipcidr", ipcidr.(string))
|
||||
req.IPCIDR = ipcidr.(string)
|
||||
}
|
||||
if desc, ok := d.GetOk("desc"); ok {
|
||||
urlValues.Add("desc", desc.(string))
|
||||
req.Description = desc.(string)
|
||||
}
|
||||
urlValues.Add("preReservationsNum", strconv.Itoa(d.Get("pre_reservations_num").(int)))
|
||||
id, err := c.DecortAPICall(ctx, "POST", VinsCreateInAccountAPI, urlValues)
|
||||
|
||||
id, err := c.CloudAPI().VINS().CreateInAccount(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
d.SetId(id)
|
||||
|
||||
d.SetId(strconv.FormatUint(id, 10))
|
||||
}
|
||||
|
||||
vinsId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
|
||||
warnings := dc.Warnings{}
|
||||
urlValues = &url.Values{}
|
||||
if ipRes, ok := d.GetOk("ip"); ok {
|
||||
ipsSlice := ipRes.([]interface{})
|
||||
for _, ipInterfase := range ipsSlice {
|
||||
ip := ipInterfase.(map[string]interface{})
|
||||
urlValues = &url.Values{}
|
||||
urlValues.Add("vinsId", d.Id())
|
||||
urlValues.Add("type", ip["type"].(string))
|
||||
|
||||
req := vins.IPReserveRequest{
|
||||
VINSID: vinsId,
|
||||
Type: ip["type"].(string),
|
||||
}
|
||||
|
||||
if ipAddr, ok := ip["ip_addr"]; ok {
|
||||
urlValues.Add("ipAddr", ipAddr.(string))
|
||||
req.IPAddr = ipAddr.(string)
|
||||
}
|
||||
if macAddr, ok := ip["mac_addr"]; ok {
|
||||
urlValues.Add("mac", macAddr.(string))
|
||||
req.MAC = macAddr.(string)
|
||||
}
|
||||
if computeId, ok := ip["compute_id"]; ok {
|
||||
urlValues.Add("computeId", strconv.Itoa(computeId.(int)))
|
||||
req.ComputeID = uint64(computeId.(int))
|
||||
}
|
||||
_, err := c.DecortAPICall(ctx, "POST", VinsIpReserveAPI, urlValues)
|
||||
_, err := c.CloudAPI().VINS().IPReserve(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
urlValues = &url.Values{}
|
||||
if natRule, ok := d.GetOk("nat_rule"); ok {
|
||||
addedNatRules := natRule.([]interface{})
|
||||
if len(addedNatRules) > 0 {
|
||||
for _, natRuleInterface := range addedNatRules {
|
||||
urlValues = &url.Values{}
|
||||
natRule := natRuleInterface.(map[string]interface{})
|
||||
|
||||
urlValues.Add("vinsId", d.Id())
|
||||
urlValues.Add("intIp", natRule["int_ip"].(string))
|
||||
urlValues.Add("intPort", strconv.Itoa(natRule["int_port"].(int)))
|
||||
urlValues.Add("extPortStart", strconv.Itoa(natRule["ext_port_start"].(int)))
|
||||
urlValues.Add("extPortEnd", strconv.Itoa(natRule["ext_port_end"].(int)))
|
||||
urlValues.Add("proto", natRule["proto"].(string))
|
||||
req := vins.NATRuleAddRequest{
|
||||
VINSID: vinsId,
|
||||
IntIP: natRule["int_ip"].(string),
|
||||
IntPort: uint(natRule["int_port"].(int)),
|
||||
ExtPortStart: uint(natRule["ext_port_start"].(int)),
|
||||
ExtPortEnd: uint(natRule["ext_port_end"].(int)),
|
||||
Proto: natRule["proto"].(string),
|
||||
}
|
||||
|
||||
_, err := c.DecortAPICall(ctx, "POST", VinsNatRuleAddAPI, urlValues)
|
||||
_, err := c.CloudAPI().VINS().NATRuleAdd(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
@@ -210,7 +222,7 @@ func resourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}
|
||||
c := m.(*controller.ControllerCfg)
|
||||
warnings := dc.Warnings{}
|
||||
|
||||
vins, err := utilityVinsCheckPresence(ctx, d, m)
|
||||
vinsData, err := utilityVinsCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
@@ -220,32 +232,33 @@ func resourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}
|
||||
|
||||
hasChangeState := false
|
||||
|
||||
switch vins.Status {
|
||||
switch vinsData.Status {
|
||||
case status.Destroyed:
|
||||
d.SetId("")
|
||||
d.Set("vins_id", 0)
|
||||
d.SetId("")
|
||||
return resourceVinsCreate(ctx, d, m)
|
||||
case status.Deleted:
|
||||
hasChangeState = true
|
||||
urlValues := &url.Values{}
|
||||
|
||||
urlValues.Add("vinsId", d.Id())
|
||||
req := vins.RestoreRequest{
|
||||
VINSID: vinsData.ID,
|
||||
}
|
||||
|
||||
_, err := c.DecortAPICall(ctx, "POST", VinsRestoreAPI, urlValues)
|
||||
_, err := c.CloudAPI().VINS().Restore(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
case status.Modeled:
|
||||
return diag.Errorf("ViNS are in status: %s, please, contact support for more information", vins.Status)
|
||||
return diag.Errorf("ViNS are in status: %s, please, contact support for more information", vinsData.Status)
|
||||
case status.Created:
|
||||
case status.Enabled:
|
||||
if !isEnabled {
|
||||
hasChangeState = true
|
||||
urlValues := &url.Values{}
|
||||
req := vins.DisableEnableRequest{
|
||||
VINSID: vinsData.ID,
|
||||
}
|
||||
|
||||
urlValues.Add("vinsId", d.Id())
|
||||
|
||||
_, err := c.DecortAPICall(ctx, "POST", VinsDisableAPI, urlValues)
|
||||
_, err := c.CloudAPI().VINS().Disable(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
@@ -254,29 +267,29 @@ func resourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}
|
||||
case status.Disabled:
|
||||
if isEnabled {
|
||||
hasChangeState = true
|
||||
urlValues := &url.Values{}
|
||||
req := vins.DisableEnableRequest{
|
||||
VINSID: vinsData.ID,
|
||||
}
|
||||
|
||||
urlValues.Add("vinsId", d.Id())
|
||||
|
||||
_, err := c.DecortAPICall(ctx, "POST", VinsEnableAPI, urlValues)
|
||||
_, err := c.CloudAPI().VINS().Enable(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
case status.Disabling:
|
||||
case status.Deleting:
|
||||
return diag.Errorf("ViNS are in progress with status: %s", vins.Status)
|
||||
return diag.Errorf("ViNS are in progress with status: %s", vinsData.Status)
|
||||
}
|
||||
|
||||
if hasChangeState {
|
||||
vins, err = utilityVinsCheckPresence(ctx, d, m)
|
||||
vinsData, err = utilityVinsCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
flattenVins(d, *vins)
|
||||
flattenVins(d, *vinsData)
|
||||
|
||||
return warnings.Get()
|
||||
}
|
||||
@@ -292,7 +305,7 @@ func isContainsIp(els []interface{}, el interface{}) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func isContinsNatRule(els []interface{}, el interface{}) bool {
|
||||
func isContainsNatRule(els []interface{}, el interface{}) bool {
|
||||
for _, elOld := range els {
|
||||
elOldConv := elOld.(map[string]interface{})
|
||||
elConv := el.(map[string]interface{})
|
||||
@@ -353,7 +366,7 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
}
|
||||
}
|
||||
|
||||
vins, err := utilityVinsCheckPresence(ctx, d, m)
|
||||
vinsData, err := utilityVinsCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
@@ -363,31 +376,32 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
|
||||
hasChangeState := false
|
||||
|
||||
switch vins.Status {
|
||||
switch vinsData.Status {
|
||||
case status.Destroyed:
|
||||
d.SetId("")
|
||||
return resourceVinsCreate(ctx, d, m)
|
||||
case status.Deleted:
|
||||
hasChangeState = true
|
||||
urlValues := &url.Values{}
|
||||
|
||||
urlValues.Add("vinsId", d.Id())
|
||||
req := vins.RestoreRequest{
|
||||
VINSID: vinsData.ID,
|
||||
}
|
||||
|
||||
_, err := c.DecortAPICall(ctx, "POST", VinsRestoreAPI, urlValues)
|
||||
_, err := c.CloudAPI().VINS().Restore(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
case status.Modeled:
|
||||
return diag.Errorf("ViNS are in status: %s, please, contact support for more information", vins.Status)
|
||||
return diag.Errorf("ViNS are in status: %s, please, contact support for more information", vinsData.Status)
|
||||
case status.Created:
|
||||
case status.Enabled:
|
||||
if !isEnabled {
|
||||
hasChangeState = true
|
||||
urlValues := &url.Values{}
|
||||
req := vins.DisableEnableRequest{
|
||||
VINSID: vinsData.ID,
|
||||
}
|
||||
|
||||
urlValues.Add("vinsId", d.Id())
|
||||
|
||||
_, err := c.DecortAPICall(ctx, "POST", VinsDisableAPI, urlValues)
|
||||
_, err := c.CloudAPI().VINS().Disable(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
@@ -396,43 +410,44 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
case status.Disabled:
|
||||
if isEnabled {
|
||||
hasChangeState = true
|
||||
urlValues := &url.Values{}
|
||||
req := vins.DisableEnableRequest{
|
||||
VINSID: vinsData.ID,
|
||||
}
|
||||
|
||||
urlValues.Add("vinsId", d.Id())
|
||||
|
||||
_, err := c.DecortAPICall(ctx, "POST", VinsEnableAPI, urlValues)
|
||||
_, err := c.CloudAPI().VINS().Enable(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
case status.Disabling:
|
||||
case status.Deleting:
|
||||
return diag.Errorf("ViNS are in progress with status: %s", vins.Status)
|
||||
return diag.Errorf("ViNS are in progress with status: %s", vinsData.Status)
|
||||
}
|
||||
|
||||
if hasChangeState {
|
||||
vins, err = utilityVinsCheckPresence(ctx, d, m)
|
||||
vinsData, err = utilityVinsCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
urlValues := &url.Values{}
|
||||
|
||||
enableOld, enableNew := d.GetChange("enable")
|
||||
if enableOld.(bool) && !enableNew.(bool) {
|
||||
if !urlValues.Has("vinsId") {
|
||||
urlValues.Add("vinsId", d.Id())
|
||||
req := vins.DisableEnableRequest{
|
||||
VINSID: vinsData.ID,
|
||||
}
|
||||
_, err := c.DecortAPICall(ctx, "POST", VinsDisableAPI, urlValues)
|
||||
|
||||
_, err := c.CloudAPI().VINS().Disable(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
} else if !enableOld.(bool) && enableNew.(bool) {
|
||||
if !urlValues.Has("vinsId") {
|
||||
urlValues.Add("vinsId", d.Id())
|
||||
req := vins.DisableEnableRequest{
|
||||
VINSID: vinsData.ID,
|
||||
}
|
||||
_, err := c.DecortAPICall(ctx, "POST", VinsEnableAPI, urlValues)
|
||||
|
||||
_, err := c.CloudAPI().VINS().Enable(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
@@ -443,12 +458,11 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
if oldExtNetId.(int) != newExtNedId.(int) {
|
||||
log.Debugf("resourceVinsUpdate: changing ViNS ID %s - ext_net_id %d -> %d", d.Id(), oldExtNetId.(int), newExtNedId.(int))
|
||||
|
||||
extnetParams := &url.Values{}
|
||||
extnetParams.Add("vinsId", d.Id())
|
||||
|
||||
if oldExtNetId.(int) > 0 {
|
||||
// there was preexisting external net connection - disconnect ViNS
|
||||
_, err := c.DecortAPICall(ctx, "POST", VinsExtNetDisconnectAPI, extnetParams)
|
||||
req := vins.ExtNetDisconnectRequest{VINSID: vinsData.ID}
|
||||
|
||||
_, err := c.CloudAPI().VINS().ExtNetDisconnect(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
@@ -456,19 +470,24 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
|
||||
if newExtNedId.(int) > 0 {
|
||||
// new external network connection requested - connect ViNS
|
||||
extnetParams.Add("netId", fmt.Sprintf("%d", newExtNedId.(int)))
|
||||
req := vins.ExtNetConnectRequest{
|
||||
VINSID: vinsData.ID,
|
||||
NetID: uint64(newExtNedId.(int)),
|
||||
IP: "",
|
||||
}
|
||||
|
||||
extNetIp, ok := d.GetOk("ext_net_ip")
|
||||
if ok && extNetIp.(string) != "" {
|
||||
urlValues.Add("Ip", extNetIp.(string))
|
||||
req.IP = extNetIp.(string)
|
||||
}
|
||||
_, err := c.DecortAPICall(ctx, "POST", VinsExtNetConnectAPI, extnetParams)
|
||||
|
||||
_, err := c.CloudAPI().VINS().ExtNetConnect(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
urlValues = &url.Values{}
|
||||
if d.HasChange("ip") {
|
||||
deletedIps := make([]interface{}, 0)
|
||||
addedIps := make([]interface{}, 0)
|
||||
@@ -491,17 +510,17 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
|
||||
if len(deletedIps) > 0 {
|
||||
for _, ipInterfase := range deletedIps {
|
||||
urlValues = &url.Values{}
|
||||
ip := ipInterfase.(map[string]interface{})
|
||||
req := vins.IPReleaseRequest{VINSID: vinsData.ID}
|
||||
|
||||
urlValues.Add("vinsId", d.Id())
|
||||
if ip["ip_addr"].(string) != "" {
|
||||
urlValues.Add("ipAddr", ip["ip_addr"].(string))
|
||||
req.IPAddr = ip["ip_addr"].(string)
|
||||
}
|
||||
if ip["mac_addr"].(string) != "" {
|
||||
urlValues.Add("mac", ip["mac_addr"].(string))
|
||||
req.MAC = ip["mac_addr"].(string)
|
||||
}
|
||||
_, err := c.DecortAPICall(ctx, "POST", VinsIpReleaseAPI, urlValues)
|
||||
|
||||
_, err := c.CloudAPI().VINS().IPRelese(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
@@ -510,21 +529,23 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
|
||||
if len(addedIps) > 0 {
|
||||
for _, ipInterfase := range addedIps {
|
||||
urlValues = &url.Values{}
|
||||
ip := ipInterfase.(map[string]interface{})
|
||||
req := vins.IPReserveRequest{
|
||||
VINSID: vinsData.ID,
|
||||
Type: ip["type"].(string),
|
||||
}
|
||||
|
||||
urlValues.Add("vinsId", d.Id())
|
||||
urlValues.Add("type", ip["type"].(string))
|
||||
if ip["ip_addr"].(string) != "" {
|
||||
urlValues.Add("ipAddr", ip["ip_addr"].(string))
|
||||
req.IPAddr = ip["ip_addr"].(string)
|
||||
}
|
||||
if ip["mac_addr"].(string) != "" {
|
||||
urlValues.Add("mac", ip["mac_addr"].(string))
|
||||
req.MAC = ip["mac_addr"].(string)
|
||||
}
|
||||
if ip["compute_id"].(int) != 0 {
|
||||
urlValues.Add("computeId", strconv.Itoa(ip["compute_id"].(int)))
|
||||
req.ComputeID = uint64(ip["compute_id"].(int))
|
||||
}
|
||||
_, err := c.DecortAPICall(ctx, "POST", VinsIpReserveAPI, urlValues)
|
||||
|
||||
_, err := c.CloudAPI().VINS().IPReserve(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
@@ -541,26 +562,26 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
newNatRulesSlice := newNatRulesInterface.([]interface{})
|
||||
|
||||
for _, el := range oldNatRulesSlice {
|
||||
if !isContinsNatRule(newNatRulesSlice, el) {
|
||||
if !isContainsNatRule(newNatRulesSlice, el) {
|
||||
deletedNatRules = append(deletedNatRules, el)
|
||||
}
|
||||
}
|
||||
|
||||
for _, el := range newNatRulesSlice {
|
||||
if !isContinsNatRule(oldNatRulesSlice, el) {
|
||||
if !isContainsNatRule(oldNatRulesSlice, el) {
|
||||
addedNatRules = append(addedNatRules, el)
|
||||
}
|
||||
}
|
||||
|
||||
if len(deletedNatRules) > 0 {
|
||||
for _, natRuleInterface := range deletedNatRules {
|
||||
urlValues = &url.Values{}
|
||||
natRule := natRuleInterface.(map[string]interface{})
|
||||
req := vins.NATRuleDelRequest{
|
||||
VINSID: vinsData.ID,
|
||||
RuleID: uint64(natRule["rule_id"].(int)),
|
||||
}
|
||||
|
||||
urlValues.Add("vinsId", d.Id())
|
||||
urlValues.Add("ruleId", strconv.Itoa(natRule["rule_id"].(int)))
|
||||
log.Debug("NAT_RULE_DEL_WITH: ", urlValues.Encode())
|
||||
_, err := c.DecortAPICall(ctx, "POST", VinsNatRuleDelAPI, urlValues)
|
||||
_, err := c.CloudAPI().VINS().NATRuleDel(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
@@ -569,22 +590,22 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
|
||||
if len(addedNatRules) > 0 {
|
||||
for _, natRuleInterface := range addedNatRules {
|
||||
urlValues = &url.Values{}
|
||||
natRule := natRuleInterface.(map[string]interface{})
|
||||
req := vins.NATRuleAddRequest{
|
||||
VINSID: vinsData.ID,
|
||||
IntIP: natRule["int_ip"].(string),
|
||||
IntPort: uint(natRule["int_port"].(int)),
|
||||
ExtPortStart: uint(natRule["ext_port_start"].(int)),
|
||||
}
|
||||
|
||||
urlValues.Add("vinsId", d.Id())
|
||||
urlValues.Add("intIp", natRule["int_ip"].(string))
|
||||
urlValues.Add("intPort", strconv.Itoa(natRule["int_port"].(int)))
|
||||
urlValues.Add("extPortStart", strconv.Itoa(natRule["ext_port_start"].(int)))
|
||||
if natRule["ext_port_end"].(int) != 0 {
|
||||
urlValues.Add("extPortEnd", strconv.Itoa(natRule["ext_port_end"].(int)))
|
||||
req.ExtPortEnd = uint(natRule["ext_port_end"].(int))
|
||||
}
|
||||
if natRule["proto"].(string) != "" {
|
||||
urlValues.Add("proto", natRule["proto"].(string))
|
||||
req.Proto = natRule["proto"].(string)
|
||||
}
|
||||
|
||||
log.Debug("NAT_RULE_ADD_WITH: ", urlValues.Encode())
|
||||
_, err := c.DecortAPICall(ctx, "POST", VinsNatRuleAddAPI, urlValues)
|
||||
_, err := c.CloudAPI().VINS().NATRuleAdd(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
@@ -593,18 +614,18 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
}
|
||||
|
||||
if oldRestart, newRestart := d.GetChange("vnfdev_restart"); oldRestart == false && newRestart == true {
|
||||
urlValues = &url.Values{}
|
||||
urlValues.Add("vinsId", d.Id())
|
||||
_, err := c.DecortAPICall(ctx, "POST", VinsVnfdevRestartAPI, urlValues)
|
||||
req := vins.VNFDevRestartRequest{VINSID: vinsData.ID}
|
||||
|
||||
_, err := c.CloudAPI().VINS().VNFDevRestart(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
if oldRedeploy, newRedeploy := d.GetChange("vnfdev_redeploy"); oldRedeploy == false && newRedeploy == true {
|
||||
urlValues = &url.Values{}
|
||||
urlValues.Add("vinsId", d.Id())
|
||||
_, err := c.DecortAPICall(ctx, "POST", VinsVnfdevRedeployAPI, urlValues)
|
||||
req := vins.VNFDevRedeployRequest{VINSID: vinsData.ID}
|
||||
|
||||
_, err := c.CloudAPI().VINS().VNFDevRedeploy(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
@@ -615,16 +636,21 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
}
|
||||
|
||||
func resourceVinsDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
urlValues := &url.Values{}
|
||||
c := m.(*controller.ControllerCfg)
|
||||
vinsId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req := vins.DeleteRequest{
|
||||
VINSID: vinsId,
|
||||
Force: d.Get("force").(bool),
|
||||
Permanently: d.Get("permanently").(bool),
|
||||
}
|
||||
|
||||
urlValues.Add("vinsId", d.Id())
|
||||
urlValues.Add("force", strconv.FormatBool(d.Get("force").(bool)))
|
||||
urlValues.Add("permanently", strconv.FormatBool(d.Get("permanently").(bool)))
|
||||
_, err := c.DecortAPICall(ctx, "POST", VinsDeleteAPI, urlValues)
|
||||
_, err := c.CloudAPI().VINS().Delete(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -34,49 +34,39 @@ package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityDataVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*VINSDetailed, error) {
|
||||
func utilityDataVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.RecordVINS, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
vins := &VINSDetailed{}
|
||||
req := vins.GetRequest{
|
||||
VINSID: uint64(d.Get("vins_id").(int)),
|
||||
}
|
||||
|
||||
urlValues.Add("vinsId", strconv.Itoa(d.Get("vins_id").(int)))
|
||||
vinsRaw, err := c.DecortAPICall(ctx, "POST", VinsGetAPI, urlValues)
|
||||
vins, err := c.CloudAPI().VINS().Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(vinsRaw), vins)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return vins, nil
|
||||
|
||||
}
|
||||
|
||||
func utilityVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*VINSDetailed, error) {
|
||||
func utilityVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.RecordVINS, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
vins := &VINSDetailed{}
|
||||
vinsId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req := vins.GetRequest{
|
||||
VINSID: vinsId,
|
||||
}
|
||||
|
||||
urlValues.Add("vinsId", d.Id())
|
||||
vinsRaw, err := c.DecortAPICall(ctx, "POST", VinsGetAPI, urlValues)
|
||||
vins, err := c.CloudAPI().VINS().Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(vinsRaw), vins)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return vins, nil
|
||||
|
||||
}
|
||||
|
||||
@@ -34,28 +34,22 @@ package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityVinsAuditsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (VINSAuditsList, error) {
|
||||
func utilityVinsAuditsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (vins.ListAudits, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
auditsList := VINSAuditsList{}
|
||||
req := vins.AuditsRequest{
|
||||
VINSID: uint64(d.Get("vins_id").(int)),
|
||||
}
|
||||
|
||||
urlValues.Add("vinsId", strconv.Itoa(d.Get("vins_id").(int)))
|
||||
auidtsRaw, err := c.DecortAPICall(ctx, "POST", VinsAuditsAPI, urlValues)
|
||||
audits, err := c.CloudAPI().VINS().Audits(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(auidtsRaw), &auditsList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return auditsList, nil
|
||||
return audits, nil
|
||||
}
|
||||
|
||||
@@ -34,28 +34,22 @@ package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityVinsExtNetListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (ExtNetList, error) {
|
||||
func utilityVinsExtNetListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (vins.ListExtNets, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
extNet := ExtNetList{}
|
||||
req := vins.ExtNetListRequest{
|
||||
VINSID: uint64(d.Get("vins_id").(int)),
|
||||
}
|
||||
|
||||
urlValues.Add("vinsId", strconv.Itoa(d.Get("vins_id").(int)))
|
||||
extNetRaw, err := c.DecortAPICall(ctx, "POST", VinsExtNetListAPI, urlValues)
|
||||
extNetList, err := c.CloudAPI().VINS().ExtNetList(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(extNetRaw), &extNet)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return extNet, nil
|
||||
return extNetList, nil
|
||||
}
|
||||
|
||||
@@ -34,28 +34,22 @@ package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityVinsIpListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (IPList, error) {
|
||||
func utilityVinsIpListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (vins.ListIPs, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
ips := IPList{}
|
||||
req := vins.IPListRequest{
|
||||
VINSID: uint64(d.Get("vins_id").(int)),
|
||||
}
|
||||
|
||||
urlValues.Add("vinsId", strconv.Itoa(d.Get("vins_id").(int)))
|
||||
auidtsRaw, err := c.DecortAPICall(ctx, "POST", VinsIpListAPI, urlValues)
|
||||
ips, err := c.CloudAPI().VINS().IPList(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(auidtsRaw), &ips)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ips, nil
|
||||
}
|
||||
|
||||
@@ -34,38 +34,30 @@ package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (VINSList, error) {
|
||||
vinsList := VINSList{}
|
||||
func utilityVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (vins.ListVINS, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
req := vins.ListRequest{}
|
||||
|
||||
if includeDeleted, ok := d.GetOk("include_deleted"); ok {
|
||||
urlValues.Add("includeDeleted", strconv.FormatBool(includeDeleted.(bool)))
|
||||
req.IncludeDeleted = includeDeleted.(bool)
|
||||
}
|
||||
if page, ok := d.GetOk("page"); ok {
|
||||
urlValues.Add("page", strconv.Itoa(page.(int)))
|
||||
req.Page = uint64(page.(int))
|
||||
}
|
||||
if size, ok := d.GetOk("size"); ok {
|
||||
urlValues.Add("size", strconv.Itoa(size.(int)))
|
||||
req.Size = uint64(size.(int))
|
||||
}
|
||||
|
||||
log.Debugf("utilityVinsListCheckPresence")
|
||||
vinsListRaw, err := c.DecortAPICall(ctx, "POST", VinsListAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(vinsListRaw), &vinsList)
|
||||
vinsList, err := c.CloudAPI().VINS().List(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -34,34 +34,26 @@ package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityVinsListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (VINSList, error) {
|
||||
vinsList := VINSList{}
|
||||
func utilityVinsListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (vins.ListVINS, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
req := vins.ListDeletedRequest{}
|
||||
|
||||
if page, ok := d.GetOk("page"); ok {
|
||||
urlValues.Add("page", strconv.Itoa(page.(int)))
|
||||
req.Page = uint64(page.(int))
|
||||
}
|
||||
if size, ok := d.GetOk("size"); ok {
|
||||
urlValues.Add("size", strconv.Itoa(size.(int)))
|
||||
req.Size = uint64(size.(int))
|
||||
}
|
||||
|
||||
log.Debugf("utilityVinsListDeletedCheckPresence")
|
||||
vinsListRaw, err := c.DecortAPICall(ctx, "POST", VinsListDeletedAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(vinsListRaw), &vinsList)
|
||||
vinsList, err := c.CloudAPI().VINS().ListDeleted(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -34,28 +34,22 @@ package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityVinsNatRuleListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (NATRuleList, error) {
|
||||
func utilityVinsNatRuleListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (vins.ListNATRules, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
natRuleList := NATRuleList{}
|
||||
req := vins.NATRuleListRequest{
|
||||
VINSID: uint64(d.Get("vins_id").(int)),
|
||||
}
|
||||
|
||||
urlValues.Add("vinsId", strconv.Itoa(d.Get("vins_id").(int)))
|
||||
auidtsRaw, err := c.DecortAPICall(ctx, "POST", VinsNatRuleListAPI, urlValues)
|
||||
natRuleList, err := c.CloudAPI().VINS().NATRuleList(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(auidtsRaw), &natRuleList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return natRuleList, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user