Commit e6e123f2 authored by Mike Hibler's avatar Mike Hibler

New sitevar to set a default per-project dataset quota.

In createdataset, if the "usequotas" sitevar is set for the dataset type in
question but a quota does not exist for the dataset's project, we create
a quota object using the value from the new "default_quota" sitevar for that
dataset type. If that sitevar does not exist or has a value of zero, we do
NOT create a quota object and hence createdataset will fail.
parent 593398ba
#!/usr/bin/perl -wT
#
# Copyright (c) 2012,2013 University of Utah and the Flux Group.
# Copyright (c) 2012-2015 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -179,7 +179,7 @@ sub Create($$) {
$size = $argref->{'size'};
$notes = $argref->{'notes'} || "";
if (!($quota_id && $pid && $type && $size)) {
if (!($quota_id && $pid && $type && defined($size))) {
print STDERR "Quota->Create: Missing required parameters in argref\n";
return undef;
}
......@@ -227,7 +227,7 @@ sub Create($$) {
}
$safe_notes = DBQuoteSpecial($notes);
} else {
$safe_notes = "";
$safe_notes = "NULL";
}
# Get a unique quota index and slam this stuff into the DB.
......
......@@ -134,6 +134,7 @@ INSERT INTO sitevariables VALUES ('nodecheck/check',NULL,'0','When set, perform
INSERT INTO sitevariables VALUES ('general/xenvifrouting',NULL,'0','Non-zero value says to use vif routing on XEN shared nodes.',0);
INSERT INTO sitevariables VALUES ('general/default_xen_parentosid',NULL,'emulab-ops,XEN43-64-STD','The default parent OSID to use for XEN capable images.',0);
INSERT INTO sitevariables VALUES ('storage/stdataset/usequotas',NULL,'0','If non-zero, enforce per-project dataset quotas',0);
INSERT INTO sitevariables VALUES ('storage/stdataset/default_quota',NULL,'0','Default quota (in MiB) to use for a project if no current quota is set. Only applies if usequotas is set for this type (0 == pid must have explicit quota, -1 == unlimited)',0);
INSERT INTO sitevariables VALUES ('storage/stdataset/maxextend',NULL,'2','Number of times a user can extend the lease (0 == unlimited)',0);
INSERT INTO sitevariables VALUES ('storage/stdataset/extendperiod',NULL,'1','Length (days) of each user-requested extention (0 == do not allow extensions)',0);
INSERT INTO sitevariables VALUES ('storage/stdataset/maxidle',NULL,'0','Max time (days) from last use before lease is marked expired (0 == unlimited)',0);
......@@ -146,6 +147,7 @@ INSERT INTO sitevariables VALUES ('storage/ltdataset/extendperiod',NULL,'0','Len
INSERT INTO sitevariables VALUES ('storage/ltdataset/maxlease',NULL,'0','Max time (days) from creation before lease is marked expired (0 == unlimited)',0);
INSERT INTO sitevariables VALUES ('storage/stdataset/autodestroy',NULL,'1','If non-zero, destroy expired datasets after grace period, otherwise lock them',0);
INSERT INTO sitevariables VALUES ('storage/ltdataset/usequotas',NULL,'1','If non-zero, enforce per-project dataset quotas',0);
INSERT INTO sitevariables VALUES ('storage/ltdataset/default_quota',NULL,'0','Default quota (in MiB) to use for a project if no current quota is set. Only applies if usequotas is set for this type (0 == pid must have explicit quota, -1 == unlimited)',0);
INSERT INTO sitevariables VALUES ('storage/ltdataset/maxsize',NULL,'0','Max size (MiB) of a dataset (0 == unlimited)',0);
INSERT INTO sitevariables VALUES ('storage/ltdataset/graceperiod',NULL,'180','Time (days) before an expired dataset will be destroyed (0 == no grace period)',0);
INSERT INTO sitevariables VALUES ('storage/ltdataset/maxidle',NULL,'180','Max time (days) from last use before lease is marked expired (0 == unlimited)',0);
......
#
# Add more sitevars for persistent dataset handling:
#
# storage/<type>/<var>
#
# where <type> is either "stdataset" or "ltdataset" and <var> is one of:
#
# default_quota Default quota (in MiB) to use for a project if no current
# quota is set. Only applies if usequotas is set for this type
# (0 == pid must have explicit quota, -1 == unlimited)
#
use strict;
use libdb;
sub DoUpdate($$$)
{
my ($dbhandle, $dbname, $version) = @_;
#
# Plausible defaults:
#
# Short-term datasets. Require an explicit quota be set.
#
# Long-term datasets. Ditto.
#
my %value = (
"stdataset/default_quota" => 0,
"ltdataset/default_quota" => 0,
);
my %desc = (
"stdataset/default_quota" => "Default quota (in MiB) to use for a project if no current quota is set. Only applies if usequotas is set for this type (0 == pid must have explicit quota, -1 == unlimited)",
"ltdataset/default_quota" => "Default quota (in MiB) to use for a project if no current quota is set. Only applies if usequotas is set for this type (0 == pid must have explicit quota, -1 == unlimited)",
);
foreach my $name (keys %value) {
my $val = $value{$name};
my $desc = $desc{$name};
DBQueryFatal("INSERT INTO sitevariables VALUES ".
" ('storage/$name',NULL,'$val','$desc',0)")
if (!TBSiteVarExists("storage/$name"));
}
return 0;
}
1;
# Local Variables:
# mode:perl
# End:
......@@ -72,7 +72,7 @@ my %attrs = ();
my $read_access;
my $write_access;
my $qname = "global_ltdataset";
my $qprefix = "global_";
my $quota;
# Valid dataset types
......@@ -384,9 +384,40 @@ if (Lease->Lookup($pid, $gid, $lname)) {
# must be below the project limit.
#
if ($vars->{"usequotas"}) {
my $qname = $qprefix . $dstype;
$quota = Quota->Lookup($pid, $qname);
if (!defined($quota)) {
fatal("No $qname quota associated with $pid.");
#
# XXX Quota does not exist. See if there is a system-wide
# default and use that if so (also, create a quota entry).
#
my $qval = $vars->{"default_quota"};
if ($qval) {
my $qargs = {
"quota_id" => $qname,
"pid" => $pid,
"type" => $dstype,
"size" => 0,
"notes" => "SystemDefault"
};
$quota = Quota->Create($qargs);
# XXX set size explicitly because of special "unlimited" value
if (defined($quota)) {
my $rv;
if ($qval == -1) {
$rv = $quota->SetUnlimited();
} else {
$rv = $quota->SetSize($qval);
}
if ($rv) {
print STDERR "*** could not set quota size $qval\n";
}
}
}
if (!defined($quota)) {
fatal("No $qname quota associated with $pid.");
}
}
#
......
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