GeniSliver.pm.in 16.3 KB
Newer Older
Leigh B. Stoller's avatar
Leigh B. Stoller committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/perl -wT
#
# EMULAB-COPYRIGHT
# Copyright (c) 2008 University of Utah and the Flux Group.
# All rights reserved.
#
package GeniSliver;

#
use strict;
use Exporter;
use vars qw(@ISA @EXPORT);

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

# Must come after package declaration
use lib '@prefix@/lib';
use GeniDB;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
20
use GeniComponent;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
21
use GeniSlice;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
22
use GeniCredential;
23
use GeniCertificate;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
24
use GeniAggregate;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
25
# Hate to import all this crap; need a utility library.
26
use libdb qw(TBGetUniqueIndex);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
27
use libtestbed;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
28
29
use Experiment;
use Node;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
30
31
32
use English;
use Data::Dumper;
use File::Temp qw(tempfile);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
33
use overload ('""' => 'Stringify');
Leigh B. Stoller's avatar
Leigh B. Stoller committed
34
35
36
37
38
39
40
41
42

# Configure variables
my $TB		   = "@prefix@";
my $TBOPS          = "@TBOPSEMAIL@";
my $TBAPPROVAL     = "@TBAPPROVALEMAIL@";
my $TBAUDIT   	   = "@TBAUDITEMAIL@";
my $BOSSNODE       = "@BOSSNODE@";
my $OURDOMAIN      = "@OURDOMAIN@";
my $SIGNCRED	   = "$TB/sbin/signgenicred";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
43
44
45
my $AVAIL	   = "$TB/sbin/avail";
my $NALLOC	   = "$TB/bin/nalloc";
my $NFREE	   = "$TB/bin/nfree";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
46
my $NODEREBOOT	   = "$TB/bin/node_reboot";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
47
48
49
50
51
52
53
54
55
56
57

# Cache of instances to avoid regenerating them.
my %slivers      = ();

#
# Lookup by idx, or uuid.
#
sub Lookup($$)
{
    my ($class, $token) = @_;
    my $query_result;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
58
    my $idx;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
59
60

    if ($token =~ /^\d+$/) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
61
	$idx = $token;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
62
63
64
    }
    elsif ($token =~ /^\w+\-\w+\-\w+\-\w+\-\w+$/) {
	$query_result =
Leigh B. Stoller's avatar
Leigh B. Stoller committed
65
	    DBQueryWarn("select idx from geni_slivers ".
Leigh B. Stoller's avatar
Leigh B. Stoller committed
66
			"where uuid='$token'");
Leigh B. Stoller's avatar
Leigh B. Stoller committed
67
68
69
70
	    return undef
		if (! $query_result || !$query_result->numrows);

	    ($idx) = $query_result->fetchrow_array();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
71
72
73
74
    }
    else {
	return undef;
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
75
76
77
78
79
80
81
82

    # Look in cache first
    return $slivers{"$idx"}
        if (exists($slivers{"$idx"}));

    $query_result = DBQueryWarn("select * from geni_slivers ".
				"where idx='$idx'");

Leigh B. Stoller's avatar
Leigh B. Stoller committed
83
84
85
    return undef
	if (!$query_result || !$query_result->numrows);

Leigh B. Stoller's avatar
Leigh B. Stoller committed
86
87
88
    my $self              = {};
    $self->{'SLIVER'}     = $query_result->fetchrow_hashref();
    $self->{'COMPONENT'}  = undef;	# Client side.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
89
    $self->{'SLICE'}      = undef;	# Client side.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
90
    $self->{'CREDENTIAL'} = undef;	# Client side.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
91
    $self->{'AGGREGATE'}  = undef;	# server side.
92
93
94
95
96
97
98
99
100
101
102

    #
    # Grab the certificate, since we will probably want it.
    #
    my $uuid = $self->{'SLIVER'}->{'uuid'};
    my $certificate = GeniCertificate->Lookup($uuid);
    if (!defined($certificate)) {
	print STDERR "Could not find certificate for sliver $idx ($uuid)\n";
	return undef;
    }
    $self->{'CERTIFICATE'} = $certificate;
103
104
105
106
107
108
109
110
111

    # Bless into sub package if called for.
    my $resource_type = $self->{'SLIVER'}->{'resource_type'};
    if (defined($resource_type) && $resource_type ne "") {
	bless($self, $class . "::" . $self->{'SLIVER'}->{'resource_type'});
    }
    else {
	bless($self, $class);
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
    
    # Add to cache. 
    $slivers{$self->{'SLIVER'}->{'idx'}} = $self;
    
    return $self;
}

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

    return "[GeniSliver: $uuid, IDX: $idx]";
}

#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
133
# Create a sliver record in the DB. On the client side we save the credential
Leigh B. Stoller's avatar
Leigh B. Stoller committed
134
# that allows control of it, for later operations.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
135
#
136
sub Create($$$$;$$$)
Leigh B. Stoller's avatar
Leigh B. Stoller committed
137
{
138
139
    my ($class, $slice, $user, $resource_uuid, $resource_type,
	$credential, $component) = @_;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
140
    my @insert_data = ();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
141
    my $uuid;
142
    my $certificate;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
143
144
145

    # Every sliver gets a new unique index.
    my $idx = TBGetUniqueIndex('next_sliver', 1);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
146
    if (defined($credential)) {
147
148
149
150
151
152
	# Store the certificate for later use.
	$certificate = GeniCertificate->StorePublic($credential->this_cert());
	if (!defined($certificate)) {
	    print STDERR "Could not store certificate\n";
	    return undef;
	}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
153
154
155
156
157
158
159
	$uuid = $credential->this_uuid();

	# Store the credential
	return undef
	    if ($credential->Store() != 0);
    }
    else {
160
161
162
163
	# Create a cert pair, which gives us a new uuid.
	$certificate = GeniCertificate->Create("sliver");
	if (!defined($certificate)) {
	    print STDERR "Could not generate new certificate and UUID!\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
164
165
	    return undef;
	}
166
	$uuid = $certificate->uuid();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
167
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
168
169
    my $slice_uuid     = $slice->uuid();
    my $owner_uuid     = $user->uuid();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
170
171
172
173
174

    # Now tack on other stuff we need.
    push(@insert_data, "created=now()");
    push(@insert_data, "idx='$idx'");
    push(@insert_data, "uuid='$uuid'");
Leigh B. Stoller's avatar
Leigh B. Stoller committed
175
176
    push(@insert_data, "resource_uuid='$resource_uuid'")
	if (defined($resource_uuid));
177
178
    push(@insert_data, "resource_type='$resource_type'")
	if (defined($resource_type));
Leigh B. Stoller's avatar
Leigh B. Stoller committed
179
180
181
    push(@insert_data, "creator_uuid='$owner_uuid'");
    push(@insert_data, "slice_uuid='$slice_uuid'");

Leigh B. Stoller's avatar
Leigh B. Stoller committed
182
183
184
185
    # Only on the client side.
    push(@insert_data, "credential_idx=" . $credential->idx())
	if (defined($credential));
    # Only on the client side.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
186
187
    push(@insert_data, "component_idx=" . $component->idx())
	if (defined($component));
Leigh B. Stoller's avatar
Leigh B. Stoller committed
188

Leigh B. Stoller's avatar
Leigh B. Stoller committed
189
    # Insert into DB.
190
191
192
    if (!DBQueryWarn("insert into geni_slivers set " .
		     join(",", @insert_data))) {
	$certificate->Delete();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
193
194
195
	return undef;
    }

Leigh B. Stoller's avatar
Leigh B. Stoller committed
196
197
198
    my $sliver = GeniSliver->Lookup($idx);
    return undef
	if (!defined($sliver));
Leigh B. Stoller's avatar
Leigh B. Stoller committed
199
200
201
    
    $sliver->{'CREDENTIAL'} = $credential
	if (defined($credential));
Leigh B. Stoller's avatar
Leigh B. Stoller committed
202
203
204
    $sliver->{'COMPONENT'} = $component
	if (defined($component));
    $sliver->{'AGGREGATE'} = undef;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
205
    $sliver->{'SLICE'}     = undef;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
206
207

    return $sliver;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
208
209
210
211
212
213
214
215
}
# accessors
sub field($$) { return ((! ref($_[0])) ? -1 : $_[0]->{'SLIVER'}->{$_[1]}); }
sub idx($)		{ return field($_[0], "idx"); }
sub uuid($)		{ return field($_[0], "uuid"); }
sub slice_uuid($)	{ return field($_[0], "slice_uuid"); }
sub creator_uuid($)	{ return field($_[0], "creator_uuid"); }
sub created($)		{ return field($_[0], "created"); }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
216
sub credential_idx($)	{ return field($_[0], "credential_idx"); }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
217
sub resource_uuid($)	{ return field($_[0], "resource_uuid"); }
218
sub resource_type($)	{ return field($_[0], "resource_type"); }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
219
220
sub ticket_idx($)	{ return field($_[0], "ticket_idx"); }
sub component_idx($)	{ return field($_[0], "component_idx"); }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
221
222
sub aggregate_idx($)	{ return field($_[0], "aggregate_idx"); }
sub status($)		{ return field($_[0], "status"); }
223
224
sub cert($)		{ return $_[0]->{'CERTIFICATE'}->cert(); }
sub GetCertificate($)   { return $_[0]->{'CERTIFICATE'}; }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
225
226
227
228
229
230
231
232
233
234
235

#
# Delete the sliver. The sliver should not be provisioned when this done.
#
sub Delete($)
{
    my ($self) = @_;

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

236
237
    my $idx  = $self->idx();
    my $uuid = $self->uuid();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
238

239
240
241
242
    DBQueryWarn("delete from geni_credentials where this_uuid='$uuid'")
	or return -1;
    DBQueryWarn("delete from geni_certificates where uuid='$uuid'")
	or return -1;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
243
244
245
246
247
248
    DBQueryWarn("delete from geni_slivers where idx='$idx'")
	or return -1;
    
    return 0;
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#
# Set the aggregate for a sliver.
#
sub SetAggregate($$)
{
    my ($self, $aggregate) = @_;

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

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

    return -1
	if (!DBQueryWarn("update geni_slivers set ".
			 "  aggregate_idx='$agg_idx' ".
			 "where idx='$idx'"));
    
    $self->{'SLIVER'}->{'aggregate_idx'} = $agg_idx;
    $self->{'AGGREGATE'} = $aggregate;
    return 0;
}

#
# Get the aggregate for a sliver.
#
sub GetAggregate($)
{
    my ($self) = @_;

    return undef
	if (! ref($self));

    return $self->{'AGGREGATE'} if (defined($self->{'AGGREGATE'}));
    return undef
	if (!defined($self->aggregate_idx()));

    my $aggregate = GeniAggregate->Lookup($self->aggregate_idx());
    if (!defined($aggregate)) {
	print STDERR "Could not get aggregate object associated with $self\n";
	return undef;
    }
    $self->{'AGGREGATE'} = $aggregate;
    return $aggregate;
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
295
296
297
298
299
300
301
302
303
304
305
306
307
#
# Get the experiment for the slice this sliver belongs to.
#
sub GetExperiment($)
{
    my ($self) = @_;

    return undef
	if (! ref($self));

    return Experiment->Lookup($self->slice_uuid());
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
308
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
309
# Get the credential for the sliver.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
310
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
311
sub GetCredential($)
Leigh B. Stoller's avatar
Leigh B. Stoller committed
312
313
314
315
316
317
{
    my ($self) = @_;

    return undef
	if (! ref($self));

Leigh B. Stoller's avatar
Leigh B. Stoller committed
318
319
320
321
322
323
324
325
326
    return $self->{'CREDENTIAL'} if (defined($self->{'CREDENTIAL'}));

    if (!defined($self->credential_idx())) {
	print STDERR "No credential associated with $self\n";
	return undef;
    }
    my $credential = GeniCredential->Lookup($self->credential_idx());
    if (!defined($credential)) {
	print STDERR "Could not get credential object associated with $self\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
327
328
	return undef;
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
    $self->{'CREDENTIAL'} = $credential;
    return $credential;
}

#
# Get the component for the sliver.
#
sub GetComponent($)
{
    my ($self) = @_;

    return undef
	if (! ref($self));

    return $self->{'COMPONENT'} if (defined($self->{'COMPONENT'}));

    if (!defined($self->component_idx())) {
	print STDERR "No component associated with $self\n";
	return undef;
    }
    my $component = GeniComponent->Lookup($self->component_idx());
    if (!defined($component)) {
	print STDERR "Could not get component object associated with $self\n";
	return undef;
    }
    $self->{'COMPONENT'} = $component;
    return $component;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
356
357
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
#
# Get the slice for the sliver.
#
sub GetSlice($)
{
    my ($self) = @_;

    return undef
	if (! ref($self));

    return $self->{'SLICE'} if (defined($self->{'SLICE'}));

    if (!defined($self->slice_uuid())) {
	print STDERR "No slice associated with $self\n";
	return undef;
    }
    my $slice = GeniSlice->Lookup($self->slice_uuid());
    if (!defined($slice)) {
	print STDERR "Could not get slice object associated with $self\n";
	return undef;
    }
    $self->{'SLICE'} = $slice;
    return $slice;
}

383
384
385
386
387
388
389
390
391
392
393
394
#
# Client side method to contact the sliver component and destroy it.
#
sub Destroy($$)
{
    my ($self, $user) = @_;

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

    my $component = $self->GetComponent();
    return -1
Leigh B. Stoller's avatar
Leigh B. Stoller committed
395
	if (!defined($component));
396
397
398
399
400
401
402
403
404
405
406

    return -1
	if ($component->DestroySliver($self, $user) != 0);

    # Delete the local object from the DB.
    $self->Delete() == 0
	or return -1;

    return 0;
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
#
# Client side method to contact the sliver component and start it.
#
sub Start($$)
{
    my ($self, $user) = @_;

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

    my $component = $self->GetComponent();
    return -1
	if (!defined($component));

    return -1
	if ($component->StartSliver($self, $user) != 0);

    return 0;
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
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
#
# Client side methods to bind and unbind users from slivers.
#
# XXX We issue this using the local SA as the authority, but need to allow
# the slice/sliver owner to do this.
# 
sub BindUser($$)
{
    my ($self, $target_user) = @_;

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

    my $component = $self->GetComponent();
    return -1
	if (!defined($component));

    return -1
	if ($component->BindUser($self, $target_user) != 0);

    return 0;
}

sub UnBindUser($$)
{
    my ($self, $target_user) = @_;

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

    my $component = $self->GetComponent();
    return -1
	if (!defined($component));

    return -1
	if ($component->UnBindUser($self, $target_user) != 0);

    return 0;
}

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
507
508
509
510
511
512
513
514
#
# Create a signed credential for this sliver, issued to the provided user.
# The credential will grant all permissions for now.
#
# Should we store these credentials in the DB, recording what we hand out?
#
sub NewCredential($$)
{
    my ($self, $owner) = @_;

    return undef
	if (! (ref($self) && ref($owner)));

    my $credential = GeniCredential->Create($self, $owner);
    if (!defined($credential)) {
	print STDERR "Could not create credential for $self, $owner\n";
	return undef;
    }
    if ($credential->Sign($self->GetCertificate()) != 0) {
	print STDERR "Could not sign credential for $self, $owner\n";
	return undef;
    }
    return $credential;
}

############################################################################
#
# The server side methods are in packages which inherit from above.
#
package GeniSliver::Node;
use vars qw(@ISA);
@ISA = "GeniSliver";

use GeniDB;
use GeniComponent;
use GeniSlice;
use GeniCredential;
use GeniCertificate;
use GeniAggregate;
use libdb qw(TBDB_ALLOCSTATE_RES_INIT_DIRTY);

sub Create()
{
    my ($class, $slice, $user, $resource_uuid) = @_;

    return GeniSliver->Create($slice, $user, $resource_uuid, "Node");
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
515
516
#
# Provision a slice. We actually did this when the ticket was requested.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
517
# We fill in some virt table stuff so that tbswap will work.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
518
519
520
#
sub Provision($)
{
Leigh B. Stoller's avatar
Leigh B. Stoller committed
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
    my ($self) = @_;

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

    #
    # the node is already allocated to the sliver, but still need to enter
    # a virt_nodes entry, and possibly more virt table entries, so that the
    # node will boot properly, and is otherwie controllable.
    #
    my $experiment = Experiment->Lookup($self->slice_uuid());
    if (!defined($experiment)) {
	print STDERR "Could not map $self to its experiment\n";
	return -1;
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
536
    my $resource_uuid = $self->resource_uuid();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
537
    return 0
Leigh B. Stoller's avatar
Leigh B. Stoller committed
538
539
	if (!defined($resource_uuid));
    my $node       = Node->Lookup($resource_uuid);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
540
    if (!defined($node)) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
541
	print STDERR "Could not map node $resource_uuid to its object\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
542
543
544
545
546
547
548
549
	return -1;
    }
    my $reservation = $node->Reservation();
    if (!defined($reservation)) {
	print STDERR "$node was already released from $self\n";
	return -1;
    }
    if ($reservation->SameExperiment($experiment)) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
550
551
552
553
	# Set sliver_idx in the reservation so that Emulab knows.
	if ($node->ModifyReservation({"genisliver_idx" => $self->idx()}) != 0){
	    return -1;
	}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
554
555
556
557
	#
	# This is so tbswap and children do the right thing.
	#
	$node->SetAllocState(TBDB_ALLOCSTATE_RES_INIT_DIRTY());
Leigh B. Stoller's avatar
Leigh B. Stoller committed
558
559
560
561
562
563
    }
    else {
	print STDERR "$node is reserved to another, not $self\n";
	# Signal error so we can look at what happened.
	return -1;
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
564
565
566
567
568
569
570
571
572
573
574
575
576
577
    return 0;
}

#
# Unprovision a sliver. 
#
sub UnProvision($)
{
    my ($self) = @_;

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

    my $experiment = Experiment->Lookup($self->slice_uuid());
Leigh B. Stoller's avatar
Leigh B. Stoller committed
578
579
580
581
    if (!defined($experiment)) {
	print STDERR "Could not map $self to its experiment\n";
	return -1;
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
582
    my $resource_uuid = $self->resource_uuid();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
583
    return 0
Leigh B. Stoller's avatar
Leigh B. Stoller committed
584
585
	if (!defined($resource_uuid));
    my $node       = Node->Lookup($resource_uuid);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
586
    if (!defined($node)) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
587
	print STDERR "Could not map node $resource_uuid to its object\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
588
589
590
591
592
593
594
595
	return -1;
    }
    my $reservation = $node->Reservation();
    if (!defined($reservation)) {
	print STDERR "$node was already released from $self\n";
	return 0;
    }
    if ($reservation->SameExperiment($experiment)) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
596
	my $node_id = $node->node_id();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
597
598
	my $pid = $experiment->pid();
	my $eid = $experiment->eid();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
599

Leigh B. Stoller's avatar
Leigh B. Stoller committed
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
	system("export NORELOAD=1; $NFREE -q $pid $eid $node_id");
	if ($?) {
	    print STDERR "Could not deallocate $node from $self\n";
	    return -1;
	}
    }
    else {
	print STDERR "$node is reserved to another, not $self\n";
	# Signal error so we can look at what happened.
	return -1;
    }
    return 0;
}

#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
615
# Start a sliver, which means what?
Leigh B. Stoller's avatar
Leigh B. Stoller committed
616
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
617
sub StartUp($)
Leigh B. Stoller's avatar
Leigh B. Stoller committed
618
619
620
621
622
623
624
625
626
627
628
{
    my ($self) = @_;

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

    my $experiment = Experiment->Lookup($self->slice_uuid());
    if (!defined($experiment)) {
	print STDERR "Could not map $self to its experiment\n";
	return -1;
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
629
    my $resource_uuid = $self->resource_uuid();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
630
    return 0
Leigh B. Stoller's avatar
Leigh B. Stoller committed
631
632
	if (!defined($resource_uuid));
    my $node       = Node->Lookup($resource_uuid);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
633
    if (!defined($node)) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
634
	print STDERR "Could not map node $resource_uuid to its object\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
635
636
637
638
639
640
641
642
	return -1;
    }
    my $reservation = $node->Reservation();
    if (!defined($reservation)) {
	print STDERR "$node was already released from $self\n";
	return -1;
    }
    if ($reservation->SameExperiment($experiment)) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
643
	my $node_id = $node->node_id();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
644
645
646
	#
	# Reboot and wait?
	#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
647
	#system("$NODEREBOOT $node_id");
Leigh B. Stoller's avatar
Leigh B. Stoller committed
648
649
650
651
652
    }
    else {
	print STDERR "$node is reserved to another, not $self\n";
	# Signal error so we can look at what happened.
	return -1;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
653
654
655
    }
    return 0;
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
656

657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
##########################################################################
package GeniSliver::Interface;
use vars qw(@ISA);
@ISA = "GeniSliver";

use GeniDB;
use GeniComponent;
use GeniSlice;
use GeniCredential;
use GeniCertificate;
use GeniAggregate;

sub Create()
{
    my ($class, $slice, $user, $resource_uuid) = @_;

    return GeniSliver->Create($slice, $user, $resource_uuid, "Interface");
}

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

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

    return 0;
}

#
# Unprovision a sliver. 
#
sub UnProvision($)
{
    my ($self) = @_;

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

    return 0;
}

#
# Start a sliver, which means what?
#
sub StartUp($)
{
    my ($self) = @_;

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

    return 0;
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
711

Leigh B. Stoller's avatar
Leigh B. Stoller committed
712
713
# _Always_ make sure that this 1 is at the end of the file...
1;