Active IQ Unified Manager Discussions

Powershell Add-NaNetRoute messing with /etc/rc file

sheelnidhig
4,544 Views

Hello All,

 

I am trying to create a vFiler using WFA and could not find a command to add a default gateway for the vFiler.

 

When i try to create a new command and test's Add-NaNetRoute it is able to able to add the gateway and also make an entry in the /etc/rc file but makes a lots of changed in the file leaving only the network configuration and removing all other options that we set:

 

Before the command was executed the /etc/rc looks like:

 

hostname inblrx900
ifgrp create vif e0b e0c
vlan create vif 1 2 3 4 5 6 7
ifconfig e0a `hostname`-e0a mediatype auto flowcontrol full mtusize 1500
ifconfig e0d 192.168.16.10 netmask 255.255.255.0
ifconfig vif-6 192.168.160.10 netmask 255.255.255.0
ifconfig vif-7 192.168.170.10 netmask 255.255.255.0
ifconfig vif-6 alias 192.168.160.11 netmask 255.255.255.0
ifconfig vif-6 alias 192.168.170.11 netmask 255.255.255.0
route add default 192.168.220.1 1
routed on
options dns.enable off
options nis.enable off
savecore

 

After the following command was executed:

 

Add-NaNetRoute default 192.168.16.1 1 -Creator inblrx802

 

the /etc/rc file became like this:

 

hostname inblrx900
ifgrp create multi vif -b ip e0b e0c
vlan create vif 1
vlan add vif 2
vlan add vif 3
vlan add vif 4
vlan add vif 5
vlan add vif 6
vlan add vif 7
ifconfig e0a `hostname`-e0a netmask 255.255.255.0 broadcast 192.168.220.255 flowcontrol full up
ifconfig e0b flowcontrol full up
ifconfig e0c flowcontrol full up
ifconfig e0d `hostname`-e0d netmask 255.255.255.0 broadcast 192.168.16.255 flowcontrol full up
ifconfig vif up
ifconfig vif-1 up
ifconfig vif-2 up
ifconfig vif-3 up
ifconfig vif-4 up
ifconfig vif-5 up
ifconfig vif-6 `hostname`-vif-6 netmask 255.255.255.0 broadcast 192.168.160.255 up
ifconfig vif-6 alias 192.168.160.11 netmask 255.255.255.0 broadcast 192.168.160.255 up
ifconfig vif-6 alias 192.168.170.11 netmask 255.255.255.0 broadcast 192.168.170.255 up
ifconfig vif-7 `hostname`-vif-7 netmask 255.255.255.0 broadcast 192.168.170.255 up

 

 

Do we have any other way to add the default gateway to a newly created vfiler and make an entry in the /etc/rc file in a much cleaner way?

 

,Sheel

4 REPLIES 4

rajeshr
4,479 Views

Hi, please add Data ONTAP version and PowerShell toolkit version. I see this is not expected behavior - it should have the options and savecore after execution of the command even.

AssenLS
4,430 Views

Hi,

 

I have the same issue that when WFA creates a vFiler /etc/rc and /etc/hosts files are messed up.

 

The cmdlets used by the creation process are the following:

New-NaNetIpspace

Set-NaNetIpspace

New-NaVfiler

Set-NaVfilerAddress

Set-NaVfilerDns

Set-NaVfilerNis

Set-NaVfilerAdminHost

Set-NaVfilerPassword

Set-NaVfilerProtocol

 

Any idea where should i put the case for this? The WFA versions is 2.2.0.2.6 and i can get the PSTK version as well if needed.

 

I also find a bug which might be relevant (746083).

 

Any hints are welcome!

 

Kind regards,

Assen

abhit
4,355 Views

Hi:

 

Request you to call up NetApp support and open a support case for the same.

 

Regards

Abhi

mbeattie
3,784 Views

Hi Guys,

 

I developed a solution to this issue as a workaround for BURT 746803. Instead of using the PowerShell CmdLet just use SSH.

Rather than using the WFA Certified Commands I created custom commands that use the "Invoke-NaSsh" CmdLet to run the SSH commands you would use to create a vfiler as per the following KB article:

 

https://kb.netapp.com/support/index?page=content&id=1011779

 

See source code for the WFA commands below to create a vfiler and a vlan

 

Create and configure vfiler using SSH:

 

Param(
   [Parameter(Mandatory=$True, HelpMessage="The name or IP address of the controller")]
   [String]$Array,
   [Parameter(Mandatory=$True, HelpMessage="The name of the vFiler")]
   [String]$VfilerName,
   [Parameter(Mandatory=$False, HelpMessage="The name or IP address of the partner controller")]
   [String]$Partner,
   [Parameter(Mandatory=$True, HelpMessage="Delimited list of ip_address:netmask:interface to be bound to the new vFiler eg 10.10.10.10:255.255.0.0:e0a")]
   [Array]$IpAddressBindings,
   [Parameter(Mandatory=$False, HelpMessage="The IP Address of the vFilers default route to add")]
   [String]$DefaultRoute,
   [Parameter(Mandatory=$True, HelpMessage="Comma separated list of volume or qtree paths to be owned by the new vFiler")]
   [Array]$Storage,
   [Parameter(Mandatory=$False, HelpMessage="IPspace of the new vFiler. If it does not exist it will be created. If not provided, the vFiler will be created in the default-ipspace")]
   [String]$IpSpace,
   [Parameter(Mandatory=$False, HelpMessage="DNS domain name for the vFiler")]
   [String]$DnsDomainName,
   [Parameter(Mandatory=$False, HelpMessage="Comma separated list of DNS servers for the vFiler")]
   [Array]$DnsServers,
   [Parameter(Mandatory=$False, HelpMessage="NIS domain name for the vFiler")]
   [String]$NisDomainName,
   [Parameter(Mandatory=$False, HelpMessage="Comma separated list of NIS servers for the vFiler")]
   [Array]$NisServers,
   [Parameter(Mandatory=$False, HelpMessage="Administrative host name for the vFiler")]
   [String]$AdminHostName,
   [Parameter(Mandatory=$False, HelpMessage="Administrative host IP address for the vFiler")]
   [String]$AdminHostIpAddress,
   [Parameter(Mandatory=$False, HelpMessage="Enable CIFS on the new vFiler")]
   [Bool]$CifsSupported=$True,
   [Parameter(Mandatory=$False, HelpMessage="Enable NFS on the new vFiler")]
   [Bool]$NfsSupported=$True,
   [Parameter(Mandatory=$False, HelpMessage="Enable HTTP on the new vFiler")]
   [Bool]$HttpSupported=$True,
   [Parameter(Mandatory=$False, HelpMessage="Enable FTP on the new vFiler")]
   [Bool]$FtpSupported=$True,
   [Parameter(Mandatory=$False, HelpMessage="Enable iSCSI on the new vFiler")]
   [Bool]$IscsiSupported=$True,
   [Parameter(Mandatory=$False, HelpMessage="Enable RSH on the new vFiler")]
   [Bool]$RshSupported=$True,
   [Parameter(Mandatory=$False, HelpMessage="Enable SSH on the new vFiler")]
   [Bool]$SshSupported=$True
)
#'------------------------------------------------------------------------------
#Validate input paramaters ensuring there is atleast one IPAddress binding info in the command input.
#'------------------------------------------------------------------------------
If($IpAddressBindings.Length -eq 0){
   Throw "At least one IpAddress binding should be provided";
}
#'------------------------------------------------------------------------------
#'Ensure that either both DNS domain name and servers or none are provided.
#'------------------------------------------------------------------------------
If(($DnsDomainName -And !$DnsServers) -Or (!$DnsDomainName -and $DnsServers)){
   Throw "Both DNS Domain name and servers should be provided";
}
#'------------------------------------------------------------------------------
#'Ensure that either both NIS domain name and servers or none are provided.
#'------------------------------------------------------------------------------
If(($NisDomainName -And !$NisServers) -Or (!$NisDomainName -and $NisServers)){
   Throw "Both NIS Domain name and servers should be provided";
}
#'------------------------------------------------------------------------------
#'Store only the IP Addresses from the IPAddressBiding array as only IpAddresses are required for New-NaVfiler
#'Complete binding information is required for New-NaVFilerIPAddress in the form of array of IpBindingInfo objects
#'List of interfaces are derived from array of IpAddressBinding. Required for assigning the interfaces to a non-default IPspace if specified.
#'------------------------------------------------------------------------------
[String]$filePath   = "/vol/vol0/etc/rc"
[Array]$ipAddresses = @()
[Array]$interfaces  = @()
#'------------------------------------------------------------------------------
#'Each element in $IpAddressBindings is in the form of <IpAddress>:<Netmask>:<Interface>
#'------------------------------------------------------------------------------
ForEach($ipAddressBindingInfo In $IpAddressBindings){
   $binding = $ipAddressBindingInfo.split(":")
   If($binding.Length -ne 3){
      Throw "Each element in the IpAddressBindings must be in the format of`: <IpAddress>`:<Netmask>`:<Interface>"
   }
   [Array]$ipAddresses  += $binding[0]
   [Array]$interfaces   += $binding[2]
   [String]$vFilerSubnet = $binding[0].SubString(0, $binding[0].LastIndexOfAny("."))
}
#'------------------------------------------------------------------------------
#'Check if the vFilers Default Route is on the same subnet as the vfiler.
#'------------------------------------------------------------------------------
If($DefaultRoute){
   [String]$routeSubnet = $DefaultRoute.SubString(0, $DefaultRoute.LastIndexOfAny("."))
   If($vFilerSubnet -ne $routeSubnet){
      Get-WFALogger -Info -Message "The vFilers default Route ""$DefaultRoute"" is not on the same subnet as ""$ipAddresses"""
      #Throw "The vFilers default Route ""$DefaultRoute"" is not on the same subnet as ""$ipAddresses"""
   }
}
#'------------------------------------------------------------------------------
#'Connect to the controller.
#'------------------------------------------------------------------------------
Connect-WfaController -Array $Array
Get-WFALogger -Info -Message $("Creating vFiler`: name`: " + $VfilerName + ", IP addresses`: " + $IpAddressBindings + ", storage`: " + $Storage + ", IP space: " + $Ipspace)
#'------------------------------------------------------------------------------
#'Check if the IPspace exists on the controller.
#'------------------------------------------------------------------------------
If($Ipspace){
   Try{
      $ipSpaceInArray = Get-NaNetIpspace -ErrorAction Stop | Where-Object {$_.ipspace -eq $Ipspace}
      Get-WFALogger -Info -Message "Enumerated IP Space ""$Ipspace"" on controller ""$Array"""
   }Catch{
      Get-WFALogger -Error -Message $("Failed enumerating IP Space ""$Ipspace"" on controller ""$Array"". Error " + $_.Exception.Message)
      Throw "Failed enumerating IP Space ""$Ipspace"""
   }
   #'---------------------------------------------------------------------------
   #'Ensure the IPspace is created on the controller.
   #'---------------------------------------------------------------------------
   If(-Not($ipSpaceInArray)){
      Try{
         Get-WFALogger -Info -message "Creating Ipspace ""$Ipspace"" on controller ""$Array"""
         [String]$command = "ipspace create $Ipspace"
         #New-NaNetIpspace -Name $Ipspace
         Invoke-NaSsh -Command $command -ErrorAction Stop
         Get-WFALogger -Info -Message "Executed Command`: $command"
      }Catch{
         Get-WFALogger -Error -Message $("Failed Executing Command`: $command. Error`: " + $_.Exception.Message)
         Throw "Failed creating IPspace ""$Ipspace""  on controller ""$Array"""
      }
      Get-WFALogger -Info -Message "Created IPspace ""$Ipspace"" on controller ""$Array"""
   }Else{
      Get-WFALogger -Info -Message "The IPspace ""$Ipspace"" already exists on controller ""$Array"""
   }
   #'---------------------------------------------------------------------------
   #'Enumerate the network interface.
   #'---------------------------------------------------------------------------
   ForEach($interface In $interfaces){
      #Check if interface is already in ipspace. Addition will fail if it is.
      Try{
         $interfaceInIpSpace = Get-NaNetInterface -Name $interface -ErrorAction Stop | Where-Object {$_.IpspaceName -eq $Ipspace}
         Get-WFALogger -Info -Message "Enumerated network interface ""$interface"" on controller ""$Array"""
      }Catch{
         Get-WFALogger -Error -Message $("Failed enumerating network interface ""$interface"" on controller ""$Array"". Error`: " + $_.Exception.Message)
         Throw "Failed enumerating network interface ""$interface"" on controller ""$Array"""
      }
      #'------------------------------------------------------------------------
      #'Assign the network interface to the ipspace if the vfiler is being created in a non-default IPspace.
      #'------------------------------------------------------------------------
      If(-Not($interfaceInIpSpace)){
         Try{
            Get-WFALogger -Info -Message $("Assigning interface " + $interface + " to IPspace " + $Ipspace)
            #Set-NaNetIpspace -Name $Ipspace -Interfaces $interfaces -ErrorAction Stop
            [String]$command = "ipspace assign $Ipspace $interface"
            Invoke-NaSsh -Command $command -ErrorAction Stop
            Get-WFALogger -Info -Message "Executed Command`: $command"
         }Catch{
            Get-WFALogger -Error -Message $("Failed Executing Command`: $command. Error`: " + $_.Exception.Message)
            Throw "Failed to assign IP Space ""$Ipspace"" to network interface ""$interface"" on controller ""$Array"""
         }
      }Else{
         Get-WFALogger -Info -Message "The network interface ""$interface"" is already in IPspace ""$Ipspace"""
      }
   }
}Else{
   $Ipspace = "default-ipspace";
}
#'------------------------------------------------------------------------------
#'Re-Enumerate the network interface now that it has been assigned to the IP Space
#'------------------------------------------------------------------------------
Try{
   $interfaceInIpSpace = Get-NaNetInterface -Name $interface -ErrorAction Stop | Where-Object {$_.IpspaceName -eq $Ipspace}
   Get-WFALogger -Info -Message "Enumerated network interface ""$interface"" on controller ""$Array"""
}Catch{
   Get-WFALogger -Error -Message $("Failed enumerating network interface ""$interface"" on controller ""$Array"". Error`: " + $_.Exception.Message)
   Throw "Failed enumerating network interface ""$interface"" on controller ""$Array"""
}
#'------------------------------------------------------------------------------
#'Get the MTU Size if it is specified on the interface.
#'------------------------------------------------------------------------------
[Bool]$setMtu = $False
If($interfaceInIpSpace.MtusizeSpecified){
   [Int]$mtuSize = $interfaceInIpSpace.Mtusize
   [Bool]$setMtu = $True
}
#'------------------------------------------------------------------------------
#'Create the vFiler.
#'------------------------------------------------------------------------------
Try{
   [String]$vFilerRootVolume = $Storage[$Storage.GetLowerBound(0)]
   Get-WFALogger -Info -Message "Creating new vfiler ""$VfilerName"" on controller ""$Array"""
   #New-NaVfiler -Name $VfilerName -Addresses $ipAddresses -Storage $Storage -Ipspace $Ipspace -ErrorAction stop
   [String]$command = "vfiler create $VfilerName -n -s $Ipspace -i $ipAddresses $vFilerRootVolume"
   Invoke-NaSsh -Command $command -ErrorAction Stop   
   Get-WFALogger -Info -Message "Executed Command`: $command"
}Catch{
   Get-WFALogger -Error -Message $("Failed Executing Command`: $command. Error " + $_.Exception.Message)
   Throw "Failed to create vFiler ""$VfilerName"" on controller ""$Array"""
}
#'------------------------------------------------------------------------------
#'Setup IP Address bindings for the vFiler.
#'------------------------------------------------------------------------------
[Array]$sourceEtcLines  = @()
[Array]$parnterEtcLines = @()
[Array]$vFilerRoutes    = @()
Try{
   ForEach($ipAddressBindingInfo in $IpAddressBindings){
      $binding = $ipAddressBindingInfo.split(":")
      Get-WFALogger -Info -Message $("Setting vfiler Address " + $binding[0] + " Interface " + $binding[2] + " Netmask " + $binding[1])
      If($setMtu){
         #Set-NaVfilerAddress -Name $VfilerName -Addresses $binding[0] -Interface $binding[2] -Netmask $binding[1]  -ErrorAction Stop
         [String]$command         = "ifconfig " + $binding[2] + " " + $binding[0] + " up netmask " + $binding[1] + " mtusize " + $mtuSize + " partner " + $binding[2]
         [Array]$sourceEtcLines  += "ifconfig " + $binding[2] + " " + $binding[0] + " netmask "    + $binding[1] + " mtusize " + $mtuSize + " partner " + $binding[2]
         [Array]$parnterEtcLines += "ifconfig " + $binding[2] + " mtusize " + $mtuSize + " partner " + $binding[2]
         Invoke-NaSsh -Command $command -ErrorAction Stop
         Get-WFALogger -Info -Message "Executed Command`: $command"
      }Else{
         [String]$command         = "ifconfig " + $binding[2] + " " + $binding[0] + " up netmask " + $binding[1] + " partner " + $binding[2]
         [Array]$sourceEtcLines  += "ifconfig " + $binding[2] + " " + $binding[0] + " netmask "    + $binding[1] + " partner " + $binding[2]
         [Array]$parnterEtcLines += "ifconfig " + $binding[2] + " partner " + $binding[2]
         Invoke-NaSsh -Command $command -ErrorAction Stop
         Get-WFALogger -Info -Message "Executed Command`: $command"
      }
   }
}Catch{
   Get-WFALogger -Error -Message $("Failed Executing Command`: $command. " + $_.Exception.Message)
   Throw "Failed to set the IP configuration for vFiler ""$VfilerName"" on controller ""$Array"""
}
#'------------------------------------------------------------------------------
#'Add the vfilers default route if required.
#'------------------------------------------------------------------------------
If($DefaultRoute -ne ""){
   Get-WFALogger -Info -Message "Adding default route for vFiler ""$VfilerName"" on controller ""$Array"""
   Try{
      [String]$command      = "vfiler run $VfilerName route add default $DefaultRoute 1"
      [Array]$vFilerRoutes += $command
      Invoke-NaSsh -Command $command
      Get-WFALogger -Info -Message "Executed Command`: $command"
   }Catch{
      Get-WFALogger -Error -Message $("Failed Executing Command`: $command. Error: " + $_.Exception.Message)
      Throw "Failed to add the default route for vFiler ""$VfilerName"" on controller ""$Array"""
   }
}
#'------------------------------------------------------------------------------
#'Setup DNS for the vFiler.
#'------------------------------------------------------------------------------
If($DnsDomainName){
   Get-WFALogger -Info -Message "Setting up DNS for vFiler ""$VfilerName"" on controller ""$Array"""
   Try{
      #Set-NaVfilerDns -Name $VfilerName -DnsDomain $DnsDomainName -DnsServerAddresses $DnsServers -ErrorAction Stop
      [String]$command = "vfiler run $VfilerName setup -d $DnsDomainName`:$DnsServers"
      Invoke-NaSsh -Command $command -ErrorAction Stop
      Get-WFALogger -Info -Message "Executed Command`: $command"
   }Catch{
      Get-WFALogger -Error -Message $("Failed Executing Command`: $command. Error " + $_.Exception.Message)
      Throw "Failed to set the DNS domain for vFiler ""$VfilerName"" on controller ""$Array"""
   }
}
#'------------------------------------------------------------------------------
#'Setup NIS for the vFiler
#'------------------------------------------------------------------------------
If($NISDomainName){
   Get-WFALogger -Info -Message "Setting up NIS for vFiler ""$VfilerName"" on controller ""$Array"""
   Try{
      #Set-NaVfilerNis -Name $VfilerName -NisDomain $NISDomainName -NisServerAddresses $NisServers -ErrorAction Stop
      [String]$command = "vfiler run $VfilerName setup -n $NISDomainName`:$NisServers"
      Invoke-NaSsh -Command $command -ErrorAction Stop
      Get-WFALogger -Info -Message "Executed Command`: $command"
   }Catch{
      Get-WFALogger -Error -Message $("Failed Executing Command`: $command. Error " + $_.Exception.Message)
      Throw "Failed to set the NIS domain for vFiler ""$VfilerName"" on controller ""$Array"""
   }
}
#'------------------------------------------------------------------------------
#'Setup administrative host for the vFiler
#'------------------------------------------------------------------------------
If($AdminHostIPAddress){
   Get-WFALogger -Info -Message "Setting vfiler AdminHost ""$AdminHostName"" IP Address ""$AdminHostIpAddress"""
   Try{
      #Set-NaVfilerAdminHost -Name $VfilerName -Hostname $AdminHostName -Address $AdminHostIpAddress -ErrorAction Stop
      [String]$command = "vfiler run $VfilerName setup -a $AdminHostName`:$AdminHostIpAddress"
      Invoke-NaSsh -Command $command -ErrorAction Stop
      Get-WFALogger -Info -Message "Executed Command`: $command"
   }Catch{
      Get-WFALogger -Error -Message $("Failed Executing Command`: $command. Error " + $_.Exception.Message)
      Throw "Failed to set the administrative host for vFiler ""$VfilerName"" on controller ""$Array"""
   }
}
#'------------------------------------------------------------------------------
#'Setup the vfiler root password
#'------------------------------------------------------------------------------
$credentials = Get-WfaCredentials -Host $ipAddresses[0]
If($credentials){
   [String]$username = $credentials.GetNetworkCredential().username
   [String]$password = $credentials.GetNetworkCredential().password
   Get-WFALogger -Info -Message "Setting up vfiler password for user ""$userName"" on vfiler ""$VfilerName"" on controller ""$Array"""
   #Set-NaVfilerPassword -Name $VfilerName -Credential $cred -ErrorAction Stop
   [String]$command  = "vfiler run $VfilerName setup -p $password"
   #'---------------------------------------------------------------------------
   #'Mask the password so it does not get written to the log in clear text.
   #'---------------------------------------------------------------------------
   [String]$passwordMask = ""
   For($i = 0; $i -le $password.Length; $i++){
      [String]$passwordMask += "*"
   }
   [String]$passwordMask    = $passwordMask.SubString(0, ($passwordMask.Length -1))
   [String]$passwordCommand = "vfiler run $VfilerName setup -p $passwordMask"
   #'---------------------------------------------------------------------------
   Try{
      Invoke-NaSsh -Command $command -ErrorAction Stop
      Get-WFALogger -Info -Message "Executed Command`: $passwordCommand"
   }Catch{
      Get-WFALogger -Error -Message $("Failed Executing Command: $passwordCommand. Error`: " + $_.Exception.Message)
      Throw "Failed to set password for user ""$username"" on vFiler ""$VfilerName"" on controller ""$Array"""
   }     
}Else{
   Get-WFALogger -Info -Message $("The VFiler Credentials were not found for IP address " + $ipAddresses[0])
}
#'------------------------------------------------------------------------------
#'Set the vfiler disallowed protocols.
#'------------------------------------------------------------------------------
If($NfsSupported -And $CifsSupported -And $IscsiSupported -And $HttpSupported -And $FtpSupported -And $RshSupported -And $SshSupported){
   #'Since it's a new vfiler all protocols are enabled by default.
}Else{
   [Array]$disAllowProtocols = @()
   If(!$NfsSupported){
      [Array]$disAllowProtocols += "proto=nfs"
   }
   If(!$CifsSupported){
      [Array]$disAllowProtocols += "proto=cifs"
   }
   If(!$IscsiSupported){
      [Array]$disAllowProtocols += "proto=iscsi"
   }
   If(!$HttpSupported){
      [Array]$disAllowProtocols += "proto=http"
   }
   If(!$FtpSupported){
      [Array]$disAllowProtocols += "proto=ftp"
   }
   If(!$RshSupported){
      [Array]$disAllowProtocols += "proto=rsh"
   }
   If(!$SshSupported){
      [Array]$disAllowProtocols += "proto=ssh"
   }
   Get-WFALogger -Info -message $("Disabling protocols on " + $VfilerName)
   Try{
      #Set-NaVfilerProtocol -Name $VFilerName -DisallowProtocols $disAllowProtocols -ErrorAction Stop
      [String]$command = "vfiler disallow $VfilerName $disAllowProtocols"
      Invoke-NaSsh -Command $command -ErrorAction Stop
      Get-WFALogger -Info -Message "Executed Command`: $command"
   }Catch{
      Get-WFALogger -Error -Message $("Failed Executing Command`: $command. Error`: " + $_.Exception.Message)
      Throw "Failed disallowing protocols for vFiler ""$VfilerName"" on controller ""$Array"""
   }
}
#'------------------------------------------------------------------------------
#'Update the ifconfig commands in the /etc/rc file.
#'------------------------------------------------------------------------------
Get-WFALogger -Info -Message "Appending ifconfig commands to the ""$filePath"" file on controller ""$Array"""
ForEach($sourceEtcLine In $sourceEtcLines){
   Try{
      Write-NaFile -Path $filePath -Data $sourceEtcLine -AppendLine -ErrorAction Stop
      Get-WFALogger -Info -Message "Added line to ""$filePath"" on controller ""$Array"". Line`: $sourceEtcLine"
   }Catch{
      Get-WFALogger -Error -Message $("Failed adding line to ""$filePath"" on controller ""$Array"". Line`: $sourceEtcLine. Error " + $_.Exception.Message)
      Throw "Failed adding line to ""$filePath"" on controller ""$Array"". Line`: $sourceEtcLine"
   }
}
#'------------------------------------------------------------------------------
#'Update the vfiler route commands in the /etc/rc file.
#'------------------------------------------------------------------------------
Get-WFALogger -Info -Message "Appending route commands to the ""$filePath"" file on controller ""$Array"""
ForEach($vFilerRoute In $vFilerRoutes){
   Try{
      Write-NaFile -Path $filePath -Data $vFilerRoute -AppendLine -ErrorAction Stop
      Get-WFALogger -Info -Message "Added line to ""$filePath"" on controller ""$Array"". Line`: $vFilerRoute"""
   }Catch{
      Get-WFALogger -Error -Message $("Failed adding line to ""$filePath"" on controller ""$Array"". Line`: $vFilerRoute. Error " + $_.Exception.Message)
      Throw "Failed adding line to ""$filePath"" on controller ""$Array"". Line`: $vFilerRoute"""
   }
}
#'------------------------------------------------------------------------------
#'Connect to the partner controller if specified.
#'------------------------------------------------------------------------------
If($Partner){
   Connect-WfaController -Array $Partner
   #'---------------------------------------------------------------------------
   Get-WFALogger -Info -Message "Appending ifconfig commands to the ""$filePath"" file on controller ""$partnerName"""
   #'---------------------------------------------------------------------------
   #'Update the ifconfig commands in the /etc/rc file on the partner.
   #'---------------------------------------------------------------------------
   ForEach($parnterEtcLine In $parnterEtcLines){
      Try{
         Write-NaFile -Path $filePath -Data $parnterEtcLine -AppendLine -ErrorAction Stop
         Get-WFALogger -Info -Message "Added line to ""$filePath"" on controller ""$Partner"". Line`: $parnterEtcLine"
      }Catch{
         Get-WFALogger -Error -Message $("Failed adding line to ""$filePath"" on controller ""$Partner"". Line`: $parnterEtcLine. Error " + $_.Exception.Message)
         Throw "Failed adding line to ""$filePath"" on controller ""$partnerName"". Line`: $parnterEtcLine"
      }
   }
}
#'------------------------------------------------------------------------------

Create VLAN using SSH:

 

param(
  [Parameter(Mandatory=$True, HelpMessage="Array name or IP address")]
  [String]$Array,
  [Parameter(Mandatory=$True, HelpMessage="Interface to add a VLAN to")]
  [String]$Interface,
  [Parameter(Mandatory=$True, HelpMessage="Vlan ID")]
  [ValidateRange(1,4094)]
  [Int]$VlanID
)
#'------------------------------------------------------------------------------
# Connect to controller
#'------------------------------------------------------------------------------
Connect-WfaController -Array $Array	
Get-WFALogger -Info -Message "Connected to controller ""$Array"""
#'------------------------------------------------------------------------------
#'Parameter setup
#'------------------------------------------------------------------------------
[Bool]$foundVlan      = $False
[Bool]$foundIpspace   = $False
[String]$newInterface = $Interface + "-" + $VlanID
[String]$filePath     = "/vol/vol0/etc/rc"
#'------------------------------------------------------------------------------
#'Enumerate the VLANs
#'------------------------------------------------------------------------------
Try{
   $vlans = Get-NaNetVlan -ErrorAction Stop
   Get-WFALogger -Info -Message "Enumerated VLANs on controller ""$Array"""
}Catch{
   Get-WFALogger -Error -Message $("Failed enumerating VLANs on controller ""$Array"". Error " + $_.Exception.Message)
   Throw "Failed enumerating VLANs on controller ""$Array"""
}
#'------------------------------------------------------------------------------
#'Check if the VLAN exists.
#'------------------------------------------------------------------------------
ForEach($vlan in $vlans){
   If($VlanID -eq $vlan.tag -And $Interface -eq $vlan.parentinterface){
      Get-WFALogger -Info -Message "The VLAN ""$vlan"" already exists"
      [Bool]$foundVlan = $True
   }
}
#'------------------------------------------------------------------------------
#'Ensure the VLAN is created if it doesn't exist.
#'------------------------------------------------------------------------------
If(-Not($foundVlan)){
   Get-WFALogger -Info -Message "Creating VLAN on Network Interface"
   Try{
      #Add-NaNetVlan -Interface $Interface -Vlans $VlanID -ErrorAction Stop
      [String]$command = "vlan add $Interface $VlanID"
      Invoke-NaSsh -Command $command -ErrorAction Stop
      Get-WFALogger -Info -Message "Executed Command`: $command"
   }Catch{
      Get-WFALogger -Error -Message $("Failed executing command`: $command. Error " + $_.Exception.Message)
      Throw "Failed creating VLAN ""$VlanID"" for interface ""$Interface"" on controller ""$Array"""
   }
}
#'------------------------------------------------------------------------------
#'Update the VLAN create command in the /etc/rc file.
#'------------------------------------------------------------------------------
If(-Not($foundVlan)){
   Get-WFALogger -Info -Message "Appending vlan create command to the ""$filePath"" file on controller ""$Array"""
   Try{
      Write-NaFile -Path $filePath -Data $command -AppendLine -ErrorAction Stop
      Get-WFALogger -Info -Message "Added line to ""$filePath"" on controller ""$Array"". Line`: $command"
   }Catch{
      Get-WFALogger -Error -Message $("Failed adding line to ""$filePath"" on controller ""$Array"". Line`: $command. Error " + $_.Exception.Message)
      Throw "Failed adding line to ""$filePath"" on controller ""$Array"". Line`: $command"
   }
}
#'------------------------------------------------------------------------------

Hope that helps

 

/matt

 

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.
Public