manageiq-appliance_console 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +47 -0
  3. data/.gitignore +12 -0
  4. data/.rspec +4 -0
  5. data/.rspec_ci +4 -0
  6. data/.rubocop.yml +4 -0
  7. data/.rubocop_cc.yml +5 -0
  8. data/.rubocop_local.yml +2 -0
  9. data/.travis.yml +19 -0
  10. data/Gemfile +6 -0
  11. data/LICENSE.txt +202 -0
  12. data/README.md +45 -0
  13. data/Rakefile +6 -0
  14. data/bin/appliance_console +661 -0
  15. data/bin/appliance_console_cli +7 -0
  16. data/lib/manageiq-appliance_console.rb +51 -0
  17. data/lib/manageiq/appliance_console/certificate.rb +146 -0
  18. data/lib/manageiq/appliance_console/certificate_authority.rb +140 -0
  19. data/lib/manageiq/appliance_console/cli.rb +363 -0
  20. data/lib/manageiq/appliance_console/database_configuration.rb +286 -0
  21. data/lib/manageiq/appliance_console/database_maintenance.rb +35 -0
  22. data/lib/manageiq/appliance_console/database_maintenance_hourly.rb +58 -0
  23. data/lib/manageiq/appliance_console/database_maintenance_periodic.rb +84 -0
  24. data/lib/manageiq/appliance_console/database_replication.rb +146 -0
  25. data/lib/manageiq/appliance_console/database_replication_primary.rb +59 -0
  26. data/lib/manageiq/appliance_console/database_replication_standby.rb +166 -0
  27. data/lib/manageiq/appliance_console/date_time_configuration.rb +117 -0
  28. data/lib/manageiq/appliance_console/errors.rb +5 -0
  29. data/lib/manageiq/appliance_console/external_auth_options.rb +153 -0
  30. data/lib/manageiq/appliance_console/external_database_configuration.rb +34 -0
  31. data/lib/manageiq/appliance_console/external_httpd_authentication.rb +157 -0
  32. data/lib/manageiq/appliance_console/external_httpd_authentication/external_httpd_configuration.rb +249 -0
  33. data/lib/manageiq/appliance_console/internal_database_configuration.rb +187 -0
  34. data/lib/manageiq/appliance_console/key_configuration.rb +118 -0
  35. data/lib/manageiq/appliance_console/logfile_configuration.rb +117 -0
  36. data/lib/manageiq/appliance_console/logger.rb +23 -0
  37. data/lib/manageiq/appliance_console/logging.rb +102 -0
  38. data/lib/manageiq/appliance_console/logical_volume_management.rb +94 -0
  39. data/lib/manageiq/appliance_console/principal.rb +46 -0
  40. data/lib/manageiq/appliance_console/prompts.rb +211 -0
  41. data/lib/manageiq/appliance_console/scap.rb +53 -0
  42. data/lib/manageiq/appliance_console/temp_storage_configuration.rb +79 -0
  43. data/lib/manageiq/appliance_console/timezone_configuration.rb +58 -0
  44. data/lib/manageiq/appliance_console/utilities.rb +67 -0
  45. data/lib/manageiq/appliance_console/version.rb +5 -0
  46. data/locales/appliance/en.yml +42 -0
  47. data/locales/container/en.yml +30 -0
  48. data/manageiq-appliance_console.gemspec +40 -0
  49. data/zanata.xml +7 -0
  50. metadata +317 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 53fe923f2b45499c44a194cd2518b98e232b1fc5
4
+ data.tar.gz: 21e3edc0a01d9611c4e6e7c73bfce9dea806b568
5
+ SHA512:
6
+ metadata.gz: 4db43b527f9c24576951fb0258637826e6328acad9888d5b54510c7ec2922147b7d0c588b4b550578579714715c04d5c32e5b068937b49034f348d66a733c670
7
+ data.tar.gz: 4a12386a105f8fe8079f28cdb32a535c78f6835d954c3883edea804d99e41a7fffd69f02c67e4b8c1704a6a4614c616bb357d2e2de9ecade90342e99b028c4dc
@@ -0,0 +1,47 @@
1
+ ---
2
+ exclude_paths:
3
+ - ".git/"
4
+ - "**.xml"
5
+ - "**.yaml"
6
+ - "**.yml"
7
+ - "locale/"
8
+ - "spec/"
9
+ - "tools/"
10
+ engines:
11
+ brakeman:
12
+ # very slow :sad_panda:
13
+ enabled: false
14
+ bundler-audit:
15
+ # requires Gemfile.lock
16
+ enabled: false
17
+ csslint:
18
+ enabled: false
19
+ duplication:
20
+ enabled: true
21
+ config:
22
+ languages:
23
+ - ruby
24
+ - javascript
25
+ eslint:
26
+ enabled: false
27
+ channel: "eslint-3"
28
+ fixme:
29
+ # let's enable later
30
+ enabled: false
31
+ markdownlint:
32
+ # let's enable later
33
+ enabled: false
34
+ rubocop:
35
+ enabled: true
36
+ config: '.rubocop_cc.yml'
37
+ prepare:
38
+ fetch:
39
+ - url: "https://raw.githubusercontent.com/ManageIQ/guides/master/.rubocop_base.yml"
40
+ path: ".rubocop_base.yml"
41
+ - url: "https://raw.githubusercontent.com/ManageIQ/guides/master/.rubocop_cc_base.yml"
42
+ path: ".rubocop_cc_base.yml"
43
+ ratings:
44
+ paths:
45
+ - Gemfile.lock
46
+ - "**.rake"
47
+ - "**.rb"
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --require spec_helper
2
+ --color
3
+ --order random
4
+ --format documentation
@@ -0,0 +1,4 @@
1
+ --require spec_helper
2
+ --color
3
+ --order random
4
+ --profile
@@ -0,0 +1,4 @@
1
+ inherit_from:
2
+ - https://raw.githubusercontent.com/ManageIQ/guides/master/.rubocop_base.yml
3
+ # put all local rubocop config into .rubocop_local.yml as it will be loaded by .rubocop_cc.yml as well
4
+ - .rubocop_local.yml
@@ -0,0 +1,5 @@
1
+ inherit_from:
2
+ # this is downloaded by .codeclimate.yml
3
+ - .rubocop_base.yml
4
+ - .rubocop_cc_base.yml
5
+ - .rubocop_local.yml
@@ -0,0 +1,2 @@
1
+ # GlobalVars:
2
+ # AllowedVariables:
@@ -0,0 +1,19 @@
1
+ language: ruby
2
+ rvm:
3
+ - '2.3.5'
4
+ - '2.4.2'
5
+ sudo: false
6
+ cache: bundler
7
+ env:
8
+ global:
9
+ - RUBY_GC_HEAP_GROWTH_MAX_SLOTS=300000
10
+ - RUBY_GC_HEAP_INIT_SLOTS=600000
11
+ - RUBY_GC_HEAP_GROWTH_FACTOR=1.25
12
+ after_script: bundle exec codeclimate-test-reporter
13
+ notifications:
14
+ webhooks:
15
+ urls:
16
+ - https://webhooks.gitter.im/e/115ada1099c46977b0d3
17
+ on_success: change
18
+ on_failure: always
19
+ on_start: never
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in manageiq-smartstate.gemspec
4
+ gemspec
5
+
6
+ gem "manageiq-gems-pending", :git => "https://github.com/ManageIQ/manageiq-gems-pending", :branch => "master"
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,45 @@
1
+ # ManageIQ::ApplianceConsole
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/manageiq-appliance_console.svg)](http://badge.fury.io/rb/manageiq-appliance_console)
4
+ [![Build Status](https://travis-ci.org/ManageIQ/manageiq-appliance_console.svg)](https://travis-ci.org/ManageIQ/manageiq-appliance_console)
5
+ [![Code Climate](https://codeclimate.com/github/ManageIQ/manageiq-appliance_console.svg)](https://codeclimate.com/github/ManageIQ/manageiq-appliance_console)
6
+ [![Test Coverage](https://codeclimate.com/github/ManageIQ/manageiq-appliance_console/badges/coverage.svg)](https://codeclimate.com/github/ManageIQ/manageiq-appliance_console/coverage)
7
+ [![Dependency Status](https://gemnasium.com/ManageIQ/manageiq-appliance_console.svg)](https://gemnasium.com/ManageIQ/manageiq-appliance_console)
8
+ [![Security](https://hakiri.io/github/ManageIQ/manageiq-appliance_console/master.svg)](https://hakiri.io/github/ManageIQ/manageiq-appliance_console/master)
9
+
10
+ [![Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ManageIQ/manageiq-appliance_console?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'manageiq-appliance_console'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install manageiq-appliance_console
27
+
28
+ ## Usage
29
+
30
+ TODO: Write usage instructions here
31
+
32
+ ## Development
33
+
34
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
35
+
36
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ManageIQ/manageiq-appliance_console.
41
+
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,661 @@
1
+ #!/usr/bin/env ruby
2
+ # description: ManageIQ appliance console
3
+ #
4
+
5
+ require 'bundler'
6
+ Bundler.setup
7
+
8
+ require 'manageiq-appliance_console'
9
+ require 'pathname'
10
+
11
+ gem_root = Pathname.new(__dir__).join("..")
12
+
13
+ require 'fileutils'
14
+ require 'highline/import'
15
+ require 'highline/system_extensions'
16
+ require 'rubygems'
17
+ require 'bcrypt'
18
+ require 'linux_admin'
19
+ require 'util/postgres_admin'
20
+ require 'awesome_spawn'
21
+ include HighLine::SystemExtensions
22
+
23
+ require 'i18n'
24
+ locales_dir = ENV['CONTAINER'] ? "container" : "appliance"
25
+ locales_paths = [
26
+ gem_root.join("locales", locales_dir, "*.yml"),
27
+ File.expand_path(File.join("productization/appliance_console/locales", locales_dir, "*.yml"), ManageIQ::ApplianceConsole::RAILS_ROOT)
28
+ ]
29
+ locales_paths.each { |p| I18n.load_path += Dir[p].sort }
30
+ I18n.enforce_available_locales = true
31
+ I18n.backend.load_translations
32
+
33
+ SCAP_RULES_DIR = File.expand_path("productization/appliance_console/config", ManageIQ::ApplianceConsole::RAILS_ROOT)
34
+
35
+ $terminal.wrap_at = 80
36
+ $terminal.page_at = 35
37
+
38
+ def summary_entry(field, value)
39
+ dfield = "#{field}:"
40
+ "#{dfield.ljust(24)} #{value}"
41
+ end
42
+
43
+ [:INT, :TERM, :ABRT, :TSTP].each { |s| trap(s) { raise MiqSignalError } }
44
+
45
+ VERSION_FILE = ManageIQ::ApplianceConsole::RAILS_ROOT.join("VERSION")
46
+ LOGFILE = ManageIQ::ApplianceConsole::RAILS_ROOT.join("log", "appliance_console.log")
47
+ DB_RESTORE_FILE = "/tmp/evm_db.backup".freeze
48
+
49
+ AS_OPTIONS = I18n.t("advanced_settings.menu_order").collect do |item|
50
+ I18n.t("advanced_settings.#{item}")
51
+ end
52
+
53
+ require 'util/miq-password'
54
+ MiqPassword.key_root = ManageIQ::ApplianceConsole::RAILS_ROOT.join("certs").to_s
55
+
56
+ # Load appliance_console libraries
57
+ include ManageIQ::ApplianceConsole::Prompts
58
+
59
+ # Restore database choices
60
+ RESTORE_LOCAL = "Local file".freeze
61
+ RESTORE_NFS = "Network File System (NFS)".freeze
62
+ RESTORE_SMB = "Samba (SMB)".freeze
63
+ RESTORE_OPTIONS = [RESTORE_LOCAL, RESTORE_NFS, RESTORE_SMB, ManageIQ::ApplianceConsole::CANCEL].freeze
64
+
65
+ # Restart choices
66
+ RE_RESTART = "Restart".freeze
67
+ RE_DELLOGS = "Restart and Clean Logs".freeze
68
+ RE_OPTIONS = [RE_RESTART, RE_DELLOGS, ManageIQ::ApplianceConsole::CANCEL].freeze
69
+
70
+ NETWORK_INTERFACE = "eth0".freeze
71
+ CLOUD_INIT_NETWORK_CONFIG_FILE = "/etc/cloud/cloud.cfg.d/99_miq_disable_network_config.cfg".freeze
72
+ CLOUD_INIT_DISABLE_NETWORK_CONFIG = "network: {config: disabled}\n".freeze
73
+
74
+ module ManageIQ
75
+ module ApplianceConsole
76
+ eth0 = LinuxAdmin::NetworkInterface.new(NETWORK_INTERFACE)
77
+ # Because it takes a few seconds, get the region once in the outside loop
78
+ region = ManageIQ::ApplianceConsole::DatabaseConfiguration.region
79
+
80
+ # Calling stty to provide the equivalent line settings when the console is run via an ssh session or
81
+ # over the virtual machine console.
82
+ system("stty -echoprt ixany iexten echoe echok")
83
+
84
+ loop do
85
+ begin
86
+ dns = LinuxAdmin::Dns.new
87
+ eth0.reload
88
+ eth0.parse_conf if eth0.respond_to?(:parse_conf)
89
+
90
+ host = LinuxAdmin::Hosts.new.hostname
91
+ ip = eth0.address
92
+ mac = eth0.mac_address
93
+ mask = eth0.netmask
94
+ gw = eth0.gateway
95
+ dns1, dns2 = dns.nameservers
96
+ order = dns.search_order.join(' ')
97
+ timezone = LinuxAdmin::TimeDate.system_timezone
98
+ version = File.read(VERSION_FILE).chomp if File.exist?(VERSION_FILE)
99
+ dbhost = ManageIQ::ApplianceConsole::DatabaseConfiguration.database_host
100
+ database = ManageIQ::ApplianceConsole::DatabaseConfiguration.database_name
101
+ evm_running = LinuxAdmin::Service.new("evmserverd").running?
102
+
103
+ summary_attributes = [
104
+ summary_entry("Hostname", host),
105
+ summary_entry("IPv4 Address", "#{ip}/#{mask}"),
106
+ summary_entry("IPv4 Gateway", gw),
107
+ summary_entry("IPv6 Address", eth0.address6 ? "#{eth0.address6}/#{eth0.prefix6}" : ''),
108
+ summary_entry("IPV6 Gateway", eth0.gateway6),
109
+ summary_entry("Primary DNS", dns1),
110
+ summary_entry("Secondary DNS", dns2),
111
+ summary_entry("Search Order", order),
112
+ summary_entry("MAC Address", mac),
113
+ summary_entry("Timezone", timezone),
114
+ summary_entry("Local Database Server", PostgresAdmin.local_server_status),
115
+ summary_entry("#{I18n.t("product.name")} Server", evm_running ? "running" : "not running"),
116
+ summary_entry("#{I18n.t("product.name")} Database", dbhost || "not configured"),
117
+ summary_entry("Database/Region", database ? "#{database} / #{region.to_i}" : "not configured"),
118
+ summary_entry("External Auth", ExternalHttpdAuthentication.config_status),
119
+ summary_entry("#{I18n.t("product.name")} Version", version),
120
+ ]
121
+
122
+ clear_screen
123
+
124
+ say(<<-EOL)
125
+ Welcome to the #{I18n.t("product.name")} Virtual Appliance.
126
+
127
+ To modify the configuration, use a web browser to access the management page.
128
+
129
+ #{$terminal.list(summary_attributes)}
130
+ EOL
131
+
132
+ press_any_key
133
+
134
+ clear_screen
135
+ selection = ask_with_menu("Advanced Setting", AS_OPTIONS, nil, true)
136
+ case selection
137
+ when I18n.t('advanced_settings.networking')
138
+ options = {
139
+ 'Set DHCP Network Configuration' => 'dhcp',
140
+ 'Set IPv4 Static Network Configuration' => 'static',
141
+ 'Set IPv6 Static Network Configuration' => 'static6',
142
+ 'Test Network Configuration' => 'testnet',
143
+ 'Set Hostname' => 'hostname'
144
+ }
145
+ case ask_with_menu('Network Configuration', options)
146
+ when 'dhcp'
147
+ say("DHCP Network Configuration\n\n")
148
+
149
+ ipv4 = agree('Enable DHCP for IPv4 network configuration? (Y/N): ')
150
+ ipv6 = agree('Enable DHCP for IPv6 network configuration? (Y/N): ')
151
+
152
+ if ipv4 || ipv6
153
+ say("\nApplying DHCP network configuration...")
154
+
155
+ resolv = LinuxAdmin::Dns.new
156
+ resolv.search_order = []
157
+ resolv.nameservers = []
158
+ resolv.save
159
+
160
+ eth0.enable_dhcp if ipv4
161
+ eth0.enable_dhcp6 if ipv6
162
+ eth0.save
163
+
164
+ File.write(CLOUD_INIT_NETWORK_CONFIG_FILE, CLOUD_INIT_DISABLE_NETWORK_CONFIG)
165
+ say("\nAfter completing the appliance configuration, please restart #{I18n.t("product.name")} server processes.")
166
+ press_any_key
167
+ end
168
+ when 'static'
169
+ say("Static Network Configuration\n\n")
170
+ say("Enter the new static network configuration settings.\n\n")
171
+
172
+ new_ip = ask_for_ipv4("IP Address", ip)
173
+ new_mask = ask_for_ipv4("Netmask", mask)
174
+ new_gw = ask_for_ipv4("Gateway", gw)
175
+ new_dns1 = ask_for_ipv4("Primary DNS", dns1)
176
+ new_dns2 = ask_for_ipv4_or_none("Secondary DNS (Enter 'none' for no value)")
177
+
178
+ new_search_order = ask_for_many("domain", "Domain search order", order)
179
+
180
+ clear_screen
181
+ say(<<-EOL)
182
+ Static Network Configuration
183
+
184
+ IP Address: #{new_ip}
185
+ Netmask: #{new_mask}
186
+ Gateway: #{new_gw}
187
+ Primary DNS: #{new_dns1}
188
+ Secondary DNS: #{new_dns2}
189
+ Search Order: #{new_search_order.join(" ")}
190
+
191
+ EOL
192
+
193
+ if agree("Apply static network configuration? (Y/N)")
194
+ say("\nApplying static network configuration...")
195
+
196
+ resolv = LinuxAdmin::Dns.new
197
+ resolv.search_order = []
198
+ resolv.nameservers = []
199
+ resolv.save
200
+
201
+ begin
202
+ network_configured = eth0.apply_static(new_ip, new_mask, new_gw, [new_dns1, new_dns2], new_search_order)
203
+ rescue ArgumentError => e
204
+ say("\nNetwork configuration failed: #{e.message}")
205
+ press_any_key
206
+ next
207
+ end
208
+
209
+ unless network_configured
210
+ say("\nNetwork interface failed to start using the values supplied.")
211
+ press_any_key
212
+ next
213
+ end
214
+
215
+ File.write(CLOUD_INIT_NETWORK_CONFIG_FILE, CLOUD_INIT_DISABLE_NETWORK_CONFIG)
216
+ say("\nAfter completing the appliance configuration, please restart #{I18n.t("product.name")} server processes.")
217
+ press_any_key
218
+ end
219
+
220
+ when 'static6'
221
+ say("IPv6: Static Network Configuration\n\n")
222
+ say("Enter the new static network configuration settings.\n\n")
223
+
224
+ new_ip = ask_for_ipv6('IP Address', eth0.address6)
225
+ new_prefix = ask_for_integer('IPv6 prefix length', 1..127, eth0.prefix6 || 64)
226
+ new_gw = ask_for_ipv6('Default gateway', eth0.gateway6)
227
+ new_dns1 = ask_for_ip('Primary DNS', dns1)
228
+ new_dns2 = ask_for_ipv6_or_none("Secondary DNS (Enter 'none' for no value)")
229
+
230
+ new_search_order = ask_for_many('domain', 'Domain search order', order)
231
+
232
+ clear_screen
233
+ say(<<-EOL)
234
+ Static Network Configuration
235
+
236
+ IP Address: #{new_ip}/#{new_prefix}
237
+ Gateway: #{new_gw}
238
+ Primary DNS: #{new_dns1}
239
+ Secondary DNS: #{new_dns2}
240
+ Search Order: #{new_search_order.join(" ")}
241
+
242
+ EOL
243
+
244
+ if agree('Apply static network configuration? (Y/N)')
245
+ say("\nApplying static network configuration...")
246
+
247
+ resolv = LinuxAdmin::Dns.new
248
+ resolv.search_order = []
249
+ resolv.nameservers = []
250
+ resolv.save
251
+
252
+ begin
253
+ network_configured = eth0.apply_static6(new_ip, new_prefix, new_gw, [new_dns1, new_dns2], new_search_order)
254
+ rescue ArgumentError => e
255
+ say("\nNetwork configuration failed: #{e.message}")
256
+ press_any_key
257
+ next
258
+ end
259
+
260
+ unless network_configured
261
+ say("\nNetwork interface failed to start using the values supplied.")
262
+ press_any_key
263
+ next
264
+ end
265
+
266
+ File.write(CLOUD_INIT_NETWORK_CONFIG_FILE, CLOUD_INIT_DISABLE_NETWORK_CONFIG)
267
+ say("\nAfter completing the appliance configuration, please restart #{I18n.t("product.name")} server processes.")
268
+ press_any_key
269
+ end
270
+
271
+ when 'testnet'
272
+ ManageIQ::ApplianceConsole::Utilities.test_network
273
+
274
+ when 'hostname'
275
+ say("Hostname Configuration\n\n")
276
+ new_host = just_ask("new hostname", host)
277
+
278
+ if new_host != host
279
+ say("Applying new hostname...")
280
+ system_hosts = LinuxAdmin::Hosts.new
281
+
282
+ system_hosts.parsed_file.each { |line| line[:hosts].to_a.delete(host) } unless host =~ /^localhost.*/
283
+
284
+ system_hosts.hostname = new_host
285
+ system_hosts.set_loopback_hostname(new_host)
286
+ system_hosts.save
287
+
288
+ press_any_key
289
+ end
290
+ end
291
+
292
+ when I18n.t("advanced_settings.timezone")
293
+ say("#{selection}\n\n")
294
+ timezone_config = ManageIQ::ApplianceConsole::TimezoneConfiguration.new(timezone)
295
+ if timezone_config.ask_questions && timezone_config.activate
296
+ say("Timezone configured")
297
+ press_any_key
298
+ else
299
+ say("Timezone not configured")
300
+ press_any_key
301
+ raise MiqSignalError
302
+ end
303
+
304
+ when I18n.t("advanced_settings.datetime")
305
+ say("#{selection}\n\n")
306
+ date_time_config = ManageIQ::ApplianceConsole::DateTimeConfiguration.new
307
+ if date_time_config.ask_questions && date_time_config.activate
308
+ say("Date and time configured")
309
+ press_any_key
310
+ else
311
+ say("Date and time not configured")
312
+ press_any_key
313
+ raise MiqSignalError
314
+ end
315
+
316
+ when I18n.t("advanced_settings.httpdauth")
317
+ say("#{selection}\n\n")
318
+
319
+ httpd_auth = ExternalHttpdAuthentication.new(host)
320
+ if httpd_auth.ask_questions && httpd_auth.activate
321
+ httpd_auth.post_activation
322
+ say("\nExternal Authentication configured successfully.\n")
323
+ press_any_key
324
+ else
325
+ say("\nExternal Authentication configuration failed!\n")
326
+ press_any_key
327
+ raise MiqSignalError
328
+ end
329
+
330
+ when I18n.t("advanced_settings.extauth_opts")
331
+ say("#{selection}\n\n")
332
+
333
+ extauth_options = ExternalAuthOptions.new
334
+ if extauth_options.ask_questions && extauth_options.any_updates?
335
+ extauth_options.update_configuration
336
+ say("\nExternal Authentication Options updated successfully.\n")
337
+ else
338
+ say("\nExternal Authentication Options not updated.\n")
339
+ end
340
+ press_any_key
341
+
342
+ when I18n.t("advanced_settings.ca")
343
+ say("#{selection}\n\n")
344
+ begin
345
+ ca = CertificateAuthority.new(:hostname => host)
346
+ if ca.ask_questions && ca.activate
347
+ say "\ncertificate result: #{ca.status_string}"
348
+ unless ca.complete?
349
+ say "After the certificates are retrieved, rerun to update service configuration files"
350
+ end
351
+ press_any_key
352
+ else
353
+ say("\nCertificates not fetched.\n")
354
+ press_any_key
355
+ end
356
+ rescue AwesomeSpawn::CommandResultError => e
357
+ say e.result.output
358
+ say e.result.error
359
+ say ""
360
+ press_any_key
361
+ end
362
+
363
+ when I18n.t("advanced_settings.evmstop")
364
+ say("#{selection}\n\n")
365
+ service = LinuxAdmin::Service.new("evmserverd")
366
+ if service.running?
367
+ if ask_yn? "\nNote: It may take up to a few minutes for all #{I18n.t("product.name")} server processes to exit gracefully. Stop #{I18n.t("product.name")}"
368
+ say("\nStopping #{I18n.t("product.name")} Server...")
369
+ logger.info("EVM server stop initiated by appliance console.")
370
+ service.stop
371
+ end
372
+ else
373
+ say("\n#{I18n.t("product.name")} Server is not running...")
374
+ end
375
+ press_any_key
376
+
377
+ when I18n.t("advanced_settings.evmstart")
378
+ say("#{selection}\n\n")
379
+ if ask_yn?("\nStart #{I18n.t("product.name")}")
380
+ say("\nStarting #{I18n.t("product.name")} Server...")
381
+ logger.info("EVM server start initiated by appliance console.")
382
+ begin
383
+ LinuxAdmin::Service.new("evmserverd").start
384
+ rescue AwesomeSpawn::CommandResultError => e
385
+ say e.result.output
386
+ say e.result.error
387
+ say ""
388
+ end
389
+ press_any_key
390
+ end
391
+
392
+ when I18n.t("advanced_settings.dbrestore")
393
+ say("#{selection}\n\n")
394
+ task_params = []
395
+ uri = nil
396
+
397
+ # TODO: merge into 1 prompt
398
+ case ask_with_menu("Restore Database File", RESTORE_OPTIONS, RESTORE_LOCAL, nil)
399
+ when RESTORE_LOCAL
400
+ validate = ->(a) { File.exist?(a) }
401
+ uri = just_ask("location of the local restore file", DB_RESTORE_FILE, validate, "file that exists")
402
+ task = "evm:db:restore:local"
403
+ task_params = ["--", {:local_file => uri}]
404
+
405
+ when RESTORE_NFS
406
+ uri = ask_for_uri("location of the remote backup file\nExample: #{sample_url('nfs')})", "nfs")
407
+ task = "evm:db:restore:remote"
408
+ task_params = ["--", {:uri => uri}]
409
+
410
+ when RESTORE_SMB
411
+ uri = ask_for_uri("location of the remote backup file\nExample: #{sample_url('smb')}", "smb")
412
+ user = just_ask("username with access to this file.\nExample: 'mydomain.com/user'")
413
+ pass = ask_for_password("password for #{user}")
414
+
415
+ task = "evm:db:restore:remote"
416
+ task_params = ["--", {:uri => uri, :uri_username => user, :uri_password => pass}]
417
+
418
+ when ManageIQ::ApplianceConsole::CANCEL
419
+ raise MiqSignalError
420
+ end
421
+
422
+ clear_screen
423
+ say("#{selection}\n\n")
424
+
425
+ delete_agreed = false
426
+ if selection == RESTORE_LOCAL
427
+ say "The local database restore file is located at: '#{uri}'.\n"
428
+ delete_agreed = agree("Should this file be deleted after completing the restore? (Y/N): ")
429
+ end
430
+
431
+ say "\nNote: A database restore cannot be undone. The restore will use the file: #{uri}.\n"
432
+ if agree("Are you sure you would like to restore the database? (Y/N): ")
433
+ say("\nRestoring the database...")
434
+ rake_success = ManageIQ::ApplianceConsole::Utilities.rake(task, task_params)
435
+ if rake_success && delete_agreed
436
+ say("\nRemoving the database restore file #{DB_RESTORE_FILE}...")
437
+ File.delete(DB_RESTORE_FILE)
438
+ elsif !rake_success
439
+ say("\nDatabase restore failed")
440
+ connections = ManageIQ::ApplianceConsole::Utilities.db_connections - 1
441
+ say("\nThere #{connections > 1 ? "are #{connections} connections" : "is 1 connection"} preventing a database restore") if connections > 0
442
+ end
443
+ end
444
+ press_any_key
445
+
446
+ when I18n.t("advanced_settings.key_gen")
447
+ say("#{selection}\n\n")
448
+
449
+ key_config = ManageIQ::ApplianceConsole::KeyConfiguration.new
450
+ if key_config.ask_question_loop
451
+ say("\nEncryption key now configured.")
452
+ press_any_key
453
+ else
454
+ say("\nEncryption key not configured.")
455
+ press_any_key
456
+ raise MiqSignalError
457
+ end
458
+
459
+ when I18n.t("advanced_settings.db_config")
460
+ say("#{selection}\n\n")
461
+
462
+ key_config = ManageIQ::ApplianceConsole::KeyConfiguration.new
463
+ unless key_config.key_exist?
464
+ say "No encryption key found.\n"
465
+ say "For migrations, copy encryption key from a hardened appliance."
466
+ say "For worker and multi-region setups, copy key from another appliance.\n"
467
+ say "If this is your first appliance, just generate one now.\n\n"
468
+
469
+ if key_config.ask_question_loop
470
+ say("\nEncryption key now configured.\n\n")
471
+ else
472
+ say("\nEncryption key not configured.")
473
+ press_any_key
474
+ raise MiqSignalError
475
+ end
476
+ end
477
+
478
+ options = {
479
+ "Create Internal Database" => "create_internal",
480
+ "Create Region in External Database" => "create_external",
481
+ "Join Region in External Database" => "join_external",
482
+ "Reset Configured Database" => "reset_region"
483
+ }
484
+ action = ask_with_menu("Database Operation", options)
485
+
486
+ database_configuration =
487
+ case action
488
+ when "create_internal"
489
+ ManageIQ::ApplianceConsole::InternalDatabaseConfiguration.new
490
+ when /_external/
491
+ ManageIQ::ApplianceConsole::ExternalDatabaseConfiguration.new(:action => action.split("_").first.to_sym)
492
+ else
493
+ ManageIQ::ApplianceConsole::DatabaseConfiguration.new
494
+ end
495
+
496
+ case action
497
+ when "reset_region"
498
+ if database_configuration.reset_region
499
+ say("Database reset successfully")
500
+ say("Start the server processes via '#{I18n.t("advanced_settings.evmstart")}'.")
501
+ else
502
+ say("Failed to reset database")
503
+ end
504
+ when "create_internal", /_external/
505
+ database_configuration.run_interactive
506
+ end
507
+ # Get the region again because it may have changed
508
+ region = ManageIQ::ApplianceConsole::DatabaseConfiguration.region
509
+
510
+ press_any_key
511
+
512
+ when I18n.t("advanced_settings.db_replication")
513
+ say("#{selection}\n\n")
514
+
515
+ options = {
516
+ "Configure Server as Primary" => "primary",
517
+ "Configure Server as Standby" => "standby"
518
+ }
519
+
520
+ action = ask_with_menu("Database replication Operation", options)
521
+
522
+ case action
523
+ when "primary"
524
+ db_replication = ManageIQ::ApplianceConsole::DatabaseReplicationPrimary.new
525
+ logger.info("Configuring Server as Primary")
526
+ when "standby"
527
+ db_replication = ManageIQ::ApplianceConsole::DatabaseReplicationStandby.new
528
+ logger.info("Configuring Server as Standby")
529
+ end
530
+
531
+ if db_replication.ask_questions && db_replication.activate
532
+ say("Database Replication configured")
533
+ logger.info("Database Replication configured")
534
+ press_any_key
535
+ else
536
+ say("Database Replication not configured")
537
+ logger.info("Database Replication not configured")
538
+ press_any_key
539
+ raise MiqSignalError
540
+ end
541
+ when I18n.t("advanced_settings.failover_monitor")
542
+ say("#{selection}\n\n")
543
+
544
+ options = {
545
+ "Start Database Failover Monitor" => "start",
546
+ "Stop Database Failover Monitor" => "stop"
547
+ }
548
+
549
+ action = ask_with_menu("Failover Monitor Configuration", options)
550
+ failover_service = LinuxAdmin::Service.new("evm-failover-monitor")
551
+
552
+ begin
553
+ case action
554
+ when "start"
555
+ logger.info("Starting and enabling evm-failover-monitor service")
556
+ failover_service.enable.start
557
+ when "stop"
558
+ logger.info("Stopping and disabling evm-failover-monitor service")
559
+ failover_service.disable.stop
560
+ end
561
+ rescue AwesomeSpawn::CommandResultError => e
562
+ say("Failed to configure failover monitor")
563
+ logger.error("Failed to configure evm-failover-monitor service")
564
+ say(e.result.output)
565
+ say(e.result.error)
566
+ say("")
567
+ press_any_key
568
+ raise MiqSignalError
569
+ end
570
+
571
+ say("Failover Monitor Service configured successfully")
572
+ press_any_key
573
+
574
+ when I18n.t("advanced_settings.db_maintenance")
575
+ say("#{selection}\n\n")
576
+ db_maintenance = ManageIQ::ApplianceConsole::DatabaseMaintenance.new
577
+ if db_maintenance.ask_questions && db_maintenance.activate
578
+ say("Database maintenance configuration updated")
579
+ press_any_key
580
+ else
581
+ say("Database maintenance configuration unchanged")
582
+ press_any_key
583
+ raise MiqSignalError
584
+ end
585
+
586
+ when I18n.t("advanced_settings.log_config")
587
+ say("#{selection}\n\n")
588
+ log_config = ManageIQ::ApplianceConsole::LogfileConfiguration.new
589
+ if log_config.ask_questions && log_config.activate
590
+ say("Log file configuration updated.")
591
+ say("The appliance may take a few minutes to fully restart.")
592
+ press_any_key
593
+ else
594
+ say("Log file configuration unchanged")
595
+ press_any_key
596
+ raise MiqSignalError
597
+ end
598
+
599
+ when I18n.t("advanced_settings.tmp_config")
600
+ say("#{selection}\n\n")
601
+ tmp_config = ManageIQ::ApplianceConsole::TempStorageConfiguration.new
602
+ if tmp_config.ask_questions && tmp_config.activate
603
+ say("Temp storage disk configured")
604
+ press_any_key
605
+ else
606
+ say("Temp storage disk not configured")
607
+ press_any_key
608
+ raise MiqSignalError
609
+ end
610
+
611
+ when I18n.t("advanced_settings.restart")
612
+ case ask_with_menu("Restart Option", RE_OPTIONS, nil, false)
613
+ when ManageIQ::ApplianceConsole::CANCEL
614
+ # don't do anything
615
+ when RE_RESTART
616
+ if are_you_sure?("restart the appliance now")
617
+ logger.info("Appliance restart initiated by appliance console.")
618
+ LinuxAdmin::Service.new("evmserverd").stop
619
+ LinuxAdmin::System.reboot!
620
+ end
621
+ when RE_DELLOGS
622
+ if are_you_sure?("restart the appliance now")
623
+ logger.info("Appliance restart with clean logs initiated by appliance console.")
624
+ LinuxAdmin::Service.new("evmserverd").stop
625
+ LinuxAdmin::Service.new("miqtop").stop
626
+ LinuxAdmin::Service.new("miqvmstat").stop
627
+ LinuxAdmin::Service.new("httpd").stop
628
+ FileUtils.rm_rf(Dir.glob("/var/www/miq/vmdb/log/*.log*"))
629
+ FileUtils.rm_rf(Dir.glob("/var/www/miq/vmdb/log/apache/*.log*"))
630
+ logger.info("Logs cleaned and appliance rebooted by appliance console.")
631
+ LinuxAdmin::System.reboot!
632
+ end
633
+ end
634
+
635
+ when I18n.t("advanced_settings.shutdown")
636
+ say("#{selection}\n\n")
637
+ if are_you_sure?("shut down the appliance now")
638
+ say("\nShutting down appliance... This process may take a few minutes.\n\n")
639
+ logger.info("Appliance shutdown initiated by appliance console")
640
+ LinuxAdmin::Service.new("evmserverd").stop
641
+ LinuxAdmin::System.shutdown!
642
+ end
643
+
644
+ when I18n.t("advanced_settings.scap")
645
+ say("#{selection}\n\n")
646
+ ManageIQ::ApplianceConsole::Scap.new(SCAP_RULES_DIR).lockdown
647
+ press_any_key
648
+
649
+ when I18n.t("advanced_settings.summary")
650
+ # Do nothing
651
+
652
+ when I18n.t("advanced_settings.quit")
653
+ break
654
+ end
655
+ rescue MiqSignalError
656
+ # If a signal is caught anywhere in the inner (after login) loop, go back to the summary screen
657
+ next
658
+ end
659
+ end
660
+ end
661
+ end