Archive for the ‘7-Mode’ Category.

Replicate igroup Information from Old Controller to New (7-Mode)

As much as I would like to exclusively be working with Clustered Data ONTAP, there are still times where I need to work with 7-Mode. As many storage admin and consultants know, hardware refreshes can be quite time consuming. This is a quick and dirty script I wrote to save some time recreating Initiator Groups on a new 7-Mode storage system. Modify the first two lines with the source and target controllers and go. The script isn’t very complex, but it sure can save a ton of time.


$SourceController = "sourceIPHostname"
$TargetController = "targetIPHostname"

Connect-NaController $SourceController

$Igroups = Get-NaIgroup

Connect-NaController $TargetController

$Igroups | New-NaIgroup

ForEach($Igroup in $Igroups) {
	$Initiators = $Igroup.Initiators
	ForEach($Initiator in $Initiators) {
		Add-NaIgroupInitiator $Igroup $Initiator
	}
}

List all Volumes on all Controllers (7-Mode)

Volumes: The flexible storage containers of Data ONTAP. They can be resized, deduplicated, compressed, and even FlexCloned. But first, let’s just see which ones we have.

Several PowerShell one-liners will require a text file that I will refer to as NaList.txt. This file is simply a list of all the NetApp controllers in your environment, one per line:


PS C:\Scripts> Get-Content NaList.txt
netapp1
netapp2

Finally, the code:


Get-Content NaList.txt | ForEach-Object {Connect-NaController $_; Get-NaVol | Format-Table}

Now, the output:


Name                 Address           Ontapi   Version
----                 -------           ------   -------
netapp1              192.168.150.98    1.14     NetApp Release 7.3.6: Thu Jul  7 02:02:45 PDT 2011

Name                      State       TotalSize  Used  Available Dedupe  FilesUsed FilesTotal Aggregate
----                      -----       ---------  ----  --------- ------  --------- ---------- ---------
backup                    online        80.0 GB   24%    60.6 GB False         102         3M aggr0
vol0                      online         8.8 GB   15%     7.5 GB False         11k         7M aggr0

Name                 Address           Ontapi   Version
----                 -------           ------   -------
netapp2              192.168.150.99    1.14     NetApp Release 7.3.6: Thu Jul  7 02:02:45 PDT 2011

Name                      State       TotalSize  Used  Available Dedupe  FilesUsed FilesTotal Aggregate
----                      -----       ---------  ----  --------- ------  --------- ---------- ---------
vol0                      online         8.8 GB   15%     7.5 GB False         11k         7M aggr0

Now let’s make the code as short as possible by removing unnecessary spaces and utilizing PowerShell’s built in command aliases:


gc NaList.txt|ForEach{Connect-NaController $_;Get-NaVol|ft}

My attempt to explain the command in plain english: Get-Content (gc) reads the contents from NaList.txt and then pipes each line (controller) as an object to the ForEach-Object (foreach) command. Then for each object (controller) we issue Connect-NaController $_ ($_ represents the current object) and then issue the Get-NaVol command and finally pipe that output to the Format-Table (ft) function in order to get the nice easy to read tabular layout.

That’s it. Now you have a simple way to get a master list of every volume in your NetApp environment.

Questions? Comments? Do you think this could be done better? with less code? Let me know in the comments, please!

List all Snapshots and Export to CSV (7-Mode)

Inspired by this post written by Yann Bizeul (@ybontap), I decided to provide an example of the NetApp PowerShell Toolkit command required to get the equivalent output.

The goal of Yann’s exercise was to gather a list of snapshots and format them in a way that was easy to cut and paste into an Excel spreadsheet.

First a look at Yann’s shell command:


ssh root@10.78.3.1 snap list -n|tr -d '\r' | sed -n -E '{/^Volume /{N;N;N;s/\n/ /g;s/.*Volume ([^ ]*).*/\1/;h;};/^---/,/^$/{/^---/d;/^$/d;G;s/(.*) (..:..)  (.*)\n(.*)/\4      \1      \2      \3/g;p;};}'

The NetApp PowerShell equivalent exported to a CSV file:


PS C:\Scripts> Connect-NaController netapp01; Get-NaVol | Get-NaSnapshot | Select-Object TargetName,Created,Name | Export-CSV -Path outfile.csv

Yann’s command works great and is very useful if you have access to a *nix shell and you are proficient in sed. However, I think it is clear how much effort could be saved by taking advantage of the NetApp PowerShell Toolkit.

Finally, I would like to thank Yann for his imformative post and I encourage you to check out his blog for more great NetApp info: YB Ontap

NetApp PowerShell Toolkit: Getting Started

Welcome! I am in the process of learning PowerShell and more specifically the NetApp PowerShell Toolkit. I’ll post one-liners, simple scripts, tips, and resources I discover along the way. If you are a NetApp storage administrator and you haven’t taken the NetApp PowerShell Toolkit for a spin yet, I highly recommend you do so. The PowerShell language combined with the Data ONTAP API is a powerful tool that can be used to document, manipulate and even automate your storage environment.

Getting setup with NetApp’s PowerShell Toolkit is very simple. More info can be found here. You will need to login to download the DataONTAP.msi installer.

Once you get the toolkit installed properly, you should be able to type “Get-NaHelp” to see a list of NetApp commandlets.

The first few lines of the Get-NaHelp command should look something like this:


PS C:\Scripts> Get-NaHelp

Name                                Category        Api
----                                --------        ---
Add-NaAggr                          aggr            {aggr-add}
Add-NaCifsShare                     cifs            {cifs-share-add}
Add-NaCredential                    toolkit
Add-NaFpolicyExtension              fpolicy         {fpolicy-extensions}
...

All of the NetApp commandlets are in the format “Verb-NaNoun” for 7-Mode and “Verb-NcNoun” for Clustered ONTAP.

To get help with a specific commandlet use the standard Microsoft “Get-Help” commandlet followed by the NetApp commandlet:


PS C:\Scripts> Get-Help Get-NaVol

NAME
    Get-NaVol

SYNOPSIS
    Get volume status.

SYNTAX
    Get-NaVol [[-Names] <String[]>] [-Aggregate <String>] [-Terse] [-Controller <NaController>] [<CommonParameters>]

DESCRIPTION
    Get volume status.  Note that all RAID-related status items (e.g., 'raid-size', 'raid-status', 'checksum-style')
    reported for a flexible volume actually describe the state of its containing aggregate.

RELATED LINKS

REMARKS
    To see the examples, type: "get-help Get-NaVol -examples".
    For more information, type: "get-help Get-NaVol -detailed".
    For technical information, type: "get-help Get-NaVol -full".

Most of the commandlets require you to first connect to a NetApp controller using the “Connect-NaController” commandlet:


PS C:\Scripts> Connect-NaController 192.168.150.98

Name                 Address           Ontapi   Version
----                 -------           ------   -------
netapp1              192.168.150.98    1.14     NetApp Release 7.3.6: Thu Jul  7 02:02:45 PDT 2011

Hopefully that is enough info to get you started if you are completely new to the NetApp Toolkit. If not, feel free to ask for help in the comments or on the NetApp Communities website.

Subscribe via RSS or follow me on Twitter (@seanluce) for updates.

Happy Scripting!