forked from theforeman/foreman
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes theforeman#4250 - API v2 - add compute profiles
- Loading branch information
Joseph Magen
authored and
Dominic Cleal
committed
May 12, 2014
1 parent
17c95ca
commit 10ac97b
Showing
18 changed files
with
234 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module Api | ||
module V2 | ||
class ComputeAttributesController < V2::BaseController | ||
|
||
before_filter :find_resource, :only => :update | ||
|
||
def_param_group :compute_attribute do | ||
param :compute_attribute, Hash, :action_aware => true do | ||
param :vm_attrs, Hash, :required => true | ||
end | ||
end | ||
|
||
api :POST, "/compute_resources/:compute_resource_id/compute_profiles/:compute_profile_id/compute_attributes", "Create a compute attribute" | ||
api :POST, "/compute_profiles/:compute_profile_id/compute_resources/:compute_resource_id/compute_attributes", "Create a compute attribute" | ||
api :POST, "/compute_resources/:compute_resource_id/compute_attributes", "Create a compute attribute" | ||
api :POST, "/compute_profiles/:compute_profile_id/compute_attributes", "Create a compute attribute" | ||
api :POST, "/compute_attributes/", "Create a compute attribute." | ||
param :compute_profile_id, :identifier, :required => true | ||
param :compute_resource_id, :identifier, :required => true | ||
param_group :compute_attribute, :as => :create | ||
|
||
def create | ||
params[:compute_attribute].merge!(:compute_profile_id => params[:compute_profile_id], | ||
:compute_resource_id => params[:compute_resource_id]) | ||
@compute_attribute = ComputeAttribute.create!(params[:compute_attribute]) | ||
render :json => @compute_attribute.to_json | ||
end | ||
|
||
api :PUT, "/compute_resources/:compute_resource_id/compute_profiles/:compute_profile_id/compute_attributes/:id", "Update a compute attribute" | ||
api :PUT, "/compute_profiles/:compute_profile_id/compute_resources/:compute_resource_id/compute_attributes/:id", "Update a compute attribute" | ||
api :PUT, "/compute_resources/:compute_resource_id/compute_attributes/:id", "Update a compute attribute" | ||
api :PUT, "/compute_profiles/:compute_profile_id/compute_attributes/:id", "Update a compute attribute" | ||
api :PUT, "/compute_attributes/:id", "Update a compute attribute." | ||
|
||
param :compute_profile_id, :identifier, :required => false | ||
param :compute_resource_id, :identifier, :required => false | ||
param :id, String, :required => true | ||
param_group :compute_attribute | ||
|
||
def update | ||
process_response @compute_attribute.update_attributes(params[:compute_attribute]) | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module Api | ||
module V2 | ||
class ComputeProfilesController < V2::BaseController | ||
before_filter :find_resource, :only => [:show, :update, :destroy] | ||
|
||
api :GET, "/compute_profiles", "List of compute profiles" | ||
param :search, String, :desc => "filter results" | ||
param :order, String, :desc => "sort results" | ||
param :page, String, :desc => "paginate results" | ||
param :per_page, String, :desc => "number of entries per request" | ||
|
||
def index | ||
@compute_profiles = ComputeProfile.authorized(:view_config_profiles). | ||
search_for(*search_options).paginate(paginate_options) | ||
end | ||
|
||
api :GET, "/compute_profiles/:id/", "Show a compute profile." | ||
param :id, :identifier, :required => true | ||
|
||
def show | ||
end | ||
|
||
def_param_group :compute_profile do | ||
param :compute_profile, Hash, :action_aware => true do | ||
param :name, String, :required => true | ||
end | ||
end | ||
|
||
api :POST, "/compute_profiles/", "Create a compute profile." | ||
param_group :compute_profile, :as => :create | ||
|
||
def create | ||
@compute_profile = ComputeProfile.new(params[:compute_profile]) | ||
process_response @compute_profile.save | ||
end | ||
|
||
api :PUT, "/compute_profiles/:id/", "Update a compute profile." | ||
param :id, String, :required => true | ||
param_group :compute_profile | ||
|
||
def update | ||
process_response @compute_profile.update_attributes(params[:compute_profile]) | ||
end | ||
|
||
api :DELETE, "/compute_profiles/:id/", "Delete a compute profile." | ||
param :id, String, :required => true | ||
|
||
def destroy | ||
process_response @compute_profile.destroy | ||
end | ||
|
||
end | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
object @compute_attribute | ||
|
||
attributes :id, :name, :compute_resource_id, :compute_resource_name, | ||
:compute_profile_id, :compute_profile_name, :vm_attrs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
collection @compute_attributes | ||
|
||
extends "api/v2/compute_attributes/main" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
object @compute_attribute | ||
|
||
extends "api/v2/compute_attributes/base" | ||
|
||
attributes :created_at, :updated_at |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
object @compute_attribute | ||
|
||
extends "api/v2/compute_attributes/main" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
object @compute_profile | ||
|
||
attributes :id, :name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
collection @compute_profiles | ||
|
||
extends "api/v2/compute_profiles/main" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
object @compute_profile | ||
|
||
extends "api/v2/compute_profiles/base" | ||
|
||
attributes :created_at, :updated_at |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
object @compute_profile | ||
|
||
extends "api/v2/compute_profiles/main" | ||
|
||
child :compute_attributes do | ||
extends "api/v2/compute_attributes/base" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
test/functional/api/v2/compute_attributes_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'test_helper' | ||
|
||
class Api::V2::ComputeAttributesControllerTest < ActionController::TestCase | ||
|
||
test "should create compute attribute" do | ||
assert_difference('ComputeAttribute.count') do | ||
valid_attrs = {:vm_attrs => {"cpus"=>"2", "memory"=>"2147483648"}} | ||
post :create, {:compute_attribute => valid_attrs, | ||
:compute_profile_id => compute_profiles(:three).id, | ||
:compute_resource_id => compute_resources(:one).id | ||
} | ||
end | ||
assert_response :success | ||
end | ||
|
||
test "should update compute attribute" do | ||
valid_attrs = {:vm_attrs => {"cpus"=>"4"}} | ||
put :update, { :id => compute_attributes(:two).id, | ||
:compute_profile_id => compute_profiles(:one).id, | ||
:compute_resource_id =>compute_resources(:one).id, | ||
:compute_attribute => valid_attrs | ||
} | ||
assert_response :success | ||
assert_equal "4", compute_attributes(:two).reload.vm_attrs[:cpus] | ||
end | ||
|
||
end |
39 changes: 39 additions & 0 deletions
39
test/functional/api/v2/compute_profiles_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require 'test_helper' | ||
|
||
class Api::V2::ComputeProfilesControllerTest < ActionController::TestCase | ||
|
||
test "should get index" do | ||
get :index, { } | ||
assert_response :success | ||
assert_not_nil assigns(:compute_profiles) | ||
compute_profiles = ActiveSupport::JSON.decode(@response.body) | ||
assert !compute_profiles.empty? | ||
end | ||
|
||
test "should show individual record" do | ||
get :show, { :id => compute_profiles(:one).to_param } | ||
assert_response :success | ||
show_response = ActiveSupport::JSON.decode(@response.body) | ||
assert !show_response.empty? | ||
end | ||
|
||
test "should create compute profile" do | ||
assert_difference('ComputeProfile.count') do | ||
post :create, { :compute_profile => {:name => '4-Xlarge'} } | ||
end | ||
assert_response :success | ||
end | ||
|
||
test "should update compute_profile" do | ||
put :update, { :id => compute_profiles(:one).to_param, :compute_profile => {:name => 'new name' } } | ||
assert_response :success | ||
end | ||
|
||
test "should destroy compute profile" do | ||
assert_difference('ComputeProfile.count', -1) do | ||
delete :destroy, { :id => compute_profiles(:three).to_param } | ||
end | ||
assert_response :success | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters