Commit fdd08bb4 authored by Leigh Stoller's avatar Leigh Stoller

Add support for creating snapshot images of OpenVZ containers via the

web interface.

Most of this commit is about making it easier to create the
descriptors (of any kind) The newimageid_ez page now takes an optional
node_id on which to base the new descriptor; most of the fields are
initialized.

You can also provide optional imageid and osinfo arguments, which
allows for slightly less info to be initialized.

Then on the ShowNode page, the link to create an image will take you
to the snapshot image page if the user has write access to the image,
otherwise to the newimageid_iz page to create and snapshot a new
image descriptor.
parent 5e4f9e7f
......@@ -106,6 +106,7 @@ my $def_devtype = "ad";
my $def_devnum = 0;
my $devtype;
my $devnum;
my $device;
my $mereuser = 0;
my $debug = 0;
my $foreground = 0;
......@@ -114,6 +115,8 @@ my $logfile;
my $oldlogfile;
my $needcleanup = 0;
my $needunlock = 0;
my $isvirtnode = 0;
my $didbackup = 0;
#
# Parse command arguments. Once we return from getopts, all that should be
......@@ -221,6 +224,8 @@ if (!defined($node)) {
die("*** $0:\n".
" Invalid node name $node_id!\n");
}
$isvirtnode = $node->isvirtnode();
if ($UID && ! $this_user->IsAdmin()) {
$mereuser = 1;
......@@ -362,26 +367,47 @@ if ($?) {
}
if (-e $filename) {
unlink($filename) or
fatal("Could not delete $filename: $!");
#
# Back it up in case of failure. Note that the frisbee upload server
# does this, so we do it only for the ssh/nfs case.
#
if (!$usefup) {
system("/bin/mv -f $filename ${filename}.bak");
if ($?) {
fatal("Could not back up $filename");
}
$didbackup = 1;
}
}
open(FILE, "> $filename") or
fatal("Could not create $filename: $!");
close(FILE) or
fatal("Could not truncate $filename: $!");
#
# Get the disktype for this node
# We want to truncate the file (we backed it up above), which also
# confirms the user can really create a new file.
#
# XXX The problem is that frisbee upload server does this too, which
# is why we have a lot of zero length backup files. So, in uploader
# mode, make sure the user can create the tmp file that the uploader
# uses.
#
$node->disktype(\$devtype);
$node->bootdisk_unit(\$devnum);
$tmp = $filename . ($usefup ? ".tmp" : "");
open(FILE, "> $tmp") or
fatal("Could not create $tmp: $!");
close(FILE) or
fatal("Could not truncate $tmp: $!");
$devtype = $def_devtype
if (!defined($devtype));
$devnum = $def_devnum
if (!defined($devnum));
my $device = "/dev/${devtype}${devnum}";
if (!$isvirtnode) {
#
# Get the disktype for this node
#
$node->disktype(\$devtype);
$node->bootdisk_unit(\$devnum);
$devtype = $def_devtype
if (!defined($devtype));
$devnum = $def_devnum
if (!defined($devnum));
$device = "/dev/${devtype}${devnum}";
}
#
# Record when this image was updated, so that we can figure out which
......@@ -396,8 +422,8 @@ $image->MarkUpdateTime() == 0 or
# slice (or perhaps the entire disk) is going to be zipped up. We do not
# allow arbitrary combos of course.
#
my $startslice = $image->loadpart();
my $loadlength = $image->loadlength();
my $startslice;
my $loadlength;
my $command = "$createimage ";
if ($usefup) {
......@@ -405,10 +431,18 @@ if ($usefup) {
$command .= " -S $BOSSIP -F $id";
}
if ($startslice || $loadlength == 1) {
$command .= " -s $startslice";
if ($isvirtnode) {
$command .= " $node_id";
}
else {
$startslice = $image->loadpart();
$loadlength = $image->loadlength();
if ($startslice || $loadlength == 1) {
$command .= " -s $startslice";
}
$command .= " $device";
}
$command .= " $device";
if ($usefup || $usessh) {
$command .= " -";
......@@ -491,6 +525,21 @@ my $maxidleticks = int($idlewait / $checkwait);
my $lastsize = 0;
my $result;
#
# We can skip a lot of the stuff below for virtnodes.
#
if ($isvirtnode) {
#
# ...execute command and wait!
#
if ($NONFS) {
$result = run_with_ssh($command, $filename);
} else {
$result = run_with_ssh($command, undef);
}
goto done;
}
#
# Reboot into admin mode and run the command.
# Note that without a shared FS, we just boot the node into the admin MFS
......@@ -691,6 +740,13 @@ sub cleanup ()
{
$needcleanup = 0;
if ($isvirtnode) {
#
# Nothing to do; the clientside script rebooted the container.
#
return 1;
}
#
# Turn admin mode back off and reboot back to the old OS
#
......@@ -750,6 +806,10 @@ sub fatal($)
}
$image->Unlock()
if ($needunlock);
# Restore old image file.
if ($didbackup) {
system("/bin/mv -f ${filename}.bak $filename");
}
exit(-1);
}
......@@ -845,6 +905,8 @@ sub run_with_ssh($$)
{
my ($cmd,$output) = @_;
my $stat = undef;
$node_id = $node->phys_nodeid()
if ($isvirtnode);
$cmd = "$TB/bin/sshtb -n -host $node_id $cmd";
if (defined($output)) {
......
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2011 University of Utah and the Flux Group.
# Copyright (c) 2000-2012 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
......@@ -86,17 +86,22 @@ $unix_pid = $project->unix_gid();
if (! isset($confirmed)) {
$url = CreateURL("loadimage", $image);
$newurl = CreateURL("newimageid_ez", $node);
echo "<center><form action='$url' method='post'>\n".
"<h2><b>Warning!</b></h2>".
"<h3>Doing a snapshot of node '$node_id' into image '$image_name' ".
"will overwrite any previous snapshot for that image. ".
"Are you sure you want to continue?</h3>".
"<b>Doing a snapshot of node '$node_id' into image '$image_name' ".
"will overwrite any previous snapshot for that image.<br><br> ".
"Are you sure you want to continue?</b><br>".
"<input type='hidden' name='node_id' value='$node_id'></input>".
"<input type='submit' name='confirmed' value='Confirm'></input>".
"&nbsp;".
"<input type='submit' name='canceled' value='Cancel'></input>\n".
"</form></center>";
"</form>".
"<br>".
"If you do not want to overwrite this image, then ".
"<a href='$newurl'>Create a new image</a>".
"</center>";
PAGEFOOTER();
return;
......
This diff is collapsed.
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2011 University of Utah and the Flux Group.
# Copyright (c) 2000-2012 University of Utah and the Flux Group.
# All rights reserved.
#
# Stuff for OSIDs. All this stuff should come from the DB instead!
......@@ -37,10 +37,12 @@ $osid_opmodes["NORMALv1"] = 0;
$osid_opmodes["MINIMAL"] = 1;
$osid_opmodes["NORMAL"] = 1;
$osid_opmodes["ALWAYSUP"] = 1;
$osid_opmodes["PCVM"] = 1;
define("TBDB_DEFAULT_OSID_OPMODE", "NORMALv2");
define("TBDB_MINIMAL_OPMODE", "MINIMAL");
define("TBDB_ALWAYSUP_OPMODE", "ALWAYSUP");
define("TBDB_PCVM_OPMODE", "PCVM");
# Default OSID boot wait timeouts. User is not allowed to edit this.
$osid_reboot_waitlist = array();
......
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2006-2011 University of Utah and the Flux Group.
# Copyright (c) 2006-2012 University of Utah and the Flux Group.
# All rights reserved.
#
......@@ -197,6 +197,7 @@ class OSinfo
function max_concurrent() { return $this->field("max_concurrent"); }
function mfs() { return $this->field("mfs"); }
function reboot_waittime() { return $this->field("reboot_waittime"); }
function def_parentosid() { return $this->field("def_parentosid"); }
#
# Access Check, determines if $user can access $this record.
......@@ -330,6 +331,7 @@ class OSinfo
$created = $this->created();
$mustclean = $this->mustclean();
$nextosid = $this->nextosid();
$def_parentosid = $this->def_parentosid();
$max_concurrent = $this->max_concurrent();
$reboot_waittime= $this->reboot_waittime();
$uuid = $this->uuid();
......@@ -457,6 +459,14 @@ class OSinfo
$nextosid</a></td>
</tr>\n";
}
if ($def_parentosid) {
echo "<tr>
<td>Parent Osid: </td>
<td class=left>
<a href='showosinfo.php3?osid=$def_parentosid'>
$def_parentosid</a></td>
</tr>\n";
}
if ($ezid) {
echo "<tr>
<td>Image Link: </td>
......
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2007 University of Utah and the Flux Group.
# Copyright (c) 2000-2012 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
include_once("node_defs.php");
include_once("imageid_defs.php");
#
# Only known and logged in users can do this.
......@@ -109,8 +110,22 @@ if ($isadmin ||
}
if ($node->AccessCheck($this_user, $TB_NODEACCESS_LOADIMAGE)) {
WRITESUBMENUBUTTON("Create a Disk Image",
"newimageid_ez.php3?formfields[node_id]=$node_id");
$baseimage = Image::Lookup($node->def_boot_osid());
if ($baseimage &&
$baseimage->AccessCheck($this_user, $TB_IMAGEID_DESTROY)) {
WRITESUBMENUBUTTON("Create a Disk Image",
"loadimage.php3?node_id=$node_id" .
"&imageid=" . $baseimage->imageid());
}
else {
#
# This can happen for virtual nodes which are running the
# defaut osid. User must create a new descriptor.
#
WRITESUBMENUBUTTON("Create a Disk Image",
"newimageid_ez.php3?node_id=$node_id");
}
}
if (($isadmin ||
......
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