NETWORK ENGINEER BLOG

Tips and Reviews for Engineers

Windows PowerShell で NetApp を制御

NetApp を Windows PowerShell により制御する事が可能です。
詳細は NetApp PowerShell Survival Guide をご参照ください。

検証環境

  • Windows Server 2008R2 Datacenter
  • Ontap Data ONTAP 8.1.0 Simulator
  • VMware Workstation 9.0.1 build-894247

手順

PowerShell Library のダウンロード

Now にアクセスし[DataONTAP.ZIP]をダウンロードします。ファイルを展開後、以下に配置します。

C:\Windows\System32\WindowsPowerShell\v1.0\Modules\DataONTAP
実行ポリシーの変更

PowerShell スクリプトの実行ポリシーを変更します。

> Set-ExecutionPolicy RemoteSigned

実行ポリシーの変更
実行ポリシーは、信頼されていないスクリプトからの保護に役立ちます。実行ポリ
のヘルプ トピックで説明されているセキュリティ上の危険にさらされる可能性があ
[Y] はい(Y)  [N] いいえ(N)  [S] 中断(S)  [?] ヘルプ (既定値は "Y"): y
Data ONTAP モジュールのインストール

モジュールファイルをインストールします。

> Import-Module DataOnTap

Data ONTAP モジュールが正常にロードされた事を確認します。

> get-module

ModuleType Name                      ExportedCommands
---------- ----                      ----------------
Manifest   DataOnTap                 {Invoke-NaSnapmirrorThrottle, Resume-NcJob, Get-NaSystemInfo, Add-NaLice...
NetApp の制御

NetApp コントローラーに接続します。

> Connect-NaController 192.168.1.51 -cred root

Name                 Address           Ontapi   Version
----                 -------           ------   -------
192.168.1.51         192.168.1.51      1.17     NetApp Release 8.1.1X34 7-Mode: Thu May 31 21:30:59 PDT 2012

アグリゲートの状態を確認します。

> Get-NaAggr

Name            State       TotalSize  Used  Available Disks RaidType RaidSize MirrorStatus     FilesUsed FilesTotal
----            -----       ---------  ----  --------- ----- -------- -------- ------------     --------- ----------
aggr0           online       900.0 MB   99%     6.2 MB   3   raid_dp     16    unmirrored              96        30k
aggr1           online         2.6 GB    0%     2.6 GB   5   raid_dp     16    unmirrored              96        31k

ボリュームの状態を確認します。

> Get-NaVol

Name                      State       TotalSize  Used  Available Dedupe  FilesUsed FilesTotal Aggregate
----                      -----       ---------  ----  --------- ------  --------- ---------- ---------
vol0                      online       808.9 MB   17%   669.9 MB  True          5k        26k aggr0
vol1                      online       100.0 MB    0%    99.8 MB  True          96         3k aggr1
vol2                      online       100.0 MB    0%    99.8 MB  True          96         3k aggr1

各ボリュームの重複排除効果を確認します。

> get-navolsis | Format-table -autosize

CompressSaved DedupSaved LastOperationBegin           LastOperationEnd             LastOperationError LastOperationSize PercentageSaved PercentCompressSaved PercentDedupSaved PercentTotalSaved
------------- ---------- ------------------           ----------------             ------------------ ----------------- --------------- -------------------- ----------------- -----------------
            0    6926336 Thu Jan 24 14:17:29 JST 2013 Thu Jan 24 14:21:58 JST 2013                            147582976               4                    0                 4                 4
            0          0 Thu Jan 24 15:23:56 JST 2013 Thu Jan 24 15:24:43 JST 2013                                    0               0                    0                 0                 0
            0          0 Thu Jan 24 15:24:00 JST 2013 Thu Jan 24 15:24:56 JST 2013                                    0               0                    0                 0                 0
スクリプトによる自動化

各ボリュームの重複排除効果を出力するスクリプト例になります。

$netapp = "192.168.1.51"
$user = "root"
$pass = "password"

#-------------------------------------------------------------------------
# function Sis-Status
#-------------------------------------------------------------------------
function Sis-Status()
{
   $outfile = "C:\logs\sis_status.log"
   $logdata = "Get-NaSis"
   $logdata | out-file $outfile -append
   Get-Date -Format g >> $outfile
   Get-NaVol | select @{Name="Volume"    ; Exp={$_.name}}, 
                      @{Name="Total(MB)" ; Exp={[math]::Truncate(($_ | Get-NaVol).TotalSize/1MB)}},
                      @{Name="Used(%)"   ; Exp={($_ | Get-NaVol).Used}},
                      @{Name="Avail(MB)" ; Exp={[math]::Truncate(($_ | Get-NaVol).Available/1MB)}},
                      @{Name="Saved(MB)" ; Exp={[math]::Round(($_ | Get-NaVolSis).SizeSaved/1MB,2)}},
                      @{Name="Saved(%)"  ; Exp={($_ | Get-NaVolSis).PercentTotalSaved}} | Format-Table -autosize >> $outfile
   write-output ""`n >> $outfile
}

#-------------------------------------------------------------------------
# Do-Initialize
#-------------------------------------------------------------------------
$password = ConvertTo-SecureString $pass -asplaintext -force
$cred = New-Object System.Management.Automation.PsCredential $user,$password

Import-Module DataOnTap
Connect-NaController $netapp -cred $cred 

#-------------------------------------------------------------------------
# Main Application Logic
#-------------------------------------------------------------------------
Sis-Status

タスクスケジューラに登録する事で、定期的に自動で実行可能です。
プログラム/スクリプトと引数を下記のとおり指定します。

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

-file "C:\scripts\get_sis_status.ps1"

タスクスケジューラの具体的な登録手順については、こちらをご参照頂ければ幸いです。

参考書籍

以上