Go to main content
Oracle® ZFS Storage Appliance Administration Guide, Release OS8.7.0

Exit Print View

Updated: July 2017
 
 

Using the Choices Function

The choices function returns an array of the valid property values for any property for which the set of values is known and enumerable. For example, the following script retrieves the list of all pools on the shares node using the choices function and then iterates all pools to list projects and shares along with the available space.

  1. For example, the following script retrieves the list of all pools on the shares node using the choices function and then iterates all pools to list projects and shares along with the available space.
    fmt = '%-40s %-15s %-15s\n';
    printf(fmt, 'SHARE', 'USED', 'AVAILABLE');
    run('cd /');
    run('shares');
    pools = choices('pool');
    for (p = 0; p < pools.length; p++) {
            set('pool', pools[p]);
            projects = list();
            for (i = 0; i < projects.length; i++) {
                    run('select ' + projects[i]);
                    shares = list();
                    for (j = 0; j < shares.length; j++) {
                            run('select ' + shares[j]);
                            share = pools[p] + ':' + projects[i] + '/' + shares[j];
                            printf(fmt, share, get('space_data'),
                                get('space_available'));
                            run('cd ..');
                    }
                    run('cd ..');
            }
    }
  2. Here is the output of running the script:
    SHARE                                    USED            AVAILABLE     
    pond:projectA/fs1                        31744           566196178944  
    pond:projectA/fs2                        31744           566196178944  
    pond:projectB/lun1                       21474836480     587670999040  
    puddle:deptA/share1                      238475          467539219283
    puddle:deptB/share1                      129564          467539219283
    puddle:deptB/share2                      19283747        467539219283