-
Notifications
You must be signed in to change notification settings - Fork 10
/
status.go
87 lines (75 loc) · 2.14 KB
/
status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package datavolume
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/kubevirt/terraform-provider-kubevirt/kubevirt/utils"
cdiv1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
)
func dataVolumeStatusFields() map[string]*schema.Schema {
return map[string]*schema.Schema{
"phase": {
Type: schema.TypeString,
Description: "DataVolumePhase is the current phase of the DataVolume.",
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{
"",
"Pending",
"PVCBound",
"ImportScheduled",
"ImportInProgress",
"CloneScheduled",
"CloneInProgress",
"SnapshotForSmartCloneInProgress",
"SmartClonePVCInProgress",
"UploadScheduled",
"UploadReady",
"Succeeded",
"Failed",
"Unknown",
}, false),
},
"progress": {
Type: schema.TypeString,
Description: "DataVolumePhase is the current phase of the DataVolume.",
Optional: true,
Computed: true,
ValidateFunc: utils.StringIsIntInRange(0, 100),
},
}
}
func dataVolumeStatusSchema() *schema.Schema {
fields := dataVolumeStatusFields()
return &schema.Schema{
Type: schema.TypeList,
Description: fmt.Sprintf("DataVolumeStatus provides the parameters to store the phase of the Data Volume"),
Optional: true,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: fields,
},
}
}
func expandDataVolumeStatus(dataVolumeStatus []interface{}) cdiv1.DataVolumeStatus {
result := cdiv1.DataVolumeStatus{}
if len(dataVolumeStatus) == 0 || dataVolumeStatus[0] == nil {
return result
}
in := dataVolumeStatus[0].(map[string]interface{})
if v, ok := in["phase"].(string); ok {
result.Phase = cdiv1.DataVolumePhase(v)
}
if v, ok := in["progress"].(string); ok {
result.Progress = cdiv1.DataVolumeProgress(v)
}
return result
}
func flattenDataVolumeStatus(in cdiv1.DataVolumeStatus) []interface{} {
att := map[string]interface{}{
"phase": string(in.Phase),
"progress": string(in.Progress),
}
return []interface{}{att}
}