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 +4 -4
- data/lib/ohai/vagrant.rb +50 -20
- data/lib/vagrant-ohai/action_install_ohai_plugin.rb +1 -0
- data/lib/vagrant-ohai/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0d0a9f3a745d2df91a57d898ecbf6aeaeba33e6
|
4
|
+
data.tar.gz: e182c75c43d40941dad353e3d2f8403742527138
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
data/lib/vagrant-ohai/version.rb
CHANGED