Class: BarkingIguana::Compound::Vagrant

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Benchmark, Logging::Helper
Defined in:
lib/barking_iguana/compound/vagrant.rb

Instance Method Summary collapse

Constructor Details

#initialize(manager, options = {}) ⇒ Vagrant

Returns a new instance of Vagrant.



17
18
19
20
21
22
# File 'lib/barking_iguana/compound/vagrant.rb', line 17

def initialize manager, options = {}
  self.manager = manager
  self.vagrant_file_template_path = options[:vagrant_file_template_path] || File.expand_path('../../../../resources/Vagrantfile.erb', __FILE__)
  self.root = options[:root] || Dir.pwd
  self.environment = options[:environment] || {}
end

Instance Method Details

#assign_ip_addressesObject



56
57
58
59
60
61
62
63
# File 'lib/barking_iguana/compound/vagrant.rb', line 56

def assign_ip_addresses
  hosts.each do |h|
    next if valid_ip_address? h.ip_address
    ip_address = next_available_ip_address
    logger.debug { "Assigning #{h.name} an IP address: #{ip_address}" }
    h.assign_ip_address ip_address
  end
end

#prepareObject



65
66
67
68
# File 'lib/barking_iguana/compound/vagrant.rb', line 65

def prepare
  assign_ip_addresses
  write_vagrant_file
end

#refresh_statusObject



82
83
84
85
86
87
88
89
90
91
# File 'lib/barking_iguana/compound/vagrant.rb', line 82

def refresh_status
  current_status = status.split(/\n/)
  hosts.each do |host|
    current_status.each do |line|
      if line =~ /^#{host.name}\b/
        host.state = line.sub(host.name, '').sub('(virtualbox)', '').strip
      end
    end
  end
end

#vagrant_file_contentObject



70
71
72
# File 'lib/barking_iguana/compound/vagrant.rb', line 70

def vagrant_file_content
  ERB.new(vagrant_file_template).result binding
end

#vagrant_file_pathObject



78
79
80
# File 'lib/barking_iguana/compound/vagrant.rb', line 78

def vagrant_file_path
  File.join root, 'Vagrantfile'
end

#vagrant_file_templateObject



74
75
76
# File 'lib/barking_iguana/compound/vagrant.rb', line 74

def vagrant_file_template
  File.read vagrant_file_template_path
end

#write_vagrant_fileObject



49
50
51
52
53
54
# File 'lib/barking_iguana/compound/vagrant.rb', line 49

def write_vagrant_file
  logger.debug { "Writing Vagrantfile to #{vagrant_file_path}" }
  File.open vagrant_file_path, 'w' do |f|
    f.puts vagrant_file_content
  end
end