Skip to content
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

[WIP] Attach detach cloud volume api #1141

Closed

Conversation

MelsHyrule
Copy link
Member

@MelsHyrule MelsHyrule commented Mar 24, 2022

Fixes:

dependent upon:

Required for upgrading _attach.html.haml and _detach.html.haml

Introduces the attach_resource and detach_resource endpoints for cloud volumes.

@MelsHyrule MelsHyrule requested a review from bdunne as a code owner March 24, 2022 19:15
@miq-bot miq-bot added the wip label Mar 24, 2022
@MelsHyrule MelsHyrule force-pushed the attach-detach-cloud-volume-api branch 3 times, most recently from b334134 to c4e0c87 Compare March 31, 2022 16:12
Copy link
Member

@kbrock kbrock left a comment

Choose a reason for hiding this comment

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

Just rebase and make the same change to both controller actions:

  • move the check
  • add the word " to"
  • add the resource_search

This looks pretty good to go.

Comment on lines 52 to 54
raise BadRequestError, "Must specify a vm_id" if data["vm_id"].nil?

api_resource(type, id, "Attaching Resource", :supports => :attach_volume) do |cloud_volume|
Copy link
Member

Choose a reason for hiding this comment

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

@agrare What do we want to do in cases like this?

Suggested change
raise BadRequestError, "Must specify a vm_id" if data["vm_id"].nil?
api_resource(type, id, "Attaching Resource", :supports => :attach_volume) do |cloud_volume|
api_resource(type, id, "Attaching Resource to", :supports => :attach_volume) do |cloud_volume|
raise BadRequestError, "Must specify a vm_id" if data["vm_id"].blank?
resource_search(data["vm_id"], :vms)

Copy link
Member Author

Choose a reason for hiding this comment

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

should we update {:task_id => cloud_volume.detach_volume_queue(User.current_userid, data["vm_id"])} to be instead {:task_id => cloud_volume.detach_volume_queue(User.current_userid, resource_search(data["vm_id"], :vms))} ?

Copy link
Member

Choose a reason for hiding this comment

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

cloud_volume.attach_volume_queue takes an :ems_ref not an :id or Vm object, so you should lookup the VM like @kbrock's suggestion, then pass in vm.ems_ref

@MelsHyrule MelsHyrule force-pushed the attach-detach-cloud-volume-api branch 2 times, most recently from 86f1bfa to 209e14b Compare March 31, 2022 18:33
@MelsHyrule MelsHyrule requested review from kbrock and agrare March 31, 2022 18:33
@MelsHyrule MelsHyrule force-pushed the attach-detach-cloud-volume-api branch from 5c3968e to f8f0d49 Compare March 31, 2022 18:41
@MelsHyrule MelsHyrule force-pushed the attach-detach-cloud-volume-api branch from f8f0d49 to 6a4e619 Compare March 31, 2022 19:21
hw = FactoryBot.create(:hardware)
vm = FactoryBot.create(:vm_vmware, :hardware => hw)
cloud_volume = FactoryBot.create(:cloud_volume_autosde, :ext_management_system => ems)
disk = FactoryBot.create(:disk, :hardware => hw, :backing => cloud_volume)
Copy link
Member

Choose a reason for hiding this comment

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

If you don't need to use disk later on you just need the record you could do

Suggested change
disk = FactoryBot.create(:disk, :hardware => hw, :backing => cloud_volume)
FactoryBot.create(:disk, :hardware => hw, :backing => cloud_volume)

And then rubocop won't yell at you

@MelsHyrule MelsHyrule force-pushed the attach-detach-cloud-volume-api branch 2 times, most recently from a632f87 to 5a9fc27 Compare March 31, 2022 19:36
@MelsHyrule MelsHyrule requested a review from agrare March 31, 2022 19:38
@MelsHyrule MelsHyrule force-pushed the attach-detach-cloud-volume-api branch from 72f3796 to 40b2ead Compare March 31, 2022 19:39
@agrare agrare removed the unmergeable label Apr 1, 2022
raise BadRequestError, "Must specify a vm_id" if data["vm_id"].blank?

vm = resource_search(data["vm_id"], :vms)
{:task_id => cloud_volume.attach_volume_queue(User.current_userid, vm.ems_ref)}
Copy link
Member

Choose a reason for hiding this comment

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

@MelsHyrule we'll also need an optional device parameter here:

Suggested change
{:task_id => cloud_volume.attach_volume_queue(User.current_userid, vm.ems_ref)}
{:task_id => cloud_volume.attach_volume_queue(User.current_userid, vm.ems_ref, data["device"].presence)}

should do the trick

cloud_volume = FactoryBot.create(:cloud_volume_autosde, :ext_management_system => ems)

api_basic_authorize(action_identifier(:cloud_volumes, :attach, :resource_actions, :post))
stub_supports(cloud_volume.class, :attach)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
stub_supports(cloud_volume.class, :attach)
stub_supports(cloud_volume.class, :attach_volume)

FactoryBot.create(:disk, :hardware => hw, :backing => cloud_volume)

api_basic_authorize(action_identifier(:cloud_volumes, :detach, :resource_actions, :post))
stub_supports(cloud_volume.class, :detach)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
stub_supports(cloud_volume.class, :detach)
stub_supports(cloud_volume.class, :detach_volume)

@MelsHyrule MelsHyrule force-pushed the attach-detach-cloud-volume-api branch from ae95f14 to a73085b Compare April 1, 2022 15:21
@MelsHyrule MelsHyrule requested a review from agrare April 1, 2022 15:26
@agrare
Copy link
Member

agrare commented Apr 4, 2022

@kbrock you want to give a second set of 👀

@MelsHyrule MelsHyrule force-pushed the attach-detach-cloud-volume-api branch 2 times, most recently from 4c92076 to fd8cef4 Compare April 4, 2022 17:34
@MelsHyrule MelsHyrule force-pushed the attach-detach-cloud-volume-api branch from eb40b49 to f5f6f2f Compare April 4, 2022 17:37
@MelsHyrule MelsHyrule force-pushed the attach-detach-cloud-volume-api branch from a54725b to d6f3678 Compare April 4, 2022 17:40
type = @req.collection.to_sym
base_klass = collection_class(type)

ems = resource_search(ems_id, :providers)
Copy link
Member

Choose a reason for hiding this comment

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

ems may be nil

type = @req.collection.to_sym
resource = resource_search(id, type)
raise BadRequestError, resource.unsupported_reason(:update) unless resource.supports?(:update)

render_options(type, :form_schema => resource.params_for_update)
if action == "attach"
Copy link
Member

Choose a reason for hiding this comment

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

I don't think overriding the render_update_resource_options method is the way to go here

For example won't we not get here if we are looking for the "attach" action but the resource doesn't support "update" a totally different action? https://github.com/ManageIQ/manageiq-api/pull/1141/files#diff-48fb0a597ebc41e5c8c4fde22100d5577a08a07b84761152f69eaa2f580c4c37R555

Plus "update" is in the name, then we also have it handle other options

@@ -34,7 +34,8 @@ def delete_resource_main_action(_type, cloud_volume, _data)

def options
if (id = params["id"])
render_update_resource_options(id)
action = params["option_action"] || "update"
render_update_resource_options(id, action)
Copy link
Member

Choose a reason for hiding this comment

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

Could we send("render_#{action}_resource_options(id)") instead? Then we would localize the methods to the controller that has those actions

@miq-bot
Copy link
Member

miq-bot commented Apr 14, 2022

Checked commits MelsHyrule/manageiq-api@d6f3678~...1e867c6 with ruby 2.6.9, rubocop 1.19.1, haml-lint 0.35.0, and yamllint
4 files checked, 1 offense detected

app/controllers/api/base_controller/renderer.rb

@agrare
Copy link
Member

agrare commented Apr 18, 2022

@MelsHyrule I was good with tackling the params_for_attach in a separate PR (ManageIQ/manageiq-ui-classic#8205 (comment)) I think what you had prior to trying to add the OPTIONS call was good if you want to move forward with that and I think @kbrock is tackling a general way of dealing with action options in his other PR

@miq-bot
Copy link
Member

miq-bot commented Apr 20, 2022

This pull request is not mergeable. Please rebase and repush.

@agrare
Copy link
Member

agrare commented Apr 27, 2022

@MelsHyrule merged #1147 if you want to build on that

@MelsHyrule
Copy link
Member Author

With changes from #1147 this PR is no longer needed, closing now.

@MelsHyrule MelsHyrule closed this May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants