chef-metal-fog 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4ea9c6ac23831a0ea9f07511d18e154f131a69f
4
- data.tar.gz: 445242bbb2c4291741ccac066de423a61c56533a
3
+ metadata.gz: f700b696e9287fbc6a14e028b27879efb1841828
4
+ data.tar.gz: eded4c9ec79313327158939eeeff70d09ef73e1b
5
5
  SHA512:
6
- metadata.gz: 5118d0d757dbbaf5bd07f8920b6bb4d8e269d5c571a32591611329a0bbdf226bc775cd75df83987502431073947b5d922431950b7f45040655f279cdbfea68a7
7
- data.tar.gz: a7462b748510bbd741320c72980d3e07541023b1182e1831562dfb023cd3d2c1e98804cd1a89d14cb0a6787a9b7100240707d9ff1f05fb1b41e0aa909a87e369
6
+ metadata.gz: 043b903bcc06d9337d2fc0910007e43a480d6ab7b70f2eb03f98a08f8825cc57235d937b8ecde0a0d48cc4cced0157b94d8f4858eb976b6286ee1e642baca204
7
+ data.tar.gz: d0f843d5bcdeeec31bc9beeb7ff033ac3befca843ba395a6a82423af7013f0dc7c01b0ecf0e4822542d0772dff294065259541b11f5526fc756dd4dedb1e9369
@@ -418,7 +418,7 @@ module ChefMetalFog
418
418
 
419
419
  def bootstrap_options_for(action_handler, machine_spec, machine_options)
420
420
  bootstrap_options = symbolize_keys(machine_options[:bootstrap_options] || {})
421
- if !bootstrap_options[:key_name]
421
+ if (provider == 'DigitalOcean' || provider == 'AWS') && !bootstrap_options[:key_name]
422
422
  bootstrap_options[:key_name] = overwrite_default_key_willy_nilly(action_handler)
423
423
  end
424
424
  tags = {
@@ -445,7 +445,11 @@ module ChefMetalFog
445
445
  bootstrap_options[:region_name] ||= 'San Francisco 1'
446
446
  bootstrap_options[:region_id] = compute.regions.select { |region| region.name == bootstrap_options[:region_name] }.first.id
447
447
  end
448
- bootstrap_options[:ssh_key_ids] ||= [ compute.ssh_keys.select { |k| k.name == bootstrap_options[:key_name] }.first.id ]
448
+ found_key = compute.ssh_keys.select { |k| k.name == bootstrap_options[:key_name] }.first
449
+ if !found_key
450
+ raise "Could not find key named '#{bootstrap_options[:key_name]}' on #{driver_url}"
451
+ end
452
+ bootstrap_options[:ssh_key_ids] ||= [ found_key.id ]
449
453
 
450
454
  # You don't get to specify name yourself
451
455
  bootstrap_options[:name] = machine_spec.name
@@ -484,7 +488,7 @@ module ChefMetalFog
484
488
  end
485
489
  end
486
490
 
487
- def ssh_options_for(machine_spec, server)
491
+ def ssh_options_for(machine_spec, machine_options, server)
488
492
  result = {
489
493
  # TODO create a user known hosts file
490
494
  # :user_known_hosts_file => vagrant_ssh_config['UserKnownHostsFile'],
@@ -492,13 +496,15 @@ module ChefMetalFog
492
496
  :auth_methods => [ 'publickey' ],
493
497
  :keys_only => true,
494
498
  :host_key_alias => "#{server.id}.#{provider}"
495
- }
499
+ }.merge(machine_options[:ssh_options] || {})
496
500
  if server.respond_to?(:private_key) && server.private_key
497
501
  result[:key_data] = [ server.private_key ]
498
502
  elsif server.respond_to?(:key_name)
499
503
  result[:key_data] = [ get_private_key(server.key_name) ]
500
504
  elsif machine_spec.location['key_name']
501
505
  result[:key_data] = [ get_private_key(machine_spec.location['key_name']) ]
506
+ elsif machine_options[:bootstrap_options][:key_name]
507
+ result[:key_data] = [ get_private_key(machine_options[:bootstrap_options][:key_name]) ]
502
508
  else
503
509
  # TODO make a way to suggest other keys to try ...
504
510
  raise "No key found to connect to #{machine_spec.name}!"
@@ -507,7 +513,7 @@ module ChefMetalFog
507
513
  end
508
514
 
509
515
  def create_ssh_transport(machine_spec, machine_options, server)
510
- ssh_options = ssh_options_for(machine_spec, server)
516
+ ssh_options = ssh_options_for(machine_spec, machine_options, server)
511
517
  # If we're on AWS, the default is to use ubuntu, not root
512
518
  if provider == 'AWS'
513
519
  username = machine_spec.location['ssh_username'] || 'ubuntu'
@@ -547,7 +553,11 @@ module ChefMetalFog
547
553
  new_compute_options = {}
548
554
  new_compute_options[:provider] = provider
549
555
  new_config = { :driver_options => { :compute_options => new_compute_options }}
550
- result = Cheffish::MergedConfig.new(new_config, config)
556
+ new_defaults = {
557
+ :driver_options => { :compute_options => {} },
558
+ :machine_options => { :bootstrap_options => {} }
559
+ }
560
+ result = Cheffish::MergedConfig.new(new_config, config, new_defaults)
551
561
 
552
562
  # Get data from the identifier in the URL
553
563
  if id && id != ''
@@ -593,8 +603,7 @@ module ChefMetalFog
593
603
  new_compute_options[:aws_access_key_id] = aws_profile[:aws_access_key_id]
594
604
  new_compute_options[:aws_secret_access_key] = aws_profile[:aws_secret_access_key]
595
605
  new_compute_options[:aws_session_token] = aws_profile[:aws_security_token]
596
- # For :region, we prefer the region in compute options or URL over the region in the profile.
597
- new_compute_options[:region] ||= aws_profile[:region] if aws_profile.has_key?(:region) && !compute_options.has_key?(:region)
606
+ new_defaults[:driver_options][:compute_options][:region] = aws_profile[:region]
598
607
  when 'OpenStack'
599
608
  # TODO it is supposed to be unnecessary to load credentials from fog this way;
600
609
  # why are we doing it?
@@ -614,6 +623,38 @@ module ChefMetalFog
614
623
  new_compute_options[:rackspace_region] ||= credential[:rackspace_region]
615
624
  new_compute_options[:rackspace_endpoint] ||= credential[:rackspace_endpoint]
616
625
  new_compute_options[:rackspace_compute_url] ||= credential[:rackspace_compute_url]
626
+ when 'DigitalOcean'
627
+ # This uses ~/.tugboat, generated by "tugboat authorize" - see https://github.com/pearkes/tugboat
628
+ tugboat_file = File.expand_path('~/.tugboat')
629
+ if File.exist?(tugboat_file)
630
+ tugboat_data = YAML.load(IO.read(tugboat_file))
631
+ new_compute_options.merge!(
632
+ :digitalocean_client_id => tugboat_data['authentication']['client_key'],
633
+ :digitalocean_api_key => tugboat_data['authentication']['api_key']
634
+ )
635
+ new_defaults[:machine_options].merge!(
636
+ #:ssh_username => tugboat_data['ssh']['ssh_user'],
637
+ :ssh_options => {
638
+ :port => tugboat_data['ssh']['ssh_port'],
639
+ # TODO we ignore ssh_key_path in favor of ssh_key / key_name stuff
640
+ #:key_data => [ IO.read(tugboat_data['ssh']['ssh_key_path']) ] # TODO use paths, not data?
641
+ }
642
+ )
643
+
644
+ # TODO verify that the key_name exists and matches the ssh key path
645
+
646
+ new_defaults[:machine_options][:bootstrap_options].merge!(
647
+ :region_id => tugboat_data['defaults']['region'].to_i,
648
+ :image_id => tugboat_data['defaults']['image'].to_i,
649
+ :size_id => tugboat_data['defaults']['region'].to_i,
650
+ :private_networking => tugboat_data['defaults']['private_networking'] == 'true',
651
+ :backups_enabled => tugboat_data['defaults']['backups_enabled'] == 'true',
652
+ )
653
+ ssh_key = tugboat_data['defaults']['ssh_key']
654
+ if ssh_key && ssh_key.size > 0
655
+ new_defaults[:machine_options][:bootstrap_options][:key_name] = ssh_key
656
+ end
657
+ end
617
658
  end
618
659
 
619
660
  id = case provider
@@ -622,11 +663,11 @@ module ChefMetalFog
622
663
  new_config[:driver_options][:aws_account_info] = account_info
623
664
  "#{account_info[:aws_account_id]}:#{result[:driver_options][:compute_options][:region]}"
624
665
  when 'DigitalOcean'
625
- config[:driver_options][:compute_options][:digitalocean_client_id]
666
+ result[:driver_options][:compute_options][:digitalocean_client_id]
626
667
  when 'OpenStack'
627
- config[:driver_options][:compute_options][:openstack_auth_url]
668
+ result[:driver_options][:compute_options][:openstack_auth_url]
628
669
  when 'Rackspace'
629
- config[:driver_options][:compute_options][:rackspace_auth_url]
670
+ result[:driver_options][:compute_options][:rackspace_auth_url]
630
671
  when 'CloudStack'
631
672
  host = result[:driver_options][:compute_options][:cloudstack_host]
632
673
  path = result[:driver_options][:compute_options][:cloudstack_path] || '/client/api'
@@ -1,3 +1,3 @@
1
1
  module ChefMetalFog
2
- VERSION = '0.5.1'
2
+ VERSION = '0.5.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-metal-fog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Keiser