Commit 99a2b1f0 authored by Leigh Stoller's avatar Leigh Stoller

Make it easier to find a slice by looking for a sliver, creator,

control IP, or control MAC. Add search box on the genislices page.
parent 0e686368
......@@ -44,7 +44,8 @@ PSBIN_STUFF = register_resources expire_daemon gencrl postcrl \
getchcredential genallow_extcred advt-merge.py \
reservevlans delgeniuser delegatecredential \
updatecert fixcerts initcerts cacontrol webcacontrol \
genextend_lifetime rspeclint chstats
genextend_lifetime rspeclint chstats \
maptoslice webmaptoslice
ifeq ($(ISCLEARINGHOUSE),1)
PSBIN_STUFF += ch_daemon
......@@ -65,7 +66,8 @@ include $(TESTBED_SRCDIR)/GNUmakerules
install: $(addprefix $(INSTALL_SBINDIR)/, $(SBIN_STUFF)) \
$(addprefix $(INSTALL_SBINDIR)/protogeni/, $(PSBIN_STUFF)) \
$(INSTALL_LIBEXECDIR)/webcacontrol
$(INSTALL_LIBEXECDIR)/webcacontrol \
$(INSTALL_LIBEXECDIR)/webmaptoslice
control-install:
......
#!/usr/bin/perl -w
#
# Copyright (c) 2008-2013 University of Utah and the Flux Group.
#
# {{{GENIPUBLIC-LICENSE
#
# GENI Public License
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and/or hardware specification (the "Work") to
# deal in the Work without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Work, and to permit persons to whom the Work
# is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Work.
#
# THE WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS
# IN THE WORK.
#
# }}}
#
use strict;
use English;
use Getopt::Std;
#
# Map a urn to a slice.
#
sub usage()
{
print "Usage: maptoslice <urn> | <ip> | <mac>\n";
exit(1);
}
sub fatal($);
my $optlist = "w";
my $fromweb = 0;
#
# Configure variables
#
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $TBLOGS = "@TBLOGSEMAIL@";
# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin:/usr/site/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Turn off line buffering on output
#
$| = 1;
# Load the Testbed support stuff.
use lib "@prefix@/lib";
use Interface;
use Node;
use GeniDB;
use GeniSlice;
use GeniUtil;
use GeniCM;
use GeniHRN;
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{"w"})) {
$fromweb = 1;
}
usage()
if (@ARGV != 1);
my $token = $ARGV[0];
my ($type, $id);
# Connect to the proper DB.
DBSetDefault(DBConnect(GENICM_DBNAME()));
if ($token =~ /^[\w]+$/) {
$type = "mac";
$id = $token;
}
elsif ($token =~ /^[\d\.]+$/) {
$type = "ip";
$id = $token;
}
elsif (GeniHRN::IsValid($token)) {
(undef, $type, $id) = GeniHRN::Parse($token);
}
my $query_result;
if ($type eq "user") {
$query_result =
GeniDB::DBQueryFatal("select uuid from geni_slices ".
"where creator_token='$token'");
}
elsif ($type eq "sliver") {
$query_result =
GeniDB::DBQueryFatal("(select slice_uuid from geni_slivers ".
" where idx='$id') ".
"UNION ".
"(select slice_uuid from geni_aggregates ".
" where idx='$id')");
}
elsif ($type eq "node") {
$query_result =
GeniDB::DBQueryFatal("select slice_uuid from geni_slivers ".
"where resource_id='$id'");
}
elsif ($type eq "slice") {
my $slice = GeniSlice->Lookup($token);
if (defined($slice)) {
if ($fromweb) {
print $slice->uuid() . "\n";
}
else {
print $slice->urn() . "\n";
}
exit(0);
}
}
elsif ($type eq "ip" || $type eq "mac") {
my $interface = ($type eq "ip" ?
Interface->LookupByIP($id) : Interface->LookupByMAC($id));
if (!defined($interface)) {
fatal("No such interface for $id");
}
my $node = Node->Lookup($interface->node_id());
if (!defined($node)) {
fatal("No such node for $interface");
}
my $nodeid = $node->node_id();
$query_result =
GeniDB::DBQueryFatal("select slice_uuid from geni_slivers ".
"where resource_id='$nodeid'");
}
else {
fatal("Do not know how to map token to a slice!");
}
if (!defined($query_result) || !$query_result->numrows) {
print STDERR "No slices matching the criteria.\n";
# For the web interface.
exit(1);
}
while (my ($token) = $query_result->fetchrow_array()) {
my $slice = GeniSlice->Lookup($token);
if (!defined($slice)) {
print STDERR "Cannot map $token to slice.\n";
next;
}
if ($fromweb) {
print $slice->uuid() . "\n";
}
else {
print $slice->urn() . "\n";
}
}
exit(0);
sub fatal($) {
my ($msg) = @_;
print STDERR "$msg\n";
exit(-1);
}
#!/usr/bin/perl -w
#
# Copyright (c) 2000-2013 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
use English;
#
# This gets invoked from the Web interface. Simply a wrapper ...
# Automatically generated from the template in the toplevel dir.
#
#
# Configure variables
#
my $PROG = "@prefix@/sbin/protogeni/maptoslice";
#
# Run the real thing, and never return.
#
exec $PROG, @ARGV;
die("Could not exec $PROG: $!");
<?php
#
# Copyright (c) 2000-2012 University of Utah and the Flux Group.
# Copyright (c) 2000-2013 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -32,14 +32,19 @@ include("table_defs.php");
$this_user = CheckLoginOrDie();
$uid = $this_user->uid();
$isadmin = ISADMIN();
$defaultsearchstring = 'Search CM for URN or IP or MAC';
#
# Verify Page Arguments.
#
$optargs = OptionalPageArguments("showtype", PAGEARG_STRING);
$optargs = OptionalPageArguments("showtype", PAGEARG_STRING,
"query", PAGEARG_STRING);
$showtypes = array();
if (!isset($showtype)) {
if (isset($query) && $query != $defaultsearchstring) {
$showtypes[] = "cm";
}
elseif (!isset($showtype)) {
$showtypes[] = "cm";
$showtypes[] = "sa";
$showtypes[] = "ch";
......@@ -60,8 +65,58 @@ if (! ($isadmin || STUDLY())) {
USERERROR("You do not have permission to view Geni slice list!", 1);
}
#
# Search box for CM only.
#
if (isset($query) && $query != $defaultsearchstring) {
$searchstring = $query;
}
else {
$searchstring = $defaultsearchstring;
}
echo "<center>";
echo "<table class=stealth>\n";
echo "<tr>";
echo "<td class=stealth>";
echo "<form method='get' action='genislices.php'>";
echo "<input name='query' class='textInputEmpty'
size=64 id='searchbox'
value='$searchstring'
onfocus='focus_text(this, \"$defaultsearchstring\")'
onblur='blur_text(this, \"$defaultsearchstring\")' />";
echo "</td><td><input type='submit' id='searchsub' value=Go />";
echo "</form>";
echo "</td></tr></table>";
echo "</center>\n";
foreach ($showtypes as $type) {
$slicelist = GeniSlice::AllSlices($type);
if ($type == "cm" && isset($query) && $query != $defaultsearchstring) {
$slicelist = array();
$uuidlist = array();
$safe_query = escapeshellarg($query);
$fp = popen("$TBSUEXEC_PATH $uid nobody ".
"webmaptoslice -w $safe_query", "r");
if (!$fp) {
TBERROR("Could not start maptoslice: $safe_query", 1);
}
while ($line = fgets($fp)) {
$uuidlist[] = rtrim($line);
}
$status = pclose($fp);
if ($status > 0 || !count($uuidlist)) {
USERERROR("No slices matching your search term", 1);
}
elseif ($status < 0) {
TBERROR("Could not run maptoslice: $safe_query", 1);
}
foreach ($uuidlist as $uuid) {
$slicelist[] = GeniSlice::Lookup($type, $uuid);
}
}
else {
$slicelist = GeniSlice::AllSlices($type);
}
$which = ($type == "cm" ? "Component Manager" :
($type == "sa" ? "Slice Authority" : "Clearing House"));
......
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