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/server.rb
CHANGED
@@ -1,478 +1,165 @@
|
|
1
1
|
require "json"
|
2
2
|
require "dev-lxc/container"
|
3
|
-
require "dev-lxc/cluster"
|
4
3
|
|
5
4
|
module DevLXC
|
6
5
|
class Server
|
7
|
-
attr_reader :
|
6
|
+
attr_reader :container
|
8
7
|
|
9
|
-
def initialize(name,
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@
|
15
|
-
|
16
|
-
@lxc_config_path = cluster.lxc_config_path
|
17
|
-
@api_fqdn = cluster.api_fqdn
|
18
|
-
@analytics_fqdn = cluster.analytics_fqdn
|
19
|
-
@compliance_fqdn = cluster.compliance_fqdn
|
20
|
-
@supermarket_fqdn = cluster.supermarket_fqdn
|
21
|
-
@chef_server_bootstrap_backend = cluster.chef_server_bootstrap_backend
|
22
|
-
@analytics_bootstrap_backend = cluster.analytics_bootstrap_backend
|
23
|
-
@chef_server_config = cluster.chef_server_config
|
24
|
-
@analytics_config = cluster.analytics_config
|
25
|
-
|
26
|
-
@server = DevLXC::Container.new(name, @lxc_config_path)
|
27
|
-
@config = cluster_config[@server_type]["servers"][@server.name]
|
28
|
-
@ipaddress = @config["ipaddress"]
|
29
|
-
@role = @config["role"]
|
30
|
-
@role ||= cluster_config[@server_type]['topology']
|
31
|
-
@role ||= 'standalone'
|
32
|
-
@mounts = cluster_config[@server_type]["mounts"]
|
33
|
-
@mounts ||= cluster_config["mounts"]
|
34
|
-
@ssh_keys = cluster_config[@server_type]["ssh-keys"]
|
35
|
-
@ssh_keys ||= cluster_config["ssh-keys"]
|
36
|
-
@platform_image_name = cluster_config[@server_type]["platform_image"]
|
37
|
-
@platform_image_name ||= cluster_config["platform_image"]
|
38
|
-
@platform_image_options = cluster_config[@server_type]["platform_image_options"]
|
39
|
-
@platform_image_options ||= cluster_config["platform_image_options"]
|
40
|
-
@packages = cluster_config[@server_type]["packages"]
|
41
|
-
|
42
|
-
case @server_type
|
43
|
-
when 'adhoc', 'compliance', 'supermarket'
|
44
|
-
@shared_image_name = ''
|
45
|
-
when 'analytics'
|
46
|
-
@shared_image_name = "s#{@platform_image_name[1..-1]}"
|
47
|
-
@shared_image_name += "-analytics-#{Regexp.last_match[1].gsub(".", "-")}" if @packages["analytics"].to_s.match(/[_-]((\d+\.?){3,})/)
|
48
|
-
when 'chef-server'
|
49
|
-
if File.basename(@packages["server"]).match(/^(\w+-\w+.*)[_-]((?:\d+\.?){3,})/)
|
50
|
-
@chef_server_type = Regexp.last_match[1]
|
51
|
-
@chef_server_version = Regexp.last_match[2].gsub(".", "-")
|
52
|
-
end
|
8
|
+
def initialize(name, ipaddress, additional_fqdn, mounts, ssh_keys)
|
9
|
+
@container = DevLXC::Container.new(name)
|
10
|
+
@ipaddress = ipaddress
|
11
|
+
@additional_fqdn = additional_fqdn
|
12
|
+
@mounts = mounts
|
13
|
+
@ssh_keys = ssh_keys
|
14
|
+
end
|
53
15
|
|
54
|
-
|
55
|
-
|
56
|
-
when 'chef-server-core'
|
57
|
-
@shared_image_name += '-cs'
|
58
|
-
@server_ctl = 'chef-server'
|
59
|
-
when 'private-chef'
|
60
|
-
@shared_image_name += '-ec'
|
61
|
-
@server_ctl = 'private-chef'
|
62
|
-
when 'chef-server'
|
63
|
-
@shared_image_name += '-osc'
|
64
|
-
@server_ctl = 'chef-server'
|
65
|
-
end
|
66
|
-
@shared_image_name += "-#{@chef_server_version}"
|
67
|
-
@shared_image_name += "-reporting-#{Regexp.last_match[1].gsub(".", "-")}" if @packages["reporting"].to_s.match(/[_-]((\d+\.?){3,})/)
|
68
|
-
@shared_image_name += "-pushy-#{Regexp.last_match[1].gsub(".", "-")}" if @packages["push-jobs-server"].to_s.match(/[_-]((\d+\.?){3,})/)
|
69
|
-
end
|
16
|
+
def name
|
17
|
+
@container.name
|
70
18
|
end
|
71
19
|
|
72
|
-
def
|
73
|
-
|
20
|
+
def status
|
21
|
+
@container.status
|
74
22
|
end
|
75
23
|
|
76
24
|
def run_command(command)
|
77
|
-
if @
|
78
|
-
puts "Running '#{command}' in '#{@
|
79
|
-
@
|
25
|
+
if @container.running?
|
26
|
+
puts "Running '#{command}' in '#{@container.name}'"
|
27
|
+
@container.run_command(command)
|
80
28
|
else
|
81
|
-
puts "'#{@
|
29
|
+
puts "'#{@container.name}' is not running"
|
82
30
|
end
|
83
31
|
end
|
84
32
|
|
33
|
+
def install_package(package_path)
|
34
|
+
@container.install_package(package_path)
|
35
|
+
end
|
36
|
+
|
85
37
|
def start
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
case @server_type
|
91
|
-
when 'analytics'
|
92
|
-
DevLXC.create_dns_record(@analytics_fqdn, @server.name, @ipaddress)
|
93
|
-
when 'chef-server'
|
94
|
-
DevLXC.create_dns_record(@api_fqdn, @server.name, @ipaddress)
|
95
|
-
when 'compliance'
|
96
|
-
DevLXC.create_dns_record(@compliance_fqdn, @server.name, @ipaddress)
|
97
|
-
when 'supermarket'
|
98
|
-
DevLXC.create_dns_record(@supermarket_fqdn, @server.name, @ipaddress)
|
99
|
-
end
|
38
|
+
hwaddr = @container.config_item("lxc.network.0.hwaddr")
|
39
|
+
if @ipaddress
|
40
|
+
DevLXC.assign_ip_address(@ipaddress, @container.name, hwaddr)
|
41
|
+
DevLXC.create_dns_record(@additional_fqdn, @container.name, @ipaddress) unless @additional_fqdn.nil?
|
100
42
|
end
|
101
|
-
@
|
102
|
-
@
|
103
|
-
@
|
43
|
+
@container.sync_mounts(@mounts)
|
44
|
+
@container.start
|
45
|
+
@container.sync_ssh_keys(@ssh_keys)
|
104
46
|
end
|
105
47
|
|
106
48
|
def stop
|
107
|
-
hwaddr = @
|
108
|
-
@
|
49
|
+
hwaddr = @container.config_item("lxc.network.0.hwaddr") if @container.defined?
|
50
|
+
@container.stop
|
109
51
|
deregister_from_dnsmasq(hwaddr)
|
110
52
|
end
|
111
53
|
|
112
|
-
def snapshot(
|
113
|
-
unless @
|
114
|
-
puts "WARNING: Skipping snapshot of '#{@
|
54
|
+
def snapshot(comment=nil)
|
55
|
+
unless @container.defined?
|
56
|
+
puts "WARNING: Skipping snapshot of '#{@container.name}' because it does not exist"
|
115
57
|
return
|
116
58
|
end
|
117
|
-
if @
|
118
|
-
puts "WARNING: Skipping snapshot of '#{@
|
59
|
+
if @container.running?
|
60
|
+
puts "WARNING: Skipping snapshot of '#{@container.name}' because it is running"
|
119
61
|
return
|
120
62
|
end
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
return
|
128
|
-
end
|
129
|
-
end
|
130
|
-
puts "Creating snapshot of container '#{@server.name}' in custom image '#{custom_image.name}'"
|
131
|
-
@server.clone("#{custom_image.name}", {:flags => LXC::LXC_CLONE_SNAPSHOT|LXC::LXC_CLONE_KEEPMACADDR})
|
132
|
-
end
|
133
|
-
|
134
|
-
def destroy
|
135
|
-
hwaddr = @server.config_item("lxc.network.0.hwaddr") if @server.defined?
|
136
|
-
@server.destroy
|
137
|
-
deregister_from_dnsmasq(hwaddr)
|
138
|
-
end
|
139
|
-
|
140
|
-
def deregister_from_dnsmasq(hwaddr)
|
141
|
-
DevLXC.search_file_delete_line("/etc/lxc/addn-hosts.conf", /^#{@ipaddress}\s/)
|
142
|
-
DevLXC.search_file_delete_line("/etc/lxc/dhcp-hosts.conf", /,#{@ipaddress}$/)
|
143
|
-
unless hwaddr.nil?
|
144
|
-
DevLXC.search_file_delete_line("/etc/lxc/dhcp-hosts.conf", /^#{hwaddr}/)
|
145
|
-
end
|
146
|
-
DevLXC.reload_dnsmasq
|
147
|
-
end
|
148
|
-
|
149
|
-
def destroy_image(type)
|
150
|
-
case type
|
151
|
-
when :custom
|
152
|
-
DevLXC::Container.new("c-#{@server.name}", @lxc_config_path).destroy
|
153
|
-
when :unique
|
154
|
-
DevLXC::Container.new("u-#{@server.name}", @lxc_config_path).destroy
|
155
|
-
when :shared
|
156
|
-
DevLXC::Container.new(@shared_image_name, @lxc_config_path).destroy unless @shared_image_name.empty?
|
157
|
-
when :platform
|
158
|
-
DevLXC::Container.new(@platform_image_name, @lxc_config_path).destroy
|
63
|
+
puts "Creating snapshot of container '#{@container.name}'"
|
64
|
+
snapname = @container.snapshot
|
65
|
+
unless comment.nil?
|
66
|
+
snapshot = @container.snapshot_list.select { |sn| sn.first == snapname }
|
67
|
+
snapshot_comment_file = snapshot.flatten[1]
|
68
|
+
IO.write(snapshot_comment_file, comment) unless snapshot_comment_file.nil?
|
159
69
|
end
|
160
70
|
end
|
161
71
|
|
162
|
-
def
|
163
|
-
|
164
|
-
puts "
|
72
|
+
def snapshot_destroy(snapname=nil)
|
73
|
+
unless @container.defined?
|
74
|
+
puts "Skipping container '#{@container.name}' because it does not exist"
|
165
75
|
return
|
166
76
|
end
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
puts "Cloning custom image '#{custom_image.name}' into container '#{@server.name}'"
|
171
|
-
custom_image.clone(@server.name, {:flags => LXC::LXC_CLONE_SNAPSHOT|LXC::LXC_CLONE_KEEPMACADDR})
|
172
|
-
@server = DevLXC::Container.new(@server.name, @lxc_config_path)
|
173
|
-
return
|
174
|
-
elsif unique_image.defined?
|
175
|
-
puts "Cloning unique image '#{unique_image.name}' into container '#{@server.name}'"
|
176
|
-
unique_image.clone(@server.name, {:flags => LXC::LXC_CLONE_SNAPSHOT|LXC::LXC_CLONE_KEEPMACADDR})
|
177
|
-
@server = DevLXC::Container.new(@server.name, @lxc_config_path)
|
178
|
-
return
|
179
|
-
else
|
180
|
-
puts "Creating container '#{@server.name}'"
|
181
|
-
if %w(adhoc compliance supermarket).include?(@server_type)
|
182
|
-
if @server_type == 'supermarket' && (@chef_server_bootstrap_backend && ! DevLXC::Container.new(@chef_server_bootstrap_backend, @lxc_config_path).defined?)
|
183
|
-
puts "ERROR: The bootstrap backend server '#{@chef_server_bootstrap_backend}' must be created first."
|
184
|
-
exit 1
|
185
|
-
end
|
186
|
-
platform_image = DevLXC.create_platform_image(@platform_image_name, @platform_image_options, @lxc_config_path)
|
187
|
-
puts "Cloning platform image '#{platform_image.name}' into container '#{@server.name}'"
|
188
|
-
platform_image.clone(@server.name, {:flags => LXC::LXC_CLONE_SNAPSHOT})
|
77
|
+
if snapname == "ALL"
|
78
|
+
if @container.snapshot_list.empty?
|
79
|
+
puts "Container '#{@container.name}' does not have any snapshots"
|
189
80
|
else
|
190
|
-
|
191
|
-
puts "
|
192
|
-
|
193
|
-
end
|
194
|
-
shared_image = create_shared_image
|
195
|
-
puts "Cloning shared image '#{shared_image.name}' into container '#{@server.name}'"
|
196
|
-
shared_image.clone(@server.name, {:flags => LXC::LXC_CLONE_SNAPSHOT})
|
197
|
-
end
|
198
|
-
@server = DevLXC::Container.new(@server.name, @lxc_config_path)
|
199
|
-
puts "Deleting SSH Server Host Keys"
|
200
|
-
FileUtils.rm_f(Dir.glob("#{@server.config_item('lxc.rootfs')}/etc/ssh/ssh_host*_key*"))
|
201
|
-
puts "Adding lxc.hook.post-stop hook"
|
202
|
-
@server.set_config_item("lxc.hook.post-stop", "/usr/local/share/lxc/hooks/post-stop-dhcp-release")
|
203
|
-
@server.save_config
|
204
|
-
hwaddr = @server.config_item("lxc.network.0.hwaddr")
|
205
|
-
if hwaddr.empty?
|
206
|
-
puts "ERROR: '#{@server.name}' needs to have an lxc.network.hwaddr entry"
|
207
|
-
exit 1
|
208
|
-
end
|
209
|
-
DevLXC.assign_ip_address(@ipaddress, @server.name, hwaddr)
|
210
|
-
unless @role == 'backend'
|
211
|
-
case @server_type
|
212
|
-
when 'analytics'
|
213
|
-
DevLXC.create_dns_record(@analytics_fqdn, @server.name, @ipaddress)
|
214
|
-
when 'chef-server'
|
215
|
-
DevLXC.create_dns_record(@api_fqdn, @server.name, @ipaddress)
|
216
|
-
when 'compliance'
|
217
|
-
DevLXC.create_dns_record(@compliance_fqdn, @server.name, @ipaddress)
|
218
|
-
when 'supermarket'
|
219
|
-
DevLXC.create_dns_record(@supermarket_fqdn, @server.name, @ipaddress)
|
81
|
+
@container.snapshot_list.each do |snapshot|
|
82
|
+
puts "Destroying snapshot '#{snapshot.first}' of container '#{@container.name}'"
|
83
|
+
@container.snapshot_destroy(snapshot.first)
|
220
84
|
end
|
221
85
|
end
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
# Allow adhoc servers time to generate SSH Server Host Keys
|
230
|
-
sleep 5 if @server_type == 'adhoc'
|
231
|
-
case @server_type
|
232
|
-
when 'compliance'
|
233
|
-
@server.install_package(@packages["compliance"]) unless @packages["compliance"].nil?
|
234
|
-
when 'supermarket'
|
235
|
-
@server.install_package(@packages["supermarket"]) unless @packages["supermarket"].nil?
|
86
|
+
elsif snapname == "LAST"
|
87
|
+
if @container.snapshot_list.empty?
|
88
|
+
puts "Container '#{@container.name}' does not have any snapshots"
|
89
|
+
else
|
90
|
+
snapname = @container.snapshot_list.last.first
|
91
|
+
puts "Destroying snapshot '#{snapname}' of container '#{@container.name}'"
|
92
|
+
@container.snapshot_destroy(snapname)
|
236
93
|
end
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
@server.install_package(@packages["manage"])
|
245
|
-
configure_manage
|
246
|
-
end
|
247
|
-
unless @role == 'open-source'
|
248
|
-
configure_reporting unless @packages["reporting"].nil?
|
249
|
-
configure_push_jobs_server unless @packages["push-jobs-server"].nil?
|
250
|
-
end
|
94
|
+
else
|
95
|
+
snapshot = @container.snapshot_list.select { |sn| sn.first == snapname }
|
96
|
+
if snapshot.flatten.empty?
|
97
|
+
puts "Container '#{@container.name}' does not have a '#{snapname}' snapshot"
|
98
|
+
else
|
99
|
+
puts "Destroying snapshot '#{snapname}' of container '#{@container.name}'"
|
100
|
+
@container.snapshot_destroy(snapname)
|
251
101
|
end
|
252
|
-
@server.stop
|
253
|
-
puts "Cloning container '#{@server.name}' into unique image '#{unique_image.name}'"
|
254
|
-
@server.clone("#{unique_image.name}", {:flags => LXC::LXC_CLONE_SNAPSHOT|LXC::LXC_CLONE_KEEPMACADDR})
|
255
102
|
end
|
256
103
|
end
|
257
104
|
|
258
|
-
def
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
105
|
+
def snapshot_list
|
106
|
+
snapshots = Array.new
|
107
|
+
return snapshots unless @container.defined?
|
108
|
+
@container.snapshot_list.each do |snapshot|
|
109
|
+
(snapname, snap_comment_file, snaptime) = snapshot
|
110
|
+
snap_comment = IO.read(snap_comment_file).chomp if File.exist?(snap_comment_file)
|
111
|
+
snapshots << [snapname, snaptime, snap_comment]
|
263
112
|
end
|
264
|
-
|
265
|
-
|
266
|
-
platform_image.clone(shared_image.name, {:flags => LXC::LXC_CLONE_SNAPSHOT})
|
267
|
-
shared_image = DevLXC::Container.new(shared_image.name, @lxc_config_path)
|
268
|
-
puts "Deleting SSH Server Host Keys"
|
269
|
-
FileUtils.rm_f(Dir.glob("#{shared_image.config_item('lxc.rootfs')}/etc/ssh/ssh_host*_key*"))
|
113
|
+
snapshots
|
114
|
+
end
|
270
115
|
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
FileUtils.mv("#{shared_image.config_item('lxc.rootfs')}/etc/sysctl.d/10-console-messages.conf",
|
276
|
-
"#{shared_image.config_item('lxc.rootfs')}/etc/sysctl.d/10-console-messages.conf.orig")
|
277
|
-
end
|
278
|
-
end
|
279
|
-
unless shared_image.config_item("lxc.mount.auto").nil?
|
280
|
-
shared_image.set_config_item("lxc.mount.auto", "proc:rw sys:rw")
|
281
|
-
shared_image.save_config
|
116
|
+
def snapshot_restore(snapname=nil)
|
117
|
+
unless @container.defined?
|
118
|
+
puts "WARNING: Skipping container '#{@container.name}' because it does not exist"
|
119
|
+
return
|
282
120
|
end
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
when 'analytics'
|
287
|
-
shared_image.install_package(@packages["analytics"]) unless @packages["analytics"].nil?
|
288
|
-
when 'chef-server'
|
289
|
-
shared_image.install_package(@packages["server"]) unless @packages["server"].nil?
|
290
|
-
shared_image.install_package(@packages["reporting"]) unless @packages["reporting"].nil?
|
291
|
-
shared_image.install_package(@packages["push-jobs-server"]) unless @packages["push-jobs-server"].nil?
|
121
|
+
if @container.running?
|
122
|
+
puts "WARNING: Skipping container '#{@container.name}' because it is running"
|
123
|
+
return
|
292
124
|
end
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
puts "
|
307
|
-
|
308
|
-
IO.write("#{@server.config_item('lxc.rootfs')}/etc/opscode/private-chef.rb", @chef_server_config)
|
309
|
-
when 'chef-server-core'
|
310
|
-
puts "Creating /etc/opscode/chef-server.rb"
|
311
|
-
FileUtils.mkdir_p("#{@server.config_item('lxc.rootfs')}/etc/opscode")
|
312
|
-
IO.write("#{@server.config_item('lxc.rootfs')}/etc/opscode/chef-server.rb", @chef_server_config)
|
125
|
+
if snapname == "LAST"
|
126
|
+
if @container.snapshot_list.empty?
|
127
|
+
puts "WARNING: Skipping container '#{@container.name}' because it does not have any snapshots"
|
128
|
+
else
|
129
|
+
snapname = @container.snapshot_list.last.first
|
130
|
+
puts "Restoring snapshot '#{snapname}' of container '#{@container.name}'"
|
131
|
+
@container.snapshot_restore(snapname)
|
132
|
+
end
|
133
|
+
else
|
134
|
+
snapshot = @container.snapshot_list.select { |sn| sn.first == snapname }
|
135
|
+
if snapshot.flatten.empty?
|
136
|
+
puts "WARNING: Skipping container '#{@container.name}' because it does not have a '#{snapname}' snapshot"
|
137
|
+
else
|
138
|
+
puts "Restoring snapshot '#{snapname}' of container '#{@container.name}'"
|
139
|
+
@container.snapshot_restore(snapname)
|
313
140
|
end
|
314
|
-
when "frontend"
|
315
|
-
puts "Copying /etc/opscode from bootstrap backend '#{@chef_server_bootstrap_backend}'"
|
316
|
-
FileUtils.cp_r("#{LXC::Container.new(@chef_server_bootstrap_backend, @lxc_config_path).config_item('lxc.rootfs')}/etc/opscode",
|
317
|
-
"#{@server.config_item('lxc.rootfs')}/etc")
|
318
|
-
end
|
319
|
-
run_ctl(@server_ctl, "reconfigure")
|
320
|
-
end
|
321
|
-
|
322
|
-
def configure_reporting
|
323
|
-
FileUtils.mkdir_p("#{@server.config_item('lxc.rootfs')}/var/opt/opscode-reporting")
|
324
|
-
FileUtils.touch("#{@server.config_item('lxc.rootfs')}/var/opt/opscode-reporting/.license.accepted")
|
325
|
-
if @role == 'frontend'
|
326
|
-
puts "Copying /etc/opscode-reporting from bootstrap backend '#{@chef_server_bootstrap_backend}'"
|
327
|
-
FileUtils.cp_r("#{LXC::Container.new(@chef_server_bootstrap_backend, @lxc_config_path).config_item('lxc.rootfs')}/etc/opscode-reporting",
|
328
|
-
"#{@server.config_item('lxc.rootfs')}/etc")
|
329
141
|
end
|
330
|
-
run_ctl(@server_ctl, "reconfigure")
|
331
|
-
run_ctl("opscode-reporting", "reconfigure")
|
332
|
-
end
|
333
|
-
|
334
|
-
def configure_push_jobs_server
|
335
|
-
run_ctl("opscode-push-jobs-server", "reconfigure")
|
336
|
-
run_ctl(@server_ctl, "reconfigure")
|
337
142
|
end
|
338
143
|
|
339
|
-
def
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
puts "Disabling old opscode-webui in /etc/opscode/private-chef.rb"
|
344
|
-
DevLXC.search_file_delete_line("#{@server.config_item('lxc.rootfs')}/etc/opscode/private-chef.rb", /opscode_webui[.enable.]/)
|
345
|
-
DevLXC.append_line_to_file("#{@server.config_item('lxc.rootfs')}/etc/opscode/private-chef.rb", "\nopscode_webui['enable'] = false\n")
|
346
|
-
run_ctl(@server_ctl, "reconfigure")
|
144
|
+
def destroy
|
145
|
+
if @container.defined?
|
146
|
+
hwaddr = @container.config_item("lxc.network.0.hwaddr")
|
147
|
+
@container.snapshot_list.each { |snapshot| @container.snapshot_destroy(snapshot.first) }
|
347
148
|
end
|
348
|
-
|
149
|
+
@container.destroy
|
150
|
+
deregister_from_dnsmasq(hwaddr)
|
349
151
|
end
|
350
152
|
|
351
|
-
def
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
when "standalone", "backend"
|
356
|
-
puts "Copying /etc/opscode-analytics from Chef Server bootstrap backend '#{@chef_server_bootstrap_backend}'"
|
357
|
-
FileUtils.cp_r("#{LXC::Container.new(@chef_server_bootstrap_backend, @lxc_config_path).config_item('lxc.rootfs')}/etc/opscode-analytics",
|
358
|
-
"#{@server.config_item('lxc.rootfs')}/etc")
|
359
|
-
|
360
|
-
IO.write("#{@server.config_item('lxc.rootfs')}/etc/opscode-analytics/opscode-analytics.rb", @analytics_config)
|
361
|
-
when "frontend"
|
362
|
-
puts "Copying /etc/opscode-analytics from Analytics bootstrap backend '#{@analytics_bootstrap_backend}'"
|
363
|
-
FileUtils.cp_r("#{LXC::Container.new(@analytics_bootstrap_backend, @lxc_config_path).config_item('lxc.rootfs')}/etc/opscode-analytics",
|
364
|
-
"#{@server.config_item('lxc.rootfs')}/etc")
|
153
|
+
def deregister_from_dnsmasq(hwaddr)
|
154
|
+
if @ipaddress
|
155
|
+
DevLXC.search_file_delete_line("/etc/lxc/addn-hosts.conf", /^#{@ipaddress}\s/)
|
156
|
+
DevLXC.search_file_delete_line("/etc/lxc/dhcp-hosts.conf", /,#{@ipaddress}$/)
|
365
157
|
end
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
def configure_compliance
|
370
|
-
FileUtils.mkdir_p("#{@server.config_item('lxc.rootfs')}/var/opt/chef-compliance")
|
371
|
-
FileUtils.touch("#{@server.config_item('lxc.rootfs')}/var/opt/chef-compliance/.license.accepted")
|
372
|
-
run_ctl("chef-compliance", "reconfigure")
|
373
|
-
end
|
374
|
-
|
375
|
-
def configure_supermarket
|
376
|
-
if @chef_server_bootstrap_backend && DevLXC::Container.new(@chef_server_bootstrap_backend, @lxc_config_path).defined?
|
377
|
-
chef_server_supermarket_config = JSON.parse(IO.read("#{LXC::Container.new(@chef_server_bootstrap_backend, @lxc_config_path).config_item('lxc.rootfs')}/etc/opscode/oc-id-applications/supermarket.json"))
|
378
|
-
supermarket_config = {
|
379
|
-
'chef_server_url' => "https://#{@api_fqdn}/",
|
380
|
-
'chef_oauth2_app_id' => chef_server_supermarket_config['uid'],
|
381
|
-
'chef_oauth2_secret' => chef_server_supermarket_config['secret'],
|
382
|
-
'chef_oauth2_verify_ssl' => false
|
383
|
-
}
|
384
|
-
FileUtils.mkdir_p("#{@server.config_item('lxc.rootfs')}/etc/supermarket")
|
385
|
-
IO.write("#{@server.config_item('lxc.rootfs')}/etc/supermarket/supermarket.json", JSON.pretty_generate(supermarket_config))
|
158
|
+
unless hwaddr.nil?
|
159
|
+
DevLXC.search_file_delete_line("/etc/lxc/dhcp-hosts.conf", /^#{hwaddr}/)
|
386
160
|
end
|
387
|
-
|
388
|
-
end
|
389
|
-
|
390
|
-
def run_ctl(component, subcommand)
|
391
|
-
puts "Running `#{component}-ctl #{subcommand}` in '#{@server.name}'"
|
392
|
-
@server.run_command("#{component}-ctl #{subcommand}")
|
161
|
+
DevLXC.reload_dnsmasq
|
393
162
|
end
|
394
163
|
|
395
|
-
def create_users
|
396
|
-
puts "Creating org, user, keys and knife.rb in /root/chef-repo/.chef"
|
397
|
-
FileUtils.mkdir_p("#{@server.config_item('lxc.rootfs')}/root/chef-repo/.chef")
|
398
|
-
|
399
|
-
case @chef_server_type
|
400
|
-
when 'chef-server'
|
401
|
-
chef_server_url = "https://127.0.0.1"
|
402
|
-
admin_username = "admin"
|
403
|
-
validator_name = "chef-validator"
|
404
|
-
|
405
|
-
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" )
|
406
|
-
when 'private-chef', 'chef-server-core'
|
407
|
-
chef_server_root = "https://127.0.0.1"
|
408
|
-
chef_server_url = "https://127.0.0.1/organizations/demo"
|
409
|
-
admin_username = "mary-admin"
|
410
|
-
username = "joe-user"
|
411
|
-
validator_name = "demo-validator"
|
412
|
-
|
413
|
-
FileUtils.cp( "#{@server.config_item('lxc.rootfs')}/etc/opscode/pivotal.pem", "#{@server.config_item('lxc.rootfs')}/root/chef-repo/.chef" )
|
414
|
-
|
415
|
-
pivotal_rb = %Q(
|
416
|
-
current_dir = File.dirname(__FILE__)
|
417
|
-
|
418
|
-
chef_server_root "#{chef_server_root}"
|
419
|
-
chef_server_url "#{chef_server_root}"
|
420
|
-
|
421
|
-
node_name "pivotal"
|
422
|
-
client_key "\#{current_dir}/pivotal.pem"
|
423
|
-
|
424
|
-
cookbook_path Dir.pwd + "/cookbooks"
|
425
|
-
knife[:chef_repo_path] = Dir.pwd
|
426
|
-
|
427
|
-
ssl_verify_mode :verify_none
|
428
|
-
)
|
429
|
-
IO.write("#{@server.config_item('lxc.rootfs')}/root/chef-repo/.chef/pivotal.rb", pivotal_rb)
|
430
|
-
end
|
431
|
-
|
432
|
-
knife_rb = %Q(
|
433
|
-
current_dir = File.dirname(__FILE__)
|
434
|
-
|
435
|
-
chef_server_url "#{chef_server_url}"
|
436
|
-
|
437
|
-
node_name "#{admin_username}"
|
438
|
-
client_key "\#{current_dir}/#{admin_username}.pem"
|
439
|
-
)
|
440
|
-
|
441
|
-
knife_rb += %Q(
|
442
|
-
#node_name "#{username}"
|
443
|
-
#client_key "\#{current_dir}/#{username}.pem"
|
444
|
-
) unless username.nil?
|
445
|
-
|
446
|
-
knife_rb += %Q(
|
447
|
-
validation_client_name "#{validator_name}"
|
448
|
-
validation_key "\#{current_dir}/#{validator_name}.pem"
|
449
|
-
|
450
|
-
cookbook_path Dir.pwd + "/cookbooks"
|
451
|
-
knife[:chef_repo_path] = Dir.pwd
|
452
|
-
|
453
|
-
ssl_verify_mode :verify_none
|
454
|
-
)
|
455
|
-
IO.write("#{@server.config_item('lxc.rootfs')}/root/chef-repo/.chef/knife.rb", knife_rb)
|
456
|
-
|
457
|
-
case @chef_server_type
|
458
|
-
when 'private-chef'
|
459
|
-
# give time for all services to come up completely
|
460
|
-
sleep 60
|
461
|
-
@server.run_command("/opt/opscode/embedded/bin/gem install knife-opc --no-ri --no-rdoc")
|
462
|
-
@server.run_command("/opt/opscode/embedded/bin/knife opc org create demo demo --filename /root/chef-repo/.chef/demo-validator.pem -c /root/chef-repo/.chef/pivotal.rb")
|
463
|
-
@server.run_command("/opt/opscode/embedded/bin/knife opc user create mary-admin mary admin mary-admin@noreply.com mary-admin --filename /root/chef-repo/.chef/mary-admin.pem -c /root/chef-repo/.chef/pivotal.rb")
|
464
|
-
@server.run_command("/opt/opscode/embedded/bin/knife opc org user add demo mary-admin --admin -c /root/chef-repo/.chef/pivotal.rb")
|
465
|
-
@server.run_command("/opt/opscode/embedded/bin/knife opc user create joe-user joe user joe-user@noreply.com joe-user --filename /root/chef-repo/.chef/joe-user.pem -c /root/chef-repo/.chef/pivotal.rb")
|
466
|
-
@server.run_command("/opt/opscode/embedded/bin/knife opc org user add demo joe-user -c /root/chef-repo/.chef/pivotal.rb")
|
467
|
-
when 'chef-server-core'
|
468
|
-
# give time for all services to come up completely
|
469
|
-
sleep 10
|
470
|
-
run_ctl(@server_ctl, "org-create demo demo --filename /root/chef-repo/.chef/demo-validator.pem")
|
471
|
-
run_ctl(@server_ctl, "user-create mary-admin mary admin mary-admin@noreply.com mary-admin --filename /root/chef-repo/.chef/mary-admin.pem")
|
472
|
-
run_ctl(@server_ctl, "org-user-add demo mary-admin --admin")
|
473
|
-
run_ctl(@server_ctl, "user-create joe-user joe user joe-user@noreply.com joe-user --filename /root/chef-repo/.chef/joe-user.pem")
|
474
|
-
run_ctl(@server_ctl, "org-user-add demo joe-user")
|
475
|
-
end
|
476
|
-
end
|
477
164
|
end
|
478
165
|
end
|
data/lib/dev-lxc/version.rb
CHANGED