vagabond 0.1.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.
Files changed (63) hide show
  1. data/CHANGELOG.md +2 -0
  2. data/README.md +94 -0
  3. data/bin/vagabond +6 -0
  4. data/lib/vagabond.rb +1 -0
  5. data/lib/vagabond/actions/create.rb +29 -0
  6. data/lib/vagabond/actions/destroy.rb +31 -0
  7. data/lib/vagabond/actions/freeze.rb +14 -0
  8. data/lib/vagabond/actions/provision.rb +31 -0
  9. data/lib/vagabond/actions/ssh.rb +13 -0
  10. data/lib/vagabond/actions/status.rb +29 -0
  11. data/lib/vagabond/actions/thaw.rb +14 -0
  12. data/lib/vagabond/actions/up.rb +27 -0
  13. data/lib/vagabond/bootstraps/server.erb +62 -0
  14. data/lib/vagabond/commands.rb +58 -0
  15. data/lib/vagabond/config.rb +7 -0
  16. data/lib/vagabond/cookbooks/lxc/CHANGELOG.md +21 -0
  17. data/lib/vagabond/cookbooks/lxc/Gemfile +3 -0
  18. data/lib/vagabond/cookbooks/lxc/Gemfile.lock +132 -0
  19. data/lib/vagabond/cookbooks/lxc/README.md +83 -0
  20. data/lib/vagabond/cookbooks/lxc/attributes/default.rb +26 -0
  21. data/lib/vagabond/cookbooks/lxc/files/default/knife_lxc +228 -0
  22. data/lib/vagabond/cookbooks/lxc/libraries/lxc.rb +279 -0
  23. data/lib/vagabond/cookbooks/lxc/libraries/lxc_expanded_resources.rb +40 -0
  24. data/lib/vagabond/cookbooks/lxc/libraries/lxc_file_config.rb +81 -0
  25. data/lib/vagabond/cookbooks/lxc/metadata.rb +11 -0
  26. data/lib/vagabond/cookbooks/lxc/providers/config.rb +82 -0
  27. data/lib/vagabond/cookbooks/lxc/providers/container.rb +342 -0
  28. data/lib/vagabond/cookbooks/lxc/providers/fstab.rb +71 -0
  29. data/lib/vagabond/cookbooks/lxc/providers/interface.rb +99 -0
  30. data/lib/vagabond/cookbooks/lxc/providers/service.rb +53 -0
  31. data/lib/vagabond/cookbooks/lxc/recipes/containers.rb +13 -0
  32. data/lib/vagabond/cookbooks/lxc/recipes/default.rb +45 -0
  33. data/lib/vagabond/cookbooks/lxc/recipes/install_dependencies.rb +15 -0
  34. data/lib/vagabond/cookbooks/lxc/recipes/knife.rb +37 -0
  35. data/lib/vagabond/cookbooks/lxc/resources/#container.rb# +28 -0
  36. data/lib/vagabond/cookbooks/lxc/resources/config.rb +19 -0
  37. data/lib/vagabond/cookbooks/lxc/resources/container.rb +28 -0
  38. data/lib/vagabond/cookbooks/lxc/resources/fstab.rb +11 -0
  39. data/lib/vagabond/cookbooks/lxc/resources/interface.rb +10 -0
  40. data/lib/vagabond/cookbooks/lxc/resources/service.rb +5 -0
  41. data/lib/vagabond/cookbooks/lxc/templates/default/client.rb.erb +13 -0
  42. data/lib/vagabond/cookbooks/lxc/templates/default/default-lxc.erb +3 -0
  43. data/lib/vagabond/cookbooks/lxc/templates/default/fstab.erb +5 -0
  44. data/lib/vagabond/cookbooks/lxc/templates/default/interface.erb +21 -0
  45. data/lib/vagabond/cookbooks/lxc/test/kitchen/Kitchenfile +7 -0
  46. data/lib/vagabond/cookbooks/lxc/test/kitchen/cookbooks/lxc_test/metadata.rb +2 -0
  47. data/lib/vagabond/cookbooks/lxc/test/kitchen/cookbooks/lxc_test/recipes/centos_lxc.rb +0 -0
  48. data/lib/vagabond/cookbooks/lxc/test/kitchen/cookbooks/lxc_test/recipes/chef-bootstrap.rb +0 -0
  49. data/lib/vagabond/cookbooks/lxc/test/kitchen/cookbooks/lxc_test/recipes/lxc_files.rb +0 -0
  50. data/lib/vagabond/cookbooks/lxc/test/kitchen/cookbooks/lxc_test/recipes/lxc_templates.rb +0 -0
  51. data/lib/vagabond/cookbooks/lxc/test/kitchen/cookbooks/lxc_test/recipes/ubuntu_lxc.rb +0 -0
  52. data/lib/vagabond/cookbooks/vagabond/attributes/default.rb +2 -0
  53. data/lib/vagabond/cookbooks/vagabond/libraries/vagabond.rb +10 -0
  54. data/lib/vagabond/cookbooks/vagabond/metadata.rb +6 -0
  55. data/lib/vagabond/cookbooks/vagabond/recipes/create.rb +3 -0
  56. data/lib/vagabond/cookbooks/vagabond/recipes/default.rb +30 -0
  57. data/lib/vagabond/internal_configuration.rb +147 -0
  58. data/lib/vagabond/server.rb +158 -0
  59. data/lib/vagabond/vagabond.rb +109 -0
  60. data/lib/vagabond/vagabondfile.rb +34 -0
  61. data/lib/vagabond/version.rb +10 -0
  62. data/vagabond.gemspec +18 -0
  63. metadata +125 -0
@@ -0,0 +1,342 @@
1
+ def load_current_resource
2
+ new_resource._lxc Lxc.new(
3
+ new_resource.name,
4
+ :base_dir => node[:lxc][:container_directory],
5
+ :dnsmasq_lease_file => node[:lxc][:dnsmasq_lease_file]
6
+ )
7
+ # TODO: Use some actual logic here, sheesh
8
+ if(new_resource.static_ip && new_resource.static_gateway.nil?)
9
+ new_resource.static_gateway new_resource.static_ip.sub(/\d+$/, '1')
10
+ end
11
+ new_resource.default_bridge node[:lxc][:bridge] unless new_resource.default_bridge
12
+ new_resource.new_container !new_resource._lxc.exists?
13
+ end
14
+
15
+ action :create do
16
+
17
+ #### Add custom key for host based interactions
18
+ lxc_dir = directory '/opt/hw-lxc-config' do
19
+ action :nothing
20
+ end
21
+ lxc_dir.run_action(:create)
22
+
23
+ lxc_key = execute "lxc host_ssh_key" do
24
+ command "ssh-keygen -P '' -f /opt/hw-lxc-config/id_rsa"
25
+ creates "/opt/hw-lxc-config/id_rsa"
26
+ action :nothing
27
+ end
28
+ lxc_key.run_action(:run)
29
+
30
+ #### Create container
31
+ execute "lxc create[#{new_resource.name}]" do
32
+ command "lxc-create -n #{new_resource.name} -t #{new_resource.template} -- #{new_resource.template_opts.to_a.flatten.join(' ')}"
33
+ only_if do
34
+ !new_resource._lxc.exists? && new_resource.updated_by_last_action(true)
35
+ end
36
+ end
37
+
38
+ #### Create container configuration bits
39
+ if(new_resource.default_config)
40
+ lxc_config new_resource.name do
41
+ action :create
42
+ default_bridge new_resource.default_bridge
43
+ static_ip new_resource.static_ip
44
+ end
45
+ end
46
+
47
+ if(new_resource.default_fstab)
48
+ lxc_fstab "proc[#{new_resource.name}]" do
49
+ container new_resource.name
50
+ file_system 'proc'
51
+ mount_point 'proc'
52
+ type 'proc'
53
+ options %w(nodev noexec nosuid)
54
+ end
55
+
56
+ lxc_fstab "sysfs[#{new_resource.name}]" do
57
+ container new_resource.name
58
+ file_system 'sysfs'
59
+ mount_point 'sys'
60
+ type 'sysfs'
61
+ options 'default'
62
+ end
63
+ end
64
+
65
+ if(new_resource.static_ip)
66
+ lxc_interface "eth0[#{new_resource.name}]" do
67
+ container new_resource.name
68
+ device 'eth0'
69
+ address new_resource.static_ip
70
+ netmask new_resource.static_netmask
71
+ gateway new_resource.static_gateway
72
+ end
73
+
74
+ ruby_block "force container gateway[#{new_resource.name}]" do
75
+ block do
76
+ file = Chef::Util::FileEdit.new(
77
+ ::File.join(
78
+ new_resource._lxc.rootfs, 'etc', 'rc.local'
79
+ )
80
+ )
81
+ file.search_file_delete_line(%r{route add default gw})
82
+ file.search_file_replace(
83
+ %r{exit 0$},
84
+ "route add default gw #{new_resource.static_gateway}\nexit 0"
85
+ )
86
+ file.write_file
87
+ end
88
+ not_if "grep \"route add default gw #{new_resource.static_gateway}\" #{::File.join(new_resource._lxc.rootfs, 'etc', 'rc.local')}"
89
+ end
90
+ end
91
+
92
+ #### Ensure host has ssh access into container
93
+ directory ::File.join(new_resource._lxc.rootfs, 'root', '.ssh')
94
+
95
+ file ::File.join(new_resource._lxc.rootfs, 'root', '.ssh', 'authorized_keys') do
96
+ content "# Chef generated key file\n#{::File.read('/opt/hw-lxc-config/id_rsa.pub')}\n"
97
+ end
98
+
99
+ if(new_resource.chef_enabled || !new_resource.container_commands.empty? || !new_resource.initialize_commands.empty?)
100
+ if(new_resource.chef_enabled && new_resource.new_container)
101
+
102
+ #### Use cached chef package from host if available
103
+ if(%w(debian ubuntu).include?(new_resource.template) && system('ls /opt/chef*.deb 2>1 > /dev/null'))
104
+ file_name = Dir.new('/opt').detect do |item|
105
+ item.start_with?('chef') && item.end_with?('.deb')
106
+ end
107
+ if(file_name)
108
+ execute "lxc copy_chef_full[#{new_resource.name}]" do
109
+ command "cp /opt/#{file_name} #{::File.join(new_resource._lxc.rootfs, 'opt')}"
110
+ not_if do
111
+ ::File.exists?(
112
+ ::File.join(new_resource._lxc.rootfs, 'opt', file_name)
113
+ )
114
+ end
115
+ end
116
+
117
+ execute "lxc install_chef_full[#{new_resource.name}]" do
118
+ action :nothing
119
+ command "chroot #{new_resource._lxc.rootfs} dpkg -i #{::File.join('/opt', file_name)}"
120
+ subscribes :run, resources(:execute => "lxc copy_chef_full[#{new_resource.name}]"), :immediately
121
+ end
122
+ @chef_installed = true
123
+ end
124
+ end
125
+
126
+ # TODO: Add resources for RPM install
127
+
128
+ #### Setup chef related bits within container
129
+ directory ::File.join(new_resource._lxc.rootfs, 'etc', 'chef') do
130
+ action :create
131
+ mode 0755
132
+ end
133
+
134
+ template "lxc chef-config[#{new_resource.name}]" do
135
+ source 'client.rb.erb'
136
+ cookbook 'lxc'
137
+ path ::File.join(new_resource._lxc.rootfs, 'etc', 'chef', 'client.rb')
138
+ variables(
139
+ :validation_client => new_resource.validation_client,
140
+ :node_name => new_resource.node_name || "#{node.name}-#{new_resource.name}",
141
+ :server_uri => new_resource.server_uri,
142
+ :chef_environment => new_resource.chef_environment || '_default'
143
+ )
144
+ mode 0644
145
+ end
146
+
147
+ file "lxc chef-validator[#{new_resource.name}]" do
148
+ path ::File.join(new_resource._lxc.rootfs, 'etc', 'chef', 'validator.pem')
149
+ content new_resource.validator_pem || node[:lxc][:validator_pem]
150
+ mode 0600
151
+ end
152
+
153
+ file "lxc chef-runlist[#{new_resource.name}]" do
154
+ path ::File.join(new_resource._lxc.rootfs, 'etc', 'chef', 'first_run.json')
155
+ content({:run_list => new_resource.run_list}.to_json)
156
+ not_if do
157
+ ::File.exists?(
158
+ ::File.join(new_resource._lxc.rootfs, 'etc', 'chef', 'client.pem')
159
+ )
160
+ end
161
+ mode 0644
162
+ end
163
+
164
+ #### Provide data bag secret file if required
165
+ if(new_resource.copy_data_bag_secret_file)
166
+ if ::File.readable?(new_resource.data_bag_secret_file)
167
+ file "lxc chef-data-bag-secret[#{new_resource.name}]" do
168
+ path ::File.join(new_resource._lxc.rootfs, 'etc', 'chef', 'encrypted_data_bag_secret')
169
+ content ::File.open(new_resource.data_bag_secret_file, "rb").read
170
+ mode 0600
171
+ end
172
+ else
173
+ Chef::Log.warn "Could not read #{new_resource.data_bag_secret_file}"
174
+ end
175
+ end
176
+ end
177
+
178
+ ruby_block "lxc start[#{new_resource.name}]" do
179
+ block do
180
+ new_resource._lxc.start
181
+ end
182
+ only_if do
183
+ ::File.exists?(
184
+ ::File.join(new_resource._lxc.rootfs, 'etc', 'chef', 'first_run.json')
185
+ ) || (new_resource.new_container && new_resource.initialize_commands)
186
+ end
187
+ end
188
+
189
+ if(new_resource.chef_enabled && new_resource.new_container)
190
+ # Make sure we have chef in the container
191
+ unless(@chef_installed)
192
+ # Use remote file to remove curl dep
193
+ remote_file "lxc chef_install_script[#{new_resource.name}]" do
194
+ source "http://opscode.com/chef/install.sh"
195
+ path ::File.join(new_resource._lxc.rootfs, 'opt', 'chef-install.sh')
196
+ action :create_if_missing
197
+ end
198
+
199
+ ruby_block "lxc install_chef[#{new_resource.name}]" do
200
+ block do
201
+ new_resource._lxc.container_command(
202
+ "bash /opt/chef-install.sh"
203
+ )
204
+ end
205
+ not_if do
206
+ ::File.exists?(
207
+ ::File.join(new_resource._lxc.rootfs, 'usr', 'bin', 'chef-client')
208
+ )
209
+ end
210
+ end
211
+ end
212
+
213
+ #### Let chef configure the container
214
+ ruby_block "lxc run_chef[#{new_resource.name}]" do
215
+ block do
216
+ new_resource._lxc.container_command(
217
+ "chef-client -K /etc/chef/validator.pem -c /etc/chef/client.rb -j /etc/chef/first_run.json",
218
+ new_resource.chef_retries
219
+ )
220
+ end
221
+ not_if do
222
+ ::File.exists?(
223
+ ::File.join(new_resource._lxc.rootfs, 'etc', 'chef', 'client.pem')
224
+ )
225
+ end
226
+ end
227
+ end
228
+
229
+ #### Have initialize commands for the container? Run them now
230
+ if(new_resource.new_container && !new_resource.initialize_commands.empty?)
231
+ ruby_block "lxc initialize_commands[#{new_resource.name}]" do
232
+ block do
233
+ new_resource.initialize_commands.each do |cmd|
234
+ new_resource._lxc.container_command(cmd, 2)
235
+ end
236
+ end
237
+ end
238
+ end
239
+
240
+ #### Have commands for the container? Run them now
241
+ unless(new_resource.container_commands.empty?)
242
+ ruby_block "lxc container_commands[#{new_resource.name}]" do
243
+ block do
244
+ new_resource.container_commands.each do |cmd|
245
+ new_resource._lxc.container_command(cmd, 2)
246
+ end
247
+ end
248
+ end
249
+ end
250
+
251
+ #### NOTE: Creation always leaves the container in a stopped state
252
+ ruby_block "lxc shutdown[#{new_resource.name}]" do
253
+ block do
254
+ new_resource._lxc.shutdown
255
+ end
256
+ only_if do
257
+ new_resource.new_container
258
+ end
259
+ end
260
+
261
+ #### Clean up after chef if it's enabled
262
+ if(new_resource.chef_enabled)
263
+ file ::File.join(new_resource._lxc.rootfs, 'etc', 'chef', 'first_run.json') do
264
+ action :delete
265
+ end
266
+
267
+ file ::File.join(new_resource._lxc.rootfs, 'etc', 'chef', 'validator.pem') do
268
+ action :delete
269
+ end
270
+ end
271
+ end
272
+
273
+ end
274
+
275
+ action :delete do
276
+ ruby_block "lxc stop[#{new_resource.name}]" do
277
+ block do
278
+ new_resource._lxc.stop
279
+ end
280
+ only_if do
281
+ new_resource._lxc.running?
282
+ end
283
+ end
284
+
285
+ execute "lxc delete[#{new_resource.name}]" do
286
+ command "lxc-destroy -n #{new_resource.name}"
287
+ only_if do
288
+ new_resource._lxc.exists? && new_resource.updated_by_last_action(true)
289
+ end
290
+ end
291
+ end
292
+
293
+ action :clone do
294
+ execute "lxc clone[#{new_resource.base_container} -> #{new_resource.name}]" do
295
+ command "lxc-clone -o #{new_resource.base_container} -n #{new_resource.name}"
296
+ only_if do
297
+ !new_resource._lxc.exists? && new_resource.updated_by_last_action(true)
298
+ end
299
+ end
300
+
301
+ lxc_service "lxc config_restart[#{new_resource.name}]" do
302
+ service_name new_resource.name
303
+ action :nothing
304
+ only_if do
305
+ new_resource._lxc.running?
306
+ end
307
+ end
308
+
309
+ lxc_config new_resource.name do
310
+ config new_resource.config
311
+ action :create
312
+ notifies :restart, resources(:lxc_service => "lxc config_restart[#{new_resource.name}]"), :immediately
313
+ end
314
+
315
+ if(new_resource.chef_enabled)
316
+ ruby_block "lxc start[#{new_resource.name}]" do
317
+ block do
318
+ new_resource._lxc.start
319
+ end
320
+ action :nothing
321
+ subscribes :create, resources(:execute => "lxc clone[#{new_resource.base_container} -> #{new_resource.name}]"), :immediately
322
+ end
323
+
324
+ ruby_block "lxc run_chef[#{new_resource.name}]" do
325
+ block do
326
+ new_resource._lxc.container_command(
327
+ "chef-client -K /etc/chef/validator.pem -c /etc/chef/client.rb -j /etc/chef/first_run.json", 3
328
+ )
329
+ end
330
+ action :nothing
331
+ subscribes :create, resources(:execute => "lxc clone[#{new_resource.base_container} -> #{new_resource.name}]"), :immediately
332
+ end
333
+
334
+ ruby_block "lxc shutdown[#{new_resource.name}]" do
335
+ block do
336
+ new_resource._lxc.shutdown
337
+ end
338
+ action :nothing
339
+ subscribes :create, resources(:execute => "lxc clone[#{new_resource.base_container} -> #{new_resource.name}]"), :immediately
340
+ end
341
+ end
342
+ end
@@ -0,0 +1,71 @@
1
+ def load_current_resource
2
+ new_resource._lxc Lxc.new(
3
+ new_resource.container,
4
+ :base_dir => node[:lxc][:container_directory],
5
+ :dnsmasq_lease_file => node[:lxc][:dnsmasq_lease_file]
6
+ )
7
+ @loaded ||= {}
8
+ node.run_state[:lxc] ||= Mash.new
9
+ node.run_state[:lxc][:fstabs] ||= Mash.new
10
+ node.run_state[:lxc][:fstabs][new_resource.container] ||= []
11
+ end
12
+
13
+ action :create do
14
+ unless(@loaded[new_resource.container])
15
+ @loaded[new_resource.container] = true
16
+ ruby_block "lxc_fstab_notifier[#{new_resource.container}]" do
17
+ action :create
18
+ block{ true }
19
+ only_if do
20
+ new_resource.updated_by_last_action?
21
+ end
22
+ end
23
+ template ::File.join(new_resource._lxc.container_path, 'fstab') do
24
+ cookbook 'lxc'
25
+ source 'fstab.erb'
26
+ mode 0644
27
+ variables :container => new_resource.container
28
+ subscribes :create, resources(:ruby_block => "lxc_fstab_notifier[#{new_resource.container}]"), :delayed
29
+ end
30
+ end
31
+
32
+ line = "#{new_resource.file_system}\t#{new_resource.mount_point}\t" <<
33
+ "#{new_resource.type}\t#{Array(new_resource.options).join(',')}\t" <<
34
+ "#{new_resource.dump}\t#{new_resource.pass}"
35
+
36
+ unless(node.run_state[:lxc][:fstabs][new_resource.container].include?(line))
37
+ node.run_state[:lxc][:fstabs][new_resource.container] << line
38
+ new_resource.updated_by_last_action(true)
39
+ end
40
+
41
+ end
42
+
43
+ action :delete do
44
+ unless(@loaded[new_resource.container])
45
+ @loaded[new_resource.container] = true
46
+
47
+ ruby_block "lxc_fstab_notifier[#{new_resource.container}]" do
48
+ action :create
49
+ block{ true }
50
+ only_if do
51
+ new_resource.updated_by_last_action?
52
+ end
53
+ end
54
+
55
+ template ::File.join(new_resource._lxc.container_path, 'fstab') do
56
+ cookbook 'lxc'
57
+ source 'fstab.erb'
58
+ mode 0644
59
+ variables :container => new_resource.container
60
+ subscribes :create, resources(:ruby_block => "lxc_fstab_notifier[#{new_resource.container}]"), :delayed
61
+ end
62
+ end
63
+
64
+ line = "#{new_resource.file_system}\t#{new_resource.mount_point}\t" <<
65
+ "#{new_resource.type}\t#{Array(new_resource.options).join(' ')}\t" <<
66
+ "#{new_resource.dump}\t#{new_resource.pass}"
67
+ if(node.run_state[:lxc][:fstabs][new_resource.container].include?(line))
68
+ node.run_state[:lxc][:fstabs][new_resource.container].delete(line)
69
+ new_resource.updated_by_last_action(true)
70
+ end
71
+ end
@@ -0,0 +1,99 @@
1
+ def load_current_resource
2
+ @lxc = Lxc.new(
3
+ new_resource.container,
4
+ :base_dir => node[:lxc][:container_directory],
5
+ :dnsmasq_lease_file => node[:lxc][:dnsmasq_lease_file]
6
+ )
7
+ @loaded ||= {}
8
+ # value checks
9
+ unless(new_resource.dynamic)
10
+ %w(address netmask).each do |key|
11
+ raise "#{key} is required for static interfaces" if new_resource.send(key).nil?
12
+ end
13
+ end
14
+ # address checks
15
+ unless(new_resource.dynamic)
16
+ %w(address).each do |key|
17
+ new_resource.send(key).split('.').each do |oct|
18
+ raise "#{key} is not a valid address" if oct.to_i > 254
19
+ end
20
+ end
21
+ new_resource.netmask.split('.').each do |oct|
22
+ raise 'netmask is not valid' if oct.to_i > 255
23
+ end
24
+ end
25
+ interfaces = node[:lxc][:interfaces] || Mash.new
26
+ interfaces[new_resource.container] ||= []
27
+ node[:lxc][:interfaces] = interfaces
28
+ end
29
+
30
+ action :create do
31
+ unless(@loaded[new_resource.container])
32
+ @loaded[new_resource.container] = true
33
+ ruby_block "lxc_interface_notifier[#{new_resource.container}]" do
34
+ action :create
35
+ block{ true }
36
+ only_if do
37
+ new_resource.updated_by_last_action?
38
+ end
39
+ end
40
+ template ::File.join(@lxc.rootfs, 'etc', 'network', 'interfaces') do
41
+ source 'interface.erb'
42
+ cookbook 'lxc'
43
+ variables :container => new_resource.container
44
+ subscribes :create, resources(:ruby_block => "lxc_interface_notifier[#{new_resource.container}]"), :delayed
45
+ mode 0644
46
+ end
47
+ end
48
+
49
+ net_set = Mash.new(:device => new_resource.device)
50
+ if(new_resource.dynamic)
51
+ net_set[:dynamic] = true
52
+ else
53
+ net_set[:address] = new_resource.address
54
+ net_set[:gateway] = new_resource.gateway
55
+ net_set[:netmask] = new_resource.netmask
56
+ end
57
+
58
+ unless(node[:lxc][:interfaces][new_resource.container].include?(net_set))
59
+ current_interfaces = node[:lxc][:interfaces][new_resource.container].dup
60
+ current_interfaces << net_set
61
+ node[:lxc][:interfaces][new_resource.contaienr] = current_interfaces
62
+ new_resource.updated_by_last_action(true)
63
+ end
64
+ end
65
+
66
+ action :delete do
67
+ unless(@loaded[new_resource.container])
68
+ @loaded[new_resource.container] = true
69
+ ruby_block "lxc_interface_notifier[#{new_resource.container}]" do
70
+ action :create
71
+ block{ true }
72
+ only_if do
73
+ new_resource.updated_by_last_action?
74
+ end
75
+ end
76
+ template ::File.join(@lxc.rootfs, 'etc', 'interfaces') do
77
+ cookbook 'lxc'
78
+ source 'interface.erb'
79
+ variables :container => new_resource.container
80
+ subscribes :create, resources(:ruby_block => "lxc_interface_notifier[#{new_resource.container}]"), :delayed
81
+ end
82
+ end
83
+
84
+ net_set = Mash.new(:device => new_resource.device)
85
+ if(new_resource.dynamic)
86
+ net_set[:dynamic] = true
87
+ else
88
+ net_set[:address] = new_resource.address
89
+ net_set[:gateway] = new_resource.gateway
90
+ net_set[:netmask] = new_resource.netmask
91
+ end
92
+
93
+ if(node[:lxc][:interfaces][new_resource.container].include?(net_set))
94
+ current_interfaces = node[:lxc][:interfaces][new_resource.container].dup
95
+ current_interfaces.delete(net_set)
96
+ node[:lxc][:interfaces][new_resource.contaienr] = current_interfaces
97
+ new_resource.updated_by_last_action(true)
98
+ end
99
+ end