-
Notifications
You must be signed in to change notification settings - Fork 133
/
data_dedicated_ceph.go
98 lines (93 loc) · 2.29 KB
/
data_dedicated_ceph.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
88
89
90
91
92
93
94
95
96
97
98
package ovh
import (
"fmt"
"log"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
)
func dataSourceDedicatedCeph() *schema.Resource {
return &schema.Resource{
Read: dataSourceDedicatedCephRead,
Schema: map[string]*schema.Schema{
"ceph_mons": {
Type: schema.TypeList,
Optional: false,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"ceph_version": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"crush_tunables": {
Type: schema.TypeString,
Optional: false,
Computed: true,
},
"label": {
Type: schema.TypeString,
Optional: false,
Computed: true,
},
"region": {
Type: schema.TypeString,
Optional: false,
Computed: true,
},
"service_name": {
Type: schema.TypeString,
Optional: false,
Computed: false,
Required: true,
},
"size": {
Type: schema.TypeFloat,
Optional: false,
Computed: true,
},
"state": {
Type: schema.TypeString,
Optional: false,
Computed: true,
},
"status": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
err := helpers.ValidateDedicatedCephStatus(v.(string))
if err != nil {
errors = append(errors, err)
}
return
},
},
},
}
}
func dataSourceDedicatedCephRead(d *schema.ResourceData, meta interface{}) error {
url := "/dedicated/ceph"
config := meta.(*Config)
serviceName := d.Get("service_name").(string)
log.Printf("[DEBUG] Will retrieve dedicated CEPH %s", serviceName)
ceph := &DedicatedCeph{}
err := config.OVHClient.Get(fmt.Sprintf("%s/%s", url, serviceName), &ceph)
if err != nil {
return fmt.Errorf("Error calling %s/%s:\n\t %q", url, serviceName, err)
}
log.Printf("[DEBUG] CEPH is %v", ceph.CephMonitors)
d.SetId(ceph.ServiceName)
d.Set("service_name", ceph.ServiceName)
d.Set("ceph_mons", ceph.CephMonitors)
d.Set("ceph_version", ceph.CephVersion)
d.Set("crush_tunables", ceph.CrushTunables)
d.Set("label", ceph.Label)
d.Set("region", ceph.Region)
d.Set("size", ceph.Size)
d.Set("state", ceph.State)
d.Set("status", ceph.Status)
return nil
}