-
Notifications
You must be signed in to change notification settings - Fork 356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Physical server page #970
Physical server page #970
Changes from 26 commits
ca99b62
95edeb1
0ef30c0
d60cc0a
3c0e12f
8affee9
aa60337
92c7549
4feb863
7142a11
bef6016
471a4e2
fb91056
ea20828
0a3a4a3
4b2916a
7bb757a
7ad7e4b
019c7f4
fefe826
4d82e5d
5c0ef75
dc082d9
6d646bc
26de5af
4b08d75
87c39e4
f3c5a59
f069e05
19d23a1
f3f6bdc
9b82528
7e836c4
762d426
3f36681
8adb93b
301bb36
1c139d0
017ae3f
088fb68
0fc2547
4bfd07a
462f14f
13ee483
420a230
ee96de7
6e61f01
fd8c51e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,13 +44,6 @@ def set_ownership | |
if @explorer | ||
@sb[:explorer] = true | ||
ownership(ownership_items) | ||
if @ownershipitems.empty? | ||
add_flash(_('None of the selected items allow ownership changes'), :error) | ||
|
||
@refresh_div = "flash_msg_div" | ||
@refresh_partial = "layouts/flash_msg" | ||
return | ||
end | ||
else | ||
if role_allows?(:feature => "vm_ownership") | ||
drop_breadcrumb(:name => _("Set Ownership"), :url => "/vm_common/ownership") | ||
|
@@ -60,7 +53,6 @@ def set_ownership | |
end | ||
end | ||
end | ||
|
||
alias_method :image_ownership, :set_ownership | ||
alias_method :instance_ownership, :set_ownership | ||
alias_method :vm_ownership, :set_ownership | ||
|
@@ -84,7 +76,6 @@ def ownership(ownership_items = []) | |
drop_breadcrumb(:name => _("Set Ownership"), :url => "/vm_common/ownership") | ||
ownership_items = params[:rec_ids] if params[:rec_ids] | ||
build_ownership_info(ownership_items) | ||
return if @ownershipitems.empty? | ||
build_targets_hash(@ownershipitems) | ||
if @sb[:explorer] | ||
@refresh_partial = "shared/views/ownership" | ||
|
@@ -108,10 +99,8 @@ def build_ownership_info(ownership_items) | |
Rbac.filtered(MiqGroup.non_tenant_groups).each { |g| @groups[g.description] = g.id.to_s } | ||
|
||
@user = @group = DONT_CHANGE_OWNER if ownership_items.length > 1 | ||
ownership_scope = klass.where(:id => ownership_items) | ||
ownership_scope = ownership_scope.with_ownership if klass.respond_to?(:with_ownership) | ||
@origin_ownership_items = ownership_items | ||
@ownershipitems = ownership_scope.order(:name) | ||
|
||
@ownershipitems = klass.find(ownership_items).sort_by(&:name) | ||
@view = get_db_view(klass == VmOrTemplate ? Vm : klass) # Instantiate the MIQ Report view object | ||
@view.table = MiqFilter.records2table(@ownershipitems, @view.cols + ['id']) | ||
end | ||
|
@@ -127,18 +116,11 @@ def build_ownership_hash(ownership_items) | |
@group = group ? group.id.to_s : nil | ||
Rbac.filtered(MiqGroup).each { |g| @groups[g.description] = g.id.to_s } | ||
@user = @group = DONT_CHANGE_OWNER if ownership_items.length > 1 | ||
@ownershipitems = Rbac.filtered(klass.where(:id => ownership_items).order(:name), :class => klass) | ||
raise _('Invalid items passed') unless @ownershipitems.pluck(:id).to_set == ownership_items.map(&:to_i).to_set | ||
@ownershipitems = klass.find(ownership_items).sort_by(&:name) | ||
{:user => @user, | ||
:group => @group} | ||
end | ||
|
||
def valid_items_for(klass, param_ids) | ||
scope = klass.respond_to?(:with_ownership) ? klass.with_ownership : klass | ||
checked_ids = Rbac.filtered(scope.where(:id => param_ids)).pluck(:id) | ||
checked_ids.to_set == param_ids.to_set | ||
end | ||
|
||
def ownership_update | ||
case params[:button] | ||
when "cancel" | ||
|
@@ -169,10 +151,7 @@ def ownership_update | |
end | ||
|
||
klass = get_class_from_controller_param(request.parameters[:controller]) | ||
param_ids = params[:objectIds].map(&:to_i) | ||
raise _('Invalid items selected.') unless valid_items_for(klass, param_ids) | ||
|
||
result = klass.set_ownership(param_ids, opts) | ||
result = klass.set_ownership(params[:objectIds].map(&:to_i), opts) | ||
unless result == true | ||
result["missing_ids"].each { |msg| add_flash(msg, :error) } if result["missing_ids"] | ||
result["error_updating"].each { |msg| add_flash(msg, :error) } if result["error_updating"] | ||
|
@@ -208,7 +187,7 @@ def ownership_update | |
# Retire 1 or more VMs | ||
def retirevms | ||
assert_privileges(params[:pressed]) | ||
vms = find_checked_items_with_rbac(VmOrTemplate) | ||
vms = find_checked_items | ||
if !%w(orchestration_stack service).include?(request.parameters["controller"]) && !%w(orchestration_stacks).include?(params[:display]) && | ||
VmOrTemplate.find(vms).any? { |vm| !vm.supports_retire? } | ||
add_flash(_("Set Retirement Date does not apply to selected %{model}") % | ||
|
@@ -1873,20 +1852,13 @@ def process_cloud_object_storage_buttons(pressed) | |
end | ||
|
||
def cloud_object_store_button_operation(klass, task) | ||
# Map to instance method name | ||
case task | ||
when "delete" | ||
method = "#{task}_#{klass.name.underscore.to_sym}" | ||
display_name = _(task.capitalize) | ||
else | ||
display_name = _(task.capitalize) | ||
method = task = "#{klass.name.underscore.to_sym}_#{task}" | ||
end | ||
method = "#{task}_#{klass.name.underscore.to_sym}" | ||
display_name = _(task.capitalize) | ||
|
||
items = [] | ||
|
||
# Either a list or coming from a different controller | ||
if @lastaction == "show_list" || %w(cloud_object_store_containers cloud_object_store_objects).include?(@display) | ||
if @lastaction == "show_list" || !%w(cloud_object_store_container).include?(request.parameters["controller"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of making these changes here in |
||
items = find_checked_items | ||
if items.empty? | ||
add_flash(_("No %{model} were selected for %{task}") % | ||
|
@@ -1920,11 +1892,9 @@ def get_rec_cls | |
when "service" | ||
return Service | ||
when "cloud_object_store_container" | ||
params[:pressed].starts_with?("cloud_object_store_object") ? CloudObjectStoreObject : CloudObjectStoreContainer | ||
when "cloud_object_store_object" | ||
CloudObjectStoreObject | ||
CloudObjectStoreContainer | ||
when "ems_storage" | ||
params[:pressed].starts_with?("cloud_object_store_object") ? CloudObjectStoreObject : CloudObjectStoreContainer | ||
CloudObjectStoreContainer | ||
else | ||
return VmOrTemplate | ||
end | ||
|
@@ -1944,9 +1914,6 @@ def process_objects(objs, task, display_name = nil) | |
when "CloudObjectStoreContainer" | ||
objs, _objs_out_reg = filter_ids_in_region(objs, "CloudObjectStoreContainer") | ||
klass = CloudObjectStoreContainer | ||
when "CloudObjectStoreObject" | ||
objs, _objs_out_reg = filter_ids_in_region(objs, "CloudObjectStoreObject") | ||
klass = CloudObjectStoreObject | ||
end | ||
|
||
assert_rbac(current_user, get_rec_cls, objs) | ||
|
@@ -2511,6 +2478,18 @@ def refreshhosts | |
host_button_operation('refresh_ems', _('Refresh')) | ||
end | ||
|
||
def refreshphysicalservers | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above. |
||
#TODO refresh physical servers | ||
end | ||
|
||
def deletephysicalservers | ||
#TODO delete physical servers | ||
end | ||
|
||
def editphysicalservers | ||
#TODO edit physical servers | ||
end | ||
|
||
# Scan all selected or single displayed host(s) | ||
def scanhosts | ||
assert_privileges("host_scan") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
class PhysicalServerController < ApplicationController | ||
include Mixins::GenericListMixin | ||
include Mixins::GenericShowMixin | ||
|
||
before_action :check_privileges | ||
before_action :session_data | ||
after_action :cleanup_action | ||
after_action :set_session_data | ||
|
||
def self.table_name | ||
@table_name ||= "physical_servers" | ||
end | ||
|
||
def session_data | ||
@title = _("Physical Servers") | ||
@layout = "physical_server" | ||
@lastaction = session[:physical_server_lastaction] | ||
end | ||
|
||
def collect_data(server_id) | ||
PhysicalServerService.new(server_id, self).all_data | ||
end | ||
|
||
def set_session_data | ||
session[:layout] = @layout | ||
session[:physical_server_lastaction] = @lastaction | ||
end | ||
|
||
def show_list | ||
# Disable the cache to prevent a caching problem that occurs when | ||
# pressing the browser's back arrow button to return to the show_list | ||
# page while on the Physical Server's show page. Disabling the cache | ||
# causes the page and its session variables to actually be reloaded. | ||
disable_client_cache | ||
|
||
process_show_list | ||
end | ||
|
||
# Handles buttons pressed on the toolbar | ||
def button | ||
# Get the list of servers to apply the action to | ||
servers = retrieve_servers | ||
|
||
# Apply the action (depending on the button pressed) to the servers | ||
apply_action_to_servers(servers) | ||
end | ||
|
||
private | ||
|
||
# Maps button actions to actual method names to be called and the | ||
# corresponding result status messages to be displayed | ||
ACTIONS = {"physical_server_power_on" => [:power_on, "Power On"], | ||
"physical_server_power_off" => [:power_off, "Power Off"], | ||
"physical_server_restart" => [:restart, "Restart"], | ||
"physical_server_blink_loc_led" => [:blink_loc_led, "Blink LED"], | ||
"physical_server_turn_on_loc_led" => [:turn_on_loc_led, "Turn On LED"], | ||
"physical_server_turn_off_loc_led" => [:turn_off_loc_led, "Turn Off LED"]}.freeze | ||
|
||
# Displays an error message | ||
def display_error_message(msg) | ||
display_message(msg, :error) | ||
end | ||
|
||
# Displays a success message | ||
def display_success_message(msg) | ||
display_message(msg, :success) | ||
end | ||
|
||
# Displays a message | ||
def display_message(msg, level) | ||
add_flash(_(msg), level) | ||
render_flash | ||
end | ||
|
||
# Returns a list of servers to which the button action will be applied | ||
def retrieve_servers | ||
server_id = params[:id] | ||
servers = [] | ||
|
||
# A list of servers | ||
if @lastaction == "show_list" | ||
server_ids = find_checked_items | ||
server_ids.each do |id| | ||
servers.push(PhysicalServer.find_by('id' => id)) | ||
end | ||
if server_ids.empty? | ||
display_error_message("No server IDs found for the selected servers") | ||
end | ||
# A single server | ||
elsif server_id.nil? || PhysicalServer.find_by('id' => server_id).nil? | ||
display_error_message("No server ID found for the current server") | ||
else | ||
servers.push(PhysicalServer.find_by('id' => server_id)) | ||
end | ||
|
||
servers | ||
end | ||
|
||
# Applies the appropriate action to a list of servers depending | ||
# on the button pressed | ||
def apply_action_to_servers(servers) | ||
button_pressed = params[:pressed] | ||
|
||
# Apply the appropriate action to each server | ||
if ACTIONS.key?(button_pressed) | ||
method = ACTIONS[button_pressed][0] | ||
action_str = ACTIONS[button_pressed][1] | ||
servers.each do |server| | ||
server.send(method) | ||
end | ||
msg = "Successfully initiated the #{action_str} action" | ||
display_success_message(msg) | ||
else | ||
display_error_message("Unknown action: #{button_pressed}") | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class ApplicationHelper::Button::PhysicalServerFeatureButton < ApplicationHelper::Button::GenericFeatureButton | ||
|
||
def visible? | ||
true | ||
end | ||
|
||
def disabled? | ||
false | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class ApplicationHelper::Button::PhysicalServerFeatureButtonWithDisable < ApplicationHelper::Button::GenericFeatureButtonWithDisable | ||
|
||
def visible? | ||
true | ||
end | ||
|
||
def disabled? | ||
false | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was the
rbac
call replaced with the non-rbac one?