-
Notifications
You must be signed in to change notification settings - Fork 521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compute v2: Availability Zones Info #704
Conversation
Add ability to get list and detailed AZs info
Build succeeded.
|
bfb4a53
to
a3e8e09
Compare
Build succeeded.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dstdfx Thank you for working on this. I did a cursory review and spotted a few things that need changed.
First, can you use the following test fixture?
{
"availabilityZoneInfo": [
{
"hosts": {
"localhost": {
"nova-cert": {
"active": true,
"available": false,
"updated_at": "2017-10-14T17:03:39.000000"
},
"nova-conductor": {
"active": true,
"available": false,
"updated_at": "2017-10-14T17:04:09.000000"
},
"nova-consoleauth": {
"active": true,
"available": false,
"updated_at": "2017-10-14T17:04:18.000000"
},
"nova-scheduler": {
"active": true,
"available": false,
"updated_at": "2017-10-14T17:04:30.000000"
}
},
"openstack-acc-tests.novalocal": {
"nova-cert": {
"active": true,
"available": true,
"updated_at": "2018-01-04T04:11:19.000000"
},
"nova-conductor": {
"active": true,
"available": true,
"updated_at": "2018-01-04T04:11:22.000000"
},
"nova-consoleauth": {
"active": true,
"available": true,
"updated_at": "2018-01-04T04:11:20.000000"
},
"nova-scheduler": {
"active": true,
"available": true,
"updated_at": "2018-01-04T04:11:23.000000"
}
}
},
"zoneName": "internal",
"zoneState": {
"available": true
}
},
{
"hosts": {
"openstack-acc-tests.novalocal": {
"nova-compute": {
"active": true,
"available": true,
"updated_at": "2018-01-04T04:11:23.000000"
}
}
},
"zoneName": "nova",
"zoneState": {
"available": true
}
}
]
}
If I recall correctly, the blocker I spotted in #327 was that the test fixture was incorrect. The above fixture is pulled from a running openstack environment so we can guarantee it works.
Second, OS
should be removed from the names/variables. ie instead of OSAvailabilityZonePage
, it should be AvailabilityZonePage
.
I haven't done an exhaustive review of this yet, but the above items should be fixed before any further review is done.
Again, thank you for working on this and let me know if you have any questions.
// UnmarshalJSON to override default | ||
func (r *ServerAvailabilityZoneExt) UnmarshalJSON(b []byte) error { | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was removed sometime after #327 was opened. Can you remove this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for feedback!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jtopjian is it okay to leave ComputeAvailabilityZonePage
name instead OSAvailabilityZonePage
? The problem is that we've already used AvailabilityZonePage
name in openstack/sharedfilesystems/v2/availabilityzones/results.go
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can re-use the name AvailabilityZonePage
. The other AvailabilityZonePage
is in another Go package and, unless I'm mistaken, there won't be a name collision.
ed8c33a
to
15ebf51
Compare
Build succeeded.
|
* Change `AvailabilityZoneInfo` type from `struct` to `slice` * Add custom `UnmarshalJSON` to `AvailabilityZoneInfo` * Get rid of 'OS' prefixes in variable's names
Build succeeded.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dstdfx This is looking good - nice work.
I did a more detailed review and left some comments. Please let me know if you have any questions.
Additionally, would you be able to provide an acceptance test for this? The file would be contained under acceptance/openstack/compute/v2
.
More information about acceptance tests can be found here: https://github.com/gophercloud/gophercloud/tree/master/acceptance
|
||
type ServerWithAZ struct { | ||
servers.Server | ||
availabilityzones.ServerAvailabilityZoneExt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example should not be removed.
|
||
allPages, err := servers.List(client, nil).AllPages() | ||
allPages, err := az.ListDetail(computeClient).AllPages() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
az
is not a valid package name.
fmt.Println(hostname) | ||
// to be continued ... | ||
// cut for brevity :) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following should work here:
for _, zoneInfo := range availabilityZoneInfo {
fmt.Printf("%+v\n", zoneInfo)
}
type ServerAvailabilityZoneExt struct { | ||
// AvailabilityZone is the availabilty zone the server is in. | ||
AvailabilityZone string `json:"OS-EXT-AZ:availability_zone"` | ||
} | ||
|
||
type StateofService struct { |
There was a problem hiding this comment.
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 ServiceState
.
NovaScheduler StateofService `json:"nova-scheduler"` | ||
NovaCompute StateofService `json:"nova-compute"` | ||
NovaCert StateofService `json:"nova-cert"` | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above is hard-coding each of the nova services into Gophercloud. By doing this, each Host result will contain all of the above services even if they are not part of the availability zone. For example, this is the result of running this code in my test environment:
"hosts": {
"openstack-acc-tests.novalocal": {
"nova-conductor": {
"active": false,
"available": false,
"updated_at": "0001-01-01T00:00:00Z"
},
"nova-consoleauth": {
"active": false,
"available": false,
"updated_at": "0001-01-01T00:00:00Z"
},
"nova-network": {
"active": false,
"available": false,
"updated_at": "0001-01-01T00:00:00Z"
},
"nova-scheduler": {
"active": false,
"available": false,
"updated_at": "0001-01-01T00:00:00Z"
},
"nova-compute": {
"active": true,
"available": true,
"updated_at": "2018-01-05T03:16:04Z"
},
"nova-cert": {
"active": false,
"available": false,
"updated_at": "0001-01-01T00:00:00Z"
}
}
},
"zoneName": "nova",
"zoneState": {
"available": true
}
}
Instead of doing the above, I think we should do:
type Service map[string]ServiceState
When I modify this PR to be the above, I now see this:
"hosts": {
"openstack-acc-tests.novalocal": {
"nova-compute": {
"active": true,
"available": true,
"updated_at": "2018-01-05T03:26:34Z"
}
}
},
"zoneName": "nova",
"zoneState": {
"available": true
}
}
Which I think is more accurate.
Please let me know if I am incorrect about this.
// AvailabilityZone contains all the information associated with an OpenStack | ||
// AvailabilityZone. | ||
type AvailabilityZone struct { | ||
Hosts `json:"hosts"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hosts Hosts `json:"hosts"`
Hosts `json:"hosts"` | ||
// The availability zone name | ||
ZoneName string `json:"zoneName"` | ||
ZoneState `json:"zoneState"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ZoneState ZoneState `json:"zoneState"`
} | ||
|
||
// AvailabilityZoneInfo contains list of AvailabilityZone info | ||
type AvailabilityZoneInfo []AvailabilityZone |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type isn't needed.
func ExtractAvailabilityZones(r pagination.Page) (AvailabilityZoneInfo, error) { | ||
var a AvailabilityZoneInfo | ||
err := (r.(AvailabilityZonePage)).ExtractInto(&a) | ||
return a, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of the above, use:
var s struct {
AvailabilityZoneInfo []AvailabilityZone `json:"availabilityZoneInfo`
}
err := (r.(AvailabilityZonePage)).ExtractInto(&s)
return s.AvailabilityZoneInfo, err
* Rename `ServiceOfState` to `ServiceState` * Change type `Services` from `struct` to `map[string]ServiceState` * Delete useless type `AvailabilityZoneInfo` * Update doc.go
Build succeeded.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dstdfx Just one more change. I apologize that I didn't catch this yesterday.
Once this change is made, this PR is good to go. Thank you very much for your work on it. 😄
type ServiceState struct { | ||
Active bool `json:"active"` | ||
Available bool `json:"available"` | ||
UpdatedAt time.Time `json:"updated_at"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UpdatedAt time.Time `json:"-"`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, useless struct tag!
Build succeeded.
|
@dstdfx This looks good to me. I've also verified it on a new Pike environment and everything is parsing correctly. Nice work! |
Add ability to get list and detailed AZs info
For #320
Links to the line numbers/files in the OpenStack source code that support the
code in this PR: