Class: LXC

Inherits:
Object
  • Object
show all
Defined in:
lib/lxc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node_name) ⇒ LXC

Returns a new instance of LXC.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/lxc.rb', line 8

def initialize(node_name)
  @node_name = node_name
  @filename = "/var/lib/lxc/#{node_name}/config"
  @mac = ''
  @interface = ''
  @template = ERB.new "lxc.utsname = <%= node_name %>\nlxc.pts = 1024\nlxc.tty = 4\nlxc.cgroup.cpu.shares = 512\nlxc.rootfs = /var/lib/lxc/<%= node_name %>/rootfs\nlxc.mount = /var/lib/lxc/<%= node_name %>/fstab\nlxc.network.type = veth\nlxc.network.name = eth0\nlxc.network.link = <%= interface %>\nlxc.network.hwaddr = <%= mac %>\nlxc.network.flags = up\nlxc.cgroup.devices.deny = a\nlxc.cgroup.devices.allow = c 1:3 rwm\nlxc.cgroup.devices.allow = c 1:5 rwm\nlxc.cgroup.devices.allow = c 5:1 rwm\nlxc.cgroup.devices.allow = c 5:0 rwm\nlxc.cgroup.devices.allow = c 4:0 rwm\nlxc.cgroup.devices.allow = c 4:1 rwm\nlxc.cgroup.devices.allow = c 1:9 rwm\nlxc.cgroup.devices.allow = c 1:8 rwm\nlxc.cgroup.devices.allow = c 136:* rwm\nlxc.cgroup.devices.allow = c 5:2 rwm\nlxc.cgroup.devices.allow = b 7:0 rwm\nlxc.cgroup.devices.allow = c 254:0 rwm\nlxc.cgroup.devices.allow = c 108:0 rwm\nlxc.cgroup.devices.allow = c 10:229 rwm\nlxc.cgroup.devices.allow = c 10:200 rwm\n"

end

Instance Attribute Details

#interfaceObject

Returns the value of attribute interface.



4
5
6
# File 'lib/lxc.rb', line 4

def interface
  @interface
end

#macObject

Returns the value of attribute mac.



5
6
7
# File 'lib/lxc.rb', line 5

def mac
  @mac
end

#node_nameObject (readonly)

Returns the value of attribute node_name.



6
7
8
# File 'lib/lxc.rb', line 6

def node_name
  @node_name
end

Instance Method Details

#save(filename = @filename) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/lxc.rb', line 45

def save(filename=@filename)
  config_data = @template.result(OpenStruct.new(:node_name => @node_name,
                                                :mac => @mac, :interface => @interface ).send(:binding))
  File.open(".tmp.lxc.conf",'w') do |f|
    f.puts config_data
  end
  system "sudo mv .tmp.lxc.conf #{@filename}"
end