Software Development Kit (SDK) and API Discussions

How to read "quota-user-name" out of "quota-report" via API?

martinafruth
4,018 Views

Hi there

I want to create an interface for my Windows admins to see actual quota usage on the filer. I managed to get an output via invoking "quota-report", but I'm unable to read the value of "quota-user-name" out of my "quota-report".

Code is (Perl):

*** snip ***

                my $quota_info = $out->child_get("quotas");
                my @result = $quota_info->children_get();
                foreach $quota (@result) {
                        my $quota_username = $quota->child_get_string("quota-user-name");
                        my $quota_limit = $quota->child_get_int("disk-limit");
                        my $quota_used = $quota->child_get_int("disk-used");
                        print ("Quota: $quota_username: $quota_limit (Limit), $quota_used (Used)\n");
                }

*** snap ***

$quota_username is always empty, but in some cases there is a value there:

*** snip ***

  <quota>
   <quota-type>user</quota-type>
   <quota-target></quota-target>
   <volume>vol1</volume>
   <tree></tree>
   <disk-used>216</disk-used>
   <disk-limit>-</disk-limit>
   <soft-disk-limit>-</soft-disk-limit>
   <threshold>-</threshold>
   <files-used>64</files-used>
   <file-limit>-</file-limit>
   <soft-file-limit>-</soft-file-limit>
   <vfiler>nalh01</vfiler>
   <quota-users>
    <quota-user>
     <quota-user-type>sid</quota-user-type>
     <quota-user-id>S-1-5-32-544</quota-user-id>
     <quota-user-name>BUILTIN\Administrators</quota-user-name>
    </quota-user>
   </quota-users>
  </quota>

*** snap ***

Does someone has a clue how to get the value "BUILTIN\Administrators" out of my quota-report? I guess, it's pretty simple ...

Thanks in advance.

3 REPLIES 3

michalburda
4,018 Views

little grave digging but better late than never

reason is quite simple - lack of info in SDK - I had hit the same wall when I was writing some tools for quota  beeing feed up with Ontap WebGUI 😕

reason is: quota-users is only populated then you have user with default quota applied 

when in etc/quotas you have entry then user quota-user is empty but instead quota-target contains user to whom you had entered specfic quota

and it is not the end ...of fun

I don't know that weed SDK developers smoke - but to access quota-users data you have to iterate not to child but to child of the child (I really cant think a reason why it is done this manner)

sorry for C# but it should be clear enough

        

if (quoInfo.GetChildByName("quota-target") != null)

     {

     if (quoInfo.GetChildByName("quota-users") != null)

              {

                 NaElement targetElem = quoInfo.GetChildByName("quota-users");

                 System.Collections.IList users = targetElem.GetChildren();

                 System.Collections.IEnumerator usersIter = users.GetEnumerator();

                 while (usersIter.MoveNext())

                          {

                             NaElement usersInfo = (NaElement)usersIter.Current;

               if (usersInfo.GetChildByName("quota-user-name") != null)

                                {

                    Console.Write(usersInfo.GetChildContent("quota-user-name") + "\t");

                                }

                          }

             }

     }

Hope it helps someone

NIGOSHIKE
4,018 Views

Is there a way I can have the above snippet in Python. The following is what I have:

output = s.invoke("quota-report")

quotalist = output.child_get("quotas").children_get()

for q in quotalist:

     print q.child_get_string("disk-limit")

     print q.child_get_string("quota-type") --> "user"

     print "Target", q.child_get_string("quota-target") --> "this is blank for all the listings"

    

     # Tried the following:

     u = NaElement ("quota-user")

     u.child_add("quota-user-name")

     print q.child_get(u) --> "None"

From what I see the quota-target should not be "null" but the api is throwing the target as "null"

Any help here will be appreciated.

zulanch
4,018 Views

I don't see anything wrong with the way you're trying to access quota-target, so it's likely that quota-target is being returned blank from the API call. You can see the raw results of the API like this to verify:

print(quotalist.sprintf())

The documentation for quota-target notes:

For an explicit quota, this value is a fully qualified quota target which is the quota target specified in the /etc/quotas file and the domain in the QUOTA_TARGET_DOMAIN directive is in effect. See na_quotas(5) for more information. Mulitple targets are comma separated. For a derived quota, the field is blank.

Are your quotas derived rather than explicit? That would explain them being blank.

-Ben

Public