Commit 5c417cf4 authored by Leigh Stoller's avatar Leigh Stoller

New script to set geni_slice expiration_max,renew_limit, and idle.

Usage: setexpiration [-f] [-m <time> | -M] [-e <datetime> | -E] [-i | -I] <slice>
Options:
  -f      - Force operation even it makes no sense.
  -m      - Max increment time for a renew. In minutes.
            Use zero to allow anything. Use "null" to clear.
            Use "NN days" or "NN hours" also.
  -M      - Clear max increment time for a renew.
  -e      - Termination date; sliver may not be renewed past this
            date. Use standard date format (YYYY-MM-DD HH:MM:SS)
  -E      - Clear max termination date.
  -i      - Set 'idle ignore'; no idle checks or email.
  -I      - Turn idle checks back on.
parent 2726b523
#!/usr/bin/perl -w
#
# Copyright (c) 2008-2013 University of Utah and the Flux Group.
#
# {{{GENIPUBLIC-LICENSE
#
# GENI Public License
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and/or hardware specification (the "Work") to
# deal in the Work without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Work, and to permit persons to whom the Work
# is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Work.
#
# THE WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS
# IN THE WORK.
#
# }}}
#
use strict;
use English;
use Getopt::Std;
use Date::Parse;
use Time::Local;
#
# Set the slice expiration slots in the DB. CM only, this makes
# no sense for the SA or CH right now.
#
sub usage()
{
print "Usage: setexpiration [-f] ".
"[-m <time> | -M] [-e <datetime> | -E] [-i | -I] <slice>\n";
print "Options:\n";
print " -f - Force operation even it makes no sense.\n";
print " -m - Max increment time for a renew. In minutes.\n";
print " Use zero to allow anything. Use \"null\" to clear.\n";
print " Use \"NN days\" or \"NN hours\" also.\n";
print " -M - Clear max increment time for a renew.\n";
print " -e - Termination date; sliver may not be renewed past this\n";
print " date. Use standard date format (YYYY-MM-DD HH:MM:SS)\n";
print " -E - Clear max termination date.\n";
print " -i - Set 'idle ignore'; no idle checks or email.\n";
print " -I - Turn idle checks back on.\n";
exit(1);
}
sub fatal($);
my $optlist = "dfm:e:MEiI";
my $debug = 0;
my $force = 0;
#
# Configure variables
#
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $TBLOGS = "@TBLOGSEMAIL@";
# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin:/usr/site/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Turn off line buffering on output
#
$| = 1;
# Load the Testbed support stuff.
use lib "@prefix@/lib";
use GeniDB;
use GeniSlice;
use GeniUtil;
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{"f"})) {
$force = 1;
}
if (defined($options{"d"})) {
$debug = 1;
}
usage()
if (@ARGV != 1);
my $token = $ARGV[0];
# Specify either or both.
my $termination;
my $maxrenew;
my $clear_maxrenew = 0;
my $clear_termination = 0;
if (defined($options{"M"})) {
$clear_maxrenew = 1;
}
elsif (defined($options{"m"})) {
$maxrenew = $options{"m"};
if ($maxrenew =~ /^(\d*)\s*days?$/) {
$maxrenew = $1 * 24 * 60;
}
elsif ($maxrenew =~ /^(\d*)\s*hours?$/) {
$maxrenew = $1 * 60;
}
elsif ($maxrenew !~ /^\d*$/) {
fatal("Must be an integer for -m option");
}
if ($maxrenew < 10) {
fatal("Too short for -m option; must be greater then 10 minutes");
}
if ($maxrenew > (30 * 24 * 60)) {
fatal("Too long for -m option; must be less then 30 days");
}
# Yep, its really seconds.
$maxrenew = $maxrenew * 60;
}
if (defined($options{"E"})) {
$clear_termination = 1;
}
elsif (defined($options{"e"})) {
$termination = str2time($options{"e"});
if (!$termination) {
fatal("Cannot parse the -e option.");
}
if ($termination < time()) {
fatal("Cannot use -e option to travel to the past");
}
}
# Connect to the proper DB.
DBConnect(GENICM_DBNAME());
my $slice = GeniSlice->Lookup($token);
if (!defined($slice)) {
fatal("No such slice for $token");
}
if ($slice->Lock()) {
fatal("Could not lock slice $slice");
}
if ($clear_maxrenew && $slice->SetRenewLimit(undef)) {
$slice->UnLock();
fatal("Could not set clear renew limit");
}
elsif (defined($maxrenew) && $slice->SetRenewLimit($maxrenew)) {
$slice->UnLock();
fatal("Could not set set renew limit");
}
if ($clear_termination && $slice->SetExpirationMax(undef)) {
$slice->UnLock();
fatal("Could not clear termination max");
}
elsif (defined($termination) && $slice->SetExpirationMax($termination)) {
$slice->UnLock();
fatal("Could not set termination max");
}
if (defined($options{"i"})) {
$slice->SetIdleIgnore(1);
}
elsif (defined($options{"I"})) {
$slice->SetIdleIgnore(0);
}
$slice->UnLock();
exit(0);
sub fatal($) {
my ($msg) = @_;
print STDERR "$msg\n";
exit(1);
}
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