Class: RefArchSetup::Install
- Inherits:
-
Object
- Object
- RefArchSetup::Install
- Defined in:
- lib/ref_arch_setup/install.rb
Overview
Installation helper
TODO: review the value for ClassLength rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#target_master ⇒ string
Host to install on.
Instance Method Summary collapse
-
#bootstrap(pe_conf_path, pe_tarball, pe_version) ⇒ true, false
Runs the initial bootstrapping install.
-
#copy_pe_tarball_on_target_master(tarball_path_on_target_master) ⇒ true, false
Copies the PE tarball from the specified location to the temp working directory on the target master.
-
#download_and_move_pe_tarball(url) ⇒ true, false
Downloads the PE tarball locally and moves it to the target master.
-
#download_pe_tarball(url, nodes) ⇒ true, false
Runs the download_pe_tarball Bolt task.
-
#file_exist_on_target_master?(path) ⇒ true, false
Determines whether the specified file exists on the target master.
-
#handle_pe_conf(pe_conf_path) ⇒ string
Handles user inputted pe.conf or if nil assumes it is in the CWD Validates file exists (allows just a dir to be given if pe.conf is in it) TODO Ensure it is valid once we have a reader/validator class Move it to the target_master.
-
#handle_pe_conf_path(pe_conf_path) ⇒ string
Handles user inputted pe.conf Validates file exists (allows just a dir to be given if pe.conf is in it) Also ensures the file is named pe.conf.
-
#handle_pe_tarball(pe_tarball) ⇒ string
Handles the PE tarball based on the the path (URL / file) and target master (local / remote).
-
#handle_tarball_path(path) ⇒ string
Handles the specified tarball path based on the target_master.
-
#handle_tarball_path_with_remote_target_master(path) ⇒ true, false
Handles the specified tarball path when the target master is not localhost.
-
#handle_tarball_url(url) ⇒ string
Handles the specified PE tarball URL by either downloading directly to the target master or downloading locally and copying to the target master.
-
#initialize(target_master) ⇒ void
constructor
Initialize class.
-
#make_tmp_work_dir ⇒ true, false
Creates a tmp work dir for ref_arch_setup on the target_host Doesn’t fail if the dir is already there.
-
#parse_url(url) ⇒ true
Parses the specified URL.
-
#specified_option?(value) ⇒ true, false
Determines whether the option is ‘specified’ (not nil and not empty).
-
#target_master_is_localhost? ⇒ true, false
Determines whether the target master is localhost.
-
#upload_pe_conf(src_pe_conf_path = "#{RAS_FIXTURES_PATH}/pe.conf", dest_pe_conf_path = "#{TMP_WORK_DIR}/pe.conf", target_master = @target_master) ⇒ true, false
Upload the pe.conf to the target_host.
-
#upload_pe_tarball(src_pe_tarball_path) ⇒ true, false
Upload the pe tarball to the target_host.
-
#valid_url?(pe_tarball) ⇒ true, false
Determines whether the specified path is a valid URL.
-
#validate_tarball_extension(pe_tarball) ⇒ true
Determines whether the specified path / url has a valid extension (.gz).
Constructor Details
#initialize(target_master) ⇒ void
Initialize class
27 28 29 |
# File 'lib/ref_arch_setup/install.rb', line 27 def initialize(target_master) @target_master = target_master end |
Instance Attribute Details
#target_master ⇒ string
Host to install on
19 20 21 |
# File 'lib/ref_arch_setup/install.rb', line 19 def target_master @target_master end |
Instance Method Details
#bootstrap(pe_conf_path, pe_tarball, pe_version) ⇒ true, false
Runs the initial bootstrapping install
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ref_arch_setup/install.rb', line 46 def bootstrap(pe_conf_path, pe_tarball, pe_version) if specified_option?(pe_tarball) puts "Proceeding with specified pe_tarball: #{pe_tarball}" @pe_tarball = pe_tarball else = "Either a pe_version or pe_tarball must be specified" raise unless specified_option?(pe_version) puts "Proceeding with specified pe_version: #{pe_version}" @pe_tarball = RefArchSetup::DownloadHelper.build_prod_tarball_url(pe_version, @target_master) end raise "Unable to create RAS working directory" unless make_tmp_work_dir conf_path_on_master = handle_pe_conf(pe_conf_path) tarball_path_on_master = handle_pe_tarball(@pe_tarball) params = {} params["pe_conf_path"] = conf_path_on_master params["pe_tarball_path"] = tarball_path_on_master output = BoltHelper.run_task_with_bolt(INSTALL_PE_TASK, params, @target_master) success = output.nil? ? false : true return success end |
#copy_pe_tarball_on_target_master(tarball_path_on_target_master) ⇒ true, false
Copies the PE tarball from the specified location to the temp working directory on the target master
310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/ref_arch_setup/install.rb', line 310 def copy_pe_tarball_on_target_master(tarball_path_on_target_master) filename = File.basename(tarball_path_on_target_master) success = if tarball_path_on_target_master == "#{TMP_WORK_DIR}/#{filename}" puts "Not copying the tarball as the source and destination are the same" true else command = "cp #{tarball_path_on_target_master} #{TMP_WORK_DIR}" output = BoltHelper.run_cmd_with_bolt(command, @target_master) output.nil? ? false : true end return success end |
#download_and_move_pe_tarball(url) ⇒ true, false
Downloads the PE tarball locally and moves it to the target master
258 259 260 261 262 263 |
# File 'lib/ref_arch_setup/install.rb', line 258 def download_and_move_pe_tarball(url) download_path = "#{TMP_WORK_DIR}/#{@pe_tarball_filename}" success = download_pe_tarball(url, "localhost") success = upload_pe_tarball(download_path) if success return success end |
#download_pe_tarball(url, nodes) ⇒ true, false
Runs the download_pe_tarball Bolt task
TODO: update to return the download path (SLV-186)
238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/ref_arch_setup/install.rb', line 238 def download_pe_tarball(url, nodes) puts "Attempting to download #{url} to #{nodes}" puts params = {} params["url"] = url params["destination"] = TMP_WORK_DIR output = BoltHelper.run_task_with_bolt(DOWNLOAD_PE_TARBALL_TASK, params, nodes) success = output.nil? ? false : true return success end |
#file_exist_on_target_master?(path) ⇒ true, false
Determines whether the specified file exists on the target master
TODO: SLV-187 - combine with copy_pe_tarball_on_target_master
214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/ref_arch_setup/install.rb', line 214 def file_exist_on_target_master?(path) command = "[ -f #{path} ]" exists = true begin BoltHelper.run_cmd_with_bolt(command, @target_master) rescue exists = false end return exists end |
#handle_pe_conf(pe_conf_path) ⇒ string
Handles user inputted pe.conf or if nil assumes it is in the CWD Validates file exists (allows just a dir to be given if pe.conf is in it) TODO Ensure it is valid once we have a reader/validator class Move it to the target_master
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/ref_arch_setup/install.rb', line 101 def handle_pe_conf(pe_conf_path) conf_path_on_master = "#{TMP_WORK_DIR}/pe.conf" if pe_conf_path.nil? file_path = Dir.pwd + "/pe.conf" raise("No pe.conf file found in current working directory") unless File.exist?(file_path) else file_path = handle_pe_conf_path(pe_conf_path) end success = upload_pe_conf(file_path) raise "Unable to upload pe.conf file to #{@target_master}" unless success return conf_path_on_master end |
#handle_pe_conf_path(pe_conf_path) ⇒ string
Handles user inputted pe.conf Validates file exists (allows just a dir to be given if pe.conf is in it) Also ensures the file is named pe.conf
128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/ref_arch_setup/install.rb', line 128 def handle_pe_conf_path(pe_conf_path) file_path = File.(pe_conf_path) if File.directory?(file_path) full_path = file_path + "/pe.conf" raise("No pe.conf file found in directory: #{file_path}") unless File.exist?(full_path) file_path = full_path else filename = File.basename(file_path) raise("Specified file is not named pe.conf #{file_path}") unless filename.eql?("pe.conf") raise("pe.conf file not found #{file_path}") unless File.exist?(file_path) end return file_path end |
#handle_pe_tarball(pe_tarball) ⇒ string
Handles the PE tarball based on the the path (URL / file) and target master (local / remote)
391 392 393 394 395 396 397 398 399 400 401 402 403 |
# File 'lib/ref_arch_setup/install.rb', line 391 def handle_pe_tarball(pe_tarball) error = "Unable to handle the specified PE tarball path: #{pe_tarball}" validate_tarball_extension(pe_tarball) tarball_path_on_master = if valid_url?(pe_tarball) handle_tarball_url(pe_tarball) else handle_tarball_path(pe_tarball) end raise error unless tarball_path_on_master return tarball_path_on_master end |
#handle_tarball_path(path) ⇒ string
Handles the specified tarball path based on the target_master
TODO: improve “host to install on”? (“host where PE will be installed?”)
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
# File 'lib/ref_arch_setup/install.rb', line 360 def handle_tarball_path(path) filename = File.basename(path) tarball_path_on_master = "#{TMP_WORK_DIR}/#{filename}" file_not_found_error = "File not found: #{path}" upload_error = "Unable to upload tarball to the RAS working directory on #{@target_master}" copy_error = "Unable to copy tarball to the RAS working directory on #{@target_master}" if target_master_is_localhost? raise file_not_found_error unless File.exist?(path) success = upload_pe_tarball(path) error = copy_error unless success else success = handle_tarball_path_with_remote_target_master(path) error = upload_error unless success end raise error unless success return tarball_path_on_master end |
#handle_tarball_path_with_remote_target_master(path) ⇒ true, false
Handles the specified tarball path when the target master is not localhost
333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/ref_arch_setup/install.rb', line 333 def handle_tarball_path_with_remote_target_master(path) remote_flag = "#{@target_master}:" if path.start_with?(remote_flag) actual_path = path.sub!(remote_flag, "") success = file_exist_on_target_master?(actual_path) success = copy_pe_tarball_on_target_master(actual_path) if success else raise "File not found: #{path}" unless File.exist?(path) success = upload_pe_tarball(path) end return success end |
#handle_tarball_url(url) ⇒ string
Handles the specified PE tarball URL by either downloading directly to the target master or downloading locally and copying to the target master
rubocop:disable Metrics/MethodLength
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/ref_arch_setup/install.rb', line 276 def handle_tarball_url(url) parse_url(url) tarball_path_on_master = "#{TMP_WORK_DIR}/#{@pe_tarball_filename}" success = false if target_master_is_localhost? success = download_pe_tarball(url, "localhost") raise "Failed downloading #{url} to localhost" unless success else begin # if downloading to the target master fails success = download_pe_tarball(url, @target_master) rescue # try to download locally and then upload puts "Unable to download the tarball directly to #{@target_master}" success = download_and_move_pe_tarball(url) ensure raise "Failed downloading #{url} locally and moving to #{@target_master}" unless success end end return tarball_path_on_master end |
#make_tmp_work_dir ⇒ true, false
Creates a tmp work dir for ref_arch_setup on the target_host Doesn’t fail if the dir is already there.
413 414 415 |
# File 'lib/ref_arch_setup/install.rb', line 413 def make_tmp_work_dir BoltHelper.make_dir(TMP_WORK_DIR, @target_master) end |
#parse_url(url) ⇒ true
Parses the specified URL
165 166 167 168 169 170 171 172 173 |
# File 'lib/ref_arch_setup/install.rb', line 165 def parse_url(url) begin @pe_tarball_uri = URI.parse(url) @pe_tarball_filename = File.basename(@pe_tarball_uri.path) rescue raise "Unable to parse the specified URL: #{url}" end return true end |
#specified_option?(value) ⇒ true, false
Determines whether the option is ‘specified’ (not nil and not empty)
83 84 85 86 |
# File 'lib/ref_arch_setup/install.rb', line 83 def specified_option?(value) specified = value.nil? || value.empty? ? false : true return specified end |
#target_master_is_localhost? ⇒ true, false
Determines whether the target master is localhost
TODO: (SLV-185) Improve check for localhost
198 199 200 201 202 |
# File 'lib/ref_arch_setup/install.rb', line 198 def target_master_is_localhost? is_localhost = false is_localhost = true if @target_master.include?("localhost") return is_localhost end |
#upload_pe_conf(src_pe_conf_path = "#{RAS_FIXTURES_PATH}/pe.conf", dest_pe_conf_path = "#{TMP_WORK_DIR}/pe.conf", target_master = @target_master) ⇒ true, false
Upload the pe.conf to the target_host
426 427 428 429 430 431 432 433 |
# File 'lib/ref_arch_setup/install.rb', line 426 def upload_pe_conf(src_pe_conf_path = "#{RAS_FIXTURES_PATH}/pe.conf", dest_pe_conf_path = "#{TMP_WORK_DIR}/pe.conf", target_master = @target_master) output = BoltHelper.upload_file(src_pe_conf_path, dest_pe_conf_path, target_master) success = output.nil? ? false : true return success end |
#upload_pe_tarball(src_pe_tarball_path) ⇒ true, false
Upload the pe tarball to the target_host
442 443 444 445 446 447 448 449 450 451 452 453 |
# File 'lib/ref_arch_setup/install.rb', line 442 def upload_pe_tarball(src_pe_tarball_path) file_name = File.basename(src_pe_tarball_path) dest_pe_tarball_path = "#{TMP_WORK_DIR}/#{file_name}" puts "Attempting upload from #{src_pe_tarball_path} " \ "to #{dest_pe_tarball_path} on #{@target_master}" output = BoltHelper.upload_file(src_pe_tarball_path, dest_pe_tarball_path, @target_master) success = output.nil? ? false : true return success end |
#valid_url?(pe_tarball) ⇒ true, false
Determines whether the specified path is a valid URL
150 151 152 153 154 |
# File 'lib/ref_arch_setup/install.rb', line 150 def valid_url?(pe_tarball) valid = false valid = true if pe_tarball =~ /\A#{URI.regexp(%w[http https])}\z/ return valid end |
#validate_tarball_extension(pe_tarball) ⇒ true
Determines whether the specified path / url has a valid extension (.gz)
184 185 186 187 188 |
# File 'lib/ref_arch_setup/install.rb', line 184 def validate_tarball_extension(pe_tarball) = "Invalid extension for tarball: #{pe_tarball}; extension must be .tar or .tar.gz" raise() unless pe_tarball =~ /.*\.(tar|tar\.gz)$/ return true end |