Commit 76e89d3f authored by Leigh Stoller's avatar Leigh Stoller

Allow URLs for osname (imported images). Fixes for shared lans.

For shared lans, move the code that sets up the underlying lan into
the Experiment module, so it can be called from tbswap. This is
to fix some race conditions that can take place if two experiments
are mucking with the underlying lan at the same time.
parent b2959169
......@@ -25,6 +25,7 @@ use Node;
use NodeType;
use Lan;
use OSinfo;
use Image;
use Port;
use English;
use emutil qw(SpanningTree GenFakeMac);
......@@ -1232,24 +1233,31 @@ sub LoadVirtNodes($)
# use the default for the type of phys node that assign picks.
#
if (defined($osname) && $osname ne "") {
my $ospid = $pid;
my $osinfo;
if ($osname =~ /^(.*)\/(.*)$/) {
$ospid = $1;
$osname = $2;
if ($osname =~ /^(ftp|http|https):/) {
my $image = Image->LookupByURL($osname);
if (!defined($image)) {
tberror("Invalid os url $osname!\n");
}
$osinfo = OSinfo->Lookup($image->imageid());
}
my $osinfo = OSinfo->Lookup("$ospid,$osname");
if (!defined($osinfo)) {
$osinfo = OSinfo->LookupByName($osname);
elsif ($osname =~ /^(.*)\/(.*)$/) {
$osinfo = OSinfo->Lookup($osname);
}
else {
$osinfo = OSinfo->Lookup($pid, $osname);
if (!defined($osinfo)) {
tberror({cause => 'user', type => 'primary',
severity => SEV_ERROR,
error => ['invalid_os', undef, $osname, $ospid]},
"Invalid OS $osname in project $ospid!");
return -1;
$osinfo = OSinfo->LookupByName($osname);
}
}
if (!defined($osinfo)) {
tberror({cause => 'user', type => 'primary',
severity => SEV_ERROR,
error => ['invalid_os', undef, $osname, $pid]},
"Invalid OS $osname!");
return -1;
}
$vnode->_osinfo($osinfo);
}
elsif ($isvirt) {
......@@ -7877,82 +7885,6 @@ sub UploadVlans($)
or return -1;
}
}
#
# Deal with port vlans.
#
foreach my $lan (@lans) {
next
if ($lan->type() ne "portlan");
my $lanname;
$lan->GetAttribute("link/lan", \$lanname);
my $virtlan = $self->vlans()->{$lanname};
if (!defined($virtlan)) {
tberror("$lanname does not exist for portvlan\n");
return -1;
}
my $portvlan = $virtlan->_portvlan();
#
# The idea here is to remove any members for this lan
# from the target lan, and then add the new ones. This
# violates update, in that an error after this will not
# restore the missing ports. Need to fix that.
#
my @members;
if ($portvlan->MemberList(\@members) != 0) {
tberror("Could not get member list for $portvlan\n");
return -1;
}
foreach my $member (@members) {
my $member_exptidx;
my $member_lanname;
$member->GetAttribute("portlan_exptidx", \$member_exptidx);
$member->GetAttribute("portlan_lanname", \$member_lanname);
# Not a port in an external lan; a native port.
next
if (!defined($member_exptidx) && !defined($member_lanname));
if (! (defined($member_exptidx) && defined($member_lanname))) {
tberror("Could not get idx/lanname from $member\n");
return -1;
}
next
if (! ($member_exptidx == $exptidx &&
$member_lanname eq $lanname));
# Delete the member.
$self->printdb("Deleting $member from $portvlan\n");
if ($portvlan->DelMember($member)) {
tberror("Could not delete $member from $portvlan\n");
return -1;
}
}
#
# Now add new members.
#
if ($lan->MemberList(\@members) != 0) {
tberror("Could not get member list for $lan\n");
return -1;
}
foreach my $member (@members) {
my $nodeid;
my $iface;
$member->GetNodeIface(\$nodeid, \$iface);
my $newmember = $portvlan->AddMember($nodeid, $iface);
if (!defined($newmember)) {
tberror("Could not add $member to $portvlan\n");
return -1;
}
$self->printdb("Added $newmember to $portvlan\n");
# Mark where the member came from.
$newmember->SetAttribute("portlan_exptidx", $exptidx);
$newmember->SetAttribute("portlan_lanname", $lanname);
}
}
}
else {
$self->printdb("Dumping final protolans table.\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment