Class: Wildcloud::Keeper::Isolators::Lxc
- Inherits:
-
Object
- Object
- Wildcloud::Keeper::Isolators::Lxc
- Defined in:
- lib/wildcloud/keeper/isolators/lxc.rb
Instance Method Summary collapse
Instance Method Details
#resources(options) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/wildcloud/keeper/isolators/lxc.rb', line 68 def resources() @id ||= [:id] run("lxc-cgroup -n #{@id} memory.limit_in_bytes \"#{[:memory]}\"") if [:memory] run("lxc-cgroup -n #{@id} memory.memsw.limit_in_bytes \"#{[:swap]}\"") if [:swap] run("lxc-cgroup -n #{@id} cpuset.cpus \"#{[:cpus]}\"") if [:cpus] run("lxc-cgroup -n #{@id} cpu.shares \"#{[:cpu_share]}\"") if [:cpu_share] end |
#start(options) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/wildcloud/keeper/isolators/lxc.rb', line 26 def start() @id = [:id] @target_path = File.join(config['paths']['mounts'], "#{@id}") @config_file = File.join(config['paths']['config'], "#{@id}.config") @fstab_file = File.join(config['paths']['config'], "#{@id}.fstab") vm_config = ERB.new(File.read(File.('../../templates/app.config', __FILE__))).result(binding) vm_fstab = ERB.new(File.read(File.('../../templates/app.fstab', __FILE__))).result(binding) FileUtils.mkdir_p(config['paths']['config']) File.open(@config_file, 'w') { |file| file.write(vm_config) } File.open(@fstab_file, 'w') { |file| file.write(vm_fstab) } run("lxc-create -f #{@config_file} -n #{@id}") run("lxc-start -d -n #{@id}") end |
#stop(options) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/wildcloud/keeper/isolators/lxc.rb', line 47 def stop() @id ||= [:id] @config_file ||= File.join(config['paths']['config'], "#{@id}.config") @fstab_file ||= File.join(config['paths']['config'], "#{@id}.fstab") if [:build] build_status_file = File.join(config['paths']['images'], "#{@id}", 'var', 'build.done') until File.exists?(build_status_file) sleep(5) end end run("lxc-stop -n #{@id}") run("lxc-destroy -n #{@id}") FileUtils.rm(@config_file) FileUtils.rm(@fstab_file) end |