ipmember.pl 1.02 KB
Newer Older
1 2 3 4 5 6 7 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 44
#!/usr/bin/perl -w
use English;
use Errno;

use lib "/usr/testbed/lib";
use libdb;
use libtestbed;

my $allexp_result =
    DBQueryFatal("select pid,eid from experiments");

while (my ($pid,$eid) = $allexp_result->fetchrow_array) {
    my %ips = ();
    
    my $query_result =
	DBQueryFatal("select vname,ips from virt_nodes ".
		     "where pid='$pid' and eid='$eid'");
		     
    while (my ($vnode,$ips) = $query_result->fetchrow_array) {
	# Take apart the IP list.
	foreach $ipinfo (split(" ", $ips)) {
	    my ($port,$ip) = split(":",$ipinfo);

	    $ips{"$vnode:$port"} = $ip;
	}
    }

    $query_result =
	DBQueryFatal("select vname,member from virt_lans ".
		     "where pid='$pid' and eid='$eid'");
		     
    while (my ($vname,$member) = $query_result->fetchrow_array) {
	my ($vnode,$port) = split(":", $member);
	my $ip = $ips{$member};

	DBQueryFatal("update virt_lans set ".
		     "vnode='$vnode',ip='$ip',vport='$port' ".
		     "where pid='$pid' and eid='$eid' and ".
		     "vname='$vname' and member='$member'");
    }
}