manageiq-appliance_console 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.codeclimate.yml +47 -0
- data/.gitignore +12 -0
- data/.rspec +4 -0
- data/.rspec_ci +4 -0
- data/.rubocop.yml +4 -0
- data/.rubocop_cc.yml +5 -0
- data/.rubocop_local.yml +2 -0
- data/.travis.yml +19 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +202 -0
- data/README.md +45 -0
- data/Rakefile +6 -0
- data/bin/appliance_console +661 -0
- data/bin/appliance_console_cli +7 -0
- data/lib/manageiq-appliance_console.rb +51 -0
- data/lib/manageiq/appliance_console/certificate.rb +146 -0
- data/lib/manageiq/appliance_console/certificate_authority.rb +140 -0
- data/lib/manageiq/appliance_console/cli.rb +363 -0
- data/lib/manageiq/appliance_console/database_configuration.rb +286 -0
- data/lib/manageiq/appliance_console/database_maintenance.rb +35 -0
- data/lib/manageiq/appliance_console/database_maintenance_hourly.rb +58 -0
- data/lib/manageiq/appliance_console/database_maintenance_periodic.rb +84 -0
- data/lib/manageiq/appliance_console/database_replication.rb +146 -0
- data/lib/manageiq/appliance_console/database_replication_primary.rb +59 -0
- data/lib/manageiq/appliance_console/database_replication_standby.rb +166 -0
- data/lib/manageiq/appliance_console/date_time_configuration.rb +117 -0
- data/lib/manageiq/appliance_console/errors.rb +5 -0
- data/lib/manageiq/appliance_console/external_auth_options.rb +153 -0
- data/lib/manageiq/appliance_console/external_database_configuration.rb +34 -0
- data/lib/manageiq/appliance_console/external_httpd_authentication.rb +157 -0
- data/lib/manageiq/appliance_console/external_httpd_authentication/external_httpd_configuration.rb +249 -0
- data/lib/manageiq/appliance_console/internal_database_configuration.rb +187 -0
- data/lib/manageiq/appliance_console/key_configuration.rb +118 -0
- data/lib/manageiq/appliance_console/logfile_configuration.rb +117 -0
- data/lib/manageiq/appliance_console/logger.rb +23 -0
- data/lib/manageiq/appliance_console/logging.rb +102 -0
- data/lib/manageiq/appliance_console/logical_volume_management.rb +94 -0
- data/lib/manageiq/appliance_console/principal.rb +46 -0
- data/lib/manageiq/appliance_console/prompts.rb +211 -0
- data/lib/manageiq/appliance_console/scap.rb +53 -0
- data/lib/manageiq/appliance_console/temp_storage_configuration.rb +79 -0
- data/lib/manageiq/appliance_console/timezone_configuration.rb +58 -0
- data/lib/manageiq/appliance_console/utilities.rb +67 -0
- data/lib/manageiq/appliance_console/version.rb +5 -0
- data/locales/appliance/en.yml +42 -0
- data/locales/container/en.yml +30 -0
- data/manageiq-appliance_console.gemspec +40 -0
- data/zanata.xml +7 -0
- metadata +317 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
module ManageIQ
|
2
|
+
module ApplianceConsole
|
3
|
+
require 'pathname'
|
4
|
+
require 'tempfile'
|
5
|
+
RAILS_ROOT = File.exist?("/var/www/miq/vmdb") ? Pathname.new("/var/www/miq/vmdb") : Pathname.new(Dir.mktmpdir)
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_writer :logger
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.logger
|
12
|
+
@logger ||= ManageIQ::ApplianceConsole::Logger.instance
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.logger=(logger)
|
16
|
+
@logger = logger
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'manageiq/appliance_console/version'
|
22
|
+
require 'manageiq/appliance_console/errors'
|
23
|
+
require 'manageiq/appliance_console/logger'
|
24
|
+
require 'manageiq/appliance_console/logging'
|
25
|
+
|
26
|
+
require 'manageiq-gems-pending'
|
27
|
+
|
28
|
+
require 'manageiq/appliance_console/certificate'
|
29
|
+
require 'manageiq/appliance_console/certificate_authority'
|
30
|
+
require 'manageiq/appliance_console/cli'
|
31
|
+
require 'manageiq/appliance_console/database_configuration'
|
32
|
+
require 'manageiq/appliance_console/database_maintenance'
|
33
|
+
require 'manageiq/appliance_console/database_maintenance_hourly'
|
34
|
+
require 'manageiq/appliance_console/database_maintenance_periodic'
|
35
|
+
require 'manageiq/appliance_console/database_replication'
|
36
|
+
require 'manageiq/appliance_console/database_replication_primary'
|
37
|
+
require 'manageiq/appliance_console/database_replication_standby'
|
38
|
+
require 'manageiq/appliance_console/date_time_configuration'
|
39
|
+
require 'manageiq/appliance_console/external_auth_options'
|
40
|
+
require 'manageiq/appliance_console/external_database_configuration'
|
41
|
+
require 'manageiq/appliance_console/external_httpd_authentication'
|
42
|
+
require 'manageiq/appliance_console/internal_database_configuration'
|
43
|
+
require 'manageiq/appliance_console/key_configuration'
|
44
|
+
require 'manageiq/appliance_console/logfile_configuration'
|
45
|
+
require 'manageiq/appliance_console/logical_volume_management'
|
46
|
+
require 'manageiq/appliance_console/principal'
|
47
|
+
require 'manageiq/appliance_console/prompts'
|
48
|
+
require 'manageiq/appliance_console/scap'
|
49
|
+
require 'manageiq/appliance_console/temp_storage_configuration'
|
50
|
+
require 'manageiq/appliance_console/timezone_configuration'
|
51
|
+
require 'manageiq/appliance_console/utilities'
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require "awesome_spawn"
|
2
|
+
|
3
|
+
module ManageIQ
|
4
|
+
module ApplianceConsole
|
5
|
+
class Certificate
|
6
|
+
STATUS_COMPLETE = :complete
|
7
|
+
|
8
|
+
# map `getcert status` return codes to something more descriptive
|
9
|
+
# 0 => :complete -- keys/certs generated
|
10
|
+
# 1 => :no_key -- either certmonger is down, or we havent asked for the key yet. (assuming the latter)
|
11
|
+
# 2 => :rejected -- request failed. we need to resubmit once we fix stuff
|
12
|
+
# 3 => :waiting -- couldn't contact CA, will try again
|
13
|
+
# 4 => :error -- certmonger is not configured properly
|
14
|
+
# 5 => :waiting -- waiting for CA to send back the certificate
|
15
|
+
STATUS_RETURN_CODES = [:complete, :no_key, :rejected, :waiting, :error, :waiting]
|
16
|
+
|
17
|
+
# key filename defaults to certificate name w/ different extension
|
18
|
+
attr_writer :key_filename
|
19
|
+
attr_accessor :cert_filename
|
20
|
+
# root certificate filename
|
21
|
+
attr_accessor :root_filename
|
22
|
+
attr_accessor :service
|
23
|
+
# 509 v3 extesions for stuff to signify purpose of this certificate (e.g.: client)
|
24
|
+
attr_accessor :extensions
|
25
|
+
attr_accessor :owner
|
26
|
+
|
27
|
+
# hostname of current machine
|
28
|
+
attr_accessor :hostname
|
29
|
+
# ipa realm
|
30
|
+
attr_accessor :realm
|
31
|
+
# name of certificate authority
|
32
|
+
attr_accessor :ca_name
|
33
|
+
|
34
|
+
def initialize(options = {})
|
35
|
+
options.each { |n, v| public_send("#{n}=", v) }
|
36
|
+
@ca_name ||= "ipa"
|
37
|
+
@extensions ||= %w(server client)
|
38
|
+
@realm ||= hostname.split(".")[1..-1].join(".").upcase if hostname
|
39
|
+
end
|
40
|
+
|
41
|
+
def request
|
42
|
+
if should_request_key?
|
43
|
+
principal.register
|
44
|
+
request_certificate
|
45
|
+
# NOTE: status probably changed
|
46
|
+
set_owner_of_key unless rejected?
|
47
|
+
end
|
48
|
+
|
49
|
+
if complete?
|
50
|
+
make_certs_world_readable
|
51
|
+
yield if block_given?
|
52
|
+
end
|
53
|
+
self
|
54
|
+
end
|
55
|
+
|
56
|
+
def principal
|
57
|
+
@principal ||= Principal.new(:hostname => hostname, :realm => realm, :service => service, :ca_name => ca_name)
|
58
|
+
end
|
59
|
+
|
60
|
+
def request_certificate
|
61
|
+
if rejected?
|
62
|
+
request_again
|
63
|
+
else
|
64
|
+
request_first
|
65
|
+
end
|
66
|
+
clear_status
|
67
|
+
end
|
68
|
+
|
69
|
+
# workaround
|
70
|
+
# currently, the -C is not run after the root certificate is written
|
71
|
+
def make_certs_world_readable
|
72
|
+
FileUtils.chmod(0644, [root_filename, cert_filename].compact)
|
73
|
+
end
|
74
|
+
|
75
|
+
def set_owner_of_key
|
76
|
+
FileUtils.chown(owner.split(".").first, owner.split(".")[1], key_filename) if owner && (owner != "root")
|
77
|
+
self
|
78
|
+
end
|
79
|
+
|
80
|
+
# statuses
|
81
|
+
|
82
|
+
def should_request_key?
|
83
|
+
no_key? || rejected?
|
84
|
+
end
|
85
|
+
|
86
|
+
def no_key?
|
87
|
+
status == :no_key
|
88
|
+
end
|
89
|
+
|
90
|
+
def rejected?
|
91
|
+
status == :rejected
|
92
|
+
end
|
93
|
+
|
94
|
+
def complete?
|
95
|
+
status == :complete
|
96
|
+
end
|
97
|
+
|
98
|
+
def clear_status
|
99
|
+
@status = nil
|
100
|
+
end
|
101
|
+
|
102
|
+
def status
|
103
|
+
@status ||= key_status
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def request_first
|
109
|
+
params = {
|
110
|
+
nil => "request",
|
111
|
+
"-c" => ca_name,
|
112
|
+
"-v" => nil, # verbose
|
113
|
+
"-w" => nil, # wait til completion if possible
|
114
|
+
"-k" => key_filename,
|
115
|
+
"-f" => cert_filename,
|
116
|
+
"-N" => principal.subject_name,
|
117
|
+
"-K" => principal.name,
|
118
|
+
"-C" => "chmod 644 #{cert_filename} #{root_filename}",
|
119
|
+
"-U" => key_ext_usage
|
120
|
+
}
|
121
|
+
params["-F"] = root_filename if root_filename
|
122
|
+
|
123
|
+
AwesomeSpawn.run!("/usr/bin/getcert", :params => params)
|
124
|
+
self
|
125
|
+
end
|
126
|
+
|
127
|
+
def request_again
|
128
|
+
AwesomeSpawn.run!("/usr/bin/getcert", :params => ["resubmit", "-w", "-f", cert_filename])
|
129
|
+
self
|
130
|
+
end
|
131
|
+
|
132
|
+
def key_filename
|
133
|
+
@key_filename || "#{cert_filename.chomp(File.extname(cert_filename))}.key"
|
134
|
+
end
|
135
|
+
|
136
|
+
def key_status
|
137
|
+
ret = AwesomeSpawn.run("/usr/bin/getcert", :params => ["status", "-f", cert_filename])
|
138
|
+
STATUS_RETURN_CODES[ret.exit_status]
|
139
|
+
end
|
140
|
+
|
141
|
+
def key_ext_usage
|
142
|
+
extensions.collect { |n| "id-kp-#{n}Auth" }.join(",")
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'util/postgres_admin'
|
4
|
+
|
5
|
+
module ManageIQ
|
6
|
+
module ApplianceConsole
|
7
|
+
# configure ssl certificates for postgres communication
|
8
|
+
# and appliance to appliance communications
|
9
|
+
class CertificateAuthority
|
10
|
+
CFME_DIR = "/var/www/miq/vmdb/certs"
|
11
|
+
PSQL_CLIENT_DIR = "/root/.postgresql"
|
12
|
+
|
13
|
+
# hostname of current machine
|
14
|
+
attr_accessor :hostname
|
15
|
+
attr_accessor :realm
|
16
|
+
# name of certificate authority
|
17
|
+
attr_accessor :ca_name
|
18
|
+
# true if we should configure postgres client
|
19
|
+
attr_accessor :pgclient
|
20
|
+
# true if we should configure postgres server
|
21
|
+
attr_accessor :pgserver
|
22
|
+
# true if we should configure http endpoint
|
23
|
+
attr_accessor :http
|
24
|
+
attr_accessor :verbose
|
25
|
+
|
26
|
+
def initialize(options = {})
|
27
|
+
options.each { |n, v| public_send("#{n}=", v) }
|
28
|
+
@ca_name ||= "ipa"
|
29
|
+
end
|
30
|
+
|
31
|
+
def ask_questions
|
32
|
+
if ipa?
|
33
|
+
self.principal = just_ask("IPA Server Principal", @principal)
|
34
|
+
self.password = ask_for_password("IPA Server Principal Password", @password)
|
35
|
+
end
|
36
|
+
self.pgclient = ask_yn("Configure certificate for postgres client", "Y")
|
37
|
+
self.pgserver = ask_yn("Configure certificate for postgres server", "Y")
|
38
|
+
self.http = ask_yn("Configure certificate for http server", "Y")
|
39
|
+
true
|
40
|
+
end
|
41
|
+
|
42
|
+
def activate
|
43
|
+
valid_environment?
|
44
|
+
|
45
|
+
configure_pgclient if pgclient
|
46
|
+
configure_pgserver if pgserver
|
47
|
+
configure_http if http
|
48
|
+
|
49
|
+
status_string
|
50
|
+
end
|
51
|
+
|
52
|
+
def valid_environment?
|
53
|
+
if ipa? && !ExternalHttpdAuthentication.ipa_client_configured?
|
54
|
+
raise ArgumentError, "ipa client not configured"
|
55
|
+
end
|
56
|
+
|
57
|
+
raise ArgumentError, "hostname needs to be defined" unless hostname
|
58
|
+
end
|
59
|
+
|
60
|
+
def configure_pgclient
|
61
|
+
unless File.exist?(PSQL_CLIENT_DIR)
|
62
|
+
FileUtils.mkdir_p(PSQL_CLIENT_DIR, :mode => 0700)
|
63
|
+
AwesomeSpawn.run!("/sbin/restorecon -R #{PSQL_CLIENT_DIR}")
|
64
|
+
end
|
65
|
+
|
66
|
+
self.pgclient = Certificate.new(
|
67
|
+
:cert_filename => "#{PSQL_CLIENT_DIR}/postgresql.crt",
|
68
|
+
:root_filename => "#{PSQL_CLIENT_DIR}/root.crt",
|
69
|
+
:service => "manageiq",
|
70
|
+
:extensions => %w(client),
|
71
|
+
:ca_name => ca_name,
|
72
|
+
:hostname => hostname,
|
73
|
+
:realm => realm,
|
74
|
+
).request.status
|
75
|
+
end
|
76
|
+
|
77
|
+
def configure_pgserver
|
78
|
+
cert = Certificate.new(
|
79
|
+
:cert_filename => "#{CFME_DIR}/postgres.crt",
|
80
|
+
:root_filename => "#{CFME_DIR}/root.crt",
|
81
|
+
:service => "postgresql",
|
82
|
+
:extensions => %w(server),
|
83
|
+
:ca_name => ca_name,
|
84
|
+
:hostname => hostname,
|
85
|
+
:realm => realm,
|
86
|
+
:owner => "postgres.postgres"
|
87
|
+
).request
|
88
|
+
|
89
|
+
if cert.complete?
|
90
|
+
say "configuring postgres to use certs"
|
91
|
+
# only telling postgres to rewrite server configuration files
|
92
|
+
# no need for username/password since not writing database.yml
|
93
|
+
InternalDatabaseConfiguration.new(:ssl => true).configure_postgres
|
94
|
+
LinuxAdmin::Service.new(PostgresAdmin.service_name).restart
|
95
|
+
end
|
96
|
+
self.pgserver = cert.status
|
97
|
+
end
|
98
|
+
|
99
|
+
def configure_http
|
100
|
+
cert = Certificate.new(
|
101
|
+
:key_filename => "#{CFME_DIR}/server.cer.key",
|
102
|
+
:cert_filename => "#{CFME_DIR}/server.cer",
|
103
|
+
:root_filename => "#{CFME_DIR}/root.crt",
|
104
|
+
:service => "HTTP",
|
105
|
+
:extensions => %w(server),
|
106
|
+
:ca_name => ca_name,
|
107
|
+
:hostname => hostname,
|
108
|
+
:owner => "apache.apache",
|
109
|
+
).request
|
110
|
+
if cert.complete?
|
111
|
+
say "configuring apache to use new certs"
|
112
|
+
LinuxAdmin::Service.new("httpd").restart
|
113
|
+
end
|
114
|
+
self.http = cert.status
|
115
|
+
end
|
116
|
+
|
117
|
+
def status
|
118
|
+
{"pgclient" => pgclient, "pgserver" => pgserver, "http" => http}.delete_if { |_n, v| !v }
|
119
|
+
end
|
120
|
+
|
121
|
+
def status_string
|
122
|
+
status.collect { |n, v| "#{n}: #{v}" }.join " "
|
123
|
+
end
|
124
|
+
|
125
|
+
def complete?
|
126
|
+
!status.values.detect { |v| v != ManageIQ::ApplianceConsole::Certificate::STATUS_COMPLETE }
|
127
|
+
end
|
128
|
+
|
129
|
+
def ipa?
|
130
|
+
ca_name == "ipa"
|
131
|
+
end
|
132
|
+
|
133
|
+
private
|
134
|
+
|
135
|
+
def log
|
136
|
+
say yield if verbose && block_given?
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,363 @@
|
|
1
|
+
require 'trollop'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
# support for appliance_console methods
|
5
|
+
unless defined?(say)
|
6
|
+
def say(arg)
|
7
|
+
puts(arg)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module ManageIQ
|
12
|
+
module ApplianceConsole
|
13
|
+
class Cli
|
14
|
+
attr_accessor :options
|
15
|
+
|
16
|
+
# machine host
|
17
|
+
def host
|
18
|
+
options[:host] || LinuxAdmin::Hosts.new.hostname
|
19
|
+
end
|
20
|
+
|
21
|
+
# database hostname
|
22
|
+
def hostname
|
23
|
+
options[:internal] ? "localhost" : options[:hostname]
|
24
|
+
end
|
25
|
+
|
26
|
+
def local?(name = hostname)
|
27
|
+
name.presence.in?(["localhost", "127.0.0.1", nil])
|
28
|
+
end
|
29
|
+
|
30
|
+
def set_host?
|
31
|
+
options[:host]
|
32
|
+
end
|
33
|
+
|
34
|
+
def key?
|
35
|
+
options[:key] || options[:fetch_key] || (local_database? && !key_configuration.key_exist?)
|
36
|
+
end
|
37
|
+
|
38
|
+
def database?
|
39
|
+
hostname
|
40
|
+
end
|
41
|
+
|
42
|
+
def local_database?
|
43
|
+
database? && local?(hostname)
|
44
|
+
end
|
45
|
+
|
46
|
+
def certs?
|
47
|
+
options[:postgres_client_cert] || options[:postgres_server_cert] || options[:http_cert]
|
48
|
+
end
|
49
|
+
|
50
|
+
def uninstall_ipa?
|
51
|
+
options[:uninstall_ipa]
|
52
|
+
end
|
53
|
+
|
54
|
+
def install_ipa?
|
55
|
+
options[:ipaserver]
|
56
|
+
end
|
57
|
+
|
58
|
+
def tmp_disk?
|
59
|
+
options[:tmpdisk]
|
60
|
+
end
|
61
|
+
|
62
|
+
def log_disk?
|
63
|
+
options[:logdisk]
|
64
|
+
end
|
65
|
+
|
66
|
+
def time_zone?
|
67
|
+
options[:timezone]
|
68
|
+
end
|
69
|
+
|
70
|
+
def extauth_opts?
|
71
|
+
options[:extauth_opts]
|
72
|
+
end
|
73
|
+
|
74
|
+
def set_server_state?
|
75
|
+
options[:server]
|
76
|
+
end
|
77
|
+
|
78
|
+
def db_hourly_maintenance?
|
79
|
+
options[:db_hourly_maintenance]
|
80
|
+
end
|
81
|
+
|
82
|
+
def initialize(options = {})
|
83
|
+
self.options = options
|
84
|
+
end
|
85
|
+
|
86
|
+
def disk_from_string(path)
|
87
|
+
return if path.blank?
|
88
|
+
path == "auto" ? disk : disk_by_path(path)
|
89
|
+
end
|
90
|
+
|
91
|
+
def disk
|
92
|
+
LinuxAdmin::Disk.local.detect { |d| d.partitions.empty? }
|
93
|
+
end
|
94
|
+
|
95
|
+
def disk_by_path(path)
|
96
|
+
LinuxAdmin::Disk.local.detect { |d| d.path == path }
|
97
|
+
end
|
98
|
+
|
99
|
+
def parse(args)
|
100
|
+
args.shift if args.first == "--" # Handle when called through script/runner
|
101
|
+
self.options = Trollop.options(args) do
|
102
|
+
banner "Usage: appliance_console_cli [options]"
|
103
|
+
|
104
|
+
opt :host, "/etc/hosts name", :type => :string, :short => 'H'
|
105
|
+
opt :region, "Region Number", :type => :integer, :short => "r"
|
106
|
+
opt :internal, "Internal Database", :short => 'i'
|
107
|
+
opt :hostname, "Database Hostname", :type => :string, :short => 'h'
|
108
|
+
opt :port, "Database Port", :type => :integer, :default => 5432
|
109
|
+
opt :username, "Database Username", :type => :string, :short => 'U', :default => "root"
|
110
|
+
opt :password, "Database Password", :type => :string, :short => "p"
|
111
|
+
opt :dbname, "Database Name", :type => :string, :short => "d", :default => "vmdb_production"
|
112
|
+
opt :db_hourly_maintenance, "Configure database hourly maintenance", :type => :bool, :short => :none
|
113
|
+
opt :standalone, "Run this server as a standalone database server", :type => :bool, :short => 'S'
|
114
|
+
opt :key, "Create encryption key", :type => :boolean, :short => "k"
|
115
|
+
opt :fetch_key, "SSH host with encryption key", :type => :string, :short => "K"
|
116
|
+
opt :force_key, "Forcefully create encryption key", :type => :boolean, :short => "f"
|
117
|
+
opt :sshlogin, "SSH login", :type => :string, :default => "root"
|
118
|
+
opt :sshpassword, "SSH password", :type => :string
|
119
|
+
opt :verbose, "Verbose", :type => :boolean, :short => "v"
|
120
|
+
opt :dbdisk, "Database Disk Path", :type => :string
|
121
|
+
opt :logdisk, "Log Disk Path", :type => :string
|
122
|
+
opt :tmpdisk, "Temp storage Disk Path", :type => :string
|
123
|
+
opt :uninstall_ipa, "Uninstall IPA Client", :type => :boolean, :default => false
|
124
|
+
opt :ipaserver, "IPA Server FQDN", :type => :string
|
125
|
+
opt :ipaprincipal, "IPA Server principal", :type => :string, :default => "admin"
|
126
|
+
opt :ipapassword, "IPA Server password", :type => :string
|
127
|
+
opt :ipadomain, "IPA Server domain (optional)", :type => :string
|
128
|
+
opt :iparealm, "IPA Server realm (optional)", :type => :string
|
129
|
+
opt :ca, "CA name used for certmonger", :type => :string, :default => "ipa"
|
130
|
+
opt :timezone, "Time zone", :type => :string
|
131
|
+
opt :postgres_client_cert, "install certs for postgres client", :type => :boolean
|
132
|
+
opt :postgres_server_cert, "install certs for postgres server", :type => :boolean
|
133
|
+
opt :http_cert, "install certs for http server", :type => :boolean
|
134
|
+
opt :extauth_opts, "External Authentication Options", :type => :string
|
135
|
+
opt :server, "Server status", :type => :string
|
136
|
+
end
|
137
|
+
Trollop.die :region, "needed when setting up a local database" if options[:region].nil? && local_database?
|
138
|
+
self
|
139
|
+
end
|
140
|
+
|
141
|
+
def run
|
142
|
+
Trollop.educate unless set_host? || key? || database? || tmp_disk? || log_disk? ||
|
143
|
+
uninstall_ipa? || install_ipa? || certs? || extauth_opts? ||
|
144
|
+
time_zone? || set_server_state? || db_hourly_maintenance?
|
145
|
+
if set_host?
|
146
|
+
system_hosts = LinuxAdmin::Hosts.new
|
147
|
+
system_hosts.hostname = options[:host]
|
148
|
+
system_hosts.set_loopback_hostname(options[:host])
|
149
|
+
system_hosts.save
|
150
|
+
LinuxAdmin::Service.new("network").restart
|
151
|
+
end
|
152
|
+
create_key if key?
|
153
|
+
set_db if database?
|
154
|
+
set_time_zone if time_zone?
|
155
|
+
config_db_hourly_maintenance if db_hourly_maintenance?
|
156
|
+
config_tmp_disk if tmp_disk?
|
157
|
+
config_log_disk if log_disk?
|
158
|
+
uninstall_ipa if uninstall_ipa?
|
159
|
+
install_ipa if install_ipa?
|
160
|
+
install_certs if certs?
|
161
|
+
extauth_opts if extauth_opts?
|
162
|
+
set_server_state if set_server_state?
|
163
|
+
rescue AwesomeSpawn::CommandResultError => e
|
164
|
+
say e.result.output
|
165
|
+
say e.result.error
|
166
|
+
say ""
|
167
|
+
raise
|
168
|
+
end
|
169
|
+
|
170
|
+
def set_db
|
171
|
+
raise "No encryption key (v2_key) present" unless key_configuration.key_exist?
|
172
|
+
raise "A password is required to configure a database" unless password?
|
173
|
+
if local?
|
174
|
+
set_internal_db
|
175
|
+
else
|
176
|
+
set_external_db
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def password?
|
181
|
+
options[:password] && !options[:password].strip.empty?
|
182
|
+
end
|
183
|
+
|
184
|
+
def set_internal_db
|
185
|
+
say "configuring internal database"
|
186
|
+
config = ManageIQ::ApplianceConsole::InternalDatabaseConfiguration.new({
|
187
|
+
:database => options[:dbname],
|
188
|
+
:region => options[:region],
|
189
|
+
:username => options[:username],
|
190
|
+
:password => options[:password],
|
191
|
+
:interactive => false,
|
192
|
+
:disk => disk_from_string(options[:dbdisk]),
|
193
|
+
:run_as_evm_server => !options[:standalone]
|
194
|
+
}.delete_if { |_n, v| v.nil? })
|
195
|
+
config.check_disk_is_mount_point
|
196
|
+
|
197
|
+
# create partition, pv, vg, lv, ext4, update fstab, mount disk
|
198
|
+
# initdb, relabel log directory for selinux, update configs,
|
199
|
+
# start pg, create user, create db update the rails configuration,
|
200
|
+
# verify, set up the database with region. activate does it all!
|
201
|
+
unless config.activate
|
202
|
+
say "Failed to configure internal database"
|
203
|
+
return
|
204
|
+
end
|
205
|
+
|
206
|
+
# enable/start related services
|
207
|
+
config.post_activation
|
208
|
+
rescue RuntimeError => e
|
209
|
+
say e.message
|
210
|
+
say "Failed to configure internal database"
|
211
|
+
end
|
212
|
+
|
213
|
+
def set_external_db
|
214
|
+
say "configuring external database"
|
215
|
+
config = ManageIQ::ApplianceConsole::ExternalDatabaseConfiguration.new({
|
216
|
+
:host => options[:hostname],
|
217
|
+
:port => options[:port],
|
218
|
+
:database => options[:dbname],
|
219
|
+
:region => options[:region],
|
220
|
+
:username => options[:username],
|
221
|
+
:password => options[:password],
|
222
|
+
:interactive => false,
|
223
|
+
}.delete_if { |_n, v| v.nil? })
|
224
|
+
|
225
|
+
# call create_or_join_region (depends on region value)
|
226
|
+
unless config.activate
|
227
|
+
say "Failed to configure external database"
|
228
|
+
return
|
229
|
+
end
|
230
|
+
|
231
|
+
# enable/start related services
|
232
|
+
config.post_activation
|
233
|
+
end
|
234
|
+
|
235
|
+
def set_time_zone
|
236
|
+
timezone_config = ManageIQ::ApplianceConsole::TimezoneConfiguration.new(options[:timezone])
|
237
|
+
if timezone_config.activate
|
238
|
+
say("Timezone configured")
|
239
|
+
else
|
240
|
+
say("Timezone not configured")
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
def key_configuration
|
245
|
+
@key_configuration ||= KeyConfiguration.new(
|
246
|
+
:action => options[:fetch_key] ? :fetch : :create,
|
247
|
+
:force => options[:fetch_key] ? true : options[:force_key],
|
248
|
+
:host => options[:fetch_key],
|
249
|
+
:login => options[:sshlogin],
|
250
|
+
:password => options[:sshpassword],
|
251
|
+
)
|
252
|
+
end
|
253
|
+
|
254
|
+
def create_key
|
255
|
+
say "#{key_configuration.action} encryption key"
|
256
|
+
unless key_configuration.activate
|
257
|
+
raise "Could not create encryption key (v2_key)"
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
def install_certs
|
262
|
+
say "creating ssl certificates"
|
263
|
+
config = CertificateAuthority.new(
|
264
|
+
:hostname => host,
|
265
|
+
:realm => options[:iparealm],
|
266
|
+
:ca_name => options[:ca],
|
267
|
+
:pgclient => options[:postgres_client_cert],
|
268
|
+
:pgserver => options[:postgres_server_cert],
|
269
|
+
:http => options[:http_cert],
|
270
|
+
:verbose => options[:verbose],
|
271
|
+
)
|
272
|
+
|
273
|
+
config.activate
|
274
|
+
say "\ncertificate result: #{config.status_string}"
|
275
|
+
unless config.complete?
|
276
|
+
say "After the certificates are retrieved, rerun to update service configuration files"
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
def install_ipa
|
281
|
+
raise "please uninstall ipa before reinstalling" if ExternalHttpdAuthentication.ipa_client_configured?
|
282
|
+
config = ExternalHttpdAuthentication.new(
|
283
|
+
host,
|
284
|
+
:ipaserver => options[:ipaserver],
|
285
|
+
:domain => options[:ipadomain],
|
286
|
+
:realm => options[:iparealm],
|
287
|
+
:principal => options[:ipaprincipal],
|
288
|
+
:password => options[:ipapassword],
|
289
|
+
)
|
290
|
+
|
291
|
+
config.post_activation if config.activate
|
292
|
+
end
|
293
|
+
|
294
|
+
def uninstall_ipa
|
295
|
+
say "Uninstalling IPA-client"
|
296
|
+
config = ExternalHttpdAuthentication.new
|
297
|
+
config.deactivate if config.ipa_client_configured?
|
298
|
+
end
|
299
|
+
|
300
|
+
def config_tmp_disk
|
301
|
+
if (tmp_disk = disk_from_string(options[:tmpdisk]))
|
302
|
+
say "creating temp disk"
|
303
|
+
config = ManageIQ::ApplianceConsole::TempStorageConfiguration.new(:disk => tmp_disk)
|
304
|
+
config.activate
|
305
|
+
else
|
306
|
+
report_disk_error(options[:tmpdisk])
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
def config_log_disk
|
311
|
+
if (log_disk = disk_from_string(options[:logdisk]))
|
312
|
+
say "creating log disk"
|
313
|
+
config = ManageIQ::ApplianceConsole::LogfileConfiguration.new(:disk => log_disk)
|
314
|
+
config.activate
|
315
|
+
else
|
316
|
+
report_disk_error(options[:logdisk])
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
def report_disk_error(missing_disk)
|
321
|
+
choose_disk = disk.try(:path)
|
322
|
+
if choose_disk
|
323
|
+
say "could not find disk #{missing_disk}"
|
324
|
+
say "if you pass auto, it will choose: #{choose_disk}"
|
325
|
+
else
|
326
|
+
say "no disks with a free partition"
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
def extauth_opts
|
331
|
+
extauthopts = ExternalAuthOptions.new
|
332
|
+
extauthopts_hash = extauthopts.parse(options[:extauth_opts])
|
333
|
+
raise "Must specify at least one external authentication option to set" unless extauthopts_hash.present?
|
334
|
+
extauthopts.update_configuration(extauthopts_hash)
|
335
|
+
end
|
336
|
+
|
337
|
+
def set_server_state
|
338
|
+
service = LinuxAdmin::Service.new("evmserverd")
|
339
|
+
service_running = service.running?
|
340
|
+
case options[:server]
|
341
|
+
when "start"
|
342
|
+
service.start unless service_running
|
343
|
+
when "stop"
|
344
|
+
service.stop if service_running
|
345
|
+
when "restart"
|
346
|
+
service.restart
|
347
|
+
else
|
348
|
+
raise "Invalid server action"
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
def config_db_hourly_maintenance
|
353
|
+
hourly = ManageIQ::ApplianceConsole::DatabaseMaintenanceHourly.new
|
354
|
+
hourly.requested_activate = true
|
355
|
+
hourly.activate
|
356
|
+
end
|
357
|
+
|
358
|
+
def self.parse(args)
|
359
|
+
new.parse(args).run
|
360
|
+
end
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|