NetApp Community Update
This site will enter Read Only mode on July 23 as we prepare to move to a new platform. You will still be able to view content, but posting and replying will be temporarily disabled.
We're excited to launch our new Community experience on July 30 and more information will follow soon.
Stay connected during the transition - Join our Discord community today.

ONTAP Discussions

Setting Quotas with perl

GOMJABBAR
5,222 Views

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

3 REPLIES 3

kunalm
5,222 Views

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

mike_burris
5,222 Views

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.

heikokrupp
5,222 Views

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;

}

Public