chef-metal-fog 0.3.1 → 0.4

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: 38f2915e316f74e59429cd54e1fb1b2d044fbf5a
4
- data.tar.gz: e924f144a8f16bef3ef44381314c782fe8bd1d27
3
+ metadata.gz: 60b1659681a87e03c3e75748bf5e0a729d1d42e0
4
+ data.tar.gz: 7aea9de39a52c044f12f49b045bb9bad64277851
5
5
  SHA512:
6
- metadata.gz: f07cef0c5c334a9a709f996d827200d9839cb1457373bf84c974a72d6657420e12085c7ab0050b16e718728285ee6048a54079bfab3eb8b4ed4b0185c400da23
7
- data.tar.gz: 1657897320549abd7bd226d078b086b75592f1559fb7959397c84f9df5a89f0b96247c79754c29fb761648daaf5aba1a7a71e96185f9ed8b8ec385540406dc22
6
+ metadata.gz: 6528c4091d92999bf66166df4459cd036b273c65e8372cda122a35c5efbaf0a1bc2d12fa624ef2935545b05cf1c86473ca44b535a5c837a17ac1f09f24d8f6d4
7
+ data.tar.gz: 64d79d629752c5c3da14a5dfbb9a91a4a96f62bd956ecaacdd8adde30a24e4d040213ae13f06b793065e077c3df7e55aec472d5e0419dd8e4bb7fb39344610bc
@@ -13,7 +13,7 @@ class Chef::Provider::FogKeyPair < Chef::Provider::LWRPBase
13
13
  end
14
14
 
15
15
  action :create do
16
- create_key
16
+ create_key(:create)
17
17
  end
18
18
 
19
19
  action :delete do
@@ -35,29 +35,42 @@ class Chef::Provider::FogKeyPair < Chef::Provider::LWRPBase
35
35
  "#{new_resource.name} on #{new_resource.provisioner.provisioner_url}"
36
36
  end
37
37
 
38
- def create_key
38
+ def create_key(action)
39
39
  if current_resource_exists?
40
40
  # If the public keys are different, update the server public key
41
41
  if !current_resource.private_key_path
42
42
  if new_resource.allow_overwrite
43
- ensure_keys
43
+ ensure_keys(action)
44
44
  else
45
45
  raise "#{key_description} already exists on the server, but the private key #{new_resource.private_key_path} does not exist!"
46
46
  end
47
47
  else
48
- ensure_keys
48
+ ensure_keys(action)
49
49
  end
50
50
 
51
- new_fingerprint = case new_resource.provisioner.compute_options[:provider]
51
+ new_fingerprints = case new_resource.provisioner.compute_options[:provider]
52
52
  when 'DigitalOcean'
53
- Cheffish::KeyFormatter.encode(desired_key, :format => :openssh)
53
+ [Cheffish::KeyFormatter.encode(desired_key, :format => :openssh)]
54
54
  when 'OpenStack'
55
- Cheffish::KeyFormatter.encode(desired_key, :format => :openssh)
55
+ [Cheffish::KeyFormatter.encode(desired_key, :format => :openssh)]
56
56
  else
57
- Cheffish::KeyFormatter.encode(desired_key, :format => :fingerprint)
57
+ # “The nice thing about standards is that you have so many to
58
+ # choose from.” - Andrew S. Tanenbaum
59
+ #
60
+ # The AWS EC2 API uses a PKCS#1 MD5 fingerprint for keys that you
61
+ # import into EC2, but a PKCS#8 SHA1 fingerprint for keys that you
62
+ # generate using its web console. Both fingerprints are different
63
+ # from the familiar RFC4716 MD5 fingerprint that OpenSSH displays
64
+ # for host keys.
65
+ #
66
+ # So compute both possible AWS fingerprints and check if either of
67
+ # them matches.
68
+ [Cheffish::KeyFormatter.encode(desired_key, :format => :fingerprint),
69
+ lambda { Cheffish::KeyFormatter.encode(desired_private_key,
70
+ :format => :pkcs8sha1fingerprint) }]
58
71
  end
59
72
 
60
- if new_fingerprint != @current_fingerprint
73
+ if !new_fingerprints.any? { |f| (f.is_a?(Proc) ? f.call : f) == @current_fingerprint }
61
74
  if new_resource.allow_overwrite
62
75
  converge_by "update #{key_description} to match local key at #{new_resource.private_key_path}" do
63
76
  case new_resource.provisioner.compute_options[:provider]
@@ -70,12 +83,12 @@ class Chef::Provider::FogKeyPair < Chef::Provider::LWRPBase
70
83
  end
71
84
  end
72
85
  else
73
- raise "#{key_description} does not match local private key, and allow_overwrite is false!"
86
+ raise "#{key_description} with fingerprint #{@current_fingerprint} does not match local key fingerprint(s) #{new_fingerprints}, and allow_overwrite is false!"
74
87
  end
75
88
  end
76
89
  else
77
90
  # Generate the private and/or public keys if they do not exist
78
- ensure_keys
91
+ ensure_keys(action)
79
92
 
80
93
  # Create key
81
94
  converge_by "create #{key_description} from local key at #{new_resource.private_key_path}" do
@@ -91,9 +104,9 @@ class Chef::Provider::FogKeyPair < Chef::Provider::LWRPBase
91
104
  end
92
105
  end
93
106
 
94
- def ensure_keys
107
+ def ensure_keys(action)
95
108
  resource = new_resource
96
- Cheffish.inline_resource(self) do
109
+ Cheffish.inline_resource(self, action) do
97
110
  private_key resource.private_key_path do
98
111
  public_key_path resource.public_key_path
99
112
  if resource.private_key_options
@@ -111,12 +124,18 @@ class Chef::Provider::FogKeyPair < Chef::Provider::LWRPBase
111
124
  public_key, format = Cheffish::KeyFormatter.decode(IO.read(new_resource.public_key_path))
112
125
  public_key
113
126
  else
114
- private_key, format = Cheffish::KeyFormatter.decode(IO.read(new_resource.private_key_path))
115
- private_key.public_key
127
+ desired_private_key.public_key
116
128
  end
117
129
  end
118
130
  end
119
131
 
132
+ def desired_private_key
133
+ @desired_private_key ||= begin
134
+ private_key, format = Cheffish::KeyFormatter.decode(IO.read(new_resource.private_key_path))
135
+ private_key
136
+ end
137
+ end
138
+
120
139
  def current_resource_exists?
121
140
  @current_resource.action != [ :delete ]
122
141
  end
@@ -133,7 +152,7 @@ class Chef::Provider::FogKeyPair < Chef::Provider::LWRPBase
133
152
  if !new_resource.provisioner.kind_of?(ChefMetalFog::FogProvisioner)
134
153
  raise 'ec2_key_pair only works with fog_provisioner'
135
154
  end
136
- @current_resource = Chef::Resource::FogKeyPair.new(new_resource.name)
155
+ @current_resource = Chef::Resource::FogKeyPair.new(new_resource.name, run_context)
137
156
  case new_resource.provisioner.compute_options[:provider]
138
157
  when 'DigitalOcean'
139
158
  current_key_pair = compute.ssh_keys.select { |key| key.name == new_resource.name }.first
@@ -5,7 +5,7 @@ class Chef::Resource::FogKeyPair < Chef::Resource::LWRPBase
5
5
 
6
6
  def initialize(*args)
7
7
  super
8
- @provisioner = ChefMetal.enclosing_provisioner
8
+ @provisioner = run_context.chef_metal.current_provisioner
9
9
  end
10
10
 
11
11
  def after_created
@@ -6,7 +6,7 @@ require 'chef_metal_fog/fog_provisioner'
6
6
  class Chef
7
7
  class Recipe
8
8
  def with_fog_provisioner(options = {}, &block)
9
- ChefMetal.with_provisioner(ChefMetalFog::FogProvisioner.new(options), &block)
9
+ run_context.chef_metal.with_provisioner(ChefMetalFog::FogProvisioner.new(options), &block)
10
10
  end
11
11
 
12
12
  def with_fog_ec2_provisioner(options = {}, &block)
@@ -154,10 +154,17 @@ module ChefMetalFog
154
154
  #
155
155
  def acquire_machine(action_handler, node)
156
156
  # Set up the modified node data
157
+ creator = case compute_options[:provider]
158
+ when 'AWS'
159
+ aws_login_info[1]
160
+ when 'OpenStack'
161
+ compute_options[:openstack_username]
162
+ end
163
+
157
164
  provisioner_output = node['normal']['provisioner_output'] || {
158
165
  'provisioner_url' => provisioner_url,
159
166
  'provisioner_version' => ChefMetalFog::VERSION,
160
- 'creator' => aws_login_info[1]
167
+ 'creator' => creator
161
168
  }
162
169
 
163
170
  if provisioner_output['provisioner_url'] != provisioner_url
@@ -227,7 +234,7 @@ module ChefMetalFog
227
234
  Chef::Log.info 'Attaching given IP'
228
235
  server.wait_for { ready? }
229
236
  action_handler.perform_action "attach floating IP #{bootstrap_options[:floating_ip]}" do
230
- attach_ip(server, bootstrap_options[:floating_ip])
237
+ attach_ip(server, bootstrap_options[:allocation_id], bootstrap_options[:floating_ip])
231
238
  end
232
239
  end
233
240
  action_handler.perform_action "machine #{node['name']} created as #{server.id} on #{provisioner_url}" do
@@ -294,10 +301,11 @@ module ChefMetalFog
294
301
  # Attach given IP to machine
295
302
  # Code taken from kitchen-openstack driver
296
303
  # https://github.com/test-kitchen/kitchen-openstack/blob/master/lib/kitchen/driver/openstack.rb#L209-L213
297
- def attach_ip(server, ip)
304
+ def attach_ip(server, allocation_id, ip)
298
305
  Chef::Log.info "Attaching floating IP <#{ip}>"
299
- server.associate_address ip
300
- (server.addresses['public'] ||= []) << { 'version' => 4, 'addr' => ip }
306
+ compute.associate_address(:instance_id => server.id,
307
+ :allocation_id => allocation_id,
308
+ :public_ip => ip)
301
309
  end
302
310
 
303
311
  # Connect to machine without acquiring it
@@ -308,8 +316,10 @@ module ChefMetalFog
308
316
  def delete_machine(action_handler, node)
309
317
  if node['normal']['provisioner_output'] && node['normal']['provisioner_output']['server_id']
310
318
  server = compute.servers.get(node['normal']['provisioner_output']['server_id'])
311
- action_handler.perform_action "destroy machine #{node['name']} (#{node['normal']['provisioner_output']['server_id']} at #{provisioner_url})" do
312
- server.destroy
319
+ if server
320
+ action_handler.perform_action "destroy machine #{node['name']} (#{node['normal']['provisioner_output']['server_id']} at #{provisioner_url})" do
321
+ server.destroy
322
+ end
313
323
  end
314
324
  convergence_strategy_for(node).cleanup_convergence(action_handler, node)
315
325
  end
@@ -487,7 +497,7 @@ module ChefMetalFog
487
497
  :host_key_alias => "#{server.id}.#{compute_options[:provider]}"
488
498
  }
489
499
  if server.respond_to?(:private_key) && server.private_key
490
- result[:keys] = [ server.private_key ]
500
+ result[:key_data] = [ server.private_key ]
491
501
  elsif server.respond_to?(:key_name) && key_pairs[server.key_name]
492
502
  # TODO generalize for others?
493
503
  result[:keys] ||= [ key_pairs[server.key_name].private_key_path ]
@@ -1,3 +1,3 @@
1
1
  module ChefMetalFog
2
- VERSION = '0.3.1'
2
+ VERSION = '0.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-metal-fog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: '0.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Keiser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-14 00:00:00.000000000 Z
11
+ date: 2014-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: cheffish
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0.4'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: fog
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -83,7 +97,6 @@ files:
83
97
  - lib/chef_metal_fog/fog_provisioner.rb
84
98
  - lib/chef_metal_fog/version.rb
85
99
  - lib/chef_metal_fog.rb
86
- - lib/fog.rb
87
100
  homepage: https://github.com/opscode/chef-metal-fog
88
101
  licenses: []
89
102
  metadata: {}
data/lib/fog.rb DELETED
File without changes