Tuesday, June 5, 2018

Powershell - move ontap cluster lifs between interfacegroups

For a headswap procedure, I had to move lifs from 3 interface groups to 2 interface groups.

So before we had :
a0a, a0b & a0c

After we have :
a0a, a0b

This means all lifs on a0c need to move to a similar vlan port on another interface group.  here is a powershell script to do it automatically

$cluster = ""
$pass = "Netapp123"
$user = "admin"
$from_port = "a0c"
$to_port = "a0b"

function getcred($u,$p){
    $secpasswd = ConvertTo-SecureString $p -AsPlainText -Force
    return New-Object System.Management.Automation.PSCredential ($u, $secpasswd)

Connect-NcController $cluster -Credential (getcred $user $pass)

$template = Get-NcNetInterface -Template
$template.HomePort = "$from_port-*"

$lifs = Get-NcNetInterface -Query $template
foreach($l in $lifs){
    $homenode = $l.homenode
    $name = $l.interfacename
    $vserver = $l.Vserver
    if($l.homeport -match "$from_port-(.*)"){
        $vlan = $Matches[1]
    $destport = "{0}-{1}" -f $to_port,$vlan
    write-host -ForegroundColor magenta $l.interfacename -NoNewline
    write-host -ForegroundColor cyan " [vlan=$vlan ; node=$homenode]" -NoNewline
    write-host -ForegroundColor white " --> $destport" -NoNewline

    if(Get-NcNetPort -Name $destport -Node $homenode){
        write-host -ForegroundColor green " : destination port exists"
        Move-NcNetInterface -Name $name -Vserver $vserver -SourceNode $homenode -DestinationNode $homenode -DestinationPort $destport -Confirm:$false
        write-host -ForegroundColor red " : destination port not exists"

No comments :

Post a Comment