Commit fa811184 authored by Mike Hibler's avatar Mike Hibler
Browse files

Merge remote branch 'origin/master'

parents e72149e5 a368fb2c
......@@ -2,7 +2,7 @@
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2008 University of Utah and the Flux Group.
# Copyright (c) 2000-2008,2011 University of Utah and the Flux Group.
# All rights reserved.
#
......@@ -21,7 +21,7 @@ my $d = 0; #debug mode
if ($#ARGV >= 0 && $ARGV[0] =~ /^-?h/i ) {
die("Usage:\navail [help] [type[=<type>]] [OS[=<OS>]] [ver[=<OS_ver>]]\n".
" [[includevirt] or [virtonly[=<phys>]]] [rand]\n".
" [limit=N] [aslist]\n".
" [limit=N] [aslist] [notprereserved]\n".
"\n".
"type \t= pc | shark\n"."OS \t= Linux | FreeBSD | NetBSD | ...\n".
"ver \t= 6.2 | 3.4 | 4.0 | 5.2 | ...\n".#"deltas \t= anetd | ...\n".
......@@ -114,6 +114,10 @@ if (defined($args{"prereserve"})) {
$cond .= " and a.reserved_pid='$pid' ";
}
if (defined($args{"notprereserved"})) {
$cond .= " and a.reserved_pid is null";
}
my $cmd = "select $cols from $join where $cond order by $order $limit";
print "Sending cmd:\n$cmd\n" if $d;
......
......@@ -38,7 +38,7 @@ sub usage() {
}
my $optlist = "t:p:e:srafFhR";
my @columns = ("n.node_id","pid","eid","rsrv_time","reserved_pid");
my @columns = ("n.node_id","n.type","pid","eid","reserved_pid");
my %opt = ();
if (! getopts($optlist, \%opt)) {
......@@ -101,6 +101,7 @@ my $sortclause = "order by priority";
if ($opt{s}) {
$sortclause = "order by pid,eid,priority";
} elsif ($opt{r}) {
push @columns, "rsrv_time";
$sortclause = "order by rsrv_time,priority";
}
......
#!/usr/bin/perl -wT
#
# GENIPUBLIC-COPYRIGHT
# Copyright (c) 2008-2010 University of Utah and the Flux Group.
# Copyright (c) 2008-2011 University of Utah and the Flux Group.
# All rights reserved.
#
package GeniAM;
......@@ -224,6 +224,11 @@ sub CreateSliver()
};
my $response = GeniCMV2::CreateSliver($create_args);
if (!ref($response)) {
# This is cause GeniCMV2::CreateSliver does a fork, and the child
# returns plain status code, which should go to our caller.
return $response;
}
if (GeniResponse::IsError($response)) {
# The create failed, so return the response.
return $response
......
......@@ -547,6 +547,60 @@ sub Resolve($$)
return $response->value();
}
#
# Discover resources at an authority (CM).
#
sub DiscoverResources($$)
{
my ($self, $urn) = @_;
my $manager_version = $self->Version();
return undef
if (!defined($manager_version));
#
# Need a credential to make this call.
#
if (!defined(Genixmlrpc->GetContext())) {
print STDERR "Need an RPC context to generate a self credential\n";
return undef;
}
my $context = Genixmlrpc->GetContext();
my $me = GeniAuthority->Lookup($context->certificate()->uuid());
if (!defined($me)) {
print STDERR "Could not find my own authority for $context\n";
return undef;
}
my $credential = GeniCredential->GetSelfCredential($me);
if (!defined($credential)) {
print STDERR "Could not create self credential for $me\n";
return undef;
}
my $method_args;
if ($manager_version == 2.0) {
$method_args->{'credentials'} = [$credential->asString()];
$method_args->{'available'} = 1;
}
else {
print STDERR "GeniAuthority::Discover: Unknown version at $self\n";
return undef;
}
my $response =
Genixmlrpc::CallMethod($self->url(), undef,
"DiscoverResources", $method_args);
if (!defined($response)) {
print STDERR "*** Internal error discovering resources at $self\n";
return undef;
}
if ($response->code() != GENIRESPONSE_SUCCESS) {
print STDERR "Could not discover resources at $self Error:";
print STDERR " " . $response->output() . "\n";
return undef;
}
return $response->value();
}
# _Always_ make sure that this 1 is at the end of the file...
1;
......@@ -432,7 +432,6 @@ sub CreateSliver($)
# At this point we want to return and let the startsliver proceed
# in the background
#
if (0) {
my $mypid = fork();
if ($mypid) {
# Let the child get going.
......@@ -442,7 +441,6 @@ sub CreateSliver($)
}
# This switches the file that we are writing to.
libaudit::AuditFork();
}
# Make sure that the next phase sees all changes.
Experiment->FlushAll();
......
#!/usr/bin/perl -w
#
# GENIPUBLIC-COPYRIGHT
# Copyright (c) 2008-2010 University of Utah and the Flux Group.
# Copyright (c) 2008-2011 University of Utah and the Flux Group.
# All rights reserved.
#
use strict;
......@@ -17,7 +17,8 @@ sub usage()
print "Usage: ch_daemon [-d] [-n]\n";
exit(1);
}
my $optlist = "dn";
my $optlist = "dns";
my $oneshot = 0;
my $debug = 0;
my $impotent = 0;
......@@ -30,6 +31,7 @@ my $TBLOGS = "@TBLOGSEMAIL@";
my $PGENIDOMAIN = "@PROTOGENI_DOMAIN@";
my $PGENISUPPORT = @PROTOGENI_SUPPORT@;
my $PGENICLRHOUSE = @PROTOGENI_CLEARINGHOUSE@;
my $ADDIR = "$TB/www/protogeni/advertisements";
my $LOGFILE = "$TB/log/ch_daemon.log";
my $EMULAB_PEMFILE = "$TB/etc/genich.pem";
my $SLEEP_INTERVAL = 60;
......@@ -77,6 +79,9 @@ if (defined($options{"d"})) {
if (defined($options{"n"})) {
$impotent = 1;
}
if (defined($options{"s"})) {
$oneshot = 1;
}
# Do this early so that we talk to the right DB.
use vars qw($GENI_DBNAME);
......@@ -106,17 +111,19 @@ Genixmlrpc->SetTimeout(10);
$ENV{'MYUUID'} = $certificate->uuid();
$ENV{'MYURN'} = "urn:publicid:IDN+@OURDOMAIN@+authority+ch";
if (CheckDaemonRunning("ch_daemon")) {
fatal("Not starting another ch daemon!");
}
# Go to ground.
if (! $debug) {
if (TBBackGround($LOGFILE)) {
exit(0);
if (!$oneshot) {
if (CheckDaemonRunning("ch_daemon")) {
fatal("Not starting another ch daemon!");
}
# Go to ground.
if (! $debug) {
if (TBBackGround($LOGFILE)) {
exit(0);
}
}
if (MarkDaemonRunning("ch_daemon")) {
fatal("Could not mark daemon as running!");
}
}
if (MarkDaemonRunning("ch_daemon")) {
fatal("Could not mark daemon as running!");
}
#
# Setup a signal handler for newsyslog.
......@@ -130,7 +137,7 @@ sub handler()
$EUID = $SAVEEUID;
}
$SIG{HUP} = \&handler
if (!$debug);
if (! ($debug || $oneshot));
GeniUtil::FlipToGeniUser();
......@@ -146,6 +153,7 @@ sub ProbeCMs()
my $up = "Up:\n";
my $down = "Down:\n";
my $disabled = "Disabled:\n";
my %ads = ();
if (GeniAuthority->ListAll(\@authorities)) {
fatal("Could not get authorities list from the DB");
......@@ -166,12 +174,43 @@ sub ProbeCMs()
if (!defined($version)) {
print "Error getting version from $urn\n";
$down .= "$urn\n";
next;
}
print " Running version $version\n";
$up .= "$urn, version $version\n";
#
# Discover resources and cache; for the map client.
# Returns a string of xml.
#
my $resources = $authority->DiscoverResources();
# Errors will go to the log.
next
if (!defined($resources));
if (open(OUT, "> $ADDIR/$urn")) {
print OUT $resources;
print OUT "\n";
close(OUT);
# Save the name so we can write the text file at the end.
$ads{$urn} = $urn;
}
else {
print " Running version $version\n";
$up .= "$urn, version $version\n";
notify("Could not open $ADDIR/$urn for output\n");
next;
}
}
if (open(MAP, "> $ADDIR/list.txt")) {
foreach my $urn (keys(%ads)) {
print MAP "$urn\n";
}
close(MAP);
}
else {
notify("Could not open $ADDIR/list.txt for output\n");
next;
}
SENDMAIL("geni-dev-utah\@flux.utah.edu",
"ClearingHouse Daemon Message",
"This is an automated message from the ClearingHouse Daemon\n\n".
......@@ -202,6 +241,12 @@ sub ExpireSlices()
# (see below).
}
if ($oneshot) {
ProbeCMs();
ExpireSlices();
exit(0);
}
while (1) {
if (NoLogins()) {
sleep(5);
......@@ -237,7 +282,9 @@ sub fatal($)
$msg,
$TBOPS);
MarkDaemonStopped("ch_daemon");
MarkDaemonStopped("ch_daemon")
if (!$oneshot);
die("*** $0:\n".
" $msg\n");
}
......
......@@ -163,6 +163,18 @@ if (!defined($vlan)) {
fatal("Could not create vlan for $linkname");
}
my $lanid = $vlan->lanid();
#
# Setup a signal handler to clean things up.
#
sub handler()
{
fatal("Caught a signal ... cleaning up and exiting");
}
$SIG{HUP} = \&handler;
$SIG{TERM} = \&handler;
$SIG{INT} = \&handler;
my @othertags = ();
while (my @tags = ReserveLocalTags(@othertags)) {
......@@ -194,6 +206,8 @@ sub ReserveRemoteTags($$@)
$method_args->{'taglist'} = \@tags;
@$othertags = ();
print STDERR "Calling $authority with tags: @tags\n";
my $response =
Genixmlrpc::CallMethod($authority->url(),
undef, "ReserveVlanTags", $method_args);
......
#!/usr/bin/perl -w
#
# GENIPUBLIC-COPYRIGHT
# Copyright (c) 2008-2010 University of Utah and the Flux Group.
# Copyright (c) 2008-2011 University of Utah and the Flux Group.
# All rights reserved.
#
......@@ -316,6 +316,8 @@ $message .=
"Method: $method\n";
$message .=
"Version: $GENI_VERSION\n" if (defined($GENI_VERSION));
$message .=
"Start: " . TBTimeStamp() . "\n";
my $starttime = [gettimeofday()];
eval { $result = &{ $GENI_METHODS->{$method} }(@{ $call->{'value'} }) };
......@@ -333,47 +335,63 @@ if ($@) {
}
else {
my $elapsed = tv_interval($starttime);
$message .= "End: " . TBTimeStamp() . "\n";
$message .= "Elapsed: " . sprintf("%f", $elapsed) . "\n";
if (GeniResponse::IsError($result)) {
$message .= "Error: " . $result->{'code'} . "\n";
if (!ref($result)) {
$message .= "Return: $result\n";
}
else {
$message .= "Code: " . $result->{'code'} . "\n";
}
$message .= "Output: " . $result->{'output'} . "\n"
if (defined($result->{'output'}));
if (GeniResponse::IsError($result)) {
$message .= "Error: " . $result->{'code'} . "\n";
}
else {
$message .= "Code: " . $result->{'code'} . "\n";
}
$message .= "Output: " . $result->{'output'} . "\n"
if (defined($result->{'output'}));
$message .= "Result:\n" . Dumper($result->{'value'}) . "\n\n";
$message .= "Result:\n" . Dumper($result->{'value'}) . "\n\n";
}
$message .= "Request:\n" . $request . "\n";
AddAuditInfo("message", $message);
#
# If the response indicates error, and no output is defined in
# the response, then send back the contents of the audit file.
# Not sure this makes any sense at all yet, but the point is to
# get more info back to the user.
#
if (GeniResponse::IsError($result) &&
(!defined($result->{'output'}) || $result->{'output'} eq "") &&
exists($ENV{'TBAUDITLOG'}) && -s $ENV{'TBAUDITLOG'}) {
$result->{'output'} = `cat $ENV{'TBAUDITLOG'}`;
}
# Do this after above so that silly comment is not sent to user.
if (GeniResponse::IsError($result) && $mailerrors &&
$result->{'code'} != GENIRESPONSE_SEARCHFAILED()) {
print STDERR "Mail Errors is on.\n";
}
#
# Added this for geni-am ...
#
if (defined($GENI_RESPONSE_CONVERTER)) {
$response = &$GENI_RESPONSE_CONVERTER($result);
if (! ref($result)) {
#
# This could happen if the child forks.
#
if ($result) {
print STDERR "Child forked but returned an error\n";
}
}
else {
$response = $decoder->encode_response($result);
#
# If the response indicates error, and no output is defined in
# the response, then send back the contents of the audit file.
# Not sure this makes any sense at all yet, but the point is to
# get more info back to the user.
#
if (GeniResponse::IsError($result) &&
(!defined($result->{'output'}) || $result->{'output'} eq "") &&
exists($ENV{'TBAUDITLOG'}) && -s $ENV{'TBAUDITLOG'}) {
$result->{'output'} = `cat $ENV{'TBAUDITLOG'}`;
}
# Do this after above so that silly comment is not sent to user.
if (GeniResponse::IsError($result) && $mailerrors &&
$result->{'code'} != GENIRESPONSE_SEARCHFAILED()) {
print STDERR "Mail Errors is on.\n";
}
#
# Added this for geni-am ...
#
if (defined($GENI_RESPONSE_CONVERTER)) {
$response = &$GENI_RESPONSE_CONVERTER($result);
}
else {
$response = $decoder->encode_response($result);
}
}
}
......@@ -387,7 +405,8 @@ if ($debug) {
#
LogEnd(0);
print "Content-Type: text/xml \n\n" . $response;
print "Content-Type: text/xml \n\n" . $response
if (defined($response));
exit(0);
#
......
......@@ -2,7 +2,7 @@
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2010 University of Utah and the Flux Group.
# Copyright (c) 2000-2011 University of Utah and the Flux Group.
# All rights reserved.
#
......@@ -298,8 +298,36 @@ sub AuditAbort()
#
sub AuditFork()
{
$auditing = 0;
delete @ENV{'TBAUDITLOG', 'TBAUDITON'};
return 0
if (!$auditing || !defined($logfile));
$logfile = TBMakeLogname("$SCRIPTNAME");
$ENV{'TBAUDITLOG'} = $logfile;
# Need to close these so that this side of the fork is disconnected.
if (!$daemon && $PERL_VERSION >= 5.008) {
close($libaudit::SAVE_STDOUT);
close($libaudit::SAVE_STDERR);
}
close(STDOUT);
close(STDERR);
open(STDOUT, ">> $logfile") or
die("opening $logfile for STDOUT: $!");
open(STDERR, ">> $logfile") or
die("opening $logfile for STDERR: $!");
#
# Turn off line buffering on output
#
STDOUT->autoflush(1);
STDERR->autoflush(1);
#
# Create a new session to ensure we are clear of any process group.
#
POSIX::setsid();
return 0;
}
......
Supports Markdown
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