kitchen-vsphere 0.1.0.alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,106 @@
1
+ #------------------------------------------------------------------------------
2
+ # Horizontal Whitespace
3
+ #------------------------------------------------------------------------------
4
+ # allow_hard_tabs True to let hard tabs be considered a single space.
5
+ # Default: false
6
+ #
7
+ # allow_trailing_line_spaces
8
+ # True to skip detecting extra spaces at the ends of
9
+ # lines.
10
+ # Default: false
11
+ #
12
+ # indentation_spaces The number of spaces to consider a proper indent.
13
+ # Default: 2
14
+ #
15
+ # max_line_length The maximum number of characters in a line before
16
+ # tailor complains.
17
+ # Default: 80
18
+ # spaces_after_comma Number of spaces to expect after a comma.
19
+ # Default: 1
20
+ #
21
+ # spaces_before_comma Number of spaces to expect before a comma.
22
+ # Default: 0
23
+ #
24
+ # spaces_after_lbrace The number of spaces to expect after an lbrace ('{').
25
+ # Default: 1
26
+ #
27
+ # spaces_before_lbrace The number of spaces to expect before an lbrace ('{').
28
+ # Default: 1
29
+ #
30
+ # spaces_before_rbrace The number of spaces to expect before an rbrace ('}').
31
+ # Default: 1
32
+ #
33
+ # spaces_in_empty_braces The number of spaces to expect between braces when
34
+ # there's nothing in the braces (i.e. {}).
35
+ # Default: 0
36
+ #
37
+ # spaces_after_lbracket The number of spaces to expect after an
38
+ # lbracket ('[').
39
+ # Default: 0
40
+ #
41
+ # spaces_before_rbracket The number of spaces to expect before an
42
+ # rbracket (']').
43
+ # Default: 0
44
+ #
45
+ # spaces_after_lparen The number of spaces to expect after an
46
+ # lparen ('(').
47
+ # Default: 0
48
+ #
49
+ # spaces_before_rparen The number of spaces to expect before an
50
+ # rbracket (')').
51
+ # Default: 0
52
+ #
53
+ #------------------------------------------------------------------------------
54
+ # Naming
55
+ #------------------------------------------------------------------------------
56
+ # allow_camel_case_methods
57
+ # Setting to true skips detection of camel-case method
58
+ # names (i.e. def myMethod).
59
+ # Default: false
60
+ #
61
+ # allow_screaming_snake_case_classes
62
+ # Setting to true skips detection of screaming
63
+ # snake-case class names (i.e. My_Class).
64
+ # Default: false
65
+ #
66
+ #------------------------------------------------------------------------------
67
+ # Vertical Whitespace
68
+ #------------------------------------------------------------------------------
69
+ # max_code_lines_in_class The number of lines of code in a class to allow before
70
+ # tailor will warn you.
71
+ # Default: 300
72
+ #
73
+ # max_code_lines_in_method
74
+ # The number of lines of code in a method to allow
75
+ # before tailor will warn you.
76
+ # Default: 30
77
+ #
78
+ # trailing_newlines The number of newlines that should be at the end of
79
+ # the file.
80
+ # Default: 1
81
+ #
82
+ Tailor.config do |config|
83
+ config.formatters "text"
84
+ config.file_set 'lib/**/*.rb' do |style|
85
+ style.allow_camel_case_methods false, level: :error
86
+ style.allow_hard_tabs false, level: :error
87
+ style.allow_screaming_snake_case_classes false, level: :error
88
+ style.allow_trailing_line_spaces false, level: :error
89
+ style.allow_invalid_ruby false, level: :warn
90
+ style.indentation_spaces 2, level: :error
91
+ style.max_code_lines_in_class 300, level: :error
92
+ style.max_code_lines_in_method 30, level: :error
93
+ style.max_line_length 100, level: :error
94
+ style.spaces_after_comma 1, level: :off
95
+ style.spaces_after_lbrace 1, level: :error
96
+ style.spaces_after_lbracket 0, level: :error
97
+ style.spaces_after_lparen 0, level: :error
98
+ style.spaces_before_comma 0, level: :error
99
+ style.spaces_before_lbrace 1, level: :off
100
+ style.spaces_before_rbrace 1, level: :error
101
+ style.spaces_before_rbracket 0, level: :error
102
+ style.spaces_before_rparen 0, level: :error
103
+ style.spaces_in_empty_braces 0, level: :error
104
+ style.trailing_newlines 1, level: :error
105
+ end
106
+ end
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.1.0 / Unreleased
2
+
3
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kitchen-vsphere.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'rake'
8
+ gem 'pry'
9
+ end
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ Author:: Matt Wrock (<matt@mattwrock.com>)
2
+
3
+ # Copyright (C) 2014, Matt Wrock
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # <a name="title"></a> Kitchen::Vsphere: A Test Kitchen Driver for VMWare vSphere
2
+
3
+ A [Test Kitchen](https://kitchen.ci/) Driver for VMWare vSphere
4
+
5
+ This driver uses the [fog gem](https://rubygems.org/gems/fog) to provision and destroy VMWare vSphere instances. Use your own vSphere host for your infrastructure testing!
6
+
7
+ Shamelessly copied from [Fletcher Nichol](https://github.com/fnichol)'s
8
+ awesome work on an [EC2 driver](https://github.com/opscode/kitchen-ec2).
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'kitchen-vsphere'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install kitchen-vsphere
23
+
24
+ ## Usage
25
+
26
+ Provide, at a minimum, the required driver options in your `.kitchen.yml` file:
27
+
28
+ driver_plugin: vsphere
29
+ driver_config:
30
+ username: [ssh user name of provisioned guest (default is root)]
31
+ password: [ssh password of provisioned guest]
32
+ authentication:
33
+ vsphere_username: [your vsphere server user name]
34
+ vsphere_password: [your vsphere server password]
35
+ vsphere_server: [your vsphere server host name]
36
+ vsphere_expected_pubkey_hash: [hash of your hosts public ssl key]
37
+ server_create:
38
+ datacenter: [vsphere datacenter name where template is located]
39
+ network_label: [vsphere network name to use]
40
+ network_adapter_device_key: [network key]
41
+ template_path: [path to the template of vm to clone]
42
+
43
+ The `template-path` option can be specified as a template name or vm name. The path should include the folder path relative th the `datacenter`.
44
+
45
+ By default, a unique server name will be generated and the current user's RSA SSH key will be used.
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Run style checks and RSpec tests (`bundle exec rake`)
52
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 5. Push to the branch (`git push origin my-new-feature`)
54
+ 6. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require "bundler/gem_tasks"
2
+ require 'cane/rake_task'
3
+ require 'tailor/rake_task'
4
+
5
+ Cane::RakeTask.new
6
+
7
+ Tailor::RakeTask.new
8
+
9
+ desc "Display LOC stats"
10
+ task :stats do
11
+ puts "\n## Production Code Stats"
12
+ sh "countloc -r lib/kitchen"
13
+ end
14
+
15
+ desc "Run all quality tasks"
16
+ task :quality => [:cane, :tailor, :stats]
17
+
18
+ task :default => [:quality]
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kitchen/driver/vsphere_version.rb'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "kitchen-vsphere"
8
+ gem.version = Kitchen::Driver::VSPHERE_VERSION
9
+ gem.license = 'Apache 2.0'
10
+ gem.authors = ["Matt Wrock"]
11
+ gem.email = ["matt@mattwrock.com"]
12
+ gem.description = "A Test Kitchen Driver for VMWare vShere"
13
+ gem.summary = gem.description
14
+ gem.homepage = "https://github.com/mwrock/kitchen-vsphere"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = []
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_dependency 'test-kitchen', '~> 1.0'
22
+ gem.add_dependency 'fog'
23
+
24
+ gem.add_development_dependency 'cane'
25
+ gem.add_development_dependency 'tailor'
26
+ gem.add_development_dependency 'countloc'
27
+ end
@@ -0,0 +1,125 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Matt Wrock (<matt@mattwrock.com>)
4
+ #
5
+ # Copyright (C) 2014, Matt Wrock
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 'benchmark'
20
+ require 'fog'
21
+ require 'kitchen'
22
+ require 'etc'
23
+ require 'ipaddr'
24
+ require 'socket'
25
+
26
+ module Kitchen
27
+ module Driver
28
+ # Vsphere driver for Kitchen.
29
+ class Vsphere < Kitchen::Driver::SSHBase
30
+ default_config :public_key_path, File.expand_path('~/.ssh/id_rsa.pub')
31
+ default_config :username, 'root'
32
+ default_config :port, '22'
33
+ default_config :use_ipv6, false
34
+ default_config :upload_public_ssh_key, true
35
+
36
+ def create(state)
37
+ config[:server_name] ||= generate_name(instance.name)
38
+ server = create_server(state)
39
+ state[:hostname] = server.ipaddress
40
+ wait_for_sshd(state[:hostname], config[:username],
41
+ { :port => config[:port] }) ; info '(ssh ready)'
42
+ if config[:upload_public_ssh_key]
43
+ upload_public_ssh_key(state, config, server)
44
+ end
45
+ rescue ::Fog::Errors::Error, Excon::Errors::Error => ex
46
+ raise ActionFailed, ex.message
47
+ end
48
+
49
+ def destroy(state)
50
+ return if state[:server_id].nil?
51
+
52
+ server = compute.servers.get(state[:server_id])
53
+ server.destroy unless server.nil?
54
+ info "VSphere instance <#{state[:server_id]}> destroyed."
55
+ state.delete(:server_id)
56
+ state.delete(:hostname)
57
+ end
58
+
59
+ private
60
+
61
+ def compute
62
+ config[:authentication][:provider] = 'vsphere'
63
+ ::Fog::Compute.new(config[:authentication].dup)
64
+ end
65
+
66
+ def convert_to_strings(objay)
67
+ if objay.kind_of?(Array)
68
+ objay.map { |v| convert_to_strings(v) }
69
+ elsif objay.kind_of?(Hash)
70
+ Hash[objay.map { |(k, v)| [k.to_s, convert_to_strings(v)] }]
71
+ else
72
+ objay
73
+ end
74
+ end
75
+
76
+ def create_server(state)
77
+ server_configed = config[:server_create] || {}
78
+ server_configed = server_configed.dup
79
+ server_configed[:name] = config[:server_name]
80
+ server_configed = convert_to_strings(server_configed)
81
+ clone_results = compute.vm_clone(server_configed)
82
+ server = compute.servers.get(clone_results['new_vm']['id'])
83
+ state[:server_id] = server.id
84
+ info "VSphere instance <#{state[:server_id]}> created."
85
+ server.wait_for { print '.'; tools_state != 'toolsNotRunning' }
86
+ puts "\n(server ready)"
87
+ server
88
+ end
89
+
90
+ def generate_name(base)
91
+ # Generate what should be a unique server name
92
+ sep = '-'
93
+ pieces = [
94
+ base,
95
+ Etc.getlogin,
96
+ Socket.gethostname,
97
+ Array.new(8) { rand(36).to_s(36) }.join
98
+ ]
99
+ until pieces.join(sep).length <= 64 do
100
+ if pieces[2].length > 24
101
+ pieces[2] = pieces[2][0..-2]
102
+ elsif pieces[1].length > 16
103
+ pieces[1] = pieces[1][0..-2]
104
+ elsif pieces[0].length > 16
105
+ pieces[0] = pieces[0][0..-2]
106
+ end
107
+ end
108
+ pieces.join sep
109
+ end
110
+
111
+ def upload_public_ssh_key(state, config, server)
112
+ ssh = ::Fog::SSH.new(state[:hostname], config[:username],
113
+ { :password => config[:password] })
114
+ pub_key = open(config[:public_key_path]).read
115
+ ssh.run([
116
+ %{mkdir .ssh},
117
+ %{echo "#{pub_key}" >> ~/.ssh/authorized_keys},
118
+ %{passwd -l #{config[:username]}}
119
+ ])
120
+ end
121
+ end
122
+ end
123
+ end
124
+
125
+ # vim: ai et ts=2 sts=2 sw=2 ft=ruby
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Matt Wrock (<matt@mattwrock.com>)
4
+ #
5
+ # Copyright (C) 2014, Matt Wrock
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
+
23
+ # Version string for vsphere Test Kitchen driver
24
+ VSPHERE_VERSION = '0.1.0.alpha.2'
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kitchen-vsphere
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.alpha.2
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Matt Wrock
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-05-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: test-kitchen
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: fog
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: cane
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: tailor
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: countloc
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: A Test Kitchen Driver for VMWare vShere
95
+ email:
96
+ - matt@mattwrock.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - .tailor
103
+ - .travis.yml
104
+ - CHANGELOG.md
105
+ - Gemfile
106
+ - LICENSE
107
+ - README.md
108
+ - Rakefile
109
+ - kitchen-vsphere.gemspec
110
+ - lib/kitchen/driver/vsphere.rb
111
+ - lib/kitchen/driver/vsphere_version.rb
112
+ homepage: https://github.com/mwrock/kitchen-vsphere
113
+ licenses:
114
+ - Apache 2.0
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ! '>'
129
+ - !ruby/object:Gem::Version
130
+ version: 1.3.1
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 1.8.28
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: A Test Kitchen Driver for VMWare vShere
137
+ test_files: []
138
+ has_rdoc: