kitchen-libvirtlxc 0.1.0 → 0.2.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/kitchen-libvirtlxc.gemspec +1 -1
- data/lib/kitchen/driver/libvirtlxc.rb +16 -5
- metadata +3 -3
data/kitchen-libvirtlxc.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
Gem::Specification.new do |spec|
|
3
3
|
spec.name = "kitchen-libvirtlxc"
|
4
|
-
spec.version = "0.
|
4
|
+
spec.version = "0.2.0"
|
5
5
|
spec.authors = ["Adam Jacob"]
|
6
6
|
spec.email = ["adam@opscode.com"]
|
7
7
|
spec.description = %q{Kitchen driver for libvirt LXC containers}
|
@@ -17,6 +17,7 @@ module Kitchen
|
|
17
17
|
|
18
18
|
def create(state)
|
19
19
|
state[:container_id] = SecureRandom.uuid
|
20
|
+
info("Creating LXC container #{state[:container_id]}")
|
20
21
|
new_container = File.join(config[:container_path], state[:container_id])
|
21
22
|
state[:container_path] = new_container
|
22
23
|
run_command("cp -r #{File.join(config[:container_path], config[:base_container])} #{new_container}")
|
@@ -24,9 +25,9 @@ module Kitchen
|
|
24
25
|
run_command("chmod 0700 #{new_container}/root/.ssh")
|
25
26
|
run_command("cat #{config[:ssh_public_key]} >> #{new_container}/root/.ssh/authorized_keys")
|
26
27
|
run_command("chmod 0644 #{new_container}/root/.ssh/authorized_keys")
|
27
|
-
fixup_files(container_id, new_container)
|
28
|
+
fixup_files(state[:container_id], new_container)
|
28
29
|
run_command("virt-install --connect lxc:/// --name #{state[:container_id]} --ram #{config[:customize][:memory]} --vcpu #{config[:customize][:vcpu]} --filesystem #{new_container}/,/ --noautoconsole")
|
29
|
-
run_command("virsh --connect lxc:/// start #{state[:container_id]}")
|
30
|
+
run_command("virsh --connect lxc:/// start #{state[:container_id]}", :returns => [0,1])
|
30
31
|
state[:hostname] = wait_for_lease(state[:container_id])
|
31
32
|
wait_for_sshd(state[:hostname])
|
32
33
|
end
|
@@ -42,16 +43,23 @@ module Kitchen
|
|
42
43
|
def fixup_files(container_id, container_path)
|
43
44
|
etc_sysconfig_network = File.join(container_path, "etc", "sysconfig", "network")
|
44
45
|
if File.exists?(etc_sysconfig_network)
|
45
|
-
|
46
|
+
info("manipulating sysconfig")
|
47
|
+
run_command("sed -i 's/HOSTNAME=.*/HOSTNAME=#{container_id}/g' #{etc_sysconfig_network}")
|
46
48
|
end
|
47
49
|
ifcfg_eth0 = File.join(container_path, "etc", "sysconfig", "network-scripts", "ifcfg-eth0")
|
48
50
|
if File.exists?(etc_sysconfig_network)
|
49
|
-
run_command("sed -i s/BOOTPROTO
|
50
|
-
run_command("sed -i s/IPADDR=.+//g #{ifcfg_eth0}")
|
51
|
+
run_command("sed -i 's/BOOTPROTO=.*/BOOTPROTO=dhcp/g' #{ifcfg_eth0}")
|
52
|
+
run_command("sed -i 's/IPADDR=.+//g' #{ifcfg_eth0}")
|
53
|
+
end
|
54
|
+
etc_sudoers = File.join(container_path, "etc", "sudoers")
|
55
|
+
if File.exists?(etc_sudoers)
|
56
|
+
run_command("sed -i 's/Defaults.*requiretty/# Defaults requiretty/g' #{etc_sudoers}")
|
57
|
+
run_command("sed -i 's/Defaults.*visiblepw/# Defaults !visiblepw/g' #{etc_sudoers}")
|
51
58
|
end
|
52
59
|
end
|
53
60
|
|
54
61
|
def wait_for_lease(container_id)
|
62
|
+
info("Determining mac address...")
|
55
63
|
mac_address = nil
|
56
64
|
ip_address = nil
|
57
65
|
File.open("/etc/libvirt/lxc/#{container_id}.xml", "r") do |xml|
|
@@ -62,6 +70,7 @@ module Kitchen
|
|
62
70
|
end
|
63
71
|
end
|
64
72
|
end
|
73
|
+
info("Mac addresss: #{mac_address}")
|
65
74
|
|
66
75
|
tries = 30
|
67
76
|
while ip_address == nil && tries > 0
|
@@ -80,6 +89,8 @@ module Kitchen
|
|
80
89
|
|
81
90
|
raise ActionFailed, "Cannot determine IP Address of '#{container_id}'" unless ip_address
|
82
91
|
|
92
|
+
info("IP Address: #{ip_address}")
|
93
|
+
|
83
94
|
return ip_address
|
84
95
|
end
|
85
96
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kitchen-libvirtlxc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -89,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
89
|
version: '0'
|
90
90
|
segments:
|
91
91
|
- 0
|
92
|
-
hash: -
|
92
|
+
hash: -1780848595164475918
|
93
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
98
|
version: '0'
|
99
99
|
segments:
|
100
100
|
- 0
|
101
|
-
hash: -
|
101
|
+
hash: -1780848595164475918
|
102
102
|
requirements: []
|
103
103
|
rubyforge_project:
|
104
104
|
rubygems_version: 1.8.25
|