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

[OC-4046] Switches should be prefixed by the cloud #28

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.rdoc
Expand Up @@ -28,6 +28,10 @@ If your knife.rb file will be checked into a SCM system (ie readable by others)
knife[:rackspace_api_username] = "#{ENV['RACKSPACE_USERNAME']}"
knife[:rackspace_api_key] = "#{ENV['RACKSPACE_API_KEY']}"

Alternatively, above options can be provided as follows:
knife[:rackspace][:rackspace_api_username] = "#{ENV['RACKSPACE_USERNAME']}"
knife[:rackspace][:flavor] = "130"

You also have the option of passing your Rackspace API Username/Key into the individual knife subcommands using the <tt>-A</tt> (or <tt>--rackspace-api-username</tt>) <tt>-K</tt> (or <tt>--rackspace-api-key</tt>) command options

# provision a new 1GB Ubuntu 10.04 webserver
Expand Down
44 changes: 25 additions & 19 deletions lib/chef/knife/rackspace_base.rb
Expand Up @@ -17,6 +17,12 @@
#

class Chef

class Config
# Namespace for knife-rackspace
knife[:rackspace] = Hash.new
end

class Knife
module RackspaceBase

Expand Down Expand Up @@ -68,42 +74,42 @@ def self.included(includer)
end

def connection
Chef::Log.debug("version #{Chef::Config[:knife][:rackspace_version]}") #config file
Chef::Log.debug("version #{config[:rackspace_version]}") #cli
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]}")
Chef::Log.debug("rackspace_auth_url #{config[:rackspace_api_auth_url]}")
Chef::Log.debug("rackspace_endpoint #{Chef::Config[:knife][:rackspace_endpoint]}")
Chef::Log.debug("rackspace_endpoint #{config[:rackspace_endpoint]}")
if (Chef::Config[:knife][:rackspace_version] == 'v2') || (config[:rackspace_version] == 'v2')
Chef::Log.debug("version #{locate_config_value(:rackspace_version)}") #config file
Chef::Log.debug("version #{locate_config_value(:rackspace_version)}") #cli
Chef::Log.debug("rackspace_api_key #{locate_config_value(:rackspace_api_key)}")
Chef::Log.debug("rackspace_username #{locate_config_value(:rackspace_username)}")
Chef::Log.debug("rackspace_api_username #{locate_config_value(:rackspace_api_username)}")
Chef::Log.debug("rackspace_auth_url #{locate_config_value(:rackspace_auth_url)}")
Chef::Log.debug("rackspace_auth_url #{locate_config_value(:rackspace_api_auth_url)}")
Chef::Log.debug("rackspace_endpoint #{locate_config_value(:rackspace_endpoint)}")
Chef::Log.debug("rackspace_endpoint #{locate_config_value(:rackspace_endpoint)}")
if (locate_config_value(:rackspace_version) == 'v2') || (locate_config_value(:rackspace_version) == 'v2')
@connection ||= begin
connection = Fog::Compute.new(
:provider => 'Rackspace',
:version => 'v2',
: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_api_auth_url] || config[:rackspace_api_auth_url],
:rackspace_endpoint => Chef::Config[:knife][:rackspace_endpoint] || config[:rackspace_endpoint]
:rackspace_api_key => locate_config_value(:rackspace_api_key),
:rackspace_username => (locate_config_value(:rackspace_username) || locate_config_value(:rackspace_api_username)),
:rackspace_auth_url => locate_config_value(:rackspace_api_auth_url) || locate_config_value(:rackspace_api_auth_url),
:rackspace_endpoint => locate_config_value(:rackspace_endpoint) || locate_config_value(:rackspace_endpoint)
)
end
else
@connection ||= begin
connection = Fog::Compute.new(
:provider => 'Rackspace',
:version => 'v1',
: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_api_auth_url] || config[:rackspace_api_auth_url]
:rackspace_api_key => locate_config_value(:rackspace_api_key),
:rackspace_username => (locate_config_value(:rackspace_username) || locate_config_value(:rackspace_api_username)),
:rackspace_auth_url => locate_config_value(:rackspace_api_auth_url) || locate_config_value(:rackspace_api_auth_url)
)
end
end
end

def locate_config_value(key)
key = key.to_sym
Chef::Config[:knife][key] || config[key]
config[key] || Chef::Config[:knife][:rackspace][key] || Chef::Config[:knife][key]
end

def msg_pair(label, value, color=:cyan)
Expand Down Expand Up @@ -145,7 +151,7 @@ def version_one?
end

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

Expand Down
6 changes: 3 additions & 3 deletions lib/chef/knife/rackspace_server_create.rb
Expand Up @@ -153,7 +153,7 @@ def tcp_test_ssh(hostname)
def run
$stdout.sync = true

unless Chef::Config[:knife][:image]
unless locate_config_value(:image)
ui.error("You have not provided a valid image value. Please note the short option for this value recently changed from '-i' to '-I'.")
exit 1
end
Expand All @@ -162,9 +162,9 @@ def run

server = connection.servers.create(
:name => node_name,
:image_id => Chef::Config[:knife][:image],
:image_id => locate_config_value(:image),
:flavor_id => locate_config_value(:flavor),
:metadata => Chef::Config[:knife][:rackspace_metadata]
:metadata => locate_config_value(:rackspace_metadata)
)

msg_pair("Instance ID", server.id)
Expand Down