kitchen-lxd_api 0.0.1
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 +7 -0
- data/.cane +0 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.tailor +4 -0
- data/.travis.yml +11 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +3 -0
- data/LICENSE +15 -0
- data/README.md +123 -0
- data/Rakefile +5 -0
- data/kitchen-lxd_api.gemspec +32 -0
- data/lib/kitchen/driver/lxd_api.rb +151 -0
- data/lib/kitchen/driver/lxd_api_version.rb +10 -0
- data/spec/kitchen/driver/lxd_api_spec.rb +16 -0
- data/spec/spec_helper.rb +3 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 68f3b535b8bf262eed596aa77e0792a619fc2e0c
|
4
|
+
data.tar.gz: f8f76dd47686147b237b3eae12f3b0c2a4ca830f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fb8409e7515f22a07b349181d5679f587b615c4cdbc8310499c296cbb43eaeae131836dd2a6322221b25c30059cb82704253093d1635a1cbcfa29fe702f3eb9e
|
7
|
+
data.tar.gz: 5ceb283e0051f7a82ae6e359ee3385f312f15fd60231c4c8948ab0879dbd13e8d6028b7024f9d3610338c565a8eb1a8467c1926678100bec4b078accc7ecba70
|
data/.cane
ADDED
File without changes
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.tailor
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Author:: TODO: Write your name (<inokara@gmail.com>)
|
2
|
+
|
3
|
+
Copyright (C) 2015, TODO: Write your name
|
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,123 @@
|
|
1
|
+
# Kitchen::Driver::LxdApi
|
2
|
+
[](https://travis-ci.org/inokappa/kitchen-lxd_api)
|
3
|
+
|
4
|
+
A Test Kitchen Driver for LXD REST API.
|
5
|
+
|
6
|
+
## Attention
|
7
|
+
|
8
|
+
- Made for myself
|
9
|
+
- Testing and implementation a not enough
|
10
|
+
|
11
|
+
## Reference
|
12
|
+
|
13
|
+
- [LXD REST API](https://github.com/lxc/lxd/blob/master/specs/rest-api.md)
|
14
|
+
- [bradenwright/kitchen-lxd_cli](https://github.com/bradenwright/kitchen-lxd_cli)
|
15
|
+
|
16
|
+
## Requirements
|
17
|
+
|
18
|
+
- [LXD](https://linuxcontainers.org/)
|
19
|
+
- [Oreno LXD REST API Client](https://github.com/inokappa/oreno_lxdapi)
|
20
|
+
|
21
|
+
## Installation and Setup
|
22
|
+
|
23
|
+
### Install kitchen driver
|
24
|
+
|
25
|
+
```sh
|
26
|
+
$ git clone https://github.com/inokappa/kitchen-lxd_api.git
|
27
|
+
$ cd kitchen-lxd_api
|
28
|
+
$ bundle install
|
29
|
+
```
|
30
|
+
|
31
|
+
## Configuration
|
32
|
+
|
33
|
+
### Create Container image
|
34
|
+
|
35
|
+
```sh
|
36
|
+
$ lxc remote add images images.linuxcontainers.org
|
37
|
+
$ lxc launch images:ubuntu/trusty/amd64 oreno-ubuntu
|
38
|
+
$ lxc exec oreno-ubuntu -- apt-get -y install openssh-server
|
39
|
+
$ lxc stop oreno-ubuntu
|
40
|
+
$ lxc publish oreno-ubuntu --alias=oreno-ubuntu-image
|
41
|
+
```
|
42
|
+
|
43
|
+
### .kitchen.yml
|
44
|
+
|
45
|
+
```yaml
|
46
|
+
---
|
47
|
+
driver:
|
48
|
+
name: lxd_api
|
49
|
+
|
50
|
+
provisioner:
|
51
|
+
name: ansible_playbook
|
52
|
+
roles_path: roles
|
53
|
+
# require_chef_for_busser: false
|
54
|
+
# require_ruby_for_busser: true
|
55
|
+
|
56
|
+
platforms:
|
57
|
+
- name: oreno-ubuntu-14.04
|
58
|
+
driver_plugin: lxd_api
|
59
|
+
driver_config:
|
60
|
+
container_image: oreno-ubuntu-image
|
61
|
+
container_name: kitchen-container
|
62
|
+
#
|
63
|
+
# Optional
|
64
|
+
#
|
65
|
+
# username: kitchen
|
66
|
+
# architecture: 2
|
67
|
+
# profiles: ["default"]
|
68
|
+
# ephemeral: false
|
69
|
+
# limits_cpu: "1"
|
70
|
+
# timeout: 30
|
71
|
+
# force: true
|
72
|
+
|
73
|
+
suites:
|
74
|
+
- name: default
|
75
|
+
provisioner:
|
76
|
+
playbook: default.yml
|
77
|
+
hosts: default
|
78
|
+
|
79
|
+
verifier:
|
80
|
+
name: shell
|
81
|
+
command: rspec -c -f d -I serverspec serverspec/common_spec.rb
|
82
|
+
|
83
|
+
```
|
84
|
+
|
85
|
+
## Let's tasting...
|
86
|
+
|
87
|
+
```sh
|
88
|
+
$ kitchen create
|
89
|
+
$ kitchen converge
|
90
|
+
$ kitchen verify
|
91
|
+
$ kitchen destroy
|
92
|
+
```
|
93
|
+
|
94
|
+
## Development
|
95
|
+
|
96
|
+
* Source hosted at [GitHub][repo]
|
97
|
+
* Report issues/questions/feature requests on [GitHub Issues][issues]
|
98
|
+
|
99
|
+
Pull requests are very welcome! Make sure your patches are well tested.
|
100
|
+
Ideally create a topic branch for every separate change you make. For
|
101
|
+
example:
|
102
|
+
|
103
|
+
1. Fork the repo
|
104
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
105
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
106
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
107
|
+
5. Create new Pull Request
|
108
|
+
|
109
|
+
## Authors
|
110
|
+
|
111
|
+
Created and maintained by inokappa
|
112
|
+
|
113
|
+
## License
|
114
|
+
|
115
|
+
Apache 2.0 (see [LICENSE][license])
|
116
|
+
|
117
|
+
|
118
|
+
[author]: https://github.com/enter-github-user
|
119
|
+
[issues]: https://github.com/enter-github-user/kitchen-lxd_api/issues
|
120
|
+
[license]: https://github.com/enter-github-user/kitchen-lxd_api/blob/master/LICENSE
|
121
|
+
[repo]: https://github.com/enter-github-user/kitchen-lxd_api
|
122
|
+
[driver_usage]: http://docs.kitchen-ci.org/drivers/usage
|
123
|
+
[chef_omnibus_dl]: http://www.getchef.com/chef/install/
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
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_api_version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'kitchen-lxd_api'
|
8
|
+
spec.version = Kitchen::Driver::LXD_API_VERSION
|
9
|
+
spec.authors = ['inokappa']
|
10
|
+
spec.email = ['inokara at gmail.com']
|
11
|
+
spec.description = %q{A Test Kitchen Driver for LxdApi}
|
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'
|
22
|
+
spec.add_dependency 'oreno_lxdapi'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "pry"
|
28
|
+
|
29
|
+
#spec.add_development_dependency 'cane'
|
30
|
+
#spec.add_development_dependency 'tailor'
|
31
|
+
#spec.add_development_dependency 'countloc'
|
32
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'kitchen'
|
4
|
+
require 'oreno_lxdapi'
|
5
|
+
|
6
|
+
module Kitchen
|
7
|
+
|
8
|
+
module Driver
|
9
|
+
|
10
|
+
#
|
11
|
+
# LxdApi driver for Kitchen.
|
12
|
+
# Be unrefined!!!!!!!! :-<
|
13
|
+
#
|
14
|
+
|
15
|
+
class LxdApi < Kitchen::Driver::Base
|
16
|
+
kitchen_driver_api_version 2
|
17
|
+
|
18
|
+
default_config :uri, "unix:///var/lib/lxd/unix.socket"
|
19
|
+
|
20
|
+
default_config :container_image, nil
|
21
|
+
default_config :container_name, nil
|
22
|
+
default_config :username, "root"
|
23
|
+
default_config :public_key_path, "#{ENV["HOME"]}/.ssh/id_rsa.pub"
|
24
|
+
default_config :authorized_keys_path, "/.ssh/authorized_keys"
|
25
|
+
|
26
|
+
|
27
|
+
def create(state)
|
28
|
+
|
29
|
+
#
|
30
|
+
# config[:architecture] = 2
|
31
|
+
# config[:profiles] = ["default"]
|
32
|
+
# config[:ephemeral] = true
|
33
|
+
# config[:limits_cpu] = "1"
|
34
|
+
#
|
35
|
+
puts "Create Container..."
|
36
|
+
container.create_container(
|
37
|
+
:architecture => config[:architecture],
|
38
|
+
:profiles => config[:profiles],
|
39
|
+
:ephemeral => config[:ephemeral],
|
40
|
+
:limits_cpu => config[:limits_cpu]
|
41
|
+
)
|
42
|
+
|
43
|
+
sleep 5
|
44
|
+
|
45
|
+
#
|
46
|
+
# config[:timeout] = 30
|
47
|
+
# config[:force] = true
|
48
|
+
#
|
49
|
+
puts "Run Container..."
|
50
|
+
container.state_container(
|
51
|
+
"start",
|
52
|
+
:timeout => config[:timeout],
|
53
|
+
:force => config[:force]
|
54
|
+
)
|
55
|
+
|
56
|
+
puts "Set Username and Upload Public key..."
|
57
|
+
unless config[:username] == "root"
|
58
|
+
create_user
|
59
|
+
end
|
60
|
+
state[:username] = config[:username]
|
61
|
+
container.run_lxc_exec(
|
62
|
+
"mkdir #{set_user_home_dir_path(state[:username])}/.ssh"
|
63
|
+
)
|
64
|
+
container.file_upload(
|
65
|
+
config[:public_key_path],
|
66
|
+
set_ssh_authorized_keys_path(state[:username])
|
67
|
+
)
|
68
|
+
|
69
|
+
puts "Change Permission..."
|
70
|
+
container.run_lxc_exec(
|
71
|
+
"chown -R #{state[:username]}:#{state[:username]} #{set_user_home_dir_path(state[:username])}/.ssh"
|
72
|
+
)
|
73
|
+
container.run_lxc_exec(
|
74
|
+
"chmod 700 #{set_user_home_dir_path(state[:username])}/.ssh"
|
75
|
+
)
|
76
|
+
container.run_lxc_exec(
|
77
|
+
"chmod 600 #{set_ssh_authorized_keys_path(state[:username])}"
|
78
|
+
)
|
79
|
+
|
80
|
+
puts "Describe Container..."
|
81
|
+
metadata = container.describe_container
|
82
|
+
state[:status] = metadata['status']['status']
|
83
|
+
state[:ephemeral] = metadata['ephemeral'].to_s
|
84
|
+
metadata['status']['ips'].each do |ip|
|
85
|
+
if ip['interface'] == "eth0"
|
86
|
+
state[:hostname] = ip['address']
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def destroy(state)
|
92
|
+
|
93
|
+
# config[:timeout] = 30
|
94
|
+
# config[:force] = true
|
95
|
+
#
|
96
|
+
puts "Destroy Container..."
|
97
|
+
if state[:ephemeral] == "true"
|
98
|
+
container.state_container(
|
99
|
+
"stop",
|
100
|
+
:timeout => config[:timeout],
|
101
|
+
:force => config[:force]
|
102
|
+
)
|
103
|
+
elsif state[:ephemeral] == "false"
|
104
|
+
container.state_container(
|
105
|
+
"stop",
|
106
|
+
:timeout => config[:timeout],
|
107
|
+
:force => config[:force]
|
108
|
+
)
|
109
|
+
sleep 5
|
110
|
+
container.delete_container
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
def container
|
117
|
+
OrenoLxdapi::Client.new(
|
118
|
+
config[:uri],
|
119
|
+
config[:container_image],
|
120
|
+
config[:container_name]
|
121
|
+
)
|
122
|
+
end
|
123
|
+
|
124
|
+
def set_ssh_authorized_keys_path(username)
|
125
|
+
if username == "root"
|
126
|
+
return "/root" + "#{config[:authorized_keys_path]}"
|
127
|
+
else
|
128
|
+
return "/home/#{username}" + "#{config[:authorized_keys_path]}"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def set_user_home_dir_path(username)
|
133
|
+
if username == "root"
|
134
|
+
return "/root"
|
135
|
+
else
|
136
|
+
return "/home/#{username}"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def create_user
|
141
|
+
container.run_lxc_exec(
|
142
|
+
"useradd -m -G sudo #{config[:username]} -s /bin/bash"
|
143
|
+
)
|
144
|
+
container.run_lxc_exec(
|
145
|
+
"sh -c \"echo '#{config[:username]} ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers\""
|
146
|
+
)
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kitchen-lxd_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- inokappa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-02 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: oreno_lxdapi
|
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: rspec
|
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: pry
|
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 LxdApi
|
98
|
+
email:
|
99
|
+
- inokara at gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".cane"
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".tailor"
|
108
|
+
- ".travis.yml"
|
109
|
+
- CHANGELOG.md
|
110
|
+
- Gemfile
|
111
|
+
- LICENSE
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- kitchen-lxd_api.gemspec
|
115
|
+
- lib/kitchen/driver/lxd_api.rb
|
116
|
+
- lib/kitchen/driver/lxd_api_version.rb
|
117
|
+
- spec/kitchen/driver/lxd_api_spec.rb
|
118
|
+
- spec/spec_helper.rb
|
119
|
+
homepage: ''
|
120
|
+
licenses:
|
121
|
+
- Apache 2.0
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.2.2
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: A Test Kitchen Driver for LxdApi
|
143
|
+
test_files:
|
144
|
+
- spec/kitchen/driver/lxd_api_spec.rb
|
145
|
+
- spec/spec_helper.rb
|