Revision e669d488
Added by Michael Alves Lobo over 8 years ago
app/controllers/api/v2/compute_resources_controller.rb | ||
---|---|---|
include Api::TaxonomyScope
|
||
|
||
before_filter :find_resource, :only => [:show, :update, :destroy, :available_images, :associate,
|
||
:available_clusters, :available_folders, :available_networks,
|
||
:available_resource_pools, :available_storage_domains]
|
||
:available_clusters, :available_flavors, :available_folders,
|
||
:available_networks, :available_resource_pools, :available_security_groups, :available_storage_domains,
|
||
:available_zones]
|
||
|
||
api :GET, "/compute_resources/", N_("List all compute resources")
|
||
param_group :taxonomy_scope, ::Api::V2::BaseController
|
||
... | ... | |
render :available_clusters, :layout => 'api/v2/layouts/index_layout'
|
||
end
|
||
|
||
api :GET, "/compute_resources/:id/available_flavors", N_("List available flavors for a compute resource")
|
||
param :id, :identifier, :required => true
|
||
def available_flavors
|
||
@available_flavors = @compute_resource.available_flavors
|
||
render :available_flavors, :layout => 'api/v2/layouts/index_layout'
|
||
end
|
||
|
||
api :GET, "/compute_resources/:id/available_folders", N_("List available folders for a compute resource")
|
||
param :id, :identifier, :required => true
|
||
def available_folders
|
||
... | ... | |
render :available_folders, :layout => 'api/v2/layouts/index_layout'
|
||
end
|
||
|
||
api :GET, "/compute_resources/:id/available_zones", N_("List available zone for a compute resource")
|
||
param :id, :identifier, :required => true
|
||
def available_zones
|
||
@available_zones = @compute_resource.available_zones
|
||
render :available_zones, :layout => 'api/v2/layouts/index_layout'
|
||
end
|
||
|
||
api :GET, "/compute_resources/:id/available_networks", N_("List available networks for a compute resource")
|
||
api :GET, "/compute_resources/:id/available_clusters/:cluster_id/available_networks", N_("List available networks for a compute resource cluster")
|
||
param :id, :identifier, :required => true
|
||
... | ... | |
render :available_storage_domains, :layout => 'api/v2/layouts/index_layout'
|
||
end
|
||
|
||
api :GET, "/compute_resources/:id/available_security_groups", N_("List available security groups for a compute resource")
|
||
param :id, :identifier, :required => true
|
||
def available_security_groups
|
||
@available_security_groups = @compute_resource.available_security_groups
|
||
render :available_security_groups, :layout => 'api/v2/layouts/index_layout'
|
||
end
|
||
|
||
api :PUT, "/compute_resources/:id/associate/", N_("Associate VMs to Hosts")
|
||
param :id, :identifier, :required => true
|
||
def associate
|
||
... | ... | |
|
||
def action_permission
|
||
case params[:action]
|
||
when 'available_images', 'available_clusters', 'available_folders', 'available_networks', 'available_resource_pools', 'available_storage_domains', 'associate'
|
||
when 'available_images', 'available_clusters', 'available_flavors', 'available_folders', 'available_networks', 'available_resource_pools', 'available_security_groups', 'available_storage_domains', 'available_zones', 'associate'
|
||
:view
|
||
else
|
||
super
|
app/models/compute_resource.rb | ||
---|---|---|
false
|
||
end
|
||
|
||
def available_zones
|
||
raise ::Foreman::Exception.new(N_("Not implemented for %s"), provider_friendly_name)
|
||
end
|
||
|
||
def available_images
|
||
[]
|
||
end
|
||
... | ... | |
raise ::Foreman::Exception.new(N_("Not implemented for %s"), provider_friendly_name)
|
||
end
|
||
|
||
def available_flavors
|
||
raise ::Foreman::Exception.new(N_("Not implemented for %s"), provider_friendly_name)
|
||
end
|
||
|
||
def available_resource_pools
|
||
raise ::Foreman::Exception.new(N_("Not implemented for %s"), provider_friendly_name)
|
||
end
|
||
|
||
def available_security_groups
|
||
raise ::Foreman::Exception.new(N_("Not implemented for %s"), provider_friendly_name)
|
||
end
|
||
|
||
def available_storage_domains(storage_domain = nil)
|
||
raise ::Foreman::Exception.new(N_("Not implemented for %s"), provider_friendly_name)
|
||
end
|
app/models/compute_resources/foreman/model/ec2.rb | ||
---|---|---|
has_one :key_pair, :foreign_key => :compute_resource_id, :dependent => :destroy
|
||
|
||
delegate :flavors, :subnets, :to => :client
|
||
delegate :security_groups, :flavors, :zones, :to => :self, :prefix => 'available'
|
||
validates :user, :password, :presence => true
|
||
|
||
after_create :setup_key_pair
|
app/services/foreman/access_permissions.rb | ||
---|---|---|
map.permission :view_compute_resources, {:compute_resources => [:index, :show, :auto_complete_search, :ping, :available_images],
|
||
:"api/v1/compute_resources" => [:index, :show],
|
||
:"api/v2/compute_resources" => [:index, :show, :available_images, :available_clusters, :available_folders,
|
||
:available_networks, :available_resource_pools, :available_storage_domains]
|
||
:available_flavors, :available_networks, :available_resource_pools,
|
||
:available_security_groups, :available_storage_domains, :available_zones]
|
||
}
|
||
map.permission :create_compute_resources, {:compute_resources => [:new, :create].push(*ajax_actions),
|
||
:"api/v1/compute_resources" => [:create],
|
app/views/api/v2/compute_resources/available_flavors.rabl | ||
---|---|---|
collection @available_flavors
|
||
|
||
attribute :name, :id
|
app/views/api/v2/compute_resources/available_security_groups.rabl | ||
---|---|---|
collection @available_security_groups
|
||
|
||
attribute :name, :group_id
|
app/views/api/v2/compute_resources/available_zones.rabl | ||
---|---|---|
collection @available_zones, root_object: false
|
||
|
||
node :name do |name|
|
||
name
|
||
end
|
config/routes/api/v2.rb | ||
---|---|---|
get :available_images, :on => :member
|
||
get :available_clusters, :on => :member
|
||
get :available_folders, :on => :member
|
||
get :available_flavors, :on => :member
|
||
get :available_networks, :on => :member
|
||
get :available_security_groups, :on => :member
|
||
get :available_storage_domains, :on => :member
|
||
get 'available_storage_domains/(:storage_domain)', :to => 'compute_resources#available_storage_domains', :on => :member
|
||
get 'available_clusters/(:cluster_id)/available_networks', :to => 'compute_resources#available_networks', :on => :member
|
||
get 'available_clusters/(:cluster_id)/available_resource_pools', :to => 'compute_resources#available_resource_pools', :on => :member
|
||
get :available_zones, :on => :member
|
||
put :associate, :on => :member
|
||
(resources :locations, :only => [:index, :show]) if SETTINGS[:locations_enabled]
|
||
(resources :organizations, :only => [:index, :show]) if SETTINGS[:organizations_enabled]
|
test/functional/api/v2/compute_resources_controller_test.rb | ||
---|---|---|
assert !available_storage_domains.empty?
|
||
end
|
||
|
||
context 'ec2' do
|
||
setup do
|
||
@ec2_object = Object.new
|
||
@ec2_object.stubs(:name).returns('test_ec2_object')
|
||
end
|
||
|
||
teardown do
|
||
assert_response :success
|
||
available_objects = ActiveSupport::JSON.decode(@response.body)
|
||
assert_not_empty available_objects
|
||
end
|
||
|
||
test "should get available flavors" do
|
||
@ec2_object.stubs(:id).returns('123')
|
||
Foreman::Model::EC2.any_instance.stubs(:available_flavors).returns([@ec2_object])
|
||
get :available_flavors, { :id => compute_resources(:ec2).to_param }
|
||
end
|
||
|
||
test "should get available security groups" do
|
||
@ec2_object.stubs(:group_id).returns('123')
|
||
Foreman::Model::EC2.any_instance.stubs(:available_security_groups).returns([@ec2_object])
|
||
get :available_security_groups, { :id => compute_resources(:ec2).to_param }
|
||
end
|
||
|
||
test "should get available zones" do
|
||
Foreman::Model::EC2.any_instance.stubs(:available_zones).returns(['test_ec2_object'])
|
||
get :available_zones, { :id => compute_resources(:ec2).to_param }
|
||
end
|
||
end
|
||
|
||
context 'vmware' do
|
||
setup do
|
||
@vmware_object = Object.new
|
Also available in: Unified diff
Fixes #3650, #11600 - Compute Resource availability_zones, flavors, security_groups API v2 endpoints