vagrant-ohai 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6960eb2f2d91e26a168eb6366de96a914e02a727
4
- data.tar.gz: 763aa6dca8caf8cf6bf363138fe41e66ccc6fb6c
3
+ metadata.gz: e0d0a9f3a745d2df91a57d898ecbf6aeaeba33e6
4
+ data.tar.gz: e182c75c43d40941dad353e3d2f8403742527138
5
5
  SHA512:
6
- metadata.gz: 6adb89801c1bf641ef29f8742c8cfbd18fe942d64e156a92227b5248562e09667d1496db665511c774aee554f655266e39599d2b5483a08465c4fe274422a45e
7
- data.tar.gz: dda3aaf1f26d1223a5bb46e764cdd221dfb660a2c1d5dfddb3f5524a32f573a67e3ff7e674247e973eca79ef4f2697f0590e11ee243fcde685e0c5ce1f6af5d5
6
+ metadata.gz: 7f897a084f8946c0529bf390c2702f9ade73056b6eea10f3f04f7732c82bcf288f5246b57b7cc22daead5673b7ec84b45e561cb52354738ae5fc5c9f53a39c4e
7
+ data.tar.gz: 3613b2feca5bd22ecb7ba4013475b63455867f8b3cd47d30a145099a42ee03e45fb344e5dbd7ba2647708f8a8fa799aac659c66b4d677a21f5a9d9e08d25f1c6
data/lib/ohai/vagrant.rb CHANGED
@@ -1,34 +1,64 @@
1
1
  Ohai.plugin(:VboxIpaddress) do
2
2
 
3
+ def read_json(filename)
4
+ if defined? FFI_Yajl::Parser
5
+ FFI_Yajl::Parser.new.parse(IO.read(filename))
6
+ else
7
+ require 'json'
8
+ JSON.parse(IO.read(filename))
9
+ end
10
+ end
11
+
12
+ def lookup_address_by_nic(network, nic)
13
+ if network['interfaces'][nic]
14
+ network['interfaces'][nic]['addresses'].each do |ip, params|
15
+ if params['family'] == ('inet')
16
+ return [nic, ip]
17
+ end
18
+ end
19
+ end
20
+ return [nil, nil]
21
+ end
22
+
23
+ def lookup_address_by_ipaddress(network, ip)
24
+ nic = network['interfaces'].find do |nic, nic_info|
25
+ nic_info['addresses'].select {|addr, addr_info| addr_info['family'] == 'inet'}.keys.include?(ip)
26
+ end
27
+ if nic
28
+ return [nic, ip]
29
+ end
30
+ return [nil, nil]
31
+ end
32
+
3
33
  provides 'ipaddress'
4
34
 
5
35
  depends 'ipaddress'
36
+ depends 'network'
6
37
  depends 'network/interfaces'
7
38
  depends 'virtualization/system'
8
39
  depends 'etc/passwd'
9
40
 
41
+ collect_data(:default) do
10
42
  # Ohai hint
11
- unless File.exist?('/etc/chef/ohai_plugins/vagrant.json')
12
- Chef::Log.fail('Ohai has not set :ipaddress (Missing vagrant.json)')
13
- return
14
- end
15
- vagrant = JSON.parse(IO.read('/etc/chef/ohai_plugins/vagrant.json'))
43
+ unless File.exist?('/etc/chef/ohai_plugins/vagrant.json')
44
+ Ohai::Log.fail('Ohai has not set :ipaddress (Missing vagrant.json)')
45
+ else
46
+ vagrant = read_json('/etc/chef/ohai_plugins/vagrant.json')
16
47
 
17
- # requested nit
18
- nic = vagrant['primary_nic']
19
- if nic.nil?
20
- Chef::Log.debug('nic not set for vagrant-ohai plugin. Skipping')
21
- return
22
- end
23
-
24
- collect_data(:default) do
25
- if etc['passwd'].any? { |k, _v| k == 'vagrant' }
26
- if network['interfaces'][nic] && virtualization['system'] == 'vbox'
27
- network['interfaces'][nic]['addresses'].each do |ip, params|
28
- if params['family'] == ('inet')
29
- ipaddress ip
30
- Chef::Log.info("Ohai override :ipaddress to #{ip} from #{nic}")
31
- end
48
+ # requested nit
49
+ nic = vagrant['primary_nic']
50
+ if etc['passwd'].keys.include?('vagrant') && virtualization['system'] == 'vbox'
51
+ if nic
52
+ nic, addr = lookup_address_by_nic(network, nic)
53
+ elsif vagrant['private_ipv4']
54
+ nic, addr = lookup_address_by_ipaddress(network, vagrant['private_ipv4'])
55
+ else
56
+ nic, addr = nil, nil
57
+ Ohai::Log.info("Neither nic nor private_ipv4 are set, skipping")
58
+ end
59
+ if addr
60
+ Ohai::Log.info("Ohai override :ipaddress to #{addr} from #{nic}")
61
+ ipaddress addr
32
62
  end
33
63
  end
34
64
  end
@@ -44,6 +44,7 @@ module VagrantPlugins
44
44
  info = {}
45
45
  info[:box] = @machine.config.vm.box
46
46
  info[:primary_nic] = @machine.config.ohai.primary_nic
47
+ info[:private_ipv4] = private_ipv4
47
48
  info
48
49
  end
49
50
 
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Ohai
3
- VERSION = "0.1.9"
3
+ VERSION = "0.1.10"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-ohai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Avishai Ish-Shalom