Class: VagrantSpec::MachineData

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant_spec/machine_data.rb

Overview

Handle machine data generation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ MachineData

Returns a new instance of MachineData.



10
11
12
13
14
# File 'lib/vagrant_spec/machine_data.rb', line 10

def initialize(env)
  @env      = env
  @m_finder = VagrantSpec::MachineFinder.new(@env)
  @data     = []
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



9
10
11
# File 'lib/vagrant_spec/machine_data.rb', line 9

def data
  @data
end

#envObject

Returns the value of attribute env.



9
10
11
# File 'lib/vagrant_spec/machine_data.rb', line 9

def env
  @env
end

#m_finderObject

Returns the value of attribute m_finder.



9
10
11
# File 'lib/vagrant_spec/machine_data.rb', line 9

def m_finder
  @m_finder
end

Instance Method Details

#generateObject



16
17
18
19
# File 'lib/vagrant_spec/machine_data.rb', line 16

def generate
  populate_data
  IO.write('.vagrantspec_machine_data', JSON.pretty_generate(@data))
end

#populate_dataObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/vagrant_spec/machine_data.rb', line 21

def populate_data
  @m_finder.machines do |m|
    private_key = m.ssh_info[:private_key_path][0]
    @data << {
      name:        m.name,
      host:        m.ssh_info[:host],
      port:        m.ssh_info[:port],
      username:    m.ssh_info[:username],
      private_key: private_key
    }
  end
end