Skip to content

Commit

Permalink
Creating a endpoint for a PhysicalRack to execute toolbar actions
Browse files Browse the repository at this point in the history
  • Loading branch information
felipedf committed May 30, 2018
1 parent 9d14322 commit 4c0cd6b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
33 changes: 33 additions & 0 deletions app/controllers/api/physical_racks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Api
class PhysicalRacksController < BaseController
def refresh_resource(type, id, _data = nil)
raise BadRequestError, "Must specify an id for refreshing a #{type} resource" unless id

ensure_resource_exists(type, id) if single_resource?

api_action(type, id) do |klass|
physical_rack = resource_search(id, type, klass)
api_log_info("Refreshing #{physical_rack_ident(physical_rack)}")
refresh_physical_rack(physical_rack)
end
end

private

def ensure_resource_exists(type, id)
raise NotFoundError, "#{type} with id:#{id} not found" unless collection_class(type).exists?(id)
end

def refresh_physical_rack(physical_rack)
desc = "#{physical_rack_ident(physical_rack)} refreshing"
task_id = queue_object_action(physical_rack, desc, :method_name => "refresh_ems", :role => "ems_operations")
action_result(true, desc, :task_id => task_id)
rescue => err
action_result(false, err.to_s)
end

def physical_rack_ident(physical_rack)
"Physical Rack id:#{physical_rack.id} name:'#{physical_rack.name}'"
end
end
end
24 changes: 24 additions & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,30 @@
:identifier: physical_server_turn_off_loc_led
- :name: apply_config_pattern
:identifier: physical_server_apply_config_pattern
:physical_racks:
:description: Physical Racks
:identifier: physical_rack
:options:
- :collection
:verbs: *gp
:klass: PhysicalRack
:subcollections:
:collection_actions:
:get:
- :name: read
:identifier: physical_rack_show_list
:post:
- :name: query
:identifier: physical_rack_show_list
- :name: refresh
:identifier: physical_rack_refresh
:resource_actions:
:get:
- :name: read
:identifier: physical_rack_show
:post:
- :name: refresh
:identifier: physical_rack_refresh
:physical_switches:
:description: Physical Switches
:identifier: physical_switch
Expand Down

0 comments on commit 4c0cd6b

Please sign in to comment.