Virtualization Articles and Resources

Automate Creation of New V-Servers with Powershell with ls mirrors

I have been working on some scripts to allow the rapid creation of vservers where we can also create ls mirrors on all nodes.

Here is what I have come up with so far.

I have set this up using a text file with one or more vservers to create first line is required.

name,RootVolumeSecurityStyle,rootvolumeaggregate,NameServerSwitch,NameMappingSwitch,Language,Create_ls

vs01_vmware_de,ntfs,n1_aggr1,file,file,en_us.utf_8,true

vs02_nfs_de,ntfs,n2_aggr2,file,file,en_us.utf_8,true

# The script assumes import-module dataontap ; connect-nccontroller mycluster

$vservers = import-csv vservers.csv

$vservers | foreach {

new-ncvserver -name $_.name -RootVolume $($_.name+"_root") -RootVolumeAggregate $_.rootvolumeaggregate -NameServerSwitch $_.NameServerSwitch -RootVolumeSecurityStyle $_.RootVolumeSecurityStyle -NameMappingSwitch $_.NameMappingSwitch -Language $_.Language

}

#Query the Cluster and look for aggr1 to add the ls mirror to that aggreagate

$q = Get-NcAggr -Template

$q.Name = "*aggr1*"

#Loop through the vservers

#Loop through the aggregates queried

#Append _ls to the Name of the root volume

#remove dashes in the name

# I static set the volume size to 100m

$vservers | foreach {

if ($_.Create_ls -eq $true){

foreach ($ag in (Get-NcAggr -Query $q).name){

$lsvs = $_.name + "_" + (Get-NcAggr $ag).nodes.replace("-","_") + "_LS"

new-ncvol -Name $lsvs -Size 100m -Type dp -Aggregate $ag  -JunctionPath $null -VserverContext $_.name | out-null

New-NcSnapmirror -Source ("//" + $_.name + "/" + $($_.name+"_root")) -Destination ("//" + $_.name + "/" + $lsvs-Type LS |Set-NcSnapmirror -Schedule 5min |out-null

}

# After all mirrors have been added initialize the mirrors

Invoke-NcSnapmirrorLsInitialize ("//" + $_.name + "/" + $($_.name+"_root"))

}}

Enjoy,

John

Please Note:

All content posted on the NetApp Community is publicly searchable and viewable. Participation in the NetApp Community is voluntary.

In accordance with our Code of Conduct and Community Terms of Use, DO NOT post or attach the following:

  • Software files (compressed or uncompressed)
  • Files that require an End User License Agreement (EULA)
  • Confidential information
  • Personal data you do not want publicly available
  • Another’s personally identifiable information (PII)
  • Copyrighted materials without the permission of the copyright owner

Continued non-compliance may result in NetApp Community account restrictions or termination.

All Community Forums