Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 0 additions & 112 deletions app/controllers/ops_controller/diagnostics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,80 +74,6 @@ def pm_refresh_workers
end
alias refresh_workers pm_refresh_workers

def log_depot_edit
assert_privileges("#{@sb[:selected_typ] == "miq_server" ? "" : "zone_"}log_depot_edit")
@record = @sb[:selected_typ].classify.constantize.find(@sb[:selected_server_id])
# @schedule = nil # setting to nil, since we are using same view for both db_back and log_depot edit
case params[:button]
when "cancel"
@in_a_form = false
@edit = session[:edit] = nil
add_flash(_("Edit Log Depot settings was cancelled by the user"))
diagnostics_set_form_vars
replace_right_cell(:nodetype => x_node)
when "save"
if @flash_array
javascript_flash(:spinner_off => true)
return
end

begin
if params[:log_protocol].blank?
@record.log_file_depot.try(:destroy)
else
new_uri = "#{params[:uri_prefix]}://#{params[:uri]}"
raise _("Unsupported log depot protocol: %{protocol}") % {:protocol => params[:log_protocol]} unless FileDepot.supported_depots.key?(params[:log_protocol])

build_supported_depots_for_select
log_protocol = params[:log_protocol]
protocols = FileDepot.supported_depots.map { |k, _v| [k, k.constantize] }.to_h
raise _('Invalid or unsupported file depot type.') unless protocols.key?(log_protocol)

depot = @record.log_file_depot.instance_of?(protocols[log_protocol]) ? @record.log_file_depot : @record.build_log_file_depot(:type => log_protocol)
depot.update(:uri => new_uri, :name => params[:depot_name])
creds = set_credentials
depot.update_authentication(creds) if type.try(:requires_credentials?)
@record.save!
end
rescue => bang
add_flash(_("Error during 'Save': %{message}") % {:message => bang.message}, :error)
@changed = true
render :update do |page|
page << javascript_prologue
page.replace_html("diagnostics_collect_logs", :partial => "ops/log_collection")
end
else
add_flash(_("Log Depot Settings were saved"))
@edit = nil
diagnostics_set_form_vars
replace_right_cell(:nodetype => x_node)
end
when "validate"
creds = set_credentials
settings = {
:username => creds[:default][:userid],
:password => creds[:default][:password],
:uri => "#{params[:uri_prefix]}://#{params[:uri]}"
}

begin
log_protocol = params[:log_protocol]
protocols = FileDepot.supported_depots.map { |k, _v| [k, k.constantize] }.to_h
raise _("Unsupported log depot protocol: %{protocol}") % {:protocol => log_protocol} unless protocols.key?(log_protocol)

protocols[log_protocol].validate_settings(settings)
rescue => bang
add_flash(_("Error during 'Validate': %{message}") % {:message => bang.message}, :error)
else
add_flash(_("Log Depot Settings were validated"))
end
javascript_flash(:spinner_off => true)
when nil # Reset or first time in
@in_a_form = true
replace_right_cell(:nodetype => "log_depot_edit")
end
end

# Send the log in text format
def fetch_log
assert_privileges("fetch_log")
Expand Down Expand Up @@ -724,9 +650,6 @@ def diagnostics_set_form_vars
end
elsif @sb[:active_tab] == "diagnostics_replication" # Replication tab
@selected_server = MiqRegion.my_region
elsif @sb[:active_tab] == "diagnostics_database"
build_backup_schedule_options_for_select
build_db_options_for_select
elsif @sb[:active_tab] == "diagnostics_orphaned_data"
orphaned_records_get
elsif @sb[:active_tab] == "diagnostics_server_list"
Expand Down Expand Up @@ -804,25 +727,6 @@ def diagnostics_set_form_vars
end
end

def build_backup_schedule_options_for_select
@backup_schedules = {}
database_details
miq_schedules = MiqSchedule.where(:resource_type => 'DatabaseBackup', :adhoc => nil)
miq_schedules.sort_by { |s| s.name.downcase }.each do |s|
@backup_schedules[s.id] = s.name if s.resource_type == "DatabaseBackup"
end
end

def database_details
@database_details = ActiveRecord::Base.configurations[Rails.env]
@database_display_name =
if @database_details["host"].in?([nil, "", "localhost", "127.0.0.1"])
_("Internal Database")
else
_("External Database")
end
end

def orphaned_records_get
@sb[:orphaned_records] = MiqReportResult.orphaned_counts_by_userid
end
Expand Down Expand Up @@ -859,20 +763,4 @@ def diagnostics_get_info
diagnostics_set_form_vars
end
end

def build_supported_depots_for_select
not_supported_depots = %w[FileDepotS3 FileDepotSwift]
supported_depots = FileDepot.supported_depots.reject { |model, _desc| not_supported_depots.include?(model) }
@uri_prefixes = supported_depots.keys.map { |model| [model, model.constantize.uri_prefix] }.to_h
@supported_depots_for_select = {'' => _('<No Depot>')}.merge(supported_depots)
end

def set_credentials
creds = {}
if params[:log_userid]
log_password = params[:log_password] || @record.log_file_depot.authentication_password
creds[:default] = {:userid => params[:log_userid], :password => log_password}
end
creds
end
end
94 changes: 5 additions & 89 deletions app/controllers/ops_controller/settings/schedules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,6 @@ def schedule_form_fields

if schedule_check_compliance?(schedule)
action_type = schedule.resource_type.underscore + "_" + schedule.sched_action[:method]
elsif schedule_db_backup?(schedule)
require 'uri'
action_type = schedule.sched_action[:method]
depot = schedule.file_depot
full_uri, _query = depot.try(:uri).split('?')
uri_prefix, uri = full_uri.to_s.split('://')
protocol = depot.try(:type)
depot_name = depot.try(:name)
log_userid = depot.try(:authentication_userid)
log_aws_region = depot.try(:aws_region)
openstack_region = depot.try(:openstack_region)
keystone_api_version = depot.try(:keystone_api_version)
v3_domain_ident = depot.try(:v3_domain_ident)
swift_api_port = full_uri.blank? ? 5000 : URI(full_uri).port
security_protocol = depot.try(:security_protocol)
elsif schedule_automation_request?(schedule)
action_type = schedule.sched_action[:method]
automate_request = fetch_automate_request_vars(schedule)
Expand Down Expand Up @@ -289,43 +274,18 @@ def schedule_disable
schedule_toggle(false)
end

def log_depot_validate
assert_privileges("schedule_admin")

if params[:log_password]
file_depot = FileDepot.new
else
id = params[:id] || params[:backup_schedule_type]
file_depot = MiqSchedule.find(id).file_depot
end
uri_settings = build_uri_settings(file_depot)
begin
MiqSchedule.new.verify_file_depot(uri_settings)
rescue => bang
add_flash(_("Error during 'Validate': %{message}") % {:message => bang.message}, :error)
else
add_flash(_('Depot Settings successfuly validated'))
end
javascript_flash
end

private

def schedule_check_compliance?(schedule)
schedule.sched_action && schedule.sched_action[:method] && schedule.sched_action[:method] == "check_compliance"
end

def schedule_db_backup?(schedule)
schedule.sched_action && schedule.sched_action[:method] && schedule.sched_action[:method] == "db_backup"
end

def schedule_automation_request?(schedule)
schedule.sched_action && schedule.sched_action[:method] && schedule.sched_action[:method] == "automation_request"
end

def schedule_resource_type_from_params_action
case params[:action_typ]
when "db_backup" then "DatabaseBackup"
when /check_compliance\z/ then (params[:action_typ].split("_") - params[:action_typ].split("_").last(2)).join("_").classify
when "emscluster" then "EmsCluster"
when "automation_request" then "AutomationRequest"
Expand All @@ -337,7 +297,6 @@ def schedule_method_from_params_action
case params[:action_typ]
when "vm", "miq_template" then "vm_scan" # Default to vm_scan method for now
when /check_compliance\z/ then "check_compliance"
when "db_backup" then "db_backup"
when "automation_request" then "automation_request"
else "scan"
end
Expand Down Expand Up @@ -378,19 +337,17 @@ def build_filtered_item_list(action_type, filter_type)
when "my"
build_listnav_search_list("Vm")
filtered_item_list = @my_searches.collect { |search| [search.id, search.description] }
else
filtered_item_list = DatabaseBackup.supported_depots
end

filtered_item_list
end

def schedule_db_backup_or_automate(schedule)
%w[db_backup automation_request].include?(schedule.sched_action[:method])
def schedule_automate(schedule)
schedule.sched_action[:method] == "automation_request"
end

def determine_filter_type_and_value(schedule)
if schedule.sched_action && schedule.sched_action[:method] && !schedule_db_backup_or_automate(schedule)
if schedule.sched_action && schedule.sched_action[:method] && !schedule_automate(schedule)
if schedule.miq_search # See if a search filter is attached
filter_type = schedule.miq_search.search_type == "user" ? "my" : "global"
filter_value = schedule.miq_search.id
Expand Down Expand Up @@ -454,7 +411,7 @@ def schedule_build_list

def schedule_validate?(sched)
valid = true
unless %w[db_backup automation_request].include?(params[:action_typ])
unless params[:action_typ] == "automation_request"
if %w[global my].include?(params[:filter_typ])
if params[:filter_value].blank? # Check for search filter chosen
add_flash(_("Filter must be selected"), :error)
Expand Down Expand Up @@ -504,14 +461,7 @@ def schedule_set_record_vars(schedule)
schedule.resource_type = schedule_resource_type_from_params_action
schedule.sched_action = {:method => schedule_method_from_params_action}

if params[:action_typ] == "db_backup"
schedule.filter = nil
depot = schedule.file_depot
uri_settings = build_uri_settings(depot)
uri_settings[:name] = params[:depot_name]
uri_settings[:save] = true
schedule.verify_file_depot(uri_settings)
elsif params[:action_typ] == "automation_request"
if params[:action_typ] == "automation_request"
schedule.zone_id = params[:zone_id].presence || MiqServer.my_server.zone_id
ui_attrs = []
ApplicationController::AE_MAX_RESOLUTION_FIELDS.times do |i|
Expand Down Expand Up @@ -692,7 +642,6 @@ def build_schedule_options_for_select
if role_allows?(:feature => "container_image_check_compliance")
@action_type_options_for_select.push([_("Container Image Compliance Check"), "container_image_check_compliance"])
end
@action_type_options_for_select.push([_("Database Backup"), "db_backup"])

if role_allows?(:feature => "miq_ae_class_simulation")
@action_type_options_for_select.push([_("Automation Tasks"), "automation_request"])
Expand Down Expand Up @@ -750,16 +699,6 @@ def build_schedule_options_for_select
] +
(@storage_global_filters.empty? ? [] : [[_("Global Filters"), "global"]]) +
(@storage_my_filters.empty? ? [] : [[_("My Filters"), "my"]])

build_db_options_for_select
end

def build_db_options_for_select
@database_backup_options_for_select = DatabaseBackup.supported_depots
@database_backup_uri_prefixes = DatabaseBackup::SUPPORTED_DEPOTS.map { |model| [model, model.constantize.uri_prefix] }.to_h
@regions_options_for_select = retrieve_aws_regions
@api_versions_options_for_select = retrieve_openstack_api_versions
@security_protocols_options_for_select = retrieve_security_protocols
end

def retrieve_aws_regions
Expand Down Expand Up @@ -798,27 +737,4 @@ def schedule_set_interval_record_vars(schedule)
schedule.run_at[:interval][:unit] = params[:timer_typ].downcase
schedule.run_at[:interval][:value] = params[:timer_value]
end

def build_uri_settings(file_depot)
uri_settings = {}
type = FileDepot.supported_protocols[params[:uri_prefix]]
raise _("Invalid or unsupported file depot type.") if type.nil?

protocols = FileDepot.supported_depots.map { |k, _v| [k, k.constantize] }.to_h
if protocols[type].try(:requires_credentials?)
log_password = params[:log_password] || file_depot.try(:authentication_password)
uri_settings = {:username => params[:log_userid], :password => log_password}
end
uri_settings[:uri] = "#{params[:uri_prefix]}://#{params[:uri]}"
uri_settings[:uri_prefix] = params[:uri_prefix]
uri_settings[:log_protocol] = params[:log_protocol]
uri_settings[:aws_region] = params[:log_aws_region]
uri_settings[:openstack_region] = params[:openstack_region]
uri_settings[:keystone_api_version] = params[:keystone_api_version]
uri_settings[:v3_domain_ident] = params[:v3_domain_ident]
uri_settings[:security_protocol] = params[:security_protocol]
uri_settings[:swift_api_port] = params[:swift_api_port]
uri_settings[:type] = type
uri_settings
end
end
15 changes: 0 additions & 15 deletions app/helpers/application_helper/button/collect_logs.rb

This file was deleted.

7 changes: 0 additions & 7 deletions app/helpers/application_helper/button/log_depot_edit.rb

This file was deleted.

7 changes: 0 additions & 7 deletions app/views/ops/_diagnostics_collect_logs_tab.html.haml

This file was deleted.

11 changes: 0 additions & 11 deletions app/views/ops/_log_collection.html.haml

This file was deleted.

2 changes: 0 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2427,8 +2427,6 @@
label_tag_mapping_edit
label_tag_mapping_update
label_tag_mapping_field_changed
log_depot_edit
log_depot_validate
orphaned_records_delete
perf_chart_chooser
pglogical_save_subscriptions
Expand Down
Loading