VI-DB vapps.php v2
Jump to navigation
Jump to search
<html xmlns='http://www.w3.org/TR/REC-html40'>
<!--Version 1.0 -->
<html>
<head>
<title>vi-db (vApps)</title>
<link rel='SHORTCUT ICON' href='favicon.ico'>
<link rel='stylesheet' type='text/css' href='alpha.css' />
<meta name='Author' content='Simon Strutt'>
<meta name='Description' content='VI Info'>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >
<meta http-equiv="Content-Type" content="image/jpeg" >
<meta http-equiv='Pragma' content='no-cache'>
<meta http-equiv='Expires' content='900'>
</head>
<body>
<?php
$time_start = microtime(true);
//Local variables etc
require 'config.php';
$self = $_SERVER['PHP_SELF'];
$debug = 0;
// open connection and select database
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect to database!");
mysql_select_db($db) or die ("Unable to select database!");
//Set debug on if required
if (array_key_exists('debug', $_REQUEST) and ($_REQUEST["debug"] == 1)) {
$debug = 1;
}
// show parameters and errors
if ($debug) {
error_reporting(-1);
print_r($_REQUEST);
print "<br>";
}
print "DISCLAIMER: Please use all information gained from here with caution - I haven't performed exhaustive validation and testing of any of the information that may be presented.<br>\n";
print "If you're making changes or decisions, please double check with the reality of what is displayed by the vCentre servers. You retain full responsibility for your actions...!\n ";
print "<h1>vApps</h1>\n";
if (array_key_exists('vappid', $_REQUEST)) {
$vapp_link = "&vappid=".$_REQUEST["vappid"];
$vappid=$_REQUEST["vappid"];
} else {
$vapp_link = "";
$vappid=0;
}
// Initial query
$query = "SELECT vc.name AS vc, cluster.name AS cluster, vappid, vapp.name AS vapp, vc_path, status FROM vapp JOIN vc USING (vcid) JOIN cluster USING (clid) WHERE vapp.exist=1 ORDER BY vc, cluster, vapp;";
$result = mysql_query($query);
//print $query;
if (mysql_num_rows($result) == 0) {
die ("No vApps found....");
}
$row = mysql_fetch_assoc($result);
// ----------------- Layout table (top) ----------------------------
print "<table align='center' cellspacing=10><tr><td valign='top'>\n";
// ------------------- Summary table ------------------------
print "<table class='BasicTable' align='center'>\n<tr><th>vCentre<th>Cluster<th>vApp<th>Status<th>vCenter<br>Path\n";
while ($row = mysql_fetch_assoc($result)) {
print "<tr><td>".$row['vc']."<td>".$row['cluster'];
if ($vappid == $row['vappid']) {
print "<td><b>".$row['vapp']."</b>";
} else {
print "<td><a href='$self?vappid=".$row['vappid']."'>".$row['vapp']."</a>";
}
if ($row['status'] == "Started") {
print "<td class='good'>Started";
} else {
print "<td class='warn'>".$row['status'];
}
print "<td>".$row['vc_path'];
}
print "</table>\n";
// ------------------ Layout table cell (bottom)--------------------------
print "\n<tr><td valign='top'>\n";
// ----------------- Detail table ---------------------------------------
if ($vappid) {
$query = "SELECT name, prod_name, prod_ver, prod_fver, prod_vend FROM vapp WHERE vappid=$vappid;";
$result = mysql_query($query);
if (mysql_num_rows($result) == 0) {
die ("Unexpected error...!");
}
$row = mysql_fetch_assoc($result);
print "<h1>".$row['name']."</h1>\n";
print "<table class='BasicTable' align='center'><tr><th colspan=2>Product";
print "<tr><th>Name<td width=150>".$row['prod_name'];
print "<tr><th>Version<td>".$row['prod_ver'];
print "<tr><th>Full Version<td>".$row['prod_fver'];
print "<tr><th>Vendor<td>".$row['prod_vend']."</table><br>\n";
$query = "SELECT vmid, name, is_on, ord, start_dly, start_wait, stop_dly, stop_act FROM vapp_vm JOIN vm USING (vmid) WHERE vapp_vm.vappid=$vappid ORDER BY ord, name;";
$result = mysql_query($query);
if (mysql_num_rows($result) == 0) {
die ("No VM's found in vApp...!");
}
print "<table class='BasicTable' align='center'><tr><th rowspan=2>Start<br>Order<th rowspan=2>VM<th rowspan=2>Power<th colspan=2>Start<th colspan=2>Stop\n";
print "<tr><th>Delay<br><small>sec</small><th>Proceed<br>After<th>Delay<br><small>sec</small><th>Method\n";
$odd_row = false;
$last_ord = false;
while ($row = mysql_fetch_assoc($result)) {
if ($last_ord <> $row['ord']) {
$odd_row = !$odd_row;
$last_ord = $row['ord'];
}
if ($odd_row) {
print "<tr class='odd'>";
} else {
print "<tr>";
}
print "<td class='num'>".$row['ord']."<td><a href='vm-detail.php?vmid=".$row['vmid']."'>".$row['name']."</a>";
if ($row['is_on']) {
print "<td class='good'>ON";
} else {
print "<td class='warn'>off";
}
print "<td class='num'>".$row['start_dly'];
if ($row['start_wait']) {
print "<td>Tools started";
} else {
print "<td>Delay expired";
}
print "<td class='num'>".$row['stop_dly'];
if ($row['stop_act'] == "guestShutdown") {
print "<td>Shutdown Guest";
} elseif ($row['stop_act'] == "powerOff") {
print "<td>Power Off VM";
} else {
print "<td>".$row['stop_act'];
}
}
print "</table>";
} else {
print "Select a vApp...\n";
}
// ------------------- Layout table end ------------------------------
print "</table>\n";
print "<br><a href='index.php'>Search page</a>   <a href='status.php'>Status page</a><br>\n";
$time = round((microtime(true) - $time_start)*1000);
print "Page took $time msecs to execute on server";
// ------------------- End of HTML ---------------------------------
print "</body><html>";
// ================ FUNCTIONS ============================
function search_char ($text) {
return (str_replace(array("*", "?"), array("%", "_"), trim($text)));
}
?>