chef-provisioning-fog 0.13 → 0.13.1

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: e33216302d47668520364a911ed5161cd681ca4a
4
- data.tar.gz: 0cc594a02828434a96c2202f3ff7db057825cbe4
3
+ metadata.gz: aaf6579771b48654165dcc7ede21e3d60c8a80fe
4
+ data.tar.gz: 57a93d7417190ba9e5f9b7fdc56e0364e2c654f3
5
5
  SHA512:
6
- metadata.gz: 35cb4c6b4f3dbd4711db0e791568b49a614169b2b648a3f815684759219412b6a027b636ebc3e2a8ce521ef007a388aa37998bb989c95611f6b553a001e42b08
7
- data.tar.gz: db0e74164bf16bb798025477d3dc1239ad3bf34eb69c823bf58ae2fcaa7c42222b6aa1100530108f4d03234de8fdf21b32afd43445c0b16bb7cbfa53bdcb917c
6
+ metadata.gz: bce04b039918073b474e6d039cf07f0b3d59ff9dc4f4d317a436b46e21d61eaa4cdaeac5b06a126a8cd4034c79a545a5680da0dacc9d8b028704196827452df7
7
+ data.tar.gz: 3138f0debc2d93f818fbd7e618db2ae420d85b4c58f066c254d83d400fb3ff4807da5143522739e096a2281ca0333cbc21495e5352ee8590c1fc51c91c47521e
@@ -18,7 +18,7 @@ class Chef::Provider::FogKeyPair < Chef::Provider::LWRPBase
18
18
  converge_by "delete #{key_description}" do
19
19
  case new_driver.compute_options[:provider]
20
20
  when 'DigitalOcean'
21
- compute.destroy_key_pair(@current_id)
21
+ compute.destroy_ssh_key(@current_id)
22
22
  when 'Joyent'
23
23
  compute.delete_key(@current_id)
24
24
  when 'OpenStack', 'Rackspace'
@@ -78,7 +78,7 @@ module FogDriver
78
78
  # - ssh_timeout: the time to wait for ssh to be available if the instance is detected as up (defaults to 20)
79
79
  # - ssh_username: username to use for ssh
80
80
  # - sudo: true to prefix all commands with "sudo"
81
- # - use_private_ip_for_ssh: hint to use private ip when available
81
+ # - use_private_ip_for_ssh: hint to use private floating_ip when available
82
82
  # - convergence_options: hash of options for the convergence strategy
83
83
  # - chef_client_timeout: the time to wait for chef-client to finish
84
84
  # - chef_server - the chef server to point convergence at
@@ -92,6 +92,7 @@ module FogDriver
92
92
  # }
93
93
  #
94
94
  class Driver < Provisioning::Driver
95
+ @@ip_pool_lock = Mutex.new
95
96
 
96
97
  include Chef::Mixin::ShellOut
97
98
 
@@ -199,12 +200,13 @@ module FogDriver
199
200
  raise "Machine #{machine_spec.name} does not have a server associated with it, or server does not exist."
200
201
  end
201
202
 
202
- # Attach floating IPs if necessary
203
- attach_floating_ips(action_handler, machine_spec, machine_options, server)
204
-
205
203
  # Start the server if needed, and wait for it to start
206
204
  start_server(action_handler, machine_spec, server)
207
205
  wait_until_ready(action_handler, machine_spec, machine_options, server)
206
+
207
+ # Attach/detach floating IPs if necessary
208
+ converge_floating_ips(action_handler, machine_spec, machine_options, server)
209
+
208
210
  begin
209
211
  wait_for_transport(action_handler, machine_spec, machine_options, server)
210
212
  rescue Fog::Errors::TimeoutError
@@ -424,46 +426,82 @@ module FogDriver
424
426
  end
425
427
  end
426
428
 
427
- def attach_floating_ips(action_handler, machine_spec, machine_options, server)
428
- # TODO this is not particularly idempotent. OK, it is not idempotent AT ALL. Fix.
429
- if option_for(machine_options, :floating_ip_pool)
430
- Chef::Log.info 'Attaching IP from pool'
431
- action_handler.perform_action "attach floating IP from #{option_for(machine_options, :floating_ip_pool)} pool" do
432
- attach_ip_from_pool(server, option_for(machine_options, :floating_ip_pool))
429
+ def converge_floating_ips(action_handler, machine_spec, machine_options, server)
430
+ pool = option_for(machine_options, :floating_ip_pool)
431
+ floating_ip = option_for(machine_options, :floating_ip)
432
+ attached_floating_ips = find_floating_ips(server)
433
+ if pool
434
+
435
+ Chef::Log.debug "Attaching IP from pool #{pool}"
436
+ if attached_floating_ips.size > 0
437
+ Chef::Log.info "Server already assigned attached_floating_ips `#{attached_floating_ips}`"
438
+ elsif
439
+ action_handler.perform_action "Attaching floating IP from pool `#{pool}`" do
440
+ attach_ip_from_pool(server, pool)
441
+ end
442
+ end
443
+
444
+ elsif floating_ip
445
+
446
+ Chef::Log.debug "Attaching given IP #{floating_ip}"
447
+ if attached_floating_ips.include? floating_ip
448
+ Chef::Log.info "Address <#{floating_ip}> already allocated"
449
+ else
450
+ action_handler.perform_action "Attaching floating IP #{floating_ip}" do
451
+ attach_ip(server, floating_ip)
452
+ end
433
453
  end
434
- elsif option_for(machine_options, :floating_ip)
435
- Chef::Log.info 'Attaching given IP'
436
- action_handler.perform_action "attach floating IP #{option_for(machine_options, :floating_ip)}" do
437
- attach_ip(server, option_for(machine_options, :allocation_id), option_for(machine_options, :floating_ip))
454
+
455
+ elsif !attached_floating_ips.empty?
456
+
457
+ # If nothing is assigned, lets remove any floating IPs
458
+ Chef::Log.debug 'Missing :floating_ip_pool or :floating_ip, removing attached floating IPs'
459
+ action_handler.perform_action "Removing floating IPs #{attached_floating_ips}" do
460
+ attached_floating_ips.each do |ip|
461
+ server.disassociate_address(ip)
462
+ end
463
+ server.reload
464
+ end
465
+
466
+ end
467
+ end
468
+
469
+ # Find all attached floating IPs from all networks
470
+ def find_floating_ips(server)
471
+ floating_ips = []
472
+ server.addresses.each do |network, addrs|
473
+ addrs.each do | full_addr |
474
+ if full_addr['OS-EXT-IPS:type'] == 'floating'
475
+ floating_ips << full_addr['addr']
476
+ end
438
477
  end
439
478
  end
479
+ floating_ips
440
480
  end
441
481
 
442
482
  # Attach IP to machine from IP pool
443
483
  # Code taken from kitchen-openstack driver
444
- # https://github.com/test-kitchen/kitchen-openstack/blob/master/lib/kitchen/driver/openstack.rb#L196-L207
484
+ # https://github.com/test-kitchen/kitchen-openstack/blob/master/lib/kitchen/driver/openstack.rb
445
485
  def attach_ip_from_pool(server, pool)
446
- @ip_pool_lock ||= Mutex.new
447
- @ip_pool_lock.synchronize do
486
+ @@ip_pool_lock.synchronize do
448
487
  Chef::Log.info "Attaching floating IP from <#{pool}> pool"
449
- free_addrs = compute.addresses.collect do |i|
450
- i.ip if i.fixed_ip.nil? and i.instance_id.nil? and i.pool == pool
488
+ free_addrs = compute.addresses.map do |i|
489
+ i.ip if i.fixed_ip.nil? && i.instance_id.nil? && i.pool == pool
451
490
  end.compact
452
491
  if free_addrs.empty?
453
- raise ActionFailed, "No available IPs in pool <#{pool}>"
492
+ raise RuntimeError, "No available IPs in pool <#{pool}>"
454
493
  end
455
494
  attach_ip(server, free_addrs[0])
456
495
  end
457
496
  end
458
497
 
459
- # Attach given IP to machine
498
+ # Attach given IP to machine, assign it as public
460
499
  # Code taken from kitchen-openstack driver
461
- # https://github.com/test-kitchen/kitchen-openstack/blob/master/lib/kitchen/driver/openstack.rb#L209-L213
462
- def attach_ip(server, allocation_id, ip)
500
+ # https://github.com/test-kitchen/kitchen-openstack/blob/master/lib/kitchen/driver/openstack.rb
501
+ def attach_ip(server, ip)
463
502
  Chef::Log.info "Attaching floating IP <#{ip}>"
464
- compute.associate_address(:instance_id => server.id,
465
- :allocation_id => allocation_id,
466
- :public_ip => ip)
503
+ server.associate_address ip
504
+ server.reload
467
505
  end
468
506
 
469
507
  def symbolize_keys(options)
@@ -636,7 +674,7 @@ module FogDriver
636
674
  if machine_spec.location['use_private_ip_for_ssh']
637
675
  remote_host = server.private_ip_address
638
676
  elsif !server.public_ip_address
639
- Chef::Log.warn("Server #{machine_spec.name} has no public ip address. Using private ip '#{server.private_ip_address}'. Set driver option 'use_private_ip_for_ssh' => true if this will always be the case ...")
677
+ Chef::Log.warn("Server #{machine_spec.name} has no public floating_ip address. Using private floating_ip '#{server.private_ip_address}'. Set driver option 'use_private_ip_for_ssh' => true if this will always be the case ...")
640
678
  remote_host = server.private_ip_address
641
679
  elsif server.public_ip_address
642
680
  remote_host = server.public_ip_address
@@ -173,6 +173,14 @@ module FogDriver
173
173
  super(machine_spec, machine_options)
174
174
  end
175
175
 
176
+ # Attach given IP to machine
177
+ def attach_ip(server, ip)
178
+ Chef::Log.info "Attaching floating IP <#{ip}>"
179
+ compute.associate_address(:instance_id => server.id,
180
+ :allocation_id => option_for(machine_options, :allocation_id),
181
+ :public_ip => ip)
182
+ end
183
+
176
184
  def self.get_aws_profile(driver_options, aws_account_id)
177
185
  aws_credentials = get_aws_credentials(driver_options)
178
186
  compute_options = driver_options[:compute_options] || {}
@@ -10,6 +10,10 @@ module FogDriver
10
10
  ''
11
11
  end
12
12
 
13
+ def converge_floating_ips(action_handler, machine_spec, machine_options, server)
14
+ # Digital ocean does not have floating IPs
15
+ end
16
+
13
17
  def bootstrap_options_for(action_handler, machine_spec, machine_options)
14
18
  bootstrap_options = symbolize_keys(machine_options[:bootstrap_options] || {})
15
19
  if bootstrap_options[:key_path]
@@ -29,8 +33,16 @@ module FogDriver
29
33
  bootstrap_options[:tags] = default_tags(machine_spec, bootstrap_options[:tags] || {})
30
34
 
31
35
  if !bootstrap_options[:image_id]
32
- bootstrap_options[:image_name] ||= 'CentOS 6.4 x32'
33
- bootstrap_options[:image_id] = compute.images.select { |image| image.name == bootstrap_options[:image_name] }.first.id
36
+ if !bootstrap_options[:image_distribution] && !bootstrap_options[:image_name]
37
+ bootstrap_options[:image_distribution] = 'CentOS'
38
+ bootstrap_options[:image_name] = '6.5 x64'
39
+ end
40
+ matches = compute.images.select { |image| image.distribution == bootstrap_options[:image_distribution] }
41
+ matches = matches.select { |image| image.name == bootstrap_options[:image_name] } if bootstrap_options[:image_name]
42
+ if matches.empty?
43
+ raise "No images on DigitalOcean with distribution #{bootstrap_options[:image_distribution].inspect} and name #{bootstrap_options[:image_name].inspect}"
44
+ end
45
+ bootstrap_options[:image_id] = matches.first.id
34
46
  end
35
47
  if !bootstrap_options[:flavor_id]
36
48
  bootstrap_options[:flavor_name] ||= '512MB'
@@ -69,8 +81,8 @@ module FogDriver
69
81
  new_compute_options[:provider] = provider
70
82
  new_config = { :driver_options => { :compute_options => new_compute_options }}
71
83
  new_defaults = {
72
- :driver_options => { :compute_options => {} },
73
- :machine_options => { :bootstrap_options => {} }
84
+ :driver_options => { :compute_options => {} },
85
+ :machine_options => { :bootstrap_options => {}, :ssh_options => {} }
74
86
  }
75
87
  result = Cheffish::MergedConfig.new(new_config, config, new_defaults)
76
88
 
@@ -80,39 +92,27 @@ module FogDriver
80
92
  tugboat_file = File.expand_path('~/.tugboat')
81
93
  if File.exist?(tugboat_file)
82
94
  tugboat_data = YAML.load(IO.read(tugboat_file))
83
- new_compute_options.merge!(
84
- :digitalocean_client_id => tugboat_data['authentication']['client_key'],
85
- :digitalocean_api_key => tugboat_data['authentication']['api_key']
86
- )
87
- new_defaults[:machine_options].merge!(
88
- #:ssh_username => tugboat_data['ssh']['ssh_user'],
89
- :ssh_options => {
90
- :port => tugboat_data['ssh']['ssh_port'],
91
- # TODO we ignore ssh_key_path in favor of ssh_key / key_name stuff
92
- #:key_data => [ IO.read(tugboat_data['ssh']['ssh_key_path']) ] # TODO use paths, not data?
93
- }
94
- )
95
-
96
- # TODO verify that the key_name exists and matches the ssh key path
97
95
 
98
- new_defaults[:machine_options][:bootstrap_options].merge!(
99
- :region_id => tugboat_data['defaults']['region'].to_i,
100
- :image_id => tugboat_data['defaults']['image'].to_i,
101
- :size_id => tugboat_data['defaults']['size'].to_i,
102
- :private_networking => tugboat_data['defaults']['private_networking'] == 'true',
103
- :backups_enabled => tugboat_data['defaults']['backups_enabled'] == 'true',
104
- )
105
- if tugboat_data['ssh']['ssh_key_path']
106
- new_defaults[:machine_options][:bootstrap_options][:key_path] = tugboat_data['ssh']['ssh_key_path']
96
+ new_bootstrap_options = new_defaults[:machine_options][:bootstrap_options]
97
+ if tugboat_data['authentication']
98
+ new_compute_options[:digitalocean_client_id] = tugboat_data['authentication']['client_key'] if tugboat_data['authentication']['client_key'] && tugboat_data['authentication']['client_key'].size > 0
99
+ new_compute_options[:digitalocean_api_key] = tugboat_data['authentication']['api_key'] if tugboat_data['authentication']['api_key'] && tugboat_data['authentication']['api_key'].size > 0
100
+ end
101
+ if tugboat_data['defaults']
102
+ new_bootstrap_options[:region_id] = tugboat_data['defaults']['region'].to_i if tugboat_data['defaults']['region'] && tugboat_data['defaults']['region'].size > 0
103
+ new_bootstrap_options[:image_id] = tugboat_data['defaults']['image'].to_i if tugboat_data['defaults']['image'] && tugboat_data['defaults']['image'].size > 0
104
+ new_bootstrap_options[:size_id] = tugboat_data['defaults']['size'].to_i if tugboat_data['defaults']['size'] && tugboat_data['defaults']['size'].size > 0
105
+ new_bootstrap_options[:private_networking] = (tugboat_data['defaults']['private_networking'] == 'true') if tugboat_data['defaults']['private_networking'] && tugboat_data['defaults']['private_networking'].size > 0
106
+ new_bootstrap_options[:backups_enabled] = (tugboat_data['defaults']['backups_enabled'] == 'true') if tugboat_data['defaults']['backups_enabled'] && tugboat_data['defaults']['backups_enabled'].size > 0
107
+ new_bootstrap_options[:key_name] = tugboat_data['defaults']['ssh_key'] if tugboat_data['defaults']['ssh_key'] && tugboat_data['defaults']['ssh_key'].size > 0
107
108
  end
108
- ssh_key = tugboat_data['defaults']['ssh_key']
109
- if ssh_key && ssh_key.size > 0
110
- new_defaults[:machine_options][:bootstrap_options][:key_name] = ssh_key
109
+ if tugboat_data['ssh']
110
+ new_bootstrap_options[:key_path] = tugboat_data['ssh']['ssh_key_path'] if tugboat_data['ssh']['ssh_key_path'] && tugboat_data['ssh']['ssh_key_path'].size > 0
111
+ new_defaults[:machine_options][:ssh_options][:port] = tugboat_data['ssh']['ssh_port'] if tugboat_data['ssh']['ssh_port'] if tugboat_data['ssh']['ssh_port'].size > 0
111
112
  end
112
113
  end
113
- id = result[:driver_options][:compute_options][:digitalocean_client_id]
114
114
 
115
- [result, id]
115
+ [result, new_compute_options[:digitalocean_client_id]]
116
116
  end
117
117
 
118
118
  end
@@ -1,7 +1,7 @@
1
1
  class Chef
2
2
  module Provisioning
3
3
  module FogDriver
4
- VERSION = '0.13'
4
+ VERSION = '0.13.1'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-provisioning-fog
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.13'
4
+ version: 0.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Keiser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-26 00:00:00.000000000 Z
11
+ date: 2015-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef
@@ -144,9 +144,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  version: '0'
145
145
  requirements: []
146
146
  rubyforge_project:
147
- rubygems_version: 2.2.2
147
+ rubygems_version: 2.4.2
148
148
  signing_key:
149
149
  specification_version: 4
150
150
  summary: Driver for creating Fog instances in Chef Provisioning.
151
151
  test_files: []
152
- has_rdoc: