Class: ManageIQ::ApplianceConsole::DatabaseAdmin

Inherits:
HighLine
  • Object
show all
Includes:
Prompts
Defined in:
lib/manageiq/appliance_console/database_admin.rb

Constant Summary collapse

DB_RESTORE_FILE =
"/tmp/evm_db.backup".freeze
DB_DEFAULT_DUMP_FILE =
"/tmp/evm_db.dump".freeze
LOCAL_FILE_VALIDATOR =
->(a) { File.exist?(a) }.freeze
USER_PROMPT =
<<-PROMPT.strip_heredoc.chomp
  username with access to this file.
  Example: 'mydomain.com/user'
PROMPT

Constants included from Prompts

Prompts::CLEAR_CODE, Prompts::DOMAIN_REGEXP, Prompts::HOSTNAME_REGEXP, Prompts::INT_REGEXP, Prompts::IPV4_REGEXP, Prompts::IPV6_REGEXP, Prompts::IP_REGEXP, Prompts::NONE_REGEXP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Prompts

#are_you_sure?, #ask_for_disk, #ask_for_domain, #ask_for_hostname, #ask_for_hour_number, #ask_for_integer, #ask_for_ip, #ask_for_ip_or_hostname, #ask_for_ip_or_hostname_or_none, #ask_for_many, #ask_for_month_day_number, #ask_for_password, #ask_for_schedule_frequency, #ask_for_string, #ask_for_uri, #ask_for_week_day_number, #ask_with_menu, #ask_yn?, #clear_screen, #default_to_index, #just_ask, #press_any_key

Constructor Details

#initialize(action = :restore, input = $stdin, output = $stdout) ⇒ DatabaseAdmin

Returns a new instance of DatabaseAdmin.



20
21
22
23
24
25
# File 'lib/manageiq/appliance_console/database_admin.rb', line 20

def initialize(action = :restore, input = $stdin, output = $stdout)
  super(input, output)

  @action        = action
  @database_opts = {:dbname => DatabaseConfiguration.database_name}
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



18
19
20
# File 'lib/manageiq/appliance_console/database_admin.rb', line 18

def action
  @action
end

#backup_typeObject (readonly)

Returns the value of attribute backup_type.



18
19
20
# File 'lib/manageiq/appliance_console/database_admin.rb', line 18

def backup_type
  @backup_type
end

#database_optsObject (readonly)

Returns the value of attribute database_opts.



18
19
20
# File 'lib/manageiq/appliance_console/database_admin.rb', line 18

def database_opts
  @database_opts
end

#delete_agreeObject (readonly)

Returns the value of attribute delete_agree.



18
19
20
# File 'lib/manageiq/appliance_console/database_admin.rb', line 18

def delete_agree
  @delete_agree
end

#filenameObject (readonly)

Returns the value of attribute filename.



18
19
20
# File 'lib/manageiq/appliance_console/database_admin.rb', line 18

def filename
  @filename
end

Instance Method Details

#activateObject



42
43
44
45
46
47
48
# File 'lib/manageiq/appliance_console/database_admin.rb', line 42

def activate
  clear_screen
  setting_header

  ask_to_delete_backup_after_restore
  confirm_and_execute
end

#allowed_to_execute?Boolean

Returns:

  • (Boolean)


89
90
91
92
93
94
# File 'lib/manageiq/appliance_console/database_admin.rb', line 89

def allowed_to_execute?
  return true unless action == :restore

  say("\nNote: A database restore cannot be undone.  The restore will use the file: #{uri}.\n")
  agree("Are you sure you would like to restore the database? (Y/N): ")
end

#ask_file_locationObject



50
51
52
# File 'lib/manageiq/appliance_console/database_admin.rb', line 50

def ask_file_location
  @database_opts[:local_file] = just_ask(*filename_prompt_args)
end

#ask_for_tables_to_exclude_in_dumpObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/manageiq/appliance_console/database_admin.rb', line 61

def ask_for_tables_to_exclude_in_dump
  if action == :dump && should_exclude_tables?
    say(<<-PROMPT.strip_heredoc)

      To exclude tables from the dump, enter them in a space separated
      list.  For example:

          > metrics_* vim_performance_states event_streams

    PROMPT
    table_excludes = ask_for_many("table",
                                  "tables to exclude",
                                  "metrics_* vim_performance_states event_streams",
                                  255,
                                  Float::INFINITY)

    @database_opts[:exclude_table_data] = table_excludes
  end || true
end

#ask_questionsObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/manageiq/appliance_console/database_admin.rb', line 31

def ask_questions
  setting_header
  if action == :restore && EvmServer.running?
    say("\nDatabase restore failed. Please execute the \“Stop EVM Server Processes\” command and try again.")
    press_any_key
    raise MiqSignalError
  end
  ask_file_location
  ask_for_tables_to_exclude_in_dump
end

#ask_to_delete_backup_after_restoreObject



54
55
56
57
58
59
# File 'lib/manageiq/appliance_console/database_admin.rb', line 54

def ask_to_delete_backup_after_restore
  if action == :restore
    say("The local database restore file is located at: '#{uri}'.\n")
    @delete_agree = agree("Should this file be deleted after completing the restore? (Y/N): ")
  end
end

#confirm_and_executeObject



81
82
83
84
85
86
87
# File 'lib/manageiq/appliance_console/database_admin.rb', line 81

def confirm_and_execute
  if allowed_to_execute?
    processing_message
    run_action
  end
  press_any_key
end

#file_optionsObject



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/manageiq/appliance_console/database_admin.rb', line 96

def file_options
  @file_options ||= I18n.t("database_admin.menu_order").each_with_object({}) do |file_option, h|
    # special anonymous ftp sites are defined by uri
    uri = URI(file_option)
    if uri.scheme
      h["#{uri.scheme} to #{uri.host}"] = file_option unless skip_file_location?(uri.host)
    else
      h[I18n.t("database_admin.#{file_option}")] = file_option
    end
  end
end

#setting_headerObject



108
109
110
# File 'lib/manageiq/appliance_console/database_admin.rb', line 108

def setting_header
  say("#{I18n.t("advanced_settings.db#{action}")}\n\n")
end

#uriObject



27
28
29
# File 'lib/manageiq/appliance_console/database_admin.rb', line 27

def uri
  @database_opts[:local_file]
end