Skip to content

Added Shelve, Shelve-offload and Unshelve API#1799

Merged
jtopjian merged 4 commits intogophercloud:masterfrom
qhua948:shelve-unshelve
Dec 11, 2019
Merged

Added Shelve, Shelve-offload and Unshelve API#1799
jtopjian merged 4 commits intogophercloud:masterfrom
qhua948:shelve-unshelve

Conversation

@qhua948
Copy link
Copy Markdown
Contributor

@qhua948 qhua948 commented Dec 10, 2019

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

@qhua948 qhua948 changed the title Added Shelve, Shelve-offload and Unshelve API [WIP] Added Shelve, Shelve-offload and Unshelve API Dec 10, 2019
@coveralls
Copy link
Copy Markdown

coveralls commented Dec 10, 2019

Coverage Status

Coverage decreased (-0.03%) to 76.968% when pulling 231b8a5 on qhua948:shelve-unshelve into 7aa2e52 on gophercloud:master.

@qhua948 qhua948 changed the title [WIP] Added Shelve, Shelve-offload and Unshelve API Added Shelve, Shelve-offload and Unshelve API Dec 10, 2019
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Dec 10, 2019

Build failed.

@qhua948
Copy link
Copy Markdown
Contributor Author

qhua948 commented Dec 10, 2019

recheck

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Dec 10, 2019

Build failed.

Copy link
Copy Markdown
Contributor

@jtopjian jtopjian left a comment

Choose a reason for hiding this comment

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

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

@qhua948
Copy link
Copy Markdown
Contributor Author

qhua948 commented Dec 10, 2019

@jtopjian Thanks, I'll work on this later.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Dec 10, 2019

Build failed.

@jtopjian
Copy link
Copy Markdown
Contributor

jtopjian commented Dec 10, 2019

@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 availability_zone:

https://github.com/openstack/nova/blob/17b5a1ab85c358a1096788371849f0cccfe84972/nova/api/openstack/compute/shelve.py#L79-L81

We'll then need to add a struct called UnshelveOpts with AvailabilityZone field. Then we'll need to make sure the struct is conditionally sent only if it's specified, and null when not, in order to be backwards compatible.

No doubt that's a bit more work than you anticipated by wanting to add support for basic un/shelving. I can add the AvailabilityZone feature after this PR is merged. Just a heads up that the function signature for Unshelve will be changed shortly after this is merged, in case you wanted to use this feature right away.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Dec 10, 2019

Build failed.

@qhua948
Copy link
Copy Markdown
Contributor Author

qhua948 commented Dec 10, 2019

Thanks for pointing it out, for the sake of completeness, I should add that in as well.

@jtopjian
Copy link
Copy Markdown
Contributor

@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 make, though - a unit test will confirm if that will end up sending nil or {}.

@qhua948
Copy link
Copy Markdown
Contributor Author

qhua948 commented Dec 10, 2019

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Dec 11, 2019

Build failed.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Dec 11, 2019

Build failed.

@qhua948 qhua948 requested a review from jtopjian December 11, 2019 03:25
Copy link
Copy Markdown
Contributor

@jtopjian jtopjian left a comment

Choose a reason for hiding this comment

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

@qhua948 This looks really good - thank you for your work and patience.

Just a few minor fixes and this is good to go.

ToUnshelveMap() (map[string]interface{}, error)
}

// ShelveOffloadOpts specifies parameters of shelve-offload action.
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.

UnshelveOpts

}

// ShelveOffloadOpts specifies parameters of shelve-offload action.
type UnshelvedOpts 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.

UnshelveOpts

minor nit: Unshelved implies actions after unshelving has happened.

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.

Indeed!

@@ -0,0 +1,24 @@
/*
Package startstop provides functionality to start and stop servers that have
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.

shelveunshelve


serverID := "47b6b7b7-568d-40e4-868c-d5c41735532e"

err := startstop.Shelve(computeClient, serverID).ExtractErr()
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.

err := shelveunshelve.Shelve(computeClient, serverID).ExtractErr()

panic(err)
}

err := startstop.ShelveOffload(computeClient, serverID).ExtractErr()
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.

err := shelveunshelve.ShelveOffload(computeClient, serverID).ExtractErr()

panic(err)
}

err := startstop.Unshelve(computeClient, serverID).ExtractErr()
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.

err := shelveunshelve.Unshelve(computeClient, serverID, nil).ExtractErr()

AvailabilityZone string `json:"availability_zone,omitempty"`
}

func (opts UnshelvedOpts) ToUnshelveMap() (map[string]interface{}, 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.

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.

@qhua948 qhua948 requested a review from jtopjian December 11, 2019 19:46
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Dec 11, 2019

Build failed.

Copy link
Copy Markdown
Contributor

@jtopjian jtopjian left a comment

Choose a reason for hiding this comment

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

LGTM - thank you!

@jtopjian jtopjian merged commit bfa5322 into gophercloud:master Dec 11, 2019
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.

3 participants