knife-server 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 27f50b0e90320e91ee8aa88d87c08dbf570f856e
4
- data.tar.gz: deabf7cb66885f2566953221cfa843753e6b7aad
3
+ metadata.gz: 7f3438d1a1763d6e1b499924e5d003bbf61bedc1
4
+ data.tar.gz: 7e323fdee09dc509f99116e5ac0dd58e367c885e
5
5
  SHA512:
6
- metadata.gz: ae51fa3de1500febc09772c79edc354db518afb0e42b5c649db0fc7e2e5e3c50517b48c7499c1f5677044c6580ba8319d694f9dfe9cd10a92ef029262efa3962
7
- data.tar.gz: 21b67c8ca3a1e0ce7f54bd600d9a8c9999a711ccfa23c660515403434608efdf73b423b06acf717f0879c20a6987c16ede9da701bd3a5b376df126f50e183a82
6
+ metadata.gz: 1c490bfd6820c94c6e7e3065f36b7265096a81b3474627f92cb253017dc665b66ca90b3f26f5a27a1b717d8d0092ee6d68f3da8366158f8c2d7535aca7dd973d
7
+ data.tar.gz: f53bb247487c0cb4f29e6f7fcab5ca3b0049ece1db8bc7a3ecf36c979a19f467f7a9989fe2d77cb4c3fba3b9e25cd25d7adbca727b86aa073c62fd2b28099600
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 1.3.0 / 2014-09-14
2
+
3
+ ### New features
4
+
5
+ * Pull request [#55][]: Add Digital Ocean support! ([@fnichol][])
6
+
7
+
1
8
  ## 1.2.0 / 2014-09-13
2
9
 
3
10
  ### Upstream changes
@@ -194,6 +201,7 @@ The initial release.
194
201
  [#48]: https://github.com/fnichol/knife-server/issues/48
195
202
  [#50]: https://github.com/fnichol/knife-server/issues/50
196
203
  [#51]: https://github.com/fnichol/knife-server/issues/51
204
+ [#55]: https://github.com/fnichol/knife-server/issues/55
197
205
  [@danryan]: https://github.com/danryan
198
206
  [@dldinternet]: https://github.com/dldinternet
199
207
  [@erikh]: https://github.com/erikh
data/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # <a name="title"></a> Knife::Server
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/knife-server.svg)](http://badge.fury.io/rb/knife-server)
3
4
  [![Build Status](https://secure.travis-ci.org/fnichol/knife-server.png?branch=master)](http://travis-ci.org/fnichol/knife-server)
4
5
  [![Code Climate](https://codeclimate.com/github/fnichol/knife-server.png)](https://codeclimate.com/github/fnichol/knife-server)
6
+ [![Dependency Status](https://gemnasium.com/fnichol/knife-server.png)](https://gemnasium.com/fnichol/knife-server)
5
7
 
6
- An Opscode Chef knife plugin to manage Chef Servers. Bootstrap a new Chef
7
- Server on Amazon's EC2, Linode or a standalone server. Backup and restore
8
- your Chef Server or Hosted Chef's node, role, data bag, and environment JSON
9
- data.
8
+ An Chef Knife plugin to manage Chef Servers. Bootstrap a new Chef
9
+ Server on Amazon's EC2, Digital Ocean, Linode, OpenStack or a standalone server.
10
+ Backup and restore your Chef Server or Hosted Chef's node, role, data bag, and
11
+ environment JSON data.
10
12
 
11
13
  ## <a name="usage"></a> Usage
12
14
 
@@ -37,6 +39,20 @@ $ knife server bootstrap ec2 \
37
39
  --ssh-user ubuntu
38
40
  ```
39
41
 
42
+ To spin up your Chef Server on [Digital Ocean][do_site]:
43
+
44
+ ```bash
45
+ knife server bootstrap digitalocean \
46
+ --node-name chefapalooza.example.com \
47
+ --digital_ocean_client_id $DIGITAL_OCEAN_CLIENT_ID \
48
+ --digital_ocean_api_key $DIGITAL_OCEAN_API_KEY \
49
+ --location 3 \
50
+ --size 63 \
51
+ --image 5588928 \
52
+ --ssh-keys $DIGITAL_OCEAN_SSH_KEY_ID \
53
+ --identity-file ~/.ssh/id_rsa-do
54
+ ```
55
+
40
56
  To spin up your Chef Server on Linode:
41
57
 
42
58
  ```bash
@@ -120,12 +136,15 @@ Add this line to your application's Gemfile:
120
136
  gem 'knife-server'
121
137
  ```
122
138
 
123
- **Note** If you want to use the `bootstrap ec2` or `bootstrap linode`
139
+ **Note** If you want to use the `bootstrap ec2`, `bootstrap digitalocean`,
140
+ `bootstrap linode`, or `bootstrap openstack`
124
141
  subcommands you will need to explicitly add this to your Gemfile with:
125
142
 
126
143
  ```ruby
127
144
  gem 'knife-ec2'
145
+ gem 'knife-digital_ocean'
128
146
  gem 'knife-linode'
147
+ gem 'knife-openstack'
129
148
  ```
130
149
 
131
150
  Finally execute:
@@ -140,8 +159,9 @@ Or install it yourself as:
140
159
  $ gem install knife-server
141
160
  ```
142
161
 
143
- (Don't forget a `gem install knife-ec2` or `gem install knife-linode` if using
144
- the `bootstrap ec2` or `bootstrap linode` subcommands).
162
+ (Don't forget a `gem install knife-ec2`, `gem install knife-digital_ocean`,
163
+ `gem install knife-linode`, or `gem install knife-openstack` if using any
164
+ cloud-specific subcommands).
145
165
 
146
166
  Next, you **must** set up a [knife.rb configuration](#installation-knife) so
147
167
  that the shipped Knife subcommands know where to place and modify key files,
@@ -194,6 +214,10 @@ knife[:flavor] = "t1.micro"
194
214
 
195
215
  # for linode
196
216
  knife[:linode_api_key] = "MY_KEY"
217
+
218
+ # for digitalocean
219
+ knife[:digital_ocean_client_id] = "MY_CLIENT_ID"
220
+ knife[:digital_ocean_api_key] = "MY_KEY"
197
221
  ```
198
222
 
199
223
  Better yet, why not try a more generic [knife.rb][chef_bootstrap_knife_rb] file
@@ -406,22 +430,28 @@ The resulting set will include:
406
430
  * `"Node=#{config[:chef_node_name]}"`
407
431
  * `"Role=chef_server"`
408
432
 
409
- ### <a name="knife-server-bootstrap-linode"></a> knife server bootstrap linode
433
+ ### <a name="knife-server-bootstrap-digitalocean"></a> knife server bootstrap digitalocean
410
434
 
411
- **Note:** You must install the [knife-linode gem][knife-linode] to use this
412
- subcommand. This was done to keep the dependencies of this library lighter and
413
- to make future cloud adapter support easier to add.
435
+ **Note:** You must install the [knife-digital_ocean gem][knife-digital_ocean]
436
+ to use this subcommand. This was done to keep the dependencies of this library
437
+ lighter and to make future cloud adapter support easier to add.
414
438
 
415
- Provisions a Linode instance and sets up an Open Source Chef Server as
439
+ Provisions a Digital Ocean droplet and sets up an Open Source Chef Server as
416
440
  described [above](#knife-server-bootstrap).
417
441
 
418
- ### <a name="knife-server-bootstrap-openstack"></a> knife server bootstrap openstack
442
+ #### Configuration
419
443
 
420
- **Note:** You must install the [knife-openstack gem][knife-openstack] to use this
444
+ This subcommand imports all relavent options from the knife-digital_ocean gem.
445
+ For detailed documentation relating to these options, please visit the [project
446
+ page][knife-digital_ocean].
447
+
448
+ ### <a name="knife-server-bootstrap-linode"></a> knife server bootstrap linode
449
+
450
+ **Note:** You must install the [knife-linode gem][knife-linode] to use this
421
451
  subcommand. This was done to keep the dependencies of this library lighter and
422
452
  to make future cloud adapter support easier to add.
423
453
 
424
- Provisions a Openstack instance and sets up an Open Source Chef Server as
454
+ Provisions a Linode instance and sets up an Open Source Chef Server as
425
455
  described [above](#knife-server-bootstrap).
426
456
 
427
457
  #### Configuration
@@ -478,6 +508,15 @@ password so that you know how to connect later.
478
508
 
479
509
  The default value is a random password.
480
510
 
511
+ ### <a name="knife-server-bootstrap-openstack"></a> knife server bootstrap openstack
512
+
513
+ **Note:** You must install the [knife-openstack gem][knife-openstack] to use this
514
+ subcommand. This was done to keep the dependencies of this library lighter and
515
+ to make future cloud adapter support easier to add.
516
+
517
+ Provisions a Openstack instance and sets up an Open Source Chef Server as
518
+ described [above](#knife-server-bootstrap).
519
+
481
520
  ### <a name="knife-server-bootstrap-standalone"></a> knife server bootstrap standalone
482
521
 
483
522
  Provisions a standalone server that is reachable on the network and sets up
@@ -636,11 +675,13 @@ Apache License, Version 2.0 (see [LICENSE][license])
636
675
  [backup_restore]: https://github.com/stevendanna/knife-hacks/blob/master/plugins/backup_restore.rb
637
676
  [chef_bootstrap_knife_rb]: https://github.com/fnichol/chef-bootstrap-repo/blob/master/.chef/knife.rb
638
677
  [chef_bootstrap_repo]: https://github.com/fnichol/chef-bootstrap-repo/
678
+ [do_site]: https://www.digitalocean.com/
639
679
  [docs_knife]: http://docs.opscode.com/config_rb_knife.html
640
680
  [docs_knife_ec2]: http://docs.opscode.com/plugin_knife_ec2.html
641
681
  [docs_knife_linode]: http://docs.opscode.com/plugin_knife_linode.html
642
682
  [jtimberman]: https://github.com/jtimberman
643
683
  [install_chef]: http://www.opscode.com/chef/install/
684
+ [knife-digital_ocean]: https://github.com/rmoriz/knife-digital_ocean
644
685
  [knife-ec2]: https://github.com/opscode/knife-ec2
645
686
  [knife-linode]: https://github.com/opscode/knife-linode
646
687
  [knife-openstack]: https://github.com/opscode/knife-openstack
data/knife-server.gemspec CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |gem|
23
23
  gem.add_dependency "chef", ">= 0.10.10"
24
24
 
25
25
  gem.add_development_dependency "rake"
26
+ gem.add_development_dependency "knife-digital_ocean"
26
27
  gem.add_development_dependency "knife-ec2", ">= 0.5.12"
27
28
  gem.add_development_dependency "knife-linode"
28
29
  gem.add_development_dependency "knife-openstack"
@@ -0,0 +1,153 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Fletcher Nichol (<fnichol@nichol.ca>)
4
+ # Copyright:: Copyright (c) 2014 Fletcher Nichol
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ require "chef/knife/server_bootstrap_base"
21
+
22
+ class Chef
23
+ class Knife
24
+ # Provisions a Digital Ocean instance and sets up an Open Source Chef
25
+ # Server.
26
+ class ServerBootstrapDigitalocean < Knife
27
+
28
+ banner "knife server bootstrap digitalocean (options)"
29
+
30
+ include Knife::ServerBootstrapBase
31
+
32
+ deps do
33
+ require "knife/server/ssh"
34
+ require "knife/server/credentials"
35
+
36
+ begin
37
+ require "chef/knife/digital_ocean_droplet_create"
38
+ require "fog"
39
+ Chef::Knife::DigitalOceanDropletCreate.load_deps
40
+
41
+ current_options = options
42
+ self.options = Chef::Knife::DigitalOceanDropletCreate.options.dup
43
+ options.merge!(current_options)
44
+ rescue LoadError => ex
45
+ ui.error [
46
+ "Knife plugin knife-digital_ocean could not be loaded.",
47
+ "Please add the knife-digital_ocean gem to your Gemfile or",
48
+ "install the gem manually with `gem install knife-digital_ocean'.",
49
+ "(#{ex.message})"
50
+ ].join(" ")
51
+ exit 1
52
+ end
53
+
54
+ # Monkey patch to prevent Kernel#exit calls at the end of the upstream
55
+ # Knife plugin. Instead, non-zero exits will be raised and zero exits
56
+ # will be ignored ;)
57
+ #
58
+ # rubocop:disable Style/ClassAndModuleChildren
59
+ class ::Chef::Knife::DigitalOceanDropletCreate
60
+ def exit(code)
61
+ if code != 0
62
+ raise "DigitalOceanDropletCreate exited with code: #{code}"
63
+ end
64
+ end
65
+ end
66
+ # rubocop:enable Style/ClassAndModuleChildren
67
+ end
68
+
69
+ option :chef_node_name,
70
+ :short => "-N NAME",
71
+ :long => "--node-name NAME",
72
+ :description => "The Chef node name for your new node",
73
+ :proc => proc { |key| Chef::Config[:knife][:server_name] = key }
74
+
75
+ def run
76
+ super
77
+ digital_ocean_bootstrap.run
78
+ fetch_validation_key
79
+ create_root_client
80
+ install_client_key
81
+ end
82
+
83
+ def digital_ocean_bootstrap
84
+ setup_environment
85
+ bootstrap = Chef::Knife::DigitalOceanDropletCreate.new
86
+ bootstrap.config[:bootstrap] = true
87
+ Chef::Knife::DigitalOceanDropletCreate.options.keys.each do |attr|
88
+ val = config_val(attr)
89
+ next if val.nil?
90
+
91
+ bootstrap.config[attr] = val
92
+ end
93
+ bootstrap.config[:server_name] = config_val(:chef_node_name)
94
+ bootstrap.config[:distro] = bootstrap_distro
95
+ bootstrap
96
+ end
97
+
98
+ def digital_ocean_connection
99
+ @digital_ocean_connection ||= Fog::Compute.new(
100
+ :provider => "DigitalOcean",
101
+ :digitalocean_client_id => config_val(:digital_ocean_client_id),
102
+ :digitalocean_api_key => config_val(:digital_ocean_api_key)
103
+ )
104
+ end
105
+
106
+ def server_ip_address
107
+ server = digital_ocean_connection.servers.find do |s|
108
+ s.state == "active" && s.name == config_val(:chef_node_name)
109
+ end
110
+
111
+ server && server.public_ip_address
112
+ end
113
+
114
+ private
115
+
116
+ def validate!
117
+ super
118
+
119
+ if config[:chef_node_name].nil?
120
+ ui.error "You did not provide a valid --node-name value."
121
+ exit 1
122
+ end
123
+ if config_val(:platform) == "auto"
124
+ ui.error "Auto platform mode cannot be used with " \
125
+ "knife-digital_ocean plugin"
126
+ exit 1
127
+ end
128
+ end
129
+
130
+ def setup_environment
131
+ ENV["WEBUI_PASSWORD"] = config_val(:webui_password)
132
+ ENV["AMQP_PASSWORD"] = config_val(:amqp_password)
133
+ ENV["NO_TEST"] = "1" if config[:no_test]
134
+ end
135
+
136
+ def ssh_connection
137
+ opts = {
138
+ :host => server_ip_address,
139
+ :user => config_val(:ssh_user),
140
+ :port => "22",
141
+ :keys => [config_val(:identity_file)].compact,
142
+ :password => config_val(:ssh_password)
143
+ }
144
+ if config_val(:host_key_verify) == false
145
+ opts[:user_known_hosts_file] = "/dev/null"
146
+ opts[:paranoid] = false
147
+ end
148
+
149
+ ::Knife::Server::SSH.new(opts)
150
+ end
151
+ end
152
+ end
153
+ end
@@ -19,6 +19,6 @@
19
19
 
20
20
  module Knife
21
21
  module Server
22
- VERSION = "1.2.0"
22
+ VERSION = "1.3.0"
23
23
  end
24
24
  end
@@ -0,0 +1,317 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Fletcher Nichol (<fnichol@nichol.ca>)
4
+ # Copyright:: Copyright (c) 2014 Fletcher Nichol
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ require "chef/knife/server_bootstrap_digitalocean"
21
+ require "chef/knife/ssh"
22
+ require "fakefs/spec_helpers"
23
+ require "net/ssh"
24
+ Chef::Knife::ServerBootstrapDigitalocean.load_deps
25
+
26
+ describe Chef::Knife::ServerBootstrapDigitalocean do
27
+ include FakeFS::SpecHelpers
28
+
29
+ before do
30
+ Chef::Log.logger = Logger.new(StringIO.new)
31
+ @knife = Chef::Knife::ServerBootstrapDigitalocean.new
32
+ @stdout = StringIO.new
33
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
34
+ @stderr = StringIO.new
35
+ allow(@knife.ui).to receive(:stderr).and_return(@stderr)
36
+ @knife.config[:chef_node_name] = "yakky"
37
+ @knife.config[:platform] = "omnibus"
38
+ @knife.config[:ssh_user] = "root"
39
+ end
40
+
41
+ let(:connection) { double(Fog::Compute::AWS) }
42
+
43
+ describe "#digital_ocean_bootstrap" do
44
+
45
+ before do
46
+ @knife.config[:chef_node_name] = "shave.yak"
47
+ @knife.config[:ssh_user] = "jdoe"
48
+ @knife.config[:identity_file] = "~/.ssh/mykey_dsa"
49
+ @knife.config[:digital_ocean_client_id] = "clientxyz"
50
+ @knife.config[:digital_ocean_api_key] = "do123"
51
+ @knife.config[:distro] = "distro-praha"
52
+ @knife.config[:webui_password] = "daweb"
53
+ @knife.config[:amqp_password] = "queueitup"
54
+
55
+ ENV["_SPEC_WEBUI_PASSWORD"] = ENV["WEBUI_PASSWORD"]
56
+ ENV["_SPEC_AMQP_PASSWORD"] = ENV["AMQP_PASSWORD"]
57
+ end
58
+
59
+ after do
60
+ ENV["WEBUI_PASSWORD"] = ENV.delete("_SPEC_WEBUI_PASSWORD")
61
+ ENV["AMQP_PASSWORD"] = ENV.delete("_SPEC_AMQP_PASSWORD")
62
+ end
63
+
64
+ let(:bootstrap) { @knife.digital_ocean_bootstrap }
65
+
66
+ it "returns a DitialOceanDropletCreate instance" do
67
+ expect(bootstrap).to be_a(Chef::Knife::DigitalOceanDropletCreate)
68
+ end
69
+
70
+ it "configs the bootstrap's server_name" do
71
+ expect(bootstrap.config[:server_name]).to eq("shave.yak")
72
+ end
73
+
74
+ it "configs the bootstrap's ssh_user" do
75
+ expect(bootstrap.config[:ssh_user]).to eq("jdoe")
76
+ end
77
+
78
+ it "configs the bootstrap's identity_file" do
79
+ expect(bootstrap.config[:identity_file]).to eq("~/.ssh/mykey_dsa")
80
+ end
81
+
82
+ it "configs the bootstrap's digital_ocean_client_id" do
83
+ expect(bootstrap.config[:digital_ocean_client_id]).to eq("clientxyz")
84
+ end
85
+
86
+ it "configs the bootstrap's digital_ocean_api_key" do
87
+ expect(bootstrap.config[:digital_ocean_api_key]).to eq("do123")
88
+ end
89
+
90
+ it "configs the bootstrap's distro" do
91
+ expect(bootstrap.config[:distro]).to eq("distro-praha")
92
+ end
93
+
94
+ it "configs the bootstrap's distro to chef11/omnibus by default" do
95
+ @knife.config.delete(:distro)
96
+
97
+ expect(bootstrap.config[:distro]).to eq("chef11/omnibus")
98
+ end
99
+
100
+ it "configs the bootstrap's distro value driven off platform value" do
101
+ @knife.config.delete(:distro)
102
+ @knife.config[:platform] = "freebsd"
103
+
104
+ expect(bootstrap.config[:distro]).to eq("chef11/freebsd")
105
+ end
106
+
107
+ it "configs the distro based on bootstrap_version and platform" do
108
+ @knife.config.delete(:distro)
109
+ @knife.config[:platform] = "freebsd"
110
+ @knife.config[:bootstrap_version] = "10"
111
+
112
+ expect(bootstrap.config[:distro]).to eq("chef10/freebsd")
113
+ end
114
+
115
+ it "configs the bootstrap's ENV with the webui password" do
116
+ bootstrap
117
+
118
+ expect(ENV["WEBUI_PASSWORD"]).to eq("daweb")
119
+ end
120
+
121
+ it "configs the bootstrap's ENV with the amqp password" do
122
+ bootstrap
123
+
124
+ expect(ENV["AMQP_PASSWORD"]).to eq("queueitup")
125
+ end
126
+
127
+ it "configs the bootstrap flag to true" do
128
+ expect(bootstrap.config[:bootstrap]).to eq(true)
129
+ end
130
+
131
+ it "skips config values with nil defaults" do
132
+ expect(bootstrap.config[:bootstrap_version]).to be_nil
133
+ end
134
+ end
135
+
136
+ describe "#digital_ocean_connection" do
137
+
138
+ before do
139
+ @before_config = Hash.new
140
+ @before_config[:knife] = Hash.new
141
+ [:digital_ocean_client_id, :digital_ocean_api_key].each do |key|
142
+ @before_config[:knife][key] = Chef::Config[:knife][key]
143
+ end
144
+
145
+ Chef::Config[:knife][:digital_ocean_client_id] = "client"
146
+ Chef::Config[:knife][:digital_ocean_api_key] = "api"
147
+ end
148
+
149
+ after do
150
+ [:digital_ocean_client_id, :digital_ocean_api_key].each do |key|
151
+ Chef::Config[:knife][key] = @before_config[:knife][key]
152
+ end
153
+ end
154
+
155
+ it "constructs a connection" do
156
+ expect(Fog::Compute).to receive(:new).with(
157
+ :provider => "DigitalOcean",
158
+ :digitalocean_client_id => "client",
159
+ :digitalocean_api_key => "api"
160
+ )
161
+
162
+ @knife.digital_ocean_connection
163
+ end
164
+ end
165
+
166
+ describe "#server_ip_address" do
167
+
168
+ before do
169
+ @knife.config[:chef_node_name] = "yak"
170
+ allow(@knife).to receive(:digital_ocean_connection) { connection }
171
+ end
172
+
173
+ context "when server is found" do
174
+
175
+ before do
176
+ allow(connection).to receive(:servers) { [server] }
177
+ end
178
+
179
+ let(:server) do
180
+ double(
181
+ :name => "yak",
182
+ :state => "active",
183
+ :public_ip_address => "10.11.12.13"
184
+ )
185
+ end
186
+
187
+ it "returns the provisioned ip address" do
188
+ expect(@knife.server_ip_address).to eq("10.11.12.13")
189
+ end
190
+
191
+ it "ignores terminated instances" do
192
+ allow(server).to receive(:state) { "foobar" }
193
+
194
+ expect(@knife.server_ip_address).to be_nil
195
+ end
196
+ end
197
+
198
+ context "when server is not found" do
199
+ before do
200
+ allow(connection).to receive(:servers) { [] }
201
+ end
202
+
203
+ it "returns nil" do
204
+ expect(@knife.server_ip_address).to be_nil
205
+ end
206
+ end
207
+ end
208
+
209
+ describe "#run" do
210
+
211
+ before do
212
+ @before_config = Hash.new
213
+ [:node_name, :client_key].each do |attr|
214
+ @before_config[attr] = Chef::Config[attr]
215
+ end
216
+ Chef::Config[:node_name] = "smithers"
217
+ Chef::Config[:client_key] = "/var/tmp/myclientkey.pem"
218
+
219
+ @knife.config[:validation_key] = "/var/tmp/validation.pem"
220
+ @knife.config[:identity_file] = "~/.ssh/mykey_dsa"
221
+ @knife.config[:ssh_password] = "booboo"
222
+ allow(@knife).to receive(:digital_ocean_connection) { connection }
223
+ allow(@knife).to receive(:server_ip_address) { "11.11.11.13" }
224
+ allow(Chef::Knife::DigitalOceanDropletCreate).to receive(:new) do
225
+ bootstrap
226
+ end
227
+ allow(Knife::Server::SSH).to receive(:new) { ssh }
228
+ allow(Knife::Server::Credentials).to receive(:new) { credentials }
229
+ allow(credentials).to receive(:install_validation_key)
230
+ allow(credentials).to receive(:create_root_client)
231
+ end
232
+
233
+ after do
234
+ [:node_name, :client_key].each do |attr|
235
+ Chef::Config[attr] = @before_config[attr]
236
+ end
237
+ end
238
+
239
+ let(:bootstrap) { double(:run => true, :config => Hash.new) }
240
+ let(:ssh) { double }
241
+ let(:credentials) { double.as_null_object }
242
+
243
+ it "exits if Chef::Config[:node_name] is missing" do
244
+ Chef::Config[:node_name] = nil
245
+
246
+ expect { @knife.run }.to raise_error SystemExit
247
+ end
248
+
249
+ it "exits if Chef::Config[:client_key] is missing" do
250
+ Chef::Config[:client_key] = nil
251
+
252
+ expect { @knife.run }.to raise_error SystemExit
253
+ end
254
+
255
+ it "exits if node_name option is missing" do
256
+ @knife.config.delete(:chef_node_name)
257
+
258
+ expect { @knife.run }.to raise_error(SystemExit)
259
+ end
260
+
261
+ it "exits if platform is set to auto" do
262
+ @knife.config[:platform] = "auto"
263
+
264
+ expect { @knife.run }.to raise_error(SystemExit)
265
+ end
266
+
267
+ it "bootstraps a digital ocean server" do
268
+ expect(bootstrap).to receive(:run)
269
+
270
+ @knife.run
271
+ end
272
+
273
+ it "installs a new validation.pem key from the chef 10 server" do
274
+ @knife.config[:bootstrap_version] = "10"
275
+ expect(Knife::Server::SSH).to receive(:new).with(
276
+ :host => "11.11.11.13",
277
+ :user => "root",
278
+ :port => "22",
279
+ :keys => ["~/.ssh/mykey_dsa"],
280
+ :password => "booboo"
281
+ )
282
+ expect(Knife::Server::Credentials).to receive(:new).
283
+ with(ssh, "/etc/chef/validation.pem", {})
284
+ expect(credentials).to receive(:install_validation_key)
285
+
286
+ @knife.run
287
+ end
288
+
289
+ it "installs a new validation.pem key from the omnibus server" do
290
+ expect(Knife::Server::SSH).to receive(:new).with(
291
+ :host => "11.11.11.13",
292
+ :user => "root",
293
+ :port => "22",
294
+ :keys => ["~/.ssh/mykey_dsa"],
295
+ :password => "booboo"
296
+ )
297
+ expect(Knife::Server::Credentials).to receive(:new).
298
+ with(ssh, "/etc/chef/validation.pem", :omnibus => true)
299
+ expect(credentials).to receive(:install_validation_key)
300
+
301
+ @knife.run
302
+ end
303
+
304
+ it "create a root client key" do
305
+ expect(credentials).to receive(:create_root_client)
306
+
307
+ @knife.run
308
+ end
309
+
310
+ it "installs a client key" do
311
+ expect(credentials).to receive(:install_client_key).
312
+ with("smithers", "/var/tmp/myclientkey.pem")
313
+
314
+ @knife.run
315
+ end
316
+ end
317
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fletcher Nichol
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-13 00:00:00.000000000 Z
11
+ date: 2014-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: knife-digital_ocean
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: knife-ec2
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -222,6 +236,7 @@ files:
222
236
  - lib/chef/knife/bootstrap/chef11/rhel.erb
223
237
  - lib/chef/knife/server_backup.rb
224
238
  - lib/chef/knife/server_bootstrap_base.rb
239
+ - lib/chef/knife/server_bootstrap_digitalocean.rb
225
240
  - lib/chef/knife/server_bootstrap_ec2.rb
226
241
  - lib/chef/knife/server_bootstrap_linode.rb
227
242
  - lib/chef/knife/server_bootstrap_openstack.rb
@@ -233,6 +248,7 @@ files:
233
248
  - lib/knife/server/ssh.rb
234
249
  - lib/knife/server/version.rb
235
250
  - spec/chef/knife/server_backup_spec.rb
251
+ - spec/chef/knife/server_bootstrap_digitalocean_spec.rb
236
252
  - spec/chef/knife/server_bootstrap_ec2_spec.rb
237
253
  - spec/chef/knife/server_bootstrap_linode_spec.rb
238
254
  - spec/chef/knife/server_bootstrap_openstack_spec.rb
@@ -266,6 +282,7 @@ specification_version: 4
266
282
  summary: Chef Knife plugin to bootstrap Chef Servers
267
283
  test_files:
268
284
  - spec/chef/knife/server_backup_spec.rb
285
+ - spec/chef/knife/server_bootstrap_digitalocean_spec.rb
269
286
  - spec/chef/knife/server_bootstrap_ec2_spec.rb
270
287
  - spec/chef/knife/server_bootstrap_linode_spec.rb
271
288
  - spec/chef/knife/server_bootstrap_openstack_spec.rb