dev-lxc 1.7.0 → 2.0.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.
- checksums.yaml +4 -4
- data/README.md +230 -452
- data/dev-lxc.gemspec +2 -1
- data/lib/dev-lxc/cli.rb +174 -309
- data/lib/dev-lxc/cluster.rb +772 -113
- data/lib/dev-lxc/container.rb +1 -107
- data/lib/dev-lxc/server.rb +107 -420
- data/lib/dev-lxc/version.rb +1 -1
- data/lib/dev-lxc.rb +72 -76
- metadata +18 -4
data/lib/dev-lxc/container.rb
CHANGED
@@ -104,118 +104,12 @@ module DevLXC
|
|
104
104
|
puts "Installing #{package_path} in container '#{self.name}'"
|
105
105
|
case File.extname(package_path)
|
106
106
|
when ".deb"
|
107
|
-
install_command = "dpkg -D10 -i #{package_path}"
|
107
|
+
install_command = "dpkg -D10 -i --skip-same-version #{package_path}"
|
108
108
|
when ".rpm"
|
109
109
|
install_command = "rpm -Uvh #{package_path}"
|
110
110
|
end
|
111
111
|
run_command(install_command)
|
112
112
|
end
|
113
113
|
|
114
|
-
def install_chef_client(version=nil)
|
115
|
-
unless self.defined?
|
116
|
-
puts "ERROR: Container '#{self.name}' does not exist."
|
117
|
-
exit 1
|
118
|
-
end
|
119
|
-
unless running?
|
120
|
-
puts "ERROR: Container '#{self.name}' is not running"
|
121
|
-
exit 1
|
122
|
-
end
|
123
|
-
if self.ip_addresses.empty?
|
124
|
-
puts "ERROR: Container '#{self.name}' network is not available."
|
125
|
-
exit 1
|
126
|
-
end
|
127
|
-
|
128
|
-
require 'tempfile'
|
129
|
-
|
130
|
-
installed_version = nil
|
131
|
-
file = Tempfile.new('installed_chef_client_version')
|
132
|
-
begin
|
133
|
-
attach_opts = { wait: true, env_policy: LXC::LXC_ATTACH_CLEAR_ENV, extra_env_vars: ['HOME=/root'], stdout: file }
|
134
|
-
attach(attach_opts) do
|
135
|
-
puts `chef-client -v`
|
136
|
-
end
|
137
|
-
file.rewind
|
138
|
-
installed_version = Regexp.last_match[1] if file.read.match(/chef:\s*(\d+\.\d+\.\d+)/i)
|
139
|
-
ensure
|
140
|
-
file.close
|
141
|
-
file.unlink
|
142
|
-
end
|
143
|
-
if installed_version.nil? || ( ! version.nil? && ! installed_version.start_with?(version) )
|
144
|
-
require "net/https"
|
145
|
-
require "uri"
|
146
|
-
|
147
|
-
uri = URI.parse("https://www.chef.io/chef/install.sh")
|
148
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
149
|
-
http.use_ssl = true
|
150
|
-
|
151
|
-
request = Net::HTTP::Get.new(uri.request_uri)
|
152
|
-
|
153
|
-
response = http.request(request)
|
154
|
-
|
155
|
-
file = Tempfile.new('install_sh', "#{config_item('lxc.rootfs')}/tmp")
|
156
|
-
file.write(response.body)
|
157
|
-
begin
|
158
|
-
version = 'latest' if version.nil?
|
159
|
-
install_command = "bash /tmp/#{File.basename(file.path)} -v #{version}"
|
160
|
-
run_command(install_command)
|
161
|
-
ensure
|
162
|
-
file.close
|
163
|
-
file.unlink
|
164
|
-
end
|
165
|
-
else
|
166
|
-
puts "Chef #{installed_version} is already installed."
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
def configure_chef_client(chef_server_url, validation_client_name, validation_key)
|
171
|
-
unless self.defined?
|
172
|
-
puts "ERROR: Container '#{self.name}' does not exist."
|
173
|
-
exit 1
|
174
|
-
end
|
175
|
-
|
176
|
-
puts "Configuring Chef Client in container '#{self.name}' for Chef Server '#{chef_server_url}'"
|
177
|
-
|
178
|
-
FileUtils.mkdir_p("#{config_item('lxc.rootfs')}/etc/chef")
|
179
|
-
|
180
|
-
client_rb = %Q(chef_server_url '#{chef_server_url}'
|
181
|
-
validation_client_name '#{validation_client_name}'
|
182
|
-
ssl_verify_mode :verify_none
|
183
|
-
)
|
184
|
-
IO.write("#{config_item('lxc.rootfs')}/etc/chef/client.rb", client_rb)
|
185
|
-
|
186
|
-
begin
|
187
|
-
FileUtils.cp(validation_key, "#{config_item('lxc.rootfs')}/etc/chef/validation.pem")
|
188
|
-
rescue Errno::ENOENT
|
189
|
-
puts "ERROR: The validation key '#{validation_key}' does not exist."
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
def bootstrap_container(base_container_name=nil, version=nil, run_list=nil, chef_server_url, validation_client_name, validation_key)
|
194
|
-
puts "Bootstrapping container '#{self.name}' for Chef Server '#{chef_server_url}'"
|
195
|
-
if base_container_name
|
196
|
-
if self.defined?
|
197
|
-
puts "WARN: Skipping cloning. Container '#{self.name}' already exists"
|
198
|
-
else
|
199
|
-
puts "Cloning base container '#{base_container_name}' into container '#{self.name}'"
|
200
|
-
base_container = DevLXC::Container.new(base_container_name)
|
201
|
-
unless base_container.defined?
|
202
|
-
puts "ERROR: Base container '#{base_container_name} does not exist"
|
203
|
-
exit 1
|
204
|
-
end
|
205
|
-
base_container.clone(self.name, {:flags => LXC::LXC_CLONE_SNAPSHOT})
|
206
|
-
self.load_config
|
207
|
-
puts "Deleting SSH Server Host Keys"
|
208
|
-
FileUtils.rm_f(Dir.glob("#{self.config_item('lxc.rootfs')}/etc/ssh/ssh_host*_key*"))
|
209
|
-
end
|
210
|
-
end
|
211
|
-
self.start unless self.running?
|
212
|
-
self.install_chef_client(version)
|
213
|
-
self.configure_chef_client(chef_server_url, validation_client_name, validation_key)
|
214
|
-
|
215
|
-
chef_client_command = "chef-client"
|
216
|
-
chef_client_command += " -r #{run_list}" if run_list
|
217
|
-
self.run_command(chef_client_command)
|
218
|
-
end
|
219
|
-
|
220
114
|
end
|
221
115
|
end
|