kitchen-lxd_cli 0.1.0.beta

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 90f808190b07d50dd9404d55a80c7e5bdf23fcb6
4
+ data.tar.gz: 6697d367bfd6ebcd472429ac3a63c156a65fc1bc
5
+ SHA512:
6
+ metadata.gz: 760fcae5bb6f14e0d6df9067160f7e0676dc826b6c43dcefb46773fc4902df2a37dbccf8fd8afef5679820f3f662c216977af6d37869cb2ee1a382f645373348
7
+ data.tar.gz: 8217561471842586e3e39492cd6e348dd1c72913904653a30d5a8d620f4a19f0c444eb248b106f089a573a10c956ce67ce0800ca1ff600efb0ed2da86ef109d1
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,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ Author:: Braden Wright (<braden.m.wright@gmail.com>)
2
+
3
+ Copyright (C) 2015, Braden Wright
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,131 @@
1
+ # <a name="title"></a> Kitchen::LxdCli
2
+
3
+ A Test Kitchen Driver for LxdCli.
4
+
5
+ ## <a name="overview"></a> Overview
6
+
7
+ This is a test-kitchen driver for lxd, which controls lxc. I named it LxdCli because this is my first plugin and I wanted to leave LXD driver name in case a more extensive project is put together.
8
+
9
+ Basics are working. I'm running lxd --version 0.20 on ubuntu 15.10.
10
+
11
+ I started the project because I really like the idea of developing containers, but kitchen-lxc wouldn't work with my version. I also tried docker but preferred how lxd is closer to a hypervisor virtual machine. For instance kitchen-docker my recipes that had worked on virtual machies for mongodb, the service would not start when using docker. Ultimately I was interested in LXD and there wasn't anything out there. I was quickly able to get my mongodb recipe working. I figured I'd clean things up, and some features and publish it. At least if someone like me wants to play with lxd, chef, test-kitchen they can test some basics without having to recreate the wheel.
12
+
13
+ I AM VERY OPEN TO SUGGESTIONS/HELP. As I mentioned I haven't written a kitchen driver or published any ruby gems before so I was hesitant to even release it.
14
+
15
+ ```yaml
16
+ ---
17
+ driver:
18
+ name: lxd_cli
19
+ # optional: searches ~/.ssh/ by default for public key
20
+ # public_key_path: "~/.ssh/id_rsa.pub"
21
+
22
+ provisioner:
23
+ name: chef_zero
24
+ # name: nodes
25
+
26
+ platforms:
27
+ # Following 3 will all use the same image (LTS), but it will be named accordingly
28
+ - name: ubuntu-14.04
29
+ - name: ubuntu-1404
30
+ - name: ubuntu-trusty
31
+ # Following 3 will all use the same image (Latest Release as of now), but it will be named accordingly
32
+ - name: ubuntu-15.10
33
+ - name: ubuntu-1510
34
+ - name: ubuntu-wily
35
+ ```
36
+
37
+ As of now if you install lxd, and have a public key setup in ~/.ssh/ then you should be able to use plugin without manual intervention. I have only tested with ubuntu container. What does it do:
38
+
39
+ Kitchen Create
40
+
41
+ 1) Creates image if its missing. If a platform is specified LXD will check if an image with the same name exists, if not it will parse the platform name, and install the appropriate image. If the image exists it will use that image.
42
+
43
+ 2) If container does not exists, creates container. Using the instance name as the container name, and using the image from previous step.
44
+
45
+ 3) If container exists, starts it
46
+
47
+ 4) copies public key from ~/.ssh/ to container /root/.ssh/
48
+
49
+
50
+ Note: if you have troubles with the public key, you can always manually setup public key on container, and publish it to an image. If the image already exists it will not be download via test-kitchen.
51
+
52
+ Kitchen Destroy
53
+
54
+ 1) Stops container if its running
55
+
56
+ 2) Destroys container if it exists
57
+
58
+ LXD Links:
59
+
60
+ [LXD Basics](https://insights.ubuntu.com/2015/03/20/installing-lxd-and-the-command-line-tool/)
61
+
62
+ [LXD Publish Image](https://insights.ubuntu.com/2015/06/30/publishing-lxd-images/)
63
+
64
+ ## <a name="installation"></a> Installation and Setup
65
+
66
+ Please read the [Driver usage][driver_usage] page for more details.
67
+
68
+ ## <a name="config"></a> Configuration
69
+
70
+ public_key_path config can be manual set or is derived by default based
71
+ ~/.ssh/ directory, specifically the setting is derived by searching for:
72
+ - `~/.ssh/id_rsa.pub`
73
+ - `~/.ssh/id_dsa.pub`
74
+ - `~/.ssh/identity.pub`
75
+ - `~/.ssh/id_ecdsa.pub`
76
+
77
+ ### <a name="config-require-chef-omnibus"></a> require\_chef\_omnibus
78
+
79
+ Determines whether or not a Chef [Omnibus package][chef_omnibus_dl] will be
80
+ installed. There are several different behaviors available:
81
+
82
+ * `true` - the latest release will be installed. Subsequent converges
83
+ will skip re-installing if chef is present.
84
+ * `latest` - the latest release will be installed. Subsequent converges
85
+ will always re-install even if chef is present.
86
+ * `<VERSION_STRING>` (ex: `10.24.0`) - the desired version string will
87
+ be passed the the install.sh script. Subsequent converges will skip if
88
+ the installed version and the desired version match.
89
+ * `false` or `nil` - no chef is installed.
90
+
91
+ The default value is unset, or `nil`.
92
+
93
+ ## <a name="roadmap"></a> Roadmap
94
+ * Update/Clean README
95
+ * Config option for remote host, remote user, etc. So lxc can be launched on a remote server, not just locally
96
+ * Config option for adding/using lxc remote command
97
+ * Config option to publish container on verify
98
+ * Config options for static ip, cpu, mem
99
+ * Config option to install upstart (not used by default in containers)
100
+ * Config option for proxy/cache
101
+
102
+ ## <a name="development"></a> Development
103
+
104
+ * Source hosted at [GitHub][repo]
105
+ * Report issues/questions/feature requests on [GitHub Issues][issues]
106
+
107
+ Pull requests are very welcome! Make sure your patches are well tested.
108
+ Ideally create a topic branch for every separate change you make. For
109
+ example:
110
+
111
+ 1. Fork the repo
112
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
113
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
114
+ 4. Push to the branch (`git push origin my-new-feature`)
115
+ 5. Create new Pull Request
116
+
117
+ ## <a name="authors"></a> Authors
118
+
119
+ Created and maintained by [Braden Wright][author] (<braden.m.wright@gmail.com>)
120
+
121
+ ## <a name="license"></a> License
122
+
123
+ Apache 2.0 (see [LICENSE][license])
124
+
125
+
126
+ [author]: https://github.com/enter-github-user
127
+ [issues]: https://github.com/enter-github-user/kitchen-lxd_cli/issues
128
+ [license]: https://github.com/enter-github-user/kitchen-lxd_cli/blob/master/LICENSE
129
+ [repo]: https://github.com/enter-github-user/kitchen-lxd_cli
130
+ [driver_usage]: http://docs.kitchen-ci.org/drivers/usage
131
+ [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,29 @@
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/lxd_cli_version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'kitchen-lxd_cli'
8
+ spec.version = Kitchen::Driver::LXD_CLI_VERSION
9
+ spec.authors = ['Braden Wright']
10
+ spec.email = ['braden.m.wright@gmail.com']
11
+ spec.description = %q{A Test Kitchen Driver for LxdCli}
12
+ spec.summary = spec.description
13
+ spec.homepage = ''
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.4.2'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.10'
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
+ end
@@ -0,0 +1,144 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Braden Wright (<braden.m.wright@gmail.com>)
4
+ #
5
+ # Copyright (C) 2015, Braden Wright
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
+
21
+ module Kitchen
22
+
23
+ module Driver
24
+
25
+ # LxdCli driver for Kitchen.
26
+ #
27
+ # @author Braden Wright <braden.m.wright@gmail.com>
28
+ class LxdCli < Kitchen::Driver::SSHBase
29
+ default_config :public_key_path do
30
+ [
31
+ File.expand_path('~/.ssh/id_rsa.pub'),
32
+ File.expand_path('~/.ssh/id_dsa.pub'),
33
+ File.expand_path('~/.ssh/identity.pub'),
34
+ File.expand_path('~/.ssh/id_ecdsa.pub')
35
+ ].find { |path| File.exist?(path) }
36
+ end
37
+
38
+ def create(state)
39
+ if exists?
40
+ if running?
41
+ debug("#{instance.name} already exists, and is already running. Nothing to do")
42
+ else
43
+ debug("#{instance.name} already exists, starting instead")
44
+ run_command("lxc start #{instance.name}")
45
+ end
46
+ else
47
+ create_image_if_missing
48
+ run_command("lxc launch #{instance.platform.name} #{instance.name}")
49
+ end
50
+ ip_address(state)
51
+ setup_ssh_access
52
+ end
53
+
54
+ def destroy(state)
55
+ if exists?
56
+ if running?
57
+ run_command("lxc stop #{instance.name}")
58
+ else
59
+ debug("#{instance.name} isn't running, just destroying instead")
60
+ end
61
+ run_command("lxc delete #{instance.name}")
62
+ else
63
+ debug("#{instance.name} doesn't exist. Nothing to do")
64
+ end
65
+ state.delete(:hostname)
66
+ end
67
+
68
+ private
69
+ def exists?
70
+ status = `lxc info #{instance.name} > /dev/null 2>&1 && echo $?`.chomp
71
+ if "#{status}" == "0"
72
+ debug("#{instance.name} exists")
73
+ return true
74
+ else
75
+ debug("#{instance.name} doesn't exist")
76
+ return false
77
+ end
78
+ end
79
+
80
+ def running?
81
+ status = `lxc info #{instance.name}`.match(/Status: ([a-zA-Z]+)[\n]/).captures[0].upcase
82
+ if status == "RUNNING"
83
+ debug("#{instance.name} is running")
84
+ return true
85
+ else
86
+ debug("#{instance.name} isn't running")
87
+ return false
88
+ end
89
+ end
90
+
91
+ def create_image_if_missing
92
+ status = `lxc image show #{instance.name} > /dev/null 2>&1 && echo $?`.chomp
93
+ if "#{status}" == "0"
94
+ debug("Image #{instance.name} exists")
95
+ return false
96
+ else
97
+ debug("Image #{instance.name} doesn't exist, creating now.")
98
+ image = get_ubuntu_image_info
99
+ debug("lxd-images import #{image[:os]} #{image[:release]} --alias #{instance.platform.name}")
100
+ run_command("lxd-images import #{image[:os]} #{image[:release]} --alias #{instance.platform.name}")
101
+ return true
102
+ end
103
+ end
104
+
105
+ def get_ubuntu_image_info
106
+ platform, release = instance.platform.name.split('-')
107
+ if platform.downcase == "ubuntu"
108
+ case release.downcase
109
+ when "14.04", "1404", "trusty", "", nil
110
+ image = { :os => platform, :release => "trusty" }
111
+ when "14.10", "1410", "utopic"
112
+ image = { :os => platform, :release => "utopic" }
113
+ when "15.04", "1504", "vivid"
114
+ image = { :os => platform, :release => "vivid" }
115
+ when "15.10", "1510", "wily"
116
+ image = { :os => platform, :release => "wily" }
117
+ when "16.04", "1604", "xenial"
118
+ image = { :os => platform, :release => "xenial" }
119
+ else
120
+ image = { :os => platform, :release => release }
121
+ end
122
+ return image
123
+ end
124
+ end
125
+
126
+ def ip_address(state)
127
+ begin
128
+ lxc_info = `lxc info #{instance.name}`
129
+ end while (!lxc_info.match(/eth0:[\t]IPV[46][\t]([0-9.]+)[\n]/))
130
+ lxc_ip = lxc_info.match(/eth0:[\t]IPV[46][\t]([0-9.]+)[\n]/).captures[0].to_s
131
+ state[:hostname] = lxc_ip
132
+ return lxc_ip
133
+ end
134
+
135
+ def setup_ssh_access
136
+ info("Copying public key from #{config[:public_key_path]} to #{instance.name}")
137
+ begin
138
+ sleep 1
139
+ status = `lxc file push #{config[:public_key_path]} #{instance.name}/root/.ssh/authorized_keys 2> /dev/null && echo $?`.chomp
140
+ end while ("#{status}" != "0")
141
+ end
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Braden Wright (<braden.m.wright@gmail.com>)
4
+ #
5
+ # Copyright (C) 2015, Braden Wright
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 LxdCli Kitchen driver
24
+ LXD_CLI_VERSION = "0.1.0.beta"
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kitchen-lxd_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.beta
5
+ platform: ruby
6
+ authors:
7
+ - Braden Wright
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-30 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: 1.4.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.4.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: cane
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: tailor
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: countloc
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
+ description: A Test Kitchen Driver for LxdCli
98
+ email:
99
+ - braden.m.wright@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".cane"
105
+ - ".gitignore"
106
+ - ".tailor"
107
+ - ".travis.yml"
108
+ - CHANGELOG.md
109
+ - Gemfile
110
+ - LICENSE
111
+ - README.md
112
+ - Rakefile
113
+ - kitchen-lxd_cli.gemspec
114
+ - lib/kitchen/driver/lxd_cli.rb
115
+ - lib/kitchen/driver/lxd_cli_version.rb
116
+ homepage: ''
117
+ licenses:
118
+ - Apache 2.0
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">"
132
+ - !ruby/object:Gem::Version
133
+ version: 1.3.1
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.4.8
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: A Test Kitchen Driver for LxdCli
140
+ test_files: []
141
+ has_rdoc: