knife-rackspace 0.11.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- M2NhZmI1NDM4OWUxODEwODI1ZGVmNWQ2YzgxZjBjNmJiYjMzOGVkYQ==
5
- data.tar.gz: !binary |-
6
- OTY4MTM0MTMzNzY5M2U4NWUwMmMxNmFhZWEyNjQ3YjQzYTdkNWMwZA==
2
+ SHA1:
3
+ metadata.gz: 967c80d89cf4bd3ce780e24b678aaf50324c52f6
4
+ data.tar.gz: 68897241bb46bd04c1f61e9ed40b9ea002997a8e
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NTdjN2ZlMzBiNjUwZDZjODQ0M2U1YmQyODkwMTA0MGMyMTIxYjZmYTNhODQ5
10
- MGExY2U5NmEzMzc5MTUxMWE4YzkwZDBiMGJmNzMxZTAyODc2MzZmMjdiMjg1
11
- NzVlMWU0NWZlYjY1Yzc5MDU2OWE4MjI4NGUxMjM4N2I5MGFjZjQ=
12
- data.tar.gz: !binary |-
13
- YTVkNjkwMjM4MDM0YTZhZDdjNmEzZDhlYzY2OTk4NTA3MTdmODE2YjgyNzRj
14
- MzJjODA0MjY1MmFhNjY5NzFmMWFhMzY4YjhlZjQ4OTA1MTkwNGRlMjBiZTc4
15
- Mzk4MjE1OGU3ODkyOTM3NDJmMWQ1ZDcxYWQ5MGY4YjI4ZTdjN2E=
6
+ metadata.gz: aeaed772b104df0db30785c4ca82f3ff121bb3e311201bc48de2c3b6f8df21b1f1784278a14e2895796acb4a68fcb6cd48a3951135ca5c75735b1278e233ffd3
7
+ data.tar.gz: f2501f2c1f7d29e6f3778d58145f2768bb6b6a9a355a0e49a778ae2573cb8ee07838587536ad42268bea2d9392563ce013fd6206d28142cb2c59701f3f4508fc
@@ -0,0 +1,21 @@
1
+ # Version:
2
+
3
+ [Version of the project installed]
4
+
5
+ # Environment: [Details about the environment such as the Operating System, cookbook details, etc...]
6
+
7
+ # Scenario:
8
+
9
+ [What you are trying to achieve and you can't?]
10
+
11
+ # Steps to Reproduce:
12
+
13
+ [If you are filing an issue what are the things we need to do in order to repro your problem?]
14
+
15
+ # Expected Result:
16
+
17
+ [What are you expecting to happen as the consequence of above reproduction steps?]
18
+
19
+ # Actual Result:
20
+
21
+ [What actually happens after the reproduction steps?]
@@ -1,8 +1,9 @@
1
1
  language: ruby
2
+ cache: bundler
3
+ sudo: false
2
4
  rvm:
3
- - 2.2
4
- - 2.1
5
- - 2.0.0
5
+ - 2.2.5
6
+ - 2.3.1
6
7
  env:
7
8
  global:
8
9
  - excon_debug: true
@@ -1,3 +1,14 @@
1
+ ## v1.0.0
2
+ * Use fog/rackspace instead of fog gem
3
+ * Require Ruby 2.2.2 / Chef 12 and general cleanup
4
+ * Spec updates to avoid deprecation warnings
5
+ * Chefstyle fixes
6
+ * Modified server list - #118
7
+
8
+ ## v0.11.1
9
+ * Remove unused, and unsupported/ancient knife-dsl requirement
10
+ * Take it all the way to 11 (Chef 11.x) and greater
11
+
1
12
  ## v0.11.0
2
13
  * Add -B (boot volume ID) to `knife rackspace server create` - #91
3
14
 
data/Gemfile CHANGED
@@ -1,3 +1,10 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
+ # Specify your gem's dependencies in knife-rackspace.gemspec
3
4
  gemspec
5
+
6
+ gem "rspec", "~> 3.0"
7
+ gem "vcr"
8
+ gem "ansi"
9
+ gem "chefstyle"
10
+ gem "rake", "~> 11.0"
@@ -0,0 +1,230 @@
1
+ # Knife Rackspace
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/knife-rackspace.svg)](https://rubygems.org/gems/knife-rackspace) [![Build Status](https://travis-ci.org/chef/knife-rackspace.svg?branch=master)](https://travis-ci.org/chef/knife-rackspace)
4
+
5
+ This is the official Chef Knife plugin for Rackspace Cloud Servers. This plugin gives knife the ability to create, bootstrap, and manage servers on all the regions for Rackspace Cloud Servers.
6
+
7
+ ## Requirements
8
+
9
+ - Chef 12.0 higher
10
+ - Ruby 2.2.2 or higher
11
+
12
+ ## Installation
13
+
14
+ Using [ChefDK](https://downloads.chef.io/chef-dk/), simply install the Gem:
15
+
16
+ ```bash
17
+ chef gem install knife-rackspace
18
+ ```
19
+
20
+ ## Configuration
21
+
22
+ In order to communicate with the Rackspace Cloud API you will have to tell Knife about your Username and API Key. The easiest way to accomplish this is to create some entries in your knife.rb file:
23
+
24
+ ```ruby
25
+ knife[:rackspace_api_username] = "Your Rackspace API username"
26
+ knife[:rackspace_api_key] = "Your Rackspace API Key"
27
+ ```
28
+
29
+ If your knife.rb file will be checked into a SCM system (ie readable by others) you may want to read the values from environment variables:
30
+
31
+ ```ruby
32
+ knife[:rackspace_api_username] = "#{ENV['RACKSPACE_USERNAME']}"
33
+ knife[:rackspace_api_key] = "#{ENV['RACKSPACE_API_KEY']}"
34
+ ```
35
+
36
+ You also have the option of passing your Rackspace API Username/Key into the individual knife subcommands using the **-A** (or **--rackspace-api-username**) **-K** (or **--rackspace-api-key**) command options
37
+
38
+ ```
39
+ # provision a new 1GB Ubuntu 10.04 webserver
40
+ knife rackspace server create -I 112 -f 3 -A 'Your Rackspace API username' -K "Your Rackspace API Key" -r 'role[webserver]'
41
+ ```
42
+
43
+ To select for the previous Rackspace API (aka 'v1'), you can use the **--rackspace-version v1** command option. 'v2' is the default, so if you're still using exclusively 'v1' you will probably want to add the following to your knife.rb:
44
+
45
+ ```ruby
46
+ knife[:rackspace_version] = 'v1'
47
+ ```
48
+
49
+ 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 knife.rb:
50
+
51
+ ```ruby
52
+ knife[:rackspace_auth_url] = "auth.my-custom-endpoint.com"
53
+ ```
54
+
55
+ 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.
56
+
57
+ If you are behind a proxy you can specify it in the knife.rb file as follows:
58
+
59
+ ```ruby
60
+ https_proxy https://PROXY_IP_ADDRESS:PORT
61
+ ```
62
+
63
+ SSL certificate verification can be disabled by include the following in your knife.rb file:
64
+
65
+ ```ruby
66
+ knife[:ssl_verify_peer] = false
67
+ ```
68
+
69
+ Additionally the following options may be set in your knife.rb:
70
+
71
+ - flavor
72
+ - image
73
+ - distro
74
+ - template_file
75
+
76
+ ## Knife Sub Commands
77
+
78
+ This plugin provides the following Knife subcommands. Specific command options can be found by invoking the subcommand with a --help flag
79
+
80
+ ### knife rackspace server create
81
+
82
+ Provisions a new server in the Rackspace Cloud and then perform a Chef bootstrap (using the SSH protocol). The goal of the bootstrap is to get Chef installed on the target system so it can run Chef Client with a Chef Server. The main assumption is a baseline OS installation exists (provided by the provisioning). It is primarily intended for Chef Client systems that talk to a Chef server. By default the server is bootstrapped using the {chef-full}[<https://github.com/opscode/chef/blob/master/chef/lib/chef/knife/bootstrap/chef-full.erb>] template. This can be overridden using the **-d** or **--template-file** command options.
83
+
84
+ If no name is provided, nodes created with the v1 API are named after their instance ID, with the v2 API they are given a random 'rs-XXXXXXXXX' name.
85
+
86
+ Files can be injected onto the provisioned system using the **--file** switch. For example to inject my_script.sh into **/root/initialize.sh** you would use the following switch: **--file /root/initialize.sh=my_script.sh**
87
+
88
+ Note: You can only inject text files and the maximum destination path is 255 characters.
89
+
90
+ You may specify if want to manage your disk partitioning scheme with the **--rackspace-disk-config DISKCONFIG** option. If you bootstrap a `v2` node and leave this set to the default "AUTO", larger nodes take longer to bootstrap as it grows the disk from 10G to fill the full amount of local disk provided. This option allows you to pass "MANUAL" - which give you a node (in 1/2 to 1/4 of the time) and lets you manage ignoring, or formatting the rest of the disk on your own.
91
+
92
+ <http://docs.openstack.org/essex/openstack-compute/starter/content/Launch_and_manage_instances-d1e1885.html>
93
+
94
+ You may specify a custom network using the **--network [LABEL_OR_ID]** option. You can also remove the default internal ServiceNet and PublicNet networks by specifying the **--no-default-networks** switch. To use a network other than PublicNet for the bootstrap connection, specify the **--bootstrap-network LABEL** option.
95
+
96
+ Note: If you are using one of the `performanceX-X` machines, you need to put **-f** or **--flavor** in quotes.
97
+
98
+ #### Windows
99
+
100
+ Windows Servers require special treatment with the knife-rackspace gem.
101
+
102
+ First, you'll need to ensure you've installed the knife-windows gem. Installation instructions can be found over here: <http://docs.chef.io/plugin_knife_windows.html#install-this-plugin>
103
+
104
+ Secondly, you need to make sure that the image you're using has WinRM pre-configured. Unfortunately, none of the Rackspace Windows image have this done by default, so you'll need to run the following instructions in a Windows machine, then save a Snapshot to use when creating servers with knife rackspace: <http://docs.chef.io/plugin_knife_windows.html#requirements>
105
+
106
+ Thirdly, you must pass **--bootstrap-protocol winrm** and **--distro windows-chef-client-msi** parameters to the knife rackspace create command
107
+
108
+ If you have troubles, make sure you add the **-VV** switch for extra verbosity. The **--server-create-timeout** switch may also be your friend, as Windows machines take a long time to build compared to Linux ones.
109
+
110
+ ### knife rackspace server delete
111
+
112
+ Deletes an existing server in the currently configured Rackspace Cloud account by the server/instance id. You can find the instance id by entering **knife rackspace server list**. Please note - this does not delete the associated node and client objects from the Chef server unless you pass the **-P** or **--purge** command option. Using the **--purge** option with v2 nodes will attempt to delete the node and client by the name of the node.
113
+
114
+ ### knife rackspace server list
115
+
116
+ Outputs a list of all servers in the currently configured Rackspace Cloud account. Please note - this shows all instances associated with the account, some of which may not be currently managed by the Chef server. You may need to use the **--rackspace-version** and **--rackspace-region** options to see nodes in different Rackspace regions.
117
+
118
+ ### knife rackspace flavor list
119
+
120
+ Outputs a list of all available flavors (available hardware configuration for a server) available to the currently configured Rackspace Cloud account. Each flavor has a unique combination of disk space, memory capacity and priority for CPU time. This data can be useful when choosing a flavor id to pass to the **knife rackspace server create** subcommand. You may need to use the **--rackspace-version** and **--rackspace-region** options to see nodes in different Rackspace regions.
121
+
122
+ ### knife rackspace image list
123
+
124
+ Outputs a list of all available images available to the currently configured Rackspace Cloud account. An image is a collection of files used to create or rebuild a server. Rackspace provides a number of pre-built OS images by default. This data can be useful when choosing an image id to pass to the **knife rackspace server create** subcommand. You may need to use the **--rackspace-version** and **--rackspace-region** options to see nodes in different Rackspace regions.
125
+
126
+ ### knife rackspace network list
127
+
128
+ Outputs a list of available networks to the currently configured Rackspace Cloud account. Networks can be added at a server during the creation process using the **--network [LABEL_OR_ID]** option. Knife does not currently support adding a network to an existing server.
129
+
130
+ ### knife rackspace network create
131
+
132
+ Creates a new cloud network. Both the label and the CIDR are required parameters which are specified using the **--label LABEL** and **--cidr CIDR**
133
+
134
+ respectively. The CIDR should be in the form of 172.16.0.0/24 or 2001:DB8::/64\. Refer to <http://www.rackspace.com/knowledge_center/article/using-cidr-notation-in-cloud-networks> for more information.
135
+
136
+ ### knife rackspace network delete
137
+
138
+ Deletes one or more specified networks by id. The network must be detached from all hosts before it is deleted.
139
+
140
+ ### Knife & Rackspace Rackconnect
141
+
142
+ Rackspace Rackconnect allows the creation of a hybrid setup where you can have Cloud servers which are connected to bare metal hardware like Firewalls and Load balancers. You can read more about this product at <http://www.rackspace.com/cloud/hybrid/rackconnect/>
143
+
144
+ Under the hood, this changes the behavior of how the cloud servers are configured and how IP addresses are assigned to them. So when using knife-rackspace with a 'Rack connected' cloud account you need use some additional parameters. See the sections below for more information regarding the two versions of Rack Connect.
145
+
146
+ Note: If you account is leveraging private cloud networks for Rackconnnect then you are using Rackconnect v3\. You can also find your version of Rackconnect by checking with your support team
147
+
148
+ #### Knife and Rackconnect version 2
149
+
150
+ ```
151
+ knife rackspace server create \
152
+ --server-name <name of the server> \
153
+ --image <Rackspace image id> \
154
+ --flavor <Rackspace flavor id> \
155
+ -r 'role[base]' \
156
+ --rackconnect-wait
157
+ ```
158
+
159
+ Note: If the server is also part of Rackspace Managed Operations service level you will need to add the
160
+
161
+ **--rackspace-servicelevel-wait** option.
162
+
163
+ ```
164
+ knife rackspace server create \
165
+ --server-name <name of the server> \
166
+ --image <Rackspace image id> \
167
+ --flavor <Rackspace flavor id> \
168
+ -r 'role[base]' \
169
+ --rackconnect-wait \
170
+ --rackspace-servicelevel-wait
171
+ ```
172
+
173
+ **--rackconnect-wait** does the following:
174
+
175
+ - Rackconnect version 2 changes the networking on the cloud server and forces all trafic to route via the dedicated firewall or load balancer. It also then assigns the cloud server a new public IP address. The status of this automation provided by updates to the cloud server metadata. This option makes Knife wait for the Rackconnect automation to complete by checking the metadata.
176
+
177
+ - Once the status is updated, it triggers the bootstrap process.
178
+
179
+ **--rackspace-servicelevel-wait** does the following:
180
+
181
+ - For Cloud servers in the Managed operations service level, Rackspace installs additional agents and software which enables them to provide support. This automation. like the Rackconnect one, updates the cloud server metadata of its status. Likewise, using this option, makes knife wait till the automation is complete before triggering the bootstrap process.
182
+
183
+ #### Knife and Rackconnect version 3
184
+
185
+ In case of version 3, there is a different command line option.
186
+
187
+ ```
188
+ knife rackspace server create \
189
+ --server-name <name of the server> \
190
+ --image <Rackspace image id> \
191
+ --flavor <Rackspace flavor id> \
192
+ -r 'role[base]' \
193
+ --rackconnect-v3-network-id <cloud network id>
194
+ ```
195
+
196
+ **--rackconnect-v3-network-id** does the following :-
197
+
198
+ - Create the server with the corresponding cloud network. The network id the id of an existing cloud network.
199
+ - Knife will then issue additional API calls to the Rackconnect API to assign a new public IP to the cloud server. The new IP is also stored in the Cloud Server Metadata under accessv4IP.
200
+ - Knife then waits for the IP to be provisioned before triggering the bootstrap process.
201
+
202
+ Functionally, this operates the same way as version 2\. However, behind the scenes, Rackconnect v3 is significantly different in implementation. You can learn about the differences here : <http://www.rackspace.com/knowledge_center/article/comparing-rackconnect-v30-and-rackconnect-v20>
203
+
204
+ ## Contributing
205
+
206
+ For information on contributing to this project see <https://github.com/chef/chef/blob/master/CONTRIBUTING.md>
207
+
208
+ ## License and Authors
209
+
210
+ ```text
211
+ Author:: Adam Jacob (<adam@chef.io>)
212
+ Author:: Seth Chisamore (<schisamo@chef.io>)
213
+ Author:: Matt Ray (<matt@chef.io>)
214
+ Author:: JJ Asghar (<jj@chef.io>)
215
+ Author:: Rackspace Developers
216
+ Copyright:: Copyright (c) 2019-2016 Chef Software, Inc.
217
+ License:: Apache License, Version 2.0
218
+
219
+ Licensed under the Apache License, Version 2.0 (the "License");
220
+ you may not use this file except in compliance with the License.
221
+ You may obtain a copy of the License at
222
+
223
+ http://www.apache.org/licenses/LICENSE-2.0
224
+
225
+ Unless required by applicable law or agreed to in writing, software
226
+ distributed under the License is distributed on an "AS IS" BASIS,
227
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
228
+ See the License for the specific language governing permissions and
229
+ limitations under the License.
230
+ ```
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Author:: Daniel DeLeo (<dan@opscode.com>)
4
- # Copyright:: Copyright (c) 2008, 2010 Opscode, Inc.
2
+ # Author:: Adam Jacob (<adam@chef.io>)
3
+ # Author:: Daniel DeLeo (<dan@chef.io>)
4
+ # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
5
5
  # License:: Apache License, Version 2.0
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,35 +17,35 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require 'bundler'
20
+ require "bundler"
21
21
  Bundler::GemHelper.install_tasks
22
22
 
23
- require 'rspec/core/rake_task'
23
+ require "rspec/core/rake_task"
24
24
  RSpec::Core::RakeTask.new(:spec)
25
- task :default => [:credentials, :spec, 'integration:live']
25
+ task :default => [:credentials, :spec, "integration:live"]
26
26
 
27
27
  task :credentials do
28
- if ENV['TRAVIS_SECURE_ENV_VARS'] == 'false'
28
+ if ENV["TRAVIS_SECURE_ENV_VARS"] == "false"
29
29
  puts "Setting vars"
30
- ENV['OS_USERNAME'] = '_RAX_USERNAME_'
31
- ENV['OS_PASSWORD'] = '_RAX_PASSWORD_'
32
- ENV['RS_TENANT_ID'] = '000000'
33
- ENV['RS_CDN_TENANT_NAME'] = '_CDN-TENANT-NAME_'
30
+ ENV["OS_USERNAME"] = "_RAX_USERNAME_"
31
+ ENV["OS_PASSWORD"] = "_RAX_PASSWORD_"
32
+ ENV["RS_TENANT_ID"] = "000000"
33
+ ENV["RS_CDN_TENANT_NAME"] = "_CDN-TENANT-NAME_"
34
34
  end
35
- fail "Not all required variables detected" unless ENV['OS_USERNAME'] && ENV['OS_PASSWORD'] && ENV['RS_CDN_TENANT_NAME'] && ENV['RS_TENANT_ID']
35
+ raise "Not all required variables detected" unless ENV["OS_USERNAME"] && ENV["OS_PASSWORD"] && ENV["RS_CDN_TENANT_NAME"] && ENV["RS_TENANT_ID"]
36
36
  end
37
37
 
38
38
  namespace :integration do
39
- desc 'Run the integration tests'
39
+ desc "Run the integration tests"
40
40
  RSpec::Core::RakeTask.new(:test) do |t|
41
- t.pattern = 'spec/integration/**'
41
+ t.pattern = "spec/integration/**"
42
42
  end
43
43
 
44
- desc 'Run the integration tests live (no VCR cassettes)'
44
+ desc "Run the integration tests live (no VCR cassettes)"
45
45
  task :live do
46
- unless ENV['TRAVIS'] == 'true' && ENV['TRAVIS_SECURE_ENV_VARS'] == 'false'
47
- ENV['INTEGRATION_TESTS'] = 'live'
48
- Rake::Task['integration:test'].invoke
46
+ unless ENV["TRAVIS"] == "true" && ENV["TRAVIS_SECURE_ENV_VARS"] == "false"
47
+ ENV["INTEGRATION_TESTS"] = "live"
48
+ Rake::Task["integration:test"].invoke
49
49
  end
50
50
  end
51
51
  end
@@ -6,24 +6,19 @@ Gem::Specification.new do |s|
6
6
  s.name = "knife-rackspace"
7
7
  s.version = Knife::Rackspace::VERSION
8
8
  s.has_rdoc = true
9
- s.authors = ["Adam Jacob","Seth Chisamore", "Matt Ray","Rackspace Developers","JJ Asghar"]
10
- s.email = ["adam@chef.io","schisamo@chef.io", "matt@chef.io","jj@chef.io"]
11
- s.homepage = "https://docs.chef.io/plugin_knife_rackspace.html"
9
+ s.authors = ["Adam Jacob", "Seth Chisamore", "Matt Ray", "Rackspace Developers", "JJ Asghar"]
10
+ s.email = ["adam@chef.io", "schisamo@chef.io", "matt@chef.io", "jj@chef.io"]
11
+ s.homepage = "https://github.com/chef/knife-rackspace"
12
12
  s.summary = "Rackspace Support for Chef's Knife Command"
13
13
  s.description = s.summary
14
- s.extra_rdoc_files = ["README.rdoc", "LICENSE" ]
14
+ s.extra_rdoc_files = ["README.md", "LICENSE" ]
15
15
 
16
+ s.required_ruby_version = ">= 2.2.2"
16
17
  s.files = `git ls-files`.split("\n")
17
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
19
20
  s.add_dependency "knife-windows"
20
- s.add_dependency "fog", '>= 1.24'
21
- s.add_dependency "chef", ">= 0.10.10"
21
+ s.add_dependency "fog-rackspace", ">= 0.1"
22
+ s.add_dependency "chef", ">= 12.0"
22
23
  s.require_paths = ["lib"]
23
-
24
- s.add_development_dependency "knife-dsl"
25
- s.add_development_dependency "rspec"
26
- s.add_development_dependency "vcr"
27
- s.add_development_dependency "ansi"
28
- s.add_development_dependency "rake"
29
24
  end
@@ -1,6 +1,6 @@
1
1
  #
2
- # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
- # Copyright:: Copyright (c) 2011-2013 Opscode, Inc.
2
+ # Author:: Seth Chisamore (<schisamo@chef.io>)
3
+ # Copyright:: Copyright (c) 2011-2016 Chef Software, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,8 +16,8 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef/knife'
20
- require 'fog'
19
+ require "chef/knife"
20
+ require "fog/rackspace"
21
21
 
22
22
  class Chef
23
23
  class Knife
@@ -30,10 +30,10 @@ class Chef
30
30
  includer.class_eval do
31
31
 
32
32
  deps do
33
- require 'fog'
34
- require 'net/ssh/multi'
35
- require 'readline'
36
- require 'chef/json_compat'
33
+ require "fog/rackspace"
34
+ require "net/ssh/multi"
35
+ require "readline"
36
+ require "chef/json_compat"
37
37
  end
38
38
 
39
39
  option :rackspace_api_key,
@@ -49,8 +49,8 @@ class Chef
49
49
  :proc => Proc.new { |username| Chef::Config[:knife][:rackspace_username] = username }
50
50
 
51
51
  option :rackspace_version,
52
- :long => '--rackspace-version VERSION',
53
- :description => 'Rackspace Cloud Servers API version',
52
+ :long => "--rackspace-version VERSION",
53
+ :description => "Rackspace Cloud Servers API version",
54
54
  :default => "v2",
55
55
  :proc => Proc.new { |version| Chef::Config[:knife][:rackspace_version] = version }
56
56
 
@@ -65,8 +65,8 @@ class Chef
65
65
  :proc => Proc.new { |region| Chef::Config[:knife][:rackspace_region] = region }
66
66
 
67
67
  option :file,
68
- :long => '--file DESTINATION-PATH=SOURCE-PATH',
69
- :description => 'File to inject on node',
68
+ :long => "--file DESTINATION-PATH=SOURCE-PATH",
69
+ :description => "File to inject on node",
70
70
  :proc => Proc.new {|arg|
71
71
  Chef::Config[:knife][:file] ||= []
72
72
  Chef::Config[:knife][:file] << arg
@@ -77,58 +77,72 @@ class Chef
77
77
  def connection
78
78
  Chef::Log.debug("version #{Chef::Config[:knife][:rackspace_version]} (config)")
79
79
  Chef::Log.debug("version #{config[:rackspace_version]} (cli)")
80
- Chef::Log.debug("rackspace_api_key #{Chef::Config[:knife][:rackspace_api_key]}")
81
- Chef::Log.debug("rackspace_username #{Chef::Config[:knife][:rackspace_username]}")
82
- Chef::Log.debug("rackspace_api_username #{Chef::Config[:knife][:rackspace_api_username]}")
83
- Chef::Log.debug("rackspace_auth_url #{Chef::Config[:knife][:rackspace_auth_url]}")
84
- Chef::Log.debug("rackspace_auth_url #{config[:rackspace_api_auth_url]}")
80
+ Chef::Log.debug("rackspace_api_key #{Chef::Config[:knife][:rackspace_api_key]} (config)")
81
+ Chef::Log.debug("rackspace_api_key #{config[:rackspace_api_key]} (cli)")
82
+ Chef::Log.debug("rackspace_username #{Chef::Config[:knife][:rackspace_username]} (config)")
83
+ Chef::Log.debug("rackspace_username #{config[:rackspace_username]} (cli)")
84
+ Chef::Log.debug("rackspace_api_username #{Chef::Config[:knife][:rackspace_api_username]} (config)")
85
+ Chef::Log.debug("rackspace_api_username #{config[:rackspace_api_username]} (cli)")
86
+ Chef::Log.debug("rackspace_auth_url #{Chef::Config[:knife][:rackspace_auth_url]} (config)")
87
+ Chef::Log.debug("rackspace_auth_url #{config[:rackspace_api_auth_url]} (cli)")
85
88
  Chef::Log.debug("rackspace_auth_url #{auth_endpoint} (using)")
86
- Chef::Log.debug("rackspace_region #{Chef::Config[:knife][:rackspace_region]}")
87
- Chef::Log.debug("rackspace_region #{config[:rackspace_region]}")
89
+ Chef::Log.debug("rackspace_region #{Chef::Config[:knife][:rackspace_region]} (config)")
90
+ Chef::Log.debug("rackspace_region #{config[:rackspace_region]} (cli)")
88
91
 
89
92
  if version_one?
90
93
  Chef::Log.debug("rackspace v1")
91
94
  region_warning_for_v1
92
95
  @connection ||= begin
93
96
  connection = Fog::Compute.new(connection_params({
94
- :version => 'v1'
97
+ :version => "v1",
95
98
  }))
96
99
  end
97
100
  else
98
101
  Chef::Log.debug("rackspace v2")
99
102
  @connection ||= begin
100
103
  connection = Fog::Compute.new(connection_params({
101
- :version => 'v2'
104
+ :version => "v2",
102
105
  }))
103
106
  end
104
107
  end
105
108
  end
106
109
 
107
110
  def region_warning_for_v1
108
- if Chef::Config[:knife][:rackspace_region] || config[:rackspace_region]
111
+ if locate_config_value(:rackspace_region)
109
112
  Chef::Log.warn("Ignoring the rackspace_region parameter as it is only supported for Next Gen Cloud Servers (v2)")
110
113
  end
111
114
  end
112
115
 
113
- def connection_params(options={})
116
+ def connection_params(options = {})
114
117
  unless locate_config_value(:rackspace_region)
115
118
  ui.error "Please specify region via the command line using the --rackspace-region switch or add a knife[:rackspace_region] = REGION to your knife file."
116
119
  exit 1
117
120
  end
118
121
 
122
+ username = locate_config_value(:rackspace_username) || locate_config_value(:rackspace_api_username)
123
+ unless username
124
+ ui.error "Please specify an api username via the command line using the --rackspace-username switch or add a knife[:rackspace_username] = USERNAME to your knife file."
125
+ exit 1
126
+ end
127
+
128
+ unless locate_config_value(:rackspace_api_key)
129
+ ui.error "Please specify an api key via the command line using the --rackspace-api-key switch or add a knife[:rackspace_api_key] = USERNAME to your knife file."
130
+ exit 1
131
+ end
132
+
119
133
  hash = options.merge({
120
- :provider => 'Rackspace',
121
- :rackspace_api_key => Chef::Config[:knife][:rackspace_api_key],
122
- :rackspace_username => (Chef::Config[:knife][:rackspace_username] || Chef::Config[:knife][:rackspace_api_username]),
134
+ :provider => "Rackspace",
135
+ :rackspace_api_key => locate_config_value(:rackspace_api_key),
136
+ :rackspace_username => username,
123
137
  :rackspace_auth_url => auth_endpoint,
124
- :rackspace_region => locate_config_value(:rackspace_region)
138
+ :rackspace_region => locate_config_value(:rackspace_region),
125
139
  })
126
140
 
127
141
  hash[:connection_options] ||= {}
128
142
  Chef::Log.debug("https_proxy #{ Chef::Config[:https_proxy] || "<not specified>"} (config)")
129
143
  Chef::Log.debug("http_proxy #{ Chef::Config[:http_proxy] || "<not specified>"} (config)")
130
144
  if Chef::Config.has_key?(:https_proxy) || Chef::Config.has_key?(:http_proxy)
131
- hash[:connection_options] = {:proxy => Chef::Config[:https_proxy] || Chef::Config[:http_proxy] }
145
+ hash[:connection_options] = { :proxy => Chef::Config[:https_proxy] || Chef::Config[:http_proxy] }
132
146
  end
133
147
  Chef::Log.debug("using proxy #{hash[:connection_options][:proxy] || "<none>"} (config)")
134
148
  Chef::Log.debug("ssl_verify_peer #{Chef::Config[:knife].has_key?(:ssl_verify_peer) ? Chef::Config[:knife][:ssl_verify_peer] : "<not specified>"} (config)")
@@ -140,7 +154,7 @@ class Chef
140
154
  def auth_endpoint
141
155
  url = locate_config_value(:rackspace_auth_url)
142
156
  return url if url
143
- (locate_config_value(:rackspace_region) == 'lon') ? ::Fog::Rackspace::UK_AUTH_ENDPOINT : ::Fog::Rackspace::US_AUTH_ENDPOINT
157
+ (locate_config_value(:rackspace_region) == "lon") ? ::Fog::Rackspace::UK_AUTH_ENDPOINT : ::Fog::Rackspace::US_AUTH_ENDPOINT
144
158
  end
145
159
 
146
160
  def locate_config_value(key)
@@ -148,21 +162,21 @@ class Chef
148
162
  Chef::Config[:knife][key] || config[key]
149
163
  end
150
164
 
151
- def msg_pair(label, value, color=:cyan)
165
+ def msg_pair(label, value, color = :cyan)
152
166
  if value && !value.to_s.empty?
153
167
  puts "#{ui.color(label, color)}: #{value}"
154
168
  end
155
169
  end
156
170
 
157
- def ip_address(server, network='public')
171
+ def ip_address(server, network = "public")
158
172
  if version_one?
159
173
  case network
160
- when 'public'; v1_public_ip(server)
161
- when 'private'; v1_private_ip(server)
174
+ when "public" then v1_public_ip(server)
175
+ when "private" then v1_private_ip(server)
162
176
  else raise NotImplementedError
163
177
  end
164
178
  else
165
- if network == 'public' && v2_access_ip(server) != ""
179
+ if network == "public" && v2_access_ip(server) != ""
166
180
  v2_access_ip(server)
167
181
  else
168
182
  v2_ip_address(server, network)
@@ -171,7 +185,7 @@ class Chef
171
185
  end
172
186
 
173
187
  def public_dns_name(server)
174
- if public_ip_address = ip_address(server, 'public')
188
+ if public_ip_address = ip_address(server, "public")
175
189
  @public_dns_name ||= begin
176
190
  Resolv.getname(public_ip_address)
177
191
  rescue
@@ -183,11 +197,11 @@ class Chef
183
197
  private
184
198
 
185
199
  def version_one?
186
- rackspace_api_version == 'v1'
200
+ rackspace_api_version == "v1"
187
201
  end
188
202
 
189
203
  def rackspace_api_version
190
- version = locate_config_value(:rackspace_version) || 'v2'
204
+ version = locate_config_value(:rackspace_version) || "v2"
191
205
  version.downcase
192
206
  end
193
207