forked from hashicorp/terraform-provider-vsphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatastore_summary_structure.go
73 lines (69 loc) · 2.62 KB
/
datastore_summary_structure.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
package vsphere
import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-vsphere/vsphere/internal/helper/structure"
"github.com/vmware/govmomi/vim25/types"
)
// schemaDatastoreSummary returns schema items for resources that
// need to work with a DatastoreSummary.
func schemaDatastoreSummary() map[string]*schema.Schema {
return map[string]*schema.Schema{
// Note that the following fields are not represented in the schema here:
// * Name (more than likely the ID attribute and will be represented in
// resource schema)
// * Type (redundant attribute as the datastore type will be represented by
// the resource)
"accessible": &schema.Schema{
Type: schema.TypeBool,
Description: "The connectivity status of the datastore. If this is false, some other computed attributes may be out of date.",
Computed: true,
},
"capacity": &schema.Schema{
Type: schema.TypeInt,
Description: "Maximum capacity of the datastore, in MB.",
Computed: true,
},
"free_space": &schema.Schema{
Type: schema.TypeInt,
Description: "Available space of this datastore, in MB.",
Computed: true,
},
"maintenance_mode": &schema.Schema{
Type: schema.TypeString,
Description: "The current maintenance mode state of the datastore.",
Computed: true,
},
"multiple_host_access": &schema.Schema{
Type: schema.TypeBool,
Description: "If true, more than one host in the datacenter has been configured with access to the datastore.",
Computed: true,
},
"uncommitted_space": &schema.Schema{
Type: schema.TypeInt,
Description: "Total additional storage space, in MB, potentially used by all virtual machines on this datastore.",
Computed: true,
},
"url": &schema.Schema{
Type: schema.TypeString,
Description: "The unique locator for the datastore.",
Computed: true,
},
}
}
// flattenDatastoreSummary reads various fields from a DatastoreSummary into
// the passed in ResourceData.
func flattenDatastoreSummary(d *schema.ResourceData, obj *types.DatastoreSummary) error {
d.Set("accessible", obj.Accessible)
d.Set("capacity", structure.ByteToMB(obj.Capacity))
d.Set("free_space", structure.ByteToMB(obj.FreeSpace))
d.Set("maintenance_mode", obj.MaintenanceMode)
d.Set("multiple_host_access", obj.MultipleHostAccess)
d.Set("uncommitted_space", structure.ByteToMB(obj.Uncommitted))
d.Set("url", obj.Url)
// Set the name attribute off of the name here - since we do not track this
// here we check for errors
if err := d.Set("name", obj.Name); err != nil {
return err
}
return nil
}