/[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 84 - (show annotations)
Fri Jul 31 17:35:20 2009 UTC (11 years, 10 months ago) by dpavlin
File size: 843 byte(s)
if interface is up, just change IP address

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 $interfaces .= qq{
24
25 iface tap0 inet static
26 address $server::ip
27 netmask $server::netmask
28 vde2-switch -
29
30 };
31
32 write_file '/etc/network/interfaces', $interfaces;
33
34 }
35
36 my $ifconfig = ifconfig('tap0');
37 if ( $ifconfig =~ m{UP} ) {
38 $ifconfig =~ m{$server::ip}s && return 'up';
39 system("sudo /sbin/ifconfig tap0 $server::ip netmask $server::netmask") == 0 && return "ip changed $server::ip";
40 die "can't change IP address of tap0 to $server::ip";
41 }
42 system("sudo ifup tap0") == 0 && return 'started';
43 die "can't start tap0: $!";
44 }
45
46 1;

  ViewVC Help
Powered by ViewVC 1.1.26