The functions below
include applying an export-policy to a volume, to a qtree, to every qtree in a
volume, creating the export-policy...
FUNCTION
Apply-VolExportPol {
Param([String]$VOLNAME,[String]$EXPPOL,[String]$SVMNAME)
$a = Get-NcVol -Template
$q = Get-NcVol -Template
Initialize-NcObjectProperty $a
VolumeExportAttributes
Initialize-NcObjectProperty $q
VolumeIdAttributes
$a.VolumeExportAttributes.Policy = $EXPPOL
$q.VolumeIdAttributes.Name = $VOLNAME
$q.VolumeIdAttributes.OwningVserverName =
$SVMNAME
[Void](Update-NcVol -Attributes $a -Query $q)
$a.VolumeExportAttributes.Policy =
""
IF((Get-NcVol -Name $VOLNAME -Attributes $a
-VserverContext $SVMNAME).VolumeExportAttributes.Policy -eq $EXPPOL){ RETURN
$TRUE }
ELSE{ RETURN $FALSE }
}
FUNCTION
Check-ApplyVolExpPol {
Param([String]$VOLNAME,[String]$EXPPOL,[String]$SVMNAME,[String]$LOGFILE)
[Boolean]$Check = Apply-VolExportPol $VOLNAME
$EXPPOL $SVMNAME
IF($Check){ Wr ("Applied export policy
$EXPPOL to volume $VOLNAME") GREEN; Wr }
ELSE{ Wr ("FAILED to apply export policy
$EXPPOL to volume $VOLNAME") RED -Log $LOGFILE; Wr }
}
FUNCTION
Apply-ExportPolToQtree {
Param([String]$VOLNAME,[String]$QTREENAME,[String]$EXPPOL,[String]$SVMNAME)
[Void](Set-NcQtree -Volume $VOLNAME -qtree
$QTREENAME -VserverContext $SVMNAME -ExportPolicy $EXPPOL)
$a = Get-NcQtree -Template
$a.ExportPolicy = ""
IF((Get-NcQtree -Qtree $QTREENAME
-VserverContext $SVMNAME -Attributes $a).ExportPolicy -eq $EXPPOL){ RETURN
$TRUE }
ELSE{ RETURN $FALSE }
}
FUNCTION
Check-QtreeExportPol {
Param([String]$VOLNAME,[String]$QTREENAME,[String]$EXPPOL,[String]$SVMNAME,[String]$LOGFILE)
[Boolean]$Check = Apply-ExportPolToQtree
"$VOLNAME" "$QTREENAME" "$EXPPOL"
"$SVMNAME"
IF($Check){ Wr ("Applied export policy
$EXPPOL to qtree $QTREENAME on volume $VOLNAME") GREEN; Wr }
ELSE{ Wr ("FAILED to apply export policy
$EXPPOL to qtree $QTREENAME on volume $VOLNAME") RED -Log $LOGFILE;Wr }
}
FUNCTION
Check-ApplyExpPolToAllQtreesInVol {
Param([String]$VOLNAME,[String]$EXPPOL,[String]$SVMNAME,[String]$LOGFILE)
$a = Get-NcQtree -Template
$a.Qtree = ""
(Get-NcQtree -Volume $VOLNAME -VserverContext
$SVMNAME).Qtree | Foreach {
If($_){ [Void](Check-QtreeExportPol
"$VOLNAME" "$_" "$EXPPOL" "$SVMNAME"
"$LOGFILE") }
}
}
FUNCTION
Create-ExportPolicy{
Param([String]$EXPPOL,[String]$SVMNAME)
[Void](New-NcExportPolicy -Name $EXPPOL
-VserverContext $SVMNAME)
If(Get-NcExportPolicy -Name $EXPPOL
-VserverContext $SVMNAME){ RETURN $TRUE }
ELSE{ RETURN $FALSE }
}
FUNCTION
Check-CreateExportPol{
Param([String]$EXPPOL,[String]$SVMNAME,[String]$LOGFILE)
[Boolean]$Check = Create-ExportPolicy
"$EXPPOL" "$SVMNAME"
IF($Check){ Wr ("Created Export Policy
$EXPPOL") GREEN; Wr }
ELSE{ Wr ("FAILED to create export
policy $EXPPOL") RED -Log $LOGFILE; Wr}
}
FUNCTION
Check-ExportRuleCreate{
Param([String]$EXPPOL,$Index,[String]$SVMNAME,[String]$LOGFILE)
$a = Get-NcExportRule -Template
IF(Get-NcExportRule -Policy
"$EXPPOL" -Index $INDEX -Attributes $a -VserverContext
"$SVMNAME"){
Wr ("Ruleindex " + [String]$INDEX
+ " created in export-policy $EXPPOL") GREEN; Wr
} ELSE {
Wr ("FAILED to create ruleindex "
+ [String]$INDEX + " in export-policy $EXPPOL") RED -Log $LOGFILE; Wr
}
}
FUNCTION
Wr {
Param([String]$ToDisplay,[String]$Color =
"WHITE",[String]$Log)
If($ToDisplay){ Write-Host $ToDisplay
-ForegroundColor $Color -NoNewLine } else { Write-Host }
If($Log){ $ToDisplay >> $Log }
}
Comments
Post a Comment