/[pxelator]/lib/PXElator/network.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

Contents of /lib/PXElator/network.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 99 - (show annotations)
Fri Jul 31 21:42:10 2009 UTC (11 years, 5 months ago) by dpavlin
File size: 951 byte(s)
update /etc/network/interfaces as root, add user to vde2-net group
1 package network;
2
3 use warnings;
4 use strict;
5
6 use File::Slurp;
7
8 use server;
9
10 sub ifconfig {
11 my $dev = shift;
12 `/sbin/ifconfig $dev`
13 }
14
15 sub tap {
16
17 my $interfaces = read_file '/etc/network/interfaces';
18
19 if ( $interfaces !~ m{tap0.*$server::ip}s ) {
20
21 system "sudo apt-get install vde2";
22
23 write_file '/tmp/interfaces', qq{
24
25 # added by PXElator
26 iface tap0 inet static
27 address $server::ip
28 netmask $server::netmask
29 vde2-switch -
30
31 };
32
33 system q|sudo sh -c 'cat /tmp/interfaces >> /etc/network/interfaces'|;
34 system q|sudo sh -c 'usermod -G vde2-net -a $SUDO_USER'|;
35
36 }
37
38 my $ifconfig = ifconfig('tap0');
39 if ( $ifconfig =~ m{UP} ) {
40 $ifconfig =~ m{$server::ip}s && return 'up';
41 system("sudo /sbin/ifconfig tap0 $server::ip netmask $server::netmask") == 0 && return "ip changed $server::ip";
42 die "can't change IP address of tap0 to $server::ip";
43 }
44 system("sudo ifup tap0") == 0 && return 'started';
45 die "can't start tap0: $!";
46 }
47
48 1;

  ViewVC Help
Powered by ViewVC 1.1.26