Project

General

Profile

Download (3.47 KB) Statistics
| Branch: | Tag: | Revision:
aa2cd9f2 Joseph Mitchell Magen
module Api
module V2
21bf889a Joseph Mitchell Magen
class PuppetclassesController < V2::BaseController
aa2cd9f2 Joseph Mitchell Magen
include Api::Version2
include Api::TaxonomyScope

21bf889a Joseph Mitchell Magen
before_filter :find_resource, :only => %w{show update destroy}
885dd246 Joseph Magen
before_filter :find_optional_nested_object, :only => [:index, :show]
aa2cd9f2 Joseph Mitchell Magen
api :GET, "/puppetclasses/", "List all puppetclasses."
api :GET, "/hosts/:host_id/puppetclasses", "List all puppetclasses for host"
api :GET, "/hostgroups/:hostgroup_id/puppetclasses", "List all puppetclasses for hostgroup"
api :GET, "/environments/:environment_id/puppetclasses", "List all puppetclasses for environment"
param :host_id, String, :desc => "id of nested host"
param :hostgroup_id, String, :desc => "id of nested hostgroup"
param :environment_id, String, :desc => "id of nested environment"
21bf889a Joseph Mitchell Magen
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"
aa2cd9f2 Joseph Mitchell Magen
def index
acfbc458 Marek Hulan
values = Puppetclass.authorized(:view_puppetclasses).search_for(*search_options) unless nested_obj
21bf889a Joseph Mitchell Magen
values ||= case nested_obj
when Host::Base, Hostgroup
#NOTE: no search_for on array generated by all_puppetclasses
nested_obj.all_puppetclasses
else
nested_obj.puppetclasses.search_for(*search_options)
end
92b7b44d Joseph Magen
@total = Puppetclass.count unless nested_obj
@total ||= case nested_obj
when Host::Base, Hostgroup
values.count
else
nested_obj.puppetclasses.count
end
@subtotal = values.count
@puppetclasses = Puppetclass.classes2hash_v2(values.paginate(paginate_options))
aa2cd9f2 Joseph Mitchell Magen
end

api :GET, "/puppetclasses/:id", "Show a puppetclass"
api :GET, "/hosts/:host_id/puppetclasses/:id", "Show a puppetclass for host"
api :GET, "/hostgroups/:hostgroup_id/puppetclasses/:id", "Show a puppetclass for hostgroup"
api :GET, "/environments/:environment_id/puppetclasses/:id", "Show a puppetclass for environment"
param :host_id, String, :desc => "id of nested host"
param :hostgroup_id, String, :desc => "id of nested hostgroup"
param :environment_id, String, :desc => "id of nested environment"
param :id, String, :required => true, :desc => "id of puppetclass"

def show
end

2be84f3d Joseph Magen
def_param_group :puppetclass do
param :puppetclass, Hash, :action_aware => true do
param :name, String, :required => true
end
21bf889a Joseph Mitchell Magen
end

2be84f3d Joseph Magen
api :POST, "/puppetclasses/", "Create a puppetclass."
param_group :puppetclass, :as => :create

21bf889a Joseph Mitchell Magen
def create
@puppetclass = Puppetclass.new(params[:puppetclass])
process_response @puppetclass.save
end

api :PUT, "/puppetclasses/:id/", "Update a puppetclass."
param :id, String, :required => true
2be84f3d Joseph Magen
param_group :puppetclass
21bf889a Joseph Mitchell Magen
def update
process_response @puppetclass.update_attributes(params[:puppetclass])
end

api :DELETE, "/puppetclasses/:id/", "Delete a puppetclass."
param :id, String, :required => true

def destroy
process_response @puppetclass.destroy
end

private

c1a23d77 Joseph Mitchell Magen
def allowed_nested_id
%w(environment_id host_id hostgroup_id)
aa2cd9f2 Joseph Mitchell Magen
end

end
end
end