Skip to content

Cinder Storage Pools API - #205

Merged
jrperritt merged 12 commits into
gophercloud:masterfrom
spjmurray:blockstorage_pool_stats
Jun 8, 2017
Merged

jrperritt merged 12 commits into
gophercloud:masterfrom
spjmurray:blockstorage_pool_stats

Conversation

@spjmurray

Copy link
Copy Markdown
Contributor

Addresses issue #194. The documentation is a little hazy links to code in the issue discussion thread.

@coveralls

coveralls commented Nov 25, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.07%) to 68.732% when pulling af51c86 on spjmurray:blockstorage_pool_stats into d5eda97 on gophercloud:master.

return err
}

// Should be a numeric, "unknown", "infinite"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add unit tests for the unknown and infinite cases?

@jtopjian

jtopjian commented Nov 25, 2016 •

Copy link
Copy Markdown
Contributor

A few inline comments. In addition, can you run the code through gofmt? If you're a vi user, the vim-go plugin will take care of that :)

Capabilities `json:"capabilities"`
}

func (s *StoragePool) UnmarshalJSON(b []byte) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit: this should be (r *StoragePool)

func (s *StoragePool) UnmarshalJSON(b []byte) error {
// Unmarshal the generic stuff
type tmp StoragePool
var p *struct {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit: this should be var s

@spjmurray

Copy link
Copy Markdown
Contributor Author

@jtopjian it's almost like you knew adding those unit tests would throw up an error ... good catch :)

@coveralls

coveralls commented Nov 29, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.04%) to 68.836% when pulling 9f0e2b0 on spjmurray:blockstorage_pool_stats into d5eda97 on gophercloud:master.

@jrperritt

Copy link
Copy Markdown
Contributor

@spjmurray still correctly titled [wip] or ready for review?

@jtopjian jtopjian mentioned this pull request May 21, 2017
spjmurray added 3 commits June 2, 2017 12:26
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
@spjmurray
spjmurray force-pushed the blockstorage_pool_stats branch from 9f0e2b0 to 3c4a174 Compare June 2, 2017 11:32
@spjmurray spjmurray changed the title [wip] Cinder Storage Pools API Cinder Storage Pools API Jun 2, 2017
@coveralls

coveralls commented Jun 2, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.07%) to 70.074% when pulling 970fc29 on spjmurray:blockstorage_pool_stats into 11fd706 on gophercloud:master.

@jtopjian jtopjian left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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-extensions

You'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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrperritt Would it be better to set the value to 0.0 or return an error?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QoSSupport

ReservedPercentage int64 `json:"reserved_percentage"`
LocationInfo string `json:"location_info"`
QoSSupprt bool `json:"QoS_support"`
ProvisonedCapacityGB float64 `json:"provisoned_capacity_gb"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capabilities Capabilities `json:"capabilities"`

case float64:
r.Capabilities.FreeCapacityGB = q.Capabilities.FreeCapacityGB.(float64)
case int:
r.Capabilities.FreeCapacityGB = q.Capabilities.FreeCapacityGB.(float64)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here as above (type-assert to int, then cast to float64).

spjmurray added 4 commits June 5, 2017 09:43
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.
@coveralls

coveralls commented Jun 5, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.2%) to 70.165% when pulling 5a6d3cc on spjmurray:blockstorage_pool_stats into 11fd706 on gophercloud:master.

Renamed to scheduler stats, relocated to v2 extension as it's not part of v1.
@coveralls

coveralls commented Jun 5, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.2%) to 70.165% when pulling c8f2a5d on spjmurray:blockstorage_pool_stats into 11fd706 on gophercloud:master.

@spjmurray

Copy link
Copy Markdown
Contributor Author

@jtopjian @jrperritt Should be much better now...

@jtopjian jtopjian left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all default actions should be to just set to 0.0 rather than return an error.

spjmurray added 2 commits June 7, 2017 11:09
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.
@coveralls

coveralls commented Jun 7, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.6%) to 70.565% when pulling e799df0 on spjmurray:blockstorage_pool_stats into 11fd706 on gophercloud:master.

@jtopjian

jtopjian commented Jun 7, 2017

Copy link
Copy Markdown
Contributor

Thanks, Simon :)


// Generic function to parse a capacity value which may be a numeric
// value, "unknown", or "infinite"
func ParseCapacity(capacity interface{}) float64 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@coveralls

coveralls commented Jun 8, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.6%) to 70.583% when pulling 34dcdd5 on spjmurray:blockstorage_pool_stats into 11fd706 on gophercloud:master.

@jrperritt
jrperritt merged commit 36954b3 into gophercloud:master Jun 8, 2017
j-griffith pushed a commit to j-griffith/gophercloud that referenced this pull request Jul 15, 2017
* 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.
cardoe pushed a commit to cardoe/gophercloud that referenced this pull request Aug 27, 2020
Acc Tests: Enable DNS test to run with other tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants