Go to main content

Oracle® ZFS Storage Appliance 관리 설명서, 릴리스 OS8.8.x

인쇄 보기 종료

업데이트 날짜: 2021년 8월
 
 

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@hostname < 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@hostname < 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 함수는 선택적 인수 depthfilter를 지원합니다.

    형식은 list ([depth, [filter]])입니다. depth 인수는 숫자로 정의할 수 있습니다. depth 숫자가 클수록 더 많은 세부정보가 반환됩니다. filter 인수의 형식은 {<prop1>:<val1>, <prop2>:<val2> ...}입니다. filter가 지정된 경우 depth도 지정해야 합니다.

    사용법 및 입력 동작:

    • list() - 노드 이름만 반환합니다.

    • list(0) - 노드의 등록 정보 및 하위 항목 이름만 반환합니다.

    • list(0, {kiosk_mode: true}) - kiosk_mode=true의 필터링된 목록을 하위 항목의 이름과 함께 반환합니다.

    • list(1) - 노드의 등록 정보, 하위 항목의 이름 및 등록 정보, 2차 하위 항목은 이름만 반환합니다.

    • list(1, {kiosk_mode: true}) - kiosk_mode=true의 필터링된 목록을 최대 depth=1까지의 세부정보와 함께 반환합니다.

    • list(2) - 노드의 등록 정보, 하위 항목의 이름 및 등록 정보, 2차 하위 항목의 list(0) 출력을 반환합니다.

    • list(2, {fullname:'Super*', kiosk_mode: true}) - Super를 포함하는 fullname, kiosk_mode=true의 필터링된 목록을 최대 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'
                        } 
                    }]
                }]
            }]