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

Commit

Permalink
Merge branch 'CHEF-2067'
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsdeleo committed Mar 21, 2011
2 parents 7fb9fea + 28659fd commit 706be8a
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 21 deletions.
4 changes: 4 additions & 0 deletions README.rdoc
Expand Up @@ -29,6 +29,10 @@ You also have the option of passing your Rackspace API Username/Key into the ind
# provision a new 1GB Ubuntu 10.04 webserver
knife rackspace server create 'role[webserver]' -i 49 -f 3 -A 'Your Rackspace API username' -K "Your Rackspace API Key"

This plugin also has support for authenticating against an alternate API Auth URL. This is useful if you are a Rackspace Cloud UK user or OpenStack early adopter. Here is an example of configuring knife for Rackspace Cloud UK:

knife[:rackspace_api_auth_url] = "lon.auth.api.rackspacecloud.com"

Additionally the following options may be set in your `knife.rb`:

* flavor
Expand Down
21 changes: 20 additions & 1 deletion lib/chef/knife/rackspace_flavor_list.rb
Expand Up @@ -26,6 +26,24 @@ class RackspaceFlavorList < Knife

banner "knife rackspace flavor list (options)"

option :rackspace_api_key,
:short => "-K KEY",
:long => "--rackspace-api-key KEY",
:description => "Your rackspace API key",
:proc => Proc.new { |key| Chef::Config[:knife][:rackspace_api_key] = key }

option :rackspace_api_username,
:short => "-A USERNAME",
:long => "--rackspace-api-username USERNAME",
:description => "Your rackspace API username",
:proc => Proc.new { |username| Chef::Config[:knife][:rackspace_api_username] = username }

option :rackspace_api_auth_url,
:long => "--rackspace-api-auth-url URL",
:description => "Your rackspace API auth url",
:default => "auth.api.rackspacecloud.com",
:proc => Proc.new { |url| Chef::Config[:knife][:rackspace_api_auth_url] = url }

def h
@highline ||= HighLine.new
end
Expand All @@ -36,7 +54,8 @@ def run
connection = Fog::Compute.new(
:provider => 'Rackspace',
:rackspace_api_key => Chef::Config[:knife][:rackspace_api_key],
:rackspace_username => Chef::Config[:knife][:rackspace_api_username]
:rackspace_username => Chef::Config[:knife][:rackspace_api_username],
:rackspace_auth_url => Chef::Config[:knife][:rackspace_api_auth_url] || config[:rackspace_api_auth_url]
)

flavor_list = [ h.color('ID', :bold), h.color('Name', :bold), h.color('Architecture', :bold), h.color('RAM', :bold), h.color('Disk', :bold) , h.color('Cores', :bold) ]
Expand Down
21 changes: 20 additions & 1 deletion lib/chef/knife/rackspace_image_list.rb
Expand Up @@ -26,6 +26,24 @@ class RackspaceImageList < Knife

banner "knife rackspace image list (options)"

option :rackspace_api_key,
:short => "-K KEY",
:long => "--rackspace-api-key KEY",
:description => "Your rackspace API key",
:proc => Proc.new { |key| Chef::Config[:knife][:rackspace_api_key] = key }

option :rackspace_api_username,
:short => "-A USERNAME",
:long => "--rackspace-api-username USERNAME",
:description => "Your rackspace API username",
:proc => Proc.new { |username| Chef::Config[:knife][:rackspace_api_username] = username }

option :rackspace_api_auth_url,
:long => "--rackspace-api-auth-url URL",
:description => "Your rackspace API auth url",
:default => "auth.api.rackspacecloud.com",
:proc => Proc.new { |url| Chef::Config[:knife][:rackspace_api_auth_url] = url }

def h
@highline ||= HighLine.new
end
Expand All @@ -36,7 +54,8 @@ def run
connection = Fog::Compute.new(
:provider => 'Rackspace',
:rackspace_api_key => Chef::Config[:knife][:rackspace_api_key],
:rackspace_username => Chef::Config[:knife][:rackspace_api_username]
:rackspace_username => Chef::Config[:knife][:rackspace_api_username],
:rackspace_auth_url => Chef::Config[:knife][:rackspace_api_auth_url] || config[:rackspace_api_auth_url]
)

image_list = [ h.color('ID', :bold), h.color('Name', :bold) ]
Expand Down
28 changes: 17 additions & 11 deletions lib/chef/knife/rackspace_server_create.rb
Expand Up @@ -32,8 +32,7 @@ class RackspaceServerCreate < Knife
:short => "-f FLAVOR",
:long => "--flavor FLAVOR",
:description => "The flavor of server",
:proc => Proc.new { |f| Chef::Config[:knife][:flavor] = f.to_i },
:default => 1
:proc => Proc.new { |f| Chef::Config[:knife][:flavor] = f.to_i }

option :image,
:short => "-i IMAGE",
Expand Down Expand Up @@ -62,18 +61,24 @@ class RackspaceServerCreate < Knife
:long => "--ssh-password PASSWORD",
:description => "The ssh password"

option :api_key,
option :rackspace_api_key,
:short => "-K KEY",
:long => "--rackspace-api-key KEY",
:description => "Your rackspace API key",
:proc => Proc.new { |key| Chef::Config[:knife][:rackspace_api_key] = key }

option :api_username,
option :rackspace_api_username,
:short => "-A USERNAME",
:long => "--rackspace-api-username USERNAME",
:description => "Your rackspace API username",
:proc => Proc.new { |username| Chef::Config[:knife][:rackspace_api_username] = username }

option :rackspace_api_auth_url,
:long => "--rackspace-api-auth-url URL",
:description => "Your rackspace API auth url",
:proc => Proc.new { |url| Chef::Config[:knife][:rackspace_api_auth_url] = url },
:default => "auth.api.rackspacecloud.com"

option :prerelease,
:long => "--prerelease",
:description => "Install the pre-release chef gems"
Expand All @@ -82,8 +87,8 @@ class RackspaceServerCreate < Knife
:short => "-d DISTRO",
:long => "--distro DISTRO",
:description => "Bootstrap a distro using a template",
:default => "ubuntu10.04-gems",
:proc => Proc.new { |d| Chef::Config[:knife][:distro] = d }
:proc => Proc.new { |d| Chef::Config[:knife][:distro] = d },
:default => "ubuntu10.04-gems"

option :use_sudo,
:long => "--sudo",
Expand All @@ -93,8 +98,8 @@ class RackspaceServerCreate < Knife
option :template_file,
:long => "--template-file TEMPLATE",
:description => "Full path to location of template to use",
:default => false,
:proc => Proc.new { |t| Chef::Config[:knife][:template_file] = t }
:proc => Proc.new { |t| Chef::Config[:knife][:template_file] = t },
:default => false

def h
@highline ||= HighLine.new
Expand Down Expand Up @@ -130,7 +135,8 @@ def run
connection = Fog::Compute.new(
:provider => 'Rackspace',
:rackspace_api_key => Chef::Config[:knife][:rackspace_api_key],
:rackspace_username => Chef::Config[:knife][:rackspace_api_username]
:rackspace_username => Chef::Config[:knife][:rackspace_api_username],
:rackspace_auth_url => Chef::Config[:knife][:rackspace_api_auth_url] || config[:rackspace_api_auth_url]
)

server = connection.servers.create(
Expand Down Expand Up @@ -185,10 +191,10 @@ def bootstrap_for_node(server)
bootstrap.config[:identity_file] = config[:identity_file]
bootstrap.config[:chef_node_name] = config[:chef_node_name] || server.id
bootstrap.config[:prerelease] = config[:prerelease]
bootstrap.config[:distro] = Chef::Config[:knife][:distro]
bootstrap.config[:distro] = Chef::Config[:knife][:distro] || config[:distro]
# bootstrap will run as root...sudo (by default) also messes up Ohai on CentOS boxes
bootstrap.config[:use_sudo] = config[:use_sudo]
bootstrap.config[:template_file] = Chef::Config[:knife][:template_file]
bootstrap.config[:template_file] = Chef::Config[:knife][:template_file] || config[:template_file]
bootstrap.config[:environment] = config[:environment]
bootstrap
end
Expand Down
27 changes: 23 additions & 4 deletions lib/chef/knife/rackspace_server_delete.rb
Expand Up @@ -6,9 +6,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -27,11 +27,29 @@ class RackspaceServerDelete < Knife

banner "knife rackspace server delete SERVER (options)"

option :rackspace_api_key,
:short => "-K KEY",
:long => "--rackspace-api-key KEY",
:description => "Your rackspace API key",
:proc => Proc.new { |key| Chef::Config[:knife][:rackspace_api_key] = key }

option :rackspace_api_username,
:short => "-A USERNAME",
:long => "--rackspace-api-username USERNAME",
:description => "Your rackspace API username",
:proc => Proc.new { |username| Chef::Config[:knife][:rackspace_api_username] = username }

option :rackspace_api_auth_url,
:long => "--rackspace-api-auth-url URL",
:description => "Your rackspace API auth url",
:default => "auth.api.rackspacecloud.com",
:proc => Proc.new { |url| Chef::Config[:knife][:rackspace_api_auth_url] = url }

def h
@highline ||= HighLine.new
end

def run
def run
require 'fog'
require 'highline'
require 'net/ssh/multi'
Expand All @@ -40,7 +58,8 @@ def run
connection = Fog::Compute.new(
:provider => 'Rackspace',
:rackspace_api_key => Chef::Config[:knife][:rackspace_api_key],
:rackspace_username => Chef::Config[:knife][:rackspace_api_username]
:rackspace_username => Chef::Config[:knife][:rackspace_api_username],
:rackspace_auth_url => Chef::Config[:knife][:rackspace_api_auth_url] || config[:rackspace_api_auth_url]
)

server = connection.servers.get(@name_args[0])
Expand Down
27 changes: 23 additions & 4 deletions lib/chef/knife/rackspace_server_list.rb
Expand Up @@ -6,9 +6,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -26,11 +26,29 @@ class RackspaceServerList < Knife

banner "knife rackspace server list (options)"

option :rackspace_api_key,
:short => "-K KEY",
:long => "--rackspace-api-key KEY",
:description => "Your rackspace API key",
:proc => Proc.new { |key| Chef::Config[:knife][:rackspace_api_key] = key }

option :rackspace_api_username,
:short => "-A USERNAME",
:long => "--rackspace-api-username USERNAME",
:description => "Your rackspace API username",
:proc => Proc.new { |username| Chef::Config[:knife][:rackspace_api_username] = username }

option :rackspace_api_auth_url,
:long => "--rackspace-api-auth-url URL",
:description => "Your rackspace API auth url",
:default => "auth.api.rackspacecloud.com",
:proc => Proc.new { |url| Chef::Config[:knife][:rackspace_api_auth_url] = url }

def h
@highline ||= HighLine.new
end

def run
def run
require 'fog'
require 'highline'
require 'net/ssh/multi'
Expand All @@ -39,7 +57,8 @@ def run
connection = Fog::Compute.new(
:provider => 'Rackspace',
:rackspace_api_key => Chef::Config[:knife][:rackspace_api_key],
:rackspace_username => Chef::Config[:knife][:rackspace_api_username]
:rackspace_username => Chef::Config[:knife][:rackspace_api_username],
:rackspace_auth_url => Chef::Config[:knife][:rackspace_api_auth_url] || config[:rackspace_api_auth_url]
)

server_list = [ h.color('ID', :bold), h.color('Name', :bold), h.color('Public IP', :bold), h.color('Private IP', :bold), h.color('Flavor', :bold), h.color('Image', :bold), h.color('State', :bold) ]
Expand Down

0 comments on commit 706be8a

Please sign in to comment.