Commit 8db4850e authored by Leigh B Stoller's avatar Leigh B Stoller

Another ProtoGeni checkbox; record vlan tags in a history table

and provide a web interface to look at them.
parent 7ee63200
......@@ -2753,7 +2753,8 @@ sub ReserveVlanTag($$;$$)
$force = 0 if (!defined($force));
DBQueryWarn("lock tables lan_attributes write, lans write, ".
" reserved_vlantags write, vlans read")
" reserved_vlantags write, vlans read, ".
" vlantag_history write")
or return undef;
#
......@@ -2787,6 +2788,12 @@ sub ReserveVlanTag($$;$$)
" lanid='$lanid', tag='$tag', vname='$vname', ".
" pid='$pid', eid='$eid', exptidx='$exptidx', ".
" reserve_time=now()"));
#
# Insert a history record.
#
DBQueryWarn("insert into vlantag_history set history_id=NULL, ".
" lanid='$lanid', tag='$tag', lanname='$vname', ".
" exptidx='$exptidx', allocated=UNIX_TIMESTAMP(now())");
isfree:
DBQueryWarn("unlock tables");
return $tag;
......@@ -2805,6 +2812,16 @@ sub ClearReservedVlanTag($;$)
my $lanid = (ref($arg) ? $arg->lanid() : $arg);
my $clause = (defined($tag) ? "and tag='$tag'" : "");
#
# Update history record(s), but if not told the tag, have to
# modify records for all of them. The only time there would be
# more then one tag in the table, is when doing a block allocate
# for Protogeni stitching.
#
DBQueryWarn("update vlantag_history set released=UNIX_TIMESTAMP(now()) ".
"where lanid='$lanid' $clause")
or return -1;
DBQueryWarn("delete from reserved_vlantags where lanid='$lanid' $clause")
or return -1;
......
......@@ -2348,7 +2348,7 @@ sub CreateVnodes($$$)
"port" => 1,
"iface" => "eth0",
"role" => TBDB_IFACEROLE_CONTROL(),
"MAC" => GenFakeMac(),
"MAC" => "genfake",
"IP" => $jailip,
"mask" => $jailmask,
"type" => "generic",
......
......@@ -4748,6 +4748,24 @@ CREATE TABLE `vis_nodes` (
UNIQUE KEY `pideid` (`pid`,`eid`,`vname`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Table structure for table `vlantag_history`
--
DROP TABLE IF EXISTS `vlantag_history`;
CREATE TABLE `vlantag_history` (
`history_id` int(10) unsigned NOT NULL auto_increment,
`tag` smallint(5) NOT NULL default '0',
`lanid` int(11) NOT NULL default '0',
`lanname` varchar(64) NOT NULL default '',
`exptidx` int(10) unsigned default NULL,
`allocated` int(10) unsigned default NULL,
`released` int(10) unsigned default NULL,
PRIMARY KEY (`history_id`),
KEY `tag` (`tag`,`history_id`),
KEY `exptidx` (`exptidx`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Table structure for table `vlans`
--
......
#
# Add vlantag history table.
#
use strict;
use libdb;
sub DoUpdate($$$)
{
my ($dbhandle, $dbname, $version) = @_;
if (!DBTableExists("vlantag_history")) {
DBQueryFatal("CREATE TABLE `vlantag_history` ( ".
" `history_id` int(10) unsigned NOT NULL auto_increment, ".
" `tag` smallint(5) NOT NULL default '0', ".
" `lanid` int(11) NOT NULL default '0', ".
" `lanname` varchar(64) NOT NULL default '', ".
" `exptidx` int(10) unsigned default NULL, ".
" `allocated` int(10) unsigned default NULL, ".
" `released` int(10) unsigned default NULL, ".
" PRIMARY KEY (`history_id`), ".
" KEY `tag` (`tag`,`history_id`), ".
" KEY `exptidx` (`exptidx`) ".
") ENGINE=MyISAM DEFAULT CHARSET=latin1");
}
return 0;
}
1;
# Local Variables:
# mode:perl
# End:
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2012 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
#
# Only known and logged in users can do this.
#
$this_user = CheckLoginOrDie();
$uid = $this_user->uid();
$isadmin = ISADMIN();
if (! ($isadmin || OPSGUY() || STUDLY())) {
USERERROR("Cannot view node history.", 1);
}
#
# Verify page arguments.
#
$optargs = OptionalPageArguments("datetime", PAGEARG_STRING,
"record", PAGEARG_INTEGER,
"count", PAGEARG_INTEGER,
"when", PAGEARG_STRING,
"tag", PAGEARG_INTEGER);
#
# Standard Testbed Header
#
PAGEHEADER("Vlan Tag History");
if (!isset($count)) {
$count = 200;
}
if (!isset($record) || $record == "") {
$record = null;
}
if (isset($record)) {
# Record overrides date/when.
$dateopt = "";
$datetime = null;
$when = null;
}
elseif (isset($datetime) && $datetime != "") {
if (! strtotime($datetime)) {
USERERROR("Invalid date specified", 1);
}
$dateopt = "&datetime=" . urlencode($datetime);
$record = null;
}
elseif (isset($when) && $when == "current") {
$datetime = null;
$dateopt = "";
$record = null;
}
elseif (isset($when) && $when == "yesterday") {
$datetime = date("Y-m-d H:i:s", time() - (24 * 3600));
$dateopt = "&datetime=" . urlencode($datetime);
$record = null;
}
elseif (isset($when) && $when == "lastweek") {
$datetime = date("Y-m-d H:i:s", time() - (7 * 24 * 3600));
$dateopt = "&datetime=" . urlencode($datetime);
$record = null;
}
elseif (isset($when) && $when == "lastmonth") {
$datetime = date("Y-m-d H:i:s", time() - (30 * 24 * 3600));
$dateopt = "&datetime=" . urlencode($datetime);
$record = null;
}
else {
$dateopt = "";
$datetime = null;
$when = "epoch";
}
if (isset($tag)) {
$tag_opt = "tag=$tag";
$form_opt = "<input type=hidden name=tag value=$tag>";
$IP = null;
$mac = null;
}
else {
$tag_opt = "";
$form_opt = "";
$tag = null;
}
$opts="$tag_opt$dateopt";
echo "<br><b>Show:</b> ";
if ($when == "lastmonth") {
echo "Last Month, ";
}
else {
echo "<a href='showvlantaghistory.php?$opts&when=lastmonth'>".
"Last Month</a>, ";
}
if ($when == "lastweek") {
echo "Last Week, ";
}
else {
echo "<a href='showvlantaghistory.php?$opts&when=lastweek'>".
"Last Week</a>, ";
}
if ($when == "yesterday") {
echo "Yesterday, ";
}
else {
echo "<a href='showvlantaghistory.php?$opts&when=yesterday'>".
"Yesterday</a>, ";
}
if ($when == "current") {
echo "Current, ";
}
else {
echo "<a href='showvlantaghistory.php?$opts&when=current'>".
"Current</a>, ";
}
if ($when == "Epoch") {
echo "Epoch";
}
else {
echo "<a href='showvlantaghistory.php?$opts&when=epoch'>Epoch</a>";
}
#
# Spit out the various search forms.
#
echo "<br>";
echo "<table class=stealth>\n";
echo "<tr><form action=showvlantaghistory.php method=get>
<td class=stealth><b>Show Datetime:</b></td>
<td class=stealth><input type=text style=\"float:right\"
name=datetime
size=20
value=\"" . ($datetime ? $datetime : "mm/dd/yy HH:MM") . "\"></td>
<input type=hidden name=when value=$when>
$tag_opt
</td><td class=stealth>
<b><input type=submit name=search1 value=Search></b></td>\n";
echo "</form></tr>\n";
echo "<tr><form action=showvlantaghistory.php method=get>
<td class=stealth><b>Search for tag:</b></td>
<td class=stealth><input type=text style=\"float:right\"
name=tag
size=6
value=\"$tag\"></td>
<input type=hidden name=when value=$when></td>
<td class=stealth>
<b><input type=submit name=search3 value=Search></b></td>\n";
echo "</form></tr>\n";
echo "</table><br>\n";
#
#
#
if ($when == "current") {
$clauses = array();
$clause = "";
if ($tag) {
$clauses[] = "tag='$tag'";
}
if ($datetime) {
$clauses[] = "reserve_time>" . strtotime($datetime);
}
if (count($clauses)) {
$clause = "where " . join(" and ", $clauses);
}
$query_result =
DBQueryFatal("select v.*, ".
" reserve_time as allocated ".
" from reserved_vlantags as v ".
"left join experiment_stats as s on s.exptidx=v.exptidx ".
"$clause ".
"order by tag desc");
}
else {
$clauses = array();
$clause = "";
if ($tag) {
$clauses[] = "tag='$tag'";
}
if ($datetime) {
$clauses[] = "allocated>" . strtotime($datetime);
}
if ($record) {
$clauses[] = "history_id>$record";
}
if (count($clauses)) {
$clause = "where " . join(" and ", $clauses);
}
$query_result =
DBQueryFatal("select v.*,s.pid,s.eid, ".
" from_unixtime(allocated) as allocated, ".
" from_unixtime(released) as released ".
" from vlantag_history as v ".
"left join experiment_stats as s on s.exptidx=v.exptidx ".
"$clause ".
"order by history_id limit $count");
}
if (mysql_num_rows($query_result)) {
$num_records = mysql_num_rows($query_result);
# Keep track of history record bounds, for paging through.
$max_history_id = 0;
# Build up table contents.
$html = "";
while ($row = mysql_fetch_array($query_result)) {
$thistag = $row{"tag"};
$exptidx = $row{"exptidx"};
$pid = $row{"pid"};
$eid = $row{"eid"};
$alloc = $row{"allocated"};
$free = $row{"released"};
$id = $row{"history_id"};
$slice = "--";
if (!$free)
$free = "&nbsp";
$experiment = Experiment::Lookup($exptidx);
$experiment_stats = ExperimentStats::Lookup($exptidx);
if ($experiment_stats &&
$experiment_stats->slice_uuid()) {
$url = CreateURL("genihistory",
"slice_uuid",
$experiment_stats->slice_uuid());
$slice = "<a href='$url'>" .
"<img src=\"greenball.gif\" border=0></a>";
}
if ($experiment) {
$expurl = CreateURL("showexp",
URLARG_EID, $experiment->idx());
}
else {
$expurl = CreateURL("showexpstats",
"record",
$experiment_stats->exptidx());
}
if ($id > $max_history_id)
$max_history_id = $id;
$html .= "<tr>";
if (!$tag) {
$html .= "<td>$thistag</td>";
}
$html .= "<td>$pid</td>";
if ($expurl) {
$html .= "<td><a href='$expurl'>$eid</a></td>";
}
else {
$html .= "<td>$eid</td>";
}
if ($PROTOGENI) {
$html .= "<td>$slice</td>";
}
$html .= "<td>$alloc</td>
<td>$free</td>
</tr>\n";
}
if ($num_records >= $count && $when != "current") {
echo "<center><a href='showvlantaghistory.php?record=$max_history_id".
"&count=$count&$tag_opt'>Next $count records</a></center>\n";
}
echo "<table border=1 cellpadding=2 cellspacing=2 align='center'>\n";
echo "<tr>";
if (! $tag) {
echo "<th>Tag</th>";
}
echo "<th>Pid</th>
<th>Eid</th>";
if ($PROTOGENI) {
echo "<th>Slice</th>";
}
echo "<th>Allocated</th>
<th>Released</th>
</tr>\n";
echo $html;
echo "</table>\n";
}
#
# Standard Testbed Footer
#
PAGEFOOTER();
?>
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