dev-lxc 0.5.0 → 0.6.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 +248 -141
- data/dev-lxc.gemspec +1 -1
- data/files/configs/open-source.yml +20 -10
- data/files/configs/standalone.yml +40 -18
- data/files/configs/tier.yml +56 -26
- data/lib/dev-lxc/cli.rb +128 -65
- data/lib/dev-lxc/cluster.rb +174 -0
- data/lib/dev-lxc/container.rb +2 -2
- data/lib/dev-lxc/server.rb +414 -0
- data/lib/dev-lxc/version.rb +1 -1
- data/lib/dev-lxc.rb +34 -34
- metadata +6 -6
- data/lib/dev-lxc/chef-cluster.rb +0 -97
- data/lib/dev-lxc/chef-server.rb +0 -339
@@ -0,0 +1,414 @@
|
|
1
|
+
require "dev-lxc/container"
|
2
|
+
require "dev-lxc/cluster"
|
3
|
+
|
4
|
+
module DevLXC
|
5
|
+
class Server
|
6
|
+
attr_reader :server, :platform_image_name, :shared_image_name
|
7
|
+
|
8
|
+
def initialize(name, server_type, cluster_config)
|
9
|
+
unless cluster_config[server_type]["servers"].keys.include?(name)
|
10
|
+
raise "Server #{name} is not defined in the cluster config"
|
11
|
+
end
|
12
|
+
@server_type = server_type
|
13
|
+
cluster = DevLXC::Cluster.new(cluster_config)
|
14
|
+
@api_fqdn = cluster.api_fqdn
|
15
|
+
@analytics_fqdn = cluster.analytics_fqdn
|
16
|
+
@chef_server_bootstrap_backend = cluster.chef_server_bootstrap_backend
|
17
|
+
@analytics_bootstrap_backend = cluster.analytics_bootstrap_backend
|
18
|
+
@chef_server_config = cluster.chef_server_config
|
19
|
+
@analytics_config = cluster.analytics_config
|
20
|
+
|
21
|
+
@server = DevLXC::Container.new(name)
|
22
|
+
@config = cluster_config[@server_type]["servers"][@server.name]
|
23
|
+
@ipaddress = @config["ipaddress"]
|
24
|
+
@role = @config["role"] ? @config["role"] : cluster_config[@server_type]['topology']
|
25
|
+
@mounts = cluster_config[@server_type]["mounts"]
|
26
|
+
@platform_image_name = cluster_config[@server_type]["platform_image"]
|
27
|
+
@packages = cluster_config[@server_type]["packages"]
|
28
|
+
|
29
|
+
case @server_type
|
30
|
+
when 'analytics'
|
31
|
+
@shared_image_name = "s#{@platform_image_name[1..-1]}"
|
32
|
+
@shared_image_name += "-analytics-#{Regexp.last_match[1].gsub(".", "-")}" if @packages["analytics"].to_s.match(/[_-]((\d+\.?){3,})/)
|
33
|
+
when 'chef-server'
|
34
|
+
if File.basename(@packages["server"]).match(/^(\w+-\w+.*)[_-]((?:\d+\.?){3,})/)
|
35
|
+
@chef_server_type = Regexp.last_match[1]
|
36
|
+
@chef_server_version = Regexp.last_match[2].gsub(".", "-")
|
37
|
+
end
|
38
|
+
|
39
|
+
@shared_image_name = "s#{@platform_image_name[1..-1]}"
|
40
|
+
case @chef_server_type
|
41
|
+
when 'chef-server-core'
|
42
|
+
@shared_image_name += '-cs'
|
43
|
+
@server_ctl = 'chef-server'
|
44
|
+
when 'private-chef'
|
45
|
+
@shared_image_name += '-ec'
|
46
|
+
@server_ctl = 'private-chef'
|
47
|
+
when 'chef-server'
|
48
|
+
@shared_image_name += '-osc'
|
49
|
+
@server_ctl = 'chef-server'
|
50
|
+
end
|
51
|
+
@shared_image_name += "-#{@chef_server_version}"
|
52
|
+
@shared_image_name += "-reporting-#{Regexp.last_match[1].gsub(".", "-")}" if @packages["reporting"].to_s.match(/[_-]((\d+\.?){3,})/)
|
53
|
+
@shared_image_name += "-pushy-#{Regexp.last_match[1].gsub(".", "-")}" if @packages["push-jobs-server"].to_s.match(/[_-]((\d+\.?){3,})/)
|
54
|
+
@shared_image_name += "-sync-#{Regexp.last_match[1].gsub(".", "-")}" if @packages["sync"].to_s.match(/[_-]((\d+\.?){3,})/)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def status
|
59
|
+
if @server.defined?
|
60
|
+
state = @server.state
|
61
|
+
ip_addresses = @server.ip_addresses.join(" ") if @server.state == :running
|
62
|
+
else
|
63
|
+
state = "not_created"
|
64
|
+
end
|
65
|
+
printf "%25s %-15s %s\n", @server.name, state, ip_addresses
|
66
|
+
end
|
67
|
+
|
68
|
+
def abspath(rootfs_path)
|
69
|
+
"#{@server.config_item('lxc.rootfs')}#{rootfs_path}" if @server.defined?
|
70
|
+
end
|
71
|
+
|
72
|
+
def run_command(command)
|
73
|
+
if @server.running?
|
74
|
+
puts "Running '#{command}' in #{@server.name}"
|
75
|
+
@server.run_command(command)
|
76
|
+
else
|
77
|
+
puts "#{@server.name} is not running"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def start
|
82
|
+
create
|
83
|
+
hwaddr = @server.config_item("lxc.network.0.hwaddr")
|
84
|
+
DevLXC.assign_ip_address(@ipaddress, @server.name, hwaddr)
|
85
|
+
unless @role == 'backend'
|
86
|
+
case @server_type
|
87
|
+
when 'analytics'
|
88
|
+
DevLXC.create_dns_record(@analytics_fqdn, @server.name, @ipaddress)
|
89
|
+
when 'chef-server'
|
90
|
+
DevLXC.create_dns_record(@api_fqdn, @server.name, @ipaddress)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
@server.sync_mounts(@mounts)
|
94
|
+
@server.start
|
95
|
+
end
|
96
|
+
|
97
|
+
def stop
|
98
|
+
hwaddr = @server.config_item("lxc.network.0.hwaddr") if @server.defined?
|
99
|
+
@server.stop
|
100
|
+
deregister_from_dnsmasq(hwaddr)
|
101
|
+
end
|
102
|
+
|
103
|
+
def snapshot(force=nil)
|
104
|
+
unless @server.defined?
|
105
|
+
puts "WARNING: Skipping snapshot of '#{@server.name}' because it is not created"
|
106
|
+
return
|
107
|
+
end
|
108
|
+
if @server.state != :stopped
|
109
|
+
puts "WARNING: Skipping snapshot of '#{@server.name}' because it is not stopped"
|
110
|
+
return
|
111
|
+
end
|
112
|
+
custom_image = DevLXC::Container.new("c-#{@server.name}")
|
113
|
+
if custom_image.defined?
|
114
|
+
if force
|
115
|
+
custom_image.destroy
|
116
|
+
else
|
117
|
+
puts "WARNING: Skipping snapshot of '#{@server.name}' because a custom image already exists"
|
118
|
+
return
|
119
|
+
end
|
120
|
+
end
|
121
|
+
puts "Creating snapshot of container #{@server.name} in custom image #{custom_image.name}"
|
122
|
+
@server.clone("#{custom_image.name}", {:flags => LXC::LXC_CLONE_SNAPSHOT|LXC::LXC_CLONE_KEEPMACADDR})
|
123
|
+
end
|
124
|
+
|
125
|
+
def destroy
|
126
|
+
hwaddr = @server.config_item("lxc.network.0.hwaddr") if @server.defined?
|
127
|
+
@server.destroy
|
128
|
+
deregister_from_dnsmasq(hwaddr)
|
129
|
+
end
|
130
|
+
|
131
|
+
def deregister_from_dnsmasq(hwaddr)
|
132
|
+
DevLXC.search_file_delete_line("/etc/lxc/addn-hosts.conf", /^#{@ipaddress}\s/)
|
133
|
+
DevLXC.search_file_delete_line("/etc/lxc/dhcp-hosts.conf", /,#{@ipaddress}$/)
|
134
|
+
unless hwaddr.nil?
|
135
|
+
DevLXC.search_file_delete_line("/etc/lxc/dhcp-hosts.conf", /^#{hwaddr}/)
|
136
|
+
end
|
137
|
+
DevLXC.reload_dnsmasq
|
138
|
+
end
|
139
|
+
|
140
|
+
def destroy_image(type)
|
141
|
+
case type
|
142
|
+
when :custom
|
143
|
+
DevLXC::Container.new("c-#{@server.name}").destroy
|
144
|
+
when :unique
|
145
|
+
DevLXC::Container.new("u-#{@server.name}").destroy
|
146
|
+
when :shared
|
147
|
+
DevLXC::Container.new(@shared_image_name).destroy
|
148
|
+
when :platform
|
149
|
+
DevLXC::Container.new(@platform_image_name).destroy
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def create
|
154
|
+
if @server.defined?
|
155
|
+
puts "Using existing container #{@server.name}"
|
156
|
+
return
|
157
|
+
end
|
158
|
+
custom_image = DevLXC::Container.new("c-#{@server.name}")
|
159
|
+
unique_image = DevLXC::Container.new("u-#{@server.name}")
|
160
|
+
if custom_image.defined?
|
161
|
+
puts "Cloning custom image #{custom_image.name} into container #{@server.name}"
|
162
|
+
custom_image.clone(@server.name, {:flags => LXC::LXC_CLONE_SNAPSHOT|LXC::LXC_CLONE_KEEPMACADDR})
|
163
|
+
@server = DevLXC::Container.new(@server.name)
|
164
|
+
return
|
165
|
+
elsif unique_image.defined?
|
166
|
+
puts "Cloning unique image #{unique_image.name} into container #{@server.name}"
|
167
|
+
unique_image.clone(@server.name, {:flags => LXC::LXC_CLONE_SNAPSHOT|LXC::LXC_CLONE_KEEPMACADDR})
|
168
|
+
@server = DevLXC::Container.new(@server.name)
|
169
|
+
return
|
170
|
+
else
|
171
|
+
puts "Creating container #{@server.name}"
|
172
|
+
unless @server.name == @chef_server_bootstrap_backend || DevLXC::Container.new(@chef_server_bootstrap_backend).defined?
|
173
|
+
raise "The bootstrap backend server must be created first."
|
174
|
+
end
|
175
|
+
shared_image = create_shared_image
|
176
|
+
puts "Cloning shared image #{shared_image.name} into container #{@server.name}"
|
177
|
+
shared_image.clone(@server.name, {:flags => LXC::LXC_CLONE_SNAPSHOT})
|
178
|
+
@server = DevLXC::Container.new(@server.name)
|
179
|
+
puts "Adding lxc.hook.post-stop hook"
|
180
|
+
@server.set_config_item("lxc.hook.post-stop", "/usr/local/share/lxc/hooks/post-stop-dhcp-release")
|
181
|
+
@server.save_config
|
182
|
+
hwaddr = @server.config_item("lxc.network.0.hwaddr")
|
183
|
+
raise "#{@server.name} needs to have an lxc.network.hwaddr entry" if hwaddr.empty?
|
184
|
+
DevLXC.assign_ip_address(@ipaddress, @server.name, hwaddr)
|
185
|
+
unless @role == 'backend'
|
186
|
+
case @server_type
|
187
|
+
when 'analytics'
|
188
|
+
DevLXC.create_dns_record(@analytics_fqdn, @server.name, @ipaddress)
|
189
|
+
when 'chef-server'
|
190
|
+
DevLXC.create_dns_record(@api_fqdn, @server.name, @ipaddress)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
@server.sync_mounts(@mounts)
|
194
|
+
# if platform image is centos then `/etc/hosts` file needs to be modified so `hostname -f`
|
195
|
+
# provides the FQDN instead of `localhost`
|
196
|
+
if @platform_image_name.start_with?('p-centos-')
|
197
|
+
IO.write("#{@server.config_item('lxc.rootfs')}/etc/hosts", "127.0.0.1 localhost\n127.0.1.1 #{@server.name}\n")
|
198
|
+
end
|
199
|
+
@server.start
|
200
|
+
configure_analytics if @server_type == 'analytics'
|
201
|
+
if @server_type == 'chef-server' && ! @packages["server"].nil?
|
202
|
+
configure_server
|
203
|
+
create_users if @server.name == @chef_server_bootstrap_backend
|
204
|
+
if %w(standalone frontend).include?(@role) && ! @packages["manage"].nil?
|
205
|
+
@server.install_package(@packages["manage"])
|
206
|
+
configure_manage
|
207
|
+
end
|
208
|
+
unless @role == 'open-source'
|
209
|
+
configure_reporting unless @packages["reporting"].nil?
|
210
|
+
configure_push_jobs_server unless @packages["push-jobs-server"].nil?
|
211
|
+
if @analytics_bootstrap_backend && %w(standalone backend).include?(@role)
|
212
|
+
configure_chef_server_for_analytics
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
@server.stop
|
217
|
+
puts "Cloning container #{@server.name} into unique image #{unique_image.name}"
|
218
|
+
@server.clone("#{unique_image.name}", {:flags => LXC::LXC_CLONE_SNAPSHOT|LXC::LXC_CLONE_KEEPMACADDR})
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
def create_shared_image
|
223
|
+
shared_image = DevLXC::Container.new(@shared_image_name)
|
224
|
+
if shared_image.defined?
|
225
|
+
puts "Using existing shared image #{shared_image.name}"
|
226
|
+
return shared_image
|
227
|
+
end
|
228
|
+
platform_image = DevLXC.create_platform_image(@platform_image_name)
|
229
|
+
puts "Cloning platform image #{platform_image.name} into shared image #{shared_image.name}"
|
230
|
+
platform_image.clone(shared_image.name, {:flags => LXC::LXC_CLONE_SNAPSHOT})
|
231
|
+
shared_image = DevLXC::Container.new(shared_image.name)
|
232
|
+
|
233
|
+
# Disable certain sysctl.d files in Ubuntu 10.04, they cause `start procps` to fail
|
234
|
+
# Enterprise Chef server's postgresql recipe expects to be able to `start procps`
|
235
|
+
if platform_image.name == "p-ubuntu-1004"
|
236
|
+
if File.exist?("#{shared_image.config_item('lxc.rootfs')}/etc/sysctl.d/10-console-messages.conf")
|
237
|
+
FileUtils.mv("#{shared_image.config_item('lxc.rootfs')}/etc/sysctl.d/10-console-messages.conf",
|
238
|
+
"#{shared_image.config_item('lxc.rootfs')}/etc/sysctl.d/10-console-messages.conf.orig")
|
239
|
+
end
|
240
|
+
end
|
241
|
+
unless shared_image.config_item("lxc.mount.auto").nil?
|
242
|
+
shared_image.set_config_item("lxc.mount.auto", "proc:rw sys:rw")
|
243
|
+
shared_image.save_config
|
244
|
+
end
|
245
|
+
shared_image.sync_mounts(@mounts)
|
246
|
+
shared_image.start
|
247
|
+
case @server_type
|
248
|
+
when 'analytics'
|
249
|
+
shared_image.install_package(@packages["analytics"]) unless @packages["analytics"].nil?
|
250
|
+
when 'chef-server'
|
251
|
+
shared_image.install_package(@packages["server"]) unless @packages["server"].nil?
|
252
|
+
shared_image.install_package(@packages["reporting"]) unless @packages["reporting"].nil?
|
253
|
+
shared_image.install_package(@packages["push-jobs-server"]) unless @packages["push-jobs-server"].nil?
|
254
|
+
shared_image.install_package(@packages["sync"]) unless @packages["sync"].nil?
|
255
|
+
end
|
256
|
+
shared_image.stop
|
257
|
+
return shared_image
|
258
|
+
end
|
259
|
+
|
260
|
+
def configure_server
|
261
|
+
case @role
|
262
|
+
when "open-source"
|
263
|
+
puts "Creating /etc/chef-server/chef-server.rb"
|
264
|
+
FileUtils.mkdir_p("#{@server.config_item('lxc.rootfs')}/etc/chef-server")
|
265
|
+
IO.write("#{@server.config_item('lxc.rootfs')}/etc/chef-server/chef-server.rb", @chef_server_config)
|
266
|
+
when "standalone", "backend"
|
267
|
+
case @chef_server_type
|
268
|
+
when 'private-chef'
|
269
|
+
puts "Creating /etc/opscode/private-chef.rb"
|
270
|
+
FileUtils.mkdir_p("#{@server.config_item('lxc.rootfs')}/etc/opscode")
|
271
|
+
IO.write("#{@server.config_item('lxc.rootfs')}/etc/opscode/private-chef.rb", @chef_server_config)
|
272
|
+
when 'chef-server-core'
|
273
|
+
puts "Creating /etc/opscode/chef-server.rb"
|
274
|
+
FileUtils.mkdir_p("#{@server.config_item('lxc.rootfs')}/etc/opscode")
|
275
|
+
IO.write("#{@server.config_item('lxc.rootfs')}/etc/opscode/chef-server.rb", @chef_server_config)
|
276
|
+
end
|
277
|
+
when "frontend"
|
278
|
+
puts "Copying /etc/opscode from bootstrap backend"
|
279
|
+
FileUtils.cp_r("#{LXC::Container.new(@chef_server_bootstrap_backend).config_item('lxc.rootfs')}/etc/opscode",
|
280
|
+
"#{@server.config_item('lxc.rootfs')}/etc")
|
281
|
+
end
|
282
|
+
run_ctl(@server_ctl, "reconfigure")
|
283
|
+
end
|
284
|
+
|
285
|
+
def configure_reporting
|
286
|
+
if @role == 'frontend'
|
287
|
+
puts "Copying /etc/opscode-reporting from bootstrap backend"
|
288
|
+
FileUtils.cp_r("#{LXC::Container.new(@chef_server_bootstrap_backend).config_item('lxc.rootfs')}/etc/opscode-reporting",
|
289
|
+
"#{@server.config_item('lxc.rootfs')}/etc")
|
290
|
+
end
|
291
|
+
run_ctl(@server_ctl, "reconfigure")
|
292
|
+
run_ctl("opscode-reporting", "reconfigure")
|
293
|
+
end
|
294
|
+
|
295
|
+
def configure_push_jobs_server
|
296
|
+
run_ctl("opscode-push-jobs-server", "reconfigure")
|
297
|
+
run_ctl(@server_ctl, "reconfigure")
|
298
|
+
end
|
299
|
+
|
300
|
+
def configure_manage
|
301
|
+
if @chef_server_type == 'private-chef'
|
302
|
+
puts "Disabling old opscode-webui in /etc/opscode/private-chef.rb"
|
303
|
+
DevLXC.search_file_delete_line("#{@server.config_item('lxc.rootfs')}/etc/opscode/private-chef.rb", /opscode_webui[.enable.]/)
|
304
|
+
DevLXC.append_line_to_file("#{@server.config_item('lxc.rootfs')}/etc/opscode/private-chef.rb", "\nopscode_webui['enable'] = false\n")
|
305
|
+
run_ctl(@server_ctl, "reconfigure")
|
306
|
+
end
|
307
|
+
run_ctl("opscode-manage", "reconfigure")
|
308
|
+
end
|
309
|
+
|
310
|
+
def configure_chef_server_for_analytics
|
311
|
+
puts "Configuring for Analytics"
|
312
|
+
case @chef_server_type
|
313
|
+
when 'private-chef'
|
314
|
+
DevLXC.append_line_to_file("#{@server.config_item('lxc.rootfs')}/etc/opscode/private-chef.rb",
|
315
|
+
"\noc_id['applications'] = {\n 'analytics' => {\n 'redirect_uri' => 'https://#{@analytics_fqdn}/'\n }\n}\n")
|
316
|
+
|
317
|
+
DevLXC.append_line_to_file("#{@server.config_item('lxc.rootfs')}/etc/opscode/private-chef.rb",
|
318
|
+
"\nrabbitmq['vip'] = '#{@chef_server_bootstrap_backend}'\nrabbitmq['node_ip_address'] = '0.0.0.0'\n")
|
319
|
+
when 'chef-server-core'
|
320
|
+
DevLXC.append_line_to_file("#{@server.config_item('lxc.rootfs')}/etc/opscode/chef-server.rb",
|
321
|
+
"\noc_id['applications'] = {\n 'analytics' => {\n 'redirect_uri' => 'https://#{@analytics_fqdn}/'\n }\n}\n")
|
322
|
+
|
323
|
+
DevLXC.append_line_to_file("#{@server.config_item('lxc.rootfs')}/etc/opscode/chef-server.rb",
|
324
|
+
"\nrabbitmq['vip'] = '#{@chef_server_bootstrap_backend}'\nrabbitmq['node_ip_address'] = '0.0.0.0'\n")
|
325
|
+
end
|
326
|
+
|
327
|
+
run_ctl(@server_ctl, "stop")
|
328
|
+
run_ctl(@server_ctl, "reconfigure")
|
329
|
+
run_ctl(@server_ctl, "restart")
|
330
|
+
run_ctl("opscode-manage", "reconfigure") if @role == 'frontend'
|
331
|
+
end
|
332
|
+
|
333
|
+
def configure_analytics
|
334
|
+
case @role
|
335
|
+
when "standalone", "backend"
|
336
|
+
puts "Copying /etc/opscode-analytics from Chef Server bootstrap backend"
|
337
|
+
FileUtils.cp_r("#{LXC::Container.new(@chef_server_bootstrap_backend).config_item('lxc.rootfs')}/etc/opscode-analytics",
|
338
|
+
"#{@server.config_item('lxc.rootfs')}/etc")
|
339
|
+
|
340
|
+
IO.write("#{@server.config_item('lxc.rootfs')}/etc/opscode-analytics/opscode-analytics.rb", @analytics_config)
|
341
|
+
when "frontend"
|
342
|
+
puts "Copying /etc/opscode-analytics from Analytics bootstrap backend"
|
343
|
+
FileUtils.cp_r("#{LXC::Container.new(@analytics_bootstrap_backend).config_item('lxc.rootfs')}/etc/opscode-analytics",
|
344
|
+
"#{@server.config_item('lxc.rootfs')}/etc")
|
345
|
+
end
|
346
|
+
run_ctl("opscode-analytics", "reconfigure")
|
347
|
+
end
|
348
|
+
|
349
|
+
def run_ctl(component, subcommand)
|
350
|
+
puts "Running `#{component}-ctl #{subcommand}` in #{@server.name}"
|
351
|
+
@server.run_command("#{component}-ctl #{subcommand}")
|
352
|
+
end
|
353
|
+
|
354
|
+
def create_users
|
355
|
+
puts "Creating org, user, keys and knife.rb in /root/chef-repo/.chef"
|
356
|
+
FileUtils.mkdir_p("#{@server.config_item('lxc.rootfs')}/root/chef-repo/.chef")
|
357
|
+
|
358
|
+
case @chef_server_type
|
359
|
+
when 'chef-server'
|
360
|
+
chef_server_url = "https://127.0.0.1"
|
361
|
+
username = "admin"
|
362
|
+
validator_name = "chef-validator"
|
363
|
+
|
364
|
+
FileUtils.cp( Dir.glob("#{@server.config_item('lxc.rootfs')}/etc/chef-server/{admin,chef-validator}.pem"), "#{@server.config_item('lxc.rootfs')}/root/chef-repo/.chef" )
|
365
|
+
when 'private-chef'
|
366
|
+
chef_server_url = "https://127.0.0.1/organizations/ponyville"
|
367
|
+
username = "rainbowdash"
|
368
|
+
validator_name = "ponyville-validator"
|
369
|
+
|
370
|
+
# give time for all services to come up completely
|
371
|
+
sleep 60
|
372
|
+
pivotal_rb = %Q(
|
373
|
+
chef_server_root "https://127.0.0.1/"
|
374
|
+
chef_server_url "https://127.0.0.1/"
|
375
|
+
|
376
|
+
node_name "pivotal"
|
377
|
+
client_key "/etc/opscode/pivotal.pem"
|
378
|
+
|
379
|
+
knife[:chef_repo_path] = Dir.pwd
|
380
|
+
)
|
381
|
+
IO.write("#{@server.config_item('lxc.rootfs')}/root/chef-repo/.chef/pivotal.rb", pivotal_rb)
|
382
|
+
@server.run_command("/opt/opscode/embedded/bin/gem install knife-opc --no-ri --no-rdoc")
|
383
|
+
@server.run_command("/opt/opscode/embedded/bin/knife opc org create ponyville ponyville --filename /root/chef-repo/.chef/ponyville-validator.pem -c /root/chef-repo/.chef/pivotal.rb")
|
384
|
+
@server.run_command("/opt/opscode/embedded/bin/knife opc user create rainbowdash rainbowdash rainbowdash rainbowdash@noreply.com rainbowdash --filename /root/chef-repo/.chef/rainbowdash.pem -c /root/chef-repo/.chef/pivotal.rb")
|
385
|
+
@server.run_command("/opt/opscode/embedded/bin/knife opc org user add ponyville rainbowdash --admin -c /root/chef-repo/.chef/pivotal.rb")
|
386
|
+
when 'chef-server-core'
|
387
|
+
chef_server_url = "https://127.0.0.1/organizations/ponyville"
|
388
|
+
username = "rainbowdash"
|
389
|
+
validator_name = "ponyville-validator"
|
390
|
+
|
391
|
+
# give time for all services to come up completely
|
392
|
+
sleep 10
|
393
|
+
run_ctl(@server_ctl, "org-create ponyville ponyville --filename /root/chef-repo/.chef/ponyville-validator.pem")
|
394
|
+
run_ctl(@server_ctl, "user-create rainbowdash rainbowdash rainbowdash rainbowdash@noreply.com rainbowdash --filename /root/chef-repo/.chef/rainbowdash.pem")
|
395
|
+
run_ctl(@server_ctl, "org-user-add ponyville rainbowdash --admin")
|
396
|
+
end
|
397
|
+
knife_rb = %Q(
|
398
|
+
current_dir = File.dirname(__FILE__)
|
399
|
+
|
400
|
+
chef_server_url "#{chef_server_url}"
|
401
|
+
|
402
|
+
node_name "#{username}"
|
403
|
+
client_key "\#{current_dir}/#{username}.pem"
|
404
|
+
|
405
|
+
validation_client_name "#{validator_name}"
|
406
|
+
validation_key "\#{current_dir}/#{validator_name}.pem"
|
407
|
+
|
408
|
+
cookbook_path Dir.pwd + "/cookbooks"
|
409
|
+
knife[:chef_repo_path] = Dir.pwd
|
410
|
+
)
|
411
|
+
IO.write("#{@server.config_item('lxc.rootfs')}/root/chef-repo/.chef/knife.rb", knife_rb)
|
412
|
+
end
|
413
|
+
end
|
414
|
+
end
|
data/lib/dev-lxc/version.rb
CHANGED
data/lib/dev-lxc.rb
CHANGED
@@ -2,60 +2,60 @@ require "fileutils"
|
|
2
2
|
require "digest/sha1"
|
3
3
|
require "lxc"
|
4
4
|
require "dev-lxc/container"
|
5
|
-
require "dev-lxc/
|
6
|
-
require "dev-lxc/
|
5
|
+
require "dev-lxc/server"
|
6
|
+
require "dev-lxc/cluster"
|
7
7
|
|
8
8
|
module DevLXC
|
9
|
-
def self.
|
10
|
-
|
11
|
-
if
|
12
|
-
puts "Using existing platform
|
13
|
-
return
|
9
|
+
def self.create_platform_image(platform_image_name)
|
10
|
+
platform_image = DevLXC::Container.new(platform_image_name)
|
11
|
+
if platform_image.defined?
|
12
|
+
puts "Using existing platform image #{platform_image.name}"
|
13
|
+
return platform_image
|
14
14
|
end
|
15
|
-
puts "Creating platform
|
16
|
-
case
|
15
|
+
puts "Creating platform image #{platform_image.name}"
|
16
|
+
case platform_image.name
|
17
17
|
when "p-ubuntu-1004"
|
18
|
-
|
18
|
+
platform_image.create("download", "btrfs", {}, 0, ["-d", "ubuntu", "-r", "lucid", "-a", "amd64"])
|
19
19
|
when "p-ubuntu-1204"
|
20
|
-
|
20
|
+
platform_image.create("download", "btrfs", {}, 0, ["-d", "ubuntu", "-r", "precise", "-a", "amd64"])
|
21
21
|
when "p-ubuntu-1404"
|
22
|
-
|
22
|
+
platform_image.create("download", "btrfs", {}, 0, ["-d", "ubuntu", "-r", "trusty", "-a", "amd64"])
|
23
23
|
when "p-centos-5"
|
24
|
-
|
24
|
+
platform_image.create("centos", "btrfs", {}, 0, ["-R", "5"])
|
25
25
|
when "p-centos-6"
|
26
|
-
|
26
|
+
platform_image.create("download", "btrfs", {}, 0, ["-d", "centos", "-r", "6", "-a", "amd64"])
|
27
27
|
end
|
28
|
-
unless
|
29
|
-
|
28
|
+
unless platform_image.config_item("lxc.mount.auto").nil?
|
29
|
+
platform_image.set_config_item("lxc.mount.auto", "proc:rw sys:rw")
|
30
30
|
end
|
31
31
|
hwaddr = '00:16:3e:' + Digest::SHA1.hexdigest(Time.now.to_s).slice(0..5).unpack('a2a2a2').join(':')
|
32
|
-
puts "Setting #{
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
puts "Installing packages in platform
|
37
|
-
case
|
32
|
+
puts "Setting #{platform_image.name} platform image's lxc.network.0.hwaddr to #{hwaddr}"
|
33
|
+
platform_image.set_config_item("lxc.network.0.hwaddr", hwaddr)
|
34
|
+
platform_image.save_config
|
35
|
+
platform_image.start
|
36
|
+
puts "Installing packages in platform image #{platform_image.name}"
|
37
|
+
case platform_image.name
|
38
38
|
when "p-ubuntu-1004"
|
39
39
|
# Disable certain sysctl.d files in Ubuntu 10.04, they cause `start procps` to fail
|
40
|
-
if File.exist?("#{
|
41
|
-
FileUtils.mv("#{
|
42
|
-
"#{
|
40
|
+
if File.exist?("#{platform_image.config_item('lxc.rootfs')}/etc/sysctl.d/10-console-messages.conf")
|
41
|
+
FileUtils.mv("#{platform_image.config_item('lxc.rootfs')}/etc/sysctl.d/10-console-messages.conf",
|
42
|
+
"#{platform_image.config_item('lxc.rootfs')}/etc/sysctl.d/10-console-messages.conf.orig")
|
43
43
|
end
|
44
|
-
|
45
|
-
|
44
|
+
platform_image.run_command("apt-get update")
|
45
|
+
platform_image.run_command("apt-get install -y standard^ server^ vim-nox emacs23-nox curl tree")
|
46
46
|
when "p-ubuntu-1204", "p-ubuntu-1404"
|
47
|
-
|
48
|
-
|
47
|
+
platform_image.run_command("apt-get update")
|
48
|
+
platform_image.run_command("apt-get install -y standard^ server^ vim-nox emacs23-nox tree")
|
49
49
|
when "p-centos-5"
|
50
50
|
# downgrade openssl temporarily to overcome an install bug
|
51
51
|
# reference: http://www.hack.net.br/blog/2014/02/12/openssl-conflicts-with-file-from-package-openssl/
|
52
|
-
|
53
|
-
|
52
|
+
platform_image.run_command("yum downgrade -y openssl")
|
53
|
+
platform_image.run_command("yum install -y @base @core vim-enhanced emacs-nox tree")
|
54
54
|
when "p-centos-6"
|
55
|
-
|
55
|
+
platform_image.run_command("yum install -y @base @core vim-enhanced emacs-nox tree")
|
56
56
|
end
|
57
|
-
|
58
|
-
return
|
57
|
+
platform_image.stop
|
58
|
+
return platform_image
|
59
59
|
end
|
60
60
|
|
61
61
|
def self.assign_ip_address(ipaddress, container_name, hwaddr)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dev-lxc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremiah Snapp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.0
|
61
|
+
version: 1.2.0
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.0
|
68
|
+
version: 1.2.0
|
69
69
|
description: A tool for creating Chef server clusters using LXC containers
|
70
70
|
email:
|
71
71
|
- jeremiah@getchef.com
|
@@ -85,10 +85,10 @@ files:
|
|
85
85
|
- files/configs/standalone.yml
|
86
86
|
- files/configs/tier.yml
|
87
87
|
- lib/dev-lxc.rb
|
88
|
-
- lib/dev-lxc/chef-cluster.rb
|
89
|
-
- lib/dev-lxc/chef-server.rb
|
90
88
|
- lib/dev-lxc/cli.rb
|
89
|
+
- lib/dev-lxc/cluster.rb
|
91
90
|
- lib/dev-lxc/container.rb
|
91
|
+
- lib/dev-lxc/server.rb
|
92
92
|
- lib/dev-lxc/version.rb
|
93
93
|
homepage: https://github.com/jeremiahsnapp/dev-lxc
|
94
94
|
licenses:
|
data/lib/dev-lxc/chef-cluster.rb
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
require "dev-lxc/chef-server"
|
2
|
-
|
3
|
-
module DevLXC
|
4
|
-
class ChefCluster
|
5
|
-
attr_reader :bootstrap_backend
|
6
|
-
|
7
|
-
def initialize(cluster_config)
|
8
|
-
@cluster_config = cluster_config
|
9
|
-
@api_fqdn = @cluster_config["api_fqdn"]
|
10
|
-
@analytics_fqdn = @cluster_config["analytics_fqdn"]
|
11
|
-
@topology = @cluster_config["topology"]
|
12
|
-
@servers = @cluster_config["servers"]
|
13
|
-
@frontends = Array.new
|
14
|
-
@servers.each do |name, config|
|
15
|
-
case @topology
|
16
|
-
when 'open-source', 'standalone'
|
17
|
-
@bootstrap_backend = name if config["role"].nil?
|
18
|
-
when 'tier'
|
19
|
-
@bootstrap_backend = name if config["role"] == "backend" && config["bootstrap"] == true
|
20
|
-
@frontends << name if config["role"] == "frontend"
|
21
|
-
end
|
22
|
-
@analytics_server = name if config["role"] == "analytics"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def chef_servers
|
27
|
-
chef_servers = Array.new
|
28
|
-
chef_servers << ChefServer.new(@bootstrap_backend, @cluster_config)
|
29
|
-
if @topology == "tier"
|
30
|
-
@frontends.each do |frontend_name|
|
31
|
-
chef_servers << ChefServer.new(frontend_name, @cluster_config)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
chef_servers << ChefServer.new(@analytics_server, @cluster_config) if @analytics_server
|
35
|
-
chef_servers
|
36
|
-
end
|
37
|
-
|
38
|
-
def chef_repo
|
39
|
-
if @topology == "open-source"
|
40
|
-
puts "Unable to create a chef-repo for an Open Source Chef Server"
|
41
|
-
exit 1
|
42
|
-
end
|
43
|
-
chef_server = ChefServer.new(@bootstrap_backend, @cluster_config)
|
44
|
-
if ! chef_server.server.defined?
|
45
|
-
puts "The '#{chef_server.server.name}' Chef Server does not exist. Please create it first."
|
46
|
-
exit 1
|
47
|
-
end
|
48
|
-
puts "Creating chef-repo with pem files and knife.rb in the current directory"
|
49
|
-
FileUtils.mkdir_p("./chef-repo/.chef")
|
50
|
-
knife_rb = %Q(
|
51
|
-
current_dir = File.dirname(__FILE__)
|
52
|
-
|
53
|
-
chef_server_url "https://#{@api_fqdn}/organizations/ponyville"
|
54
|
-
|
55
|
-
node_name "rainbowdash"
|
56
|
-
client_key "\#{current_dir}/rainbowdash.pem"
|
57
|
-
|
58
|
-
validation_client_name "ponyville-validator"
|
59
|
-
validation_key "\#{current_dir}/ponyville-validator.pem"
|
60
|
-
|
61
|
-
cookbook_path Dir.pwd + "/cookbooks"
|
62
|
-
knife[:chef_repo_path] = Dir.pwd
|
63
|
-
)
|
64
|
-
IO.write("./chef-repo/.chef/knife.rb", knife_rb)
|
65
|
-
if Dir.glob("#{chef_server.abspath('/root/chef-repo/.chef')}/*.pem").empty?
|
66
|
-
puts "The pem files can not be copied because they do not exist in '#{chef_server.server.name}' Chef Server's `/root/chef-repo/.chef` directory"
|
67
|
-
else
|
68
|
-
FileUtils.cp( Dir.glob("#{chef_server.abspath('/root/chef-repo/.chef')}/*.pem"), "./chef-repo/.chef" )
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def chef_server_config
|
73
|
-
chef_server_config = %Q(api_fqdn "#{@api_fqdn}"\n)
|
74
|
-
if @topology == 'tier'
|
75
|
-
chef_server_config += %Q(
|
76
|
-
topology "#{@topology}"
|
77
|
-
|
78
|
-
server "#{@bootstrap_backend}",
|
79
|
-
:ipaddress => "#{@servers[@bootstrap_backend]["ipaddress"]}",
|
80
|
-
:role => "backend",
|
81
|
-
:bootstrap => true
|
82
|
-
|
83
|
-
backend_vip "#{@bootstrap_backend}",
|
84
|
-
:ipaddress => "#{@servers[@bootstrap_backend]["ipaddress"]}"
|
85
|
-
)
|
86
|
-
@frontends.each do |frontend_name|
|
87
|
-
chef_server_config += %Q(
|
88
|
-
server "#{frontend_name}",
|
89
|
-
:ipaddress => "#{@servers[frontend_name]["ipaddress"]}",
|
90
|
-
:role => "frontend"
|
91
|
-
)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
return chef_server_config
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|