chef-extensions 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/.deliver ADDED
@@ -0,0 +1,2 @@
1
+ APP="chef-extensions docs"
2
+ STRATEGY="gh-pages"
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ gh-pages
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use --create ree@chef-extensions
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rake/testtask'
5
5
 
6
6
  require 'rdiscount'
7
7
  require 'rocco/tasks'
8
- Rocco::make 'docs/'
8
+ Rocco::make 'gh-pages/'
9
9
 
10
10
  Rake::TestTask.new do |t|
11
11
  t.pattern = 'test/**/*_test.rb'
@@ -18,43 +18,20 @@ task :version do
18
18
  puts Chef::Extensions::VERSION
19
19
  end
20
20
 
21
- desc 'Build rocco docs'
22
- task :docs => :rocco
23
- directory 'docs/'
24
- # Alias for docs task
21
+ desc 'Build rocco gh-pages'
22
+ task :docs => :rocco do
23
+ %x{
24
+ cd gh-pages;
25
+ mv lib/* .;
26
+ rm -fr lib;
27
+ cp chef-extensions.html index.html
28
+ }
29
+ end
30
+ # Aliases for docs task
25
31
  task :doc => :docs
32
+ task :generate => :docs
26
33
 
27
34
  desc 'Build docs and open in browser for the reading'
28
35
  task :read => :docs do
29
- sh 'open docs/lib/chef-extensions.html'
30
- end
31
-
32
- # Make index.html a copy of chef-extensions.html
33
- file 'docs/index.html' => 'docs/lib/chef-extensions.html' do |f|
34
- cp 'docs/lib/chef-extensions.html', 'docs/index.html', :preserve => true
35
- end
36
- task :docs => 'docs/index.html'
37
- CLEAN.include 'docs/index.html'
38
-
39
- # Update the pages/ directory clone
40
- file 'docs/.git' => ['docs/', '.git/refs/heads/gh-pages'] do |f|
41
- sh "cd docs && git init -q && git remote add o ../.git" if !File.exist?(f.name)
42
- sh "cd docs && git fetch -q o && git reset -q --hard o/gh-pages && touch ."
43
- end
44
- CLOBBER.include 'docs/.git'
45
-
46
- # GITHUB PAGES ===============================================================
47
-
48
- desc 'Update gh-pages branch'
49
- task :pages => ['docs/.git', :docs] do
50
- rev = `git rev-parse --short HEAD`.strip
51
- Dir.chdir 'docs' do
52
- sh "git add *.html"
53
- sh "git commit -m 'rebuild pages from #{rev}'" do |ok,res|
54
- if ok
55
- verbose { puts "gh-pages updated" }
56
- sh "git push -q o HEAD:gh-pages"
57
- end
58
- end
59
- end
36
+ sh 'open gh-pages/index.html'
60
37
  end
@@ -3,7 +3,7 @@ class Chef
3
3
  module EC2
4
4
  extend self
5
5
 
6
- # **Get the instance ID from AWS's metadata service**
6
+ # **Get the instance ID from AWS's metadata service** <br />
7
7
  # If we don't hear back within 1 second, time out.
8
8
  def instance_id
9
9
  `curl --connect-timeout 1 http://169.254.169.254/2011-01-01/meta-data/instance-id 2>&1`.chomp
@@ -1,25 +1,53 @@
1
- require 'socket'
1
+ require File.expand_path('../platform', __FILE__)
2
2
 
3
3
  class Chef
4
4
  module Extensions
5
5
  module IP
6
6
  extend self
7
7
 
8
+ # **Get all local IPv4 addresses** <br />
9
+ # It excludes localhost. Easily adaptable to IPv6. <br />
10
+ # In Ruby 1.9, this is a simple call to `Socket.ip_address_list`.
8
11
  def all
9
- @all ||= Socket.ip_address_list
12
+ local_ips - localhost
10
13
  end
11
14
 
12
- def ipv4
13
- all.select(&:ipv4?)
14
- end
15
+ protected
15
16
 
16
- def ipv6
17
- all.select(&:ipv6?)
18
- end
17
+ def local_ips
18
+ `echo "#{ifconfig}" | #{filter}`.split("\n")
19
+ end
20
+
21
+ def localhost
22
+ ["127.0.0.1"]
23
+ end
24
+
25
+ def ifconfig
26
+ @ifconfig ||= `ifconfig`
27
+ end
28
+
29
+ def filter
30
+ @filter ||= if Platform.linux?
31
+ linux_filter
32
+ elsif Platform.os_x?
33
+ os_x_filter
34
+ else
35
+ raise "Only works on Linux or OS X"
36
+ end
37
+ end
38
+
39
+ def linux_filter
40
+ "#{awk} { print $4 }'"
41
+ end
42
+
43
+ def os_x_filter
44
+ "#{awk} { print $2 }'"
45
+ end
46
+
47
+ def awk
48
+ %{awk -F"[: ]+" '/inet /}
49
+ end
19
50
 
20
- def addresses(type)
21
- self.send(type).map(&:ip_address)
22
- end
23
51
  end
24
52
  end
25
53
  end
@@ -0,0 +1,19 @@
1
+ class Chef
2
+ module Extensions
3
+ module Platform
4
+ extend self
5
+
6
+ # Returns true if running on OS X
7
+ #
8
+ def os_x?
9
+ RUBY_PLATFORM.index('darwin')
10
+ end
11
+
12
+ # Returns true if running on Linux
13
+ #
14
+ def linux?
15
+ RUBY_PLATFORM.index('linux')
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,6 +1,5 @@
1
1
  class Chef
2
2
  module Extensions
3
- # Gem version
4
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
5
4
  end
6
5
  end
@@ -4,35 +4,35 @@ require 'chef-extensions/ip'
4
4
  class Chef
5
5
  module Extensions
6
6
  describe IP do
7
- describe "all" do
8
- it "returns all local ips" do
9
- IP.all.each do |ip|
10
- ip.must_be_instance_of Addrinfo
11
- end
7
+ describe "osx" do
8
+ before do
9
+ ifconfig = IO.read(File.expand_path('../../fixtures/osx.ifconfig', __FILE__))
10
+ IP.instance_variable_set(:@ifconfig, ifconfig)
12
11
  end
13
- end
14
12
 
15
- describe "ipv4" do
16
- it "only returns IPv4 ips" do
17
- IP.ipv4.each do |ip|
18
- ip.must_be :ipv4?
19
- end
13
+ it "all IPv4 addresses, excluding localhost" do
14
+ IP.all.must_equal([
15
+ "10.100.1.11",
16
+ "10.100.1.10",
17
+ "192.168.86.1",
18
+ "192.168.203.1",
19
+ "11.11.11.1"
20
+ ])
20
21
  end
21
22
  end
22
23
 
23
- describe "ipv6" do
24
- it "only returns IPv6 ips" do
25
- IP.ipv6.each do |ip|
26
- ip.must_be :ipv6?
27
- end
24
+ describe "ubuntu" do
25
+ before do
26
+ ifconfig = IO.read(File.expand_path('../../fixtures/ubuntu.ifconfig', __FILE__))
27
+ IP.instance_variable_set(:@ifconfig, ifconfig)
28
+ IP.instance_variable_set(:@filter, IP.send(:linux_filter))
28
29
  end
29
- end
30
30
 
31
- describe "addresses" do
32
- it "returns ips of a certain type as strings" do
33
- IP.addresses(:ipv4).each do |ip|
34
- ip.must_match /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/
35
- end
31
+ it "all IPv4 addresses, excluding localhost" do
32
+ IP.all.must_equal([
33
+ "10.0.1.10",
34
+ "11.11.11.10"
35
+ ])
36
36
  end
37
37
  end
38
38
  end
@@ -0,0 +1,33 @@
1
+ lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
2
+ inet 127.0.0.1 netmask 0xff000000
3
+ inet6 ::1 prefixlen 128
4
+ inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
5
+ gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
6
+ stf0: flags=0<> mtu 1280
7
+ en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
8
+ ether 58:b0:35:7f:97:aa
9
+ inet6 fe80::5ab0:35ff:fe7f:97aa%en1 prefixlen 64 scopeid 0x4
10
+ inet 10.100.1.11 netmask 0xffffff00 broadcast 10.100.2.255
11
+ media: autoselect
12
+ status: active
13
+ en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
14
+ ether 58:b0:35:f5:84:1e
15
+ inet6 fe80::5ab0:35ff:fef5:841e%en0 prefixlen 64 scopeid 0x5
16
+ inet 10.100.1.10 netmask 0xffffff00 broadcast 10.100.2.255
17
+ media: autoselect (1000baseT <full-duplex,flow-control>)
18
+ status: active
19
+ fw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 4078
20
+ lladdr d8:30:62:ff:fe:f3:80:76
21
+ media: autoselect <full-duplex>
22
+ status: inactive
23
+ vmnet1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
24
+ ether 00:50:56:c0:00:01
25
+ inet 192.168.86.1 netmask 0xffffff00 broadcast 192.168.86.255
26
+ vmnet8: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
27
+ ether 00:50:56:c0:00:08
28
+ inet 192.168.203.1 netmask 0xffffff00 broadcast 192.168.203.255
29
+ vboxnet0: flags=8842<BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
30
+ ether 0a:00:27:00:00:00
31
+ vboxnet1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
32
+ ether 0a:00:27:00:00:01
33
+ inet 11.11.11.1 netmask 0xffffff00 broadcast 11.11.11.255
@@ -0,0 +1,26 @@
1
+ eth0 Link encap:Ethernet HWaddr 08:00:27:41:53:f3
2
+ inet addr:10.0.1.10 Bcast:10.0.2.255 Mask:255.255.255.0
3
+ inet6 addr: fe80::a00:27ff:fe41:53f3/64 Scope:Link
4
+ UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
5
+ RX packets:369 errors:0 dropped:0 overruns:0 frame:0
6
+ TX packets:256 errors:0 dropped:0 overruns:0 carrier:0
7
+ collisions:0 txqueuelen:1000
8
+ RX bytes:44565 (44.5 KB) TX bytes:37502 (37.5 KB)
9
+
10
+ eth1 Link encap:Ethernet HWaddr 08:00:27:76:c1:19
11
+ inet addr:11.11.11.10 Bcast:11.11.11.255 Mask:255.255.255.0
12
+ inet6 addr: fe80::a00:27ff:fe76:c119/64 Scope:Link
13
+ UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
14
+ RX packets:114 errors:0 dropped:0 overruns:0 frame:0
15
+ TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
16
+ collisions:0 txqueuelen:1000
17
+ RX bytes:15736 (15.7 KB) TX bytes:468 (468.0 B)
18
+
19
+ lo Link encap:Local Loopback
20
+ inet addr:127.0.0.1 Mask:255.0.0.0
21
+ inet6 addr: ::1/128 Scope:Host
22
+ UP LOOPBACK RUNNING MTU:16436 Metric:1
23
+ RX packets:8 errors:0 dropped:0 overruns:0 frame:0
24
+ TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
25
+ collisions:0 txqueuelen:0
26
+ RX bytes:560 (560.0 B) TX bytes:560 (560.0 B)
metadata CHANGED
@@ -1,153 +1,197 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: chef-extensions
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.0
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 1
10
+ version: 0.2.1
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Gerhard Lazu
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-01-24 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2012-02-15 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: chef
16
- requirement: &2164269240 !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
17
24
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
22
32
  type: :development
23
- prerelease: false
24
- version_requirements: *2164269240
25
- - !ruby/object:Gem::Dependency
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
26
35
  name: guard-minitest
27
- requirement: &2164268620 !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
28
38
  none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
33
46
  type: :development
34
- prerelease: false
35
- version_requirements: *2164268620
36
- - !ruby/object:Gem::Dependency
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
37
49
  name: guard-rocco
38
- requirement: &2160320740 !ruby/object:Gem::Requirement
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
39
52
  none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '0'
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
44
60
  type: :development
45
- prerelease: false
46
- version_requirements: *2160320740
47
- - !ruby/object:Gem::Dependency
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
48
63
  name: minitest
49
- requirement: &2160319940 !ruby/object:Gem::Requirement
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
50
66
  none: false
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
55
74
  type: :development
56
- prerelease: false
57
- version_requirements: *2160319940
58
- - !ruby/object:Gem::Dependency
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
59
77
  name: pry
60
- requirement: &2160319280 !ruby/object:Gem::Requirement
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
61
80
  none: false
62
- requirements:
63
- - - ! '>='
64
- - !ruby/object:Gem::Version
65
- version: '0'
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
66
88
  type: :development
67
- prerelease: false
68
- version_requirements: *2160319280
69
- - !ruby/object:Gem::Dependency
89
+ version_requirements: *id005
90
+ - !ruby/object:Gem::Dependency
70
91
  name: rdiscount
71
- requirement: &2160318580 !ruby/object:Gem::Requirement
92
+ prerelease: false
93
+ requirement: &id006 !ruby/object:Gem::Requirement
72
94
  none: false
73
- requirements:
74
- - - ! '>='
75
- - !ruby/object:Gem::Version
76
- version: '0'
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
77
102
  type: :development
78
- prerelease: false
79
- version_requirements: *2160318580
80
- - !ruby/object:Gem::Dependency
103
+ version_requirements: *id006
104
+ - !ruby/object:Gem::Dependency
81
105
  name: rocco
82
- requirement: &2160317500 !ruby/object:Gem::Requirement
106
+ prerelease: false
107
+ requirement: &id007 !ruby/object:Gem::Requirement
83
108
  none: false
84
- requirements:
85
- - - ! '>='
86
- - !ruby/object:Gem::Version
87
- version: '0'
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ hash: 3
113
+ segments:
114
+ - 0
115
+ version: "0"
88
116
  type: :development
89
- prerelease: false
90
- version_requirements: *2160317500
91
- - !ruby/object:Gem::Dependency
117
+ version_requirements: *id007
118
+ - !ruby/object:Gem::Dependency
92
119
  name: turn
93
- requirement: &2160315680 !ruby/object:Gem::Requirement
120
+ prerelease: false
121
+ requirement: &id008 !ruby/object:Gem::Requirement
94
122
  none: false
95
- requirements:
96
- - - ! '>='
97
- - !ruby/object:Gem::Version
98
- version: '0'
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ hash: 3
127
+ segments:
128
+ - 0
129
+ version: "0"
99
130
  type: :development
100
- prerelease: false
101
- version_requirements: *2160315680
131
+ version_requirements: *id008
102
132
  description: Commands useful for checking internet connectivity, VM presence etc.
103
- email:
133
+ email:
104
134
  - gerhard@lazu.co.uk
105
135
  executables: []
136
+
106
137
  extensions: []
138
+
107
139
  extra_rdoc_files: []
108
- files:
140
+
141
+ files:
142
+ - .deliver
109
143
  - .gitignore
144
+ - .rvmrc
110
145
  - Gemfile
111
146
  - Guardfile
112
147
  - LICENSE
113
148
  - README.md
114
149
  - Rakefile
115
150
  - chef-extensions.gemspec
116
- - docs/index.html
117
- - docs/lib/chef-extensions.html
118
- - docs/lib/chef-extensions/ip.html
119
- - docs/lib/chef-extensions/version.html
120
151
  - lib/chef-extensions.rb
121
152
  - lib/chef-extensions/ec2.rb
122
153
  - lib/chef-extensions/ip.rb
154
+ - lib/chef-extensions/platform.rb
123
155
  - lib/chef-extensions/version.rb
124
156
  - test/chef-extensions/ip_test.rb
157
+ - test/fixtures/osx.ifconfig
158
+ - test/fixtures/ubuntu.ifconfig
125
159
  - test/test_helper.rb
126
160
  homepage: http://gchef.github.com/chef-extensions
127
161
  licenses: []
162
+
128
163
  post_install_message:
129
164
  rdoc_options: []
130
- require_paths:
165
+
166
+ require_paths:
131
167
  - lib
132
- required_ruby_version: !ruby/object:Gem::Requirement
168
+ required_ruby_version: !ruby/object:Gem::Requirement
133
169
  none: false
134
- requirements:
135
- - - ! '>='
136
- - !ruby/object:Gem::Version
137
- version: '0'
138
- required_rubygems_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ hash: 3
174
+ segments:
175
+ - 0
176
+ version: "0"
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
178
  none: false
140
- requirements:
141
- - - ! '>='
142
- - !ruby/object:Gem::Version
143
- version: '0'
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ hash: 3
183
+ segments:
184
+ - 0
185
+ version: "0"
144
186
  requirements: []
187
+
145
188
  rubyforge_project: chef-extensions
146
189
  rubygems_version: 1.8.10
147
190
  signing_key:
148
191
  specification_version: 3
149
192
  summary: Chef extensions, can be used stand-alone
150
- test_files:
193
+ test_files:
151
194
  - test/chef-extensions/ip_test.rb
195
+ - test/fixtures/osx.ifconfig
196
+ - test/fixtures/ubuntu.ifconfig
152
197
  - test/test_helper.rb
153
- has_rdoc:
data/docs/index.html DELETED
@@ -1,108 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
- <title>chef-extensions.rb</title>
6
- <link rel="stylesheet" href="http://jashkenas.github.com/docco/resources/docco.css">
7
- </head>
8
- <body>
9
- <div id='container'>
10
- <div id="background"></div>
11
- <div id="jump_to">
12
- Jump To &hellip;
13
- <div id="jump_wrapper">
14
- <div id="jump_page">
15
- <a class="source" href="chef-extensions.html">chef-extensions.rb</a>
16
- <a class="source" href="chef-extensions/version.html">version.rb</a>
17
- </div>
18
- </div>
19
- </div>
20
- <table cellspacing=0 cellpadding=0>
21
- <thead>
22
- <tr>
23
- <th class=docs><h1>chef-extensions.rb</h1></th>
24
- <th class=code></th>
25
- </tr>
26
- </thead>
27
- <tbody>
28
- <tr id='section-1'>
29
- <td class=docs>
30
- <div class="pilwrap">
31
- <a class="pilcrow" href="#section-1">&#182;</a>
32
- </div>
33
-
34
- </td>
35
- <td class=code>
36
- <div class='highlight'><pre><span class="nb">require</span> <span class="s1">&#39;chef-extensions/version&#39;</span>
37
- <span class="nb">require</span> <span class="s1">&#39;securerandom&#39;</span>
38
-
39
- <span class="k">module</span> <span class="nn">Chef</span>
40
- <span class="k">module</span> <span class="nn">Extensions</span>
41
- <span class="kp">extend</span> <span class="nb">self</span></pre></div>
42
- </td>
43
- </tr>
44
- <tr id='section-2'>
45
- <td class=docs>
46
- <div class="pilwrap">
47
- <a class="pilcrow" href="#section-2">&#182;</a>
48
- </div>
49
- <p><strong>Ping Google&rsquo;s DNS.</strong> <br />
50
- If it doesn&rsquo;t hear back within 1s, it&rsquo;s safe to
51
- assume that we don&rsquo;t have internet connectivity</p>
52
- </td>
53
- <td class=code>
54
- <div class='highlight'><pre> <span class="k">def</span> <span class="nf">wan_up?</span>
55
- <span class="sb">`ping -c 1 8.8.8.8 -W 2`</span><span class="o">.</span><span class="n">include?</span> <span class="s2">&quot;1 received&quot;</span>
56
- <span class="k">end</span></pre></div>
57
- </td>
58
- </tr>
59
- <tr id='section-3'>
60
- <td class=docs>
61
- <div class="pilwrap">
62
- <a class="pilcrow" href="#section-3">&#182;</a>
63
- </div>
64
- <p><strong>Checks if vagrant user exists.</strong> <br />
65
- If it does, we&rsquo;re running in the context of a VirtualBox VM, provisioned
66
- through Vagrant.</p>
67
- </td>
68
- <td class=code>
69
- <div class='highlight'><pre> <span class="k">def</span> <span class="nf">vagrant?</span>
70
- <span class="vi">@vagrant</span> <span class="o">||=</span> <span class="sb">`id vagrant 2&gt;&amp;1`</span><span class="o">.</span><span class="n">index</span> <span class="s1">&#39;uid&#39;</span>
71
- <span class="k">end</span></pre></div>
72
- </td>
73
- </tr>
74
- <tr id='section-4'>
75
- <td class=docs>
76
- <div class="pilwrap">
77
- <a class="pilcrow" href="#section-4">&#182;</a>
78
- </div>
79
- <p><strong>Get this instance&rsquo;s ID.</strong> <br />
80
- If within 1s it gets a response which starts with &lsquo;i-&rsquo;, it&rsquo;s safe to
81
- assume that we&rsquo;re running within the context of an EC2 instance.</p>
82
- </td>
83
- <td class=code>
84
- <div class='highlight'><pre> <span class="k">def</span> <span class="nf">ec2?</span>
85
- <span class="vi">@ec2</span> <span class="o">||=</span> <span class="sb">`curl --connect-timeout 1 http://169.254.169.254/2011-01-01/meta-data/instance-id 2&gt;&amp;1`</span><span class="o">.</span><span class="n">include?</span><span class="p">(</span><span class="s1">&#39;i-&#39;</span><span class="p">)</span>
86
- <span class="k">end</span></pre></div>
87
- </td>
88
- </tr>
89
- <tr id='section-5'>
90
- <td class=docs>
91
- <div class="pilwrap">
92
- <a class="pilcrow" href="#section-5">&#182;</a>
93
- </div>
94
- <p><strong>Generate base64 password using SecureRandom.</strong> <br />
95
- Trims the ending ==.</p>
96
-
97
- </td>
98
- <td class=code>
99
- <div class='highlight'><pre> <span class="k">def</span> <span class="nf">password</span><span class="p">(</span><span class="n">length</span><span class="o">=</span><span class="mi">20</span><span class="p">)</span>
100
- <span class="no">SecureRandom</span><span class="o">.</span><span class="n">base64</span><span class="p">(</span><span class="n">length</span><span class="o">+</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">tr</span><span class="p">(</span><span class="s1">&#39;=&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>
101
- <span class="k">end</span>
102
- <span class="k">end</span>
103
- <span class="k">end</span></pre></div>
104
- </td>
105
- </tr>
106
- </table>
107
- </div>
108
- </body>
File without changes
@@ -1,68 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
- <title>ip.rb</title>
6
- <link rel="stylesheet" href="http://jashkenas.github.com/docco/resources/docco.css">
7
- </head>
8
- <body>
9
- <div id='container'>
10
- <div id="background"></div>
11
- <div id="jump_to">
12
- Jump To &hellip;
13
- <div id="jump_wrapper">
14
- <div id="jump_page">
15
- <a class="source" href="../chef-extensions.html">chef-extensions.rb</a>
16
- <a class="source" href="ec2.html">ec2.rb</a>
17
- <a class="source" href="ip.html">ip.rb</a>
18
- <a class="source" href="version.html">version.rb</a>
19
- </div>
20
- </div>
21
- </div>
22
- <table cellspacing=0 cellpadding=0>
23
- <thead>
24
- <tr>
25
- <th class=docs><h1>ip.rb</h1></th>
26
- <th class=code></th>
27
- </tr>
28
- </thead>
29
- <tbody>
30
- <tr id='section-1'>
31
- <td class=docs>
32
- <div class="pilwrap">
33
- <a class="pilcrow" href="#section-1">&#182;</a>
34
- </div>
35
-
36
-
37
- </td>
38
- <td class=code>
39
- <div class='highlight'><pre><span class="nb">require</span> <span class="s1">&#39;socket&#39;</span>
40
-
41
- <span class="k">class</span> <span class="nc">Chef</span>
42
- <span class="k">module</span> <span class="nn">Extensions</span>
43
- <span class="k">module</span> <span class="nn">IP</span>
44
- <span class="kp">extend</span> <span class="nb">self</span>
45
-
46
- <span class="k">def</span> <span class="nf">all</span>
47
- <span class="vi">@all</span> <span class="o">||=</span> <span class="no">Socket</span><span class="o">.</span><span class="n">ip_address_list</span>
48
- <span class="k">end</span>
49
-
50
- <span class="k">def</span> <span class="nf">ipv4</span>
51
- <span class="n">all</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="o">&amp;</span><span class="ss">:ipv4?</span><span class="p">)</span>
52
- <span class="k">end</span>
53
-
54
- <span class="k">def</span> <span class="nf">ipv6</span>
55
- <span class="n">all</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="o">&amp;</span><span class="ss">:ipv6?</span><span class="p">)</span>
56
- <span class="k">end</span>
57
-
58
- <span class="k">def</span> <span class="nf">addresses</span><span class="p">(</span><span class="nb">type</span><span class="p">)</span>
59
- <span class="nb">self</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="nb">type</span><span class="p">)</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="o">&amp;</span><span class="ss">:ip_address</span><span class="p">)</span>
60
- <span class="k">end</span>
61
- <span class="k">end</span>
62
- <span class="k">end</span>
63
- <span class="k">end</span></pre></div>
64
- </td>
65
- </tr>
66
- </table>
67
- </div>
68
- </body>
@@ -1,56 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
- <title>version.rb</title>
6
- <link rel="stylesheet" href="http://jashkenas.github.com/docco/resources/docco.css">
7
- </head>
8
- <body>
9
- <div id='container'>
10
- <div id="background"></div>
11
- <div id="jump_to">
12
- Jump To &hellip;
13
- <div id="jump_wrapper">
14
- <div id="jump_page">
15
- <a class="source" href="../chef-extensions.html">chef-extensions.rb</a>
16
- <a class="source" href="version.html">version.rb</a>
17
- </div>
18
- </div>
19
- </div>
20
- <table cellspacing=0 cellpadding=0>
21
- <thead>
22
- <tr>
23
- <th class=docs><h1>version.rb</h1></th>
24
- <th class=code></th>
25
- </tr>
26
- </thead>
27
- <tbody>
28
- <tr id='section-1'>
29
- <td class=docs>
30
- <div class="pilwrap">
31
- <a class="pilcrow" href="#section-1">&#182;</a>
32
- </div>
33
-
34
- </td>
35
- <td class=code>
36
- <div class='highlight'><pre><span class="k">module</span> <span class="nn">Chef</span>
37
- <span class="k">module</span> <span class="nn">Extensions</span></pre></div>
38
- </td>
39
- </tr>
40
- <tr id='section-2'>
41
- <td class=docs>
42
- <div class="pilwrap">
43
- <a class="pilcrow" href="#section-2">&#182;</a>
44
- </div>
45
- <p>Gem version</p>
46
-
47
- </td>
48
- <td class=code>
49
- <div class='highlight'><pre> <span class="no">VERSION</span> <span class="o">=</span> <span class="s2">&quot;0.1.0&quot;</span>
50
- <span class="k">end</span>
51
- <span class="k">end</span></pre></div>
52
- </td>
53
- </tr>
54
- </table>
55
- </div>
56
- </body>