knife-server 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6ac23ba3967334f48e3bad6406358d0653812228
4
+ data.tar.gz: b1a1d3dd1f2616444e7a9fbe1bd3dde52a696091
5
+ SHA512:
6
+ metadata.gz: 9a19382e580ef0d6336bb74f5bef965641785c6f81c327a84d459195e82a67783181805cb6d4e2f9dc34077b13eb2ce2e504d5718e35380a7173cd770a2b171a
7
+ data.tar.gz: bb62f7d5d3c90f81e071aa975abfa9fc9be7625c6b9e1af375978a5cd689bc57e03400559a37e00785b074e35ea06c38f476e57e442679c3e8c11b3244e68a93
@@ -4,7 +4,6 @@ rvm:
4
4
  - 2.0.0
5
5
  - 1.9.2
6
6
  - ruby-head
7
- - 1.8.7
8
7
 
9
8
  env:
10
9
  - "CHEF_VERSION=11.4.0"
@@ -1,3 +1,13 @@
1
+ ## 1.1.0 / 2013-07-26
2
+
3
+ ### New features
4
+
5
+ * Pull request [#42][]: Add support for Linode (via the knife-linode gem). ([@fnichol][])
6
+
7
+ ### Improvements
8
+
9
+ * Pull request [#41][]: Add new option pretty_print for knife server backup. ([@sawanoboly][])
10
+
1
11
  ## 1.0.1 / 2013-04-11
2
12
 
3
13
  ### Bug fixes
@@ -5,7 +15,7 @@
5
15
  * Pull request [#29][]: Fix README typo in ssh password argument. ([@ranjib][])
6
16
  * Pull request [#34][]: Fix AMQP_PASSWORD propagation. ([@erikh][])
7
17
 
8
- ### Improvement
18
+ ### Improvements
9
19
 
10
20
  * Pull request [#35][]: Add VPC support. ([@jssjr][])
11
21
  * Pull request [#34][]: Provide better information when the package can't be
@@ -141,25 +151,28 @@ The initial release.
141
151
 
142
152
 
143
153
  <!--- The following link definition list is generated by PimpMyChangelog --->
144
- [#2]: https://github.com/fnichol/knife/issues/2
145
- [#3]: https://github.com/fnichol/knife/issues/3
146
- [#5]: https://github.com/fnichol/knife/issues/5
147
- [#7]: https://github.com/fnichol/knife/issues/7
148
- [#8]: https://github.com/fnichol/knife/issues/8
149
- [#9]: https://github.com/fnichol/knife/issues/9
150
- [#10]: https://github.com/fnichol/knife/issues/10
151
- [#11]: https://github.com/fnichol/knife/issues/11
152
- [#13]: https://github.com/fnichol/knife/issues/13
153
- [#15]: https://github.com/fnichol/knife/issues/15
154
- [#29]: https://github.com/fnichol/knife/issues/29
155
- [#34]: https://github.com/fnichol/knife/issues/34
156
- [#35]: https://github.com/fnichol/knife/issues/35
154
+ [#2]: https://github.com/fnichol/knife-server/issues/2
155
+ [#3]: https://github.com/fnichol/knife-server/issues/3
156
+ [#5]: https://github.com/fnichol/knife-server/issues/5
157
+ [#7]: https://github.com/fnichol/knife-server/issues/7
158
+ [#8]: https://github.com/fnichol/knife-server/issues/8
159
+ [#9]: https://github.com/fnichol/knife-server/issues/9
160
+ [#10]: https://github.com/fnichol/knife-server/issues/10
161
+ [#11]: https://github.com/fnichol/knife-server/issues/11
162
+ [#13]: https://github.com/fnichol/knife-server/issues/13
163
+ [#15]: https://github.com/fnichol/knife-server/issues/15
164
+ [#29]: https://github.com/fnichol/knife-server/issues/29
165
+ [#34]: https://github.com/fnichol/knife-server/issues/34
166
+ [#35]: https://github.com/fnichol/knife-server/issues/35
167
+ [#41]: https://github.com/fnichol/knife-server/issues/41
168
+ [#42]: https://github.com/fnichol/knife-server/issues/42
157
169
  [@danryan]: https://github.com/danryan
158
170
  [@erikh]: https://github.com/erikh
159
171
  [@fnichol]: https://github.com/fnichol
160
172
  [@iafonov]: https://github.com/iafonov
161
173
  [@jssjr]: https://github.com/jssjr
162
174
  [@ranjib]: https://github.com/ranjib
175
+ [@sawanoboly]: https://github.com/sawanoboly
163
176
  [@stormsilver]: https://github.com/stormsilver
164
177
  [@wpeterson]: https://github.com/wpeterson
165
- [@xdissent]: https://github.com/xdissent
178
+ [@xdissent]: https://github.com/xdissent
data/README.md CHANGED
@@ -4,8 +4,9 @@
4
4
  [![Code Climate](https://codeclimate.com/github/fnichol/knife-server.png)](https://codeclimate.com/github/fnichol/knife-server)
5
5
 
6
6
  An Opscode Chef knife plugin to manage Chef Servers. Bootstrap a new Chef
7
- Server on Amazon's EC2 or a standalone server. Backup and restore your Chef
8
- Server or Hosted Chef's node, role, data bag, and environment JSON data.
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.
9
10
 
10
11
  ## <a name="usage"></a> Usage
11
12
 
@@ -36,15 +37,30 @@ $ knife server bootstrap ec2 \
36
37
  --ssh-user ubuntu
37
38
  ```
38
39
 
40
+ To spin up your Chef Server on Linode:
41
+
42
+ ```bash
43
+ knife server bootstrap linode \
44
+ --node-name linny.example.com \
45
+ --linode-node-name linny \
46
+ --linode-api-key $LINODE_API_KEY \
47
+ --linode-datacenter 3 \
48
+ --linode-flavor 1 \
49
+ --linode-image 99 \
50
+ --ssh-password 'testing1234'
51
+ ```
52
+
39
53
  Or maybe you want to try out a Chef Server using [Vagrant][vagrant_site]?
40
54
 
41
55
  ```bash
42
56
  $ cat <<VAGRANTFILE > Vagrantfile
43
- Vagrant::Config.run do |config|
57
+ Vagrant.configure("2") do |config|
44
58
  config.vm.box = "precise64"
45
59
  config.vm.box_url = "http://files.vagrantup.com/precise64.box"
46
- config.vm.network :hostonly, "192.168.33.10"
47
- config.vm.customize ["modifyvm", :id, "--memory", 2048]
60
+ config.vm.network :private_network, ip: "192.168.33.10"
61
+ config.vm.provider :virtualbox do |vb|
62
+ vb.customize ["modifyvm", :id, "--memory", 2048]
63
+ end
48
64
  end
49
65
  VAGRANTFILE
50
66
  $ vagrant up
@@ -92,11 +108,12 @@ Add this line to your application's Gemfile:
92
108
  gem 'knife-server'
93
109
  ```
94
110
 
95
- **Note** If you want to use the `bootstrap ec2` subcommand you will need to
96
- explicitly add this to your Gemfile with:
111
+ **Note** If you want to use the `bootstrap ec2` or `bootstrap linode`
112
+ subcommands you will need to explicitly add this to your Gemfile with:
97
113
 
98
114
  ```ruby
99
115
  gem 'knife-ec2'
116
+ gem 'knife-linode'
100
117
  ```
101
118
 
102
119
  Finally execute:
@@ -111,8 +128,8 @@ Or install it yourself as:
111
128
  $ gem install knife-server
112
129
  ```
113
130
 
114
- (Don't forget a `gem install knife-ec2` if using the `bootstrap ec2`
115
- subcommand).
131
+ (Don't forget a `gem install knife-ec2` or `gem install knife-linode` if using
132
+ the `bootstrap ec2` or `bootstrap linode` subcommands).
116
133
 
117
134
  Next, you **must** set up a [knife.rb configuration](#installation-knife) so
118
135
  that the shipped Knife subcommands know where to place and modify key files,
@@ -156,11 +173,15 @@ add some of the common configuration to your `~/.chef/knife.rb` or your
156
173
  projects `.chef/knife.rb` file like so:
157
174
 
158
175
  ```ruby
176
+ # for aws/ec2
159
177
  knife[:aws_access_key_id] = "MY_KEY"
160
178
  knife[:aws_secret_access_key] = "MY_SECRET"
161
179
  knife[:region] = "us-west-2"
162
180
  knife[:availability_zone] = "us-west-2a"
163
181
  knife[:flavor] = "t1.micro"
182
+
183
+ # for linode
184
+ knife[:linode_api_key] = "MY_KEY"
164
185
  ```
165
186
 
166
187
  Better yet, why not try a more generic [knife.rb][chef_bootstrap_knife_rb] file
@@ -373,6 +394,69 @@ The resulting set will include:
373
394
  * `"Node=#{config[:chef_node_name]}"`
374
395
  * `"Role=chef_server"`
375
396
 
397
+ ### <a name="knife-server-bootstrap-linode"></a> knife server bootstrap linode
398
+
399
+ **Note:** You must install the [knife-linode gem][knife-linode] to use this
400
+ subcommand. This was done to keep the dependencies of this library lighter and
401
+ to make future cloud adapter support easier to add.
402
+
403
+ Provisions a Linode instance and sets up an Open Source Chef Server as
404
+ described [above](#knife-server-bootstrap).
405
+
406
+ #### Configuration
407
+
408
+ This subcommand imports all relavent options from the knife-linode gem. For
409
+ detailed documentation relating to these options, please visit the [docs
410
+ page][docs_knife_linode].
411
+
412
+ ##### --linode-api-key KEY (-A)
413
+
414
+ Your Linode API Key.
415
+
416
+ This option is **required**.
417
+
418
+ ##### --linode-datacenter DATACENTER (-D)
419
+
420
+ The datacenter for the server.
421
+
422
+ The default value is `3` (Use `knife linode datacenter list` for a list of
423
+ choices)
424
+
425
+ ##### --linode-flavor FLAVOR (-f)
426
+
427
+ The flavor of server.
428
+
429
+ The default value is `1`. (Use `knife linode flavor list` for a list of
430
+ choices)
431
+
432
+ ##### --linode-image IMAGE (-i)
433
+
434
+ The image for the server.
435
+
436
+ The default value is `93`. (Use `knife linode image list` for a list of
437
+ choices)
438
+
439
+ ##### --linode-kernel KERNEL (-k)
440
+
441
+ The kernel for the server.
442
+
443
+ The default value is `138`. (Use `knife linode kernel list` for a list of
444
+ choices)
445
+
446
+ ##### --linode-node-name NAME (-L)
447
+
448
+ The Linode node name for your new node.
449
+
450
+ This option is **required**.
451
+
452
+ ##### --ssh-password PASSWORD (-P)
453
+
454
+ The ssh password. If a password is not provided, then a random password will be
455
+ generated and echoed in logging output. It is recommended that you specify a
456
+ password so that you know how to connect later.
457
+
458
+ The default value is a random password.
459
+
376
460
  ### <a name="knife-server-bootstrap-standalone"></a> knife server bootstrap standalone
377
461
 
378
462
  Provisions a standalone server that is reachable on the network and sets up
@@ -533,8 +617,10 @@ Apache License, Version 2.0 (see [LICENSE][license])
533
617
  [chef_bootstrap_repo]: https://github.com/fnichol/chef-bootstrap-repo/
534
618
  [docs_knife]: http://docs.opscode.com/config_rb_knife.html
535
619
  [docs_knife_ec2]: http://docs.opscode.com/plugin_knife_ec2.html
620
+ [docs_knife_linode]: http://docs.opscode.com/plugin_knife_linode.html
536
621
  [jtimberman]: https://github.com/jtimberman
537
622
  [install_chef]: http://www.opscode.com/chef/install/
538
623
  [knife-ec2]: https://github.com/opscode/knife-ec2
624
+ [knife-linode]: https://github.com/opscode/knife-linode
539
625
  [stevendanna]: https://github.com/stevendanna
540
626
  [vagrant_site]: http://vagrantup.com/
@@ -15,13 +15,16 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Knife::Server::VERSION
17
17
 
18
+ gem.required_ruby_version = ">= 1.9.2"
19
+
18
20
  gem.add_dependency "fog", "~> 1.3"
19
21
  gem.add_dependency "net-ssh"
20
22
  gem.add_dependency "chef", ">= 0.10.10"
21
23
 
22
24
  gem.add_development_dependency "knife-ec2", ">= 0.5.12"
25
+ gem.add_development_dependency "knife-linode"
23
26
 
24
- gem.add_development_dependency "rspec", "~> 2.10"
27
+ gem.add_development_dependency "rspec", "~> 2.13.0"
25
28
  gem.add_development_dependency "fakefs", "~> 0.4.0"
26
29
  gem.add_development_dependency "timecop", "~> 0.3"
27
30
  end
@@ -35,6 +35,11 @@ class Chef
35
35
  :long => "--backup-dir DIR",
36
36
  :description => "The directory to host backup files"
37
37
 
38
+ option :pretty_print,
39
+ :short => "-P",
40
+ :long => "--pretty_print",
41
+ :description => "Generate Pretty JSON for file."
42
+
38
43
  def run
39
44
  validate!
40
45
  components = name_args.empty? ? COMPONENTS.keys : name_args
@@ -91,7 +96,11 @@ class Chef
91
96
  obj = c[:klass].load(name)
92
97
  ui.msg "Backing up #{c[:singular]}[#{name}]"
93
98
  ::File.open(::File.join(dir_path, "#{name}.json"), "wb") do |f|
94
- f.write(obj.to_json)
99
+ if config[:pretty_print]
100
+ f.write(JSON.pretty_generate(obj))
101
+ else
102
+ f.write(obj.to_json)
103
+ end
95
104
  end
96
105
  end
97
106
 
@@ -103,7 +112,11 @@ class Chef
103
112
  obj = Chef::DataBagItem.load(name, item_name)
104
113
  ui.msg "Backing up #{c[:singular]}[#{name}][#{item_name}]"
105
114
  ::File.open(::File.join(item_path, "#{item_name}.json"), "wb") do |f|
106
- f.write(obj.to_json)
115
+ if config[:pretty_print]
116
+ f.write(JSON.pretty_generate(obj))
117
+ else
118
+ f.write(obj.to_json)
119
+ end
107
120
  end
108
121
  end
109
122
  end
@@ -0,0 +1,117 @@
1
+ #
2
+ # Author:: Fletcher Nichol (<fnichol@nichol.ca>)
3
+ # Copyright:: Copyright (c) 2013 Fletcher Nichol
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/server_bootstrap_base'
20
+
21
+ class Chef
22
+ class Knife
23
+ class ServerBootstrapLinode < Knife
24
+
25
+ banner "knife server bootstrap linode (options)"
26
+
27
+ include Knife::ServerBootstrapBase
28
+
29
+ deps do
30
+ require 'knife/server/ssh'
31
+ require 'knife/server/credentials'
32
+
33
+ begin
34
+ require 'chef/knife/linode_server_create'
35
+ require 'fog'
36
+ Chef::Knife::LinodeServerCreate.load_deps
37
+
38
+ current_options = self.options
39
+ self.options = Chef::Knife::LinodeServerCreate.options.dup
40
+ self.options.merge!(current_options)
41
+ rescue LoadError => ex
42
+ ui.error [
43
+ "Knife plugin knife-linode could not be loaded.",
44
+ "Please add the knife-linode gem to your Gemfile or",
45
+ "install the gem manually with `gem install knife-linode'.",
46
+ "(#{ex.message})"
47
+ ].join(" ")
48
+ exit 1
49
+ end
50
+ end
51
+
52
+ def run
53
+ validate!
54
+ linode_bootstrap.run
55
+ fetch_validation_key
56
+ create_root_client
57
+ install_client_key
58
+ end
59
+
60
+ def linode_bootstrap
61
+ ENV['WEBUI_PASSWORD'] = config_val(:webui_password)
62
+ ENV['AMQP_PASSWORD'] = config_val(:amqp_password)
63
+ ENV['NO_TEST'] = "1" if config[:no_test]
64
+ bootstrap = Chef::Knife::LinodeServerCreate.new
65
+ Chef::Knife::LinodeServerCreate.options.keys.each do |attr|
66
+ bootstrap.config[attr] = config_val(attr)
67
+ end
68
+ bootstrap.config[:distro] = bootstrap_distro
69
+ bootstrap
70
+ end
71
+
72
+ def linode_connection
73
+ @linode_connection ||= Fog::Compute.new(
74
+ :provider => 'Linode',
75
+ :linode_api_key => config_val(:linode_api_key)
76
+ )
77
+ end
78
+
79
+ def server_ip_address
80
+ server = linode_connection.servers.find do |s|
81
+ s.status == 1 && s.name == config_val(:linode_node_name)
82
+ end
83
+
84
+ server && server.public_ip_address
85
+ end
86
+
87
+ private
88
+
89
+ def validate!
90
+ if config[:chef_node_name].nil?
91
+ ui.error "You did not provide a valid --node-name value."
92
+ exit 1
93
+ end
94
+ if config_val(:platform) == "auto"
95
+ ui.error "Auto platform mode cannot be used with knife-linode plugin"
96
+ exit 1
97
+ end
98
+ end
99
+
100
+ def ssh_connection
101
+ opts = {
102
+ :host => server_ip_address,
103
+ :user => config_val(:ssh_user),
104
+ :port => "22",
105
+ :keys => [config_val(:identity_file)].compact,
106
+ :password => config_val(:ssh_password)
107
+ }
108
+ if config_val(:host_key_verify) == false
109
+ opts[:user_known_hosts_file] = "/dev/null"
110
+ opts[:paranoid] = false
111
+ end
112
+
113
+ ::Knife::Server::SSH.new(opts)
114
+ end
115
+ end
116
+ end
117
+ end
@@ -18,6 +18,6 @@
18
18
 
19
19
  module Knife
20
20
  module Server
21
- VERSION = "1.0.1"
21
+ VERSION = "1.1.0"
22
22
  end
23
23
  end
@@ -0,0 +1,273 @@
1
+ #
2
+ # Author:: Fletcher Nichol (<fnichol@nichol.ca>)
3
+ # Copyright:: Copyright (c) 2013 Fletcher Nichol
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/server_bootstrap_linode'
20
+ require 'chef/knife/ssh'
21
+ require 'fakefs/spec_helpers'
22
+ require 'net/ssh'
23
+ Chef::Knife::ServerBootstrapLinode.load_deps
24
+
25
+ describe Chef::Knife::ServerBootstrapLinode do
26
+ include FakeFS::SpecHelpers
27
+
28
+ before do
29
+ Chef::Log.logger = Logger.new(StringIO.new)
30
+ @knife = Chef::Knife::ServerBootstrapLinode.new
31
+ @stdout = StringIO.new
32
+ @knife.ui.stub!(:stdout).and_return(@stdout)
33
+ @stderr = StringIO.new
34
+ @knife.ui.stub!(:stderr).and_return(@stderr)
35
+ @knife.config[:chef_node_name] = "yakky"
36
+ @knife.config[:platform] = "omnibus"
37
+ @knife.config[:ssh_user] = "root"
38
+ end
39
+
40
+ let(:connection) { mock(Fog::Compute::AWS) }
41
+
42
+ describe "#linode_bootstrap" do
43
+
44
+ before do
45
+ @knife.config[:chef_node_name] = "shave.yak"
46
+ @knife.config[:ssh_user] = "jdoe"
47
+ @knife.config[:identity_file] = "~/.ssh/mykey_dsa"
48
+ @knife.config[:linode_api_key] = "linode123"
49
+ @knife.config[:distro] = "distro-praha"
50
+ @knife.config[:webui_password] = "daweb"
51
+ @knife.config[:amqp_password] = "queueitup"
52
+
53
+ ENV['_SPEC_WEBUI_PASSWORD'] = ENV['WEBUI_PASSWORD']
54
+ ENV['_SPEC_AMQP_PASSWORD'] = ENV['AMQP_PASSWORD']
55
+ end
56
+
57
+ after do
58
+ ENV['WEBUI_PASSWORD'] = ENV.delete('_SPEC_WEBUI_PASSWORD')
59
+ ENV['AMQP_PASSWORD'] = ENV.delete('_SPEC_AMQP_PASSWORD')
60
+ end
61
+
62
+ let(:bootstrap) { @knife.linode_bootstrap }
63
+
64
+ it "returns a LinodeServerCreate instance" do
65
+ bootstrap.should be_a(Chef::Knife::LinodeServerCreate)
66
+ end
67
+
68
+ it "configs the bootstrap's chef_node_name" do
69
+ bootstrap.config[:chef_node_name].should eq("shave.yak")
70
+ end
71
+
72
+ it "configs the bootstrap's ssh_user" do
73
+ bootstrap.config[:ssh_user].should eq("jdoe")
74
+ end
75
+
76
+ it "configs the bootstrap's identity_file" do
77
+ bootstrap.config[:identity_file].should eq("~/.ssh/mykey_dsa")
78
+ end
79
+
80
+ it "configs the bootstrap's linode_api_key" do
81
+ bootstrap.config[:linode_api_key].should eq("linode123")
82
+ end
83
+
84
+ it "configs the bootstrap's distro" do
85
+ bootstrap.config[:distro].should eq("distro-praha")
86
+ end
87
+
88
+ it "configs the bootstrap's distro to chef11/omnibus by default" do
89
+ @knife.config.delete(:distro)
90
+
91
+ bootstrap.config[:distro].should eq("chef11/omnibus")
92
+ end
93
+
94
+ it "configs the bootstrap's distro value driven off platform value" do
95
+ @knife.config.delete(:distro)
96
+ @knife.config[:platform] = "freebsd"
97
+
98
+ bootstrap.config[:distro].should eq("chef11/freebsd")
99
+ end
100
+
101
+ it "configs the bootstrap's distro based on bootstrap_version and platform" do
102
+ @knife.config.delete(:distro)
103
+ @knife.config[:platform] = "freebsd"
104
+ @knife.config[:bootstrap_version] = "10"
105
+
106
+ bootstrap.config[:distro].should eq("chef10/freebsd")
107
+ end
108
+
109
+ it "configs the bootstrap's ENV with the webui password" do
110
+ bootstrap
111
+ ENV['WEBUI_PASSWORD'].should eq("daweb")
112
+ end
113
+
114
+ it "configs the bootstrap's ENV with the amqp password" do
115
+ bootstrap
116
+ ENV['AMQP_PASSWORD'].should eq("queueitup")
117
+ end
118
+ end
119
+
120
+ describe "#linode_connection" do
121
+
122
+ before do
123
+ @before_config = Hash.new
124
+ @before_config[:knife] = Hash.new
125
+ @before_config[:knife][:linode_api_key] =
126
+ Chef::Config[:knife][:linode_api_key]
127
+
128
+ Chef::Config[:knife][:linode_api_key] = "key"
129
+ end
130
+
131
+ after do
132
+ Chef::Config[:knife][:linode_api_key] =
133
+ @before_config[:knife][:linode_api_key]
134
+ end
135
+
136
+ it "constructs a connection" do
137
+ Fog::Compute.should_receive(:new).with({
138
+ :provider => 'Linode',
139
+ :linode_api_key => 'key'
140
+ })
141
+
142
+ @knife.linode_connection
143
+ end
144
+ end
145
+
146
+ describe "#server_ip_address" do
147
+
148
+ before do
149
+ @knife.config[:linode_node_name] = 'yak'
150
+ @knife.stub(:linode_connection) { connection }
151
+ end
152
+
153
+ context "when server is found" do
154
+
155
+ before do
156
+ connection.stub(:servers) { [server] }
157
+ end
158
+
159
+ let(:server) do
160
+ stub(:name => 'yak', :status => 1, :public_ip_address => '10.11.12.13')
161
+ end
162
+
163
+ it "returns the provisioned ip address" do
164
+ @knife.server_ip_address.should eq('10.11.12.13')
165
+ end
166
+
167
+ it "ignores terminated instances" do
168
+ server.stub(:status) { 0 }
169
+
170
+ @knife.server_ip_address.should be_nil
171
+ end
172
+ end
173
+
174
+ context "when server is not found" do
175
+ before do
176
+ connection.stub(:servers) { [] }
177
+ end
178
+
179
+ it "returns nil" do
180
+ @knife.server_ip_address.should be_nil
181
+ end
182
+ end
183
+ end
184
+
185
+ describe "#run" do
186
+
187
+ before do
188
+ @before_config = Hash.new
189
+ [:node_name, :client_key].each do |attr|
190
+ @before_config[attr] = Chef::Config[attr]
191
+ end
192
+ Chef::Config[:node_name] = "smithers"
193
+ Chef::Config[:client_key] = "/var/tmp/myclientkey.pem"
194
+
195
+ @knife.config[:validation_key] = "/var/tmp/validation.pem"
196
+ @knife.config[:identity_file] = "~/.ssh/mykey_dsa"
197
+ @knife.config[:ssh_password] = "booboo"
198
+ @knife.stub(:linode_connection) { connection }
199
+ @knife.stub(:server_ip_address) { "11.11.11.13" }
200
+ Chef::Knife::LinodeServerCreate.stub(:new) { bootstrap }
201
+ Knife::Server::SSH.stub(:new) { ssh }
202
+ Knife::Server::Credentials.stub(:new) { credentials }
203
+ credentials.stub(:install_validation_key)
204
+ credentials.stub(:create_root_client)
205
+ end
206
+
207
+ after do
208
+ [:node_name, :client_key].each do |attr|
209
+ Chef::Config[attr] = @before_config[attr]
210
+ end
211
+ end
212
+
213
+ let(:bootstrap) { stub(:run => true, :config => Hash.new) }
214
+ let(:ssh) { stub }
215
+ let(:credentials) { stub.as_null_object }
216
+
217
+ it "exits if node_name option is missing" do
218
+ @knife.config.delete(:chef_node_name)
219
+
220
+ lambda { @knife.run }.should raise_error(SystemExit)
221
+ end
222
+
223
+ it "exits if platform is set to auto" do
224
+ @knife.config[:platform] = "auto"
225
+
226
+ lambda { @knife.run }.should raise_error(SystemExit)
227
+ end
228
+
229
+ it "bootstraps a linode server" do
230
+ bootstrap.should_receive(:run)
231
+
232
+ @knife.run
233
+ end
234
+
235
+ it "installs a new validation.pem key from the chef 10 server" do
236
+ @knife.config[:bootstrap_version] = "10"
237
+ Knife::Server::SSH.should_receive(:new).with({
238
+ :host => "11.11.11.13", :user => "root",
239
+ :port => "22", :keys => ["~/.ssh/mykey_dsa"], :password => "booboo"
240
+ })
241
+ Knife::Server::Credentials.should_receive(:new).
242
+ with(ssh, "/etc/chef/validation.pem", {})
243
+ credentials.should_receive(:install_validation_key)
244
+
245
+ @knife.run
246
+ end
247
+
248
+ it "installs a new validation.pem key from the omnibus server" do
249
+ Knife::Server::SSH.should_receive(:new).with({
250
+ :host => "11.11.11.13", :user => "root",
251
+ :port => "22", :keys => ["~/.ssh/mykey_dsa"], :password => "booboo"
252
+ })
253
+ Knife::Server::Credentials.should_receive(:new).
254
+ with(ssh, "/etc/chef/validation.pem", {:omnibus => true})
255
+ credentials.should_receive(:install_validation_key)
256
+
257
+ @knife.run
258
+ end
259
+
260
+ it "create a root client key" do
261
+ credentials.should_receive(:create_root_client)
262
+
263
+ @knife.run
264
+ end
265
+
266
+ it "installs a client key" do
267
+ credentials.should_receive(:install_client_key).
268
+ with("smithers", "/var/tmp/myclientkey.pem")
269
+
270
+ @knife.run
271
+ end
272
+ end
273
+ end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Fletcher Nichol
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-11 00:00:00.000000000 Z
11
+ date: 2013-07-26 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: fog
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,71 +27,76 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: net-ssh
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: chef
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: 0.10.10
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: 0.10.10
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: knife-ec2
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: 0.5.12
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: 0.5.12
69
+ - !ruby/object:Gem::Dependency
70
+ name: knife-linode
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'
78
83
  - !ruby/object:Gem::Dependency
79
84
  name: rspec
80
85
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
86
  requirements:
83
87
  - - ~>
84
88
  - !ruby/object:Gem::Version
85
- version: '2.10'
89
+ version: 2.13.0
86
90
  type: :development
87
91
  prerelease: false
88
92
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
93
  requirements:
91
94
  - - ~>
92
95
  - !ruby/object:Gem::Version
93
- version: '2.10'
96
+ version: 2.13.0
94
97
  - !ruby/object:Gem::Dependency
95
98
  name: fakefs
96
99
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
100
  requirements:
99
101
  - - ~>
100
102
  - !ruby/object:Gem::Version
@@ -102,7 +104,6 @@ dependencies:
102
104
  type: :development
103
105
  prerelease: false
104
106
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
107
  requirements:
107
108
  - - ~>
108
109
  - !ruby/object:Gem::Version
@@ -110,7 +111,6 @@ dependencies:
110
111
  - !ruby/object:Gem::Dependency
111
112
  name: timecop
112
113
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
114
  requirements:
115
115
  - - ~>
116
116
  - !ruby/object:Gem::Version
@@ -118,7 +118,6 @@ dependencies:
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
121
  requirements:
123
122
  - - ~>
124
123
  - !ruby/object:Gem::Version
@@ -151,6 +150,7 @@ files:
151
150
  - lib/chef/knife/server_backup.rb
152
151
  - lib/chef/knife/server_bootstrap_base.rb
153
152
  - lib/chef/knife/server_bootstrap_ec2.rb
153
+ - lib/chef/knife/server_bootstrap_linode.rb
154
154
  - lib/chef/knife/server_bootstrap_standalone.rb
155
155
  - lib/chef/knife/server_restore.rb
156
156
  - lib/knife-server.rb
@@ -160,6 +160,7 @@ files:
160
160
  - lib/knife/server/version.rb
161
161
  - spec/chef/knife/server_backup_spec.rb
162
162
  - spec/chef/knife/server_bootstrap_ec2_spec.rb
163
+ - spec/chef/knife/server_bootstrap_linode_spec.rb
163
164
  - spec/chef/knife/server_bootstrap_standalone_spec.rb
164
165
  - spec/chef/knife/server_restore_spec.rb
165
166
  - spec/knife/server/credientials_spec.rb
@@ -167,37 +168,31 @@ files:
167
168
  - spec/knife/server/ssh_spec.rb
168
169
  homepage: http://fnichol.github.com/knife-server
169
170
  licenses: []
171
+ metadata: {}
170
172
  post_install_message:
171
173
  rdoc_options: []
172
174
  require_paths:
173
175
  - lib
174
176
  required_ruby_version: !ruby/object:Gem::Requirement
175
- none: false
176
177
  requirements:
177
- - - ! '>='
178
+ - - '>='
178
179
  - !ruby/object:Gem::Version
179
- version: '0'
180
- segments:
181
- - 0
182
- hash: -2573931868041806838
180
+ version: 1.9.2
183
181
  required_rubygems_version: !ruby/object:Gem::Requirement
184
- none: false
185
182
  requirements:
186
- - - ! '>='
183
+ - - '>='
187
184
  - !ruby/object:Gem::Version
188
185
  version: '0'
189
- segments:
190
- - 0
191
- hash: -2573931868041806838
192
186
  requirements: []
193
187
  rubyforge_project:
194
- rubygems_version: 1.8.24
188
+ rubygems_version: 2.0.3
195
189
  signing_key:
196
- specification_version: 3
190
+ specification_version: 4
197
191
  summary: Chef Knife plugin to bootstrap Chef Servers
198
192
  test_files:
199
193
  - spec/chef/knife/server_backup_spec.rb
200
194
  - spec/chef/knife/server_bootstrap_ec2_spec.rb
195
+ - spec/chef/knife/server_bootstrap_linode_spec.rb
201
196
  - spec/chef/knife/server_bootstrap_standalone_spec.rb
202
197
  - spec/chef/knife/server_restore_spec.rb
203
198
  - spec/knife/server/credientials_spec.rb