Repository navigation
Cinder Storage Pools API - #205
Conversation
| return err | ||
| } | ||
|
|
||
| // Should be a numeric, "unknown", "infinite" |
There was a problem hiding this comment.
Maybe add unit tests for the unknown and infinite cases?
|
A few inline comments. In addition, can you run the code through |
| Capabilities `json:"capabilities"` | ||
| } | ||
|
|
||
| func (s *StoragePool) UnmarshalJSON(b []byte) error { |
There was a problem hiding this comment.
Style nit: this should be (r *StoragePool)
| func (s *StoragePool) UnmarshalJSON(b []byte) error { | ||
| // Unmarshal the generic stuff | ||
| type tmp StoragePool | ||
| var p *struct { |
There was a problem hiding this comment.
Style nit: this should be var s
|
@jtopjian it's almost like you knew adding those unit tests would throw up an error ... good catch :) |
|
@spjmurray still correctly titled |
Adds in the ability to probe storage backends to get the current and maximum pool utilization. Useful for capacity planning based on committed-to metrics and those as a result of thin-provisioning.
Additionally makes the distinction between required and optional fields based on said documentation, adding in the optional fields
9f0e2b0 to
3c4a174
Compare
There was a problem hiding this comment.
@spjmurray The bulk of this is really good, so thank you for putting it together :)
A few notes:
The UnmarshalJSON stuff needed fixing up. It was easier for me to just make a diff than try to explain it inline: jtopjian@8ce30e3
I have one question for @jrperritt inline.
Additionally, if you do:
cinder list-extensionsYou'll see Scheduler_stats listed, so I think this should be renamed to schedulerstats and placed under the extensions directory.
Edit: One more thing: I think the List call needs to be paginated, even if everything will be in a single page. Just like how your hypervisor stats support was implemented.
Let me know if you have any questions.
| case "infinite": | ||
| r.Capabilities.FreeCapacityGB = math.Inf(1) | ||
| default: | ||
| return fmt.Errorf("capabilities.free_capacity_gb: unexpected string %v", keyword) |
There was a problem hiding this comment.
@jrperritt Would it be better to set the value to 0.0 or return an error?
There was a problem hiding this comment.
I think you're right: setting it to 0.0 seems reasonable.
| case "infinite": | ||
| r.Capabilities.FreeCapacityGB = math.Inf(1) | ||
| default: | ||
| return fmt.Errorf("capabilities.free_capacity_gb: unexpected string %v", keyword) |
There was a problem hiding this comment.
I think you're right: setting it to 0.0 seems reasonable.
| } | ||
|
|
||
| // List makes a request against the API to list hypervisors. | ||
| func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) (r ListResult) { |
There was a problem hiding this comment.
We'll want to paginate this, even it's a single-page type.
| // Optional Fields | ||
| ReservedPercentage int64 `json:"reserved_percentage"` | ||
| LocationInfo string `json:"location_info"` | ||
| QoSSupprt bool `json:"QoS_support"` |
| ReservedPercentage int64 `json:"reserved_percentage"` | ||
| LocationInfo string `json:"location_info"` | ||
| QoSSupprt bool `json:"QoS_support"` | ||
| ProvisonedCapacityGB float64 `json:"provisoned_capacity_gb"` |
There was a problem hiding this comment.
Haven't looked at the schema, but I suspect these should be "Provisioned" (and "provisioned")
|
|
||
| type StoragePool struct { | ||
| Name string `json:"name"` | ||
| Capabilities `json:"capabilities"` |
There was a problem hiding this comment.
Capabilities Capabilities `json:"capabilities"`| case float64: | ||
| r.Capabilities.FreeCapacityGB = q.Capabilities.FreeCapacityGB.(float64) | ||
| case int: | ||
| r.Capabilities.FreeCapacityGB = q.Capabilities.FreeCapacityGB.(float64) |
There was a problem hiding this comment.
That will panic. Type-assert to int, then cast to float64. Better would be writing a unit test for it.
| case float64: | ||
| r.Capabilities.TotalCapacityGB = q.Capabilities.TotalCapacityGB.(float64) | ||
| case int: | ||
| r.Capabilities.TotalCapacityGB = q.Capabilities.TotalCapacityGB.(float64) |
There was a problem hiding this comment.
Same here as above (type-assert to int, then cast to float64).
Cleans up wine-induced typos. Updated the unmarshall code, seems the integer case is unnecessarily as go when unmarshalling a number defaults to float64, so has been deleted. As we default to 0.0 for total and free capacities I've folded the unknown case into the default. Testing code has been updated to include an 'integer' in the JSON to ensure the assumptions hold.
Rather than unmarshal the entire storage pool struct we only need cater for the capabilities structure, the JSON unmarshalling code auto-magically takes care of invoking the correct routines for us.
Renamed to scheduler stats, relocated to v2 extension as it's not part of v1.
|
@jtopjian @jrperritt Should be much better now... |
jtopjian
left a comment
There was a problem hiding this comment.
@spjmurray Thanks for making all of these changes.
I left a comment about the remaining default switch clauses.
In addition, can you move this to blockstorage/extensions rather than blockstorage/v2/extensions? This works in both v1 and v2 (and I suspect v3).
Points for blaming wine on the typos :)
| r.FreeCapacityGB = 0.0 | ||
| } | ||
| default: | ||
| return fmt.Errorf("capabilities.free_capacity_gb: unexpected type %v", t) |
There was a problem hiding this comment.
I think all default actions should be to just set to 0.0 rather than return an error.
Makes all defaults silently return 0.0 if something is amiss. Also thought it best to share the duplicated code in the form of a separate function.
|
Thanks, Simon :) |
|
|
||
| // Generic function to parse a capacity value which may be a numeric | ||
| // value, "unknown", or "infinite" | ||
| func ParseCapacity(capacity interface{}) float64 { |
There was a problem hiding this comment.
I'd prefer to just put this logic in UnmarshalJSON, but if you want to use a function, it should to be unexported (lowercase).
Unbeknownst to me symbol visibility across compilation units is controlled by capitalization, guess I'm too old and used to C's static :) This removes the export. Jrperritt preferred the functionality in the actual JSON code, I wanted to reduce code duplication so what I gather is the most idiomatic go is function literals/lambdas.
* Cinder Storage Pools API Adds in the ability to probe storage backends to get the current and maximum pool utilization. Useful for capacity planning based on committed-to metrics and those as a result of thin-provisioning. * jtopjian's comments from 25/11/16 * Update field source documentation Additionally makes the distinction between required and optional fields based on said documentation, adding in the optional fields * Fix up CI header format failures * Move Storage Pools to Block Storage Extension * Jrperritt's Review Comments Cleans up wine-induced typos. Updated the unmarshall code, seems the integer case is unnecessarily as go when unmarshalling a number defaults to float64, so has been deleted. As we default to 0.0 for total and free capacities I've folded the unknown case into the default. Testing code has been updated to include an 'integer' in the JSON to ensure the assumptions hold. * Add Pagination * Tweak Unmarshalling Rather than unmarshal the entire storage pool struct we only need cater for the capabilities structure, the JSON unmarshalling code auto-magically takes care of invoking the correct routines for us. * Update Name and Location Renamed to scheduler stats, relocated to v2 extension as it's not part of v1. * Move Back To Generic Extension * Alter JSON Unmarshalling Makes all defaults silently return 0.0 if something is amiss. Also thought it best to share the duplicated code in the form of a separate function. * Remove Capacity Parser Global Unbeknownst to me symbol visibility across compilation units is controlled by capitalization, guess I'm too old and used to C's static :) This removes the export. Jrperritt preferred the functionality in the actual JSON code, I wanted to reduce code duplication so what I gather is the most idiomatic go is function literals/lambdas.
Acc Tests: Enable DNS test to run with other tests
Addresses issue #194. The documentation is a little hazy links to code in the issue discussion thread.