-
Notifications
You must be signed in to change notification settings - Fork 141
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
[WIP] Attach detach cloud volume api #1141
Conversation
b334134
to
c4e0c87
Compare
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.
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.
raise BadRequestError, "Must specify a vm_id" if data["vm_id"].nil? | ||
|
||
api_resource(type, id, "Attaching Resource", :supports => :attach_volume) do |cloud_volume| |
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.
@agrare What do we want to do in cases like this?
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) |
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.
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))}
?
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.
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
86f1bfa
to
209e14b
Compare
5c3968e
to
f8f0d49
Compare
f8f0d49
to
6a4e619
Compare
spec/requests/cloud_volumes_spec.rb
Outdated
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) |
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.
If you don't need to use disk
later on you just need the record you could do
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
a632f87
to
5a9fc27
Compare
72f3796
to
40b2ead
Compare
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)} |
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.
@MelsHyrule we'll also need an optional device
parameter here:
{: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
spec/requests/cloud_volumes_spec.rb
Outdated
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) |
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.
stub_supports(cloud_volume.class, :attach) | |
stub_supports(cloud_volume.class, :attach_volume) |
spec/requests/cloud_volumes_spec.rb
Outdated
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) |
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.
stub_supports(cloud_volume.class, :detach) | |
stub_supports(cloud_volume.class, :detach_volume) |
ae95f14
to
a73085b
Compare
@kbrock you want to give a second set of 👀 |
4c92076
to
fd8cef4
Compare
eb40b49
to
f5f6f2f
Compare
a54725b
to
d6f3678
Compare
type = @req.collection.to_sym | ||
base_klass = collection_class(type) | ||
|
||
ems = resource_search(ems_id, :providers) |
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.
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" |
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.
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) |
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.
Could we send("render_#{action}_resource_options(id)")
instead? Then we would localize the methods to the controller that has those actions
Checked commits MelsHyrule/manageiq-api@d6f3678~...1e867c6 with ruby 2.6.9, rubocop 1.19.1, haml-lint 0.35.0, and yamllint app/controllers/api/base_controller/renderer.rb
|
@MelsHyrule I was good with tackling the |
This pull request is not mergeable. Please rebase and repush. |
@MelsHyrule merged #1147 if you want to build on that |
With changes from #1147 this PR is no longer needed, closing now. |
Fixes:
dependent upon:
Required for upgrading _attach.html.haml and _detach.html.haml
Introduces the attach_resource and detach_resource endpoints for cloud volumes.