class Provisioner::Command::Base

Attributes

distro[RW]
environment[RW]
flavor[RW]
host_number[RW]
host_prefix[RW]
host_presuffix[RW]
host_sequence[RW]
host_suffix[RW]
image[RW]
log_dir[RW]
networks[RW]
options[RW]
run_list[RW]
ssh_user[RW]
tags[RW]

Public Class Methods

new(template_configuration, options = {}) click to toggle source
# File lib/provisioner/command/base.rb, line 9
def initialize(template_configuration, options = {})
  @options = options
  @host_number = options[:number]
  template_configuration.each_pair do |key, value|
    self.send("#{key}=", value)
  end
  @ssh_user = options[:ssh_user] if options[:ssh_user]
  raise "Log path is required" unless @log_dir
  Dir.mkdir(log_dir) unless Dir.exists?(log_dir)
end

Public Instance Methods

run() click to toggle source
# File lib/provisioner/command/base.rb, line 20
def run
  shell_commands.each do |command|
    shellout command
    sleep 0.5
  end
end
shell_commands() click to toggle source
# File lib/provisioner/command/base.rb, line 31
def shell_commands
  host_numbers.map do |i|
    shell_commands_for(i.to_i)
  end.flatten
end
shell_commands_for(host_number) click to toggle source
# File lib/provisioner/command/base.rb, line 27
def shell_commands_for host_number
  raise 'Abstract method, implement in subclasses'
end

Protected Instance Methods

host_name(number) click to toggle source
# File lib/provisioner/command/base.rb, line 46
def host_name(number)
  host_name = sprintf('%s%03d', host_prefix, number)
  host_name += ".#{host_presuffix}" if host_presuffix
  host_name += ".#{host_suffix}" if host_suffix
  host_name
end
host_numbers() click to toggle source
# File lib/provisioner/command/base.rb, line 39
def host_numbers
  @host_numbers ||= begin
    return [host_number] if host_number
    eval "(#{host_sequence}).to_a"
  end
end
shellout(command) click to toggle source
# File lib/provisioner/command/base.rb, line 53
def shellout(command)
  puts "Running provision command:"
  puts command
  system(command)
end