loadimage.php3 3.37 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
include("showstuff.php3");

#
# Standard Testbed Header
#
Chad Barb's avatar
Chad Barb committed
13
PAGEHEADER("Snapshot Node Disk into Existing Image Descriptor");
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

#
# Only known and logged in users.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
$isadmin = ISADMIN($uid);

if (! isset($imageid)) {
    USERERROR("Must pass image name to page as 'imageid'.", 1 );
}

# get imageid group/project

$query_result = 
    DBQueryFatal("SELECT pid, gid, imagename, path FROM images ".
		 "WHERE imageid='$imageid'");

if (mysql_num_rows($query_result) == 0) {
    USERERROR("No such image '$imageid'.",1);
}

$row = mysql_fetch_array($query_result);
$image_pid  = $row[pid];
$image_gid  = $row[gid];
$image_name = $row[imagename];
$image_path = $row[path];

# permission check.

#if (! TBProjAccessCheck($uid, $image_pid, $image_gid,
#			$TB_PROJECT_MAKEINFO) ) {
#    USERERROR("You do not have permission to modify images in "
#	    "$pid/$gid.",1);            
#}

if (! TBImageIDAccessCheck($uid, $imageid, $TB_IMAGEID_MODIFYINFO )) {
    USERERROR("You do not have permission to modify image '$imageid'.", 1);
}

if (! isset($node) || isset($cancelled)) {
    echo "<center>";

    if (isset($cancelled)) {
	echo "<h3>Operation cancelled.</h3>";
    }

    echo "<br />";

    echo "<form action='loadimage.php3' method='post'>\n".
Chad Barb's avatar
Chad Barb committed
64
	 "<font size=+1>Node to snapshot into image '$imageid':</font> ".
65 66 67 68 69 70 71 72 73 74 75 76 77 78
	 "<input type='text'   name='node' value='$node'></input>\n".
	 "<input type='hidden' name='imageid' value='$imageid'></input>\n".
	 "<input type='submit' name='submit'  value='Go!'></input>\n".
	 "</form>";
    echo "<font size=+1>Information for Image Descriptor '$imageid':</font>\n";
    SHOWIMAGEID($imageid, 0);

    echo "</center>";
    PAGEFOOTER();
    return;
}

if (! TBNodeAccessCheck($uid, $node, $TB_NODEACCESS_LOADIMAGE)) {
    USERERROR("You do not have permission to ".
Chad Barb's avatar
Chad Barb committed
79
	      "snapshot an image from node '$node'.", 1);
80 81 82 83 84 85 86 87 88
}

# Should check for file file_exists($image_path),
# but that's too messy.

if (! isset($confirmed) ) {
    echo "<center><form action='loadimage.php3' method='post'>\n".
#         "<h2>Image already exists at '<code>$image_path</code>'.".
         "<h2><b>Warning!</b><br />".
Chad Barb's avatar
Chad Barb committed
89 90
	 "Doing a snapshot of node '$node' into image '$imageid' ".
	 "will overwrite any previous snapshot for that image. ".
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
	 "Are you sure you want to continue?</h2>".
         "<input type='hidden' name='node'      value='$node'></input>".
         "<input type='hidden' name='imageid'   value='$imageid'></input>".
         "<input type='submit' name='confirmed' value='Confirm'></input>".
         "&nbsp;".
         "<input type='submit' name='cancelled' value='Cancel'></input>\n".    
         "</form></center>";

    PAGEFOOTER();
    return;
}

TBGroupUnixInfo($image_pid, $image_gid, $unix_gid, $unix_name);

echo "<br>
Chad Barb's avatar
Chad Barb committed
106
      Taking a snapshot of node '$node' into image '$imageid' ...
107 108 109 110 111 112
      <br><br>\n";
flush();

SUEXEC($uid, $unix_gid, "webcreateimage -p $image_pid $image_name $node", 1);

echo "This will take 10 minutes or more; you will receive email
Chad Barb's avatar
Chad Barb committed
113
      notification when the snapshot is complete. In the meantime,
114 115 116 117 118 119 120 121 122 123 124 125
      <b>PLEASE DO NOT</b> delete the imageid or the experiment
      $node is in. In fact, it is best if you do not mess with 
      the node at all!<br>\n";

#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>