Skip to content

Commit

Permalink
Add available sizes API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
01100010011001010110010101110000 committed Jun 15, 2017
1 parent 4a24637 commit d196a3e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- /compute_resources/:id/:region_id/available_sizes endpoint to list all sizes in an Azure region
### Fixed
- Apply .freeze to version constant
- Changelog hyperlink for to compare v1.1.1 to v1.2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ def available_resource_groups
render :available_resource_groups, :layout => 'api/v2/layouts/index_layout'
end

def available_sizes
compute_resource = ComputeResource.find_by_id(params[:id])
@available_sizes = compute_resource.vm_sizes(params[:region_id])
render :available_sizes, :layout => 'api/v2/layouts/index_layout'
end

def action_permission
case params[:action]
when 'available_resource_groups'
when 'available_resource_groups', 'available_sizes'
:view
else
super
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module HostsControllerExtensions
def sizes
if (azure_rm_resource = Image.unscoped.find_by_uuid(params[:image_id])).present?
resource = azure_rm_resource.compute_resource
render :json => resource.vm_sizes(params[:location_string])
render :json => resource.vm_sizes(params[:location_string]).map { |size| size.name }
else
no_sizes = _('The location you selected has no sizes associated with it')
render :json => "[\"#{no_sizes}\"]"
Expand All @@ -16,7 +16,7 @@ def subnets
azure_rm_image = Image.unscoped.find_by_uuid(params[:image_id])
if azure_rm_image.present?
azure_rm_resource = azure_rm_image.compute_resource
subnets = azure_rm_resource.subnets(params[:location])
subnets = azure_rm_resource.subnets(params[:location])
if subnets.present?
render :json => azure_rm_resource.subnets(params[:location])
else
Expand Down
6 changes: 1 addition & 5 deletions app/models/concerns/fog_extensions/azurerm/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ def initialize(options)
end

def list_available_sizes(location)
sizes = []
@compute_mgmt_client.virtual_machine_sizes.list(location).value().each do |vmsize|
sizes << vmsize.name
end
sizes
@compute_mgmt_client.virtual_machine_sizes.list(location).value()
end

def list_all_vms
Expand Down
3 changes: 3 additions & 0 deletions app/views/api/v2/compute_resources/available_sizes.rabl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
collection @available_sizes

attribute :name, :number_of_cores, :os_disk_size_in_mb, :resource_disk_size_in_mb, :memory_in_mb, :max_data_disk_count
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
scope "(:apiv)", :module => :v2, :defaults => { :apiv => 'v2' }, :apiv => /v1|v2/, :constraints => ApiConstraints.new(:version => 2, :default => true) do
resources :compute_resources, :except => [:new, :edit] do
get :available_resource_groups, :on => :member
get '(:region_id)/available_sizes', :to => 'compute_resources#available_sizes', :on => :member
end
end
end
Expand Down

0 comments on commit d196a3e

Please sign in to comment.