Class: Chef::LXC::Fleet
Instance Method Summary
collapse
#chef_config, #create_data_bag, #create_environment, #create_role, #knife, #load_secret, #update_data_bag_item, #upload_cookbooks, #upload_data_bag, #upload_data_bag_item_from_hash
Instance Method Details
#container(name) ⇒ Object
36
37
38
39
40
|
# File 'lib/chef/lxc/fleet.rb', line 36
def container(name)
ct = ::LXC::Container.new(name)
ct.extend Chef::LXC::ContainerHelper
ct
end
|
#create_container(name, opts = {}) {|ct| ... } ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/chef/lxc/fleet.rb', line 15
def create_container(name, opts = {})
force = opts[:force]
ct = container(name)
if ct.defined?
if force
ct.stop if ct.running?
ct.destroy
ct = provision(name, opts)
end
else
ct = provision(name, opts)
end
ct.start unless ct.running?
while ct.ip_addresses.empty?
sleep 1
end
yield ct if block_given?
ct.stop if opts[:stop_after]
ct
end
|
#provision(name, opts = {}) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/chef/lxc/fleet.rb', line 42
def provision(name, opts = {})
from = opts[:from]
if from
base = container(from)
base.clone(name)
else
template = opts[:template] || 'download'
bdevtype = opts[:bdevtype]
bdevspecs = opts[:bdevspecs] || {}
flags = opts[:flags] || 0
args = opts[:args] || %w(-d ubuntu -r trusty -a amd64)
ct = container(name)
ct.create(template, bdevtype, bdevspecs, flags, args)
end
container(name)
end
|