Commit 85ea76eb authored by Leigh Stoller's avatar Leigh Stoller

Add two calls to CM interface; SliverStatus() and SliceStatus() which

allow you to find out the status of your sliver. As you can guess, one
takes a sliver credential and the other takes the slice credential.
See the test scripts test/slicestatus.py and test/slicestatus.py. Both
calls return the same thing. In pythonese:

{'status': 'notready',
 'details': {'de9803c2-773e-102b-8eb4-001143e453fe': 'notready'}
}

The 'status' is a summary of the entire aggregate; if all nodes are
ISUP then the status is 'ready'

The details is an array of the status of each sliver, indexed by the
sliver uuid.

Probably need to define a better set of status indicators, but this is
the one that was bothering me the most.
parent 1cff2741
......@@ -181,6 +181,9 @@ sub status($) { return field($_[0], "status"); }
sub cert($) { return $_[0]->{'CERTIFICATE'}->cert(); }
sub GetCertificate($) { return $_[0]->{'CERTIFICATE'}; }
# An alias so that slivers look like aggregates.
sub resource_type($) { return field($_[0], "type"); }
#
# Destroy all the slivers in the aggregate, and then the aggregate if there
# is nothing in it. Leave it around if something goes wrong.
......
......@@ -1934,6 +1934,182 @@ sub ListUsage($)
return GeniResponse->Create(GENIRESPONSE_SUCCESS, \@result);
}
#
# Slice Status
#
sub SliceStatus($)
{
my ($argref) = @_;
my $cred = $argref->{'credential'};
my $mode = $argref->{'mode'};
$mode = "summary"
if (!defined($mode));
if (! (defined($cred))) {
return GeniResponse->MalformedArgsResponse();
}
my $credential = GeniCredential->CreateFromSigned($cred);
if (!defined($credential)) {
return GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"Could not create GeniCredential object");
}
my $slice_uuid = $credential->target_uuid();
my $user_uuid = $credential->owner_uuid();
#
# Make sure the credential was issued to the caller.
#
if ($credential->owner_uuid() ne $ENV{'GENIUUID'}) {
return GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"This is not your credential!");
}
my $slice = GeniSlice->Lookup($slice_uuid);
if (!defined($slice)) {
return GeniResponse->Create(GENIRESPONSE_SEARCHFAILED, undef,
"No such slice here");
}
if ($slice->Lock() != 0) {
return GeniResponse->BusyResponse();
}
my $aggregate = GeniAggregate->SliceAggregate($slice);
if (!defined($aggregate)) {
$slice->UnLock();
return GeniResponse->Create(GENIRESPONSE_SEARCHFAILED, undef,
"No slivers here for slice");
}
#
# Grab all the slivers for this slice, and then
# look for just the nodes.
#
my $summary = "ready";
my %details = ();
my @slivers = ();
if (GeniSliver->SliceSlivers($slice, \@slivers) != 0) {
print STDERR "Could not get slivers for $slice\n";
$slice->UnLock();
return GeniResponse->Create(GENIRESPONSE_ERROR);
}
foreach my $sliver (@slivers) {
next
if ($sliver->resource_type() ne "Node");
my $node_uuid = $sliver->resource_uuid();
my $node = Node->Lookup($node_uuid);
if (!defined($node)) {
$slice->UnLock();
print STDERR "Cannot find node by uuid $node_uuid\n";
return GeniResponse->Create(GENIRESPONSE_ERROR);
}
if ($node->IsUp()) {
$details{$node_uuid} = "ready";
}
else {
$details{$node_uuid} = "notready";
$summary = "notready";
}
}
$slice->UnLock();
my $blob = {"status" => $summary,
"details" => \%details};
return GeniResponse->Create(GENIRESPONSE_SUCCESS, $blob);
}
#
# Sliver status.
#
sub SliverStatus($)
{
my ($argref) = @_;
my $cred = $argref->{'credential'};
if (!defined($cred)) {
return GeniResponse->Create(GENIRESPONSE_BADARGS);
}
my $credential = GeniCredential->CreateFromSigned($cred);
if (!defined($credential)) {
return GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"Could not create GeniCredential object");
}
my $sliver_uuid = $credential->target_uuid();
my $user_uuid = $credential->owner_uuid();
#
# Make sure the credential was issued to the caller.
#
if ($credential->owner_uuid() ne $ENV{'GENIUUID'}) {
return GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"This is not your credential!");
}
#
# For now, only allow top level aggregate to be deleted.
#
my $aggregate = GeniAggregate->Lookup($sliver_uuid);
if (!defined($aggregate)) {
my $sliver = GeniSliver->Lookup($sliver_uuid);
if (defined($sliver)) {
return GeniResponse->Create(GENIRESPONSE_BADARGS, undef,
"Must supply toplevel sliver");
}
else {
return GeniResponse->Create(GENIRESPONSE_BADARGS, undef,
"No such sliver");
}
}
elsif ($aggregate->type() ne "Aggregate") {
return GeniResponse->Create(GENIRESPONSE_BADARGS, undef,
"Must supply toplevel sliver");
}
my $slice_uuid = $aggregate->slice_uuid();
my $slice = GeniSlice->Lookup($slice_uuid);
if (!defined($slice)) {
return GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"No slice record for slice");
}
if ($slice->Lock() != 0) {
return GeniResponse->BusyResponse();
}
#
# Grab all the slivers for this slice, and then
# look for just the nodes.
#
my $summary = "ready";
my %details = ();
my @slivers = ();
if ($aggregate->SliverList(\@slivers) != 0) {
print STDERR "Could not get slivers for $aggregate\n";
$slice->UnLock();
return GeniResponse->Create(GENIRESPONSE_ERROR);
}
foreach my $sliver (@slivers) {
next
if ($sliver->isa("GeniAggregate"));
next
if ($sliver->resource_type() ne "Node");
my $node_uuid = $sliver->resource_uuid();
my $node = Node->Lookup($node_uuid);
if (!defined($node)) {
$slice->UnLock();
print STDERR "Cannot find node by uuid $node_uuid\n";
return GeniResponse->Create(GENIRESPONSE_ERROR);
}
if ($node->IsUp()) {
$details{$node_uuid} = "ready";
}
else {
$details{$node_uuid} = "notready";
$summary = "notready";
}
}
$slice->UnLock();
my $blob = {"status" => $summary,
"details" => \%details};
return GeniResponse->Create(GENIRESPONSE_SUCCESS, $blob);
}
#
# Utility Routines.
#
......
#! /usr/bin/env python
#
# EMULAB-COPYRIGHT
# Copyright (c) 2008-2009 University of Utah and the Flux Group.
# All rights reserved.
#
# Permission to use, copy, modify and distribute this software is hereby
# granted provided that (1) source code retains these copyright, permission,
# and disclaimer notices, and (2) redistributions including binaries
# reproduce the notices in supporting documentation.
#
# THE UNIVERSITY OF UTAH ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
# CONDITION. THE UNIVERSITY OF UTAH DISCLAIMS ANY LIABILITY OF ANY KIND
# FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
#
#
#
import sys
import pwd
import getopt
import os
import re
import xmlrpclib
from M2Crypto import X509
execfile( "test-common.py" )
#
# Get a credential for myself, that allows me to do things at the SA.
#
mycredential = get_self_credential()
print "Got my SA credential. Looking for slice ..."
#
# Lookup slice, delete before proceeding.
#
myslice = resolve_slice( SLICENAME, mycredential )
myuuid = myslice["uuid"]
print "Found the slice, asking for a credential ..."
#
# Get the slice credential.
#
slicecred = get_slice_credential( myslice, mycredential )
print "Got the slice credential, asking for slice status ..."
#
# Get the slice status
#
params = {}
params["credential"] = slicecred
rval,response = do_method("cm", "SliceStatus", params)
if rval:
Fatal("Could not get slice status")
pass
print str(response["value"])
#! /usr/bin/env python
#
# EMULAB-COPYRIGHT
# Copyright (c) 2008-2009 University of Utah and the Flux Group.
# All rights reserved.
#
# Permission to use, copy, modify and distribute this software is hereby
# granted provided that (1) source code retains these copyright, permission,
# and disclaimer notices, and (2) redistributions including binaries
# reproduce the notices in supporting documentation.
#
# THE UNIVERSITY OF UTAH ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
# CONDITION. THE UNIVERSITY OF UTAH DISCLAIMS ANY LIABILITY OF ANY KIND
# FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
#
#
#
import sys
import pwd
import getopt
import os
import re
import xmlrpclib
from M2Crypto import X509
execfile( "test-common.py" )
#
# Get a credential for myself, that allows me to do things at the SA.
#
mycredential = get_self_credential()
print "Got my SA credential. Looking for slice ..."
#
# Lookup slice, delete before proceeding.
#
myslice = resolve_slice( SLICENAME, mycredential )
myuuid = myslice["uuid"]
print "Found the slice, asking for a credential ..."
#
# Get the slice credential.
#
slicecred = get_slice_credential( myslice, mycredential )
print "Got the slice credential, asking for a sliver credential ..."
#
# Get the sliver credential.
#
params = {}
params["credential"] = slicecred
rval,response = do_method("cm", "GetSliver", params)
if rval:
Fatal("Could not get Sliver credential")
pass
slivercred = response["value"]
print "Got the sliver credential, asking for sliver status";
#
# Get the sliver status
#
params = {}
params["credential"] = slivercred
rval,response = do_method("cm", "SliverStatus", params)
if rval:
Fatal("Could not get sliver status")
pass
print str(response["value"])
......@@ -136,6 +136,8 @@ my $responder = Frontier::Responder->new( "methods" => {
"BindToSlice" => \&GeniCM::BindToSlice,
"Shutdown" => \&GeniCM::Shutdown,
"ListUsage" => \&GeniCM::ListUsage,
"SliceStatus" => \&GeniCM::SliceStatus,
"SliverStatus" => \&GeniCM::SliverStatus,
},
);
......
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