Go to main content
Oracle® ZFS Storage Appliance 管理ガイド、Release OS8.7.0

印刷ビューの終了

更新: 2017 年 3 月
 
 

list 関数の使用

動的な子が存在するコンテキストでは、これらの子をプログラムから繰り返し処理すると非常に有効です。これを行うには、動的な子の配列を返す list 関数を使用します。

  1. たとえば、次のスクリプト例は、すべてのプロジェクト内のすべてのシェアを繰り返し処理し、消費されている領域と空き領域を出力します。
    script
           run('shares');
           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]);
                           printf("%s/%s %1.64g %1.64g\n", projects[i], shares[j],
                               get('space_data'), get('space_available'));
                           run('cd ..');
                   }
    
                   run('cd ..');
           }
  2. このスクリプトが「space.aksh」という名前のファイルに保存されたと仮定して、スクリプトを実行した出力を次に示します。
    % ssh root@koi < space.aksh
    Password: 
    admin/accounts 18432 266617007104
    admin/exports 18432 266617007104
    admin/primary 18432 266617007104
    admin/traffic 18432 266617007104
    admin/workflow 18432 266617007104
    aleventhal/hw_eng 18432 266617007104
    bcantrill/analytx 1073964032 266617007104
    bgregg/dashbd 18432 266617007104
    bgregg/filesys01 26112 107374156288
    bpijewski/access_ctrl 18432 266617007104
    ...
  3. この結果の「きれいに出力された」バージョン (ただし、プログラムの処理はより困難になる) が必要な場合は、get コマンドの出力を直接解析することもできます。
    script
           run('shares');
           projects = list();
    
           printf('%-40s %-10s %-10s\n', 'SHARE', 'USED', 'AVAILABLE');
    
           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 = projects[i] + '/' + shares[j];
                           used = run('get space_data').split(/\s+/)[3];
                           avail = run('get space_available').split(/\s+/)[3];
    
                           printf('%-40s %-10s %-10s\n', share, used, avail);
                           run('cd ..');
                   }
    
                   run('cd ..');
           }
  4. このスクリプトが「prettyspace.aksh」という名前であると仮定して、この新しいスクリプトを実行した出力を次に示します。
    % ssh root@koi < prettyspace.aksh
    Password:
    SHARE                                    USED       AVAILABLE 
    admin/accounts                           18K        248G      
    admin/exports                            18K        248G      
    admin/primary                            18K        248G      
    admin/traffic                            18K        248G      
    admin/workflow                           18K        248G      
    aleventhal/hw_eng                        18K        248G      
    bcantrill/analytx                        1.00G      248G      
    bgregg/dashbd                            18K        248G       
    bgregg/filesys01                         25.5K      100G      
    bpijewski/access_ctrl                    18K        248G      
    ...
  5. list 関数は、オプション引数 depth および filter をサポートします。

    形式は、list ([depth, [filter]]) です。引数 depth は、1 つの数値で定義できます。depth の数値を大きくすると、より詳細な出力が返されます。引数 filter の形式は、{<prop1>:<val1>, <prop2>:<val2> ...} です。filter を指定する場合は、depth も指定する必要があります。

    使用方法と入力の動作:

    • list() - ノード名のみを返します。

    • list(0) - ノードのプロパティーと子の名前のみ返します。

    • list(0, {kiosk_mode: true}) - kiosk_modetrue の場合のフィルタ済みリストと子の名前を返します。

    • list(1) - ノードのプロパティー、子の名前とプロパティー、孫の名前のみ返します。

    • list(1, {kiosk_mode: true}) - kiosk_modetrue の場合のフィルタ済みリストと depth=1 までの詳細を返します。

    • list(2) - ノードのプロパティー、子の名前とプロパティー、孫の list(0) 出力を返します。

    • list(2, {fullname:'Super*', kiosk_mode: true}) - fullnameSuper を含み、kiosk_modetrue の場合のフィルタ済みリストと、depth=2 までの詳細を返します。

  6. これは depth=2 のときのリストの出力例です。

    ラベル name はリスト項目 (すなわちノード) の名前を示します。ラベル properties はリスト項目のプロパティーを示します。ラベル children はリスト項目の静的な子を示します。ラベル list はリスト項目の動的な子を示します。

    script
            ("." to run)> dump(list(2));
            ("." to run)> .
    
            [{
                name: 'restuser',
                properties: {
                    kiosk_screen: 'status/dashboard',
                    kiosk_mode: false,
                    roles: ['basic'],
                    require_annotation: false,
                    initial_password: 'DummyPassword',
                    fullname: 'REST User',
                    logname: 'restuser'
                },
                children: [{
                    name: 'preferences',
                    properties: {
                        advanced_analytics: false,
                        session_timeout: 15,
                        login_screen: 'status/dashboard',
                        locale: 'C'
                    }
                }, {
                    name: 'exceptions',
                    list: [{
                        name: 'auth-000',
                        properties: {
                             allow_configure: false,
                             scope: 'alert'
                        }
                    }, {
                        name: 'auth-001',
                        properties: {
                             allow_workgroup: false,
                             allow_domain: false,
                             name: '*',
                             scope: 'ad'
                        } 
                    }]
                }]
            }]