Subscribe

Setting Quotas with perl

Does anyone have an already written script or example of setting quotas via perl?   Thanks!

Re: Setting Quotas with perl

Hello Paul

Check this out - https://communities.netapp.com/docs/DOC-14719

Zach has written a Qtree Quota Manager which might be of help, though it is in .NET

-Kunal

Re: Setting Quotas with perl

Doing some searching around, I found an article which referred to the example code that comes with the ONTAP API when you download it.  Looking at what I've downloaded (v4.0 atm), it's <extracted_api_folder>/src/sample/Data_ONTAP/Perl and in there is a file called "quotalist.pl"... Relatively sure you could modify that code to use "quota-set-entry" with the necessary params and you should be good to go..

Sorry I dont have an actual code example but hopefully this will get you guided down the right path.

Re: Setting Quotas with perl

Here my subs I used in my LDAP -> Quota script. Maybe you find them helpful. Beware: resize quota just helps in case you changed a quota entry of an existing user. Otherwise you have to do an quota off/on.  

sub create_quota($uid,$quota) {         

my $out;        

my $disklimit;        

my $filelimit;        

my $softdisk;        

my $softfile;       

my $threshold;        

my $s = NaServer->new ($filer, 1, 3);       

my $response = $s->set_style(LOGIN);       

if (ref ($response) eq "NaElement" && $response->results_errno != 0)

         {       my $r = $response->results_reason();

                 print "Unable to set authentication style $r\n";

                 return 2;

         }

         $s->set_admin_user($user, $pw);

         $response = $s->set_transport_type(HTTPS);

         if (ref ($response) eq "NaElement" && $response->results_errno != 0)

         {

                my $r = $response->results_reason();

                 print "Unable to set transport type $r\n";

                 return 2;

         }

         $response = $s->set_port(443);

         if (ref ($response) eq "NaElement" && $response->results_errno != 0)

         {

                 my $r = $response->results_reason();

                 print "Unable to set port to 443$r\n";

                 return 2;

         }

          if($quota==0)

         {

           $disklimit="-";

           $filelimit="-";

           $softdisk="-";

           $softfile="-";

           $threshold="-";

         }

         else

         {

           $disklimit=$quota;

           $filelimit=ceil($quota*0.1);

           $softdisk=ceil($quota*0.95);

           $softfile=ceil($filelimit*0.95);

           $threshold=ceil($quota*0.95);

         }

          $out = $s->invoke( "quota-add-entry",

                            "disk-limit","$disklimit",

                            "file-limit","$filelimit",

                            "quota-type","user",

                            "soft-disk-limit","$softdisk",

                            "soft-file-limit","$softfile",

                            "threshold","$threshold",

                            "volume","$volume",

                            "quota-target","$uid",

                            "qtree","" );

          if ($out->results_status() eq "failed")

         {

           $out = $s->invoke( "quota-modify-entry",

                              "disk-limit","$disklimit",

                              "file-limit","$filelimit",

                              "quota-type","user",

                              "soft-disk-limit","$softdisk",

                              "soft-file-limit","$softfile",

                              "threshold","$threshold",

                              "volume","$volume",

                              "quota-target","$uid",

                              "qtree","" );

           if ($out->results_status() eq "failed")

           {

                 print($out->results_reason());

                 print("\n");

                 return 2;

           }

         }

          return 0;

}

  sub resize_quota() {

          my $s = NaServer->new ($filer, 1, 3);

         my $response = $s->set_style(LOGIN);

         if (ref ($response) eq "NaElement" && $response->results_errno != 0)

         {

                 my $r = $response->results_reason();

                 print "Unable to set authentication style $r\n";

                 return 2;

         }

         $s->set_admin_user($user, $pw);

         $response = $s->set_transport_type(HTTPS);

         if (ref ($response) eq "NaElement" && $response->results_errno != 0)

         {

                 my $r = $response->results_reason();

                 print "Unable to set transport type $r\n";

                 return 2;

         }

         $response = $s->set_port(443);

         if (ref ($response) eq "NaElement" && $response->results_errno != 0)

         {

                 my $r = $response->results_reason();

                 print "Unable to set port to 443$r\n";

                 return 2;

         }

          $out = $s->invoke("quota-resize",

                           "volume","$volume");

          if ($out->results_status() eq "failed")

         {

           print($out->results_reason());

           print("\n");

           return 2;

         }

  return 0;

}