Skip to content
Browse files

api v1 - operatingsystems controller

  • Loading branch information...
1 parent 1443d37 commit c72a2f0f078850c23e355d9173157c1ebe574789 @tstrachota tstrachota committed with Jun 21, 2012
View
37 app/controllers/api/v1/operatingsystems_controller.rb
@@ -0,0 +1,37 @@
+module Api
+ module V1
+ class OperatingsystemsController < BaseController
+
+ before_filter :find_by_name, :only => %w{show edit update destroy bootfiles}
+
+ def index
+ @operatingsystems = Operatingsystem.all
+ end
+
+ def show
+ end
+
+ def create
+ @operatingsystem = Operatingsystem.new(params[:operatingsystem])
+ process_error unless @operatingsystem.save
+ end
+
+ def update
+ process_error unless @operatingsystem.update_attributes(params[:operatingsystem])
+ end
+
+ def destroy
+ process_error unless @operatingsystem.destroy
+ end
+
+ def bootfiles
+ medium = Medium.find_by_name(params[:medium])
+ arch = Architecture.find_by_name(params[:architecture])
+ render :json => @operatingsystem.pxe_files(medium, arch)
+ rescue => e
+ render :json => e.to_s, :status => :unprocessable_entity
+ end
+
+ end
+ end
+end
View
4 app/views/api/v1/operatingsystems/create.json.rabl
@@ -0,0 +1,4 @@
+object @operatingsystem
+
+extends "api/v1/operatingsystems/show"
+
View
3 app/views/api/v1/operatingsystems/index.json.rabl
@@ -0,0 +1,3 @@
+collection @operatingsystems
+
+extends "api/v1/operatingsystems/show"
View
3 app/views/api/v1/operatingsystems/show.json.rabl
@@ -0,0 +1,3 @@
+object @operatingsystem
+attributes :name, :id
+
View
6 config/routes.rb
@@ -285,6 +285,12 @@
scope :module => :v1, :constraints => ApiConstraints.new(:version => 1, :default => true) do
resources :bookmarks, :except => [:new, :edit]
resources :architectures, :except => [:new, :edit]
+ resources :operatingsystems, :except => [:new, :edit] do
+ member do
+ get 'bootfiles'
+ end
+ end
+
match '/', :to => 'home#index'
match 'status', :to => 'home#status', :as => "status"
end

0 comments on commit c72a2f0

Please sign in to comment.
Something went wrong with that request. Please try again.