Skip to content

Commit

Permalink
r/vmfs_datastore: Flatten disk space denominations to MB
Browse files Browse the repository at this point in the history
Just to make things a bit more readable.
  • Loading branch information
vancluever committed Sep 1, 2017
1 parent b2c0f0f commit f4c1da1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
12 changes: 6 additions & 6 deletions vsphere/datastore_summary_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ func schemaDatastoreSummary() map[string]*schema.Schema {
},
"capacity": &schema.Schema{
Type: schema.TypeInt,
Description: "Maximum capacity of the datastore, in bytes.",
Description: "Maximum capacity of the datastore, in MB.",
Computed: true,
},
"free_space": &schema.Schema{
Type: schema.TypeInt,
Description: "Available space of this datastore, in bytes.",
Description: "Available space of this datastore, in MB.",
Computed: true,
},
"maintenance_mode": &schema.Schema{
Expand All @@ -41,7 +41,7 @@ func schemaDatastoreSummary() map[string]*schema.Schema {
},
"uncommitted_space": &schema.Schema{
Type: schema.TypeInt,
Description: "Total additional storage space, in bytes, potentially used by all virtual machines on this datastore.",
Description: "Total additional storage space, in MB, potentially used by all virtual machines on this datastore.",
Computed: true,
},
"url": &schema.Schema{
Expand All @@ -56,11 +56,11 @@ func schemaDatastoreSummary() map[string]*schema.Schema {
// the passed in ResourceData.
func flattenDatastoreSummary(d *schema.ResourceData, obj *types.DatastoreSummary) error {
d.Set("accessible", obj.Accessible)
d.Set("capacity", obj.Capacity)
d.Set("free_space", obj.FreeSpace)
d.Set("capacity", byteToMB(obj.Capacity))
d.Set("free_space", byteToMB(obj.FreeSpace))
d.Set("maintenance_mode", obj.MaintenanceMode)
d.Set("multiple_host_access", obj.MultipleHostAccess)
d.Set("uncommitted_space", obj.Uncommitted)
d.Set("uncommitted_space", byteToMB(obj.Uncommitted))
d.Set("url", obj.Url)

// Set the name attribute off of the name here - since we do not track this
Expand Down
14 changes: 14 additions & 0 deletions vsphere/structure_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,17 @@ func mergeSchema(dst, src map[string]*schema.Schema) {
func boolPtr(v bool) *bool {
return &v
}

// byteToMB returns n/1000000. The input must be an integer that can be divisible
// by 1000000.
func byteToMB(n interface{}) interface{} {
switch v := n.(type) {
case int:
return v / 1000000
case int32:
return v / 1000000
case int64:
return v / 1000000
}
panic(fmt.Errorf("non-integer type %T for value", n))
}

0 comments on commit f4c1da1

Please sign in to comment.