Creating tools for NetApp Storage – Provisioning volumes

Creating tools for NetApp Storage – Provisioning volumes

Provisioning storage from any storage vendor often requires several configuration steps before it is accessible by the intended host.
With NetApp this could be automated with NetApp´s PowerShell cmdlets.

With NetApp, NAS-Volumes are the most common volumes to create. So to automate this I have created a provisioning function that creates a volume with the desired properties and makes it available to share with the correct type of permission sets.

To use the function NetApp´s Data ONTAP PowerShell Toolkit is required. The toolkit contains cmdlets for both the 7-mode and the cluster mode Data ONTAP OS.
By using the cmdlets: New-NaVol, Set-NaVolOption, Set-NaQtree, Enable-NaSis, I have created a function to create Volumes with customizable options. The resulting volume object could then be piped to another function that presents the volume as a share or to a vfiler.
With the correct tools a volume could be create, presented to a host and then provision with the right permission sets in one wrapper-script.

<# .Synopsis   Creates a new CIFS or NFS volym .DESCRIPTION Creates a new volume for CIFS or NFS shares. It is possible to select aggregate, thin/thick, size and file system/protocol. .EXAMPLE New-NASVolume -Name TestVolume -Aggregate aggr1 -Type Thin -Size 5TB -Protocol ntfs This command creates a new volume with the name TestVolume on aggregate aggr1 with thin provisoning, the size of 5TB and NTFS support. .NOTES    CMDleten requires a connected session to a controller. .FUNCTIONALITY    Creating volumes .PARAMETER Name Name of the volume .PARAMETER Type Thin or thick provisioning .PARAMETER Aggregate Aggregate for the new volume .PARAMETER Size Size of the volume in MB,GB,TB. Ex: 50GB for 50 gibabyte. .PARAMETER Protocol Sets the security style for the volume. Unix or Windows. NTFS is default. #>
Function New-NASVolume {
    [CmdletBinding(DefaultParameterSetName='Default Set', 
                  SupportsShouldProcess=$true, 
                  PositionalBinding=$false,
                  ConfirmImpact='Medium')]
    [OutputType([String])]
    Param
    (
        [Parameter(Mandatory=$true, 
                   ValueFromPipeline=$true,
                   ValueFromPipelineByPropertyName=$true, 
                   ValueFromRemainingArguments=$false, 
                   Position=0
                   )]  
        [Alias("VolumeName")]
        [String]
        $Name,
        
         [Parameter(Mandatory=$false, 
                   ValueFromPipeline=$true,
                   ValueFromPipelineByPropertyName=$true, 
                   Position=1
                   )] 
        [ValidateSet("Thin", "Thick")]
        $Type = "none",

        [Parameter(Mandatory=$True, 
                   ValueFromPipeline=$true,
                   ValueFromPipelineByPropertyName=$true, 
                   Position=2
                   )] 
        [ValidateSet("aggr1", "aggr2","aggr3","aggr4")]
        $Aggregate,

        [Parameter(Mandatory=$True, 
                   ValueFromPipeline=$true,
                   ValueFromPipelineByPropertyName=$true, 
                   Position=3
                   )]
        [String]
        $Size, 

        [Parameter(Mandatory=$False, 
                   ValueFromPipeline=$true,
                   ValueFromPipelineByPropertyName=$true, 
                   Position=4
                   )]
        [ValidateSet("ntfs", "unix")]
        $Protocol="ntfs",  

        [Parameter(Mandatory=$False, 
                   ValueFromPipeline=$true,
                   ValueFromPipelineByPropertyName=$true, 
                   Position=5
                   )]
        [ValidateSet("true", "false")]
        $Dedup="true"
    )
    
    Begin
    {
    
    }
    
    Process
    {
       
        if  ($Type -eq "Thick"){
        $Typevalue = "volume"
     
        }
        else { 
            $Typevalue = "none"
        }
     
       Write-Verbose "Volume type is $Typevalue"
      
       $calcsize = ($Size / 1GB)
       
        if ($pscmdlet.ShouldProcess("$Aggregate with name $Name", "Creating a volume with the $calcsize GB on $global:CurrentNaController"))
        {

            $NewVol= New-NaVol -Name $Name -Aggregate $Aggregate -Size $Size -SpaceReserve $Typevalue -Confirm:$false
        
            Set-NaVolOption -Name $Name -Key create_ucode -Value on -Confirm:$false | Out-Null
            Set-NaVolOption -Name $Name -Key convert_ucode -Value on  -Confirm:$false| Out-Null
            Set-NaVolOption -Name $Name -Key fractional_reserve -Value 0 -Confirm:$false | Out-Null
            Set-NaVolOption -Name $Name -Key no_atime_update -Value on  -Confirm:$false | Out-Null

            Write-Verbose "Volume $NewVol.Name have been created"

            Get-NaQtree $Name | Set-NaQtree -SecurityStyle $Protocol -Confirm:$false

            if ($Dedup -eq "true") {
                $NewVol.name | Enable-NaSis
                Write-Verbose "Deduplication has been enabled"          
        
            }

         }#End if
    }#End process

    End
    {
    }
}



Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *