forked from ManageIQ/manageiq-ui-classic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloud_object_store_container_controller.rb
155 lines (133 loc) · 4.52 KB
/
cloud_object_store_container_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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
class CloudObjectStoreContainerController < ApplicationController
before_action :check_privileges
before_action :get_session_data
after_action :cleanup_action
after_action :set_session_data
include Mixins::GenericListMixin
include Mixins::GenericShowMixin
include Mixins::GenericSessionMixin
include Mixins::GenericFormMixin
include Mixins::BreadcrumbsMixin
def breadcrumb_name(_model)
_('Cloud Object Store Containers')
end
# handle buttons pressed on the button bar
def button
@edit = session[:edit] # Restore @edit for adv search box
params[:page] = @current_page unless @current_page.nil? # Save current page for list refresh
case params[:pressed]
when "cloud_object_store_container_new"
return javascript_redirect(:action => "new")
when "custom_button"
custom_buttons
return
else
process_cloud_object_storage_buttons(params[:pressed])
end
if params[:pressed].ends_with?("delete")
delete_action
else
render_flash unless @flash_array.nil? || performed?
end
end
def self.display_methods
%w[cloud_object_store_objects custom_button_events]
end
def new
assert_privileges("cloud_object_store_container_new")
@in_a_form = true
if params[:storage_manager_id]
@storage_manager = find_record_with_rbac(ExtManagementSystem, params[:storage_manager_id])
end
@provider_regions = retrieve_provider_regions
drop_breadcrumb(
:name => _("Add New Cloud Object Store Container"),
:url => "/cloud_object_store_container/new"
)
end
def create
assert_privileges("cloud_object_store_container_new")
case params[:button]
when "cancel"
javascript_redirect previous_breadcrumb_url
when "add"
options = form_params_create
ext_management_system = options.delete(:ems)
# Queue task
task_id = CloudObjectStoreContainer.cloud_object_store_container_create_queue(
session[:userid],
ext_management_system,
options
)
if task_id.kind_of?(Integer)
initiate_wait_for_task(:task_id => task_id, :action => "create_finished")
else
add_flash(_("Cloud Object Store Container creation failed: Task start failed"), :error)
javascript_flash(:spinner_off => true)
end
end
end
def create_finished
task_id = session[:async][:params][:task_id]
container_name = session[:async][:params][:name]
task = MiqTask.find(task_id)
if MiqTask.status_ok?(task.status)
add_flash(_("Cloud Object Store Container \"%{name}\" created") % {
:name => container_name
})
else
add_flash(_("Unable to create Cloud Object Store Container \"%{name}\": %{details}") % {
:name => container_name,
:details => task.message
}, :error)
end
flash_to_session
javascript_redirect previous_breadcrumb_url
end
def form_params_create
options = {}
options[:name] = params[:name] if params[:name]
# Depending on the storage manager type, collect required form params.
case params[:emstype]
when "ManageIQ::Providers::Amazon::StorageManager::S3"
if params[:provider_region]
options[:create_bucket_configuration] = {
:location_constraint => params[:provider_region]
}
end
# Get the storage manager.
storage_manager_id = params[:storage_manager_id] if params[:storage_manager_id]
options[:ems] = find_record_with_rbac(ExtManagementSystem, storage_manager_id)
end
options
end
private
def record_class
params[:pressed].starts_with?('cloud_object_store_object') ? CloudObjectStoreObject : CloudObjectStoreContainer
end
def retrieve_provider_regions
managers = ManageIQ::Providers::CloudManager.supported_subclasses.select(&:supports_regions?)
managers.each_with_object({}) do |manager, provider_regions|
regions = manager.parent::Regions.all.sort_by { |r| r[:description] }
provider_regions[manager.name] = regions.map { |region| [region[:description], region[:name]] }
end
end
def textual_group_list
[%i[properties relationships], %i[tags]]
end
helper_method :textual_group_list
def breadcrumbs_options
{
:breadcrumbs => [
{:title => _("Storage")},
{:title => _("Object Storage")},
{:title => _("Object Store Containers")},
{:url => controller_url, :title => _("Cloud Object Store Containers")},
],
:record_info => @record,
:record_title => :key,
}.compact
end
menu_section :ost
has_custom_buttons
end