Module: CemAcpt::Utils

Extended by:
Logging
Defined in:
lib/cem_acpt/utils.rb,
lib/cem_acpt/utils/ssh.rb,
lib/cem_acpt/utils/puppet.rb,
lib/cem_acpt/utils/terminal.rb,
lib/cem_acpt/utils/winrm_runner.rb

Overview

Utility methods and modules for CemAcpt.

Defined Under Namespace

Modules: Puppet, SSH, Terminal, WinRMRunner

Constant Summary

Constants included from Logging

Logging::LEVEL_MAP

Class Method Summary collapse

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

Class Method Details

.get_windows_login_info(instance_name, hash_of_instance) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cem_acpt/utils.rb', line 35

def (instance_name, hash_of_instance)
  password_and_username = {}
  password_and_username[instance_name] = {}
  info = reset_password_readiness_polling(instance_name).split(/\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



14
15
16
17
18
19
20
21
22
23
# File 'lib/cem_acpt/utils.rb', line 14

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}" }
  return package_file
end

.reset_password_readiness_polling(instance_name) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/cem_acpt/utils.rb', line 25

def reset_password_readiness_polling(instance_name)
  result = %x(echo Y | gcloud compute reset-windows-password #{instance_name} --zone=us-west1-b)
  while result.empty?
    logger.info('CemAcpt') { "Waiting for instance #{instance_name} to be ready for password reset..." }
    sleep 10
    result = %x(echo Y | gcloud compute reset-windows-password #{instance_name} --zone=us-west1-b)
  end
  return result
end