Commit 1cfa9b6d authored by Leigh Stoller's avatar Leigh Stoller

Add LookupAggregate() utility to lookup an aggregate by urn,nickname,domain

parent 7606439b
#!/usr/bin/perl -wT
#
# Copyright (c) 2007-2016, 2018 University of Utah and the Flux Group.
# Copyright (c) 2007-2016, 2018, 2019 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -42,6 +42,7 @@ use vars qw(@ISA @EXPORT);
use emdb;
use libtestbed;
use APT_Instance;
use APT_Aggregate;
use Project;
use Group;
use GeniHRN;
......@@ -226,3 +227,24 @@ sub ReservationUtilization($$)
return 0;
}
#
# Look using all the various lookup ways.
#
sub LookupAggregate($)
{
my ($token) = @_;
my $aggregate = APT_Aggregate->Lookup($token);
return $aggregate
if (defined($aggregate));
$aggregate = APT_Aggregate->LookupByNickname($token);
return $aggregate
if (defined($aggregate));
$aggregate = APT_Aggregate->LookupByDomain($token);
return $aggregate
if (defined($aggregate));
return undef;
}
......@@ -88,7 +88,6 @@ sub DoShow();
sub DoFlags();
sub DoPing();
sub DoPortals();
sub LookupAggregate($);
#
# Parse command arguments. Once we return from getopts, all that should be
......@@ -109,7 +108,7 @@ my $action = shift(@ARGV);
#
# Default to local cluster, unless overridden in the action.
#
my $aggregate = LookupAggregate($MYURN);
my $aggregate = APT_Utility::LookupAggregate($MYURN);
if (!defined($aggregate)) {
fatal("Could not lookup local aggregate: $MYURN");
}
......@@ -187,7 +186,7 @@ sub DoShow()
if (@ARGV);
if (defined($options{"a"})) {
$aggregate = LookupAggregate($options{"a"});
$aggregate = APT_Utility::LookupAggregate($options{"a"});
fatal("No such aggregate")
if (!defined($aggregate));
}
......@@ -226,7 +225,7 @@ sub DoFlags()
if (@ARGV != 2 || $ARGV[1] !~ /^(yes|no)$/);
if (defined($options{"a"})) {
$aggregate = LookupAggregate($options{"a"});
$aggregate = APT_Utility::LookupAggregate($options{"a"});
fatal("No such aggregate")
if (!defined($aggregate));
}
......@@ -304,7 +303,7 @@ sub DoPing()
if (@ARGV);
if (defined($options{"a"})) {
$aggregate = LookupAggregate($options{"a"});
$aggregate = APT_Utility::LookupAggregate($options{"a"});
fatal("No such aggregate")
if (!defined($aggregate));
}
......@@ -327,7 +326,7 @@ sub DoPortals()
usage();
}
if (defined($options{"a"})) {
$aggregate = LookupAggregate($options{"a"});
$aggregate = APT_Utility::LookupAggregate($options{"a"});
fatal("No such aggregate")
if (!defined($aggregate));
}
......
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