kitchen-lxd_cli 0.1.1 → 0.1.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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/kitchen/driver/lxd_cli.rb +3 -3
- data/lib/kitchen/driver/lxd_cli_version.rb +1 -1
- metadata +1 -2
- data/:w +0 -176
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 112756d8089174d8d09c213de838bab91c83e3e0
|
4
|
+
data.tar.gz: c5f39fe2e691968c105ba1cddb90a09d8e0dc468
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 178e25551ee4becf7e0372994ca22195c331769640218a2b0a923fe11f4bde1b06e90a4f61bb87c15ea981dcae1e89c64b2f9241fbb70c63377d45d51feef3b0
|
7
|
+
data.tar.gz: 7694f9f60cc3e1cdccd56b4d1b6e52f8954593e7ca23100a69f405c1e654c46b5eafdd5a951c0a5828e1211ccf02fe113c6a6fb5511596d92c84177882671d11
|
data/README.md
CHANGED
@@ -115,7 +115,7 @@ Current config options:
|
|
115
115
|
* ip_gateway
|
116
116
|
* stop_instead_of_destroy
|
117
117
|
|
118
|
-
public_key_path:
|
118
|
+
public_key_path:
|
119
119
|
|
120
120
|
can be manual set otherwise is derived by default based
|
121
121
|
~/.ssh/ directory, specifically the setting is derived by searching for:
|
@@ -101,9 +101,8 @@ module Kitchen
|
|
101
101
|
image = get_image_info
|
102
102
|
image_os = config[:image_os] ||= image[:os]
|
103
103
|
image_release = config[:image_release] ||= image[:release]
|
104
|
-
|
105
|
-
|
106
|
-
run_local_command("lxd-images import #{image_os} #{image_release} --alias #{image_name}")
|
104
|
+
debug("Ran command: lxd-images import #{image_os} #{image_release} --alias #{image_name}")
|
105
|
+
IO.popen("lxd-images import #{image_os} #{image_release} --alias #{image_name}", "w") { |pipe| puts pipe.gets rescue nil }
|
107
106
|
end
|
108
107
|
return image_name
|
109
108
|
end
|
@@ -166,6 +165,7 @@ module Kitchen
|
|
166
165
|
debug("Setting up the following dns servers via /etc/resolvconf/resolv.conf.d/base:")
|
167
166
|
debug(dns_servers.gsub("\n", ' '))
|
168
167
|
p.puts(" echo \"#{dns_servers.chomp}\" > /etc/resolvconf/resolv.conf.d/base")
|
168
|
+
wait_for_path("/run/resolvconf/interface")
|
169
169
|
p.puts("resolvconf -u")
|
170
170
|
end
|
171
171
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kitchen-lxd_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Braden Wright
|
@@ -106,7 +106,6 @@ files:
|
|
106
106
|
- ".kitchen/logs/kitchen.log"
|
107
107
|
- ".tailor"
|
108
108
|
- ".travis.yml"
|
109
|
-
- ":w"
|
110
109
|
- CHANGELOG.md
|
111
110
|
- Gemfile
|
112
111
|
- LICENSE
|
data/:w
DELETED
@@ -1,176 +0,0 @@
|
|
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
|
-
class LxdCli < Kitchen::Driver::Base
|
30
|
-
kitchen_driver_api_version 2
|
31
|
-
|
32
|
-
default_config :public_key_path do
|
33
|
-
[
|
34
|
-
File.expand_path('~/.ssh/id_rsa.pub'),
|
35
|
-
File.expand_path('~/.ssh/id_dsa.pub'),
|
36
|
-
File.expand_path('~/.ssh/identity.pub'),
|
37
|
-
File.expand_path('~/.ssh/id_ecdsa.pub')
|
38
|
-
].find { |path| File.exist?(path) }
|
39
|
-
end
|
40
|
-
|
41
|
-
required_config :public_key_path
|
42
|
-
|
43
|
-
def create(state)
|
44
|
-
if exists?
|
45
|
-
if running?
|
46
|
-
debug("#{instance.name} already exists, and is already running. Nothing to do")
|
47
|
-
else
|
48
|
-
debug("#{instance.name} already exists, starting instead")
|
49
|
-
run_lxc_command("start #{instance.name}")
|
50
|
-
end
|
51
|
-
else
|
52
|
-
image_name = create_image_if_missing
|
53
|
-
profile = "-p #{config[:profile]}" if config[:profile]
|
54
|
-
lxc_config = "-c #{config[:config]}" if config[:config]
|
55
|
-
run_lxc_command("launch #{image_name} #{instance.name} #{profile} #{lxc_config}")
|
56
|
-
end
|
57
|
-
ip_address(state)
|
58
|
-
setup_ssh_access
|
59
|
-
|
60
|
-
conn(state).execute("touch testing")
|
61
|
-
# instance.transport.connection(state).login_command #fails
|
62
|
-
end
|
63
|
-
|
64
|
-
def destroy(state)
|
65
|
-
if exists?
|
66
|
-
if running?
|
67
|
-
run_lxc_command("stop #{instance.name}")
|
68
|
-
else
|
69
|
-
debug("#{instance.name} isn't running, just destroying instead")
|
70
|
-
end
|
71
|
-
run_lxc_command("delete #{instance.name}")
|
72
|
-
else
|
73
|
-
debug("#{instance.name} doesn't exist. Nothing to do")
|
74
|
-
end
|
75
|
-
state.delete(:hostname)
|
76
|
-
end
|
77
|
-
|
78
|
-
private
|
79
|
-
def exists?
|
80
|
-
status = `lxc info #{instance.name} > /dev/null 2>&1 && echo $?`.chomp
|
81
|
-
if "#{status}" == "0"
|
82
|
-
debug("#{instance.name} exists")
|
83
|
-
return true
|
84
|
-
else
|
85
|
-
debug("#{instance.name} doesn't exist")
|
86
|
-
return false
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def running?
|
91
|
-
status = `lxc info #{instance.name}`.match(/Status: ([a-zA-Z]+)[\n]/).captures[0].upcase
|
92
|
-
if status == "RUNNING"
|
93
|
-
debug("#{instance.name} is running")
|
94
|
-
return true
|
95
|
-
else
|
96
|
-
debug("#{instance.name} isn't running")
|
97
|
-
return false
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def create_image_if_missing
|
102
|
-
image_name = config[:image_name] ||= instance.platform.name
|
103
|
-
status = `lxc image show #{image_name} > /dev/null 2>&1 && echo $?`.chomp
|
104
|
-
if "#{status}" == "0"
|
105
|
-
debug("Image #{image_name} exists")
|
106
|
-
else
|
107
|
-
debug("Image #{image_name} doesn't exist, creating now.")
|
108
|
-
image = get_ubuntu_image_info
|
109
|
-
image_os = config[:image_os] ||= image[:os]
|
110
|
-
image_release = config[:image_release] ||= image[:release]
|
111
|
-
debug("lxd-images import #{image_os} #{image_release} --alias #{image_name}")
|
112
|
-
run_local_command("lxd-images import #{image_os} #{image_release} --alias #{image_name}")
|
113
|
-
end
|
114
|
-
return image_name
|
115
|
-
end
|
116
|
-
|
117
|
-
def get_ubuntu_image_info
|
118
|
-
platform, release = instance.platform.name.split('-')
|
119
|
-
if platform.downcase == "ubuntu"
|
120
|
-
case release.downcase
|
121
|
-
when "14.04", "1404", "trusty", "", nil
|
122
|
-
image = { :os => platform, :release => "trusty" }
|
123
|
-
when "14.10", "1410", "utopic"
|
124
|
-
image = { :os => platform, :release => "utopic" }
|
125
|
-
when "15.04", "1504", "vivid"
|
126
|
-
image = { :os => platform, :release => "vivid" }
|
127
|
-
when "15.10", "1510", "wily"
|
128
|
-
image = { :os => platform, :release => "wily" }
|
129
|
-
when "16.04", "1604", "xenial"
|
130
|
-
image = { :os => platform, :release => "xenial" }
|
131
|
-
else
|
132
|
-
image = { :os => platform, :release => release }
|
133
|
-
end
|
134
|
-
else
|
135
|
-
image = { :os => platform, :release => release }
|
136
|
-
end
|
137
|
-
return image
|
138
|
-
end
|
139
|
-
|
140
|
-
def ip_address(state)
|
141
|
-
debug("start ip")
|
142
|
-
begin
|
143
|
-
lxc_info = `lxc info #{instance.name}`
|
144
|
-
end while (!lxc_info.match(/eth0:[\t]IPV[46][\t]([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*[\n]/))
|
145
|
-
conn(state).execute("-- ifconfig eth0 #{config[:ipv4]} up") if config[:ipv4]
|
146
|
-
# run_local_command("lxc exec #{instance.name} -- ifconfig eth0 #{config[:ipv4]} up") if config[:ipv4]
|
147
|
-
lxc_ip = config[:ipv4] ||= lxc_info.match(/eth0:[\t]IPV[46][\t]([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*[\n]/).captures[0].to_s
|
148
|
-
debug("found ip #{lxc_ip}")
|
149
|
-
state[:hostname] = lxc_ip
|
150
|
-
return lxc_ip
|
151
|
-
end
|
152
|
-
|
153
|
-
def setup_ssh_access
|
154
|
-
info("Copying public key from #{config[:public_key_path]} to #{instance.name}")
|
155
|
-
begin
|
156
|
-
sleep 0.3
|
157
|
-
status = `lxc file push #{config[:public_key_path]} #{instance.name}/root/.ssh/authorized_keys 2> /dev/null && echo $?`.chomp
|
158
|
-
end while ("#{status}" != "0")
|
159
|
-
end
|
160
|
-
|
161
|
-
def run_lxc_command(cmd)
|
162
|
-
# should be moved to transport and run_command used
|
163
|
-
#conn(state).run_lxc_command("stop #{instance.name}")
|
164
|
-
`lxc #{cmd}` if cmd
|
165
|
-
end
|
166
|
-
|
167
|
-
def run_local_command(cmd)
|
168
|
-
`#{cmd}` if cmd
|
169
|
-
end
|
170
|
-
|
171
|
-
def conn(state)
|
172
|
-
return instance.transport.connection(state)
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|