forked from Taryck/idrive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet_Quota.pl
67 lines (60 loc) · 2.2 KB
/
Get_Quota.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/perl
####################################################################
#Script Name : Get_Quota.pl
#TBE : ENH-004 - Get Quota, compute remaining quota
# Get a fresh Quota,
# Save it to .quota file
# Display Quota file content
#####################################################################
use strict;
use warnings;
use lib map{if(__FILE__ =~ /\//) { substr(__FILE__, 0, rindex(__FILE__, '/'))."/$_";} else { "./$_"; }} qw(Idrivelib/lib);
use Helpers;
our $lineFeed = "\n";
our $userName = ${ARGV[0]};
if (! defined $userName or $userName eq "") {
# $userName = getCurrentUser();
#}
#if ($userName eq "") {
print 'Provide User as first parameter or login using Login.pl !'.$lineFeed;
exit 1;
}
Helpers::loadAppPath();
Helpers::loadServicePath();
Helpers::setUsername($userName) if(defined($userName) && $userName ne '');
#if(Helpers::loadUsername()){
Helpers::loadUserConfiguration();
#}
getAndUpdateQuota();
my $file = Helpers::getCachedStorageFile();
open QUOTA_FILE, "<", $file or die "Quota file $file do not exists";
my @QuotaFile = <QUOTA_FILE>;
close QUOTA_FILE;
print @QuotaFile;
#*****************************************************************************************************
# Subroutine : getAndUpdateQuota
# Objective : This method is used to get the quota value and update in the file.
# Added By : Anil Kumar
#****************************************************************************************************/
sub getAndUpdateQuota {
my $csf = Helpers::getCachedStorageFile();
unlink($csf);
Helpers::createUTF8File('GETQUOTA') or Helpers::retreat('failed_to_create_utf8_file');
my @result = Helpers::runEVS('tree');
if (exists $result[0]->{'message'}) {
if ($result[0]->{'message'} eq 'ERROR') {
Helpers::display('unable_to_retrieve_the_quota');
return 0;
}
}
my $freeQuota = $result[0]->{'totalquota'} - $result[0]->{'usedquota'} ;
# $result[0]->{$Configuration::accountStorageSchema{'freeQuota'}{'evs_name'}}
$result[0]->{'remainingQuota'} = $freeQuota;
if (Helpers::saveUserQuota(@result)) {
# return 1 if(Helpers::loadStorageSize());
return 1 ;
}
Helpers::traceLog('unable_to_cache_the_quota');
Helpers::display('unable_to_cache_the_quota') ;
return 0;
}