Skip to content
This repository has been archived by the owner on Jul 24, 2020. It is now read-only.

Updated to reflect new configuration options in Fog 1.10.1 #37

Merged
merged 12 commits into from Jul 9, 2013
Merged
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -3,7 +3,6 @@ language: ruby
rvm:
- 2.0.0
- 1.9.3
- 1.8.7
env:
global:
- secure: ! 'eEsikE/p2yz7/cFvCN/NOoljxBqjzsTWnKC7iZ+fEGGsyhKVJgWn4AasBusZ
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,5 +1,6 @@
## v0.8.0
* KNIFE-180 include option to pass :disk_config option to fog for new node bootstrap
* KNIFE-312 updated to reflect new configuration options in Fog 1.10.1
* KNIFE-314 provisioning First Gen Cloud Server is broken
* KNIFE-315 fixed DEPRECATION warnings related to use of old rackpace_auth_url and removed rackspace_endpoint

Expand Down
7 changes: 5 additions & 2 deletions README.rdoc
Expand Up @@ -48,9 +48,12 @@ To select for the previous Rackspace API (aka 'v1'), you can use the <tt>--racks

knife[:rackspace_version] = 'v1'

This plugin also has support for authenticating against an alternate API Auth URL. Please refer to this Rackspace documentation page for the support choices: http://docs.rackspace.com/auth/api/v2.0/auth-client-devguide/content/Endpoints-d1e180.html This is useful if you are a Rackspace Cloud UK user, here is an example of configuring your <tt>knife.rb</tt>:
This plugin also has support for authenticating against an alternate API Auth URL. This is useful if you are a using a custom endpoint, here is an example of configuring your <tt>knife.rb</tt>:

knife[:rackspace_auth_url] = "https://lon.identity.api.rackspacecloud.com/v2.0"
knife[:rackspace_auth_url] = "auth.my-custom-endpoint.com"


Different regions can be specified by using the `--rackspace-region` switch or using the `knife[:rackspace_region]` in the knife.rb file. Valid regions include :dfw, :ord, :lon, and :syd.

If you are behind a proxy you can specify it in the knife.rb file as follows:

Expand Down
2 changes: 1 addition & 1 deletion knife-rackspace.gemspec
Expand Up @@ -16,8 +16,8 @@ Gem::Specification.new do |s|
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.add_dependency "fog", "~> 1.10"
s.add_dependency "knife-windows"
s.add_dependency "fog", "~> 1.12"
s.add_dependency "chef", ">= 0.10.10"
s.require_paths = ["lib"]

Expand Down
36 changes: 30 additions & 6 deletions lib/chef/knife/rackspace_base.rb
Expand Up @@ -17,6 +17,7 @@
#

require 'chef/knife'
require 'fog'

class Chef
class Knife
Expand Down Expand Up @@ -56,9 +57,14 @@ def self.included(includer)
option :rackspace_auth_url,
:long => "--rackspace-auth-url URL",
:description => "Your rackspace API auth url",
:default => "https://identity.api.rackspacecloud.com/v2.0",
:proc => Proc.new { |url| Chef::Config[:knife][:rackspace_auth_url] = url }

option :rackspace_region,
:long => "--rackspace-region REGION",
:description => "Your rackspace region",
:default => "dfw",
:proc => Proc.new { |region| Chef::Config[:knife][:rackspace_region] = region }

option :file,
:long => '--file DESTINATION-PATH=SOURCE-PATH',
:description => 'File to inject on node',
Expand All @@ -75,10 +81,15 @@ def connection
Chef::Log.debug("rackspace_api_key #{Chef::Config[:knife][:rackspace_api_key]}")
Chef::Log.debug("rackspace_username #{Chef::Config[:knife][:rackspace_username]}")
Chef::Log.debug("rackspace_api_username #{Chef::Config[:knife][:rackspace_api_username]}")
Chef::Log.debug("rackspace_auth_url #{Chef::Config[:knife][:rackspace_auth_url]} (config)")
Chef::Log.debug("rackspace_auth_url #{config[:rackspace_auth_url]} (cli)")
if (Chef::Config[:knife][:rackspace_version] == 'v1') || (config[:rackspace_version] == 'v1')
Chef::Log.debug("rackspace_auth_url #{Chef::Config[:knife][:rackspace_auth_url]}")
Chef::Log.debug("rackspace_auth_url #{config[:rackspace_api_auth_url]}")
Chef::Log.debug("rackspace_auth_url #{auth_endpoint} (using)")
Chef::Log.debug("rackspace_region #{Chef::Config[:knife][:rackspace_region]}")
Chef::Log.debug("rackspace_region #{config[:rackspace_region]}")

if version_one?
Chef::Log.debug("rackspace v1")
region_warning_for_v1
@connection ||= begin
connection = Fog::Compute.new(connection_params({
:version => 'v1'
Expand All @@ -93,13 +104,20 @@ def connection
end
end
end

def region_warning_for_v1
if Chef::Config[:knife][:rackspace_region] || config[:rackspace_region]
Chef::Log.warn("Ignoring the rackspace_region parameter as it is only supported for Next Gen Cloud Servers (v2)")
end
end

def connection_params(options={})
hash = options.merge({
:provider => 'Rackspace',
:rackspace_api_key => Chef::Config[:knife][:rackspace_api_key],
:rackspace_username => (Chef::Config[:knife][:rackspace_username] || Chef::Config[:knife][:rackspace_api_username]),
:rackspace_auth_url => Chef::Config[:knife][:rackspace_auth_url] || config[:rackspace_auth_url]
:rackspace_auth_url => auth_endpoint,
:rackspace_region => locate_config_value(:rackspace_region)
})

hash[:connection_options] ||= {}
Expand All @@ -115,6 +133,12 @@ def connection_params(options={})
hash
end

def auth_endpoint
url = locate_config_value(:rackspace_auth_url)
return url if url
(locate_config_value(:rackspace_region) == 'lon') ? ::Fog::Rackspace::UK_AUTH_ENDPOINT : ::Fog::Rackspace::US_AUTH_ENDPOINT
end

def locate_config_value(key)
key = key.to_sym
Chef::Config[:knife][key] || config[key]
Expand Down Expand Up @@ -159,7 +183,7 @@ def version_one?
end

def rackspace_api_version
version = Chef::Config[:knife][:rackspace_version] || 'v2'
version = locate_config_value(:rackspace_version) || 'v2'
version.downcase
end

Expand Down
83 changes: 38 additions & 45 deletions spec/cassettes/v1/should_list_images.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.