kitchen-linode 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ad3bb6e0dc353cf7c224e8192eb9953c7613783d
4
+ data.tar.gz: 93d6f0aacb1994f67a2a13bf5c662630a5dc105b
5
+ SHA512:
6
+ metadata.gz: ba9d42e18e810cb95c8843cb71cb238fd9ee0eb7a948df6ea3eb5ea63623929f2ed76d8dea10ac0ed6cbad124805e290fdda2f04d1b56c44e1305825081ac589
7
+ data.tar.gz: 9520cb6e9bfc9e72f01dbdde537e7820592247c0b30a77026b947e69a3d40c6dd2d0897d7e1d6cf26d1060af00300269c0f63b6d1cbb6696fe208b85f0508019
data/.cane ADDED
File without changes
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.tailor ADDED
@@ -0,0 +1,4 @@
1
+ Tailor.config do |config|
2
+ config.formatters "text"
3
+ config.file_set 'lib/**/*.rb'
4
+ end
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.0.0
5
+ - 1.9.3
6
+ - 1.9.2
7
+ - ruby-head
8
+
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: ruby-head
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.1.0 / Unreleased
2
+
3
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in knife-linode.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # <a name="title"></a> Kitchen::Linode
2
+
3
+ A Test Kitchen Driver for Linode.
4
+
5
+ ## <a name="requirements"></a> Requirements
6
+
7
+ **TODO:** document any software or library prerequisites that are required to
8
+ use this driver. Implement the `#verify_dependencies` method in your Driver
9
+ class to enforce these requirements in code, if possible.
10
+
11
+ ## <a name="installation"></a> Installation and Setup
12
+
13
+ Please read the [Driver usage][driver_usage] page for more details.
14
+
15
+ ## <a name="config"></a> Configuration
16
+
17
+ **TODO:** Write descriptions of all configuration options
18
+
19
+ ### <a name="config-require-chef-omnibus"></a> require\_chef\_omnibus
20
+
21
+ Determines whether or not a Chef [Omnibus package][chef_omnibus_dl] will be
22
+ installed. There are several different behaviors available:
23
+
24
+ * `true` - the latest release will be installed. Subsequent converges
25
+ will skip re-installing if chef is present.
26
+ * `latest` - the latest release will be installed. Subsequent converges
27
+ will always re-install even if chef is present.
28
+ * `<VERSION_STRING>` (ex: `10.24.0`) - the desired version string will
29
+ be passed the the install.sh script. Subsequent converges will skip if
30
+ the installed version and the desired version match.
31
+ * `false` or `nil` - no chef is installed.
32
+
33
+ The default value is unset, or `nil`.
34
+
35
+ ## <a name="development"></a> Development
36
+
37
+ * Source hosted at [GitHub][repo]
38
+ * Report issues/questions/feature requests on [GitHub Issues][issues]
39
+
40
+ Pull requests are very welcome! Make sure your patches are well tested.
41
+ Ideally create a topic branch for every separate change you make. For
42
+ example:
43
+
44
+ 1. Fork the repo
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
49
+
50
+ ## <a name="authors"></a> Authors
51
+
52
+ Created and maintained by [Brett Taylor][author] (<btaylor@linode.com>)
53
+
54
+ ## <a name="license"></a> License
55
+
56
+ Apache 2.0 (see [LICENSE][license])
57
+
58
+
59
+ [author]: https://github.com/enter-github-user
60
+ [issues]: https://github.com/enter-github-user/kitchen-linode/issues
61
+ [license]: https://github.com/enter-github-user/kitchen-linode/blob/master/LICENSE
62
+ [repo]: https://github.com/enter-github-user/kitchen-linode
63
+ [driver_usage]: http://docs.kitchen-ci.org/drivers/usage
64
+ [chef_omnibus_dl]: http://www.getchef.com/chef/install/
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require "bundler/gem_tasks"
2
+ require 'cane/rake_task'
3
+ require 'tailor/rake_task'
4
+
5
+ desc "Run cane to check quality metrics"
6
+ Cane::RakeTask.new do |cane|
7
+ cane.canefile = './.cane'
8
+ end
9
+
10
+ Tailor::RakeTask.new
11
+
12
+ desc "Display LOC stats"
13
+ task :stats do
14
+ puts "\n## Production Code Stats"
15
+ sh "countloc -r lib"
16
+ end
17
+
18
+ desc "Run all quality tasks"
19
+ task :quality => [:cane, :tailor, :stats]
20
+
21
+ task :default => [:quality]
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kitchen/driver/linode_version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'kitchen-linode'
8
+ spec.version = Kitchen::Driver::LINODE_VERSION
9
+ spec.authors = ['Brett Taylor']
10
+ spec.email = ['btaylor@linode.com']
11
+ spec.description = %q{A Test Kitchen Driver for Linode}
12
+ spec.summary = spec.description
13
+ spec.homepage = 'https://github.com/ssplatt/kitchen-linode'
14
+ spec.license = 'Apache 2.0'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = []
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'test-kitchen'
22
+ spec.add_dependency 'fog'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.3'
25
+ spec.add_development_dependency 'rake'
26
+
27
+ spec.add_development_dependency 'cane'
28
+ spec.add_development_dependency 'tailor'
29
+ spec.add_development_dependency 'countloc'
30
+ end
@@ -0,0 +1,205 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Brett Taylor (<btaylor@linode.com>)
4
+ #
5
+ # Copyright (C) 2015, Brett Taylor
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
+ require 'kitchen'
20
+ require 'fog'
21
+ require_relative 'linode_version'
22
+
23
+ module Kitchen
24
+
25
+ module Driver
26
+ # Linode driver for Kitchen.
27
+ #
28
+ # @author Brett Taylor <btaylor@linode.com>
29
+ class Linode < Kitchen::Driver::Base
30
+ kitchen_driver_api_version 2
31
+ plugin_version Kitchen::Driver::LINODE_VERSION
32
+
33
+ default_config :username, 'root'
34
+ default_config :password, nil
35
+ default_config(:image) { |driver| driver.default_image }
36
+ default_config :data_center, 1
37
+ default_config :flavor, 1
38
+ default_config :payment_terms, 1
39
+ default_config :ssh_key_name, nil
40
+ default_config :kernel, 215
41
+
42
+ default_config :sudo, true
43
+ default_config :port, 22
44
+
45
+ default_config :private_key, nil
46
+ default_config :private_key_path, "~/.ssh/id_rsa"
47
+ default_config :public_key, nil
48
+ default_config :public_key_path, "~/.ssh/id_rsa.pub"
49
+
50
+ default_config :api_key do
51
+ ENV['LINODE_API_KEY']
52
+ end
53
+
54
+ required_config :api_key
55
+
56
+ def create(state)
57
+ # create and boot server
58
+ config_server_name
59
+
60
+ if state[:server_id]
61
+ info "#{config[:server_name]} (#{state[:server_id]}) already exists."
62
+ return
63
+ end
64
+
65
+ info("Creating Linode.")
66
+
67
+ server = create_server
68
+
69
+ # assign the machine id for reference in other commands
70
+ state[:server_id] = server.id
71
+ state[:hostname] = server.public_ip_address
72
+ info("Linode <#{state[:server_id]}> created.")
73
+ info("Waiting for linode to boot...")
74
+ server.wait_for { ready? }
75
+ info("Linode <#{state[:server_id]}> ready.")
76
+ setup_ssh(server, state) if bourne_shell?
77
+ rescue Fog::Errors::Error, Excon::Errors::Error => ex
78
+ raise ActionFailed, ex.message
79
+ end
80
+
81
+ def destroy(state)
82
+ return if state[:server_id].nil?
83
+ server = compute.servers.get(state[:server_id])
84
+
85
+ server.destroy
86
+
87
+ info("Linode <#{state[:server_id]}> destroyed.")
88
+ state.delete(:server_id)
89
+ state.delete(:hostname)
90
+ end
91
+
92
+ private
93
+
94
+ def compute
95
+ Fog::Compute.new(:provider => 'Linode', :linode_api_key => config[:api_key])
96
+ end
97
+
98
+ def create_server
99
+ if config[:password].nil?
100
+ config[:password] = Digest::SHA2.new.update(config[:api_key]).to_s
101
+ end
102
+
103
+ # set datacenter
104
+ if config[:data_center].is_a? Integer
105
+ data_center = compute.data_centers.find { |dc| dc.id == config[:data_center] }
106
+ else
107
+ data_center = compute.data_centers.find { |dc| dc.location == config[:data_center] }
108
+ if data_center.nil?
109
+ data_center = compute.data_centers.find { |dc| dc.location =~ /#{config[:data_center]}/ }
110
+ end
111
+ end
112
+ if config[:data_center].nil?
113
+ fail(UserError, 'No match for data_center')
114
+ end
115
+
116
+ # set flavor
117
+ if config[:flavor].is_a? Integer
118
+ flavor = compute.flavors.get(config[:flavor])
119
+ else
120
+ flavor = compute.flavors.find { |f| f.ram == config[:flavor] }
121
+ if flavor.nil?
122
+ flavor = compute.flavors.find { |f| f.name == config[:flavor] }
123
+ end
124
+ if flavor.nil?
125
+ flavor = compute.flavors.find { |f| f.name =~ /#{config[:flavor]}/ }
126
+ end
127
+ end
128
+ if config[:flavor].nil?
129
+ fail(UserError, 'No match for flavor')
130
+ end
131
+
132
+ # set image/distribution
133
+ if config[:image].is_a? Integer
134
+ image = compute.images.get(config[:image])
135
+ else
136
+ image = compute.images.find { |i| i.name == config[:image] }
137
+ if image.nil?
138
+ image = compute.images.find { |i| i.name == /#{config[:image]}/ }
139
+ end
140
+ end
141
+ if config[:image].nil?
142
+ fail(UserError, 'No match for image')
143
+ end
144
+
145
+ # set kernel
146
+ if config[:kernel].is_a? Integer
147
+ kernel = compute.kernels.get(config[:kernel])
148
+ else
149
+ kernel = compute.kernels.find { |k| k.name == config[:kernel] }
150
+ if kernel.nil?
151
+ kernel = compute.kernels.find { |k| k.name == /#{config[:kernel]}/ }
152
+ end
153
+ end
154
+ if config[:kernel].nil?
155
+ fail(UserError, 'No match for kernel')
156
+ end
157
+
158
+ if config[:private_key_path]
159
+ config[:private_key_path] = File.expand_path(config[:private_key_path])
160
+ end
161
+ if config[:public_key_path]
162
+ config[:public_key_path] = File.expand_path(config[:public_key_path])
163
+ end
164
+
165
+ # submit new linode request
166
+ compute.servers.create(
167
+ :data_center => data_center,
168
+ :flavor => flavor,
169
+ :payment_terms => config[:payment_terms],
170
+ :name => config[:server_name],
171
+ :image => image,
172
+ :kernel => kernel,
173
+ :username => config[:username],
174
+ :password => config[:password]
175
+ )
176
+ end
177
+
178
+ def setup_ssh(server, state)
179
+ info "Using public SSH key <#{config[:public_key_path]}>"
180
+ info "Using private SSH key <#{config[:private_key_path]}>"
181
+ state[:ssh_key] = config[:private_key_path]
182
+ do_ssh_setup(state, config, server)
183
+ end
184
+
185
+ def do_ssh_setup(state, config, server)
186
+ info "Setting up SSH access for key <#{config[:public_key_path]}>"
187
+ ssh = Fog::SSH.new(state[:hostname],
188
+ config[:username],
189
+ password: config[:password])
190
+ pub_key = open(config[:public_key_path]).read
191
+ ssh.run([
192
+ %(mkdir .ssh),
193
+ %(echo "#{pub_key}" >> ~/.ssh/authorized_keys),
194
+ %(passwd -l #{config[:username]})
195
+ ])
196
+ end
197
+
198
+ # Set the proper server name in the config
199
+ def config_server_name
200
+ return if config[:server_name]
201
+ config[:server_name] = "kitchen_linode-#{rand.to_s.split('.')[1]}"
202
+ end
203
+ end
204
+ end
205
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Brett Taylor (<btaylor@linode.com>)
4
+ #
5
+ # Copyright (C) 2015, Brett Taylor
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
+ module Kitchen
20
+
21
+ module Driver
22
+ # Version string for Linode Kitchen driver
23
+ LINODE_VERSION = "0.1.0"
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kitchen-linode
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brett Taylor
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: test-kitchen
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: fog
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: cane
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'
83
+ - !ruby/object:Gem::Dependency
84
+ name: tailor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: countloc
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: A Test Kitchen Driver for Linode
112
+ email:
113
+ - btaylor@linode.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .cane
119
+ - .gitignore
120
+ - .tailor
121
+ - .travis.yml
122
+ - CHANGELOG.md
123
+ - Gemfile
124
+ - README.md
125
+ - Rakefile
126
+ - kitchen-linode.gemspec
127
+ - lib/kitchen/driver/linode.rb
128
+ - lib/kitchen/driver/linode_version.rb
129
+ homepage: https://github.com/ssplatt/kitchen-linode
130
+ licenses:
131
+ - Apache 2.0
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.0.14
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: A Test Kitchen Driver for Linode
153
+ test_files: []