You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
3.6 KiB
138 lines
3.6 KiB
package extnet
|
|
|
|
import (
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/extnet"
|
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
|
|
)
|
|
|
|
func flattenExtnet(d *schema.ResourceData, e *extnet.RecordExtNet) {
|
|
d.Set("ckey", e.CKey)
|
|
d.Set("meta", flattens.FlattenMeta(e.Meta))
|
|
d.Set("check__ips", e.CheckIPs)
|
|
d.Set("check_ips", e.CheckIps)
|
|
d.Set("default", e.Default)
|
|
d.Set("default_qos", flattenExtnetDefaultQos(e.DefaultQOS))
|
|
d.Set("desc", e.Description)
|
|
d.Set("dns", e.DNS)
|
|
d.Set("excluded", flattenExcluded(e.Excluded))
|
|
d.Set("free_ips", e.FreeIPs)
|
|
d.Set("gateway", e.Gateway)
|
|
d.Set("gid", e.GID)
|
|
d.Set("guid", e.GUID)
|
|
d.Set("ipcidr", e.IPCIDR)
|
|
d.Set("milestones", e.Milestones)
|
|
d.Set("net_name", e.Name)
|
|
d.Set("network", e.Network)
|
|
d.Set("network_id", e.NetworkID)
|
|
d.Set("pre_reservations_num", e.PreReservationsNum)
|
|
d.Set("prefix", e.Prefix)
|
|
d.Set("pri_vnf_dev_id", e.PriVNFDevID)
|
|
d.Set("reservations", flattenExtnetReservations(e.Reservations))
|
|
d.Set("shared_with", e.SharedWith)
|
|
d.Set("status", e.Status)
|
|
d.Set("vlan_id", e.VLANID)
|
|
d.Set("vnfs", flattenExtnetVNFS(e.VNFs))
|
|
}
|
|
|
|
func flattenExcluded(ex []extnet.Excluded) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
for _, item := range ex {
|
|
temp := map[string]interface{}{
|
|
"client_type": item.ClientType,
|
|
"mac": item.MAC,
|
|
"ip": item.IP,
|
|
"type": item.Type,
|
|
"vm_id": item.VMID,
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
|
|
return res
|
|
}
|
|
|
|
func flattenExtnetReservations(ers extnet.ListReservations) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
for _, er := range ers {
|
|
temp := map[string]interface{}{
|
|
"client_type": er.ClientType,
|
|
"domainname": er.DomainName,
|
|
"hostname": er.Hostname,
|
|
"desc": er.Description,
|
|
"ip": er.IP,
|
|
"mac": er.MAC,
|
|
"type": er.Type,
|
|
"vm_id": er.VMID,
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
|
|
return res
|
|
}
|
|
|
|
func flattenExtnetDefaultQos(edqos extnet.QOS) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
temp := map[string]interface{}{
|
|
"e_rate": edqos.ERate,
|
|
"e_burst": edqos.EBurst,
|
|
"guid": edqos.GUID,
|
|
"in_burst": edqos.InBurst,
|
|
"in_rate": edqos.InRate,
|
|
}
|
|
res = append(res, temp)
|
|
return res
|
|
}
|
|
|
|
func flattenExtnetVNFS(evnfs extnet.VNFs) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
temp := map[string]interface{}{
|
|
"dhcp": evnfs.DHCP,
|
|
}
|
|
res = append(res, temp)
|
|
return res
|
|
}
|
|
|
|
func flattenExtnetsComputes(ecs extnet.ListExtNetExtends) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
for _, ec := range ecs {
|
|
temp := map[string]interface{}{
|
|
"net_id": ec.ID,
|
|
"ipaddr": ec.IPAddr,
|
|
"ipcidr": ec.IPCIDR,
|
|
"name": ec.Name,
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
return res
|
|
}
|
|
|
|
func flattenExtnetComputesList(ecl extnet.ListExtNetComputes) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
for _, ec := range ecl {
|
|
temp := map[string]interface{}{
|
|
"account_id": ec.AccountID,
|
|
"account_name": ec.AccountName,
|
|
"extnets": flattenExtnetsComputes(ec.ExtNets),
|
|
"id": ec.ID,
|
|
"name": ec.Name,
|
|
"rg_id": ec.RGID,
|
|
"rg_name": ec.RGName,
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
return res
|
|
}
|
|
|
|
func flattenExtnetList(el extnet.ListExtNets) []map[string]interface{} {
|
|
res := make([]map[string]interface{}, 0)
|
|
for _, e := range el {
|
|
temp := map[string]interface{}{
|
|
"net_id": e.ID,
|
|
"ipcidr": e.IPCIDR,
|
|
"name": e.Name,
|
|
}
|
|
res = append(res, temp)
|
|
}
|
|
return res
|
|
}
|