Class: Provisioner::Command::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/provisioner/command/base.rb

Direct Known Subclasses

Bootstrap, Provision

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_configuration, options = {}) ⇒ Base

Returns a new instance of Base.



9
10
11
12
13
14
15
16
17
18
# 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

Instance Attribute Details

#distroObject

Returns the value of attribute distro.



4
5
6
# File 'lib/provisioner/command/base.rb', line 4

def distro
  @distro
end

#environmentObject

Returns the value of attribute environment.



4
5
6
# File 'lib/provisioner/command/base.rb', line 4

def environment
  @environment
end

#flavorObject

Returns the value of attribute flavor.



4
5
6
# File 'lib/provisioner/command/base.rb', line 4

def flavor
  @flavor
end

#host_numberObject

Returns the value of attribute host_number.



4
5
6
# File 'lib/provisioner/command/base.rb', line 4

def host_number
  @host_number
end

#host_prefixObject

Returns the value of attribute host_prefix.



4
5
6
# File 'lib/provisioner/command/base.rb', line 4

def host_prefix
  @host_prefix
end

#host_presuffixObject

Returns the value of attribute host_presuffix.



4
5
6
# File 'lib/provisioner/command/base.rb', line 4

def host_presuffix
  @host_presuffix
end

#host_sequenceObject

Returns the value of attribute host_sequence.



4
5
6
# File 'lib/provisioner/command/base.rb', line 4

def host_sequence
  @host_sequence
end

#host_suffixObject

Returns the value of attribute host_suffix.



4
5
6
# File 'lib/provisioner/command/base.rb', line 4

def host_suffix
  @host_suffix
end

#imageObject

Returns the value of attribute image.



4
5
6
# File 'lib/provisioner/command/base.rb', line 4

def image
  @image
end

#log_dirObject

Returns the value of attribute log_dir.



4
5
6
# File 'lib/provisioner/command/base.rb', line 4

def log_dir
  @log_dir
end

#networksObject

Returns the value of attribute networks.



4
5
6
# File 'lib/provisioner/command/base.rb', line 4

def networks
  @networks
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/provisioner/command/base.rb', line 4

def options
  @options
end

#run_listObject

Returns the value of attribute run_list.



4
5
6
# File 'lib/provisioner/command/base.rb', line 4

def run_list
  @run_list
end

#ssh_userObject

Returns the value of attribute ssh_user.



4
5
6
# File 'lib/provisioner/command/base.rb', line 4

def ssh_user
  @ssh_user
end

#tagsObject

Returns the value of attribute tags.



4
5
6
# File 'lib/provisioner/command/base.rb', line 4

def tags
  @tags
end

Instance Method Details

#runObject



20
21
22
23
24
25
# File 'lib/provisioner/command/base.rb', line 20

def run
  shell_commands.each do |command|
    shellout command
    sleep 0.5
  end
end

#shell_commandsObject



31
32
33
34
35
# 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) ⇒ Object



27
28
29
# File 'lib/provisioner/command/base.rb', line 27

def shell_commands_for host_number
  raise 'Abstract method, implement in subclasses'
end