Module: CemAcpt::Utils
- Extended by:
- Logging
- Defined in:
- lib/cem_acpt/utils.rb,
lib/cem_acpt/utils/ssh.rb,
lib/cem_acpt/utils/files.rb,
lib/cem_acpt/utils/shell.rb,
lib/cem_acpt/utils/puppet.rb,
lib/cem_acpt/utils/terminal.rb,
lib/cem_acpt/utils/winrm_runner.rb,
lib/cem_acpt/utils/finalizer_queue.rb
Overview
Utility methods and modules for CemAcpt.
Defined Under Namespace
Modules: Files, Puppet, SSH, Shell, Terminal, WinRMRunner Classes: FinalizerQueue, FinalizerQueueError
Constant Summary
Constants included from Logging
Class Method Summary collapse
- .get_windows_login_info(instance_name, hash_of_instance) ⇒ Object
- .reset_password_readiness_polling(instance_name) ⇒ Object
Methods included from Logging
current_log_config, current_log_config, current_log_format, current_log_format, current_log_level, current_log_level, included, logger, logger, new_log_config, new_log_config, new_log_formatter, new_log_formatter, new_log_level, new_log_level, new_logger, new_logger, verbose?, verbose?
Class Method Details
.get_windows_login_info(instance_name, hash_of_instance) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cem_acpt/utils.rb', line 42 def get_windows_login_info(instance_name, hash_of_instance) password_and_username = {} password_and_username[instance_name] = {} info = reset_password_readiness_polling(instance_name).split(%r{\r?\n})[1..2] info.each do |line| key_val = line.split(' ') password_and_username[instance_name][key_val[0].strip.delete(':')] = key_val[1].strip end password_and_username[instance_name]['ip'] = hash_of_instance['ip'] password_and_username[instance_name]['test_name'] = hash_of_instance['test_name'] password_and_username end |
.reset_password_readiness_polling(instance_name) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cem_acpt/utils.rb', line 16 def reset_password_readiness_polling(instance_name) attempts = 0 last_error = nil result = nil begin result = CemAcpt::Utils::Shell.run_cmd("echo Y | gcloud compute reset-windows-password #{instance_name} --zone=us-west1-b") rescue StandardError => e logger.debug('CemAcpt::Utils') { "Error polling for password readiness: #{e}" } last_error = e end while result.nil? || result.empty? raise "Instance not ready for password reset. Last error: #{last_error}" if attempts >= 60 # 10 minutes logger.info('CemAcpt') { "Waiting for instance #{instance_name} to be ready for password reset..." } sleep 10 begin result = CemAcpt::Utils::Shell.run_cmd("echo Y | gcloud compute reset-windows-password #{instance_name} --zone=us-west1-b") rescue StandardError => e logger.debug('CemAcpt::Utils') { "Error polling for password readiness: #{e}" } last_error = e end attempts += 1 end result end |