testlab 1.8.5 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/testlab/provisioner.rb +1 -0
- data/lib/testlab/provisioners/hosts_file.rb +84 -0
- data/lib/testlab/version.rb +1 -1
- metadata +4 -3
data/lib/testlab/provisioner.rb
CHANGED
@@ -11,6 +11,7 @@ class TestLab
|
|
11
11
|
autoload :AptCacherNG, 'testlab/provisioners/apt_cacher_ng'
|
12
12
|
autoload :Bind, 'testlab/provisioners/bind'
|
13
13
|
autoload :Chef, 'testlab/provisioners/chef'
|
14
|
+
autoload :HostsFile, 'testlab/provisioners/hosts_file'
|
14
15
|
autoload :NFSMount, 'testlab/provisioners/nfs_mount'
|
15
16
|
autoload :Raring, 'testlab/provisioners/raring'
|
16
17
|
autoload :Resolv, 'testlab/provisioners/resolv'
|
@@ -0,0 +1,84 @@
|
|
1
|
+
class TestLab
|
2
|
+
|
3
|
+
class Provisioner
|
4
|
+
|
5
|
+
# HostsFile Provisioner Error Class
|
6
|
+
class HostsFileError < ProvisionerError; end
|
7
|
+
|
8
|
+
# HostsFile Provisioner Class
|
9
|
+
#
|
10
|
+
# @author Zachary Patten <zachary AT jovelabs DOT com>
|
11
|
+
class HostsFile
|
12
|
+
|
13
|
+
def initialize(config={}, ui=nil)
|
14
|
+
@config = (config || Hash.new)
|
15
|
+
@ui = (ui || TestLab.ui)
|
16
|
+
@command = ZTK::Command.new(:ui => @ui, :silence => true, :ignore_exit_status => true)
|
17
|
+
|
18
|
+
@ui.logger.debug { "config(#{@config.inspect})" }
|
19
|
+
end
|
20
|
+
|
21
|
+
# HostsFile: Container Provision
|
22
|
+
def on_container_callback(container)
|
23
|
+
remove_hosts
|
24
|
+
add_hosts(container)
|
25
|
+
|
26
|
+
true
|
27
|
+
end
|
28
|
+
alias :on_container_create :on_container_callback
|
29
|
+
alias :on_container_up :on_container_callback
|
30
|
+
alias :on_container_provision :on_container_callback
|
31
|
+
|
32
|
+
alias :on_container_deprovision:on_container_callback
|
33
|
+
alias :on_container_down :on_container_callback
|
34
|
+
alias :on_container_destroy :on_container_callback
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def add_hosts(container)
|
39
|
+
@command.exec(<<-EOF)
|
40
|
+
set -x
|
41
|
+
cat <<EOI | #{sudo} tee -a /etc/hosts
|
42
|
+
#{def_tag}
|
43
|
+
#{hosts_blob(container)}
|
44
|
+
#{end_tag}
|
45
|
+
EOI
|
46
|
+
EOF
|
47
|
+
end
|
48
|
+
|
49
|
+
def remove_hosts
|
50
|
+
@command.exec(sed_hostsfile)
|
51
|
+
end
|
52
|
+
|
53
|
+
def hosts_blob(container)
|
54
|
+
blob = Array.new
|
55
|
+
container.node.containers.each do |con|
|
56
|
+
blob << "#{con.primary_interface.ip}\t#{con.id} #{con.fqdn}"
|
57
|
+
end
|
58
|
+
|
59
|
+
blob.join("\n")
|
60
|
+
end
|
61
|
+
|
62
|
+
def sed_hostsfile
|
63
|
+
case RUBY_PLATFORM
|
64
|
+
when /darwin/ then
|
65
|
+
%(#{sudo} sed -i '' '/#{def_tag}/,/#{end_tag}/d' /etc/hosts)
|
66
|
+
when /linux/ then
|
67
|
+
%(#{sudo} sed -i '/#{def_tag}/,/#{end_tag}/d' /etc/hosts)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# NFS Exports Start Definition Tag
|
72
|
+
def def_tag
|
73
|
+
"#TESTLAB-HOSTSFILE"
|
74
|
+
end
|
75
|
+
|
76
|
+
# NFS Exports End Definition Tag
|
77
|
+
def end_tag
|
78
|
+
"#TESTLAB-HOSTSFILE"
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
data/lib/testlab/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: testlab
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -286,6 +286,7 @@ files:
|
|
286
286
|
- lib/testlab/provisioners/chef/omni_truck.rb
|
287
287
|
- lib/testlab/provisioners/chef/ruby_gem_client.rb
|
288
288
|
- lib/testlab/provisioners/chef/ruby_gem_server.rb
|
289
|
+
- lib/testlab/provisioners/hosts_file.rb
|
289
290
|
- lib/testlab/provisioners/nfs_mount.rb
|
290
291
|
- lib/testlab/provisioners/raring.rb
|
291
292
|
- lib/testlab/provisioners/resolv.rb
|
@@ -344,7 +345,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
344
345
|
version: '0'
|
345
346
|
segments:
|
346
347
|
- 0
|
347
|
-
hash:
|
348
|
+
hash: 1545777099270245561
|
348
349
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
349
350
|
none: false
|
350
351
|
requirements:
|
@@ -353,7 +354,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
353
354
|
version: '0'
|
354
355
|
segments:
|
355
356
|
- 0
|
356
|
-
hash:
|
357
|
+
hash: 1545777099270245561
|
357
358
|
requirements: []
|
358
359
|
rubyforge_project:
|
359
360
|
rubygems_version: 1.8.25
|