/[pxelator]/lib/PXElator/lxc.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/PXElator/lxc.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 438 by dpavlin, Sun Sep 20 15:10:31 2009 UTC revision 439 by dpavlin, Sun Sep 20 16:12:03 2009 UTC
# Line 9  use file; Line 9  use file;
9  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
10    
11  sub create {  sub create {
12          my ( $hostname, $ip, $path ) = @_;          my ( $hostname, $path, $ip, $netmask, $server_ip ) = @_;
13    
14          file::append "$path/etc/initab" => $_ foreach qw(          die "$path: $!" unless -d $path;
15    
16            file::append "$path/etc/initab" => "$_\n" foreach split(/\n/, qq|
17  z6:6:respawn:/sbin/sulogin  z6:6:respawn:/sbin/sulogin
18  1:2345:respawn:/sbin/getty 38400 console  1:2345:respawn:/sbin/getty 38400 console
19  c1:12345:respawn:/sbin/getty 38400 tty1 linux  c1:12345:respawn:/sbin/getty 38400 tty1 linux
20  c2:12345:respawn:/sbin/getty 38400 tty2 linux  c2:12345:respawn:/sbin/getty 38400 tty2 linux
21  c3:12345:respawn:/sbin/getty 38400 tty3 linux  c3:12345:respawn:/sbin/getty 38400 tty3 linux
22  c4:12345:respawn:/sbin/getty 38400 tty4 linux  c4:12345:respawn:/sbin/getty 38400 tty4 linux
23          );          |);
24    
25          file::append '/etc/fstab' => 'cgroup /cgroup cgroup rw 0 0' && mkdir '/cgroup';          file::append '/etc/fstab' => 'cgroup /cgroup cgroup rw 0 0' && mkdir '/cgroup';
26          system "mount /cgroup";          system "mount /cgroup";
27    
28          system "lxc-stop    -n $hostname";          system "lxc-stop    --name $hostname";
29          system "lxc-destroy -n $hostname";          system "lxc-destroy --name $hostname";
30    
31          file::replace "$path/etc/hostname" => $hostname;          file::replace "$path/etc/hostname" => $hostname;
32          file::append  "$path/hosts"        => "$ip $hostname";          file::append  "$path/etc/hosts"    => "$ip $hostname";
33    
34            file::replace "$path/etc/network/interfaces" => qq|
35    auto eth0 lo
36    
37    iface lo inet loopback
38    
39    iface eth0 inet static
40        address $ip
41        netmask $netmask
42        gateway $server_ip
43            |;
44    
45            file::replace "$path/etc/resolv.conf" => "nameserver $server_ip";
46    
47          my $conf = "/virtual/$hostname.conf";          my $conf = "/virtual/$hostname.conf";
48    
# Line 37  lxc.tty = 4 Line 52  lxc.tty = 4
52  lxc.pts = 1024  lxc.pts = 1024
53  lxc.network.type = veth  lxc.network.type = veth
54  lxc.network.flags = up  lxc.network.flags = up
55  lxc.network.link = br0  lxc.network.link = virtual
56  lxc.network.name = eth0  lxc.network.name = eth0
57  lxc.network.mtu = 1500  lxc.network.mtu = 1500
58  #lxc.mount = MNTFILE  #lxc.mount = MNTFILE
# Line 60  lxc.cgroup.devices.allow = c 5:2 rwm Line 75  lxc.cgroup.devices.allow = c 5:2 rwm
75  lxc.cgroup.devices.allow = c 254:0 rwm  lxc.cgroup.devices.allow = c 254:0 rwm
76          |;          |;
77    
78          system "lxc-create -n $hostname -f $conf";          system "lxc-create --name $hostname --rcfile $conf";
79    
80          warn "created $hostname $ip $path";          warn "created $hostname $ip $path";
81  }  }

Legend:
Removed from v.438  
changed lines
  Added in v.439

  ViewVC Help
Powered by ViewVC 1.1.26