Skip to content

Commit

Permalink
add vms subcollection to providers
Browse files Browse the repository at this point in the history
  • Loading branch information
Jillian Tullo committed Sep 22, 2017
1 parent c83fca7 commit 5c8eafe
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/api/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ProvidersController < BaseController
include Subcollections::CloudTenants
include Subcollections::CustomAttributes
include Subcollections::LoadBalancers
include Subcollections::Vms

def create_resource(type, _id, data = {})
assert_id_not_specified(data, type)
Expand Down
1 change: 1 addition & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,7 @@
- :cloud_tenants
- :custom_attributes
- :load_balancers
- :vms
:collection_actions:
:get:
- :name: read
Expand Down
41 changes: 41 additions & 0 deletions spec/requests/providers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1144,4 +1144,45 @@ def gen_import_request
expect(response.parsed_body["data"]["provider_settings"]["kubernetes"]["proxy_settings"]["settings"]["http_proxy"]["label"]).to eq(N_('HTTP Proxy'))
end
end

context 'GET /api/providers/:id/vms' do
it 'returns the vms for a provider with an appropriate role' do
ems = FactoryGirl.create(:ext_management_system)
vm = FactoryGirl.create(:vm_amazon, :ext_management_system => ems)
api_basic_authorize action_identifier(:providers, :read, :resource_actions, :get)

get(api_provider_vms_url(nil, ems))

expected = {
'name' => 'vms',
'subcount' => 1,
'resources' => [
{'href' => api_provider_vm_url(nil, ems, vm)}
]
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end

it 'allows for expansion of vms on a provider' do
ems = FactoryGirl.create(:ext_management_system)
vm = FactoryGirl.create(:vm_amazon, :ext_management_system => ems)
api_basic_authorize collection_action_identifier(:providers, :read, :get)
get(api_providers_url, :params => { :expand => 'resources,vms' })

expected = {
'name' => 'providers',
'resources' => [
a_hash_including(
'href' => api_provider_url(nil, ems),
'vms' => [
a_hash_including('href' => api_provider_vm_url(nil, ems, vm))
]
)
]
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end
end
end

0 comments on commit 5c8eafe

Please sign in to comment.