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
-
.package_win_module(module_dir) ⇒ Object
This is method currently unused, see lib/cem_acpt/utils/puppet.rb for details.
- .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
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/cem_acpt/utils.rb', line 54 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 |
.package_win_module(module_dir) ⇒ Object
This is method currently unused, see lib/cem_acpt/utils/puppet.rb for details.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cem_acpt/utils.rb', line 17 def package_win_module(module_dir) # Path to the package file package_file = File.join(module_dir, 'puppetlabs-cem_windows.tar.gz') # Remove the old package file if it exists FileUtils.rm_f(package_file) `cd #{module_dir} && touch puppetlabs-cem_windows.tar.gz && tar -czf puppetlabs-cem_windows.tar.gz --exclude=puppetlabs-cem_windows.tar.gz *` logger.info('CemAcpt') { "Windows module packaged at #{package_file}" } package_file end |
.reset_password_readiness_polling(instance_name) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cem_acpt/utils.rb', line 28 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 |