Class: Beaker::DSL::PEClientTools::ConfigFileHelper::Private

Inherits:
Object
  • Object
show all
Extended by:
Beaker::DSL, Beaker::DSL::Patterns
Defined in:
lib/beaker-pe/pe-client-tools/config_file_helper.rb

Class Method Summary collapse

Class Method Details

.config_path(host, config_level) ⇒ Object


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/beaker-pe/pe-client-tools/config_file_helper.rb', line 43

def self.config_path(host, config_level)

  puppetlabs_dir = 'puppetlabs'
  puppetlabs_dir.prepend('.') if config_level == 'user'
  client_tools_path_array = [puppetlabs_dir, 'client-tools']

  case config_level

    when /global/
      @base_path = global_base_path(host)
    when /user/
      @base_path = home_dir(host)
    else
      raise ArgumentError.new("Unknown config level #{config_level}")
  end

  client_tools_dir = client_tools_path_array.unshift(@base_path).join(path_separator(host))
  opts = {:cmdexe => true}

  if host.platform =~ /win/
    host.exec(Beaker::Command.new('MD', [client_tools_dir.gsub('\\', '\\\\\\')], opts), :accept_all_exit_codes => true)
  else
    host.exec(Beaker::Command.new("mkdir -p #{client_tools_dir}", [], opts), :accept_all_exit_codes => true)
  end
  client_tools_dir
end

.file_name(tool) ⇒ Object


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/beaker-pe/pe-client-tools/config_file_helper.rb', line 29

def self.file_name(tool)
  if tool =~ /orchestrator|job|app/i
    'orchestrator.conf'
  elsif tool =~ /code/i
    'puppet-code.conf'
  elsif tool =~ /access/i
    'puppet-access.conf'
  elsif tool =~ /db|query/i
    'puppetdb.conf'
  else
    raise ArgumentError.new("Unknown pe-client-tool type '#{tool}'")
  end
end

.global_base_path(host) ⇒ Object


80
81
82
83
# File 'lib/beaker-pe/pe-client-tools/config_file_helper.rb', line 80

def self.global_base_path(host)

  (host.platform =~ /win/) ?host.exec(Beaker::Command.new('echo', ['%PROGRAMDATA%'], :cmdexe => true)).stdout.chomp : '/etc//'
end

.home_dir(host) ⇒ Object


70
71
72
73
74
75
76
77
78
# File 'lib/beaker-pe/pe-client-tools/config_file_helper.rb', line 70

def self.home_dir(host)

  if (host.platform =~ /win/) then
    @cmd = Beaker::Command.new('echo', ['%userprofile%'], :cmdexe => true)
  else
    @cmd = Beaker::Command.new('echo', ['$HOME'])
  end
  host.exec(@cmd).stdout.chomp
end

.path_separator(host) ⇒ Object


85
86
87
88
# File 'lib/beaker-pe/pe-client-tools/config_file_helper.rb', line 85

def self.path_separator(host)

  (host.platform =~ /win/) ? '\\' : '/'
end