use strict;
use autodie;
+use lib 'lib';
+use base qw(CloudStore::Gearman);
+
use File::Path qw(make_path remove_tree);
use File::Find;
use Data::Dump qw(dump);
sub new {
- my $class = shift;
- my $self = {@_};
+ my ($class,$group) = @_;
+
+ my ( undef, $dir, $port, undef ) = getgrnam($group) || die "can't find group $group: $!";
+ my $self = {
+ passwd => '/var/lib/extrausers/passwd',
+ PORT => $port,
+ SLICE => $dir,
+ };
bless $self, $class;
- $self->{passwd} ||= '/var/lib/extrausers/passwd';
- $self->{PORT} ||= $ENV{PORT} || die "no PORT in env";
- $self->{SLICE} ||= $ENV{SLICE} || die "no SLICE in env";
-
$self->{md5} = $self->user_info('md5');
return $self;
mkdir $dir;
chown $max_uid, $self->{PORT}, $dir;
+
}
+ # FIXME update quota only on create?
+ $self->gearman_do( 'narada_s1_quota_set' => "$found $new_quota" );
+
return $found;
}
sub usage {
my ( $self, $user ) = @_;
+ $user = $self->user_info($user) unless ref $user eq 'HASH';
my $path = $self->user_dir( $user => '.log');
my $sum;
open(my $fh, '<', $path);
chomp;
my @v = split(/#/,$_);
$sum->{ $v[0] } += $v[1];
- $sum->{_total} += $v[1];
+ $sum->{_usage} += $v[1];
}
+ my ( $usage, $quota ) = split(/ /,
+ $self->gearman_do( 'narada_s1_quota_get' => $user->{uid} )
+ );
+ $sum->{_usage} += $usage;
+ $sum->{_quota} = $quota;
warn "## usage ",dump($user, $sum), $/;
return $sum;
}