Skip to content

Nova Hypervisors API - #178

Closed
spjmurray wants to merge 5 commits into
gophercloud:masterfrom
spjmurray:compute_hypervisors_list
Closed

spjmurray wants to merge 5 commits into
gophercloud:masterfrom
spjmurray:compute_hypervisors_list

Conversation

@spjmurray

@spjmurray spjmurray commented Nov 3, 2016 •

Copy link
Copy Markdown
Contributor

Adds in support to list all available hypervisors (detailed) for applications
such as monitoring and capacity planning.

API: https://github.com/openstack/nova/blob/master/nova/api/openstack/compute/hypervisors.py#L46

Pay particular attention to line 71 where the horrible cpu_info hack is introduced

For #179

@coveralls

coveralls commented Nov 3, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.02%) to 68.397% when pulling 10f6a0a on spjmurray:compute_hypervisors_list into 22bf82b on gophercloud:master.

@jtopjian

jtopjian commented Nov 3, 2016

Copy link
Copy Markdown
Contributor

@spjmurray Nice! I'd love to see this added.

Can you open a corresponding Issue per the style guide? This helps separate feature discussion vs code review discussion.

For the code itself, one question I have is whether or not this should go under directly under the compute/v2 package or compute/v2/extensions. The previous API docs had this listed as an extension, but now everything is bundled under compute. @jrperritt: thoughts?

@spjmurray

Copy link
Copy Markdown
Contributor Author

Sure thing @jtopjian. Reads Also FYI the end goal of this is related to influxdata/telegraf#243

@jtopjian

jtopjian commented Nov 3, 2016

Copy link
Copy Markdown
Contributor

@spjmurray This just might make me revisit InfluxDB now...

@spjmurray

Copy link
Copy Markdown
Contributor Author

@jtopjian Here's some more fun InfluxDB related things I've done to really stoke a fire ;p http://www.datacentred.co.uk/blog/icinga-2-5-released/ http://www.datacentred.co.uk/blog/ceph-monitoring-telegraf-grafana/

@spjmurray spjmurray mentioned this pull request Nov 3, 2016
@spjmurray
spjmurray force-pushed the compute_hypervisors_list branch from 10f6a0a to e4c6181 Compare November 3, 2016 15:44
@spjmurray spjmurray changed the title Nova Hypervisors API [WIP] Nova Hypervisors API Nov 3, 2016
@coveralls

coveralls commented Nov 3, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.02%) to 68.397% when pulling e4c6181 on spjmurray:compute_hypervisors_list into 22bf82b on gophercloud:master.

@jrperritt

Copy link
Copy Markdown
Contributor

@spjmurray is this still correctly labeled WIP or is it ready for review?

Adds in support to list all available hypervisors (detailed) for applications
such as monitoring and capacity planning.

For gophercloud#179
@spjmurray
spjmurray force-pushed the compute_hypervisors_list branch from e4c6181 to 530d34d Compare February 20, 2017 11:48
@spjmurray spjmurray changed the title [WIP] Nova Hypervisors API Nova Hypervisors API Feb 20, 2017
@spjmurray

Copy link
Copy Markdown
Contributor Author

Apologies @jtopjian this got buried in my inbox and forgotten about. Yes this is ready for review, I've stripped the WIP out of the pull request and the commit message.

@coveralls

coveralls commented Feb 20, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.008%) to 69.472% when pulling 530d34d on spjmurray:compute_hypervisors_list into f47ca3a on gophercloud:master.

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

I've made some comments (mostly stylistic). If you'd prefer, I can submit this code as a PR, which makes most of the changes I mentioned on top of your commit.
The style guide should mention all the changes needed.

Arch string `json:"arch"`
Model string `json:"model"`
Features []string `json:"features"`
Topology `json:"topology"`

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.

Let's name this field (Topology).


type Hypervisor struct {
// A structure that contains cpu information like arch, model, vendor, features and topology
CpuInfo `json:"cpu_info"`

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.

Let's change this to:

CPUInfo CPUInfo `json:"-"`

// The number of running vms on this hypervisor
RunningVMs int `json:"running_vms"`
// The hypervisor service object
Service `json:"service"`

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.

Let's name this field (Service).

// The hypervisor type
HypervisorType string `json:"hypervisor_type"`
// The hypervisor version
HypervisorVersion int `json:"hypervisor_version"`

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.

Let's change this to:

HypervisorVersion int `json:"-"`

// Newer versions pass the CPU into around as the correct types, this just needs
// converting and copying into place. Older versions pass CPU info around as a string
// and can simply be unmarshalled by the json parser
switch t := hypervisor.CpuInfo.(type) {

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.

Is there any reason this couldn't be simplified to this:
master...jrperritt:compute_hypervisors_list#diff-cf3e97a140d10e9f8115943de0bab133R93

}

type HypervisorPage struct {
pagination.LinkedPageBase

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.

If this is a linked page, it should have a way to get from one page to the next (usually a Links field). Does that exist?
I noticed there are Marker and Limit fields in the ListOpts, so maybe it's a MarkerPage?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jrperritt You are right, it's actually a marker page. Sadly when I implemented it properly it seems our version of OpenStack doesn't support the marker field (e.g. needs Nova V2.33) and just spins forever. Do we have a standard way of catering for OpenStack's API stupidity regarding backwards compatibility?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm guessing lowest common denominator e.g. SinglePageBase

VCPUsUsed int `json:"vcpus_used"`
}

func (h *Hypervisor) 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.

Have a look at the other UnmarshalJSON functions for style changes in this method (variable name changes).

pagination.LinkedPageBase
}

func (page HypervisorPage) IsEmpty() (bool, 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.

Have a look at the other UnmarshalJSON functions for style changes in this method (variable name changes).

return len(hypervisors) == 0, err
}

func ExtractHypervisors(p pagination.Page) ([]Hypervisor, 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.

Have a look at the other UnmarshalJSON functions for style changes in this method (variable name changes).

For some reason this morning storage space started to (in gophercloud only
not via curl) return sizes as scientific notation
Our environment doesn't support marker pages, so go for the backwards compatible
option.
@coveralls

coveralls commented Mar 27, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.1%) to 69.597% when pulling 4202358 on spjmurray:compute_hypervisors_list into f47ca3a on gophercloud:master.

func (r *Hypervisor) UnmarshalJSON(b []byte) error {

type tmp Hypervisor
var s *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.

@jrperritt I'm unable to find Go documentation to explain when *struct is required. All other UnmarshalJSON functions use struct. Testing with both seems to result in the same.

Is *struct required here?

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.

To clarify a little bit:

I can do some separate / local tests with struct and *struct and see the differences there, but it seems here, json.Unmarshal will happily take both. Just not sure if *struct should be respected here.

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.

Is *struct required here?

No, and we should maintain consistency with the other UnmarshalJSON methods [by changing it to a non-pointer].

@jtopjian

Copy link
Copy Markdown
Contributor

I've cleaned this up a bit and going to resubmit this in a new PR. @spjmurray's changes will remain in the commit history.

@jtopjian jtopjian closed this May 18, 2017
cardoe pushed a commit to cardoe/gophercloud that referenced this pull request Aug 27, 2020
…updates

Networking v2: Updates to openstack_networking_router_v2
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