github.com/gophercloud/gophercloud@v1.11.0/openstack/sharedfilesystems/v2/schedulerstats/results.go (about) 1 package schedulerstats 2 3 import ( 4 "encoding/json" 5 "math" 6 7 "github.com/gophercloud/gophercloud/pagination" 8 ) 9 10 // Capabilities represents the information of an individual Pool. 11 type Capabilities struct { 12 // The following fields should be present in all storage drivers. 13 14 // The quality of service (QoS) support. 15 Qos bool `json:"qos"` 16 // The date and time stamp when the API request was issued. 17 Timestamp string `json:"timestamp"` 18 // The name of the share back end. 19 ShareBackendName string `json:"share_backend_name"` 20 // Share server is usually a storage virtual machine or a lightweight container that is used to export shared file systems. 21 DriverHandlesShareServers bool `json:"driver_handles_share_servers"` 22 // The driver version of the back end. 23 DriverVersion string `json:"driver_version"` 24 // The amount of free capacity for the back end, in GiBs. A valid value is a string, such as unknown, or an integer. 25 FreeCapacityGB float64 `json:"-"` 26 // The storage protocol for the back end. For example, NFS_CIFS, glusterfs, HDFS, etc. 27 StorageProtocol string `json:"storage_protocol"` 28 // The total capacity for the back end, in GiBs. A valid value is a string, such as unknown, or an integer. 29 TotalCapacityGB float64 `json:"-"` 30 // The specification that filters back ends by whether they do or do not support share snapshots. 31 SnapshotSupport bool `json:"snapshot_support"` 32 // The back end replication domain. 33 ReplicationDomain string `json:"replication_domain"` 34 // The name of the vendor for the back end. 35 VendorName string `json:"vendor_name"` 36 37 // The following fields are optional and may have empty values depending 38 39 // on the storage driver in use. 40 ReservedPercentage int64 `json:"reserved_percentage"` 41 AllocatedCapacityGB float64 `json:"-"` 42 } 43 44 // Pool represents an individual Pool retrieved from the 45 // schedulerstats API. 46 type Pool struct { 47 // The name of the back end. 48 Name string `json:"name"` 49 // The name of the back end. 50 Backend string `json:"backend"` 51 // The pool name for the back end. 52 Pool string `json:"pool"` 53 // The host name for the back end. 54 Host string `json:"host"` 55 // The back end capabilities which include qos, total_capacity_gb, etc. 56 Capabilities Capabilities `json:"capabilities,omitempty"` 57 } 58 59 func (r *Capabilities) UnmarshalJSON(b []byte) error { 60 type tmp Capabilities 61 var s struct { 62 tmp 63 AllocatedCapacityGB interface{} `json:"allocated_capacity_gb"` 64 FreeCapacityGB interface{} `json:"free_capacity_gb"` 65 TotalCapacityGB interface{} `json:"total_capacity_gb"` 66 } 67 err := json.Unmarshal(b, &s) 68 if err != nil { 69 return err 70 } 71 *r = Capabilities(s.tmp) 72 73 // Generic function to parse a capacity value which may be a numeric 74 // value, "unknown", or "infinite" 75 parseCapacity := func(capacity interface{}) float64 { 76 if capacity != nil { 77 switch capacity.(type) { 78 case float64: 79 return capacity.(float64) 80 case string: 81 if capacity.(string) == "infinite" { 82 return math.Inf(1) 83 } 84 } 85 } 86 return 0.0 87 } 88 89 r.AllocatedCapacityGB = parseCapacity(s.AllocatedCapacityGB) 90 r.FreeCapacityGB = parseCapacity(s.FreeCapacityGB) 91 r.TotalCapacityGB = parseCapacity(s.TotalCapacityGB) 92 93 return nil 94 } 95 96 // PoolPage is a single page of all List results. 97 type PoolPage struct { 98 pagination.SinglePageBase 99 } 100 101 // IsEmpty satisfies the IsEmpty method of the Page interface. It returns true 102 // if a List contains no results. 103 func (page PoolPage) IsEmpty() (bool, error) { 104 if page.StatusCode == 204 { 105 return true, nil 106 } 107 108 va, err := ExtractPools(page) 109 return len(va) == 0, err 110 } 111 112 // ExtractPools takes a List result and extracts the collection of 113 // Pools returned by the API. 114 func ExtractPools(p pagination.Page) ([]Pool, error) { 115 var s struct { 116 Pools []Pool `json:"pools"` 117 } 118 err := (p.(PoolPage)).ExtractInto(&s) 119 return s.Pools, err 120 }