chef-metal-fog 0.5.beta.2 → 0.5.beta.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/chef/provider/fog_key_pair.rb +5 -5
- data/lib/chef_metal_fog/aws_credentials.rb +3 -1
- data/lib/chef_metal_fog/fog_driver.rb +43 -12
- data/lib/chef_metal_fog/fog_driver_aws.rb +31 -23
- data/lib/chef_metal_fog/recipe_dsl.rb +5 -0
- data/lib/chef_metal_fog/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1eee68d2204401956fc7abcaa093bc9c203e1d28
|
4
|
+
data.tar.gz: 4e14f8d8cc4e4821c79713b0a655686342837caf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35084cc9f278d5788f63094484d8f837d34ce856ef5e65076c27a1035ba5f4df57621fdaa27a97640af61956475e0524c370cabb812632bc3d297169b7b655f1
|
7
|
+
data.tar.gz: 27031e7de4dc5ab6efb343bb685eeada72ef50aa49f24812583d832234431a062d55ccac657d771fdd39bb88dec40bdc5f3b8966e57b026105f620621f4e78f5
|
data/README.md
CHANGED
@@ -19,7 +19,7 @@ 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 'OpenStack'
|
22
|
+
when 'OpenStack', 'Rackspace'
|
23
23
|
compute.key_pairs.destroy(@current_id)
|
24
24
|
else
|
25
25
|
compute.key_pairs.delete(new_resource.name)
|
@@ -54,7 +54,7 @@ class Chef::Provider::FogKeyPair < Chef::Provider::LWRPBase
|
|
54
54
|
case new_driver.compute_options[:provider]
|
55
55
|
when 'DigitalOcean'
|
56
56
|
new_fingerprints = [Cheffish::KeyFormatter.encode(desired_key, :format => :openssh)]
|
57
|
-
when 'OpenStack'
|
57
|
+
when 'OpenStack', 'Rackspace'
|
58
58
|
new_fingerprints = [Cheffish::KeyFormatter.encode(desired_key, :format => :openssh)]
|
59
59
|
else
|
60
60
|
# “The nice thing about standards is that you have so many to
|
@@ -81,7 +81,7 @@ class Chef::Provider::FogKeyPair < Chef::Provider::LWRPBase
|
|
81
81
|
case new_driver.compute_options[:provider]
|
82
82
|
when 'DigitalOcean'
|
83
83
|
compute.create_ssh_key(new_resource.name, Cheffish::KeyFormatter.encode(desired_key, :format => :openssh))
|
84
|
-
when 'OpenStack'
|
84
|
+
when 'OpenStack', 'Rackspace'
|
85
85
|
compute.create_key_pair(new_resource.name, Cheffish::KeyFormatter.encode(desired_key, :format => :openssh))
|
86
86
|
else
|
87
87
|
compute.key_pairs.get(new_resource.name).destroy
|
@@ -101,7 +101,7 @@ class Chef::Provider::FogKeyPair < Chef::Provider::LWRPBase
|
|
101
101
|
case new_driver.compute_options[:provider]
|
102
102
|
when 'DigitalOcean'
|
103
103
|
compute.create_ssh_key(new_resource.name, Cheffish::KeyFormatter.encode(desired_key, :format => :openssh))
|
104
|
-
when 'OpenStack'
|
104
|
+
when 'OpenStack', 'Rackspace'
|
105
105
|
compute.create_key_pair(new_resource.name, Cheffish::KeyFormatter.encode(desired_key, :format => :openssh))
|
106
106
|
else
|
107
107
|
compute.import_key_pair(new_resource.name, Cheffish::KeyFormatter.encode(desired_key, :format => :openssh))
|
@@ -189,7 +189,7 @@ class Chef::Provider::FogKeyPair < Chef::Provider::LWRPBase
|
|
189
189
|
else
|
190
190
|
current_resource.action :delete
|
191
191
|
end
|
192
|
-
when 'OpenStack'
|
192
|
+
when 'OpenStack', 'Rackspace'
|
193
193
|
current_key_pair = compute.key_pairs.get(new_resource.name)
|
194
194
|
if current_key_pair
|
195
195
|
@current_id = current_key_pair.name
|
@@ -8,6 +8,8 @@ module ChefMetalFog
|
|
8
8
|
@credentials = {}
|
9
9
|
end
|
10
10
|
|
11
|
+
include Enumerable
|
12
|
+
|
11
13
|
def default
|
12
14
|
@credentials[ENV['AWS_DEFAULT_PROFILE'] || 'default'] || @credentials.first[1]
|
13
15
|
end
|
@@ -51,7 +53,7 @@ module ChefMetalFog
|
|
51
53
|
end
|
52
54
|
|
53
55
|
def load_default
|
54
|
-
load_ini('~/.aws/config')
|
56
|
+
load_ini(ENV['AWS_CONFIG_FILE'] || File.expand_path('~/.aws/config'))
|
55
57
|
end
|
56
58
|
|
57
59
|
def self.method_missing(name, *args, &block)
|
@@ -29,6 +29,7 @@ module ChefMetalFog
|
|
29
29
|
# fog:AWS:<account_id>
|
30
30
|
# fog:OpenStack:https://identityHost:portNumber/v2.0
|
31
31
|
# fog:DigitalOcean:<client id>
|
32
|
+
# fog:Rackspace:https://identity.api.rackspacecloud.com/v2.0
|
32
33
|
#
|
33
34
|
# Identifier is generally something uniquely identifying the account. If multiple
|
34
35
|
# users can access the account, the identifier should be the same for all of
|
@@ -93,9 +94,13 @@ module ChefMetalFog
|
|
93
94
|
|
94
95
|
# Passed in a driver_url, and a config in the format of Driver.config.
|
95
96
|
def self.from_url(driver_url, config)
|
97
|
+
FogDriver.new(driver_url, config)
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.canonicalize_url(driver_url, config)
|
96
101
|
scheme, provider, id = driver_url.split(':', 3)
|
97
102
|
config, id = compute_options_for(provider, id, config)
|
98
|
-
|
103
|
+
[ "fog:#{provider}:#{id}", config ]
|
99
104
|
end
|
100
105
|
|
101
106
|
# Passed in a config which is *not* merged with driver_url (because we don't
|
@@ -129,7 +134,7 @@ module ChefMetalFog
|
|
129
134
|
end
|
130
135
|
|
131
136
|
def compute_options
|
132
|
-
driver_options[:compute_options] || {}
|
137
|
+
driver_options[:compute_options].to_hash || {}
|
133
138
|
end
|
134
139
|
|
135
140
|
def provider
|
@@ -248,6 +253,8 @@ module ChefMetalFog
|
|
248
253
|
driver_options[:aws_account_info][:aws_username]
|
249
254
|
when 'OpenStack'
|
250
255
|
compute_options[:openstack_username]
|
256
|
+
when 'Rackspace'
|
257
|
+
compute_options[:rackspace_username]
|
251
258
|
end
|
252
259
|
server = compute.servers.create(bootstrap_options)
|
253
260
|
machine_spec.location = {
|
@@ -491,9 +498,9 @@ module ChefMetalFog
|
|
491
498
|
ssh_options = ssh_options_for(machine_spec, server)
|
492
499
|
# If we're on AWS, the default is to use ubuntu, not root
|
493
500
|
if provider == 'AWS'
|
494
|
-
username = machine_spec.location[
|
501
|
+
username = machine_spec.location['ssh_username'] || 'ubuntu'
|
495
502
|
else
|
496
|
-
username = machine_spec.location[
|
503
|
+
username = machine_spec.location['ssh_username'] || 'root'
|
497
504
|
end
|
498
505
|
options = {}
|
499
506
|
if machine_spec.location[:sudo] || (!machine_spec.location.has_key?(:sudo) && username != 'root')
|
@@ -501,7 +508,7 @@ module ChefMetalFog
|
|
501
508
|
end
|
502
509
|
|
503
510
|
remote_host = nil
|
504
|
-
if machine_spec.location[
|
511
|
+
if machine_spec.location['use_private_ip_for_ssh']
|
505
512
|
remote_host = server.private_ip_address
|
506
513
|
elsif !server.public_ip_address
|
507
514
|
Chef::Log.warn("Server 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 ...")
|
@@ -514,7 +521,7 @@ module ChefMetalFog
|
|
514
521
|
|
515
522
|
#Enable pty by default
|
516
523
|
options[:ssh_pty_enable] = true
|
517
|
-
options[:ssh_gateway] = machine_spec.location[
|
524
|
+
options[:ssh_gateway] = machine_spec.location['ssh_gateway'] if machine_spec.location.has_key?('ssh_gateway')
|
518
525
|
|
519
526
|
ChefMetal::Transport::SSH.new(remote_host, username, ssh_options, options, config)
|
520
527
|
end
|
@@ -539,19 +546,25 @@ module ChefMetalFog
|
|
539
546
|
new_compute_options[:digitalocean_client_id] = id
|
540
547
|
when 'OpenStack'
|
541
548
|
new_compute_options[:openstack_auth_url] = id
|
549
|
+
when 'Rackspace'
|
550
|
+
new_compute_options[:rackspace_auth_url] = id
|
551
|
+
when 'CloudStack'
|
552
|
+
cloudstack_uri = URI.parse(id)
|
553
|
+
new_compute_options[:cloudstack_scheme] = cloudstack_uri.scheme
|
554
|
+
new_compute_options[:cloudstack_host] = cloudstack_uri.host
|
555
|
+
new_compute_options[:cloudstack_port] = cloudstack_uri.port
|
556
|
+
new_compute_options[:cloudstack_path] = cloudstack_uri.path
|
542
557
|
else
|
543
558
|
raise "unsupported fog provider #{provider}"
|
544
559
|
end
|
545
|
-
elsif provider == 'AWS'
|
546
|
-
driver_options[:aws_profile] = 'default'
|
547
560
|
end
|
548
561
|
|
549
562
|
# Set auth info from environment
|
550
563
|
case provider
|
551
564
|
when 'AWS'
|
552
565
|
# Grab the profile
|
553
|
-
aws_profile = FogDriverAWS.get_aws_profile(driver_options,
|
554
|
-
[ :aws_access_key_id, :aws_secret_access_key, :aws_session_token ].each do |key|
|
566
|
+
aws_profile = FogDriverAWS.get_aws_profile(driver_options, id)
|
567
|
+
[ :aws_access_key_id, :aws_secret_access_key, :aws_session_token, :region ].each do |key|
|
555
568
|
new_compute_options[key] = aws_profile[key] if aws_profile[key]
|
556
569
|
end
|
557
570
|
when 'OpenStack'
|
@@ -564,6 +577,15 @@ module ChefMetalFog
|
|
564
577
|
new_compute_options[:openstack_api_key] ||= credential[:openstack_api_key]
|
565
578
|
new_compute_options[:openstack_auth_url] ||= credential[:openstack_auth_url]
|
566
579
|
new_compute_options[:openstack_tenant] ||= credential[:openstack_tenant]
|
580
|
+
when 'Rackspace'
|
581
|
+
credential = Fog.credential
|
582
|
+
|
583
|
+
new_compute_options[:rackspace_username] ||= credential[:rackspace_username]
|
584
|
+
new_compute_options[:rackspace_api_key] ||= credential[:rackspace_api_key]
|
585
|
+
new_compute_options[:rackspace_auth_url] ||= credential[:rackspace_auth_url]
|
586
|
+
new_compute_options[:rackspace_region] ||= credential[:rackspace_region]
|
587
|
+
new_compute_options[:rackspace_endpoint] ||= credential[:rackspace_endpoint]
|
588
|
+
new_compute_options[:rackspace_compute_url] ||= credential[:rackspace_compute_url]
|
567
589
|
end
|
568
590
|
|
569
591
|
config = Cheffish::MergedConfig.new(new_config, config)
|
@@ -574,9 +596,18 @@ module ChefMetalFog
|
|
574
596
|
new_config[:driver_options][:aws_account_info] = account_info
|
575
597
|
account_info[:aws_account_id]
|
576
598
|
when 'DigitalOcean'
|
577
|
-
compute_options[:digitalocean_client_id]
|
599
|
+
config[:driver_options][:compute_options][:digitalocean_client_id]
|
578
600
|
when 'OpenStack'
|
579
|
-
compute_options[:openstack_auth_url]
|
601
|
+
config[:driver_options][:compute_options][:openstack_auth_url]
|
602
|
+
when 'Rackspace'
|
603
|
+
config[:driver_options][:compute_options][:rackspace_auth_url]
|
604
|
+
when 'CloudStack'
|
605
|
+
host = config[:driver_options][:compute_options][:cloudstack_host]
|
606
|
+
path = config[:driver_options][:compute_options][:cloudstack_path] || '/client/api'
|
607
|
+
port = config[:driver_options][:compute_options][:cloudstack_port] || 443
|
608
|
+
scheme = config[:driver_options][:compute_options][:cloudstack_scheme] || 'https'
|
609
|
+
|
610
|
+
URI.scheme_list[scheme.upcase].build(:host => host, :port => port, :path => path).to_s
|
580
611
|
end
|
581
612
|
|
582
613
|
[ config, id ]
|
@@ -4,33 +4,42 @@ require 'fog/aws'
|
|
4
4
|
|
5
5
|
module ChefMetalFog
|
6
6
|
module FogDriverAWS
|
7
|
-
def self.get_aws_profile(driver_options,
|
7
|
+
def self.get_aws_profile(driver_options, aws_account_id)
|
8
8
|
aws_credentials = get_aws_credentials(driver_options)
|
9
9
|
|
10
|
-
#
|
11
|
-
aws_access_key_id
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
10
|
+
# Order of operations:
|
11
|
+
# driver_options[:aws_access_key_id] / driver_options[:aws_secret_access_key] / driver_options[:aws_security_token]
|
12
|
+
# driver_options[:aws_profile]
|
13
|
+
# ENV['AWS_ACCESS_KEY_ID'] / ENV['AWS_SECRET_ACCESS_KEY'] / ENV['AWS_SECURITY_TOKEN']
|
14
|
+
# ENV['AWS_PROFILE']
|
15
|
+
# ENV['DEFAULT_PROFILE']
|
16
|
+
# 'default'
|
17
|
+
aws_profile = if driver_options[:aws_access_key_id]
|
18
|
+
Chef::Log.debug("Using AWS driver access key options")
|
19
|
+
{
|
20
|
+
:aws_access_key_id => driver_options[:aws_access_key_id],
|
21
|
+
:aws_secret_access_key => driver_options[:aws_secret_access_key],
|
22
|
+
:aws_security_token => driver_options[:aws_security_token]
|
23
|
+
}
|
22
24
|
elsif driver_options[:aws_profile]
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
Chef::Log.debug("Using AWS profile #{driver_options[:aws_profile]}")
|
26
|
+
aws_credentials[driver_options[:aws_profile]]
|
27
|
+
elsif ENV['AWS_ACCESS_KEY_ID']
|
28
|
+
Chef::Log.debug("Using AWS environment variable access keys")
|
29
|
+
{
|
30
|
+
:aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'],
|
31
|
+
:aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'],
|
32
|
+
:aws_security_token => ENV['AWS_SECURITY_TOKEN']
|
33
|
+
}
|
34
|
+
elsif ENV['AWS_PROFILE']
|
35
|
+
Chef::Log.debug("Using AWS profile #{ENV['AWS_PROFILE']} from AWS_PROFILE environment variable")
|
36
|
+
aws_credentials[ENV['AWS_PROFILE']]
|
28
37
|
else
|
29
|
-
|
30
|
-
|
38
|
+
Chef::Log.debug("Using AWS default profile")
|
39
|
+
aws_credentials.default
|
31
40
|
end
|
32
41
|
|
33
|
-
# Merge in account info
|
42
|
+
# Merge in account info for profile
|
34
43
|
if aws_profile
|
35
44
|
aws_profile = aws_profile.merge(aws_account_info_for(aws_profile))
|
36
45
|
end
|
@@ -46,8 +55,7 @@ module ChefMetalFog
|
|
46
55
|
end
|
47
56
|
|
48
57
|
# Set region
|
49
|
-
|
50
|
-
aws_profile[:region] = region if region
|
58
|
+
aws_profile[:region] ||= ENV['AWS_DEFAULT_REGION']
|
51
59
|
aws_profile.delete_if { |key, value| value.nil? }
|
52
60
|
aws_profile
|
53
61
|
end
|
@@ -18,6 +18,11 @@ class Chef
|
|
18
18
|
def with_fog_openstack_driver(driver_options = nil, &block)
|
19
19
|
with_fog_driver('OpenStack', driver_options, &block)
|
20
20
|
end
|
21
|
+
|
22
|
+
def with_fog_rackspace_driver(driver_options = nil, &block)
|
23
|
+
with_fog_driver('Rackspace', driver_options, &block)
|
24
|
+
end
|
25
|
+
|
21
26
|
end
|
22
27
|
end
|
23
28
|
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.5.beta.
|
4
|
+
version: 0.5.beta.3
|
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-05-
|
11
|
+
date: 2014-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef
|