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

Add create action for templates #337

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/controllers/api/subcollections/cloud_templates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ def cloud_templates_query_resource(object)
object.vms_and_templates.where(:template => true)
end

def cloud_templates_create_resource(parent, _type, _id, data)
task_id = ManageIQ::Providers::CloudManager::Template.create_image_queue(User.current_user.id, parent, data)
action_result(true, 'Creating Image', :task_id => task_id)
rescue => err
action_result(false, err.to_s)
end

def cloud_templates_delete_resource(_parent, type, id, _data)
image = resource_search(id, type, collection_class(type))
task_id = image.delete_image_queue(User.current_user.id)
Expand Down
2 changes: 2 additions & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@
- :name: read
:identifier: image_show_list
:post:
- :name: create
:identifier: image_create
- :name: delete
:identifier: image_delete
:subresource_actions:
Expand Down
31 changes: 31 additions & 0 deletions spec/requests/cloud_templates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,37 @@
end
end

describe "POST /api/providers/:c_id/cloud_templates" do
it "can queue the creation of an images" do
api_basic_authorize(action_identifier(:cloud_templates, :create, :subcollection_actions))
ems = FactoryGirl.create(:ems_cloud)

post(api_provider_cloud_templates_url(nil, ems), :params => { :name => "test-image", :vendor => "test-cloud", :location => "test-location" })

expected = {
"results" => [
a_hash_including(
"success" => true,
"message" => "Creating Image",
"task_id" => anything,
"task_href" => a_string_matching(api_tasks_url)
)
]
}
expect(response.parsed_body).to include(expected)
expect(response).to have_http_status(:ok)
end

it "will not create an image unless authorized" do
api_basic_authorize
ems = FactoryGirl.create(:ems_cloud)

post(api_provider_cloud_templates_url(nil, ems), :params => { :name => "test-image" })

expect(response).to have_http_status(:forbidden)
end
end

describe "DELETE /api/providers/:c_id/cloud_templates/:id" do
it "can delete an image" do
api_basic_authorize(action_identifier(:cloud_templates, :delete, :subresource_actions, :delete))
Expand Down