Added Shelve, Shelve-offload and Unshelve API#1799
Added Shelve, Shelve-offload and Unshelve API#1799jtopjian merged 4 commits intogophercloud:masterfrom
Conversation
|
Build failed.
|
|
recheck |
|
Build failed.
|
jtopjian
left a comment
There was a problem hiding this comment.
@qhua948 Thank you for working on this! You can ignore the OpenLab failures as there's an ongoing issue right now.
Note that while the API documentation is helpful, we need to see the actual Nova API service code that implements shelving and unshelving. The contributor tutorial (linked in this PR) has examples here.
I've left a few other minor comments. Please let me know if you have any questions.
|
@jtopjian Thanks, I'll work on this later. |
39da48e to
3b1cde0
Compare
|
Build failed.
|
|
@qhua948 Thank you for digging up the API code - it's a pain, but it can sometimes identify areas that aren't reflected in the docs. For this PR, the docs match the API code, so the exercise feels moot, but there's been enough occasions worth the effort. It looks like the unshelve action can take an optional parameter of We'll then need to add a struct called No doubt that's a bit more work than you anticipated by wanting to add support for basic un/shelving. I can add the |
|
Build failed.
|
|
Thanks for pointing it out, for the sake of completeness, I should add that in as well. |
|
@qhua948 let me know if you need any help. A rough draft of the conditional logic is going to be something like: func (opts UnshelveOpts) ToShelveUnshelveMap() (map[string]interface{}, error) {
b, err := gophercloud.BuildRequestBody(opts, "")
if err != nil {
return nil, err
}
unshelveOpts := make(map[string]interface{})
if b["availability_zone"] != "" {
unshelveOpts["availability_zone"] = b["availability_zone"]
}
return unshelveOpts
}
func Unshelve(client *gophercloud.ServiceClient, id string, opts ShelveUnshelveOptsBuilder) (r UnshelveResult) {
b, err := opts.ToShelveUnshelveOpts()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(extensions.ActionURL(client, id), map[string]interface{}{"unshelve": b}, nil, nil)
return
}I might be wrong about |
c3b988b to
ee1d4d1
Compare
|
Build failed.
|
ee1d4d1 to
3100fb5
Compare
|
Build failed.
|
| ToUnshelveMap() (map[string]interface{}, error) | ||
| } | ||
|
|
||
| // ShelveOffloadOpts specifies parameters of shelve-offload action. |
| } | ||
|
|
||
| // ShelveOffloadOpts specifies parameters of shelve-offload action. | ||
| type UnshelvedOpts struct { |
There was a problem hiding this comment.
UnshelveOpts
minor nit: Unshelved implies actions after unshelving has happened.
| @@ -0,0 +1,24 @@ | |||
| /* | |||
| Package startstop provides functionality to start and stop servers that have | |||
|
|
||
| serverID := "47b6b7b7-568d-40e4-868c-d5c41735532e" | ||
|
|
||
| err := startstop.Shelve(computeClient, serverID).ExtractErr() |
There was a problem hiding this comment.
err := shelveunshelve.Shelve(computeClient, serverID).ExtractErr()| panic(err) | ||
| } | ||
|
|
||
| err := startstop.ShelveOffload(computeClient, serverID).ExtractErr() |
There was a problem hiding this comment.
err := shelveunshelve.ShelveOffload(computeClient, serverID).ExtractErr()
| panic(err) | ||
| } | ||
|
|
||
| err := startstop.Unshelve(computeClient, serverID).ExtractErr() |
There was a problem hiding this comment.
err := shelveunshelve.Unshelve(computeClient, serverID, nil).ExtractErr()
| AvailabilityZone string `json:"availability_zone,omitempty"` | ||
| } | ||
|
|
||
| func (opts UnshelvedOpts) ToUnshelveMap() (map[string]interface{}, error) { |
There was a problem hiding this comment.
Note for posterity if anyone comes across this:
Our usual naming pattern of To-Package-Action-Map doesn't work well here. ToShelveUnshelveUnshelveMap just looks weird.
ToUnshelveMap is fine.
|
Build failed.
|
Prior to starting a PR, please make sure you have read our
contributor tutorial.
Prior to a PR being reviewed, there needs to be a Github issue that the PR
addresses. Replace the brackets and text below with that issue number.
For #1798
Links to the line numbers/files in the OpenStack source code that support the
code in this PR:
https://docs.openstack.org/api-guide/compute/server_concepts.html
https://docs.openstack.org/api-ref/compute/?expanded=shelve-server-shelve-action-detail,unshelve-restore-shelved-server-unshelve-action-detail,shelf-offload-remove-server-shelveoffload-action-detail
Controllers
https://github.com/openstack/nova/blob/17b5a1ab85c358a1096788371849f0cccfe84972/nova/api/openstack/compute/shelve.py#L40
https://github.com/openstack/nova/blob/17b5a1ab85c358a1096788371849f0cccfe84972/nova/api/openstack/compute/shelve.py#L60
https://github.com/openstack/nova/blob/17b5a1ab85c358a1096788371849f0cccfe84972/nova/api/openstack/compute/shelve.py#L78
https://github.com/openstack/nova/blob/c6218428e9b29a2c52808ec7d27b4b21aadc0299/nova/compute/instance_actions.py#49
APIs
https://github.com/openstack/nova/blob/6695b5633ba34b758b7f742985bc21122acb2637/nova/compute/api.py#L3906
https://github.com/openstack/nova/blob/6695b5633ba34b758b7f742985bc21122acb2637/nova/compute/api.py#L3930
https://github.com/openstack/nova/blob/6695b5633ba34b758b7f742985bc21122acb2637/nova/compute/api.py#L3994
https://github.com/openstack/nova/blob/c45d9da8d1c9b9e40a43965ea757a74015272ded/nova/compute/rpcapi.py#L1286
Schema
https://github.com/openstack/nova/blob/master/nova/api/openstack/compute/schemas/shelve.py