knife-bluebox 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +9 -0
- data/lib/chef/knife/bluebox_image_create.rb +66 -0
- data/lib/chef/knife/bluebox_image_delete.rb +55 -0
- data/lib/chef/knife/{bluebox_images_list.rb → bluebox_image_list.rb} +7 -7
- data/lib/chef/knife/bluebox_server_create.rb +26 -13
- data/lib/knife-bluebox/version.rb +1 -1
- metadata +5 -3
data/README.rdoc
CHANGED
@@ -15,9 +15,18 @@ Set the following environmental variables
|
|
15
15
|
export BLUEBOX_API_KEY="YourAPIKey" # should match /[a-f0-9]+/
|
16
16
|
export BLUEBOX_CUSTOMER_ID="YourCustomerNumber" # should match /d+/
|
17
17
|
|
18
|
+
Then add the following lines to <chef-repo-root>/.chef/knife.rb
|
19
|
+
|
20
|
+
# API credentials for knife-bluebox
|
21
|
+
knife[:bluebox_customer_id] = ENV['BLUEBOX_CUSTOMER_ID']
|
22
|
+
knife[:bluebox_api_key] = ENV['BLUEBOX_API_KEY']
|
23
|
+
knife[:identity_file] = "#{ENV['HOME']}/.ssh/id_rsa"
|
24
|
+
knife[:public_identity_file] = "#{ENV['HOME']}/.ssh/id_rsa.pub"
|
25
|
+
|
18
26
|
== Usage
|
19
27
|
knife bluebox images list
|
20
28
|
knife bluebox server create [RUN LIST...] (options)
|
21
29
|
knife bluebox server delete BLOCK-HOSTNAME
|
22
30
|
knife bluebox server list (options)
|
23
31
|
|
32
|
+
You will need to run knife from within your chef-repo to have the knife.rb config take effect.
|
@@ -0,0 +1,66 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Jesse Proudman (<jesse.proudman@blueboxgrp.com>)
|
3
|
+
# Copyright:: Copyright (c) 2010 Blue Box Group
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/knife'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Knife
|
23
|
+
class BlueboxImageCreate < Knife
|
24
|
+
|
25
|
+
deps do
|
26
|
+
require 'fog'
|
27
|
+
require 'highline'
|
28
|
+
require 'chef/json_compat'
|
29
|
+
end
|
30
|
+
|
31
|
+
banner "knife bluebox image create [uuid]"
|
32
|
+
|
33
|
+
option :description,
|
34
|
+
:short => '-d DESCRIPTION',
|
35
|
+
:long => '--description DESCRIPTION',
|
36
|
+
:description => 'The description to give the created image. Defaults to Hostname and Timestamp'
|
37
|
+
|
38
|
+
option :public,
|
39
|
+
:short => '-p',
|
40
|
+
:long => '--public',
|
41
|
+
:description => 'Makes the image public so that anyone can deploy from it',
|
42
|
+
:boolean => true
|
43
|
+
|
44
|
+
def highline
|
45
|
+
@highline ||= HighLine.new
|
46
|
+
end
|
47
|
+
|
48
|
+
def run
|
49
|
+
bluebox,image,create = ARGV.shift, ARGV.shift, ARGV.shift
|
50
|
+
bluebox = Fog::Compute::Bluebox.new(
|
51
|
+
:bluebox_customer_id => Chef::Config[:knife][:bluebox_customer_id],
|
52
|
+
:bluebox_api_key => Chef::Config[:knife][:bluebox_api_key]
|
53
|
+
)
|
54
|
+
|
55
|
+
config[:public] ||= false
|
56
|
+
config[:block_id] ||= ARGV.shift
|
57
|
+
|
58
|
+
image = bluebox.images.new(config)
|
59
|
+
|
60
|
+
response = image.save
|
61
|
+
|
62
|
+
puts response
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Jesse Proudman (<jesse.proudman@blueboxgrp.com>)
|
3
|
+
# Copyright:: Copyright (c) 2010 Blue Box Group
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/knife'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Knife
|
23
|
+
class BlueboxImageDelete < Knife
|
24
|
+
|
25
|
+
deps do
|
26
|
+
require 'fog'
|
27
|
+
require 'highline'
|
28
|
+
require 'chef/json_compat'
|
29
|
+
end
|
30
|
+
|
31
|
+
banner "knife bluebox image delete [UUID]"
|
32
|
+
|
33
|
+
def highline
|
34
|
+
@highline ||= HighLine.new
|
35
|
+
end
|
36
|
+
|
37
|
+
def run
|
38
|
+
bluebox,image,delete = ARGV.shift, ARGV.shift, ARGV.shift
|
39
|
+
bluebox = Fog::Compute::Bluebox.new(
|
40
|
+
:bluebox_customer_id => Chef::Config[:knife][:bluebox_customer_id],
|
41
|
+
:bluebox_api_key => Chef::Config[:knife][:bluebox_api_key]
|
42
|
+
)
|
43
|
+
image_uuid = ARGV.shift
|
44
|
+
|
45
|
+
image = bluebox.images.get( image_uuid )
|
46
|
+
|
47
|
+
if image
|
48
|
+
puts image.destroy
|
49
|
+
else
|
50
|
+
ui.error("Image: #{image_uuid} could not be found")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -6,9 +6,9 @@
|
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
8
8
|
# You may obtain a copy of the License at
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# Unless required by applicable law or agreed to in writing, software
|
13
13
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
14
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -20,7 +20,7 @@ require 'chef/knife'
|
|
20
20
|
|
21
21
|
class Chef
|
22
22
|
class Knife
|
23
|
-
class
|
23
|
+
class BlueboxImageList < Knife
|
24
24
|
|
25
25
|
deps do
|
26
26
|
require 'fog'
|
@@ -28,7 +28,7 @@ class Chef
|
|
28
28
|
require 'chef/json_compat'
|
29
29
|
end
|
30
30
|
|
31
|
-
banner "knife bluebox
|
31
|
+
banner "knife bluebox image list"
|
32
32
|
|
33
33
|
def highline
|
34
34
|
@highline ||= HighLine.new
|
@@ -44,9 +44,9 @@ class Chef
|
|
44
44
|
|
45
45
|
image_list = [ highline.color('ID', :bold), highline.color('Name', :bold) ]
|
46
46
|
|
47
|
-
bluebox.images.each do |
|
48
|
-
image_list <<
|
49
|
-
image_list <<
|
47
|
+
bluebox.images.each do |image|
|
48
|
+
image_list << image.id.to_s
|
49
|
+
image_list << image.description
|
50
50
|
end
|
51
51
|
puts highline.list(image_list, :columns_across, 2)
|
52
52
|
|
@@ -60,8 +60,7 @@ class Chef
|
|
60
60
|
option :password,
|
61
61
|
:short => "-P password",
|
62
62
|
:long => "--password password",
|
63
|
-
:description => "User password on new server."
|
64
|
-
:default => ""
|
63
|
+
:description => "User password on new server."
|
65
64
|
|
66
65
|
option :disable_bootstrap,
|
67
66
|
:long => "--disable-bootstrap",
|
@@ -76,8 +75,13 @@ class Chef
|
|
76
75
|
|
77
76
|
option :identity_file,
|
78
77
|
:short => "-I IDENTITY_FILE",
|
79
|
-
:long => "--identity-file
|
80
|
-
:description => "The SSH identity file used for authentication"
|
78
|
+
:long => "--identity-file PRIVATE_IDENTITY_FILE",
|
79
|
+
:description => "The private SSH identity file used for authentication to the new server"
|
80
|
+
|
81
|
+
option :public_identity_file,
|
82
|
+
:short => "-B PUBLIC_IDENTITY_FILE",
|
83
|
+
:long => "--public-identity-file PUBLIC_IDENTITY_FILE",
|
84
|
+
:description => "The public SSH identity file used for authentication to new server"
|
81
85
|
|
82
86
|
option :load_balancer,
|
83
87
|
:short => "-b LB",
|
@@ -96,12 +100,20 @@ class Chef
|
|
96
100
|
def run
|
97
101
|
$stdout.sync = true
|
98
102
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
103
|
+
public_key = config[:public_identity_file] || Chef::Config[:knife][:public_identity_file]
|
104
|
+
identity_file = config[:identity_file] || Chef::Config[:knife][:identity_file]
|
105
|
+
|
106
|
+
if config[:password].nil?
|
107
|
+
|
108
|
+
if !public_key
|
109
|
+
ui.error('Since no password was provided a public_identity_file needs to be set.')
|
110
|
+
exit 1
|
111
|
+
end
|
112
|
+
|
113
|
+
if !identity_file
|
114
|
+
ui.error('Since no password was provided an identity_file needs to be set.')
|
115
|
+
exit 1
|
116
|
+
end
|
105
117
|
end
|
106
118
|
|
107
119
|
bluebox = Fog::Compute::Bluebox.new(
|
@@ -120,7 +132,7 @@ class Chef
|
|
120
132
|
:hostname => config[:chef_node_name],
|
121
133
|
:username => Chef::Config[:knife][:username] || config[:username],
|
122
134
|
:password => config[:password],
|
123
|
-
:public_key => public_key,
|
135
|
+
:public_key => File.read(public_key),
|
124
136
|
:lb_applications => Chef::Config[:knife][:load_balancer] || config[:load_balancer]
|
125
137
|
)
|
126
138
|
|
@@ -166,13 +178,14 @@ class Chef
|
|
166
178
|
bootstrap = Chef::Knife::Bootstrap.new
|
167
179
|
bootstrap.name_args = [ server.ips[0]['address'] ]
|
168
180
|
bootstrap.config[:run_list] = run_list
|
169
|
-
bootstrap.config[:
|
181
|
+
bootstrap.config[:ssh_password] = config[:password]
|
170
182
|
bootstrap.config[:ssh_user] = config[:username]
|
171
|
-
bootstrap.config[:identity_file] =
|
183
|
+
bootstrap.config[:identity_file] = identity_file
|
172
184
|
bootstrap.config[:chef_node_name] = config[:chef_node_name] || server.hostname
|
173
185
|
bootstrap.config[:use_sudo] = true
|
174
186
|
bootstrap.config[:distro] = config[:distro]
|
175
187
|
bootstrap.run
|
188
|
+
print "\n#{h.color("Finished bootstrapping #{server.hostname}\n\n", :green)}"
|
176
189
|
rescue Errno::ECONNREFUSED
|
177
190
|
puts h.color("Connection refused on SSH, retrying - CTRL-C to abort")
|
178
191
|
sleep 1
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-bluebox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-02-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: chef
|
@@ -54,7 +54,9 @@ extra_rdoc_files:
|
|
54
54
|
files:
|
55
55
|
- LICENSE
|
56
56
|
- README.rdoc
|
57
|
-
- lib/chef/knife/
|
57
|
+
- lib/chef/knife/bluebox_image_create.rb
|
58
|
+
- lib/chef/knife/bluebox_image_delete.rb
|
59
|
+
- lib/chef/knife/bluebox_image_list.rb
|
58
60
|
- lib/chef/knife/bluebox_server_create.rb
|
59
61
|
- lib/chef/knife/bluebox_server_delete.rb
|
60
62
|
- lib/chef/knife/bluebox_server_list.rb
|