kitchen-cloudstack 0.1.0

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/.cane ADDED
File without changes
data/.gitignore ADDED
@@ -0,0 +1,20 @@
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
18
+ .idea
19
+ *.log
20
+ logs/
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,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ Author:: Jeff Moody (<fifthecho@gmail.com>)
2
+
3
+ Copyright (C) 2013, Jeff Moody
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,94 @@
1
+ # <a name="title"></a> Kitchen::CloudStack
2
+
3
+ A Test Kitchen Driver for Apache CloudStack / Citrix CloudPlatform.
4
+
5
+ ## <a name="requirements"></a> Requirements
6
+
7
+ This Gem only requires FOG of a version greater than 1.3.1. However, as most of your knife plugins will be using newer
8
+ versions of FOG, that shouldn't be an issue.
9
+
10
+ ## <a name="installation"></a> Installation and Setup
11
+
12
+ Please read the [Driver usage][driver_usage] page for more details.
13
+
14
+ ## <a name="config"></a> Configuration
15
+
16
+ Provide, at a minimum, the required driver options in your `.kitchen.yml` file:
17
+
18
+ driver_plugin: cloudstack
19
+ driver_config:
20
+ cloudstack_api_key: [YOUR CLOUDSTACK API KEY]
21
+ cloudstack_secret_key: [YOUR CLOUDSTACK SECRET KEY]
22
+ cloudstack_api_url: [YOUR CLOUDSTACK API URL]
23
+ require_chef_omnibus: latest (if you'll be using Chef)
24
+
25
+ Then to specify different OS templates,
26
+
27
+ platforms:
28
+ cloudstack_template_id: [INSTANCE TEMPLATE ID]
29
+ cloudstack_serviceoffering_id: [INSTANCE SERVICE OFFERING ID]
30
+ cloudstack_zone_id: [INSTANCE ZONE ID]
31
+ cloudstack_network_id: [NETWORK ID FOR ISOLATED OR VPC NETWORKS]
32
+ cloudstack_security_group_id: [SECURITY GROUP ID FOR SHARED NETWORKS]
33
+ OPTIONAL
34
+ cloudstack_ssh_keypair_name: [SSH KEY NAME]
35
+
36
+ By default, a unique server name will be generated and the randomly generated password will be used, though that
37
+ behavior can be overridden with additional options (e.g., to specify a SSH private key):
38
+
39
+ name: [A UNIQUE SERVER NAME]
40
+ public_key_path: [PATH TO YOUR SSH PUBLIC KEY]
41
+ username: [SSH USER]
42
+ port: [SSH PORT]
43
+
44
+ Only disable SSL cert validation if you absolutely know what you are doing,
45
+ but are stuck with an CloudStack deployment without valid SSL certs.
46
+
47
+ disable_ssl_validation: true
48
+
49
+ ### <a name="config-require-chef-omnibus"></a> require\_chef\_omnibus
50
+
51
+ Determines whether or not a Chef [Omnibus package][chef_omnibus_dl] will be
52
+ installed. There are several different behaviors available:
53
+
54
+ * `true` - the latest release will be installed. Subsequent converges
55
+ will skip re-installing if chef is present.
56
+ * `latest` - the latest release will be installed. Subsequent converges
57
+ will always re-install even if chef is present.
58
+ * `<VERSION_STRING>` (ex: `10.24.0`) - the desired version string will
59
+ be passed the the install.sh script. Subsequent converges will skip if
60
+ the installed version and the desired version match.
61
+ * `false` or `nil` - no chef is installed.
62
+
63
+ The default value is unset, or `nil`.
64
+
65
+ ## <a name="development"></a> Development
66
+
67
+ * Source hosted at [GitHub][repo]
68
+ * Report issues/questions/feature requests on [GitHub Issues][issues]
69
+
70
+ Pull requests are very welcome! Make sure your patches are well tested.
71
+ Ideally create a topic branch for every separate change you make. For
72
+ example:
73
+
74
+ 1. Fork the repo
75
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
76
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
77
+ 4. Push to the branch (`git push origin my-new-feature`)
78
+ 5. Create new Pull Request
79
+
80
+ ## <a name="authors"></a> Authors
81
+
82
+ Created and maintained by [Jeff Moody][author] (<fifthecho@gmail.com>)
83
+
84
+ ## <a name="license"></a> License
85
+
86
+ Apache 2.0 (see [LICENSE][license])
87
+
88
+
89
+ [author]: https://github.com/fifthecho
90
+ [issues]: https://github.com/fifthecho/kitchen-cloudstack/issues
91
+ [license]: https://github.com/fifthecho/kitchen-cloudstack/blob/master/LICENSE
92
+ [repo]: https://github.com/fifthecho/kitchen-cloudstack
93
+ [driver_usage]: http://docs.kitchen-ci.org/drivers/usage
94
+ [chef_omnibus_dl]: http://www.opscode.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/cloudstack_version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'kitchen-cloudstack'
8
+ spec.version = Kitchen::Driver::CLOUDSTACK_VERSION
9
+ spec.authors = ['Jeff Moody']
10
+ spec.email = ['fifthecho@gmail.com']
11
+ spec.description = %q{A Test Kitchen Driver for Cloudstack}
12
+ spec.summary = spec.description
13
+ spec.homepage = 'https://github.com/fifthecho/kitchen-cloudstack'
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', '~> 1.0.0.alpha.3'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake'
25
+
26
+ spec.add_development_dependency 'cane'
27
+ spec.add_development_dependency 'tailor'
28
+ spec.add_development_dependency 'countloc'
29
+ spec.add_dependency 'fog', '>=1.3.1'
30
+ end
@@ -0,0 +1,174 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Jeff Moody (<fifthecho@gmail.com>)
4
+ #
5
+ # Copyright (C) 2013, Jeff Moody
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 'kitchen'
21
+ require 'fog'
22
+ require 'socket'
23
+ require 'net/ssh/multi'
24
+
25
+ module Kitchen
26
+
27
+ module Driver
28
+
29
+ # Cloudstack driver for Kitchen.
30
+ #
31
+ # @author Jeff Moody <fifthecho@gmail.com>
32
+ class Cloudstack < Kitchen::Driver::SSHBase
33
+ default_config :name, nil
34
+ default_config :username, 'root'
35
+ default_config :port, '22'
36
+
37
+ def compute
38
+ cloudstack_uri = URI.parse(config[:cloudstack_api_url])
39
+ connection = Fog::Compute.new(
40
+ :provider => :cloudstack,
41
+ :cloudstack_api_key => config[:cloudstack_api_key],
42
+ :cloudstack_secret_access_key => config[:cloudstack_secret_key],
43
+ :cloudstack_host => cloudstack_uri.host,
44
+ :cloudstack_port => cloudstack_uri.port,
45
+ :cloudstack_path => cloudstack_uri.path,
46
+ :cloudstack_scheme => cloudstack_uri.scheme
47
+ )
48
+
49
+ end
50
+
51
+ def create_server
52
+ options = {}
53
+ options['zoneid'] = config[:cloudstack_zone_id]
54
+ options['templateid'] = config[:cloudstack_template_id]
55
+ options['displayname'] = config[:name]
56
+ options['serviceofferingid'] = config[:cloudstack_serviceoffering_id]
57
+ if (!config[:cloudstack_security_group_id].nil?)
58
+ options['securitygroupids'] = config[:cloudstack_security_group_id]
59
+ end
60
+ if (!config[:cloudstack_network_id].nil?)
61
+ options['networkids'] = config[:cloudstack_security_group_id]
62
+ end
63
+ if (!config[:cloudstack_ssh_keypair_name].nil?)
64
+ options['keypair'] = config[:cloudstack_ssh_keypair_name]
65
+ end
66
+ debug(options)
67
+ compute.deploy_virtual_machine(options)
68
+ end
69
+
70
+ def create(state)
71
+ if not config[:name]
72
+ # Generate what should be a unique server name
73
+ config[:name] = "#{instance.name}-#{Etc.getlogin}-" +
74
+ "#{Socket.gethostname}-#{Array.new(8){rand(36).to_s(36)}.join}"
75
+ end
76
+ if config[:disable_ssl_validation]
77
+ require 'excon'
78
+ Excon.defaults[:ssl_verify_peer] = false
79
+ end
80
+ password = ''
81
+ if (!config[:cloudstack_ssh_keypair_name].nil?)
82
+ keypair = config[:cloudstack_ssh_keypair_name]
83
+ end
84
+ server = create_server
85
+ debug(server)
86
+ state[:server_id] = server['deployvirtualmachineresponse'].fetch('id')
87
+ jobid = server['deployvirtualmachineresponse'].fetch('jobid')
88
+ info("CloudStack instance <#{state[:server_id]}> created.")
89
+ debug("Job ID #{jobid}")
90
+ server_start = compute.query_async_job_result('jobid'=>jobid)
91
+ while server_start['queryasyncjobresultresponse'].fetch('jobstatus') == 0
92
+ print "."
93
+ sleep(10)
94
+ server_start = compute.query_async_job_result('jobid'=>jobid)
95
+ debug("Server_Start: #{server_start} \n")
96
+ end
97
+ if server_start['queryasyncjobresultresponse'].fetch('jobstatus') == 2
98
+ errortext = server_start['queryasyncjobresultresponse'].fetch('jobresult').fetch('errortext')
99
+ error("ERROR! Job failed with #{errortext}")
100
+ end
101
+
102
+ if server_start['queryasyncjobresultresponse'].fetch('jobstatus') == 1
103
+ server_info = server_start['queryasyncjobresultresponse']['jobresult']['virtualmachine']
104
+ debug(server_info)
105
+ puts "\n(server ready)"
106
+ if (server_info.fetch('passwordenabled') == true)
107
+ password = server_info.fetch('password')
108
+ state[:hostname] = server_info.fetch('nic').first.fetch('ipaddress')
109
+ info("Password for #{config[:username]} at #{state[:hostname]} is #{password}")
110
+ ssh = Fog::SSH.new(state[:hostname], config[:username], {:password => password})
111
+ debug(state[:hostname])
112
+ debug(config[:username])
113
+ debug(password)
114
+ tcp_test_ssh(state[:hostname])
115
+ # Installing SSH keys is consistently failing. Not sure why.
116
+ if !(config[:public_key_path].nil?)
117
+ pub_key = open(config[:public_key_path]).read
118
+ # Wait a few moments for the OS to run the cloud-setup-sshkey/password scripts
119
+ sleep(30)
120
+ ssh.run([
121
+ %{mkdir .ssh},
122
+ %{echo "#{pub_key}" >> ~/.ssh/authorized_keys}
123
+ ])
124
+ end
125
+ info("(ssh ready)")
126
+ end
127
+
128
+ end
129
+
130
+ end
131
+
132
+ def destroy(state)
133
+ return if state[:server_id].nil?
134
+
135
+ server = compute.servers.get(state[:server_id])
136
+ server.destroy unless server.nil?
137
+ info("CloudStack instance <#{state[:server_id]}> destroyed.")
138
+ state.delete(:server_id)
139
+ state.delete(:hostname)
140
+ end
141
+
142
+ def tcp_test_ssh(hostname)
143
+ print(".")
144
+ tcp_socket = TCPSocket.new(hostname, 22)
145
+ readable = IO.select([tcp_socket], nil, nil, 5)
146
+ if readable
147
+ debug("\nsshd accepting connections on #{hostname}, banner is #{tcp_socket.gets}\n")
148
+ yield
149
+ true
150
+ else
151
+ false
152
+ end
153
+
154
+ rescue Errno::ETIMEDOUT
155
+ sleep 2
156
+ false
157
+ rescue Errno::EPERM
158
+ false
159
+ rescue Errno::ECONNREFUSED
160
+ sleep 2
161
+ false
162
+ rescue Errno::EHOSTUNREACH
163
+ sleep 2
164
+ false
165
+ rescue Errno::ENETUNREACH
166
+ sleep 30
167
+ false
168
+ ensure
169
+ tcp_socket && tcp_socket.close
170
+ end
171
+
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Jeff Moody (<fifthecho@gmail.com>)
4
+ #
5
+ # Copyright (C) 2013, Jeff Moody
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 Cloudstack Kitchen driver
24
+ CLOUDSTACK_VERSION = "0.1.0"
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kitchen-cloudstack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeff Moody
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-29 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.0.alpha.3
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.0.alpha.3
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
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: cane
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: tailor
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
+ - !ruby/object:Gem::Dependency
95
+ name: countloc
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: fog
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 1.3.1
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: 1.3.1
126
+ description: A Test Kitchen Driver for Cloudstack
127
+ email:
128
+ - fifthecho@gmail.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .cane
134
+ - .gitignore
135
+ - .tailor
136
+ - .travis.yml
137
+ - CHANGELOG.md
138
+ - Gemfile
139
+ - LICENSE
140
+ - README.md
141
+ - Rakefile
142
+ - kitchen-cloudstack.gemspec
143
+ - lib/kitchen/driver/cloudstack.rb
144
+ - lib/kitchen/driver/cloudstack_version.rb
145
+ homepage: https://github.com/fifthecho/kitchen-cloudstack
146
+ licenses:
147
+ - Apache 2.0
148
+ post_install_message:
149
+ rdoc_options: []
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 1.8.24
167
+ signing_key:
168
+ specification_version: 3
169
+ summary: A Test Kitchen Driver for Cloudstack
170
+ test_files: []