chef-metal-fog 0.7.1 → 0.8

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: a55ddb8af472d71de01c6206ec99c8373a3472bb
4
- data.tar.gz: 8dbd7d62d6a31fb4f2e4d03a3790ce8cb859c9ec
3
+ metadata.gz: 2278f6624a0634e205da58bcc1e966b22eab39cf
4
+ data.tar.gz: a1f4213a340ec309ef22d4fa141262f367e379d0
5
5
  SHA512:
6
- metadata.gz: c3fd1d83614f27f4c452a3db315f4ddbd2e56771953af3fa0b05e5e9550643a9f27e0fa3ff0fe6c8cfa626922c37f43afde9a1b9d1be2f05d50d070f1c999b2e
7
- data.tar.gz: 45c301339fca7a8296288daeb4c69797a1d5ae7a346496b429da0f74f6bfd7186861be99889aa330db218f907833943f98e0228ef000c9ac1a004cc8c8f6f496
6
+ metadata.gz: dd9e876567aaf22364a1e12efd5747464ecea0722e9758a5866feb4bb0877d3fd4a9bdc7799aa31b18c67c79c4c5b1fdc517e550812b9ea8fda7315feaaef050
7
+ data.tar.gz: 9a4b72747673099393f9571bc81492b951c901e6b5773a6cb2d6918fa0dfc17f14b7ca03e078d673660dbc72ea7bec6b3a4f84da0833563f3c3b88640ea70db5
@@ -19,6 +19,8 @@ class Chef::Provider::FogKeyPair < Chef::Provider::LWRPBase
19
19
  case new_driver.compute_options[:provider]
20
20
  when 'DigitalOcean'
21
21
  compute.destroy_key_pair(@current_id)
22
+ when 'Joyent'
23
+ compute.delete_key(@current_id)
22
24
  when 'OpenStack', 'Rackspace'
23
25
  compute.key_pairs.destroy(@current_id)
24
26
  else
@@ -56,6 +58,8 @@ class Chef::Provider::FogKeyPair < Chef::Provider::LWRPBase
56
58
  case new_driver.compute_options[:provider]
57
59
  when 'DigitalOcean'
58
60
  new_fingerprints = [Cheffish::KeyFormatter.encode(desired_key, :format => :openssh)]
61
+ when 'Joyent'
62
+ new_fingerprints = [Cheffish::KeyFormatter.encode(desired_key, :format => :rfc4716md5fingerprint)]
59
63
  when 'OpenStack', 'Rackspace'
60
64
  new_fingerprints = [Cheffish::KeyFormatter.encode(desired_key, :format => :openssh)]
61
65
  else
@@ -94,6 +98,8 @@ class Chef::Provider::FogKeyPair < Chef::Provider::LWRPBase
94
98
  case new_driver.compute_options[:provider]
95
99
  when 'DigitalOcean'
96
100
  compute.create_ssh_key(new_resource.name, Cheffish::KeyFormatter.encode(desired_key, :format => :openssh))
101
+ when 'Joyent'
102
+ compute.create_key(name: new_resource.name, key: Cheffish::KeyFormatter.encode(desired_key, :format => :openssh))
97
103
  when 'OpenStack'
98
104
  compute.create_key_pair(new_resource.name, Cheffish::KeyFormatter.encode(desired_key, :format => :openssh))
99
105
  when 'Rackspace'
@@ -116,6 +122,8 @@ class Chef::Provider::FogKeyPair < Chef::Provider::LWRPBase
116
122
  case new_driver.compute_options[:provider]
117
123
  when 'DigitalOcean'
118
124
  compute.create_ssh_key(new_resource.name, Cheffish::KeyFormatter.encode(desired_key, :format => :openssh))
125
+ when 'Joyent'
126
+ compute.create_key(name: new_resource.name, key: Cheffish::KeyFormatter.encode(desired_key, :format => :openssh))
119
127
  when 'OpenStack'
120
128
  compute.create_key_pair(new_resource.name, Cheffish::KeyFormatter.encode(desired_key, :format => :openssh))
121
129
  when 'Rackspace'
@@ -212,6 +220,25 @@ class Chef::Provider::FogKeyPair < Chef::Provider::LWRPBase
212
220
  else
213
221
  current_resource.action :delete
214
222
  end
223
+ when 'Joyent'
224
+ current_key_pair = begin
225
+ compute.keys.get(new_resource.name)
226
+ rescue Fog::Compute::Joyent::Errors::NotFound
227
+ nil
228
+ end
229
+ if current_key_pair
230
+ @current_id = current_key_pair.name
231
+ @current_fingerprint = if current_key_pair.respond_to?(:fingerprint)
232
+ current_key_pair.fingerprint
233
+ elsif current_key_pair.respond_to?(:key)
234
+ public_key, format = Cheffish::KeyFormatter.decode(current_key_pair.key)
235
+ public_key.fingerprint
236
+ else
237
+ nil
238
+ end
239
+ else
240
+ current_resource.action :delete
241
+ end
215
242
  when 'OpenStack', 'Rackspace'
216
243
  current_key_pair = compute.key_pairs.get(new_resource.name)
217
244
  if current_key_pair
@@ -244,6 +244,10 @@ module ChefMetalFog
244
244
  end
245
245
  end
246
246
 
247
+ def image_for(image_spec)
248
+ compute.images.get(image_spec.location['image_id'])
249
+ end
250
+
247
251
  def compute
248
252
  @compute ||= Fog::Compute.new(compute_options)
249
253
  end
@@ -1,5 +1,6 @@
1
1
  require 'chef/log'
2
2
  require 'fog/aws'
3
+ require 'uri'
3
4
 
4
5
  # fog:AWS:<account_id>:<region>
5
6
  # fog:AWS:<profile_name>
@@ -20,6 +21,64 @@ module ChefMetalFog
20
21
  'ubuntu'
21
22
  end
22
23
 
24
+ def allocate_image(action_handler, image_spec, image_options, machine_spec)
25
+ if image_spec.location
26
+ image = compute.images.get(image_spec.location['image_id'])
27
+ if image
28
+ raise "The image already exists, why are you asking me to create it? I can't do that, Dave."
29
+ end
30
+ end
31
+ action_handler.perform_action "Create image #{image_spec.name} from machine #{machine_spec.name} with options #{image_options.inspect}" do
32
+ opt = image_options.dup
33
+ response = compute.create_image(machine_spec.location['server_id'],
34
+ image_spec.name,
35
+ opt.delete(:description) || "The image formerly and currently named '#{image_spec.name}'",
36
+ opt.delete(:no_reboot) || false,
37
+ opt)
38
+ image_spec.location = {
39
+ 'driver_url' => driver_url,
40
+ 'driver_version' => ChefMetalFog::VERSION,
41
+ 'image_id' => response.body['imageId'],
42
+ 'creator' => creator,
43
+ 'allocated_at' => Time.now.to_i
44
+ }
45
+
46
+ image_spec.machine_options ||= {}
47
+ image_spec.machine_options.merge!({
48
+ :bootstrap_options => {
49
+ :image_id => image_spec.location['image_id']
50
+ }
51
+ })
52
+
53
+ end
54
+ end
55
+
56
+ def ready_image(action_handler, image_spec, image_options)
57
+ if !image_spec.location
58
+ raise "Cannot ready an image that does not exist"
59
+ end
60
+ image = compute.images.get(image_spec.location['image_id'])
61
+ if !image.ready?
62
+ action_handler.report_progress "Waiting for image to be ready ..."
63
+ # TODO timeout
64
+ image.wait_for { ready? }
65
+ action_handler.report_progress "Image is ready!"
66
+ end
67
+ end
68
+
69
+ def destroy_image(action_handler, image_spec, image_options)
70
+ if !image_spec.location
71
+ return
72
+ end
73
+ image = compute.images.get(image_spec.location['image_id'])
74
+ if !image
75
+ return
76
+ end
77
+ delete_snapshots = image_options[:delete_snapshots]
78
+ delete_snapshots = true if delete_snapshots.nil?
79
+ image.deregister(delete_snapshots)
80
+ end
81
+
23
82
  def bootstrap_options_for(action_handler, machine_spec, machine_options)
24
83
  bootstrap_options = symbolize_keys(machine_options[:bootstrap_options] || {})
25
84
 
@@ -45,7 +104,7 @@ module ChefMetalFog
45
104
  if extra_tags.size > 0 || different_tags.size > 0
46
105
  tags_description = [ "Update tags for #{machine_spec.name} on #{driver_url}" ]
47
106
  tags_description += extra_tags.map { |tag| " Add #{tag} = #{tags[tag].inspect}" }
48
- tags_description += different_tags.map { |tag| " Update #{tag.name} from #{tag.value.inspect} to #{tags[tag.name].inspect}"}
107
+ tags_description += different_tags.map { |tag_name, tag_value| " Update #{tag_name} from #{tag_value.inspect} to #{tags[tag_name].inspect}"}
49
108
  action_handler.perform_action tags_description do
50
109
  # TODO should we narrow this down to just extra/different tags or
51
110
  # is it OK to just pass 'em all? Certainly easier to do the
@@ -56,6 +115,11 @@ module ChefMetalFog
56
115
  end
57
116
  end
58
117
 
118
+ def convergence_strategy_for(machine_spec, machine_options)
119
+ machine_options[:convergence_options][:ohai_hints] = { 'ec2' => ''}
120
+ super(machine_spec, machine_options)
121
+ end
122
+
59
123
  def self.get_aws_profile(driver_options, aws_account_id)
60
124
  aws_credentials = get_aws_credentials(driver_options)
61
125
  compute_options = driver_options[:compute_options] || {}
@@ -78,11 +142,11 @@ module ChefMetalFog
78
142
  elsif driver_options[:aws_profile]
79
143
  Chef::Log.debug("Using AWS profile #{driver_options[:aws_profile]}")
80
144
  aws_credentials[driver_options[:aws_profile]]
81
- elsif ENV['AWS_ACCESS_KEY_ID']
145
+ elsif ENV['AWS_ACCESS_KEY_ID'] || ENV['AWS_ACCESS_KEY']
82
146
  Chef::Log.debug("Using AWS environment variable access keys")
83
147
  {
84
- :aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'],
85
- :aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'],
148
+ :aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'] || ENV['AWS_ACCESS_KEY'],
149
+ :aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'] || ENV['AWS_SECRET_KEY'],
86
150
  :aws_security_token => ENV['AWS_SECURITY_TOKEN'],
87
151
  :region => ENV['AWS_REGION']
88
152
  }
@@ -93,6 +157,19 @@ module ChefMetalFog
93
157
  Chef::Log.debug("Using AWS default profile")
94
158
  aws_credentials.default
95
159
  end
160
+ # Endpoint configuration
161
+ if compute_options[:ec2_endpoint]
162
+ aws_profile[:ec2_endpoint] = compute_options[:ec2_endpoint]
163
+ elsif ENV['EC2_URL']
164
+ aws_profile[:ec2_endpoint] = ENV['EC2_URL']
165
+ end
166
+ if compute_options[:iam_endpoint]
167
+ aws_profile[:iam_endpoint] = compute_options[:iam_endpoint]
168
+ elsif ENV['AWS_IAM_URL']
169
+ aws_profile[:iam_endpoint] = ENV['AWS_IAM_URL']
170
+ else
171
+ aws_profile[:iam_endpoint] = "https://iam.amazonaws.com/"
172
+ end
96
173
 
97
174
  # Merge in account info for profile
98
175
  if aws_profile
@@ -144,7 +221,11 @@ module ChefMetalFog
144
221
  options = {
145
222
  :aws_access_key_id => aws_profile[:aws_access_key_id],
146
223
  :aws_secret_access_key => aws_profile[:aws_secret_access_key],
147
- :aws_session_token => aws_profile[:aws_security_token]
224
+ :aws_session_token => aws_profile[:aws_security_token],
225
+ :host => URI(aws_profile[:iam_endpoint]).host,
226
+ :scheme => URI(aws_profile[:iam_endpoint]).scheme,
227
+ :port => URI(aws_profile[:iam_endpoint]).port,
228
+ :path => URI(aws_profile[:iam_endpoint]).path
148
229
  }
149
230
  options.delete_if { |key, value| value.nil? }
150
231
 
@@ -224,6 +305,7 @@ module ChefMetalFog
224
305
  new_compute_options[:aws_secret_access_key] = aws_profile[:aws_secret_access_key]
225
306
  new_compute_options[:aws_session_token] = aws_profile[:aws_security_token]
226
307
  new_defaults[:driver_options][:compute_options][:region] = aws_profile[:region]
308
+ new_defaults[:driver_options][:compute_options][:endpoint] = aws_profile[:ec2_endpoint]
227
309
 
228
310
  account_info = aws_account_info_for(result[:driver_options][:compute_options])
229
311
  new_config[:driver_options][:aws_account_info] = account_info
@@ -0,0 +1,55 @@
1
+ require 'fog/joyent'
2
+
3
+ # fog:Joyent:<joyent_url>
4
+ module ChefMetalFog
5
+ module Providers
6
+ class Joyent < ChefMetalFog::FogDriver
7
+
8
+ ChefMetalFog::FogDriver.register_provider_class('Joyent', ChefMetalFog::Providers::Joyent)
9
+
10
+ def creator
11
+ compute_options[:joyent_username]
12
+ end
13
+
14
+ def bootstrap_options_for(action_handler, machine_spec, machine_options)
15
+ bootstrap_options = symbolize_keys(machine_options[:bootstrap_options] || {})
16
+
17
+ bootstrap_options[:tags] = default_tags(machine_spec, bootstrap_options[:tags] || {})
18
+
19
+ bootstrap_options[:tags].each do |key, val|
20
+ bootstrap_options["tag.#{key}"] = val
21
+ end
22
+
23
+ bootstrap_options[:name] ||= machine_spec.name
24
+
25
+ bootstrap_options
26
+ end
27
+
28
+ def self.compute_options_for(provider, id, config)
29
+ new_compute_options = {}
30
+ new_compute_options[:provider] = provider
31
+ new_config = { :driver_options => { :compute_options => new_compute_options }}
32
+ new_defaults = {
33
+ :driver_options => { :compute_options => {} },
34
+ :machine_options => { :bootstrap_options => {} }
35
+ }
36
+ result = Cheffish::MergedConfig.new(new_config, config, new_defaults)
37
+
38
+ new_compute_options[:joyent_url] = id if (id && id != '')
39
+ credential = Fog.credentials
40
+
41
+ new_compute_options[:joyent_username] ||= credential[:joyent_username]
42
+ new_compute_options[:joyent_password] ||= credential[:joyent_password]
43
+ new_compute_options[:joyent_keyname] ||= credential[:joyent_keyname]
44
+ new_compute_options[:joyent_keyfile] ||= credential[:joyent_keyfile]
45
+ new_compute_options[:joyent_url] ||= credential[:joyent_url]
46
+ new_compute_options[:joyent_version] ||= credential[:joyent_version]
47
+
48
+ id = result[:driver_options][:compute_options][:joyent_url]
49
+
50
+ [result, id]
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -1,3 +1,3 @@
1
1
  module ChefMetalFog
2
- VERSION = '0.7.1'
2
+ VERSION = '0.8'
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.7.1
4
+ version: '0.8'
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-07-15 00:00:00.000000000 Z
11
+ date: 2014-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef
@@ -114,6 +114,7 @@ files:
114
114
  - lib/chef_metal_fog/providers/aws/credentials.rb
115
115
  - lib/chef_metal_fog/providers/cloudstack.rb
116
116
  - lib/chef_metal_fog/providers/digitalocean.rb
117
+ - lib/chef_metal_fog/providers/joyent.rb
117
118
  - lib/chef_metal_fog/providers/openstack.rb
118
119
  - lib/chef_metal_fog/providers/rackspace.rb
119
120
  - lib/chef_metal_fog/recipe_dsl.rb