github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/evs/extensions/schedulerstats/list.go (about) 1 package schedulerstats 2 3 import ( 4 "encoding/json" 5 "math" 6 7 "github.com/opentelekomcloud/gophertelekomcloud" 8 "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" 9 ) 10 11 type ListOpts struct { 12 // ID of the tenant to look up storage pools for. 13 TenantID string `q:"tenant_id"` 14 // Whether to list extended details. 15 Detail bool `q:"detail"` 16 } 17 18 func List(client *golangsdk.ServiceClient, opts ListOpts) ([]StoragePool, error) { 19 url, err := golangsdk.NewURLBuilder().WithEndpoints("scheduler-stats", "get_pools").WithQueryParams(&opts).Build() 20 if err != nil { 21 return nil, err 22 } 23 24 raw, err := client.Get(client.ServiceURL(url.String()), nil, nil) 25 if err != nil { 26 return nil, err 27 } 28 29 var res []StoragePool 30 err = extract.IntoSlicePtr(raw.Body, &res, "pools") 31 return res, err 32 } 33 34 type StoragePool struct { 35 Name string `json:"name"` 36 Capabilities Capabilities `json:"capabilities"` 37 } 38 39 type Capabilities struct { 40 // The following fields should be present in all storage drivers. 41 DriverVersion string `json:"driver_version"` 42 FreeCapacityGB float64 `json:"-"` 43 StorageProtocol string `json:"storage_protocol"` 44 TotalCapacityGB float64 `json:"-"` 45 VendorName string `json:"vendor_name"` 46 VolumeBackendName string `json:"volume_backend_name"` 47 // The following fields are optional and may have empty values depending 48 // on the storage driver in use. 49 ReservedPercentage int64 `json:"reserved_percentage"` 50 LocationInfo string `json:"location_info"` 51 QoSSupport bool `json:"QoS_support"` 52 ProvisionedCapacityGB float64 `json:"provisioned_capacity_gb"` 53 MaxOverSubscriptionRatio string `json:"max_over_subscription_ratio"` 54 ThinProvisioningSupport bool `json:"thin_provisioning_support"` 55 ThickProvisioningSupport bool `json:"thick_provisioning_support"` 56 TotalVolumes int64 `json:"total_volumes"` 57 FilterFunction string `json:"filter_function"` 58 GoodnessFuction string `json:"goodness_function"` 59 Mutliattach bool `json:"multiattach"` 60 SparseCopyVolume bool `json:"sparse_copy_volume"` 61 } 62 63 func (r *Capabilities) UnmarshalJSON(b []byte) error { 64 type tmp Capabilities 65 var s struct { 66 tmp 67 FreeCapacityGB interface{} `json:"free_capacity_gb"` 68 TotalCapacityGB interface{} `json:"total_capacity_gb"` 69 } 70 err := json.Unmarshal(b, &s) 71 if err != nil { 72 return err 73 } 74 *r = Capabilities(s.tmp) 75 76 // Generic function to parse a capacity value which may be a numeric 77 // value, "unknown", or "infinite" 78 parseCapacity := func(capacity interface{}) float64 { 79 if capacity != nil { 80 switch capacity := capacity.(type) { 81 case float64: 82 return capacity 83 case string: 84 if capacity == "infinite" { 85 return math.Inf(1) 86 } 87 } 88 } 89 return 0.0 90 } 91 92 r.FreeCapacityGB = parseCapacity(s.FreeCapacityGB) 93 r.TotalCapacityGB = parseCapacity(s.TotalCapacityGB) 94 95 return nil 96 }