Monday, 13 October 2014

SVM-CreatorX4.ps1

After posting a script to dismantle lab SVMs, it’s only right that my next post is a script to build SVMs!

This script builds up a lab of 4 SVMs, with LIF, DNS, CIFS, NFS, and Vserver Peering. It’s probably a pretty unique lab setup requirement, but nicely demonstrates the constructive power of the Data ONTAP PowerShell toolkit. As always with scripts like these, you’re left thinking there’s so much more potential - like having an Excel Spreadsheet that the script can read to automate and standardize the construction for any requirement - alas that’s going to have to be for another day.

The Script

Note: I’ve formatted this especially to display better in blogger by removing tab indentations.

"";"<<<<< Multi-SVM Creator: 2 Prod SVMs (Data + SV), 2 DR SVMs (Data + SV) >>>>>";""
"This program connects to 4 Clusters:"
"Cluster 1 = Site A (Prod) Data Serving Cluster"
"Cluster 2 = Site A (Prod) SnapVault Cluster"
"Cluster 3 = Site B (DR)   Data Serving Cluster"
"Cluster 4 = Site B (DR)   SnapVault Cluster";""
"And creates an SVM in each cluster."
"The Data Serving Clusters have CIFS and NFS enabled SVMs, the SnapVault Clusters have just CIFS."
"Vserver peering is set up from 1 to 2, 1 to 3, 2 to 3, and 3 to 4.";""

Import-Module DataONTAP
$clus = @{}; $temp = @{}; $objects = 1,2,3,4; $object = 0; $number = 0;

"<<<<< PART 1: COLLECT CONFIGURATION DATA >>>>";""

">>>>> STEP 1.1: STORE CREDENTIALS (for Connect-NcController)";""
$temp.1 = Read-Host "Enter Cluster Admin User"
$temp.2 = Read-Host "Enter Cluster Password" -AsSecureString;""

$objects | Foreach {
$clus.$_ = @{}
$clus.$_.name       = Read-Host "Enter Cluster $_ Name"
$clus.$_.username   = $temp.1
$clus.$_.password   = $temp.2
$clus.$_.credential = New-Object System.Management.Automation.PsCredential($clus.$_.username,$clus.$_.password)
};""  

">>>>> STEP 1.2: COLLECT SVM DETAILS (for New-NcVserver)";""
$temp.1 = Read-Host "Enter SVM name suffix to add to Cluster Name (e.g. V1)";""

$objects | Foreach {
$clus.$_.svm = @{}
$clus.$_.svm.Name = $clus.$_.name + $temp.1
$clus.$_.svm.RootVolume              = "rootvol"
$clus.$_.svm.RootVolumeAggregate     = "aggr1"
$clus.$_.svm.RootVolumeSecurityStyle = "ntfs"
$clus.$_.svm.NameServerSwitch        = "file"
$clus.$_.svm.NameMappingSwitch       = "file"
$clus.$_.svm.Language                = "en_US.UTF-8"
$clus.$_.svm.SnapshotPolicy          = "default"
}

">>>>> STEP 1.3: COLLECT LIF DETAILS (for New-NcNetInterface)";""
$objects | Foreach {
Write-Host ($clus.$_.svm.Name + " > LIF1 information:")
$clus.$_.svm.lif = @{}
$clus.$_.svm.lif.Name = "lif1"
$clus.$_.svm.lif.Role = "data"
$clus.$_.svm.lif.Node = $clus.$_.name + "N1"
$clus.$_.svm.lif.Port = "e0c"
$clus.$_.svm.lif.DataProtocols = Read-Host "DataProtocols"
$clus.$_.svm.lif.Address = Read-Host "Address"
$clus.$_.svm.lif.NetMask = Read-Host "Netmask"
$clus.$_.svm.lif.FirewallPolicy = "data";""
}

">>>>> STEP 1.4: COLLECT DNS DETAILS (for New-NcNetDns)";""
$temp.1 = Read-Host "Enter DNS FQDN domains (comma separated)"
$temp.2 = Read-Host "Enter DNS NameServers (comma separated) ";""

$objects | Foreach {
$clus.$_.svm.Domains = $temp.1
$clus.$_.svm.NameServers = $temp.2
}

">>>>> STEP 1.5: COLLECT CIFS SERVER DETAILS (for Add-NcCifsServer)";""
$temp.1 = Read-Host "Enter FQDN of Windows Active Directory"
$temp.2 = Read-Host "Enter Admin Username to connect to AD"
$temp.3 = Read-Host "Enter Admin Password to connect to AD" -AsSecureString
$temp.4 = New-Object System.Management.Automation.PsCredential($temp.2,$temp.3);""

$objects | Foreach {
$clus.$_.svm.cifs = @{}
$clus.$_.svm.cifs.Name = $clus.$_.svm.Name
$clus.$_.svm.cifs.Domain = $temp.1
$clus.$_.svm.cifs.AdminCredential = $temp.4
}

">>>>> STEP 1.6: COLLECT NFS SERVER DETAILS (for Add-NcNfsService)";""
$objects | Foreach {
$clus.$_.svm.nfs = @{}
Write-Host ("Configure NFS server for SVM " + $clus.$_.svm.Name + " on cluster " + $clus.$_.name)
$clus.$_.svm.nfs.AddNcNfsService = (Read-Host "(Y/N)").ToUpper()
<# ENHANCEMENT: Look at Get-NcNfsService Attributes #>
};""

">>>>> STEP 1.7: COLLECT SVM PEERING DETAILS (for New-NcVserverPeer)";""
$objects | Foreach {

Write-Host "NOTE: Vserver peers are bidirectional, only configure one time for each bidirectional pair!"
Write-Host ("How many Vservers peers do you want to configure for for SVM " + $clus.$_.svm.Name + " on cluster " + $clus.$_.name)
$clus.$_.svm.VserverPeers = [Int](Read-Host "(0 for none)")
$temp.Array = @(); $number = 1

while($number -le $clus.$_.svm.VserverPeers){
$temp.Array += $number
$number ++
}

$clus.$_.svm.VserverPeer = @{}

foreach ($number in ($temp.Array)){
$clus.$_.svm.VserverPeer.$number = @{}
$clus.$_.svm.VserverPeer.$number.PeerCluster = Read-Host "PeerCluster"
$clus.$_.svm.VserverPeer.$number.PeerVserver = Read-Host "PeerVserver"
};""

} # END: $objects | Foreach

$temp.1 = $false
while ($temp.1 -ne "Y"){$temp.1 = (Read-Host "Ready to build SVMs (Y/N)").ToUpper()};""

"<<<<< PART 2: CREATE SVM CONFIGURATIONS >>>>";""

">>>>> STEP 2.1: CREATE SVMs (with New-NcVserver)";""
$objects | Foreach {
Connect-NcController $clus.$_.name -Credential $clus.$_.credential
New-NcVserver -Name $clus.$_.svm.Name -RootVolume $clus.$_.svm.RootVolume -RootVolumeAggregate $clus.$_.svm.RootVolumeAggregate -RootVolumeSecurityStyle $clus.$_.svm.RootVolumeSecurityStyle -NameServerSwitch     $clus.$_.svm.NameServerSwitch -NameMappingSwitch $clus.$_.svm.NameMappingSwitch -Language $clus.$_.svm.Language -AntivirusOnAccessPolicy $clus.$_.svm.AntivirusOnAccessPolicy -SnapshotPolicy $clus.$_.svm.SnapshotPolicy
}

">>>>> STEP 2.2: CREATE SVM LIFs(with New-NcNetInterface)";""
$objects | Foreach {
Connect-NcController $clus.$_.name -Credential $clus.$_.credential
$global:currentnccontroller.Vserver = $clus.$_.svm.Name
New-NcNetInterface -Name $clus.$_.svm.lif.Name -Vserver $clus.$_.svm.Name -Role $clus.$_.svm.lif.Role -Node $clus.$_.svm.lif.Node -Port $clus.$_.svm.lif.Port -DataProtocols $clus.$_.svm.lif.DataProtocols -Address $clus.$_.svm.lif.Address -NetMask $clus.$_.svm.lif.NetMask -FirewallPolicy $clus.$_.svm.lif.FirewallPolicy
}

">>>>> STEP 2.3: CONFIGURE SVM DNS (with New-NcNetDns)";""
$objects | Foreach {
Connect-NcController $clus.$_.name -Credential $clus.$_.credential
$global:currentnccontroller.Vserver = $clus.$_.svm.Name
New-NcNetDns -Domains $clus.$_.svm.Domains -NameServers $clus.$_.svm.NameServers
}

">>>>> STEP 2.4: CONFIGURE SVM CIFS SERVER (with Add-NcCifsServer)";""
$objects | Foreach {
Connect-NcController $clus.$_.name -Credential $clus.$_.credential
$global:currentnccontroller.Vserver = $clus.$_.svm.Name
Add-NcCifsServer -Name $clus.$_.svm.Name -Domain $clus.$_.svm.cifs.Domain -AdminCredential $clus.$_.svm.cifs.AdminCredential
}

">>>>> STEP 2.5: CONFIGURE SVM NFS SERVER (with Add-NcNfsService)";""
$objects | Foreach {
Connect-NcController $clus.$_.name -Credential $clus.$_.credential
$global:currentnccontroller.Vserver = $clus.$_.svm.Name
If ($clus.$_.svm.nfs.AddNcNfsService -eq "Y"){Add-NcNfsService}
}

">>>>> STEP 2.6: SVM PEERING (with New-NcVserverPeer)";""
$objects | Foreach {

If ($clus.$_.svm.VserverPeers -ne 0){
$temp.Array = @(); $number = 1

while($number -le $clus.$_.svm.VserverPeers){
$temp.Array += $number
$number ++                 
}

foreach ($number in ($temp.Array)){
Connect-NcController $clus.$_.name -Credential $clus.$_.credential
$global:currentnccontroller.Vserver = $clus.$_.svm.Name      
New-NcVserverPeer -Vserver $clus.$_.svm.Name -PeerCluster $clus.$_.svm.VserverPeer.$number.PeerCluster -PeerVserver   $clus.$_.svm.VserverPeer.$number.PeerVserver -Application snapmirror

foreach ($object in $objects){
If ($clus.$object.name -eq $clus.$_.svm.VserverPeer.$number.PeerCluster){

Connect-NcController $clus.$object.name -Credential $clus.$object.credential
$global:currentnccontroller.Vserver = $clus.$_.svm.VserverPeer.$number.PeerVserver
Confirm-NcVserverPeer -Vserver $clus.$_.svm.VserverPeer.$number.PeerVserver -PeerVserver $clus.$_.svm.Name

} ##### END If ($clus.$object.name -eq $clus.$_.svm.VserverPeer.$number.PeerCluster)
} #### END foreach ($object in $objects)
} ### END foreach ($number in ($temp.Array))
} ## END If ($clus.$_.svm.VserverPeers -ne 0)
} # $objects | Foreach

"Complete!"

## THE END ##

1 comment:

  1. Been here on and off looking for info for a while , and have to say you always deliver , so thank you very much , keep up the good posts.....

    ReplyDelete