deleteimageid.php3 3.98 KB
Newer Older
1
<?php
Leigh Stoller's avatar
Leigh Stoller committed
2 3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
Leigh Stoller's avatar
Leigh Stoller committed
5 6
# All rights reserved.
#
7 8 9 10 11
include("defs.php3");

#
# Standard Testbed Header
#
12
PAGEHEADER("Delete an Image Descriptor");
13 14 15 16 17 18 19 20

#
# Only known and logged in users can end experiments.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);

#
21
# Must provide the ImageID.
22 23 24
# 
if (!isset($imageid) ||
    strcmp($imageid, "") == 0) {
25
    USERERROR("The ImageID was not provided!", 1);
26 27 28
}

if (! TBValidImageID($imageid)) {
29
    USERERROR("ImageID '$imageid' is not a valid ImageID!", 1);
30 31 32 33 34 35 36 37 38
}

#
# Verify permission.
#
if (!TBImageIDAccessCheck($uid, $imageid, $TB_IMAGEID_DESTROY)) {
    USERERROR("You do not have permission to destroy ImageID $imageid!", 1);
}

39 40 41 42 43 44 45
#
# Get user level info.
#
if (!TBImageInfo($imageid, $imagename, $pid)) {
    USERERROR("ImageID '$imageid' is no longer a valid ImageID!", 1);
}

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
#
# Check to see if the imageid is being used in various places
#
$query_result1 =
    DBQueryFatal("select * from current_reloads where image_id='$imageid'");
$query_result2 =
    DBQueryFatal("select * from scheduled_reloads where image_id='$imageid'");
$query_result3 =
    DBQueryFatal("select * from node_types where imageid='$imageid'");

if (mysql_num_rows($query_result1)) {
    echo "$imageid is referenced in the current_reloads table!<br>";
    $conflicts++;
}
if (mysql_num_rows($query_result2)) {
    echo "$imageid is referenced in the scheduled_reloads table!<br>";
    $conflicts++;
}
if (mysql_num_rows($query_result3)) {
    echo "$imageid is referenced in the node_types table!<br>";
    $conflicts++;
}
if ($conflicts) {
    echo "<br>
          You must resolve these issues before the imageid can be deleted!";
    PAGEFOOTER();
    return;
}

75 76 77 78 79 80 81 82
#
# We run this twice. The first time we are checking for a confirmation
# by putting up a form. The next time through the confirmation will be
# set. Or, the user can hit the cancel button, in which case we should
# probably redirect the browser back up a level.
#
if ($canceled) {
    echo "<center><h2><br>
Leigh Stoller's avatar
Leigh Stoller committed
83
          Image Descriptor removal canceled!
84 85 86 87 88 89 90 91 92
          </h2></center>\n";
    
    PAGEFOOTER();
    return;
}

if (!$confirmed) {
    echo "<center><h2><br>
          Are you <b>REALLY</b>
93
          sure you want to delete Image '$imagename' in project $pid?
94 95 96 97 98 99 100 101 102
          </h2>\n";
    
    echo "<form action='deleteimageid.php3' method=post>";
    echo "<input type=hidden name=imageid value='$imageid'>\n";
    echo "<b><input type=submit name=confirmed value=Confirm></b>\n";
    echo "<b><input type=submit name=canceled value=Cancel></b>\n";
    echo "</form>\n";
    echo "</center>\n";

103 104 105 106 107 108 109 110 111
    echo "<br>
          <ul>
           <li> Please note that if you have any experiments (swapped in
                <b>or</b> out) using an OS in this image, that experiment
                cannot be swapped in or out properly. You should terminate
                those experiments first, or cancel the deletion of this
                image by clicking on the cancel button above.
          </ul>\n";
    
112 113 114 115
    PAGEFOOTER();
    return;
}

116 117
DBQueryFatal("lock tables images write, os_info write, osidtoimageid write");

118
#
119 120 121
# If this is an EZ imageid, then delete the corresponding OSID too.
#
$query_result =
122 123 124 125
    DBQueryFatal("select ezid,path from images where imageid='$imageid'");
$row = mysql_fetch_row($query_result);
$ezid = $row[0];
$path = $row[1];
126 127 128

#
# Delete the record(s).
129 130
#
DBQueryFatal("DELETE FROM images WHERE imageid='$imageid'");
131
DBQueryFatal("DELETE FROM osidtoimageid where imageid='$imageid'");
132
if ($ezid) {
133 134 135 136
    DBQueryFatal("DELETE FROM os_info WHERE osid='$imageid'");
}

DBQueryFatal("unlock tables");
137

138 139 140 141 142 143 144 145 146 147
echo "<br>
      <h3>
      Image '$imageid' in project $pid has been deleted!\n";

if ($path) {
    echo "<br>
          <br>
          <font color=red>Please remember to delete $path!</font>\n";
}
echo "</h3>\n";
148 149

echo "<br>
150 151 152 153
      <center>
      <a href='showimageid_list.php3'>Back to Image Descriptor list</a>
      </center>
      <br><br>\n";
154 155 156 157 158 159

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