From 86564e958c073ea3722b90151d24c3edb28d662c Mon Sep 17 00:00:00 2001 From: Leigh B Stoller Date: Thu, 12 Jan 2012 15:09:49 -0700 Subject: [PATCH] Allow override of the default jail ip/mask to make it easier to bring up a container using a routable IP. --- db/Node.pm.in | 42 ++++++++++++++++++++++++++++++++------ tbsetup/libvtop_test.pm.in | 5 +++++ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/db/Node.pm.in b/db/Node.pm.in index 8db4ef515..bfbc8ba0b 100644 --- a/db/Node.pm.in +++ b/db/Node.pm.in @@ -1,7 +1,7 @@ #!/usr/bin/perl -wT # # EMULAB-COPYRIGHT -# Copyright (c) 2005-2011 University of Utah and the Flux Group. +# Copyright (c) 2005-2012 University of Utah and the Flux Group. # All rights reserved. # package Node; @@ -13,7 +13,8 @@ use vars qw(@ISA @EXPORT $AUTOLOAD @EXPORT_OK); @EXPORT = qw(); # Configure variables -use vars qw($TB $BOSSNODE $WOL $OSSELECT $ISUTAH $CONTROL_NETMASK $TBOPS); +use vars qw($TB $BOSSNODE $WOL $OSSELECT $ISUTAH $CONTROL_NETMASK + $TBOPS $JAILIPMASK); $TB = "@prefix@"; $BOSSNODE = "@BOSSNODE@"; $TBOPS = "@TBOPSEMAIL@"; @@ -23,6 +24,7 @@ $OSSELECT = "$TB/bin/os_select"; $ISUTAH = @TBMAINSITE@; # Need this for jail ip assignment. $CONTROL_NETMASK = "@CONTROL_NETMASK@"; +$JAILIPMASK = "@JAILIPMASK@"; use libdb; use libtestbed; @@ -1897,6 +1899,7 @@ sub CreateVnodes($$$) my ($class, $rptr, $options) = @_; my @created = (); my @tocreate = (); + my @vlist = (); require Interface; require NodeType; @@ -2193,9 +2196,10 @@ sub CreateVnodes($$$) "def_boot_osid" => $osid, "update_accounts" => 1, "jailflag" => $isjailed); - $nodesets{"jailip"} = $jailip - if ($isjailed && !$isremote); - + if ($isjailed && !$isremote) { + $nodesets{"jailip"} = $jailip; + $nodesets{"jailipmask"} = $JAILIPMASK; + } my $statement = "insert into nodes set ". join(",", map("$_='" . $nodesets{$_} . "'", keys(%nodesets))); @@ -3048,7 +3052,32 @@ sub GetJailIP($;$) $pnet++; $pnode2 -= $nodenumlimit; } - return "${IPBASE1}.${pnet}.${pnode2}.${num}"; + return ("${IPBASE1}.${pnet}.${pnode2}.${num}", $JAILIPMASK); +} + +# +# Another variant of above, this one looks in the virt_node_attributes +# table of the vnode assigned to the pnode. +# +sub SetJailIPFromVnode($$$) +{ + my ($self, $experiment, $vnode_id) = @_; + my ($jailip, $jailipmask); + + return -1 + if ($experiment->GetVirtNodeAttribute($vnode_id, \$jailip) < 0 || + $experiment->GetVirtNodeAttribute($vnode_id, \$jailipmask) < 0); + + if (defined($jailip)) { + if (!defined($jailipmask)) { + print STDERR + "*** $vnode_id has a jailip attribute but no jailipmask.\n"; + return -1; + } + return $self->Update({"jailip" => $jailip, + "jailipmask" => $jailipmask}); + } + return 0; } # @@ -3136,5 +3165,6 @@ sub CheckPreReserve($$) return $result; } + # _Always_ make sure that this 1 is at the end of the file... 1; diff --git a/tbsetup/libvtop_test.pm.in b/tbsetup/libvtop_test.pm.in index 1ca37a505..15810f4cc 100644 --- a/tbsetup/libvtop_test.pm.in +++ b/tbsetup/libvtop_test.pm.in @@ -5117,6 +5117,11 @@ sub AllocVirtNodes($) # $pnode->ModifyReservation({"vname" => $virtual}) == 0 or return -1 if (!$self->impotent()); + + # + # Not sure where to put this. + # + $pnode->SetJailIPFromVnode($experiment, $virtual); } # Since we have some extra physical vnodes reserved on this pnode, -- GitLab