APT_Dataset.pm.in 18.9 KB
Newer Older
1 2
#!/usr/bin/perl -wT
#
3
# Copyright (c) 2007-2018 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
# 
# {{{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/>.
# 
# }}}
#
package APT_Dataset;

use strict;
use English;
28
use Date::Parse;
29 30 31 32 33 34 35 36 37 38 39 40 41 42
use Data::Dumper;
use Carp;
use Exporter;
use vars qw(@ISA @EXPORT $AUTOLOAD);

@ISA    = "Exporter";
@EXPORT = qw ( );

# Must come after package declaration!
use EmulabConstants;
use emdb;
use emutil;
use libtestbed;
use APT_Geni;
43
use APT_Aggregate;
Leigh Stoller's avatar
Leigh Stoller committed
44
use GeniHRN;
45 46 47
use Genixmlrpc;
use GeniResponse;
use GeniCertificate;
Leigh Stoller's avatar
Leigh Stoller committed
48 49
use GeniAuthority;
use GeniCredential;
50
use WebTask;
51 52 53 54 55
use overload ('""' => 'Stringify');

# Configure variables
my $TB		  = "@prefix@";
my $TBOPS         = "@TBOPSEMAIL@";
Leigh Stoller's avatar
Leigh Stoller committed
56
my $OURDOMAIN     = "@OURDOMAIN@";
57
my $MAINSITE      = @TBMAINSITE@;
58

59
# Debugging
60
my $usemydevtree  = ($MAINSITE ? 0 : 0);
61

62 63 64 65 66 67 68 69 70 71 72 73
#
# Lookup by uuid.
#
sub Lookup($$;$)
{
    my ($class, $token) = @_;
    my $query_result;

    if ($token =~ /^\w+\-\w+\-\w+\-\w+\-\w+$/) {
	$query_result =
	    DBQueryWarn("select * from apt_datasets where uuid='$token'");
    }
74 75
    elsif ($token =~ /^([-\w]+)\/([-\w]+)$/ ||
	   $token =~ /^([-\w]+),([-\w]+)$/) {
76 77 78 79 80 81 82 83 84 85 86 87
	$query_result =
	    DBQueryWarn("select * from apt_datasets ".
			"where pid='$1' and dataset_id='$2'");
    }
    else {
	return undef;
    }
    return undef
	if (!$query_result || !$query_result->numrows);

    my $self            = {};
    $self->{'DATASET'}  = $query_result->fetchrow_hashref();
88
    $self->{'HASH'}     = {};
89 90

    bless($self, $class);
91

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
    #
    # Grab the webtask. Backwards compat mode, see if there is one associated
    # with the object, use that. Otherwise create a new one.
    #
    my $webtask;
    
    if (defined($self->webtask_id())) {
	$webtask = WebTask->Lookup($self->webtask_id());
    }
    if (!defined($webtask)) {
	$webtask = WebTask->LookupByObject($self->uuid());
	if (!defined($webtask)) {
	    $webtask = WebTask->Create();
	    return undef
		if (!defined($webtask));
	}
	$self->Update({"webtask_id" => $webtask->task_id()}) == 0
	    or return undef;
    }
    $self->{'WEBTASK'} = $webtask;

113 114 115
    return $self;
}

116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
#
# Lookup by remote URN.
#
sub LookupByRemoteURN($$)
{
    my ($class, $urn) = @_;

    return undef
	if (!GeniHRN::IsValid($urn));

    my $safe_urn = DBQuoteSpecial($urn);
    my $query_result =
	DBQueryWarn("select uuid from apt_datasets ".
		    "where remote_urn=$safe_urn");
    return undef
	if (!$query_result || !$query_result->numrows);

    my ($uuid) = $query_result->fetchrow_array();
    return Lookup($class, $uuid);
}

137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
#
# Lookup by remote UUID
#
sub LookupByRemoteUUID($$)
{
    my ($class, $uuid) = @_;

    return undef
	if ($uuid !~ /^\w+\-\w+\-\w+\-\w+\-\w+$/);
    
    my $query_result =
	DBQueryWarn("select uuid from apt_datasets ".
		    "where remote_uuid='$uuid'");
    return undef
	if (!$query_result || !$query_result->numrows);

    ($uuid) = $query_result->fetchrow_array();
    return Lookup($class, $uuid);
}

157 158 159 160 161 162 163 164 165 166
AUTOLOAD {
    my $self  = $_[0];
    my $type  = ref($self) or croak "$self is not an object";
    my $name  = $AUTOLOAD;
    $name =~ s/.*://;   # strip fully-qualified portion

    # A DB row proxy method call.
    if (exists($self->{'DATASET'}->{$name})) {
	return $self->{'DATASET'}->{$name};
    }
167 168 169 170 171 172 173 174 175 176
    # Or it is for a local storage slot.
    elsif ($name =~ /^_.*$/) {
	if (scalar(@_) == 2) {
	    return $self->{'HASH'}->{$name} = $_[1];
	}
	elsif (exists($self->{'HASH'}->{$name})) {
	    return $self->{'HASH'}->{$name};
	}
	return undef;
    }
177 178 179
    carp("No such slot '$name' field in class $type");
    return undef;
}
180
sub webtask($)  { return $_[0]->{'WEBTASK'}; }
181 182 183 184 185 186

# Break circular reference someplace to avoid exit errors.
sub DESTROY {
    my $self = shift;

    $self->{'DATASET'} = undef;
187
    $self->{'HASH'}    = undef;
188
    $self->{'WEBTASK'} = undef;
189 190
}

Leigh Stoller's avatar
Leigh Stoller committed
191 192 193 194
# Valid Blockstore backend.
sub ValidBlockstoreBackend($)
{
    my ($authority) = @_;
195
    my $aggregate   = APT_Aggregate->Lookup($authority);
196
    return -1
197
	if (!defined($aggregate));
Leigh Stoller's avatar
Leigh Stoller committed
198

199
    return $aggregate->has_datasets();
Leigh Stoller's avatar
Leigh Stoller committed
200 201
}

202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
#
# Refresh a class instance by reloading from the DB.
#
sub Refresh($)
{
    my ($self) = @_;

    return -1
	if (! ref($self));

    my $uuid = $self->uuid();
    
    my $query_result =
	DBQueryWarn("select * from apt_datasets where uuid='$uuid'");

    return -1
	if (!$query_result || !$query_result->numrows);

    $self->{'DATASET'} = $query_result->fetchrow_hashref();
    return 0;
}

#
# Create an Dataset
#
sub Create($$)
{
    my ($class, $argref) = @_;
230 231
    my $pid = $argref->{'pid'};
    my $id  = $argref->{'dataset_id'};
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
    my $uuid;

    if (exists($argref->{'uuid'})) {
	$uuid = $argref->{'uuid'};
	delete($argref->{'uuid'});
    }
    else {
	$uuid = NewUUID();
    }
    my $idx = TBGetUniqueIndex('next_leaseidx');

    #
    # The uuid has to be unique, so lock the table for the check/insert.
    #
    DBQueryWarn("lock tables apt_datasets write")
	or return undef;

    my $query_result =
	DBQueryWarn("select uuid from apt_datasets where uuid='$uuid'");

    if ($query_result->numrows) {
	DBQueryWarn("unlock tables");
	tberror("Dataset uuid $uuid already exists!");
	return undef;
    }

258 259 260 261 262 263 264 265 266 267
    $query_result =
	DBQueryWarn("select uuid from apt_datasets ".
		    "where pid='$pid' and dataset_id='$id'");

    if ($query_result->numrows) {
	DBQueryWarn("unlock tables");
	tberror("Dataset $pid/$id already exists!");
	return undef;
    }

268 269 270 271 272 273 274 275 276 277 278 279
    my $query = "insert into apt_datasets set ".
	" locked=now(),locker_pid='$PID', ".
	" idx='$idx',created=now(),uuid='$uuid', ".
	join(",", map("$_=" .
		      DBQuoteSpecial($argref->{$_}), keys(%{$argref})));

    if (! DBQueryWarn($query)) {
	DBQueryWarn("unlock tables");
	tberror("Error inserting new apt_datasets record for $uuid!");
	return undef;
    }
    DBQueryWarn("unlock tables");
Leigh Stoller's avatar
Leigh Stoller committed
280 281 282 283 284 285 286

    my $dataset = Lookup($class, $uuid);
    return undef
	if (!defined($dataset));
    return undef
	if ($dataset->CreateCertificate());
    return $dataset;
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
}

#
# Stringify for output.
#
sub Stringify($)
{
    my ($self) = @_;
    
    my $uuid  = $self->uuid();

    return "[APT_Dataset: $uuid]";
}

#
# Perform some updates ...
#
sub Update($$)
{
    my ($self, $argref) = @_;

    # Must be a real reference. 
    return -1
	if (! ref($self));

    my $uuid = $self->uuid();

    my $query = "update apt_datasets set ".
	join(",", map("$_=" . DBQuoteSpecial($argref->{$_}), keys(%{$argref})));

    $query .= " where uuid='$uuid'";

    return -1
	if (! DBQueryWarn($query));

    return Refresh($self);
}

sub Delete($)
{
    my ($self) = @_;

    # Must be a real reference. 
    return -1
	if (! ref($self));

    my $uuid = $self->uuid();

Leigh Stoller's avatar
Leigh Stoller committed
335 336 337
    my $certificate = $self->GetCertificate();
    $certificate->Delete()
	if (defined($certificate));
338 339 340
    $self->webtask()->Delete()
	if ($self->webtask());
    
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
    DBQueryWarn("delete from apt_datasets where uuid='$uuid'") or
	return -1;

    return 0;
}

sub SetStatus($$)
{
    my ($self,$status) = @_;

    # Must be a real reference. 
    return -1
	if (! ref($self));

    my $uuid = $self->uuid();

    DBQueryWarn("update apt_datasets set status='$status' ".
		"where uuid='$uuid'") or
	return -1;

    $self->{'DATASET'}->{'status'} = $status;
    return 0;
    
}

366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
#
# Is dataset expired?
#
sub IsExpired($)
{
    my ($self) = @_;

    my $expires = $self->expires();
    return 0
	if (!defined($expires));
    
    $expires = str2time($expires);

    return (time() >= $expires);
}

382
#
383
# Load the project.
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
#
sub GetProject($)
{
    my ($self) = @_;
    require Project;

    my $project = Project->Lookup($self->pid_idx());
    
    if (! defined($project)) {
	print("*** WARNING: Could not lookup project object for $self!\n");
	return undef;
    }
    return $project;
}

399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
#
# Load the creator
#
sub GetCreator($)
{
    my ($self) = @_;
    require User;

    my $creator = User->Lookup($self->creator_idx());
    
    if (! defined($creator)) {
	print("*** WARNING: Could not lookup creator object for $self!\n");
	return undef;
    }
    return $creator;
}

416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
#
# Lock and Unlock
#
sub Lock($;$)
{
    my ($self, $steal) = @_;

    # Already locked?
    if ($self->GotLock()) {
	return 0;
    }
    return -1
	if (!DBQueryWarn("lock tables apt_datasets write"));

    my $idx = $self->idx();

    my $query_result =
	DBQueryWarn("update apt_datasets set locked=now(),locker_pid=$PID " .
		    "where idx=$idx ".
		    (!defined($steal) ? "and locked is null" : ""));

    if (! $query_result ||
	$query_result->numrows == 0) {
	DBQueryWarn("unlock tables");
	return -1
    }
    DBQueryWarn("unlock tables");
    $self->{'LOCKED'} = time();
    $self->{'LOCKER_PID'} = $PID;
    return 0;
}

sub Unlock($)
{
    my ($self) = @_;
    my $idx    = $self->idx();

    return -1
	if (! DBQueryWarn("update apt_datasets set locked=null,locker_pid=0 " .
			  "where idx=$idx"));
    
    $self->{'LOCKED'} = 0;
    $self->{'LOCKER_PID'} = 0;
    return 0;
}

sub GotLock($)
{
    my ($self) = @_;

    return 1
	if ($self->{'LOCKED'} &&
	    $self->{'LOCKER_PID'} == $PID);
    
    return 0;
}

sub TakeLock($)
{
    my ($self) = @_;

    return $self->Lock(1);
}

#
# Locate Geni objects
#
sub GetGeniUser($)
{
    my ($self) = @_;
    require GeniUser;
    require User;

    #
    # Only local users can do this, so do a direct local lookup.
    #
    my $user = User->Lookup($self->creator_idx());
    return undef
	if (!defined($user));
    
    return GeniUser->CreateFromLocal($user);
}

sub GetGeniAuthority($)
{
    my ($self) = @_;
    require GeniAuthority;

    return APT_Geni::GetAuthority($self->aggregate_urn());
}

507 508 509 510 511 512 513
sub GetAggregate($)
{
    my ($self) = @_;

    return APT_Aggregate->Lookup($self->aggregate_urn());
}

514 515 516 517 518 519 520 521 522 523 524
#
# Warn creator that the experiment is going to expire. This is hooked
# in from the sa_daemon, so we can send a message that is less geni like
# and more APT/Cloud.
#
sub WarnExpiring($$)
{
    my ($self, $when) = @_;
    return 0;
}

Leigh Stoller's avatar
Leigh Stoller committed
525 526 527 528 529 530 531 532 533
#
# Create a certificate we can use for the credential. We want this
# certificate to be a subauthority certificate so that the backend puts
# the dataset in an SA subgroup.
#
sub CreateCertificate($)
{
    my ($self) = @_;
    my $pid  = $self->pid();
534
    my $gid  = $self->gid();
Leigh Stoller's avatar
Leigh Stoller committed
535
    my $id   = $self->dataset_id();
536 537 538 539 540 541 542 543
    my $type = $self->type();

    # New domain format for datasets.
    my $domain = $OURDOMAIN;
    $domain .= ":${pid}";
    $domain .= ":${gid}" if ($pid ne $gid);
    
    my $urn  = GeniHRN::Generate($domain, $type, $id);
Leigh Stoller's avatar
Leigh Stoller committed
544 545 546 547 548 549 550

    # Kill stale certificate.
    my $certificate = GeniCertificate->Lookup($urn);
    $certificate->Delete()
	if (defined($certificate));
    
    $certificate = GeniCertificate->Create({"urn"   => $urn,
551
					    "uuid"  => $self->uuid(),
Leigh Stoller's avatar
Leigh Stoller committed
552 553 554 555 556 557 558 559 560 561 562 563 564 565
					    "email" => "$TBOPS",
					    "hrn"   => "$OURDOMAIN.$pid.$id"});
    return -1
	if (!defined($certificate));

    # We want to save until we delete the dataset.
    $certificate->Store() == 0
	or return -1;

    return 0;
}
sub GetCertificate($)
{
    my ($self) = @_;
566 567 568 569 570 571 572 573 574
    my $cert = GeniCertificate->Lookup($self->uuid());
    # Old style
    if (!defined($cert)) {
	my $pid  = $self->pid();
	my $id   = $self->dataset_id();
	my $urn  = GeniHRN::Generate("$OURDOMAIN:$pid", "dataset", $id);
	$cert = GeniCertificate->Lookup($urn);
    }
    return $cert;
Leigh Stoller's avatar
Leigh Stoller committed
575 576
}

577 578 579 580 581 582 583 584 585 586 587 588
# Helper functions for below.
sub ContextError()
{
    return GeniResponse->Create(GENIRESPONSE_ERROR(), undef,
				"Could not generate context for RPC");
}
sub CredentialError()
{
    return GeniResponse->Create(GENIRESPONSE_ERROR(), undef,
				"Could not generate credentials for RPC");
}

589 590 591 592 593 594 595 596 597
#
# Create a dataset on the remote aggregate.
#
sub CreateDataset($)
{
    my ($self) = @_;
    my $authority = $self->GetGeniAuthority();
    my $geniuser  = $self->GetGeniUser();
    my $context   = APT_Geni::GeniContext();
Leigh Stoller's avatar
Leigh Stoller committed
598
    my $cert      = $self->GetCertificate();
599
    return ContextError()
Leigh Stoller's avatar
Leigh Stoller committed
600 601 602 603 604
	if (! (defined($geniuser) && defined($authority) &&
	       defined($context) && defined($cert)));
    
    my ($credential, $speaksfor_credential) =
	APT_Geni::GenCredentials($cert, $geniuser, ["blockstores"]);
605 606

    return CredentialError
607
	if (! (defined($speaksfor_credential) &&
Leigh Stoller's avatar
Leigh Stoller committed
608
	       defined($credential)));
609 610 611 612

    my $args = {
	"size"        => $self->size(),
	"type"        => $self->type(),
613 614
	"read_access" => $self->read_access(),
	"write_access"=> $self->write_access(),
615
	"dataset_urn" => $cert->urn(),
Leigh Stoller's avatar
Leigh Stoller committed
616
	"credentials" => [$credential->asString(),
617 618 619 620
			  $speaksfor_credential->asString()],
    };
    $args->{"fstype"} = $self->fstype()
	if ($self->fstype() ne "none");
Leigh Stoller's avatar
Leigh Stoller committed
621
    $args->{"expires"} = emutil::TBDateStringGMT($self->expires())
622 623 624
	if (defined($self->expires()));

    my $cmurl = $authority->url();
625
    $cmurl =~ s/protogeni/protogeni\/stoller/ if ($usemydevtree);
626 627 628 629 630 631 632 633 634 635 636 637 638

    return Genixmlrpc::CallMethod($cmurl, $context, "CreateDataset", $args);
}

#
# Delete a dataset on the remote aggregate.
#
sub DeleteDataset($)
{
    my ($self) = @_;
    my $authority = $self->GetGeniAuthority();
    my $geniuser  = $self->GetGeniUser();
    my $context   = APT_Geni::GeniContext();
Leigh Stoller's avatar
Leigh Stoller committed
639
    my $cert      = $self->GetCertificate();
640
    return ContextError()
Leigh Stoller's avatar
Leigh Stoller committed
641 642
	if (! (defined($geniuser) && defined($authority) &&
	       defined($context) && defined($cert)));
643

Leigh Stoller's avatar
Leigh Stoller committed
644
    my ($credential, $speaksfor_credential) =
645
	APT_Geni::GenCredentials($cert, $geniuser, ["blockstores"], 1);
646
    return CredentialError()
647
	if (!defined($credential));
648

649 650 651 652
    my $credentials = [$credential->asString()];
    if (defined($speaksfor_credential)) {
	$credentials = [@$credentials, $speaksfor_credential->asString()];
    }
653
    my $args = {
654
	"dataset_urn" => $cert->urn(),
655
	"credentials" => $credentials,
656 657
    };
    my $cmurl = $authority->url();
658
    $cmurl =~ s/protogeni/protogeni\/stoller/ if ($usemydevtree);
659 660 661 662

    return Genixmlrpc::CallMethod($cmurl, $context, "DeleteDataset", $args);
}

663 664 665 666 667 668 669 670 671 672
#
# Apply some updates to the dataset on server.
#
sub ModifyDataset($)
{
    my ($self) = @_;
    my $authority = $self->GetGeniAuthority();
    my $geniuser  = $self->GetGeniUser();
    my $context   = APT_Geni::GeniContext();
    my $cert      = $self->GetCertificate();
673
    return ContextError()
674 675
	if (! (defined($geniuser) && defined($authority) &&
	       defined($context) && defined($cert)));
676

677
    my ($credential, $speaksfor_credential) =
678
	APT_Geni::GenCredentials($cert, $geniuser, ["blockstores"], 1);
679
    return CredentialError()
680
	if (!defined($credential));
681

682 683 684 685
    my $credentials = [$credential->asString()];
    if (defined($speaksfor_credential)) {
	$credentials = [@$credentials, $speaksfor_credential->asString()];
    }
686
    my $args = {
687
	"dataset_urn" => $cert->urn(),
688
	"credentials" => $credentials,
689 690
	"read_access" => $self->read_access(),
	"write_access"=> $self->write_access(),
691 692
    };
    my $cmurl = $authority->url();
693
    $cmurl =~ s/protogeni/protogeni\/stoller/ if ($usemydevtree);
694 695 696 697 698 699 700 701 702 703 704 705 706 707

    return Genixmlrpc::CallMethod($cmurl, $context, "ModifyDataset", $args);
}

#
# Request single extension.
#
sub ExtendDataset($)
{
    my ($self) = @_;
    my $authority = $self->GetGeniAuthority();
    my $geniuser  = $self->GetGeniUser();
    my $context   = APT_Geni::GeniContext();
    my $cert      = $self->GetCertificate();
708
    return ContextError()
709 710
	if (! (defined($geniuser) && defined($authority) &&
	       defined($context) && defined($cert)));
711

712
    my ($credential, $speaksfor_credential) =
713
	APT_Geni::GenCredentials($cert, $geniuser, ["blockstores"], 1);
714
    return CredentialError()
715
	if (!defined($credential));
716

717 718 719 720
    my $credentials = [$credential->asString()];
    if (defined($speaksfor_credential)) {
	$credentials = [@$credentials, $speaksfor_credential->asString()];
    }
721
    my $args = {
722
	"dataset_urn" => $cert->urn(),
723
	"credentials" => $credentials,
724 725 726
	"extend"      => 1,
    };
    my $cmurl = $authority->url();
727
    $cmurl =~ s/protogeni/protogeni\/stoller/ if ($usemydevtree);
728 729 730 731

    return Genixmlrpc::CallMethod($cmurl, $context, "ModifyDataset", $args);
}

732 733 734 735 736 737 738 739 740
#
# Refresh our metadata.
#
sub DescribeDataset($)
{
    my ($self) = @_;
    my $authority = $self->GetGeniAuthority();
    my $geniuser  = $self->GetGeniUser();
    my $context   = APT_Geni::GeniContext();
Leigh Stoller's avatar
Leigh Stoller committed
741
    my $cert      = $self->GetCertificate();
742
    return ContextError()
Leigh Stoller's avatar
Leigh Stoller committed
743 744 745 746
	if (! (defined($geniuser) && defined($authority) &&
	       defined($context) && defined($cert)));
    
    my ($credential, $speaksfor_credential) =
747
	APT_Geni::GenCredentials($cert, $geniuser, ["blockstores"], 1);
748
    return CredentialError()
749
	if (!defined($credential));
750

751 752 753 754
    my $credentials = [$credential->asString()];
    if (defined($speaksfor_credential)) {
	$credentials = [@$credentials, $speaksfor_credential->asString()];
    }
755
    my $args = {
756 757
	"dataset_urn" => $cert->urn(),
	"credentials" => $credentials,
758 759
    };
    my $cmurl = $authority->url();
760
    $cmurl =~ s/protogeni/protogeni\/stoller/ if ($usemydevtree);
761 762 763 764

    return Genixmlrpc::CallMethod($cmurl, $context, "DescribeDataset", $args);
}

765 766 767 768 769 770 771 772 773 774
#
# Get a new credential so we can operate on the dataset.
#
sub GetCredential($)
{
    my ($self) = @_;
    my $authority = $self->GetGeniAuthority();
    my $geniuser  = $self->GetGeniUser();
    my $context   = APT_Geni::GeniContext();
    my $cert      = $self->GetCertificate();
775
    return ContextError()
776 777 778 779 780
	if (! (defined($geniuser) && defined($authority) &&
	       defined($context) && defined($cert)));
    
    my ($credential) =
	APT_Geni::GenAuthCredential($cert, ["blockstores"]);
781
    return CredentialError()
782 783 784 785 786 787 788 789 790 791 792 793 794
	if (!defined($credential));

    my $args = {
	"dataset_urn" => $cert->urn(),
	"credentials" => [$credential->asString()],
    };
    my $cmurl = $authority->url();
    $cmurl =~ s/protogeni/protogeni\/stoller/ if ($usemydevtree);

    return Genixmlrpc::CallMethod($cmurl, $context,
				  "GetDatasetCredential", $args);
}

795 796 797 798 799 800 801 802 803 804
#
# Approve a dataset using an auth credential.
#
sub ApproveDataset($)
{
    my ($self) = @_;
    my $authority = $self->GetGeniAuthority();
    my $geniuser  = $self->GetGeniUser();
    my $context   = APT_Geni::GeniContext();
    my $cert      = $self->GetCertificate();
805
    return ContextError()
806 807 808 809 810
	if (! (defined($geniuser) && defined($authority) &&
	       defined($context) && defined($cert)));
    
    my ($credential) =
	APT_Geni::GenAuthCredential($cert, ["admin"]);
811
    return CredentialError()
812 813 814 815 816 817 818 819 820 821 822 823 824
	if (!defined($credential));

    my $args = {
	"dataset_urn" => $cert->urn(),
	"credentials" => [$credential->asString()],
    };
    my $cmurl = $authority->url();
    $cmurl =~ s/protogeni/protogeni\/stoller/ if ($usemydevtree);

    return Genixmlrpc::CallMethod($cmurl, $context,
				  "ApproveDataset", $args);
}

825 826
# _Always_ make sure that this 1 is at the end of the file...
1;