forked from ManageIQ/manageiq-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphysical_storages_controller.rb
40 lines (32 loc) · 1.33 KB
/
physical_storages_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module Api
class PhysicalStoragesController < BaseController
def refresh_resource(type, id, _data = nil)
raise BadRequestError, "Must specify an id for refreshing a #{type} resource" if id.blank?
ensure_resource_exists(type, id) if single_resource?
api_action(type, id) do |klass|
physical_storage = resource_search(id, type, klass)
api_log_info("Refreshing #{physical_storage_ident(physical_storage)}")
refresh_physical_storage(physical_storage)
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_storage(physical_storage)
method_name = "refresh_ems"
role = "ems_operations"
act_refresh(physical_storage, method_name, role)
rescue => err
action_result(false, err.to_s)
end
def physical_storage_ident(physical_storage)
"Physical Storage id:#{physical_storage.id} name:'#{physical_storage.name}'"
end
def act_refresh(physical_storage, method_name, role)
desc = "#{physical_storage_ident(physical_storage)} refreshing"
task_id = queue_object_action(physical_storage, desc, :method_name => method_name, :role => role)
action_result(true, desc, :task_id => task_id)
end
end
end