3.5.0
This commit is contained in:
@@ -33,27 +33,25 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
||||
package kvmvm
|
||||
|
||||
const (
|
||||
KvmX86CreateAPI = "/restmachine/cloudapi/kvmx86/create"
|
||||
KvmPPCCreateAPI = "/restmachine/cloudapi/kvmppc/create"
|
||||
ComputeGetAPI = "/restmachine/cloudapi/compute/get"
|
||||
RgListComputesAPI = "/restmachine/cloudapi/rg/listComputes"
|
||||
ComputeNetAttachAPI = "/restmachine/cloudapi/compute/netAttach"
|
||||
ComputeNetDetachAPI = "/restmachine/cloudapi/compute/netDetach"
|
||||
ComputeDiskAttachAPI = "/restmachine/cloudapi/compute/diskAttach"
|
||||
ComputeDiskDetachAPI = "/restmachine/cloudapi/compute/diskDetach"
|
||||
ComputeStartAPI = "/restmachine/cloudapi/compute/start"
|
||||
ComputeStopAPI = "/restmachine/cloudapi/compute/stop"
|
||||
ComputeResizeAPI = "/restmachine/cloudapi/compute/resize"
|
||||
DisksResizeAPI = "/restmachine/cloudapi/disks/resize2"
|
||||
ComputeDeleteAPI = "/restmachine/cloudapi/compute/delete"
|
||||
ComputeUpdateAPI = "/restmachine/cloudapi/compute/update"
|
||||
ComputeDiskAddAPI = "/restmachine/cloudapi/compute/diskAdd"
|
||||
ComputeDiskDeleteAPI = "/restmachine/cloudapi/compute/diskDel"
|
||||
ComputeRestoreAPI = "/restmachine/cloudapi/compute/restore"
|
||||
ComputeEnableAPI = "/restmachine/cloudapi/compute/enable"
|
||||
ComputeDisableAPI = "/restmachine/cloudapi/compute/disable"
|
||||
|
||||
//affinity and anti-affinity
|
||||
KvmX86CreateAPI = "/restmachine/cloudapi/kvmx86/create"
|
||||
KvmPPCCreateAPI = "/restmachine/cloudapi/kvmppc/create"
|
||||
ComputeGetAPI = "/restmachine/cloudapi/compute/get"
|
||||
RgListComputesAPI = "/restmachine/cloudapi/rg/listComputes"
|
||||
ComputeNetAttachAPI = "/restmachine/cloudapi/compute/netAttach"
|
||||
ComputeNetDetachAPI = "/restmachine/cloudapi/compute/netDetach"
|
||||
ComputeDiskAttachAPI = "/restmachine/cloudapi/compute/diskAttach"
|
||||
ComputeDiskDetachAPI = "/restmachine/cloudapi/compute/diskDetach"
|
||||
ComputeStartAPI = "/restmachine/cloudapi/compute/start"
|
||||
ComputeStopAPI = "/restmachine/cloudapi/compute/stop"
|
||||
ComputeResizeAPI = "/restmachine/cloudapi/compute/resize"
|
||||
DisksResizeAPI = "/restmachine/cloudapi/disks/resize2"
|
||||
ComputeDeleteAPI = "/restmachine/cloudapi/compute/delete"
|
||||
ComputeUpdateAPI = "/restmachine/cloudapi/compute/update"
|
||||
ComputeDiskAddAPI = "/restmachine/cloudapi/compute/diskAdd"
|
||||
ComputeDiskDeleteAPI = "/restmachine/cloudapi/compute/diskDel"
|
||||
ComputeRestoreAPI = "/restmachine/cloudapi/compute/restore"
|
||||
ComputeEnableAPI = "/restmachine/cloudapi/compute/enable"
|
||||
ComputeDisableAPI = "/restmachine/cloudapi/compute/disable"
|
||||
ComputeAffinityLabelSetAPI = "/restmachine/cloudapi/compute/affinityLabelSet"
|
||||
ComputeAffinityLabelRemoveAPI = "/restmachine/cloudapi/compute/affinityLabelRemove"
|
||||
ComputeAffinityRuleAddAPI = "/restmachine/cloudapi/compute/affinityRuleAdd"
|
||||
@@ -62,4 +60,28 @@ const (
|
||||
ComputeAntiAffinityRuleAddAPI = "/restmachine/cloudapi/compute/antiAffinityRuleAdd"
|
||||
ComputeAntiAffinityRuleRemoveAPI = "/restmachine/cloudapi/compute/antiAffinityRuleRemove"
|
||||
ComputeAntiAffinityRulesClearAPI = "/restmachine/cloudapi/compute/antiAffinityRulesClear"
|
||||
ComputeListAPI = "/restmachine/cloudapi/compute/list"
|
||||
ComputeAuditsAPI = "/restmachine/cloudapi/compute/audits"
|
||||
ComputeGetAuditsAPI = "/restmachine/cloudapi/compute/getAudits"
|
||||
ComputeGetConsoleUrlAPI = "/restmachine/cloudapi/compute/getConsoleUrl"
|
||||
ComputeGetLogAPI = "/restmachine/cloudapi/compute/getLog"
|
||||
ComputePfwListAPI = "/restmachine/cloudapi/compute/pfwList"
|
||||
ComputeUserListAPI = "/restmachine/cloudapi/compute/userList"
|
||||
ComputeTagAddAPI = "/restmachine/cloudapi/compute/tagAdd"
|
||||
ComputeTagRemoveAPI = "/restmachine/cloudapi/compute/tagRemove"
|
||||
ComputePinToStackAPI = "/restmachine/cloudapi/compute/pinToStack"
|
||||
ComputeUnpinFromStackAPI = "/restmachine/cloudapi/compute/unpinFromStack"
|
||||
ComputePfwAddAPI = "/restmachine/cloudapi/compute/pfwAdd"
|
||||
ComputePfwDelAPI = "/restmachine/cloudapi/compute/pfwDel"
|
||||
ComputeUserGrantAPI = "/restmachine/cloudapi/compute/userGrant"
|
||||
ComputeUserRevokeAPI = "/restmachine/cloudapi/compute/userRevoke"
|
||||
ComputeSnapshotCreateAPI = "/restmachine/cloudapi/compute/snapshotCreate"
|
||||
ComputeSnapshotDeleteAPI = "/restmachine/cloudapi/compute/snapshotCreate"
|
||||
ComputeSnapshotRollbackAPI = "/restmachine/cloudapi/compute/snapshotRollback"
|
||||
ComputePauseAPI = "/restmachine/cloudapi/compute/pause"
|
||||
ComputeResumeAPI = "/restmachine/cloudapi/compute/resume"
|
||||
ComputeCdInsertAPI = "/restmachine/cloudapi/compute/cdInsert"
|
||||
ComputeCdEjectAPI = "/restmachine/cloudapi/compute/cdEject"
|
||||
ComputeResetAPI = "/restmachine/cloudapi/compute/reset"
|
||||
ComputeRedeployAPI = "/restmachine/cloudapi/compute/redeploy"
|
||||
)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,74 @@
|
||||
package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceComputeAuditsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
computeAudits, err := utilityComputeAuditsCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenComputeAudits(computeAudits))
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceComputeAuditsSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"compute_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"call": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"responsetime": {
|
||||
Type: schema.TypeFloat,
|
||||
Computed: true,
|
||||
},
|
||||
"statuscode": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"timestamp": {
|
||||
Type: schema.TypeFloat,
|
||||
Computed: true,
|
||||
},
|
||||
"user": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func DataSourceComputeAudits() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceComputeAuditsRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceComputeAuditsSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceComputeGetAuditsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
computeAudits, err := utilityComputeGetAuditsCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenComputeGetAudits(computeAudits))
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceComputeGetAuditsSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"compute_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"epoch": {
|
||||
Type: schema.TypeFloat,
|
||||
Computed: true,
|
||||
},
|
||||
"message": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func DataSourceComputeGetAudits() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceComputeGetAuditsRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceComputeGetAuditsSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceComputeGetConsoleUrlRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
computeConsoleUrl, err := utilityComputeGetConsoleUrlCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
result := strings.ReplaceAll(string(computeConsoleUrl), "\"", "")
|
||||
result = strings.ReplaceAll(string(result), "\\", "")
|
||||
d.Set("console_url", result)
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceComputeGetConsoleUrlSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"compute_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
"console_url": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func DataSourceComputeGetConsoleUrl() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceComputeGetConsoleUrlRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceComputeGetConsoleUrlSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceComputeGetLogRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
computeGetLog, err := utilityComputeGetLogCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("log", computeGetLog)
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceComputeGetLogSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"compute_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
"path": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"log": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func DataSourceComputeGetLog() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceComputeGetLogRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceComputeGetLogSchemaMake(),
|
||||
}
|
||||
}
|
||||
335
internal/service/cloudapi/kvmvm/data_source_compute_list.go
Normal file
335
internal/service/cloudapi/kvmvm/data_source_compute_list.go
Normal file
@@ -0,0 +1,335 @@
|
||||
package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceComputeListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
computeList, err := utilityDataComputeListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenComputeList(computeList))
|
||||
return nil
|
||||
}
|
||||
|
||||
func computeDisksSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"disk_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"pci_slot": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
func itemComputeSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"acl": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: computeListACLSchemaMake(),
|
||||
},
|
||||
},
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"account_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"affinity_label": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"affinity_rules": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: computeListRulesSchemaMake(),
|
||||
},
|
||||
},
|
||||
"affinity_weight": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"anti_affinity_rules": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: computeListRulesSchemaMake(),
|
||||
},
|
||||
},
|
||||
"arch": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"boot_order": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"bootdisk_size": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"clone_reference": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"clones": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"computeci_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"cpus": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"created_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"created_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"custom_fields": { //NEED
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"devices": { //NEED
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"disks": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: computeDisksSchemaMake(),
|
||||
},
|
||||
},
|
||||
"driver": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"compute_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"image_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"interfaces": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: computeInterfacesSchemaMake(),
|
||||
},
|
||||
},
|
||||
"lock_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"manager_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"manager_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"migrationjob": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"milestones": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"pinned": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"ram": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"reference_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"registered": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"res_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"rg_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"rg_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"snap_sets": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: computeSnapSetsSchemaMake(),
|
||||
},
|
||||
},
|
||||
"stateless_sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"stateless_sep_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"tags": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"key": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"val": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"tech_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"total_disk_size": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"user_managed": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"vgpus": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"vins_connected": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"virtual_image_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceCompputeListSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"includedeleted": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
},
|
||||
"page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
"size": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: itemComputeSchemaMake(),
|
||||
},
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func DataSourceComputeList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceComputeListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceCompputeListSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceComputePfwListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
computePfwList, err := utilityComputePfwListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenPfwList(computePfwList))
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceComputePfwListSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"compute_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"pfw_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"local_ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"local_port": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"protocol": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"public_port_end": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"public_port_start": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"vm_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func DataSourceComputePfwList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceComputePfwListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceComputePfwListSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceComputeUserListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
computeUserList, err := utilityComputeUserListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
flattenUserList(d, computeUserList)
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceComputeUserListSchemaMake() map[string]*schema.Schema {
|
||||
res := computeACLSchemaMake()
|
||||
res["compute_id"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func DataSourceComputeUserList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceComputeUserListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceComputeUserListSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -2,17 +2,195 @@ package kvmvm
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/status"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func flattenComputeDisksDemo(disksList []DiskRecord, extraDisks []interface{}) []map[string]interface{} {
|
||||
func flattenDisks(disks []InfoDisk) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, disk := range disks {
|
||||
temp := map[string]interface{}{
|
||||
"disk_id": disk.ID,
|
||||
"pci_slot": disk.PCISlot,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
func flattenQOS(qos QOS) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"e_rate": qos.ERate,
|
||||
"guid": qos.GUID,
|
||||
"in_brust": qos.InBurst,
|
||||
"in_rate": qos.InRate,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
func flattenInterfaces(interfaces ListInterfaces) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, interfaceItem := range interfaces {
|
||||
temp := map[string]interface{}{
|
||||
"conn_id": interfaceItem.ConnID,
|
||||
"conn_type": interfaceItem.ConnType,
|
||||
"def_gw": interfaceItem.DefGW,
|
||||
"flip_group_id": interfaceItem.FLIPGroupID,
|
||||
"guid": interfaceItem.GUID,
|
||||
"ip_address": interfaceItem.IPAddress,
|
||||
"listen_ssh": interfaceItem.ListenSSH,
|
||||
"mac": interfaceItem.MAC,
|
||||
"name": interfaceItem.Name,
|
||||
"net_id": interfaceItem.NetID,
|
||||
"netmask": interfaceItem.NetMask,
|
||||
"net_type": interfaceItem.NetType,
|
||||
"pci_slot": interfaceItem.PCISlot,
|
||||
"qos": flattenQOS(interfaceItem.QOS),
|
||||
"target": interfaceItem.Target,
|
||||
"type": interfaceItem.Type,
|
||||
"vnfs": interfaceItem.VNFs,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
func flattenSnapSets(snapSets ListSnapSets) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, snapSet := range snapSets {
|
||||
temp := map[string]interface{}{
|
||||
"disks": snapSet.Disks,
|
||||
"guid": snapSet.GUID,
|
||||
"label": snapSet.Label,
|
||||
"timestamp": snapSet.Timestamp,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
func flattenTags(tags map[string]string) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for key, val := range tags {
|
||||
temp := map[string]interface{}{
|
||||
"key": key,
|
||||
"val": val,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenListRules(listRules ListRules) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, rule := range listRules {
|
||||
temp := map[string]interface{}{
|
||||
"guid": rule.GUID,
|
||||
"key": rule.Key,
|
||||
"mode": rule.Mode,
|
||||
"policy": rule.Policy,
|
||||
"topology": rule.Topology,
|
||||
"value": rule.Value,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
func flattenListACL(listAcl ListACL) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, acl := range listAcl {
|
||||
var explicit interface{}
|
||||
switch acl.Explicit.(type) { //Платформенный хак
|
||||
case bool:
|
||||
explicit = acl.Explicit.(bool)
|
||||
case string:
|
||||
explicit, _ = strconv.ParseBool(acl.Explicit.(string))
|
||||
}
|
||||
temp := map[string]interface{}{
|
||||
"explicit": explicit,
|
||||
"guid": acl.GUID,
|
||||
"right": acl.Right,
|
||||
"status": acl.Status,
|
||||
"type": acl.Type,
|
||||
"user_group_id": acl.UserGroupID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
func flattenComputeList(computes ListComputes) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, compute := range computes {
|
||||
customFields, _ := json.Marshal(compute.CustomFields)
|
||||
devices, _ := json.Marshal(compute.Devices)
|
||||
temp := map[string]interface{}{
|
||||
"acl": flattenListACL(compute.ACL),
|
||||
"account_id": compute.AccountID,
|
||||
"account_name": compute.AccountName,
|
||||
"affinity_label": compute.AffinityLabel,
|
||||
"affinity_rules": flattenListRules(compute.AffinityRules),
|
||||
"affinity_weight": compute.AffinityWeight,
|
||||
"anti_affinity_rules": flattenListRules(compute.AntiAffinityRules),
|
||||
"arch": compute.Architecture,
|
||||
"boot_order": compute.BootOrder,
|
||||
"bootdisk_size": compute.BootDiskSize,
|
||||
"clone_reference": compute.CloneReference,
|
||||
"clones": compute.Clones,
|
||||
"computeci_id": compute.ComputeCIID,
|
||||
"cpus": compute.CPU,
|
||||
"created_by": compute.CreatedBy,
|
||||
"created_time": compute.CreatedTime,
|
||||
"custom_fields": string(customFields),
|
||||
"deleted_by": compute.DeletedBy,
|
||||
"deleted_time": compute.DeletedTime,
|
||||
"desc": compute.Description,
|
||||
"devices": string(devices),
|
||||
"disks": flattenDisks(compute.Disks),
|
||||
"driver": compute.Driver,
|
||||
"gid": compute.GID,
|
||||
"guid": compute.GUID,
|
||||
"compute_id": compute.ID,
|
||||
"image_id": compute.ImageID,
|
||||
"interfaces": flattenInterfaces(compute.Interfaces),
|
||||
"lock_status": compute.LockStatus,
|
||||
"manager_id": compute.ManagerID,
|
||||
"manager_type": compute.ManagerType,
|
||||
"migrationjob": compute.MigrationJob,
|
||||
"milestones": compute.Milestones,
|
||||
"name": compute.Name,
|
||||
"pinned": compute.Pinned,
|
||||
"ram": compute.RAM,
|
||||
"reference_id": compute.ReferenceID,
|
||||
"registered": compute.Registered,
|
||||
"res_name": compute.ResName,
|
||||
"rg_id": compute.RGID,
|
||||
"rg_name": compute.RGName,
|
||||
"snap_sets": flattenSnapSets(compute.SnapSets),
|
||||
"stateless_sep_id": compute.StatelessSepID,
|
||||
"stateless_sep_type": compute.StatelessSepType,
|
||||
"status": compute.Status,
|
||||
"tags": flattenTags(compute.Tags),
|
||||
"tech_status": compute.TechStatus,
|
||||
"total_disk_size": compute.TotalDiskSize,
|
||||
"updated_by": compute.UpdatedBy,
|
||||
"updated_time": compute.UpdatedTime,
|
||||
"user_managed": compute.UserManaged,
|
||||
"vgpus": compute.VGPUs,
|
||||
"vins_connected": compute.VINSConnected,
|
||||
"virtual_image_id": compute.VirtualImageID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenComputeDisksDemo(disksList ListComputeDisks, extraDisks []interface{}) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(disksList))
|
||||
for _, disk := range disksList {
|
||||
if disk.Name == "bootdisk" || findInExtraDisks(disk.ID, extraDisks) { //skip main bootdisk and extraDisks
|
||||
if disk.Name == "bootdisk" || findInExtraDisks(uint(disk.ID), extraDisks) { //skip main bootdisk and extraDisks
|
||||
continue
|
||||
}
|
||||
temp := map[string]interface{}{
|
||||
@@ -24,66 +202,139 @@ func flattenComputeDisksDemo(disksList []DiskRecord, extraDisks []interface{}) [
|
||||
"size_max": disk.SizeMax,
|
||||
"size_used": disk.SizeUsed,
|
||||
"pool": disk.Pool,
|
||||
"desc": disk.Desc,
|
||||
"desc": disk.Description,
|
||||
"image_id": disk.ImageID,
|
||||
"size": disk.SizeMax,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
sort.Slice(res, func(i, j int) bool {
|
||||
return res[i]["disk_id"].(uint64) < res[j]["disk_id"].(uint64)
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenNetwork(interfaces ListInterfaces) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(interfaces))
|
||||
//index := 0
|
||||
for _, network := range interfaces {
|
||||
temp := map[string]interface{}{
|
||||
"net_id": network.NetID,
|
||||
"net_type": network.NetType,
|
||||
"ip_address": network.IPAddress,
|
||||
"mac": network.MAC,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenCompute(d *schema.ResourceData, compFacts string) error {
|
||||
func findBootDisk(disks ListComputeDisks) *ItemComputeDisk {
|
||||
for _, disk := range disks {
|
||||
if disk.Name == "bootdisk" {
|
||||
return &disk
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenCompute(d *schema.ResourceData, compute RecordCompute) error {
|
||||
// This function expects that compFacts string contains response from API compute/get,
|
||||
// i.e. detailed information about compute instance.
|
||||
//
|
||||
// NOTE: this function modifies ResourceData argument - as such it should never be called
|
||||
// from resourceComputeExists(...) method
|
||||
model := ComputeGetResp{}
|
||||
log.Debugf("flattenCompute: ready to unmarshal string %s", compFacts)
|
||||
err := json.Unmarshal([]byte(compFacts), &model)
|
||||
log.Debugf("flattenCompute: ID %d, RG ID %d", compute.ID, compute.RGID)
|
||||
|
||||
devices, _ := json.Marshal(compute.Devices)
|
||||
userdata, _ := json.Marshal(compute.Userdata)
|
||||
|
||||
//check extraDisks, ipa_type, is,
|
||||
d.SetId(strconv.FormatUint(compute.ID, 10))
|
||||
d.Set("acl", flattenACL(compute.ACL))
|
||||
d.Set("account_id", compute.AccountID)
|
||||
d.Set("account_name", compute.AccountName)
|
||||
d.Set("affinity_weight", compute.AffinityWeight)
|
||||
d.Set("arch", compute.Architecture)
|
||||
d.Set("boot_order", compute.BootOrder)
|
||||
d.Set("boot_disk_size", compute.BootDiskSize)
|
||||
bootDisk := findBootDisk(compute.Disks)
|
||||
d.Set("boot_disk_id", bootDisk.ID)
|
||||
d.Set("sep_id", bootDisk.SepID)
|
||||
d.Set("pool", bootDisk.Pool)
|
||||
d.Set("clone_reference", compute.CloneReference)
|
||||
d.Set("clones", compute.Clones)
|
||||
if string(userdata) != "{}" {
|
||||
d.Set("cloud_init", string(userdata))
|
||||
}
|
||||
d.Set("computeci_id", compute.ComputeCIID)
|
||||
d.Set("created_by", compute.CreatedBy)
|
||||
d.Set("created_time", compute.CreatedTime)
|
||||
d.Set("custom_fields", flattenCustomFields(compute.CustomFields))
|
||||
d.Set("deleted_by", compute.DeletedBy)
|
||||
d.Set("deleted_time", compute.DeletedTime)
|
||||
d.Set("description", compute.Description)
|
||||
d.Set("devices", string(devices))
|
||||
err := d.Set("disks", flattenComputeDisksDemo(compute.Disks, d.Get("extra_disks").(*schema.Set).List()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debugf("flattenCompute: ID %d, RG ID %d", model.ID, model.RgID)
|
||||
|
||||
d.SetId(fmt.Sprintf("%d", model.ID))
|
||||
// d.Set("compute_id", model.ID) - we should NOT set compute_id in the schema here: if it was set - it is already set, if it wasn't - we shouldn't
|
||||
d.Set("name", model.Name)
|
||||
d.Set("rg_id", model.RgID)
|
||||
d.Set("rg_name", model.RgName)
|
||||
d.Set("account_id", model.AccountID)
|
||||
d.Set("account_name", model.AccountName)
|
||||
d.Set("driver", model.Driver)
|
||||
d.Set("cpu", model.Cpu)
|
||||
d.Set("ram", model.Ram)
|
||||
// d.Set("boot_disk_size", model.BootDiskSize) - bootdiskSize key in API compute/get is always zero, so we set boot_disk_size in another way
|
||||
if model.VirtualImageID != 0 {
|
||||
d.Set("image_id", model.VirtualImageID)
|
||||
d.Set("driver", compute.Driver)
|
||||
d.Set("cpu", compute.CPU)
|
||||
d.Set("gid", compute.GID)
|
||||
d.Set("guid", compute.GUID)
|
||||
d.Set("compute_id", compute.ID)
|
||||
if compute.VirtualImageID != 0 {
|
||||
d.Set("image_id", compute.VirtualImageID)
|
||||
} else {
|
||||
d.Set("image_id", model.ImageID)
|
||||
d.Set("image_id", compute.ImageID)
|
||||
}
|
||||
d.Set("description", model.Desc)
|
||||
d.Set("interfaces", flattenInterfaces(compute.Interfaces))
|
||||
d.Set("lock_status", compute.LockStatus)
|
||||
d.Set("manager_id", compute.ManagerID)
|
||||
d.Set("manager_type", compute.ManagerType)
|
||||
d.Set("migrationjob", compute.MigrationJob)
|
||||
d.Set("milestones", compute.Milestones)
|
||||
d.Set("name", compute.Name)
|
||||
d.Set("natable_vins_id", compute.NatableVINSID)
|
||||
d.Set("natable_vins_ip", compute.NatableVINSIP)
|
||||
d.Set("natable_vins_name", compute.NatableVINSName)
|
||||
d.Set("natable_vins_network", compute.NatableVINSNetwork)
|
||||
d.Set("natable_vins_network_name", compute.NatableVINSNetworkName)
|
||||
if err := d.Set("os_users", parseOsUsers(compute.OSUsers)); err != nil {
|
||||
return err
|
||||
}
|
||||
d.Set("pinned", compute.Pinned)
|
||||
d.Set("ram", compute.RAM)
|
||||
d.Set("reference_id", compute.ReferenceID)
|
||||
d.Set("registered", compute.Registered)
|
||||
d.Set("res_name", compute.ResName)
|
||||
d.Set("rg_id", compute.RGID)
|
||||
d.Set("rg_name", compute.RGName)
|
||||
d.Set("snap_sets", flattenSnapSets(compute.SnapSets))
|
||||
d.Set("stateless_sep_id", compute.StatelessSepID)
|
||||
d.Set("stateless_sep_type", compute.StatelessSepType)
|
||||
d.Set("status", compute.Status)
|
||||
d.Set("tags", flattenTags(compute.Tags))
|
||||
d.Set("tech_status", compute.TechStatus)
|
||||
d.Set("updated_by", compute.UpdatedBy)
|
||||
d.Set("updated_time", compute.UpdatedTime)
|
||||
d.Set("user_managed", compute.UserManaged)
|
||||
d.Set("vgpus", compute.VGPUs)
|
||||
d.Set("virtual_image_id", compute.VirtualImageID)
|
||||
d.Set("virtual_image_name", compute.VirtualImageName)
|
||||
|
||||
d.Set("enabled", false)
|
||||
if model.Status == status.Enabled {
|
||||
if compute.Status == status.Enabled {
|
||||
d.Set("enabled", true)
|
||||
}
|
||||
|
||||
//d.Set("cloud_init", "applied") // NOTE: for existing compute we hard-code this value as an indicator for DiffSuppress fucntion
|
||||
//d.Set("status", model.Status)
|
||||
//d.Set("tech_status", model.TechStatus)
|
||||
d.Set("started", false)
|
||||
if model.TechStatus == "STARTED" {
|
||||
if compute.TechStatus == "STARTED" {
|
||||
d.Set("started", true)
|
||||
}
|
||||
|
||||
bootDisk := findBootDisk(model.Disks)
|
||||
|
||||
d.Set("boot_disk_size", bootDisk.SizeMax)
|
||||
d.Set("boot_disk_id", bootDisk.ID) // we may need boot disk ID in resize operations
|
||||
d.Set("sep_id", bootDisk.SepID)
|
||||
d.Set("pool", bootDisk.Pool)
|
||||
d.Set("network", flattenNetwork(compute.Interfaces))
|
||||
|
||||
//if len(model.Disks) > 0 {
|
||||
//log.Debugf("flattenCompute: calling parseComputeDisksToExtraDisks for %d disks", len(model.Disks))
|
||||
@@ -92,24 +343,288 @@ func flattenCompute(d *schema.ResourceData, compFacts string) error {
|
||||
//}
|
||||
//}
|
||||
|
||||
if len(model.Interfaces) > 0 {
|
||||
log.Debugf("flattenCompute: calling parseComputeInterfacesToNetworks for %d interfaces", len(model.Interfaces))
|
||||
if err = d.Set("network", parseComputeInterfacesToNetworks(model.Interfaces)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if len(model.OsUsers) > 0 {
|
||||
log.Debugf("flattenCompute: calling parseOsUsers for %d logins", len(model.OsUsers))
|
||||
if err = d.Set("os_users", parseOsUsers(model.OsUsers)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
err = d.Set("disks", flattenComputeDisksDemo(model.Disks, d.Get("extra_disks").(*schema.Set).List()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenDataComputeDisksDemo(disksList ListComputeDisks, extraDisks []interface{}) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, disk := range disksList {
|
||||
if findInExtraDisks(uint(disk.ID), extraDisks) { //skip main bootdisk and extraDisks
|
||||
continue
|
||||
}
|
||||
temp := map[string]interface{}{
|
||||
"disk_name": disk.Name,
|
||||
"disk_id": disk.ID,
|
||||
"disk_type": disk.Type,
|
||||
"sep_id": disk.SepID,
|
||||
"shareable": disk.Shareable,
|
||||
"size_max": disk.SizeMax,
|
||||
"size_used": disk.SizeUsed,
|
||||
"pool": disk.Pool,
|
||||
"desc": disk.Description,
|
||||
"image_id": disk.ImageID,
|
||||
"size": disk.SizeMax,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenACL(acl RecordACL) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"account_acl": flattenListACL(acl.AccountACL),
|
||||
"compute_acl": flattenListACL(acl.ComputeACL),
|
||||
"rg_acl": flattenListACL(acl.RGACL),
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenAffinityRules(affinityRules ListRules) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, affinityRule := range affinityRules {
|
||||
temp := map[string]interface{}{
|
||||
"guid": affinityRule.GUID,
|
||||
"key": affinityRule.Key,
|
||||
"mode": affinityRule.Mode,
|
||||
"policy": affinityRule.Policy,
|
||||
"topology": affinityRule.Topology,
|
||||
"value": affinityRule.Value,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenIotune(iotune IOTune) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"read_bytes_sec": iotune.ReadBytesSec,
|
||||
"read_bytes_sec_max": iotune.ReadBytesSecMax,
|
||||
"read_iops_sec": iotune.ReadIOPSSec,
|
||||
"read_iops_sec_max": iotune.ReadIOPSSecMax,
|
||||
"size_iops_sec": iotune.SizeIOPSSec,
|
||||
"total_bytes_sec": iotune.TotalBytesSec,
|
||||
"total_bytes_sec_max": iotune.TotalBytesSecMax,
|
||||
"total_iops_sec": iotune.TotalIOPSSec,
|
||||
"total_iops_sec_max": iotune.TotalIOPSSecMax,
|
||||
"write_bytes_sec": iotune.WriteBytesSec,
|
||||
"write_bytes_sec_max": iotune.WriteBytesSecMax,
|
||||
"write_iops_sec": iotune.WriteIOPSSec,
|
||||
"write_iops_sec_max": iotune.WriteIOPSSecMax,
|
||||
}
|
||||
res = append(res, temp)
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenSnapshots(snapshots SnapshotExtendList) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, snapshot := range snapshots {
|
||||
temp := map[string]interface{}{
|
||||
"guid": snapshot.GUID,
|
||||
"label": snapshot.Label,
|
||||
"res_id": snapshot.ResID,
|
||||
"snap_set_guid": snapshot.SnapSetGUID,
|
||||
"snap_set_time": snapshot.SnapSetTime,
|
||||
"timestamp": snapshot.TimeStamp,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenListComputeDisks(disks ListComputeDisks) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, disk := range disks {
|
||||
acl, _ := json.Marshal(disk.ACL)
|
||||
temp := map[string]interface{}{
|
||||
"_ckey": disk.CKey,
|
||||
"acl": string(acl),
|
||||
"account_id": disk.AccountID,
|
||||
"boot_partition": disk.BootPartition,
|
||||
"created_time": disk.CreatedTime,
|
||||
"deleted_time": disk.DeletedTime,
|
||||
"description": disk.Description,
|
||||
"destruction_time": disk.DestructionTime,
|
||||
"disk_path": disk.DiskPath,
|
||||
"gid": disk.GID,
|
||||
"guid": disk.GUID,
|
||||
"disk_id": disk.ID,
|
||||
"image_id": disk.ImageID,
|
||||
"images": disk.Images,
|
||||
"iotune": flattenIotune(disk.IOTune),
|
||||
"iqn": disk.IQN,
|
||||
"login": disk.Login,
|
||||
"milestones": disk.Milestones,
|
||||
"name": disk.Name,
|
||||
"order": disk.Order,
|
||||
"params": disk.Params,
|
||||
"parent_id": disk.ParentID,
|
||||
"passwd": disk.Passwd,
|
||||
"pci_slot": disk.PCISlot,
|
||||
"pool": disk.Pool,
|
||||
"present_to": disk.PresentTo,
|
||||
"purge_time": disk.PurgeTime,
|
||||
"reality_device_number": disk.RealityDeviceNumber,
|
||||
"res_id": disk.ResID,
|
||||
"role": disk.Role,
|
||||
"sep_id": disk.SepID,
|
||||
"shareable": disk.Shareable,
|
||||
"size_max": disk.SizeMax,
|
||||
"size_used": disk.SizeUsed,
|
||||
"snapshots": flattenSnapshots(disk.Snapshots),
|
||||
"status": disk.Status,
|
||||
"tech_status": disk.TechStatus,
|
||||
"type": disk.Type,
|
||||
"vmid": disk.VMID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenCustomFields(customFileds map[string]interface{}) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for key, val := range customFileds {
|
||||
value, _ := json.Marshal(val)
|
||||
temp := map[string]interface{}{
|
||||
"key": key,
|
||||
"val": string(value),
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
func flattenOsUsers(osUsers ListOSUser) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, user := range osUsers {
|
||||
temp := map[string]interface{}{
|
||||
"guid": user.GUID,
|
||||
"login": user.Login,
|
||||
"password": user.Password,
|
||||
"public_key": user.PubKey,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenDataCompute(d *schema.ResourceData, compute RecordCompute) {
|
||||
devices, _ := json.Marshal(compute.Devices)
|
||||
userdata, _ := json.Marshal(compute.Userdata)
|
||||
d.Set("acl", flattenACL(compute.ACL))
|
||||
d.Set("account_id", compute.AccountID)
|
||||
d.Set("account_name", compute.AccountName)
|
||||
d.Set("affinity_label", compute.AffinityLabel)
|
||||
d.Set("affinity_rules", flattenAffinityRules(compute.AffinityRules))
|
||||
d.Set("affinity_weight", compute.AffinityWeight)
|
||||
d.Set("anti_affinity_rules", flattenListRules(compute.AntiAffinityRules))
|
||||
d.Set("arch", compute.Architecture)
|
||||
d.Set("boot_order", compute.BootOrder)
|
||||
d.Set("bootdisk_size", compute.BootDiskSize)
|
||||
d.Set("clone_reference", compute.CloneReference)
|
||||
d.Set("clones", compute.Clones)
|
||||
d.Set("computeci_id", compute.ComputeCIID)
|
||||
d.Set("cpus", compute.CPU)
|
||||
d.Set("created_by", compute.CreatedBy)
|
||||
d.Set("created_time", compute.CreatedTime)
|
||||
d.Set("custom_fields", flattenCustomFields(compute.CustomFields))
|
||||
d.Set("deleted_by", compute.DeletedBy)
|
||||
d.Set("deleted_time", compute.DeletedTime)
|
||||
d.Set("desc", compute.Description)
|
||||
d.Set("devices", string(devices))
|
||||
d.Set("disks", flattenListComputeDisks(compute.Disks))
|
||||
d.Set("driver", compute.Driver)
|
||||
d.Set("gid", compute.GID)
|
||||
d.Set("guid", compute.GUID)
|
||||
d.Set("compute_id", compute.ID)
|
||||
d.Set("image_id", compute.ImageID)
|
||||
d.Set("interfaces", flattenInterfaces(compute.Interfaces))
|
||||
d.Set("lock_status", compute.LockStatus)
|
||||
d.Set("manager_id", compute.ManagerID)
|
||||
d.Set("manager_type", compute.ManagerType)
|
||||
d.Set("migrationjob", compute.MigrationJob)
|
||||
d.Set("milestones", compute.Milestones)
|
||||
d.Set("name", compute.Name)
|
||||
d.Set("natable_vins_id", compute.NatableVINSID)
|
||||
d.Set("natable_vins_ip", compute.NatableVINSIP)
|
||||
d.Set("natable_vins_name", compute.NatableVINSName)
|
||||
d.Set("natable_vins_network", compute.NatableVINSNetwork)
|
||||
d.Set("natable_vins_network_name", compute.NatableVINSNetworkName)
|
||||
d.Set("os_users", flattenOsUsers(compute.OSUsers))
|
||||
d.Set("pinned", compute.Pinned)
|
||||
d.Set("ram", compute.RAM)
|
||||
d.Set("reference_id", compute.ReferenceID)
|
||||
d.Set("registered", compute.Registered)
|
||||
d.Set("res_name", compute.ResName)
|
||||
d.Set("rg_id", compute.RGID)
|
||||
d.Set("rg_name", compute.RGName)
|
||||
d.Set("snap_sets", flattenSnapSets(compute.SnapSets))
|
||||
d.Set("stateless_sep_id", compute.StatelessSepID)
|
||||
d.Set("stateless_sep_type", compute.StatelessSepType)
|
||||
d.Set("status", compute.Status)
|
||||
d.Set("tags", compute.Tags)
|
||||
d.Set("tech_status", compute.TechStatus)
|
||||
d.Set("updated_by", compute.UpdatedBy)
|
||||
d.Set("updated_time", compute.UpdatedTime)
|
||||
d.Set("user_managed", compute.UserManaged)
|
||||
d.Set("userdata", string(userdata))
|
||||
d.Set("vgpus", compute.VGPUs)
|
||||
d.Set("virtual_image_id", compute.VirtualImageID)
|
||||
d.Set("virtual_image_name", compute.VirtualImageName)
|
||||
}
|
||||
|
||||
func flattenComputeAudits(computeAudits ListAudits) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, computeAudit := range computeAudits {
|
||||
temp := map[string]interface{}{
|
||||
"call": computeAudit.Call,
|
||||
"responsetime": computeAudit.ResponseTime,
|
||||
"statuscode": computeAudit.StatusCode,
|
||||
"timestamp": computeAudit.Timestamp,
|
||||
"user": computeAudit.User,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenPfwList(computePfws ListPFWs) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, computePfw := range computePfws {
|
||||
temp := map[string]interface{}{
|
||||
"pfw_id": computePfw.ID,
|
||||
"local_ip": computePfw.LocalIP,
|
||||
"local_port": computePfw.LocalPort,
|
||||
"protocol": computePfw.Protocol,
|
||||
"public_port_end": computePfw.PublicPortEnd,
|
||||
"public_port_start": computePfw.PublicPortStart,
|
||||
"vm_id": computePfw.VMID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenUserList(d *schema.ResourceData, userList RecordACL) {
|
||||
d.Set("account_acl", flattenListACL(userList.AccountACL))
|
||||
d.Set("compute_acl", flattenListACL(userList.ComputeACL))
|
||||
d.Set("rg_acl", flattenListACL(userList.RGACL))
|
||||
}
|
||||
|
||||
func flattenComputeGetAudits(computeAudits ListShortAudits) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, computeAudit := range computeAudits {
|
||||
temp := map[string]interface{}{
|
||||
"epoch": computeAudit.Epoch,
|
||||
"message": computeAudit.Message,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ type SnapshotRecord struct {
|
||||
TimeStamp uint64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
type SnapshotRecordList []SnapshotRecord
|
||||
//type SnapshotRecordList []SnapshotRecord
|
||||
|
||||
type ComputeGetResp struct {
|
||||
// ACLs `json:"ACL"` - it is a dictionary, special parsing required
|
||||
@@ -190,3 +190,888 @@ type ComputeBriefRecord struct { // this is a brief compute specifiaction as ret
|
||||
}
|
||||
|
||||
type RgListComputesResp []ComputeBriefRecord
|
||||
|
||||
//#############
|
||||
|
||||
// Access Control List
|
||||
type RecordACL struct {
|
||||
// Account ACL list
|
||||
AccountACL ListACL `json:"accountAcl"`
|
||||
|
||||
// Compute ACL list
|
||||
ComputeACL ListACL `json:"computeAcl"`
|
||||
|
||||
// Resource group ACL list
|
||||
RGACL ListACL `json:"rgAcl"`
|
||||
}
|
||||
|
||||
// ACL information
|
||||
type ItemACL struct {
|
||||
// Explicit
|
||||
Explicit interface{} `json:"explicit"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Right
|
||||
Right string `json:"right"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Type
|
||||
Type string `json:"type"`
|
||||
|
||||
// User group ID
|
||||
UserGroupID string `json:"userGroupId"`
|
||||
}
|
||||
|
||||
// List ACL
|
||||
type ListACL []ItemACL
|
||||
|
||||
// Main information about usage snapshot
|
||||
type ItemUsageSnapshot struct {
|
||||
// Count
|
||||
Count uint64 `json:"count,omitempty"`
|
||||
|
||||
// Stored
|
||||
Stored float64 `json:"stored"`
|
||||
|
||||
// Label
|
||||
Label string `json:"label,omitempty"`
|
||||
|
||||
// Timestamp
|
||||
Timestamp uint64 `json:"timestamp,omitempty"`
|
||||
}
|
||||
|
||||
// List of usage snapshot
|
||||
type ListUsageSnapshots []ItemUsageSnapshot
|
||||
|
||||
// Main information about snapshot
|
||||
type ItemSnapshot struct {
|
||||
// List disk ID
|
||||
Disks []uint64 `json:"disks"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Label
|
||||
Label string `json:"label"`
|
||||
|
||||
// Timestamp
|
||||
Timestamp uint64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
// List of snapshots
|
||||
type ListSnapShots []ItemSnapshot
|
||||
|
||||
// Main information about port forward
|
||||
type ItemPFW struct {
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Local IP
|
||||
LocalIP string `json:"localIp"`
|
||||
|
||||
// Local port
|
||||
LocalPort uint64 `json:"localPort"`
|
||||
|
||||
// Protocol
|
||||
Protocol string `json:"protocol"`
|
||||
|
||||
// Public port end
|
||||
PublicPortEnd uint64 `json:"publicPortEnd"`
|
||||
|
||||
// Public port start
|
||||
PublicPortStart uint64 `json:"publicPortStart"`
|
||||
|
||||
// Virtuel machine ID
|
||||
VMID uint64 `json:"vmId"`
|
||||
}
|
||||
|
||||
// List port forwards
|
||||
type ListPFWs []ItemPFW
|
||||
|
||||
// Main information about affinity relations
|
||||
type RecordAffinityRelations struct {
|
||||
// Other node
|
||||
OtherNode []interface{} `json:"otherNode"`
|
||||
|
||||
// Other node indirect
|
||||
OtherNodeIndirect []interface{} `json:"otherNodeIndirect"`
|
||||
|
||||
// Other node indirect soft
|
||||
OtherNodeIndirectSoft []interface{} `json:"otherNodeIndirectSoft"`
|
||||
|
||||
// Other node soft
|
||||
OtherNodeSoft []interface{} `json:"otherNodeSoft"`
|
||||
|
||||
// Same node
|
||||
SameNode []interface{} `json:"sameNode"`
|
||||
|
||||
// Same node soft
|
||||
SameNodeSoft []interface{} `json:"sameNodeSoft"`
|
||||
}
|
||||
|
||||
// Main information about attached network
|
||||
type RecordNetAttach struct {
|
||||
// Connection ID
|
||||
ConnID uint64 `json:"connId"`
|
||||
|
||||
// Connection type
|
||||
ConnType string `json:"connType"`
|
||||
|
||||
// Default GW
|
||||
DefGW string `json:"defGw"`
|
||||
|
||||
// FLIPGroup ID
|
||||
FLIPGroupID uint64 `json:"flipgroupId"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// IP address
|
||||
IPAddress string `json:"ipAddress"`
|
||||
|
||||
// Listen SSH
|
||||
ListenSSH bool `json:"listenSsh"`
|
||||
|
||||
// MAC
|
||||
MAC string `json:"mac"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Network ID
|
||||
NetID uint64 `json:"netId"`
|
||||
|
||||
// Network mask
|
||||
NetMask uint64 `json:"netMask"`
|
||||
|
||||
// Network type
|
||||
NetType string `json:"netType"`
|
||||
|
||||
// PCI slot
|
||||
PCISlot uint64 `json:"pciSlot"`
|
||||
|
||||
// QOS
|
||||
QOS QOS `json:"qos"`
|
||||
|
||||
// Target
|
||||
Target string `json:"target"`
|
||||
|
||||
// Type
|
||||
Type string `json:"type"`
|
||||
|
||||
// List VNF IDs
|
||||
VNFs []uint64 `json:"vnfs"`
|
||||
}
|
||||
|
||||
// Detailed information about audit
|
||||
type ItemAudit struct {
|
||||
// Call
|
||||
Call string `json:"call"`
|
||||
|
||||
// Response time
|
||||
ResponseTime float64 `json:"responsetime"`
|
||||
|
||||
// Status code
|
||||
StatusCode uint64 `json:"statuscode"`
|
||||
|
||||
// Timestamp
|
||||
Timestamp float64 `json:"timestamp"`
|
||||
|
||||
// User
|
||||
User string `json:"user"`
|
||||
}
|
||||
|
||||
// List Detailed audits
|
||||
type ListAudits []ItemAudit
|
||||
|
||||
// Short information about audit
|
||||
type ItemShortAudit struct {
|
||||
// Epoch
|
||||
Epoch float64 `json:"epoch"`
|
||||
|
||||
// Message
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// List short audits
|
||||
type ListShortAudits []ItemShortAudit
|
||||
|
||||
// Main information about rule
|
||||
type ItemRule struct {
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Key
|
||||
Key string `json:"key"`
|
||||
|
||||
// Mode
|
||||
Mode string `json:"mode"`
|
||||
|
||||
// Policy
|
||||
Policy string `json:"policy"`
|
||||
|
||||
// Topology
|
||||
Topology string `json:"topology"`
|
||||
|
||||
// Value
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
// List rules
|
||||
type ListRules []ItemRule
|
||||
|
||||
// Detailed information about compute
|
||||
type RecordCompute struct {
|
||||
// Access Control List
|
||||
ACL RecordACL `json:"ACL"`
|
||||
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
// Account name
|
||||
AccountName string `json:"accountName"`
|
||||
|
||||
// Affinity label
|
||||
AffinityLabel string `json:"affinityLabel"`
|
||||
|
||||
// List affinity rules
|
||||
AffinityRules ListRules `json:"affinityRules"`
|
||||
|
||||
// Affinity weight
|
||||
AffinityWeight uint64 `json:"affinityWeight"`
|
||||
|
||||
// List anti affinity rules
|
||||
AntiAffinityRules ListRules `json:"antiAffinityRules"`
|
||||
|
||||
// Architecture
|
||||
Architecture string `json:"arch"`
|
||||
|
||||
// Boot order
|
||||
BootOrder []string `json:"bootOrder"`
|
||||
|
||||
// Boot disk size
|
||||
BootDiskSize uint64 `json:"bootdiskSize"`
|
||||
|
||||
// Clone reference
|
||||
CloneReference uint64 `json:"cloneReference"`
|
||||
|
||||
// List clone IDs
|
||||
Clones []uint64 `json:"clones"`
|
||||
|
||||
// Compute CI ID
|
||||
ComputeCIID uint64 `json:"computeciId"`
|
||||
|
||||
// Number of cores
|
||||
CPU uint64 `json:"cpus"`
|
||||
|
||||
// Created by
|
||||
CreatedBy string `json:"createdBy"`
|
||||
|
||||
// Created time
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
// Custom fields items
|
||||
CustomFields map[string]interface{} `json:"customFields"`
|
||||
|
||||
// Deleted by
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
|
||||
// Deleted time
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
|
||||
// Description
|
||||
Description string `json:"desc"`
|
||||
|
||||
// Devices
|
||||
Devices interface{} `json:"devices"`
|
||||
|
||||
// List disks in compute
|
||||
Disks ListComputeDisks `json:"disks"`
|
||||
|
||||
// Driver
|
||||
Driver string `json:"driver"`
|
||||
|
||||
// Grid ID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Image ID
|
||||
ImageID uint64 `json:"imageId"`
|
||||
|
||||
// Image name
|
||||
ImageName string `json:"imageName"`
|
||||
|
||||
// List interfaces
|
||||
Interfaces ListInterfaces `json:"interfaces"`
|
||||
|
||||
// Lock status
|
||||
LockStatus string `json:"lockStatus"`
|
||||
|
||||
// Manager ID
|
||||
ManagerID uint64 `json:"managerId"`
|
||||
|
||||
// Manager type
|
||||
ManagerType string `json:"managerType"`
|
||||
|
||||
// Migration job
|
||||
MigrationJob uint64 `json:"migrationjob"`
|
||||
|
||||
// Milestones
|
||||
Milestones uint64 `json:"milestones"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Natable VINS ID
|
||||
NatableVINSID uint64 `json:"natableVinsId"`
|
||||
|
||||
// Natable VINS IP
|
||||
NatableVINSIP string `json:"natableVinsIp"`
|
||||
|
||||
// Natable VINS Name
|
||||
NatableVINSName string `json:"natableVinsName"`
|
||||
|
||||
// Natable VINS network
|
||||
NatableVINSNetwork string `json:"natableVinsNetwork"`
|
||||
|
||||
// Natable VINS network name
|
||||
NatableVINSNetworkName string `json:"natableVinsNetworkName"`
|
||||
|
||||
// List OS Users
|
||||
OSUsers ListOSUser `json:"osUsers"`
|
||||
|
||||
// Pinned or not
|
||||
Pinned bool `json:"pinned"`
|
||||
|
||||
// Number of RAM
|
||||
RAM uint64 `json:"ram"`
|
||||
|
||||
// Reference ID
|
||||
ReferenceID string `json:"referenceId"`
|
||||
|
||||
// Registered or not
|
||||
Registered bool `json:"registered"`
|
||||
|
||||
// Resource name
|
||||
ResName string `json:"resName"`
|
||||
|
||||
// Resource group ID
|
||||
RGID uint64 `json:"rgId"`
|
||||
|
||||
// Resource group name
|
||||
RGName string `json:"rgName"`
|
||||
|
||||
// List snapsets
|
||||
SnapSets ListSnapSets `json:"snapSets"`
|
||||
|
||||
// Stateless SepID
|
||||
StatelessSepID uint64 `json:"statelessSepId"`
|
||||
|
||||
// Stateless SepType
|
||||
StatelessSepType string `json:"statelessSepType"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Tags
|
||||
Tags map[string]string `json:"tags"`
|
||||
|
||||
// Tech status
|
||||
TechStatus string `json:"techStatus"`
|
||||
|
||||
// Updated by
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
|
||||
// User Managed or not
|
||||
UserManaged bool `json:"userManaged"`
|
||||
|
||||
// Userdata
|
||||
Userdata interface{} `json:"userdata"`
|
||||
|
||||
// vGPU IDs
|
||||
VGPUs []uint64 `json:"vgpus"`
|
||||
|
||||
// Virtual image ID
|
||||
VirtualImageID uint64 `json:"virtualImageId"`
|
||||
|
||||
// Virtual image name
|
||||
VirtualImageName string `json:"virtualImageName"`
|
||||
}
|
||||
|
||||
// Main information about OS user
|
||||
type ItemOSUser struct {
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Login
|
||||
Login string `json:"login"`
|
||||
|
||||
// Password
|
||||
Password string `json:"password"`
|
||||
|
||||
// Public key
|
||||
PubKey string `json:"pubkey"`
|
||||
}
|
||||
|
||||
// List OS users
|
||||
type ListOSUser []ItemOSUser
|
||||
|
||||
// Main information about snapsets
|
||||
type ItemSnapSet struct {
|
||||
// List disk IDs
|
||||
Disks []uint64 `json:"disks"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Label
|
||||
Label string `json:"label"`
|
||||
|
||||
// Timestamp
|
||||
Timestamp uint64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
// List snapsets
|
||||
type ListSnapSets []ItemSnapSet
|
||||
|
||||
// Main information about VNF
|
||||
type ItemVNFInterface struct {
|
||||
// Connection ID
|
||||
ConnID uint64 `json:"connId"`
|
||||
|
||||
// Connection type
|
||||
ConnType string `json:"connType"`
|
||||
|
||||
// Default GW
|
||||
DefGW string `json:"defGw"`
|
||||
|
||||
// FLIPGroup ID
|
||||
FLIPGroupID uint64 `json:"flipgroupId"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// IP address
|
||||
IPAddress string `json:"ipAddress"`
|
||||
|
||||
// Listen SSH or not
|
||||
ListenSSH bool `json:"listenSsh"`
|
||||
|
||||
// MAC
|
||||
MAC string `json:"mac"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Network ID
|
||||
NetID uint64 `json:"netId"`
|
||||
|
||||
// Network mask
|
||||
NetMask uint64 `json:"netMask"`
|
||||
|
||||
// Network type
|
||||
NetType string `json:"netType"`
|
||||
|
||||
// PCI slot
|
||||
PCISlot uint64 `json:"pciSlot"`
|
||||
|
||||
// QOS
|
||||
QOS QOS `json:"qos"`
|
||||
|
||||
// Target
|
||||
Target string `json:"target"`
|
||||
|
||||
// Type
|
||||
Type string `json:"type"`
|
||||
|
||||
// List VNF IDs
|
||||
VNFs []uint64 `json:"vnfs"`
|
||||
}
|
||||
|
||||
type QOS struct {
|
||||
ERate uint64 `json:"eRate"`
|
||||
GUID string `json:"guid"`
|
||||
InBurst uint64 `json:"inBurst"`
|
||||
InRate uint64 `json:"inRate"`
|
||||
}
|
||||
|
||||
// List VNF interfaces
|
||||
type ListInterfaces []ItemVNFInterface
|
||||
|
||||
// List compute disks
|
||||
type ListComputeDisks []ItemComputeDisk
|
||||
|
||||
// Main information about compute disk
|
||||
type ItemComputeDisk struct {
|
||||
// CKey
|
||||
CKey string `json:"_ckey"`
|
||||
|
||||
// Access Control List
|
||||
ACL map[string]interface{} `json:"acl"`
|
||||
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
// Boot partition
|
||||
BootPartition uint64 `json:"bootPartition"`
|
||||
|
||||
// Created time
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
// Deleted time
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
|
||||
// Description
|
||||
Description string `json:"desc"`
|
||||
|
||||
// Destruction time
|
||||
DestructionTime uint64 `json:"destructionTime"`
|
||||
|
||||
// Disk path
|
||||
DiskPath string `json:"diskPath"`
|
||||
|
||||
// Grid ID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Image ID
|
||||
ImageID uint64 `json:"imageId"`
|
||||
|
||||
// List image IDs
|
||||
Images []uint64 `json:"images"`
|
||||
|
||||
// IO tune
|
||||
IOTune IOTune `json:"iotune"`
|
||||
|
||||
// IQN
|
||||
IQN string `json:"iqn"`
|
||||
|
||||
// Login
|
||||
Login string `json:"login"`
|
||||
|
||||
// Milestones
|
||||
Milestones uint64 `json:"milestones"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Order
|
||||
Order uint64 `json:"order"`
|
||||
|
||||
// Params
|
||||
Params string `json:"params"`
|
||||
|
||||
// Parent ID
|
||||
ParentID uint64 `json:"parentId"`
|
||||
|
||||
// Password
|
||||
Passwd string `json:"passwd"`
|
||||
|
||||
// PCI slot
|
||||
PCISlot uint64 `json:"pciSlot"`
|
||||
|
||||
// Pool
|
||||
Pool string `json:"pool"`
|
||||
|
||||
// Present to
|
||||
PresentTo []uint64 `json:"presentTo"`
|
||||
|
||||
// Purge time
|
||||
PurgeTime uint64 `json:"purgeTime"`
|
||||
|
||||
// Reality device number
|
||||
RealityDeviceNumber uint64 `json:"realityDeviceNumber"`
|
||||
|
||||
// Resource ID
|
||||
ResID string `json:"resId"`
|
||||
|
||||
// Role
|
||||
Role string `json:"role"`
|
||||
|
||||
// SepID
|
||||
SepID uint64 `json:"sepId"`
|
||||
|
||||
// Shareable
|
||||
Shareable bool `json:"shareable"`
|
||||
|
||||
// Size max
|
||||
SizeMax uint64 `json:"sizeMax"`
|
||||
|
||||
//Size used
|
||||
SizeUsed float64 `json:"sizeUsed"`
|
||||
|
||||
// List extend snapshots
|
||||
Snapshots SnapshotExtendList `json:"snapshots"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Tech status
|
||||
TechStatus string `json:"techStatus"`
|
||||
|
||||
// Type
|
||||
Type string `json:"type"`
|
||||
|
||||
// Virtual machine ID
|
||||
VMID uint64 `json:"vmid"`
|
||||
}
|
||||
|
||||
// Main information about snapshot extend
|
||||
type SnapshotExtend struct {
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Label
|
||||
Label string `json:"label"`
|
||||
|
||||
// Resource ID
|
||||
ResID string `json:"resId"`
|
||||
|
||||
// SnapSetGUID
|
||||
SnapSetGUID string `json:"snapSetGuid"`
|
||||
|
||||
// SnapSetTime
|
||||
SnapSetTime uint64 `json:"snapSetTime"`
|
||||
|
||||
// TimeStamp
|
||||
TimeStamp uint64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
// List Snapshot Extend
|
||||
type SnapshotExtendList []SnapshotExtend
|
||||
|
||||
// Main information about IO tune
|
||||
type IOTune struct {
|
||||
// ReadBytesSec
|
||||
ReadBytesSec uint64 `json:"read_bytes_sec"`
|
||||
|
||||
// ReadBytesSecMax
|
||||
ReadBytesSecMax uint64 `json:"read_bytes_sec_max"`
|
||||
|
||||
// ReadIOPSSec
|
||||
ReadIOPSSec uint64 `json:"read_iops_sec"`
|
||||
|
||||
// ReadIOPSSecMax
|
||||
ReadIOPSSecMax uint64 `json:"read_iops_sec_max"`
|
||||
|
||||
// SizeIOPSSec
|
||||
SizeIOPSSec uint64 `json:"size_iops_sec"`
|
||||
|
||||
// TotalBytesSec
|
||||
TotalBytesSec uint64 `json:"total_bytes_sec"`
|
||||
|
||||
// TotalBytesSecMax
|
||||
TotalBytesSecMax uint64 `json:"total_bytes_sec_max"`
|
||||
|
||||
// TotalIOPSSec
|
||||
TotalIOPSSec uint64 `json:"total_iops_sec"`
|
||||
|
||||
// TotalIOPSSecMax
|
||||
TotalIOPSSecMax uint64 `json:"total_iops_sec_max"`
|
||||
|
||||
// WriteBytesSec
|
||||
WriteBytesSec uint64 `json:"write_bytes_sec"`
|
||||
|
||||
// WriteBytesSecMax
|
||||
WriteBytesSecMax uint64 `json:"write_bytes_sec_max"`
|
||||
|
||||
// WriteIOPSSec
|
||||
WriteIOPSSec uint64 `json:"write_iops_sec"`
|
||||
|
||||
// WriteIOPSSecMax
|
||||
WriteIOPSSecMax uint64 `json:"write_iops_sec_max"`
|
||||
}
|
||||
|
||||
// Main information about compute
|
||||
type ItemCompute struct {
|
||||
// Access Control List
|
||||
ACL ListACL `json:"acl"`
|
||||
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
// Account name
|
||||
AccountName string `json:"accountName"`
|
||||
|
||||
// Affinity label
|
||||
AffinityLabel string `json:"affinityLabel"`
|
||||
|
||||
// List affinity rules
|
||||
AffinityRules ListRules `json:"affinityRules"`
|
||||
|
||||
// Affinity weight
|
||||
AffinityWeight uint64 `json:"affinityWeight"`
|
||||
|
||||
// List anti affinity rules
|
||||
AntiAffinityRules ListRules `json:"antiAffinityRules"`
|
||||
|
||||
// Architecture
|
||||
Architecture string `json:"arch"`
|
||||
|
||||
// Boot order
|
||||
BootOrder []string `json:"bootOrder"`
|
||||
|
||||
// Boot disk size
|
||||
BootDiskSize uint64 `json:"bootdiskSize"`
|
||||
|
||||
// Clone reference
|
||||
CloneReference uint64 `json:"cloneReference"`
|
||||
|
||||
// List clone IDs
|
||||
Clones []uint64 `json:"clones"`
|
||||
|
||||
// Compute CI ID
|
||||
ComputeCIID uint64 `json:"computeciId"`
|
||||
|
||||
// Number of cores
|
||||
CPU uint64 `json:"cpus"`
|
||||
|
||||
// Created by
|
||||
CreatedBy string `json:"createdBy"`
|
||||
|
||||
// Created time
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
// Custom fields list
|
||||
CustomFields map[string]interface{} `json:"customFields"`
|
||||
|
||||
// Deleted by
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
|
||||
// Deleted time
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
|
||||
// Description
|
||||
Description string `json:"desc"`
|
||||
|
||||
// Devices
|
||||
Devices interface{} `json:"devices"`
|
||||
|
||||
// List disk items
|
||||
Disks []InfoDisk `json:"disks"`
|
||||
|
||||
// Driver
|
||||
Driver string `json:"driver"`
|
||||
|
||||
// Grid ID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Image ID
|
||||
ImageID uint64 `json:"imageId"`
|
||||
|
||||
// List interfaces
|
||||
Interfaces ListInterfaces `json:"interfaces"`
|
||||
|
||||
// Lock status
|
||||
LockStatus string `json:"lockStatus"`
|
||||
|
||||
// Manager ID
|
||||
ManagerID uint64 `json:"managerId"`
|
||||
|
||||
// Manager type
|
||||
ManagerType string `json:"managerType"`
|
||||
|
||||
// Migration job
|
||||
MigrationJob uint64 `json:"migrationjob"`
|
||||
|
||||
// Milestones
|
||||
Milestones uint64 `json:"milestones"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Pinned or not
|
||||
Pinned bool `json:"pinned"`
|
||||
|
||||
// Number of RAM
|
||||
RAM uint64 `json:"ram"`
|
||||
|
||||
// Reference ID
|
||||
ReferenceID string `json:"referenceId"`
|
||||
|
||||
// Registered
|
||||
Registered bool `json:"registered"`
|
||||
|
||||
// Resource name
|
||||
ResName string `json:"resName"`
|
||||
|
||||
// Resource group ID
|
||||
RGID uint64 `json:"rgId"`
|
||||
|
||||
// Resource group name
|
||||
RGName string `json:"rgName"`
|
||||
|
||||
// List snapsets
|
||||
SnapSets ListSnapSets `json:"snapSets"`
|
||||
|
||||
// Stateless SepID
|
||||
StatelessSepID uint64 `json:"statelessSepId"`
|
||||
|
||||
// Stateless SepType
|
||||
StatelessSepType string `json:"statelessSepType"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Tags
|
||||
Tags map[string]string `json:"tags"`
|
||||
|
||||
// Tech status
|
||||
TechStatus string `json:"techStatus"`
|
||||
|
||||
// Total disk size
|
||||
TotalDiskSize uint64 `json:"totalDisksSize"`
|
||||
|
||||
// Updated by
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
|
||||
// User Managed or not
|
||||
UserManaged bool `json:"userManaged"`
|
||||
|
||||
// List vGPU IDs
|
||||
VGPUs []uint64 `json:"vgpus"`
|
||||
|
||||
// VINS connected
|
||||
VINSConnected uint64 `json:"vinsConnected"`
|
||||
|
||||
// Virtual image ID
|
||||
VirtualImageID uint64 `json:"virtualImageId"`
|
||||
}
|
||||
|
||||
// Information Disk
|
||||
type InfoDisk struct {
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// PCISlot
|
||||
PCISlot uint64 `json:"pciSlot"`
|
||||
}
|
||||
|
||||
// List information about computes
|
||||
type ListComputes []ItemCompute
|
||||
|
||||
@@ -38,13 +38,13 @@ import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func parseOsUsers(logins []OsUserRecord) []interface{} {
|
||||
func parseOsUsers(logins ListOSUser) []interface{} {
|
||||
var result = make([]interface{}, len(logins))
|
||||
|
||||
for index, value := range logins {
|
||||
elem := make(map[string]interface{})
|
||||
|
||||
elem["guid"] = value.Guid
|
||||
elem["guid"] = value.GUID
|
||||
elem["login"] = value.Login
|
||||
elem["password"] = value.Password
|
||||
elem["public_key"] = value.PubKey
|
||||
@@ -70,9 +70,9 @@ func osUsersSubresourceSchemaMake() map[string]*schema.Schema {
|
||||
},
|
||||
|
||||
"password": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Sensitive: true,
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
//Sensitive: true,
|
||||
Description: "Password of this guest OS user.",
|
||||
},
|
||||
|
||||
|
||||
106
internal/service/cloudapi/kvmvm/resource_check_input_values.go
Normal file
106
internal/service/cloudapi/kvmvm/resource_check_input_values.go
Normal file
@@ -0,0 +1,106 @@
|
||||
package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func existRgID(ctx context.Context, d *schema.ResourceData, m interface{}) bool {
|
||||
log.Debugf("resourceComputeCreate: check access for RG ID: %v", d.Get("rg_id").(int))
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
rgList := []struct {
|
||||
ID int `json:"id"`
|
||||
}{}
|
||||
|
||||
rgListAPI := "/restmachine/cloudapi/rg/list"
|
||||
urlValues.Add("includedeleted", "false")
|
||||
rgListRaw, err := c.DecortAPICall(ctx, "POST", rgListAPI, urlValues)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
err = json.Unmarshal([]byte(rgListRaw), &rgList)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
rgId := d.Get("rg_id").(int)
|
||||
for _, rg := range rgList {
|
||||
if rg.ID == rgId {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func existImageId(ctx context.Context, d *schema.ResourceData, m interface{}) bool {
|
||||
log.Debugf("resourceComputeCreate: check access for image ID: %v", d.Get("image_id").(int))
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
imageList := []struct {
|
||||
ID int `json:"id"`
|
||||
}{}
|
||||
imageListAPI := "/restmachine/cloudapi/image/list"
|
||||
imageListRaw, err := c.DecortAPICall(ctx, "POST", imageListAPI, urlValues)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
err = json.Unmarshal([]byte(imageListRaw), &imageList)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
imageId := d.Get("image_id").(int)
|
||||
for _, image := range imageList {
|
||||
if image.ID == imageId {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func existVinsIdInList(vinsId int, vinsList []struct {
|
||||
ID int `json:"id"`
|
||||
}) bool {
|
||||
for _, vins := range vinsList {
|
||||
if vinsId == vins.ID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func existVinsId(ctx context.Context, d *schema.ResourceData, m interface{}) (int, bool) {
|
||||
log.Debugf("resourceComputeCreate: check access for vinses IDs")
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
vinsListAPI := "/restmachine/cloudapi/vins/list"
|
||||
urlValues.Add("includeDeleted", "false")
|
||||
vinsList := []struct {
|
||||
ID int `json:"id"`
|
||||
}{}
|
||||
vinsListRaw, err := c.DecortAPICall(ctx, "POST", vinsListAPI, urlValues)
|
||||
if err != nil {
|
||||
return 0, false
|
||||
}
|
||||
err = json.Unmarshal([]byte(vinsListRaw), &vinsList)
|
||||
if err != nil {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
networks := d.Get("network").(*schema.Set).List()
|
||||
|
||||
for _, networkInterface := range networks {
|
||||
|
||||
networkItem := networkInterface.(map[string]interface{})
|
||||
if !existVinsIdInList(networkItem["net_id"].(int), vinsList) {
|
||||
return networkItem["net_id"].(int), false
|
||||
}
|
||||
}
|
||||
return 0, true
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -37,7 +37,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -242,90 +241,20 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
|
||||
return nil
|
||||
}
|
||||
|
||||
func utilityComputeCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
|
||||
// This function tries to locate Compute by one of the following approaches:
|
||||
// - if compute_id is specified - locate by compute ID
|
||||
// - if compute_name is specified - locate by a combination of compute name and resource
|
||||
// group ID
|
||||
//
|
||||
// If succeeded, it returns non-empty string that contains JSON formatted facts about the
|
||||
// Compute as returned by compute/get API call.
|
||||
// Otherwise it returns empty string and meaningful error.
|
||||
//
|
||||
// This function does not modify its ResourceData argument, so it is safe to use it as core
|
||||
// method for resource's Exists method.
|
||||
//
|
||||
|
||||
func utilityComputeCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (RecordCompute, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
compute := &RecordCompute{}
|
||||
|
||||
// make it possible to use "read" & "check presence" functions with compute ID set so
|
||||
// that Import of Compute resource is possible
|
||||
idSet := false
|
||||
theId, err := strconv.Atoi(d.Id())
|
||||
if err != nil || theId <= 0 {
|
||||
computeId, argSet := d.GetOk("compute_id") // NB: compute_id is NOT present in computeResource schema!
|
||||
if argSet {
|
||||
theId = computeId.(int)
|
||||
idSet = true
|
||||
}
|
||||
} else {
|
||||
idSet = true
|
||||
}
|
||||
|
||||
if idSet {
|
||||
// compute ID is specified, try to get compute instance straight by this ID
|
||||
log.Debugf("utilityComputeCheckPresence: locating compute by its ID %d", theId)
|
||||
urlValues.Add("computeId", fmt.Sprintf("%d", theId))
|
||||
computeFacts, err := c.DecortAPICall(ctx, "POST", ComputeGetAPI, urlValues)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return computeFacts, nil
|
||||
}
|
||||
|
||||
// ID was not set in the schema upon entering this function - work through Compute name
|
||||
// and RG ID
|
||||
computeName, argSet := d.GetOk("name")
|
||||
if !argSet {
|
||||
return "", fmt.Errorf("cannot locate compute instance if name is empty and no compute ID specified")
|
||||
}
|
||||
|
||||
rgId, argSet := d.GetOk("rg_id")
|
||||
if !argSet {
|
||||
return "", fmt.Errorf("cannot locate compute by name %s if no resource group ID is set", computeName.(string))
|
||||
}
|
||||
|
||||
urlValues.Add("rgId", fmt.Sprintf("%d", rgId))
|
||||
apiResp, err := c.DecortAPICall(ctx, "POST", RgListComputesAPI, urlValues)
|
||||
urlValues.Add("computeId", d.Id())
|
||||
computeRaw, err := c.DecortAPICall(ctx, "POST", ComputeGetAPI, urlValues)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return *compute, err
|
||||
}
|
||||
|
||||
log.Debugf("utilityComputeCheckPresence: ready to unmarshal string %s", apiResp)
|
||||
|
||||
computeList := RgListComputesResp{}
|
||||
err = json.Unmarshal([]byte(apiResp), &computeList)
|
||||
err = json.Unmarshal([]byte(computeRaw), &compute)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return *compute, err
|
||||
}
|
||||
|
||||
// log.Printf("%#v", computeList)
|
||||
log.Debugf("utilityComputeCheckPresence: traversing decoded JSON of length %d", len(computeList))
|
||||
for index, item := range computeList {
|
||||
// need to match Compute by name, skip Computes with the same name in DESTROYED satus
|
||||
if item.Name == computeName.(string) && item.Status != "DESTROYED" {
|
||||
log.Debugf("utilityComputeCheckPresence: index %d, matched name %s", index, item.Name)
|
||||
// we found the Compute we need - now get detailed information via compute/get API
|
||||
cgetValues := &url.Values{}
|
||||
cgetValues.Add("computeId", fmt.Sprintf("%d", item.ID))
|
||||
apiResp, err = c.DecortAPICall(ctx, "POST", ComputeGetAPI, cgetValues)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return apiResp, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", nil // there should be no error if Compute does not exist
|
||||
return *compute, nil
|
||||
}
|
||||
|
||||
29
internal/service/cloudapi/kvmvm/utility_compute_audits.go
Normal file
29
internal/service/cloudapi/kvmvm/utility_compute_audits.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityComputeAuditsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (ListAudits, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
computeAudits := &ListAudits{}
|
||||
|
||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||
computeAuditsRaw, err := c.DecortAPICall(ctx, "POST", ComputeAuditsAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(computeAuditsRaw), &computeAudits)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return *computeAudits, nil
|
||||
}
|
||||
23
internal/service/cloudapi/kvmvm/utility_compute_boot_disk.go
Normal file
23
internal/service/cloudapi/kvmvm/utility_compute_boot_disk.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityComputeBootDiskCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*ItemComputeDisk, error) {
|
||||
compute, err := utilityComputeCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bootDisk := &ItemComputeDisk{}
|
||||
for _, disk := range compute.Disks {
|
||||
if disk.Name == "bootdisk" {
|
||||
*bootDisk = disk
|
||||
break
|
||||
}
|
||||
}
|
||||
return bootDisk, nil
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityComputeGetAuditsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (ListShortAudits, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
computeAudits := &ListShortAudits{}
|
||||
|
||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||
computeAuditsRaw, err := c.DecortAPICall(ctx, "POST", ComputeGetAuditsAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(computeAuditsRaw), &computeAudits)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return *computeAudits, nil
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityComputeGetConsoleUrlCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||
computeConsoleUrlRaw, err := c.DecortAPICall(ctx, "POST", ComputeGetConsoleUrlAPI, urlValues)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(computeConsoleUrlRaw), nil
|
||||
}
|
||||
24
internal/service/cloudapi/kvmvm/utility_compute_get_log.go
Normal file
24
internal/service/cloudapi/kvmvm/utility_compute_get_log.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityComputeGetLogCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||
urlValues.Add("path", d.Get("path").(string))
|
||||
computeGetLogRaw, err := c.DecortAPICall(ctx, "POST", ComputeGetLogAPI, urlValues)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(computeGetLogRaw), nil
|
||||
}
|
||||
39
internal/service/cloudapi/kvmvm/utility_compute_list.go
Normal file
39
internal/service/cloudapi/kvmvm/utility_compute_list.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityDataComputeListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (ListComputes, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
listComputes := &ListComputes{}
|
||||
|
||||
if includeDeleted, ok := d.GetOk("includedeleted"); ok {
|
||||
urlValues.Add("includeDeleted", strconv.FormatBool(includeDeleted.(bool)))
|
||||
}
|
||||
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)))
|
||||
}
|
||||
|
||||
listComputesRaw, err := c.DecortAPICall(ctx, "POST", ComputeListAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(listComputesRaw), &listComputes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return *listComputes, nil
|
||||
|
||||
}
|
||||
30
internal/service/cloudapi/kvmvm/utility_compute_pfw_list.go
Normal file
30
internal/service/cloudapi/kvmvm/utility_compute_pfw_list.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityComputePfwListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (ListPFWs, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
listPFWs := &ListPFWs{}
|
||||
|
||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||
computePfwListRaw, err := c.DecortAPICall(ctx, "POST", ComputePfwListAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(computePfwListRaw), &listPFWs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return *listPFWs, err
|
||||
|
||||
}
|
||||
28
internal/service/cloudapi/kvmvm/utility_compute_user_list.go
Normal file
28
internal/service/cloudapi/kvmvm/utility_compute_user_list.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityComputeUserListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (RecordACL, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
userList := &RecordACL{}
|
||||
|
||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||
computeUserListRaw, err := c.DecortAPICall(ctx, "POST", ComputeUserListAPI, urlValues)
|
||||
if err != nil {
|
||||
return *userList, err
|
||||
}
|
||||
err = json.Unmarshal([]byte(computeUserListRaw), &userList)
|
||||
if err != nil {
|
||||
return *userList, err
|
||||
}
|
||||
return *userList, err
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityDataComputeCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (RecordCompute, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
compute := &RecordCompute{}
|
||||
|
||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||
computeRaw, err := c.DecortAPICall(ctx, "POST", ComputeGetAPI, urlValues)
|
||||
if err != nil {
|
||||
return *compute, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(computeRaw), &compute)
|
||||
if err != nil {
|
||||
return *compute, err
|
||||
}
|
||||
return *compute, nil
|
||||
}
|
||||
Reference in New Issue
Block a user