chef-resolver 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: da1a68ea8f3b56014ff1bd7d6e4cb354fc9f88e2
4
+ data.tar.gz: 11efcc4c30f99630b230e85a96c0092d2c250380
5
+ SHA512:
6
+ metadata.gz: ae0424cb9faf3e72955c592274929a663cc6fbc1fc2e40354e9a0d497c0bce9301f4e7ecec3b276ece5b1f1b94af3a2dc126d414618542bda2c8fe0e9ad2697f
7
+ data.tar.gz: cb36533b7c3f84ee83d6d99dd5c3ff527600e8ce00d5fad19453edc68aaf2d6cb78d8bfcb8e1e68bfc72ddb434143044de09a08afe711d758bf6b1e9e2247e2a
@@ -25,6 +25,7 @@ if ARGV[0] == 'install'
25
25
  # # Access with role.config_name.chef
26
26
  # config_name:
27
27
  # knife_file: /full/path/to/knife.rb
28
+ # use_private_ip: false # optional
28
29
  # search_extra: 'role:production' # optional
29
30
  # env: # optional
30
31
  # CHEF_ENV: production
@@ -1,5 +1,5 @@
1
1
  class Chef
2
2
  module Resolver
3
- VERSION = "0.11.0"
3
+ VERSION = "0.12.0"
4
4
  end
5
5
  end
@@ -111,10 +111,23 @@ class Chef
111
111
  else
112
112
  node = nodes[index]
113
113
  puts "\tFound node: #{node['name']}"
114
- return node.has_key?('ec2') ? node['ec2']['public_ipv4'] : node['ipaddress']
114
+ return calculate_node_ip(node, config)
115
115
  end
116
116
  end
117
117
 
118
+ def calculate_node_ip node, config
119
+ ip = if node.has_key?('cloud')
120
+ if config['use_private_ip']
121
+ node['cloud']['local_ipv4']
122
+ else
123
+ node['cloud']['public_ipv4']
124
+ end
125
+ else
126
+ node['ipaddress']
127
+ end
128
+ ip.is_a?(Array) ? ip.first : ip
129
+ end
130
+
118
131
  def process_requests
119
132
  loop do
120
133
  data, from = @server.recvfrom(1024)
@@ -46,6 +46,7 @@ describe Chef::ResolverServer do
46
46
  @test_config = {'knife_file' => File.dirname(__FILE__)+'/files/test_knife.rb'}
47
47
  @test2_config = {'knife_file' => File.dirname(__FILE__)+'/files/test2_knife.rb', 'env' => {'ENV_PROP' => 'test2'}}
48
48
  @test3_config = {'knife_file' => File.dirname(__FILE__)+'/files/test_knife.rb', 'search_extra' => 'role:staging'}
49
+ @vpn_config = {'knife_file' => File.dirname(__FILE__)+'/files/test_knife.rb', 'use_private_ip' => true}
49
50
  end
50
51
 
51
52
  after :each do
@@ -123,13 +124,6 @@ describe Chef::ResolverServer do
123
124
  expect { getaddress('test_role.test2.chef') }.to raise_error(Resolv::ResolvError)
124
125
  end
125
126
 
126
- it "should resolve ec2 node public ip addresses properly" do
127
- new_server 'test' => @test_config
128
- @server.start
129
- stub_search 'role:test_role', [{'ec2' => {'public_ipv4' => '1.1.1.1'}, 'ipaddress' => '0.0.0.0'}]
130
- getaddress('test_role.chef').should == '1.1.1.1'
131
- end
132
-
133
127
  it "should support a file path" do
134
128
  path = File.dirname(__FILE__)+'/files/changing_config.yml'
135
129
  File.open(path, 'w') {|f| f.write({'test' => @test_config}.to_yaml)}
@@ -174,4 +168,20 @@ describe Chef::ResolverServer do
174
168
  getaddress('test_role.changing.chef').should == '1.1.1.1'
175
169
  Chef::Config.test_prop.should == false
176
170
  end
171
+
172
+ describe "#calculate_node_ip" do
173
+ it "should prefer cloud ip addresses over ipaddress field" do
174
+ new_server 'test' => @test_config
175
+ @server.start
176
+ stub_search 'role:test_role', [{'cloud' => {'public_ipv4' => '1.1.1.1'}, 'ipaddress' => '0.0.0.0'}]
177
+ getaddress('test_role.chef').should == '1.1.1.1'
178
+ end
179
+
180
+ it "should prefer cloud ip addresses over ipaddress field with use_private_ip" do
181
+ new_server 'test' => @vpn_config
182
+ @server.start
183
+ stub_search 'role:test_role', [{'cloud' => {'local_ipv4' => '1.1.1.1'}, 'ipaddress' => '0.0.0.0'}]
184
+ getaddress('test_role.chef').should == '1.1.1.1'
185
+ end
186
+ end
177
187
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-resolver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
5
- prerelease:
4
+ version: 0.12.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Stephen Augenstein
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-03-30 00:00:00.000000000 Z
11
+ date: 2015-10-04 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: chef
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -51,33 +48,26 @@ files:
51
48
  - spec/spec_helper.rb
52
49
  homepage: https://github.com/warhammerkid/chef-resolver
53
50
  licenses: []
51
+ metadata: {}
54
52
  post_install_message:
55
53
  rdoc_options: []
56
54
  require_paths:
57
55
  - lib
58
56
  required_ruby_version: !ruby/object:Gem::Requirement
59
- none: false
60
57
  requirements:
61
- - - ! '>='
58
+ - - '>='
62
59
  - !ruby/object:Gem::Version
63
60
  version: '0'
64
- segments:
65
- - 0
66
- hash: 160828053575409919
67
61
  required_rubygems_version: !ruby/object:Gem::Requirement
68
- none: false
69
62
  requirements:
70
- - - ! '>='
63
+ - - '>='
71
64
  - !ruby/object:Gem::Version
72
65
  version: '0'
73
- segments:
74
- - 0
75
- hash: 160828053575409919
76
66
  requirements: []
77
67
  rubyforge_project:
78
- rubygems_version: 1.8.23
68
+ rubygems_version: 2.0.14
79
69
  signing_key:
80
- specification_version: 3
70
+ specification_version: 4
81
71
  summary: Instead of doing knife search node role every time you want to look up a
82
72
  server, simply ssh into ROLE_NAME-##.chef
83
73
  test_files: