From 12dc35355f8e90b1cb3e4ef2de95382100f832bf Mon Sep 17 00:00:00 2001 From: Juan Herrera Date: Sat, 4 Mar 2017 14:08:32 -0800 Subject: [PATCH 1/7] adding lbmonitor --- .../POSHOrigin_NetScaler.psm1 | 324 +++++++++++++++++- 1 file changed, 319 insertions(+), 5 deletions(-) diff --git a/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 b/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 index bab3600..c384493 100644 --- a/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 +++ b/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 @@ -15,10 +15,10 @@ class LBVirtualServer { [Ensure]$Ensure = [Ensure]::Present [DscProperty(Mandatory)] - [string]$NetScalerFQDN + [pscredential]$Credential [DscProperty(Mandatory)] - [pscredential]$Credential + [string]$NetScalerFQDN [DscProperty(Mandatory)] [string]$IPAddress @@ -356,10 +356,10 @@ class LBServer { [Ensure]$Ensure = [Ensure]::Present [DscProperty(Mandatory)] - [string]$NetScalerFQDN + [pscredential]$Credential [DscProperty(Mandatory)] - [pscredential]$Credential + [string]$NetScalerFQDN [DscProperty(Mandatory)] [string]$IPAddress @@ -532,4 +532,318 @@ class LBServer { Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue return $obj } -} \ No newline at end of file +} + + +#888888888888888888888888888888888888888888888888888888888888888888 + +[DscResource()] +class LBMonitor { + [DscProperty(Key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty(Mandatory)] + [ValidateSet('PING', 'TCP', 'HTTP', 'TCP-ECV', 'HTTP-ECV', 'UDP-ECV', 'DNS', 'FTP', 'LDNS-PING', + 'LDNS-TCP', 'RADIUS', 'USER', 'HTTP-INLINE', 'SIP-UDP', 'LOAD', 'FTP-EXTENDED', 'SMTP', 'SNMP', + 'NNTP', 'MYSQL', 'MYSQL-ECV', 'MSSQL-ECV', 'ORACLE-ECV', 'LDAP', 'POP3', 'CITRIX-XML-SERVICE', + 'CITRIX-WEB-INTERFACE', 'DNS-TCP', 'RTSP', 'ARP', 'CITRIX-AG', 'CITRIX-AAC-LOGINPAGE', 'CITRIX-AAC-LAS', + 'CITRIX-XD-DDC', 'ND6', 'CITRIX-WI-EXTENDED', 'DIAMETER', 'RADIUS_ACCOUNTING', 'STOREFRONT')] + [string]$Type = 'HTTP' + + [DscProperty(Mandatory)] + [ValidateRange(1, 20940000)] + [int]$Interval = 5 + + [DscProperty(Mandatory)] + [ValidateSet('SEC', 'MSEC', 'MIN')] + [string]$IntervalType = 'SEC', + + [DscProperty(Mandatory)] + [ValidateRange(1, 20939000)] + [int]$ResponseTimeout = 2, + + [DscProperty(Mandatory)] + [ValidateSet('SEC', 'MSEC', 'MIN')] + [string]$ResponseTimeoutType = 'SEC', + + [DscProperty(Mandatory)] + [ValidateRange(1, 20939000)] + [int]$Downtime = 30, + + [DscProperty(Mandatory)] + [ValidateSet('SEC', 'MSEC', 'MIN')] + [string]$DowntimeType = 'SEC', + + [DscProperty(Mandatory)] + [DscProperty()] + [int]$DestinationPort, + + [DscProperty(Mandatory)] + [ValidateRange(1, 127)] + [int]$Retries = 3, + + [DscProperty(Mandatory)] + [ValidateRange(0, 32)] + [int]$SuccessRetries = 1, + + [DscProperty()] + [ValidateScript({$_ -match [IPAddress]$_ })] + [string]$DestinationIP, + + [DscProperty()] + [ValidateRange(0, 20939000)] + [int]$Deviation, + + [DscProperty()] + [ValidateRange(0, 100)] + [int]$ResponseTimeoutThreshold, + + [DscProperty()] + [ValidateRange(0, 32)] + [int]$AlertRetries, + + [DscProperty()] + [ValidateRange(0, 32)] + [int]$FailureRetries, + + [DscProperty()] + [ValidateRange(1, 127)] + [string]$NetProfile, + + [DscProperty()] + [ValidateSet('YES', 'NO')] + [string]$TOS = 'NO', + + [DscProperty()] + [ValidateRange(1, 63)] + [int]$TOSID, + + [DscProperty()] + [ValidateSet('ENABLED', 'DISABLED')] + [string]$State = 'ENABLED', + + [DscProperty()] + [ValidateSet('Yes', 'NO')] + [string]$Reverse = 'NO', + + [DscProperty()] + [ValidateSet('YES', 'NO')] + [string]$Transparent = 'NO', + + [DscProperty()] + [ValidateSet('ENABLED', 'DISABLED')] + [string]$LRTM = 'DISABLED', + + [DscProperty()] + [ValidateSet('YES', 'NO')] + [string]$Secure = 'NO', + + [DscProperty()] + [ValidateSet('YES', 'NO')] + [string]$IPTunnel = 'NO', + + [DscProperty()] + [string]$ScriptName, + + [DscProperty()] + [ValidateScript({$_ -match [IPAddress]$_ })] + [string]$DispatcherIP, + + [DscProperty()] + [int]$DispatcherPort, + + [DscProperty()] + [string]$ScriptArgs, + + [DscProperty()] + [System.Collections.Hashtable]$CustomProperty, + + [DscProperty()] + [switch]$PassThru, + + [DscProperty()] + [Parameter()] + [string[]] + $ResponseCode, + + [DscProperty()] + [Parameter()] + [string] + $HTTPRequest, + + [DscProperty()] + [Parameter()] + [string] + $Send, + + [DscProperty()] + [Parameter()] + [string] + $Recv + + [DscProperty()] + [bool]$ParameterExport = $false + + [void]Set() { + try { + [ref]$t = $null + if ([ipaddress]::TryParse($this.NetScalerFQDN,$t)) { + Connect-NetScaler -IPAddress $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } else { + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } + # Try to get the server + $server = Get-NSLBServer -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + + if ($null -ne $server) { + # Run tests and set any needed attributes to match desired configuration + if ($server.ipaddress -ne $this.IPAddress) { + Write-Verbose -Message "Setting server IP [$($this.IPAddress)]" + Set-NSLBServer -Name $this.Name -IPAddress $this.IPAddress -Force -Verbose:$false + } + if ($server.comment -ne $this.Comments) { + Write-Verbose -Message "Setting server comments [$($this.Comments)]" + Set-NSLBServer -Name $this.Name -Comment $this.Comments -Force -Verbose:$false + } + if ($server.state -ne $this.State) { + Write-Verbose -Message "Setting server state [$($this.State)]" + if ($this.State -eq 'ENABLED') { + Enable-NSLBServer -Name $this.Name -Force -Verbose:$false + } else { + Disable-NSLBServer -Name $this.Name -Force -Verbose:$false + } + } + } else { + Write-Verbose -Message "Creating server [$($this.Name)]" + $params = @{ + Name = $this.Name + IPAddress = $this.IPAddress + Comment = $this.Comments + Confirm = $false + Verbose = $false + } + if ($null -ne $this.TrafficDomainId) { + $params.TrafficDomainId = $this.TrafficDomainId + } + New-NSLBServer @params + } + + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + + $pass = $true + + [ref]$t = $null + if ([ipaddress]::TryParse($this.NetScalerFQDN,$t)) { + Connect-NetScaler -IPAddress $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } else { + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } + # Try to get the server + $server = Get-NSLBServer -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + + if ($this.Ensure = [Ensure]::Present) { + if ($server) { + Write-Verbose -Message "Server [$($this.Name)] exists" + # Run tests against server + if ($server.ipaddress -ne $this.IPAddress) { + Write-Verbose -Message "Server IP address does not match [$($server.ipaddress) <> $($this.IPAddress)]" + $pass = $false + } + if ($server.comment -ne $this.Comments) { + Write-Verbose -Message "Server comments do not match [$($server.comment) <> $($this.Comments)]" + $pass = $false + } + if ($server.td -ne $this.TrafficDomainid) { + Write-Verbose -Message "Server traffic domain ID does not match [$($server.td) <> $($this.TrafficDomainId)]" + $pass = $false + } + if ($server.state -ne $this.State) { + Write-Verbose -Message "Server state does not match [$($server.state) <> $($this.State)]" + $pass = $false + } + } else { + Write-Verbose -Message "Server [$($this.Name)] not found" + $pass = $false + } + } else { + if ($server) { + $pass = $false + } + } + + # Export the resource parameters if told to. + # These values can be used by other DSC resources down the chain + if ($this.ParameterExport) { + $fileName = "LBServer_$($this.Name).json" + $json = $this.Get() | ConvertTo-Json + $folder = Join-Path -Path $env:USERPROFILE -ChildPath '.poshorigin' + if (-Not (Test-Path -Path $folder)) { + New-Item -ItemType Directory -Path $folder -Force + } + $fullPath = Join-Path -Path $folder -ChildPath $fileName + Write-Verbose -Message "Exporting parameters to [$fullPath]" + $json | Out-File -FilePath $fullPath -Force + } + + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + + return $pass + } + + [LBServer]Get() { + [ref]$t = $null + if ([ipaddress]::TryParse($this.NetScalerFQDN,$t)) { + Connect-NetScaler -IPAddress $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } else { + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } + + $s = Get-NSLBServer -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + + $obj = [LBServer]::new() + $obj.Name = $this.Name + $obj.IPAddress = $this.IPAddress + $obj.Comments = $this.Comments + $obj.TrafficDomainId = $this.TrafficDomainId + $obj.State = $this.State + $obj.Credential = $this.Credential + $obj.NetScalerFQDN = $this.NetScalerFQDN + $obj.ParameterExport = $this.ParameterExport + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.IPAddress = $s.ipv46 + $obj.comments = $s.comment + $obj.TrafficDomainId = $s.td + $obj.State = $s.state + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} From 1b8d6b5028f36574c01bff66dea1a7aa32b02a5a Mon Sep 17 00:00:00 2001 From: root Date: Wed, 17 May 2017 14:39:47 -0700 Subject: [PATCH 2/7] adding new resources --- .../POSHOrigin_NetScaler.psd1 | 2 +- .../POSHOrigin_NetScaler.psm1 | 4007 ++++++++++++++--- 2 files changed, 3483 insertions(+), 526 deletions(-) diff --git a/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psd1 b/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psd1 index 8466a20..9a25762 100644 --- a/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psd1 +++ b/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psd1 @@ -24,7 +24,7 @@ RequiredModules = 'NetScaler' # DSC resources to export from this module - DscResourcesToExport = @('LBVirtualServer', 'LBServer') + DscResourcesToExport = @('LBVirtualServer','LBServer','LBMonitor','LBServiceGroup','LBNTPServer','LBResponderPolicy','LBResponderAction','LBSSLCertificate','LBRewritePolicy','LBRewriteAction','LBDNSServer','LBNSMode','LBNSFeature','LBNSIP','LBNSVirtualServerBinding','LBSystemFile','LBVLAN') PrivateData = @{ PSData = @{ diff --git a/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 b/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 index c384493..71b0994 100644 --- a/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 +++ b/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 @@ -23,6 +23,10 @@ class LBVirtualServer { [DscProperty(Mandatory)] [string]$IPAddress + [DscProperty()] + [ValidateLength(0, 256)] + [string]$Comment = '' + [DscProperty(Mandatory)] [ValidateRange(1, 65534)] [int]$Port @@ -39,312 +43,230 @@ class LBVirtualServer { 'SOURCEIPHASH', 'TOKEN', 'SRCIPDESTIPHASH', 'SRCIPSRCPORTHASH', 'CALLIDHASH')] [string]$LBMethod = 'ROUNDROBIN' - [DscProperty()] - [string]$Service - - [DscProperty()] - [string]$ServiceGroup + [DscProperty()] + [ValidateSet('SOURCEIP', 'COOKIEINSERT', 'SSLSESSION', 'CUSTOMSERVERID', 'RULE', 'URLPASSIVE', 'DESTIP', 'SRCIPDESTIP', 'CALLID' ,'RTSPID', 'FIXSESSION', 'NONE')] + [string]$PersistenceType = 'SOURCEIP' [DscProperty()] - [ValidateLength(0, 256)] - [string]$Comments = [string]::Empty + [string]$HttpRedirectURL = '' [DscProperty()] - #[ValidateSet('ENABLED', 'DISABLED', '')] - [string]$State = 'ENABLED' + [ValidateSet('PASSIVE', 'ACTIVE')] + [string]$ICMPVSRResponse = 'PASSIVE' [DscProperty()] - [bool]$ParameterExport = $false + [int]$TimeOut = 2 - [LBVirtualServer]Get() { - [ref]$t = $null - if ([ipaddress]::TryParse($this.NetScalerFQDN,$t)) { - Connect-NetScaler -IPAddress $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false - } else { + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" } - - $vip = Get-NSLBVirtualServer -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue - - $obj = [LBVirtualServer]::new() - $obj.Name = $this.Name - $obj.IPAddress = $this.IPAddress - $obj.NetScalerFQDN = $this.NetScalerFQDN - $obj.Credential = $this.Credential - $obj.ParameterExport = $this.ParameterExport - if ($vip) { - $obj.Ensure = [ensure]::Present - $obj.Port = $vip.port - $obj.ServiceType = $vip.servicetype - $obj.LBMethod = $vip.lbmethod - $obj.State = $vip.curstate - } else { - $obj.Ensure = [ensure]::Absent - } - Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue - return $obj } [void]Set() { - try { - $vip = $this.Get() + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + try { switch ($this.Ensure) { - 'Present' { - [ref]$t = $null - if ([ipaddress]::TryParse($this.NetScalerFQDN,$t)) { - Connect-NetScaler -IPAddress $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false - } else { - Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false - } - - # Does the record already exist? - if ($vip.Ensure -ne [ensure]::Present) { - # Create VIP - Write-Verbose -Message "Creating virtual server [$($this.Name)]" - $params = @{ - Name = $this.Name - IPAddress = $this.IPAddress - ServiceType = $this.ServiceType - Port = $this.Port - LBMethod = $this.LBMethod - Comment = $this.Comments - Verbose = $false - Confirm = $false - } - New-NSLBVirtualServer @params - $vip = $this.Get() - [ref]$t = $null - if ([ipaddress]::TryParse($this.NetScalerFQDN,$t)) { - Connect-NetScaler -IPAddress $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false - } else { - Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false - } + 'Present' { + if ($NSObject.Ensure -eq [ensure]::Present) { + if ($NSObject.name -ne $this.Name) { + Write-Warning -Message 'NetScaler does not support changing virtual server name on an existing virtual server. Virtual server must be deleted and recreated.' } - - # Run tests and set any needed attributes to match desired configuration - - # IP check - if ($vip.IPAddress -ne $this.IPAddress) { + if ($NSObject.ipaddress -ne $this.IPAddress) { Set-NSLBVirtualServer -Name $this.Name -IPAddress $this.IPAddress -Verbose:$false -Confirm:$false Write-Verbose -Message "Setting virtual server IP [$($this.IPAddress)]" } - - # Port check - if ($vip.Port -ne $this.Port) { + if ($NSObject.comment -ne $this.Comment) { + Write-Verbose -Message "Setting virtual server Comment [$($this.Comment)]" + Set-NSLBVirtualServer -Name $this.Name -Comment $this.Comment -Verbose:$false -Force + } + if ($NSObject.Port -ne $this.Port) { Write-Warning -Message 'NetScaler does not support changing virtual server port on an existing virtual server. Virtual server must be deleted and recreated.' } - - # Service type check - if ($vip.ServiceType -ne $this.ServiceType) { + if ($NSObject.ServiceType -ne $this.ServiceType) { Write-Warning -Message 'NetScaler does not support changing virtual server service type on an existing virtual server. Virtual server must be deleted and recreated.' } - - # LB method check - if ($vip.LBMethod -ne $this.LBMethod) { + if ($NSObject.lbmethod -ne $this.LBMethod) { Set-NSLBVirtualServer -Name $this.Name -LBMethod $this.LBMethod -Verbose:$false -Force Write-Verbose -Message "Setting virtual server load balance method [$($this.LBMethod)]" } - - # Comments check - if ($vip.Comments -ne $this.Comments) { - Write-Verbose -Message "Setting virtual server comments [$($this.Comments)]" - Set-NSLBVirtualServer -Name $this.Name -Comment $this.Comments -Verbose:$false -Force + if ($NSObject.persistencetype -ne $this.PersistenceType) { + Set-NSLBVirtualServer -Name $this.Name -PersistenceType $this.PersistenceType -Verbose:$false -Force + Write-Verbose -Message "Setting virtual server persistence [$($this.PersistenceType)]" } - - # Service group binding check - $bindings = Get-NSLBVirtualServerBinding -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue - $sgBinding = $bindings | where servicegroupname -eq $this.ServiceGroup - if ($this.ServiceGroup) { - if (-Not $sgBinding) { - Write-Verbose -Message "Adding virtual server service group binding [$($this.ServiceGroup)]" - Add-NSLBVirtualServerBinding -VirtualServerName $this.Name -ServiceGroupName $this.ServiceGroup -Verbose:$false -Force - } + if ($NSObject.httpredirecturl -ne $this.HttpRedirectURL) { + Set-NSLBVirtualServer -Name $this.Name -HttpRedirectURL $this.HttpRedirectURL -Verbose:$false -Force + Write-Verbose -Message "Setting virtual server redirect [$($this.HttpRedirectURL)]" + } + if ($NSObject.icmpvsrresponse -ne $this.ICMPVSRResponse) { + Set-NSLBVirtualServer -Name $this.Name -ICMPVSRResponse $this.ICMPVSRResponse -Verbose:$false -Force + Write-Verbose -Message "Setting virtual server icmpvsrresponse [$($this.ICMPVSRResponse)]" } - - # Service binding check - $bindings = Get-NSLBVirtualServerBinding -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue - $serviceBinding = $bindings | where servicename -eq $this.Service - if ($this.Service) { - if (-Not $serviceBinding) { - Write-Verbose -Message "Adding virtual server service binding [$($this.Service)]" - Add-NSLBVirtualServerBinding -VirtualServerName $this.Name -ServiceName $this.Service -Verbose:$false -Force - } + if ($NSObject.timeout -ne $this.TimeOut) { + Set-NSLBVirtualServer -Name $this.Name -TimeOut $this.TimeOut -Verbose:$false -Force + Write-Verbose -Message "Setting virtual server timeout [$($this.TimeOut)]" } - - # State check - if ($vip.State -ne 'DOWN') { - if ($vip.State -ne $this.State) { - Write-Verbose -Message "Setting virtual server state [$($this.State)]" - if ($this.State -eq 'ENABLED') { - Enable-NSLBVirtualServer -Name $this.Name -Verbose:$false -Force - # Check that the enable worked - $vip2 = Get-NSLBVirtualServer -Name $this.Name -Verbose:$false - if (-Not $vip2.State -eq 'ENABLED') { - Write-Error -Message "Enabling the virtual server was unsuccessful. The current state is $($vip.curstate)" - } - } else { - Disable-NSLBVirtualServer -Name $this.Name -Verbose:$false -Force - } - } + } else { + Write-Verbose -Message "Creating virtual server [$($this.Name)]" + $params = @{ + Name = $this.Name + IPAddress = $this.IPAddress + ServiceType = $this.ServiceType + Port = $this.Port + LBMethod = $this.LBMethod + PersistenceType = $this.PersistenceType + HttpRedirectURL = $this.HttpRedirectURL + ICMPVSRResponse = $this.ICMPVSRResponse + TimeOut = $this.TimeOut + Comment = $this.Comment } + New-NSLBVirtualServer @params -ErrorAction SilentlyContinue } - 'Absent' { - if ($vip.Ensure -eq [ensure]::Present) { - # Remove VIP - Write-Verbose -Message "Removing virtual server: $($this.Name)" - Remove-NSLBVirtualServer -Name $this.Name -Verbose:$false -Force - } else { - # Do nothing - } + } 'Absent' { + try { + Write-Verbose -Message "Removing virtual server: $($this.Name)" + Remove-NSLBVirtualServer -Name $this.Name -Confirm:$false -Verbose:$false -Force + } catch { + write-host "Virtual Server $this.Name was not found" } } - - Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } } catch { - Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue Write-Error 'There was a problem setting the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" Write-Error $_ } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } } [bool]Test() { - - $vip = $this.Get() $pass = $true - try { - Write-Verbose -Message "Validating that virtual server $($this.Name) is $($this.Ensure.ToString().ToLower())" - if ($this.Ensure -ne $vip.Ensure) { return $false } - - if ($this.Ensure -eq [Ensure]::Present) { - if ($null -ne $vip) { - Write-Verbose -Message "VIP [$($this.Name)] exists" - $bindings = Get-NSLBVirtualServerBinding -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue - - # IP check - if ($vip.IPAddress -ne $this.IPAddress) { - Write-Verbose -Message "Virtual server IP address does not match [$($vip.IPAddress) <> $($this.IPAddress)" - $pass = $false - } - - # Port check - if ($vip.Port -ne $this.Port) { - Write-Verbose -Message "Virtual server port does not match [$($vip.port) <> $($this.Port)" - $pass = $false - } - - # Service type check - if ($vip.ServiceType -ne $this.ServiceType) { - Write-Verbose -Message "Virtual server service type does not match [$($vip.servicetype) <> $($this.ServiceType)" - $pass = $false - } - - # LB method check - if ($vip.LBMethod -ne $this.LBMethod) { - Write-Verbose -Message "Virtual server load balance method does not match [$($vip.lbmethod) <> $($this.LBMethod)" - $pass = $false - } + $t = $null + $t = $this.Init() + $NSObject = $this.Get() - # Comment check - if ($vip.comment -ne $this.Comments) { - Write-Verbose -Message "Virtual server comments do not match [$($vip.comment) <> $($this.Comments)]" - $pass = $false - } + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { - # Service group binding check - if ($this.ServiceGroup) { - $sgBinding = $bindings | where servicegroupname -eq $this.ServiceGroup - if (-Not $sgBinding) { - Write-Verbose -Message 'Virtual server has no service group binding' + if ($NSObject.name -ne $this.Name) { + Write-Verbose -Message "Virtual server Name does not match [$($NSObject.name) <> $($this.Name)" + $pass = $false + } + if ($NSObject.ipaddress -ne $this.IPAddress) { + Write-Verbose -Message "Virtual server IP address does not match [$($NSObject.ipaddress) <> $($this.IPAddress)" $pass = $false - } else { - if ($sgBinding.servicegroupname -ne $this.ServiceGroup) { - Write-Verbose -Message "Virtual server binding service group does not match [$($sgBinding.servicegroupname) <> $($this.ServiceGroup)]" - $pass = $false - } } - } else { - if ($this.Service) { - $unknownBindings = $bindings | where servicename -ne $this.Service - if ($unknownBindings) { - $pass = $false - foreach ($unknownBinding in $unknownBindings) { - Write-Verbose -Message "Virtual server service group binding exists [$($unknownBinding.servicegroupname)] and should not" - } - } + if ($NSObject.comment -ne $this.Comment) { + Write-Verbose -Message "Virtual server Comment do not match [$($NSObject.comment) <> $($this.Comment)]" + $pass = $false + } + if ($NSObject.port -ne $this.Port) { + Write-Verbose -Message "Virtual server port does not match [$($NSObject.port) <> $($this.Port)" + $pass = $false } - } - - # Service binding check - $serviceBinding = $bindings | where servicename -eq $this.Service - if ($this.Service) { - if (-Not $serviceBinding) { - Write-Verbose -Message 'Virtual server has no service binding' + if ($NSObject.servicetype -ne $this.ServiceType) { + Write-Verbose -Message "Virtual server service type does not match [$($NSObject.servicetype) <> $($this.ServiceType)" $pass = $false - } else { - if ($serviceBinding.servicename -ne $this.Service) { - Write-Verbose -Message "Virtual server binding service does not match [$($serviceBinding.servicename) <> $($this.Service)]" - $pass = $false - } } - } else { - if ($this.Service) { - $unknownBindings = $bindings | where servicegroupname -ne $this.ServiceGroup - if ($unknownBindings) { - $pass = $false - foreach ($unknownBinding in $unknownBindings) { - Write-Verbose -Message "Virtual server service group binding exists [$($unknownBinding.servicegroupname)] and should not" - } - } + if ($NSObject.lbmethod -ne $this.LBMethod) { + Write-Verbose -Message "Virtual server load balance method does not match [$($NSObject.lbmethod) <> $($this.LBMethod)" + $pass = $false } - } - - # State check - if ($vip.curstate -ne 'DOWN') { - if ($this.State -eq 'DISABLED') { $this.State = 'OUT OF SERVICE'} - if ($vip.curstate -ne $this.State) { - Write-Verbose -Message "Virtual server state does not match [$($vip.curstate) <> $($this.State)]" + if ($NSObject.persistencetype -ne $this.PersistenceType) { + Write-Verbose -Message "Virtual server Persistence Type does not match [$($NSObject.persistencetype) <> $($this.PersistenceType)" $pass = $false } + if ($NSObject.ICMPVSRResponse -ne $this.ICMPVSRResponse) { + Write-Verbose -Message "Virtual server ICMP Response does not match [$($NSObject.ICMPVSRResponse) <> $($this.ICMPVSRResponse)" + $pass = $false + } + if ($NSObject.httpredirectURL -ne $this.HTTPRedirectURL) { + Write-Verbose -Message "Virtual server HTTP Redirect does not match [$($NSObject.httpredirectURL) <> $($this.HTTPRedirectURL)" + $pass = $false + } + if ($NSObject.timeout -ne $this.TimeOut) { + Write-Verbose -Message "Virtual server Timeout does not match [$($NSObject.timeout) <> $($this.TimeOut)" + $pass = $false + } + } else { + Write-Verbose -Message "Resource [$($this.Name)] was not found" + $pass = $false } - } else { - Write-Verbose -Message "VIP [$($this.Name)] not found" - $pass = $false } - } - } - catch { - Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue - Write-Error 'There was a problem setting the resource' + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" Write-Error $_ - #return $true - } - - # Export the resource parameters if told to. - # These values can be used by other DSC resources down the chain - if ($this.ParameterExport) { - $fileName = "LBVirtualServer_$($this.Name).json" - $json = $this.Get() | ConvertTo-Json - $folder = Join-Path -Path $env:USERPROFILE -ChildPath '.poshorigin' - if (-Not (Test-Path -Path $folder)) { - New-Item -ItemType Directory -Path $folder -Force - } - $fullPath = Join-Path -Path $folder -ChildPath $fileName - Write-Verbose -Message "Exporting parameters to [$fullPath]" - $json | Out-File -FilePath $fullPath -Force } - try { Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue } catch { # Do nothing } - return $pass + return $pass } - + [LBVirtualServer]Get() { + $t = $null + $t = $this.Init() + try { + $s = Get-NSLBVirtualServer -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBVirtualServer]::new() + $obj.Name = $this.Name + $obj.IPAddress = $this.IPAddress + $obj.Port = $this.Port + $obj.ServiceType = $this.ServiceType + $obj.Comment = $this.Comment + $obj.LBMethod = $this.LBMethod + $obj.PersistenceType = $this.PersistenceType + $obj.HTTPRedirectURL = $this.HTTPRedirectURL + $obj.ICMPVSRResponse = $this.ICMPVSRResponse + $obj.TimeOut = $this.TimeOut + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Name = $s.Name + $obj.IPAddress = $s.ipv46 + $obj.Port = $s.port + $obj.ServiceType = $s.servicetype + if ($s.comment) { $obj.Comment = $s.comment } + $obj.LBMethod = $s.lbmethod + $obj.PersistenceType = $s.persistencetype + if ($s.redirurl) { $obj.HTTPRedirectURL = $s.redirurl } + $obj.ICMPVSRResponse = $s.icmpvsrresponse + $obj.TimeOut = $s.timeout + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } } [DscResource()] @@ -366,11 +288,7 @@ class LBServer { [DscProperty()] [ValidateLength(0, 256)] - [string]$Comments = '' - - [DscProperty()] - [ValidateRange(0, 4094)] - [int]$TrafficDomainId + [string]$Comment = '' [DscProperty()] [ValidateSet('ENABLED', 'DISABLED')] @@ -379,50 +297,68 @@ class LBServer { [DscProperty()] [bool]$ParameterExport = $false + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { - [ref]$t = $null - if ([ipaddress]::TryParse($this.NetScalerFQDN,$t)) { - Connect-NetScaler -IPAddress $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false - } else { - Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false - } - # Try to get the server - $server = Get-NSLBServer -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue - - if ($null -ne $server) { - # Run tests and set any needed attributes to match desired configuration - if ($server.ipaddress -ne $this.IPAddress) { - Write-Verbose -Message "Setting server IP [$($this.IPAddress)]" - Set-NSLBServer -Name $this.Name -IPAddress $this.IPAddress -Force -Verbose:$false - } - if ($server.comment -ne $this.Comments) { - Write-Verbose -Message "Setting server comments [$($this.Comments)]" - Set-NSLBServer -Name $this.Name -Comment $this.Comments -Force -Verbose:$false - } - if ($server.state -ne $this.State) { - Write-Verbose -Message "Setting server state [$($this.State)]" - if ($this.State -eq 'ENABLED') { - Enable-NSLBServer -Name $this.Name -Force -Verbose:$false - } else { - Disable-NSLBServer -Name $this.Name -Force -Verbose:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + try { + switch ($this.Ensure) { + 'Present' { + if ($NSObject.Ensure -eq [ensure]::Present) { + if ($NSObject.ipaddress -ne $this.IPAddress) { + Write-Verbose -Message "Setting server IP [$($this.IPAddress)]" + Set-NSLBServer -Name $this.Name -IPAddress $this.IPAddress -Force -Verbose:$false } + if ($NSObject.comment -ne $this.Comment) { + Write-Verbose -Message "Setting server Comment [$($this.Comment)]" + Set-NSLBServer -Name $this.Name -Comment $this.Comment -Force -Verbose:$false + } + if ($NSObject.state -ne $this.State) { + Write-Verbose -Message "Setting server state [$($this.State)]" + if ($this.State -eq 'ENABLED') { + Enable-NSLBServer -Name $this.Name -Force -Verbose:$false + } else { + Disable-NSLBServer -Name $this.Name -Force -Verbose:$false + } + } + } else { + Write-Verbose -Message "Creating server [$($this.Name)]" + $params = @{ + Name = $this.Name + IPAddress = $this.IPAddress + Comment = $this.Comment + Confirm = $false + Verbose = $false + } + if ($null -ne $this.TrafficDomainId) { + $params.TrafficDomainId = $this.TrafficDomainId + } + New-NSLBServer @params } - } else { - Write-Verbose -Message "Creating server [$($this.Name)]" - $params = @{ - Name = $this.Name - IPAddress = $this.IPAddress - Comment = $this.Comments - Confirm = $false - Verbose = $false - } - if ($null -ne $this.TrafficDomainId) { - $params.TrafficDomainId = $this.TrafficDomainId + } 'Absent' { + try { + Write-Verbose -Message "Removing server: $($this.Name)" + Remove-NSLBServer -Name $this.Name -Confirm:$false -Verbose:$false -Force + } catch { + write-host "Virtual Server $this.Name was not found" } - New-NSLBServer @params } - + } } catch { Write-Error 'There was a problem setting the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" @@ -436,95 +372,72 @@ class LBServer { } [bool]Test() { - $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + Write-Verbose -Message "Server [$($this.Name)] exists" - [ref]$t = $null - if ([ipaddress]::TryParse($this.NetScalerFQDN,$t)) { - Connect-NetScaler -IPAddress $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false - } else { - Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false - } - # Try to get the server - $server = Get-NSLBServer -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue - - if ($this.Ensure = [Ensure]::Present) { - if ($server) { - Write-Verbose -Message "Server [$($this.Name)] exists" - # Run tests against server - if ($server.ipaddress -ne $this.IPAddress) { - Write-Verbose -Message "Server IP address does not match [$($server.ipaddress) <> $($this.IPAddress)]" - $pass = $false - } - if ($server.comment -ne $this.Comments) { - Write-Verbose -Message "Server comments do not match [$($server.comment) <> $($this.Comments)]" - $pass = $false - } - if ($server.td -ne $this.TrafficDomainid) { - Write-Verbose -Message "Server traffic domain ID does not match [$($server.td) <> $($this.TrafficDomainId)]" - $pass = $false - } - if ($server.state -ne $this.State) { - Write-Verbose -Message "Server state does not match [$($server.state) <> $($this.State)]" - $pass = $false + if ($NSObject.ipaddress -ne $this.IPAddress) { + Write-Verbose -Message "Server IP address does not match [$($NSObject.ipaddress) <> $($this.IPAddress)]" + $pass = $false + } + if ($NSObject.comment -ne $this.Comment) { + Write-Verbose -Message "Server Comment does not match [$($NSObject.comment) <> $($this.Comment)]" + $pass = $false + } + if ($NSObject.state -ne $this.State) { + Write-Verbose -Message "Server state does not match [$($NSObject.state) <> $($this.State)]" + $pass = $false + } + } else { + Write-Verbose -Message "Server [$($this.Name)] was not found" + $pass = $false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } } - } else { - Write-Verbose -Message "Server [$($this.Name)] not found" - $pass = $false } - } else { - if ($server) { - $pass = $false - } - } - - # Export the resource parameters if told to. - # These values can be used by other DSC resources down the chain - if ($this.ParameterExport) { - $fileName = "LBServer_$($this.Name).json" - $json = $this.Get() | ConvertTo-Json - $folder = Join-Path -Path $env:USERPROFILE -ChildPath '.poshorigin' - if (-Not (Test-Path -Path $folder)) { - New-Item -ItemType Directory -Path $folder -Force - } - $fullPath = Join-Path -Path $folder -ChildPath $fileName - Write-Verbose -Message "Exporting parameters to [$fullPath]" - $json | Out-File -FilePath $fullPath -Force + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ } - try { Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue } catch { # Do nothing } - - return $pass + return $pass } [LBServer]Get() { - [ref]$t = $null - if ([ipaddress]::TryParse($this.NetScalerFQDN,$t)) { - Connect-NetScaler -IPAddress $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false - } else { - Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + $t = $null + $t = $this.Init() + try { + $s = Get-NSLBServer -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null } - - $s = Get-NSLBServer -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue - + $obj = [LBServer]::new() $obj.Name = $this.Name $obj.IPAddress = $this.IPAddress - $obj.Comments = $this.Comments - $obj.TrafficDomainId = $this.TrafficDomainId + $obj.Comment = $this.Comment $obj.State = $this.State $obj.Credential = $this.Credential $obj.NetScalerFQDN = $this.NetScalerFQDN $obj.ParameterExport = $this.ParameterExport if ($s) { $obj.Ensure = [ensure]::Present - $obj.IPAddress = $s.ipv46 - $obj.comments = $s.comment - $obj.TrafficDomainId = $s.td + $obj.IPAddress = $s.ipaddress + $obj.Comment = $s.comment $obj.State = $s.state } else { $obj.Ensure = [ensure]::Absent @@ -534,9 +447,6 @@ class LBServer { } } - -#888888888888888888888888888888888888888888888888888888888888888888 - [DscResource()] class LBMonitor { [DscProperty(Key)] @@ -565,281 +475,3128 @@ class LBMonitor { [DscProperty(Mandatory)] [ValidateSet('SEC', 'MSEC', 'MIN')] - [string]$IntervalType = 'SEC', + [string]$IntervalType = 'SEC' [DscProperty(Mandatory)] [ValidateRange(1, 20939000)] - [int]$ResponseTimeout = 2, + [int]$ResponseTimeout = 2 [DscProperty(Mandatory)] [ValidateSet('SEC', 'MSEC', 'MIN')] - [string]$ResponseTimeoutType = 'SEC', + [string]$ResponseTimeoutType = 'SEC' [DscProperty(Mandatory)] [ValidateRange(1, 20939000)] - [int]$Downtime = 30, + [int]$Downtime = 30 [DscProperty(Mandatory)] [ValidateSet('SEC', 'MSEC', 'MIN')] - [string]$DowntimeType = 'SEC', + [string]$DowntimeType = 'SEC' [DscProperty(Mandatory)] [DscProperty()] - [int]$DestinationPort, + [int]$DestinationPort [DscProperty(Mandatory)] [ValidateRange(1, 127)] - [int]$Retries = 3, + [int]$Retries = 3 [DscProperty(Mandatory)] [ValidateRange(0, 32)] - [int]$SuccessRetries = 1, + [int]$SuccessRetries = 1 [DscProperty()] - [ValidateScript({$_ -match [IPAddress]$_ })] - [string]$DestinationIP, + [string]$DestinationIP [DscProperty()] [ValidateRange(0, 20939000)] - [int]$Deviation, + [int]$Deviation [DscProperty()] [ValidateRange(0, 100)] - [int]$ResponseTimeoutThreshold, + [int]$ResponseTimeoutThreshold [DscProperty()] [ValidateRange(0, 32)] - [int]$AlertRetries, + [int]$AlertRetries [DscProperty()] [ValidateRange(0, 32)] - [int]$FailureRetries, + [int]$FailureRetries [DscProperty()] [ValidateRange(1, 127)] - [string]$NetProfile, + [string]$NetProfile [DscProperty()] [ValidateSet('YES', 'NO')] - [string]$TOS = 'NO', + [string]$TOS = 'NO' [DscProperty()] [ValidateRange(1, 63)] - [int]$TOSID, + [int]$TOSID [DscProperty()] [ValidateSet('ENABLED', 'DISABLED')] - [string]$State = 'ENABLED', + [string]$State = 'ENABLED' [DscProperty()] [ValidateSet('Yes', 'NO')] - [string]$Reverse = 'NO', + [string]$Reverse = 'NO' [DscProperty()] [ValidateSet('YES', 'NO')] - [string]$Transparent = 'NO', + [string]$Transparent = 'NO' [DscProperty()] [ValidateSet('ENABLED', 'DISABLED')] - [string]$LRTM = 'DISABLED', + [string]$LRTM = 'DISABLED' [DscProperty()] [ValidateSet('YES', 'NO')] - [string]$Secure = 'NO', + [string]$Secure = 'NO' [DscProperty()] [ValidateSet('YES', 'NO')] - [string]$IPTunnel = 'NO', - - [DscProperty()] - [string]$ScriptName, + [string]$IPTunnel = 'NO' [DscProperty()] - [ValidateScript({$_ -match [IPAddress]$_ })] - [string]$DispatcherIP, + [string]$ScriptName [DscProperty()] - [int]$DispatcherPort, + [string]$DispatcherIP [DscProperty()] - [string]$ScriptArgs, + [int]$DispatcherPort [DscProperty()] - [System.Collections.Hashtable]$CustomProperty, + [string]$ScriptArgs [DscProperty()] - [switch]$PassThru, + [System.Collections.Hashtable]$CustomProperty [DscProperty()] - [Parameter()] - [string[]] - $ResponseCode, + [string]$ResponseCode [DscProperty()] - [Parameter()] - [string] - $HTTPRequest, + [string]$HTTPRequest [DscProperty()] - [Parameter()] - [string] - $Send, + [string]$Send [DscProperty()] - [Parameter()] - [string] - $Recv + [string]$Recv [DscProperty()] [bool]$ParameterExport = $false - - [void]Set() { - try { - [ref]$t = $null - if ([ipaddress]::TryParse($this.NetScalerFQDN,$t)) { - Connect-NetScaler -IPAddress $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false - } else { - Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false - } - # Try to get the server - $server = Get-NSLBServer -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue - - if ($null -ne $server) { - # Run tests and set any needed attributes to match desired configuration - if ($server.ipaddress -ne $this.IPAddress) { - Write-Verbose -Message "Setting server IP [$($this.IPAddress)]" - Set-NSLBServer -Name $this.Name -IPAddress $this.IPAddress -Force -Verbose:$false - } - if ($server.comment -ne $this.Comments) { - Write-Verbose -Message "Setting server comments [$($this.Comments)]" - Set-NSLBServer -Name $this.Name -Comment $this.Comments -Force -Verbose:$false - } - if ($server.state -ne $this.State) { - Write-Verbose -Message "Setting server state [$($this.State)]" - if ($this.State -eq 'ENABLED') { - Enable-NSLBServer -Name $this.Name -Force -Verbose:$false - } else { - Disable-NSLBServer -Name $this.Name -Force -Verbose:$false - } - } - } else { - Write-Verbose -Message "Creating server [$($this.Name)]" - $params = @{ - Name = $this.Name - IPAddress = $this.IPAddress - Comment = $this.Comments - Confirm = $false - Verbose = $false - } - if ($null -ne $this.TrafficDomainId) { - $params.TrafficDomainId = $this.TrafficDomainId - } - New-NSLBServer @params - } - - } catch { - Write-Error 'There was a problem setting the resource' - Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" - Write-Error $_ - } + + Init() { try { - Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false } catch { - # Do nothing + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" } } - [bool]Test() { - - $pass = $true - - [ref]$t = $null - if ([ipaddress]::TryParse($this.NetScalerFQDN,$t)) { - Connect-NetScaler -IPAddress $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false - } else { + [void]Set() { + $NSObject = $this.Get() + try { Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + try { + switch ($this.Ensure) { + 'Present' { + # Does the record already exist? + if ($NSObject.Ensure -eq [ensure]::Present) { + + #Run tests and set any needed attributes to match desired configuration + if ($NSObject.monitorname -ne $this.Name) { + Write-Warning -Message "Setting Name cannot be changed to [$($this.Name)]. Object must be recreated." + } + if ($NSObject.type -ne $this.Type) { + Write-Warning -Message "Setting Type cannot be changed to [$($this.Type)]. Object must be recreated." + } + if ($NSObject.interval -ne $this.Interval) { + Write-Verbose -Message "Setting Interval [$($this.Interval)]" + Set-NSLBMonitor -Name $this.Name -Interval $this.Interval -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.units3 -ne $this.IntervalType) { + Write-Verbose -Message "Setting Interval Type [$($this.IntervalType)]" + Set-NSLBMonitor -Name $this.Name -IntervalType $this.IntervalType -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.resptimeout -ne $this.ResponseTimeout) { + Write-Verbose -Message "Setting Response Timeout was changed to [$($this.ResponseTimeout)]" + Set-NSLBMonitor -Name $this.Name -ResponseTimeout $this.ResponseTimeout -ResponseTimeoutType $this.ResponseTimeoutType -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.destip -ne $this.DestinationIP) { + Write-Verbose -Message "Setting Destination IP was changed to [$($this.DestinationIP)]" + Set-NSLBMonitor -Name $this.Name -DestinationIP $this.DestinationIP -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.downtime -ne $this.Downtime) { + Write-Verbose -Message "Setting Downtime was changed to [$($this.Downtime)]" + Set-NSLBMonitor -Name $this.Name -Downtime $this.Downtime -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.units2 -ne $this.DowntimeType) { + Write-Verbose -Message "Setting Downtime Type was changed to [$($this.DowntimeType)]" + Set-NSLBMonitor -Name $this.Name -DowntimeType $this.DowntimeType -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.retries -ne $this.Retries) { + Write-Verbose -Message "Setting Retries was changed to [$($this.Retries)]" + Set-NSLBMonitor -Name $this.Name -Retries $this.Retries -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.successretries -ne $this.SuccessRetries) { + Write-Verbose -Message "Setting Success Retries was changed to [$($this.SuccessRetries)]" + Set-NSLBMonitor -Name $this.Name -SuccessRetries $this.SuccessRetries -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.tos -ne $this.TOS) { + Write-Verbose -Message "Setting TOS was changed to [$($this.TOS)]" + Set-NSLBMonitor -Name $this.Name -TOS $this.TOS -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.state -ne $this.State) { + Write-Verbose -Message "Setting State was changed to [$($this.State)]" + Set-NSLBMonitor -Name $this.Name -State $this.State -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.reverse -ne $this.Reverse) { + Write-Verbose -Message "Setting Reverse was changed to [$($this.Reverse)]" + Set-NSLBMonitor -Name $this.Name -Reverse $this.Reverse -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.transparent -ne $this.Transparent) { + Write-Verbose -Message "Setting Transparent was changed to [$($this.Transparent)]" + Set-NSLBMonitor -Name $this.Name -Transparent $this.Transparent -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.lrtm -ne $this.LRTM) { + Write-Verbose -Message "Setting LRTM was changed to [$($this.LRTM)]" + Set-NSLBMonitor -Name $this.Name -LRTM $this.LRTM -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.secure -ne $this.Secure) { + Write-Verbose -Message "Setting Secure was changed to [$($this.Secure)]" + Set-NSLBMonitor -Name $this.Name -Secure $this.Secure -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.iptunnel -ne $this.IPTunnel) { + Write-Verbose -Message "Setting IPTunnel was changed to [$($this.IPTunnel)]" + Set-NSLBMonitor -Name $this.Name -IPTunnel $this.IPTunnel -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.failureretries -ne $this.FailureRetries) { + Write-Verbose -Message "Setting Failure Retries was changed to [$($this.FailureRetries)]" + Set-NSLBMonitor -Name $this.Name -FailureRetries $this.FailureRetries -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.destport -ne $this.DestinationPort) { + Write-Verbose -Message "Setting Destination Port was changed to [$($this.DestinationPort)]" + Set-NSLBMonitor -Name $this.Name -DestinationPort $this.DestinationPort -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.respcode -ne $this.ResponseCode) { + Write-Verbose -Message "Setting Response Code was changed to [$($this.ResponseCode)]" + try { + Set-NSLBMonitor -Name $this.Name -ResponseCode $this.ResponseCode -Verbose:$false -ErrorAction SilentlyContinue + } catch { $null } + } + if ($NSObject.httprequest -ne $this.HTTPRequest) { + Write-Verbose -Message "Setting HTTP Request was changed to [$($this.HTTPRequest)]" + # Set-NSLBMonitor -Name $this.Name -HTTPRequest $this.HTTPRequest -Verbose:$false -ErrorAction SilentlyContinue + } + } else { + Write-Verbose -Message "Creating monitor [$($this.Name)]" + $params = @{ + name = $this.Name + type = $this.Type + interval = $this.Interval + intervaltype = $this.IntervalType + responseTimeoutType = $this.ResponseTimeoutType + downtime = $this.Downtime + downtimeType = $this.DowntimeType + retries = $this.Retries + responsetimeout = $this.ResponseTimeout + successretries = $this.SuccessRetries + failureRetries = $this.FailureRetries + state = $this.State + destinationport = $this.DestinationPort + destinationip = $this.DestinationIP + reverse = $this.Reverse + lrtm = $this.LRTM + transparent = $this.Transparent + tos = $this.TOS + secure = $this.Secure + } + if ($PSBoundParameters.ContainsKey('Transparent')) { + $params.Add('Transparent', $this.Transparent) + } + if ($PSBoundParameters.ContainsKey('LRTM')) { + $params.Add('LRTM', $this.LRTM) + } + if ($PSBoundParameters.ContainsKey('Secure')) { + $params.Add('Secure', $this.Secure) + } + if ($PSBoundParameters.ContainsKey('IPTunnel')) { + $params.Add('IPTunnel', $this.IPTunnel) + } + if ($PSBoundParameters.ContainsKey('TOS')) { + $params.Add('TOS', $this.TOS) + } + if ($PSBoundParameters.ContainsKey('Reverse')) { + $params.Add('Reverse', $this.Reverse) + } + if ($PSBoundParameters.ContainsKey('DestinationIP')) { + $params.Add('DestinationIP', $this.DestinationIP) + } + if ($PSBoundParameters.ContainsKey('Deviation')) { + $params.Add('Deviation', $this.Deviation) + } + if ($PSBoundParameters.ContainsKey('ResponseTimeoutThreshold')) { + $params.Add('ResponseTimeoutThreshold', $this.ResponseTimeoutThreshold) + } + if ($PSBoundParameters.ContainsKey('AlertRetries')) { + $params.Add('AlertRetries', $this.AlertRetries) + } + if ($PSBoundParameters.ContainsKey('FailureRetries')) { + $params.Add('FailureRetries', $this.FailureRetries) + } + if ($PSBoundParameters.ContainsKey('NetProfile')) { + $params.Add('NetProfile', $this.NetProfile) + } + if ($PSBoundParameters.ContainsKey('TOSID')) { + $params.Add('TOSID', $this.TOSID) + } + if ($PSBoundParameters.ContainsKey('ScriptName')) { + $params.Add('ScriptName', $this.ScriptName) + } + if ($PSBoundParameters.ContainsKey('DispatcherIP')) { + $params.Add('DispatcherIP', $this.DispatcherIP) + } + if ($PSBoundParameters.ContainsKey('ScriptArgs')) { + $params.Add('ScriptArgs', $this.ScriptArgs) + } + if ($PSBoundParameters.ContainsKey('CustomProperty')) { + ## Add each custom property to the $params Hashtable + foreach ($CustomProperty in $this.CustomProperty.Keys) { + $params.Add($CustomProperty.ToLower(), $CustomProperty[$CustomProperty]) + } + } + if ($PSBoundParameters.ContainsKey('ResponseCode')) { + $params.Add('ResponseCode', $this.ResponseCode) + } + if ($PSBoundParameters.ContainsKey('HTTPRequest')) { + $params.Add('HTTPRequest', $this.HTTPRequest) + } + if ($PSBoundParameters.ContainsKey('Send')) { + $params.Add('Send', $this.Send) + } + if ($PSBoundParameters.ContainsKey('Recv')) { + $params.Add('Recv', $this.Recv) + } + if ($PSBoundParameters.ContainsKey('DispatcherPort')) { + $params.Add('DispatcherPort', $this.DispatcherPort) + } + New-NSLBMonitor @params -ErrorAction SilentlyContinue + } + } 'Absent' { + try { + $params = @{ + name = $this.Name + type = $this.Type + } + Remove-NSLBMonitor @params -Confirm:$false -ErrorAction SilentlyContinue + Write-Verbose -Message "Removing Netscaler monitor: $($this.Name)" + } catch { + write-host "Monitor $this.Name was not found" + } + } + }# + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + Write-Verbose -Message "Monitor [$($this.Name)] exists" + if ($NSObject.Name -ne $this.Name) { + Write-Verbose -Message "Monitor Name does not match [$($NSObject.monitorname) <> $($this.Name)]" + $pass = $false + } + if ($NSObject.DestinationIP -ne $this.DestinationIP) { + Write-Verbose -Message "Monitor Destination IP does not match [$($NSObject.DestinationIP) <> $($this.DestinationIP)]" + $pass = $false + } + if ($NSObject.Interval -ne $this.Interval) { + Write-Verbose -Message "Monitor Interval does not match [$($NSObject.interval) <> $($this.Interval)]" + $pass = $false + } + if ($NSObject.IntervalType -ne $this.IntervalType) { + Write-Verbose -Message "Monitor Interval Type does not match [$($NSObject.IntervalType) <> $($this.IntervalType)]" + $pass = $false + } + if ($NSObject.ResponseTimeout -ne $this.ResponseTimeout) { + Write-Verbose -Message "Monitor Response Timeout does not match [$($NSObject.ResponseTimeout) <> $($this.ResponseTimeout)]" + $pass = $false + } + if ($NSObject.ResponseTimeoutType -ne $this.ResponseTimeoutType) { + Write-Verbose -Message "Monitor Response Timeout Type does not match [$($NSObject.ResponseTimeoutType) <> $($this.ResponseTimeoutType)]" + $pass = $false + } + if ($NSObject.Downtime -ne $this.Downtime) { + Write-Verbose -Message "Monitor Downtime does not match [$($NSObject.Downtime) <> $($this.Downtime)]" + $pass = $false + } + if ($NSObject.DowntimeType -ne $this.DowntimeType) { + Write-Verbose -Message "Monitor Downtime Type does not match [$($NSObject.DowntimeType) <> $($this.DowntimeType)]" + $pass = $false + } + if ($NSObject.Retries -ne $this.Retries) { + Write-Verbose -Message "Monitor Retries does not match [$($NSObject.Retries) <> $($this.Retries)]" + $pass = $false + } + if ($NSObject.SuccessRetries -ne $this.SuccessRetries) { + Write-Verbose -Message "Monitor Success Retries does not match [$($NSObject.SuccessRetries) <> $($this.SuccessRetries)]" + $pass = $false + } + if ($NSObject.TOS -ne $this.TOS) { + Write-Verbose -Message "Monitor TOS setting not match [$($NSObject.TOS) <> $($this.TOS)]" + $pass = $false + } + if ($NSObject.State -ne $this.State) { + Write-Verbose -Message "Monitor State does not match [$($NSObject.State) <> $($this.State)]" + $pass = $false + } + if ($NSObject.Reverse -ne $this.Reverse) { + Write-Verbose -Message "Monitor Reverse setting does not match [$($NSObject.Reverse) <> $($this.Reverse)]" + $pass = $false + } + if ($NSObject.Transparent -ne $this.Transparent) { + Write-Verbose -Message "Monitor Transparent setting does not match [$($NSObject.Transparent) <> $($this.Transparent)]" + $pass = $false + } + if ($NSObject.LRTM -ne $this.LRTM) { + Write-Verbose -Message "Monitor LRTM setting does not match [$($NSObject.LRTM) <> $($this.LRTM)]" + $pass = $false + } + if ($NSObject.Secure -ne $this.Secure) { + Write-Verbose -Message "Monitor Secure setting does not match [$($NSObject.Secure) <> $($this.Secure)]" + $pass = $false + } + if ($NSObject.IPTunnel -ne $this.IPTunnel) { + Write-Verbose -Message "Monitor IPTunnel setting does not match [$($NSObject.IPTunnel) <> $($this.IPTunnel)]" + $pass = $false + } + if ($NSObject.FailureRetries -ne $this.FailureRetries) { + Write-Verbose -Message "Monitor Failure Retries does not match [$($NSObject.FailureRetries) <> $($this.FailureRetries)]" + $pass = $false + } + if ($NSObject.DestinationPort -ne $this.DestinationPort) { + Write-Verbose -Message "Monitor Destination Port does not match [$($NSObject.DestinationPort) <> $($this.DestinationPort)]" + $pass = $false + } + if ($NSObject.ResponseCode -ne $this.ResponseCode) { + Write-Verbose -Message "Monitor Response Code does not match [$($NSObject.ResponseCode) <> $($this.ResponseCode)]" + $pass = $false + } + if ($NSObject.HTTPRequest -ne $this.HTTPRequest) { + Write-Verbose -Message "Monitor HTTPRequest setting does not match [$($NSObject.HTTPRequest) <> $($this.HTTPRequest)]" + $pass = $false + } + } else { + Write-Verbose -Message "Monitor [$($this.Name)] was not found" + $pass = $false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBMonitor]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSLBMonitor -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBMonitor]::new() + $obj.Name = $this.Name + $obj.Type = $this.Type + $obj.Interval = $this.Interval + $obj.IntervalType = $this.IntervalType + $obj.DestinationIP = $this.DestinationIP + $obj.ResponseTimeout = $this.ResponseTimeout + $obj.ResponseTimeoutType = $this.ResponseTimeoutType + $obj.Downtime = $this.Downtime + $obj.DowntimeType = $this.DowntimeType + $obj.Retries = $this.Retries + $obj.SuccessRetries = $this.SuccessRetries + $obj.TOS = $this.TOS + $obj.State = $this.State + $obj.Reverse = $this.Reverse + $obj.Transparent = $this.Transparent + $obj.LRTM = $this.LRTM + $obj.Secure = $this.Secure + $obj.IPTunnel = $this.IPTunnel + $obj.FailureRetries = $this.FailureRetries + $obj.DestinationPort = $this.DestinationPort + $obj.HTTPRequest = $this.HTTPRequest + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Name = $s.monitorname + $obj.Type = $s.type + $obj.Interval = $s.interval + $obj.IntervalType = $s.units3 + $obj.DestinationIP = $s.destip + $obj.ResponseTimeout = $s.resptimeout + $obj.ResponseTimeoutType = $s.units4 + $obj.Downtime = $s.downtime + $obj.DowntimeType = $s.units2 + $obj.Retries = $s.retries + $obj.SuccessRetries = $s.successRetries + $obj.TOS = $s.tos + $obj.State = $s.state + $obj.Reverse = $s.reverse + $obj.Transparent = $s.transparent + $obj.LRTM = $s.lrtm + $obj.Secure = $s.secure + $obj.IPTunnel = $s.iptunnel + $obj.FailureRetries = $s.failureretries + $obj.DestinationPort = $s.destport + $obj.HTTPRequest = $s.httprequest + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBServiceGroup { + [DscProperty(Key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty()] + [ValidateSet('ADNS','ADNS_TCP','ANY','DHCPRA','DIAMETER','DNS','DNS_TCP','DTLS','FTP','HTTP','MSSQL', + 'MYSQL','NNTP','RADIUS','RDP','RPCSVR','RTSP','SIP_UDP','SNMP','SSL','SSL_BRIDGE','SSL_DIAMETER','SSL_TCP','TCP','TFTP','UDP')] + [Alias('Protocol')] + [string]$ServiceType = 'HTTP' + + [DscProperty()] + [ValidateRange(0, 4094)] + [int]$TrafficDomainId = 0 + + [DscProperty()] + [ValidateSet('SERVER', 'FORWARD', 'TRANSPARENT', 'REVERSE')] + [string]$CacheType = 'SERVER' + + [DscProperty()] + [ValidateSet('DISABLED', 'DNS', 'POLICY')] + [string]$AutoScale = 'DISABLED' + + [DscProperty()] + [ValidateSet('NO', 'YES')] + [string]$Cacheable = 'NO' + + [DscProperty()] + [ValidateSet('ENABLED', 'DISABLED')] + [string]$State = 'ENABLED' + + [DscProperty()] + [ValidateSet('NO', 'YES')] + [string]$HealthMonitor = 'YES' + + [DscProperty()] + [ValidateSet('DISABLED', 'ENABLED')] + [string]$AppFlowLog = 'ENABLED' + + [DscProperty()] + [ValidateLength(0, 256)] + [string]$Comment = [string]::Empty + + [DscProperty()] + [ValidateSet('ON', 'OFF')] + [string]$SureConnect = 'OFF' + + [DscProperty()] + [ValidateSet('ON', 'OFF')] + [string]$SurgeProtection = 'OFF' + + [DscProperty()] + [ValidateSet('YES','NO')] + [string]$UseProxyPort = 'YES' + + [DscProperty()] + [ValidateSet('ENABLED','DISABLED')] + [string]$DownStateFlush = 'ENABLED' + + [DscProperty()] + [ValidateSet('YES','NO')] + [string]$UseClientIP = "No" + + [DscProperty()] + [ValidateSet('YES','NO')] + [string]$ClientKeepAlive = 'NO' + + [DscProperty()] + [ValidateSet('YES', 'NO')] + [string]$TCPBuffering = 'NO' + + [DscProperty()] + [ValidateSet('YES', 'NO')] + [string]$HTTPCompression = 'YES' + + [DscProperty()] + [ValidateSet('ENABLED','DISABLED')] + [string]$ClientIP = 'DISABLED' + + [DscProperty()] + [string]$ClientIPHeader + + [DscProperty()] + [ValidateRange(0, 4294967287)] + [int]$MaxBandwidthKbps + + [DscProperty()] + [ValidateRange(0, 65535)] + [int]$MonitorThreshold + + [DscProperty()] + [ValidateRange(0, 65535)] + [int]$MaxRequests + + [DscProperty()] + [ValidateRange(0, 4294967294)] + [int]$MaxClients + + [DscProperty()] + [ValidateRange(0, 31536000)] + [int]$ClientIdleTimeout = 180 + + [DscProperty()] + [ValidateRange(0, 31536000)] + [int]$ServerIdleTimeout = 360 + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + + [void]Set() { + $NSObject = $this.Get() + try { + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + if ($NSObject.Name -ne $this.Name) { + Write-Warning -Message "Setting Name cannot be changed to [$($this.Name)], must be recreated" + } + if ($NSObject.ServiceType -ne $this.ServiceType) { + Write-Warning -Message "Setting Service Type cannot be changed to [$($this.ServiceType)], must be recreated" + } + if ($NSObject.TrafficDomainId -ne $this.TrafficDomainId) { + Write-Warning -Message "Setting Traffic Domain cannot be changed to [$($this.TrafficDomainId)]" + } + if ($NSObject.CacheType -ne $this.CacheType) { + Write-Warning -Message "Setting Cache Type cannot be changed to[$($this.CacheType)]" + } + if ($NSObject.AutoScale -ne $this.AutoScale) { + Write-Verbose -Message "Setting Autoscale [$($this.AutoScale)]" + Set-NSLBServiceGroup -Name $this.Name -AutoScale $this.AutoScale -Force -Verbose:$false + } + if ($NSObject.Cacheable -ne $this.Cacheable) { + Write-Verbose -Message "Setting Cacheable [$($this.Cacheable)]" + Set-NSLBServiceGroup -Name $this.Name -Cacheable $this.Cacheable -Force -Verbose:$false + } + if ($NSObject.State -ne $this.State) { + Write-Verbose -Message "Setting State [$($this.State)]" + Set-NSLBServiceGroup -Name $this.Name -State $this.State -Force -Verbose:$false + } + if ($NSObject.HealthMonitor -ne $this.HealthMonitor) { + Write-Verbose -Message "Setting Health Monitor [$($this.HealthMonitor)]" + Set-NSLBServiceGroup -Name $this.Name -HealthMonitor $this.HealthMonitor -Force -Verbose:$false + } + if ($NSObject.AppFlowLog -ne $this.AppFlowLog) { + Write-Verbose -Message "Setting AppFlowLog [$($this.AppFlowLog)]" + Set-NSLBServiceGroup -Name $this.Name -AppFlowLog $this.AppFlowLog -Force -Verbose:$false + } + if ($NSObject.Comment -ne $this.Comment) { + Write-Verbose -Message "Setting Comment [$($this.Comment)]" + Set-NSLBServiceGroup -Name $this.Name -Comment $this.Comment -Force -Verbose:$false + } + if ($NSObject.SureConnect -ne $this.SureConnect) { + Write-Verbose -Message "Setting SureConnect [$($this.SureConnect)]" + Set-NSLBServiceGroup -Name $this.Name -SureConnect $this.SureConnect -Force -Verbose:$false + } + if ($NSObject.SurgeProtection -ne $this.SurgeProtection) { + Write-Verbose -Message "Setting Surge Protection [$($this.SurgeProtection)]" + Set-NSLBServiceGroup -Name $this.Name -SurgeProtection $this.SurgeProtection -Force -Verbose:$false + } + if ($NSObject.UseProxyPort -ne $this.UseProxyPort) { + Write-Verbose -Message "Setting Use Proxy Port [$($this.UseProxyPort)]" + Set-NSLBServiceGroup -Name $this.Name -UseProxyPort $this.UseProxyPort -Force -Verbose:$false + } + if ($NSObject.DownStateFlush -ne $this.DownStateFlush) { + Write-Verbose -Message "Setting DownState Flush [$($this.DownStateFlush)]" + Set-NSLBServiceGroup -Name $this.Name -DownStateFlush $this.DownStateFlush -Force -Verbose:$false + } + if ($NSObject.UseClientIP -ne $this.UseClientIP) { + Write-Verbose -Message "Setting Use Client IP [$($this.UseClientIP)]" + Set-NSLBServiceGroup -Name $this.Name -UseClientIP $this.UseClientIP -Force -Verbose:$false + } + if ($NSObject.ClientKeepAlive -ne $this.ClientKeepAlive) { + Write-Verbose -Message "Setting Client Keep Alive [$($this.ClientKeepAlive)]" + Set-NSLBServiceGroup -Name $this.Name -ClientKeepAlive $this.ClientKeepAlive -Force -Verbose:$false + } + if ($NSObject.TCPBuffering -ne $this.TCPBuffering) { + Write-Verbose -Message "Setting TCP Buffering [$($this.TCPBuffering)]" + Set-NSLBServiceGroup -Name $this.Name -TCPBuffering $this.TCPBuffering -Force -Verbose:$false + } + if ($NSObject.HTTPCompression -ne $this.HTTPCompression) { + Write-Verbose -Message "Setting HTTP Compression [$($this.HTTPCompression)]" + Set-NSLBServiceGroup -Name $this.Name -HTTPCompression $this.HTTPCompression -Force -Verbose:$false + } + if ($NSObject.ClientIP -ne $this.ClientIP) { + Write-Verbose -Message "Setting Client IP [$($this.ClientIP)]" + Set-NSLBServiceGroup -Name $this.Name -ClientIP $this.ClientIP -Force -Verbose:$false + } + if ($NSObject.MaxBandwidthKbps -ne $this.MaxBandwidthKbps) { + Write-Verbose -Message "Setting Maximum Bandwidth (Kbps) [$($this.MaxBandwidthKbps)]" + Set-NSLBServiceGroup -Name $this.Name -MaxBandwidthKbps $this.MaxBandwidthKbps -Force -Verbose:$false + } + if ($NSObject.MonitorThreshold -ne $this.MonitorThreshold) { + Write-Verbose -Message "Setting Monitor Threshold [$($this.MonitorThreshold)]" + Set-NSLBServiceGroup -Name $this.Name -MonitorThreshold $this.MonitorThreshold -Force -Verbose:$false + } + if ($NSObject.MaxRequests -ne $this.MaxRequests) { + Write-Verbose -Message "Setting Maximum Client Requests [$($this.MaxRequests)]" + Set-NSLBServiceGroup -Name $this.Name -MaxRequests $this.MaxRequests -Force -Verbose:$false + } + if ($NSObject.MaxClients -ne $this.MaxClients) { + Write-Verbose -Message "Setting Maximum Client connections [$($this.MaxClients)]" + Set-NSLBServiceGroup -Name $this.Name -MaxClients $this.MaxClients -Force -Verbose:$false + } + if ($NSObject.ClientIdleTimeout -ne $this.ClientIdleTimeout) { + Write-Verbose -Message "Setting Client Idle Timeout [$($this.ClientIdleTimeout)]" + Set-NSLBServiceGroup -Name $this.Name -ClientIdleTimeout $this.ClientIdleTimeout -Force -Verbose:$false + } + if ($NSObject.ServerIdleTimeout -ne $this.ServerIdleTimeout) { + Write-Verbose -Message "Setting Server Idle Timeout [$($this.ServerIdleTimeout)]" + Set-NSLBServiceGroup -Name $this.Name -ServerIdleTimeout $this.ServerIdleTimeout -Force -Verbose:$false + } + } else { + Write-Verbose -Message "Creating Service Group [$($this.Name)]" + $params = @{ + name = $this.Name + servicetype = $this.ServiceType + state = $this.State + comment = $this.Comment + } + if ($PSBoundParameters.ContainsKey('TrafficDomainId')) { + $params.Add('TrafficDomainId', $this.TrafficDomainId) + } + if ($PSBoundParameters.ContainsKey('MaxClients')) { + $params.Add('MaxClients', $this.MaxClients) + } + if ($PSBoundParameters.ContainsKey('CacheType')) { + $params.Add('CacheType', $this.CacheType) + } + if ($PSBoundParameters.ContainsKey('AutoScale')) { + $params.Add('AutoScale', $this.AutoScale) + } + if ($PSBoundParameters.ContainsKey('Cacheable')) { + $params.Add('Cacheable', $this.Cacheable) + } + if ($PSBoundParameters.ContainsKey('HealthMonitor')) { + $params.Add('HealthMonitor', $this.HealthMonitor) + } + if ($PSBoundParameters.ContainsKey('AppFlowLog')) { + $params.Add('AppFlowLog', $this.AppFlowLog) + } + if ($PSBoundParameters.ContainsKey('SureConnect')) { + $params.Add('SureConnect', $this.SureConnect) + } + if ($PSBoundParameters.ContainsKey('SurgeProtection')) { + $params.Add('SurgeProtection', $this.SurgeProtection) + } + if ($PSBoundParameters.ContainsKey('UseProxyPort')) { + $params.Add('UseProxyPort', $this.UseProxyPort) + } + if ($PSBoundParameters.ContainsKey('DownStateFlush')) { + $params.Add('DownStateFlush', $this.DownStateFlush) + } + if ($PSBoundParameters.ContainsKey('UseClientIP')) { + $params.Add('UseClientIP', $this.UseClientIP) + } + if ($PSBoundParameters.ContainsKey('ClientKeepAlive')) { + $params.Add('ClientKeepAlive', $this.ClientKeepAlive) + } + if ($PSBoundParameters.ContainsKey('TCPBuffering')) { + $params.Add('TCPBuffering', $this.TCPBuffering) + } + if ($PSBoundParameters.ContainsKey('HTTPCompression')) { + $params.Add('HTTPCompression', $this.HTTPCompression) + } + if ($PSBoundParameters.ContainsKey('ClientIP')) { + $params.Add('ClientIP', $this.ClientIP) + } + if ($PSBoundParameters.ContainsKey('MaxBandwidthKbps')) { + $params.Add('MaxBandwidthKbps', $this.MaxBandwidthKbps) + } + if ($PSBoundParameters.ContainsKey('DownStateFlush')) { + $params.Add('DownStateFlush', $this.DownStateFlush) + } + if ($PSBoundParameters.ContainsKey('MaxRequests')) { + $params.Add('MaxRequests', $this.MaxRequests) + } + if ($PSBoundParameters.ContainsKey('ClientIdleTimeout')) { + $params.Add('ClientIdleTimeout', $this.ClientIdleTimeout) + } + if ($PSBoundParameters.ContainsKey('ServerIdleTimeout')) { + $params.Add('ServerIdleTimeout', $this.ServerIdleTimeout) + } + New-NSLBServiceGroup @params -ErrorAction SilentlyContinue + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSLBServiceGroup -Name $NSObject.Name -Confirm:$false -ErrorAction SilentlyContinue + Write-Verbose -Message "Removing Netscaler monitor: $($this.Name)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + if ($NSObject.Name -ne $this.Name) { + Write-Verbose -Message "Service Group Name doest not match [$($NSObject.Name) <> $($this.Name)]" + $pass = $false + } + if ($NSObject.ServiceType -ne $this.ServiceType) { + Write-Verbose -Message "Service Type does not match [$($NSObject.ServiceType) <> $($this.ServiceType)]" + $pass = $false + } + if ($NSObject.TrafficDomainId -ne $this.TrafficDomainId) { + Write-Verbose -Message "Traffic Domain does not match [$($NSObject.TrafficDomainId) <> $($this.TrafficDomainId)]" + $pass = $false + } + if ($NSObject.CacheType -ne $this.CacheType) { + Write-Verbose -Message "Cache Type does not match [$($NSObject.CacheType) <> $($this.CacheType)]" + $pass = $false + } + if ($NSObject.Cacheable -ne $this.Cacheable) { + Write-Verbose -Message "Cacheable setting does not match [$($NSObject.Cacheable) <> $($this.Cacheable)]" + $pass = $false + } + if ($NSObject.State -ne $this.State) { + Write-Verbose -Message "State does not match [$($NSObject.State) <> $($this.State)]" + $pass = $false + } + if ($NSObject.HealthMonitor -ne $this.HealthMonitor) { + Write-Verbose -Message "Health Monitor does not match [$($NSObject.HealthMonitor) <> $($this.HealthMonitor)]" + $pass = $false + } + if ($NSObject.AppFlowLog -ne $this.AppFlowLog) { + Write-Verbose -Message "AppFlowLog does not match [$($NSObject.AppFlowLog) <> $($this.AppFlowLog)]" + $pass = $false + } + if ($NSObject.Comment -ne $this.Comment) { + Write-Verbose -Message "Comment does not match [$($NSObject.Comment) <> $($this.Comment)]" + $pass = $false + } + if ($NSObject.SurgeProtection -ne $this.SurgeProtection) { + Write-Verbose -Message "Surge Protection does not match [$($NSObject.SurgeProtection) <> $($this.SurgeProtection)]" + $pass = $false + } + if ($NSObject.SureConnect -ne $this.SureConnect) { + Write-Verbose -Message "Sure Connect does not match [$($NSObject.SureConnect) <> $($this.SureConnect)]" + $pass = $false + } + if ($NSObject.UseProxyPort -ne $this.UseProxyPort) { + Write-Verbose -Message "Use Proxy Port does not match [$($NSObject.UseProxyPort) <> $($this.UseProxyPort)]" + $pass = $false + } + if ($NSObject.DownStateFlush -ne $this.DownStateFlush) { + Write-Verbose -Message "DownState Flush does not match [$($NSObject.DownStateFlush) <> $($this.DownStateFlush)]" + $pass = $false + } + if ($NSObject.UseClientIP -ne $this.UseClientIP) { + Write-Verbose -Message "Use Client IP does not match [$($NSObject.UseClientIP) <> $($this.UseClientIP)]" + $pass = $false + } + if ($NSObject.ClientKeepAlive -ne $this.ClientKeepAlive) { + Write-Verbose -Message "Client Keep Alive does not match [$($NSObject.ClientKeepAlive) <> $($this.ClientKeepAlive)]" + $pass = $false + } + if ($NSObject.TCPBuffering -ne $this.TCPBuffering) { + Write-Verbose -Message "TCP Buffering does not match [$($NSObject.TCPBuffering) <> $($this.TCPBuffering)]" + $pass = $false + } + if ($NSObject.HTTPCompression -ne $this.HTTPCompression) { + Write-Verbose -Message "HTTP Compression does not match [$($NSObject.HTTPCompression) <> $($this.HTTPCompression)]" + $pass = $false + } + if ($NSObject.ClientIP -ne $this.ClientIP) { + Write-Verbose -Message "Client IP does not match [$($NSObject.ClientIP) <> $($this.ClientIP)]" + $pass = $false + } + # if ($NSObject.ClientIPHeader -ne $this.ClientIPHeader) { + # Write-Verbose -Message "ClientIP Header does not match [$($this.ClientIPHeader)]" + # $pass = $false + # } + if ($NSObject.MaxBandwidthKbps -ne $this.MaxBandwidthKbps) { + Write-Verbose -Message "Maximum Banddwith (Kbps) does not match [$($NSObject.MaxBandwidthKbps) <> $($this.MaxBandwidthKbps)]" + $pass = $false + } + if ($NSObject.MonitorThreshold -ne $this.MonitorThreshold) { + Write-Verbose -Message "Monitor Threshold does not match [$($NSObject.MonitorThreshold) <> $($this.MonitorThreshold)]" + $pass = $false + } + if ($NSObject.MaxRequests -ne $this.MaxRequests) { + Write-Verbose -Message "Maximum Client Requests does not match [$($NSObject.MaxRequests) <> $($this.MaxRequests)]" + $pass = $false + } + if ($NSObject.MaxClients -ne $this.MaxClients) { + Write-Verbose -Message "Maximum Client connections does not match [$($NSObject.MaxClients) <> $($this.MaxClients)]" + $pass = $false + } + if ($NSObject.ClientIdleTimeout -ne $this.ClientIdleTimeout) { + Write-Verbose -Message "Client Idle Timeout does not match [$($NSObject.ClientIdleTimeout) <> $($this.ClientIdleTimeout)]" + $pass = $false + } + if ($NSObject.ServerIdleTimeout -ne $this.ServerIdleTimeout) { + Write-Verbose -Message "Server Idle Timeout does not match [$($NSObject.ServerIdleTimeout) <> $($this.ServerIdleTimeout)]" + $pass = $false + } + } else { + Write-Verbose -Message "Resource [$($this.Name)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBServiceGroup]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSLBServiceGroup -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBServiceGroup]::new() + $obj.Name = $this.Name + $obj.ServiceType = $this.ServiceType + $obj.TrafficDomainID = $this.TrafficDomainID + $obj.CacheType = $this.CacheType + $obj.MaxClients = $this.MaxClients + $obj.MaxRequests = $this.MaxRequests + $obj.Cacheable = $this.Cacheable + $obj.ClientIP = $this.ClientIP + $obj.UseClientIP = $this.UseClientIP + $obj.UseProxyPort = $this.UseProxyPort + $obj.SureConnect = $this.SureConnect + $obj.SurgeProtection = $this.SurgeProtection + $obj.ClientKeepAlive = $this.ClientKeepAlive + $obj.ClientIdleTimeout = $this.ClientIdleTimeout + $obj.ServerIdleTimeout = $this.ServerIdleTimeout + $obj.TCPBuffering = $this.TCPBuffering + $obj.HTTPCompression = $this.HTTPCompression + $obj.MaxBandwidthKbps = $this.MaxBandwidthKbps + $obj.State = $this.State + $obj.DownStateFlush = $this.DownStateFlush + $obj.HealthMonitor = $this.HealthMonitor + $obj.AppFlowLog = $this.AppFlowLog + $obj.Comment = $this.Comment + # $obj.ClientIPHeader = $this.ClientIPHeader + $obj.MonitorThreshold = $this.MonitorThreshold + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Name = $s.servicegroupname + $obj.ServiceType = $s.servicetype + $obj.TrafficDomainID = $s.td + $obj.CacheType = $s.cachetype + $obj.MaxClients = $s.maxclient + $obj.MaxRequests = $s.maxreq + $obj.Cacheable = $s.cacheable + $obj.ClientIP = $s.cip + $obj.UseClientIP = $s.usip + $obj.UseProxyPort = $s.useproxyport + $obj.SureConnect = $s.sc + $obj.SurgeProtection = $s.sp + $obj.ClientKeepAlive = $s.cka + $obj.ClientIdleTimeout = $s.clttimeout + $obj.ServerIdleTimeout = $s.svrtimeout + $obj.TCPBuffering = $s.tcpb + $obj.HTTPCompression = $s.cmp + $obj.MaxBandwidthKbps = $s.maxbandwidth + $obj.State = $s.state + $obj.DownStateFlush = $s.downstateflush + $obj.HealthMonitor = $s.healthmonitor + $obj.AppFlowLog = $s.appflowlog + $obj.Comment = $s.comment + # $obj.ClientIPHeader = $s.cipheader + $obj.MonitorThreshold = $s.monthreshold + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBNTPServer { + [DscProperty(Key)] + [string]$Server + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty()] + [int]$MinPollInterval + + [DscProperty()] + [ValidateRange(0, 4094)] + [int]$MaxPollInterval + + [DscProperty()] + [ValidateSet('Yes','No')] + [string]$PreferredNTPServer = 'Yes' + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + if ($NSObject.Server -ne $this.Server) { + Write-Warning -Message "The NTP server name cannot be set to [$($this.Server)], resource can only be removed and recreated" + } + if ($NSObject.MinPollInterval -ne $this.MinPollInterval) { + Write-Verbose -Message "Setting Service Group MinPollInterval [$($this.MinPollInterval)]" + Set-NSNTPServer -Server $this.Server -MinPollInterval $this.MinPollInterval -Verbose:$false + } + if ($NSObject.MaxPollInterval -ne $this.MaxPollInterval) { + Write-Verbose -Message "Setting Service Group MaxPollInterval [$($this.MaxPollInterval)]" + Set-NSNTPServer -Server $this.Server -MaxPollInterval $this.MaxPollInterval -Verbose:$false + } + if ($NSObject.PreferredNTPServer -ne $this.PreferredNTPServer) { + Write-Warning -Message "The preferred NTP server cannot be set to [$($this.PreferredNTPServer)], setting can only be set manually" + } + } else { + Write-Verbose -Message "Creating resource [$($this.Name)]" + $params = @{ + server = $this.Server + minpoll = $this.MinPollInterval + maxpoll = $this.MaxPollInterval + preferredntpserver = $this.PreferredNTPServer + } + New-NSNTPServer @params -Verbose:$false -ErrorAction SilentlyContinue + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSNTPServer -Server $this.Server -ErrorAction SilentlyContinue + Write-Verbose -Message "Removing resource: $($this.Server)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Server -ne $this.Server) { + Write-Verbose -Message "Server does not match [$($NSObject.Server) <> $($this.Server)]" + $pass = $false + } + if ($NSObject.MinPollInterval -ne $this.MinPollInterval) { + Write-Verbose -Message "Min Poll Interval does not match [$($NSObject.MinPollInterval) <> $($this.MinPollInterval)]" + $pass = $false + } + if ($NSObject.MaxPollInterval -ne $this.MaxPollInterval) { + Write-Verbose -Message "Max Poll Interval does not match [$($NSObject.MaxPollInterval) <> $($this.MaxPollInterval)]" + $pass = $false + } + if ($NSObject.PreferredNTPServer -ne $this.PreferredNTPServer) { + Write-Verbose -Message "Preferred NTP Server does not match [$($NSObject.PreferredNTPServer) <> $($this.PreferredNTPServer)]" + $pass = $false + } + } else { + Write-Verbose -Message "Resource [$($this.Server)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBNTPServer]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSNTPServer -Name $this.Server -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBNTPServer]::new() + $obj.Server = $this.Server + $obj.MinPollInterval = $this.MinPollInterval + $obj.MaxPollInterval = $this.MaxPollInterval + $obj.PreferredNTPServer = $this.PreferredNTPServer + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Server = $s.serverip + $obj.MinPollInterval = $s.minpoll + $obj.MaxPollInterval = $s.maxpoll + $obj.PreferredNTPServer = $s.preferredntpserver + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBResponderPolicy { + [DscProperty(Key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty(Mandatory)] + [string]$Rule + + [DscProperty()] + [string]$Comment + + [DscProperty(Mandatory)] + [string]$Action + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne $this.Name) { + Write-Warning -Message "The Name cannot be changed to [$($this.Name)], resource can only be removed and recreated" + } + if ($NSObject.Rule -ne $this.Rule) { + Write-Verbose -Message "Setting Rule [$($this.Rule)]" + Set-NSResponderPolicy -Name $this.Name -Rule $this.Rule -Verbose:$false + } + if ($NSObject.Action -ne $this.Action) { + Write-Verbose -Message "Setting Service Group Name [$($this.MaxPollInterval)]" + Set-NSResponderPolicy -Name $this.Name -Action $this.Action -Verbose:$false + } + if ($NSObject.Comment -ne $this.Comment) { + Write-Verbose -Message "Setting monitor's Interval Type [$($this.Comment)]" + Set-NSResponderPolicy -Name $this.Name -Comment $this.Comment -Verbose:$false + } + } else { + Write-Verbose -Message "Creating resource [$($this.Name)]" + $params = @{ + name = $this.Name + rule = $this.Rule + action = $this.Action + comment = $this.Comment + } + New-NSResponderPolicy @params -ErrorAction SilentlyContinue + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSResponderPolicy -Name $NSObject.Name -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Responder Policy: $($this.Name)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne $this.Name) { + Write-Verbose -Message "Name does not match [$($NSObject.Name) <> $($this.Name)]" + $pass = $false + } + if ($NSObject.Rule -ne $this.Rule) { + Write-Verbose -Message "Rule does not match [$($NSObject.Rule) <> $($this.Rule)]" + $pass = $false + } + if ($NSObject.Action -ne $this.Action) { + Write-Verbose -Message "Action does not match [$($NSObject.Action) <> $($this.Action)]" + $pass = $false + } + } else { + Write-Verbose -Message "Responder Policy [$($this.Name)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBResponderPolicy]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSResponderPolicy -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBResponderPolicy]::new() + $obj.Name = $this.Name + $obj.Rule = $this.Rule + $obj.Action = $this.Action + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Name = $s.name + $obj.Rule = $s.rule + $obj.Action = $s.action.toString() + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBResponderAction { + [DscProperty(Key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty()] + [ValidateSet('NOOP','Redirect','RespondWith', 'RespondWithSQLOK','RespondWithSQLError','RespondWithHTMLPage')] + [string]$Type = 'NOOP' + + [DscProperty()] + [ValidateLength(0, 8191)] + [Alias('Expression')] + [string]$Target = [string]::Empty + + [DscProperty()] + [ValidateRange(100, 599)] + [int]$ResponseStatusCode + + [DscProperty()] + [ValidateLength(0, 8191)] + [string]$ReasonPhrase = [string]::Empty + + [DscProperty()] + [ValidateLength(0, 256)] + [string]$Comment = [string]::Empty + + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne $this.Name) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.Name)], resource can only be removed and recreated" + } + if ($NSObject.Type -ne $this.Type) { + Write-Verbose -Message "Setting Responder Action [$($this.Type)]" + Set-NSResponderAction -Name $this.Name -Type $this.Type -Verbose:$false + } + if ($NSObject.Target -ne $this.Target) { + Write-Verbose -Message "Setting Responder Action [$($this.Target)]" + Set-NSResponderAction -Name $this.Name -Target $this.Target -Verbose:$false + } + if ($NSObject.Comment -ne $this.Comment) { + Write-Verbose -Message "Setting Responder Action [$($this.Comment)]" + Set-NSResponderAction -Name $this.Name -Comment $this.Comment -Verbose:$false + } + } else { + Write-Verbose -Message "Creating resource [$($this.Name)]" + $params = @{ + name = $this.Name + type = $this.Type + target = $this.Target + comment = $this.Comment + } + New-NSResponderAction @params -ErrorAction SilentlyContinue + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSResponderAction -Name $NSObject.Name -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Responder Action: $($this.Name)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne $this.Name) { + Write-Verbose -Message "Name does not match [$($NSObject.Name) <> $($this.Name)]" + $pass = $false + } + if ($NSObject.Type -ne $this.Type) { + Write-Verbose -Message "Type does not match [$($NSObject.Type) <> $($this.Type)]" + $pass = $false + } + if ($NSObject.Target -ne $this.Target) { + Write-Verbose -Message "Target does not match [$($NSObject.Target) <> $($this.Target)]" + $pass = $false + } + } else { + Write-Verbose -Message "Responder Action [$($this.Name)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBResponderAction]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSResponderAction -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBResponderAction]::new() + $obj.Name = $this.Name + $obj.Type = $this.Type + $obj.Target = $this.Target + $obj.Comment = $this.Comment + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Name = $s.name + $obj.Type = $s.type + $obj.Target = $s.target + $obj.Comment = $s.comment + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBRewritePolicy { + [DscProperty(Key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty()] + [string]$ActionName + + [DscProperty()] + [string]$LogActionName + + [DscProperty()] + [ValidateLength(0, 8191)] + [Alias('Expression')] + [string]$Rule + + [DscProperty()] + [string]$Comment + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.name -ne $this.Name) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.Name)], resource can only be removed and recreated" + } + if ($NSObject.rule -ne $this.Rule) { + Write-Verbose -Message "Setting Rule [$($this.Rule)]" + Set-NSRewritePolicy -Name $this.Name -Rule $this.Rule -Verbose:$false + } + if ($NSObject.actionname -ne $this.ActionName) { + Write-Verbose -Message "Setting Action Name [$($this.ActionName)]" + Set-NSRewritePolicy -Name $this.Name -ActionName $this.ActionName -LogActionName $this.LogActionName -Rule $this.Rule -Verbose:$false + } + if ($NSObject.logActionname -ne "Use Global") { + if ($NSObject.logactionname -ne $this.LogActionName) { + Write-Verbose -Message "Setting LogActionName [$($this.LogActionName)]" + Set-NSRewritePolicy -Name $this.Name -LogActionName $this.LogActionName -Verbose:$false + } + } + if ($NSObject.Comment -ne $this.Comment) { + Write-Verbose -Message "Setting Comment [$($this.Comment)]" + Set-NSRewritePolicy -Name $this.Name -Comment $this.Comment -Verbose:$false + } + } else { + Write-Verbose -Message "Creating resource [$($this.Name)]" + $params = @{ + name = $this.Name + rule = $this.Rule + actionname = $this.ActionName + comment = $this.Comment + } + if ($PSBoundParameters.ContainsKey('LogActionName')) { + $params.Add('LogActionName', $this.LogActionName) + } + New-NSRewritePolicy @params -ErrorAction SilentlyContinue + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSRewritePolicy -Name $NSObject.Name -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Rewrite Policy: $($this.Name)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne $this.Name) { + Write-Verbose -Message "Name does not match [$($NSObject.Name) <> $($this.Name)]" + $pass = $false + } + if ($NSObject.Rule -ne $this.Rule) { + Write-Verbose -Message "Rule does not match [$($NSObject.Rule) <> $($this.Rule)]" + $pass = $false + } + if ($NSObject.ActionName -ne $this.ActionName) { + Write-Verbose -Message "Action Name does not match [$($NSObject.ActionName) <> $($this.ActionName)]" + $pass = $false + } + if ($NSObject.LogActionName -ne "Use Global") { + if ($NSObject.LogActionName -ne $this.LogActionName) { + Write-Verbose -Message "Log Action Name does not match [$($NSObject.LogActionName) <> $($this.LogActionName)]" + $pass = $false + } + } + if ($NSObject.Comment -ne $this.Comment) { + Write-Verbose -Message "Comment does not match [$($NSObject.Comment) <> $($this.Comment)]" + $pass = $false + } + } else { + Write-Verbose -Message "Responder Policy [$($this.Name)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBRewritePolicy]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSRewritePolicy -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBRewritePolicy]::new() + $obj.Name = $this.Name + $obj.Rule = $this.Rule + $obj.ActionName = $this.ActionName + $obj.LogActionName = $this.LogActionName + $obj.Comment = $this.Comment + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Name = $s.name + $obj.Rule = $s.rule + $obj.ActionName = $s.action + $obj.LogActionName = $s.logaction + $obj.Comment = $s.comment + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBRewriteAction { + [DscProperty(Key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty(Mandatory)] + [string]$Type + + [DscProperty(Mandatory)] + [ValidateLength(0, 8191)] + [string]$Target + + [DscProperty(Mandatory)] + [ValidateLength(0, 8191)] + [string]$Expression + + [DscProperty()] + [string]$Comment + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne $this.Name) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.Name)], resource can only be removed and recreated" + } + if ($NSObject.Type -ne $this.Type) { + Write-Verbose -Message "Setting Rule [$($this.Type)]" + Set-NSRewriteAction -Name $this.Name -Type $this.Type -Target $this.Target -Expression $this.Expression -Comment $this.Comment -Verbose:$false + } + if ($NSObject.Target -ne $this.Target) { + Write-Verbose -Message "Setting Action Name [$($this.Target)]" + Set-NSRewriteAction -Name $this.Name -Target $this.Target -Verbose:$false + } + if ($NSObject.Expression -ne $this.Expression) { + Write-Verbose -Message "Setting LogActionName [$($this.Expression)]" + Set-NSRewriteAction -Name $this.Name -Expression $this.Expression -Verbose:$false + } + if ($NSObject.Comment -ne $this.Comment) { + Write-Verbose -Message "Setting Comment [$($this.Comment)]" + Set-NSRewriteAction -Name $this.Name -Comment $this.Comment -Verbose:$false + } + } else { + Write-Verbose -Message "Creating resource [$($this.Name)]" + $params = @{ + name = $this.Name + Type = $this.Type.toLower() + Target = $this.Target + Expression = $this.Expression + Comment = $this.Comment + } + New-NSRewriteAction @params -ErrorAction SilentlyContinue + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSRewriteAction -Name $NSObject.Name -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Rewrite Action: $($this.Name)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.name -ne $this.Name) { + Write-Verbose -Message "Name does not match [$($NSObject.Name) <> $($this.Name)]" + $pass = $false + } + if ($NSObject.type -ne $this.Type) { + Write-Verbose -Message "Type does not match [$($NSObject.Type) <> $($this.Type)]" + $pass = $false + } + if ($NSObject.target -ne $this.Target) { + Write-Verbose -Message "Target does not match [$($NSObject.Target) <> $($this.Target)]" + $pass = $false + } + if ($NSObject.Expression -ne $this.Expression) { + Write-Verbose -Message "Expression does not match [$($NSObject.Expression) <> $($this.Expression)]" + $pass = $false + } + if ($NSObject.comment -ne $this.Comment) { + Write-Verbose -Message "Comment does not match [$($NSObject.Comment) <> $($this.Comment)]" + $pass = $false + } + } else { + Write-Verbose -Message "Responder Action [$($this.Name)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBRewriteAction]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSRewriteAction -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBRewriteAction]::new() + $obj.Name = $this.Name + $obj.Type = $this.Type + $obj.Target = $this.Target + $obj.Expression = $this.Expression + $obj.Comment = $this.Comment + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Name = $s.name + $obj.Type = $s.type + $obj.Target = $s.target + $obj.Expression = $s.stringbuilderexpr + $obj.Comment = $s.comment + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBDNSServer { + [DscProperty(Key)] + [string]$IPAddress + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty()] + [ValidateLength(0, 8191)] + [string]$Local = $false + + [DscProperty()] + [ValidateSet('ENABLED','DISABLED')] + [string]$State = 'ENABLED' + + [DscProperty()] + [ValidateSet('UDP', 'TCP', 'UDP_TCP')] + [string]$Type = 'UDP' + + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if (($NSObject.ip -ne $this.IPAddress) -OR ($NSObject.state -ne $this.State) -OR ($NSObject.type -ne $this.Type)) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.Name)], resource can only be removed and recreated. Resource deleted and re-added" + Remove-NSDnsNameServer -IPAddress $this.IPAddress -Verbose:$false -ErrorAction SilentlyContinue + Add-NSDnsNameServer -IPAddress $this.IPAddress -State $this.State -Type $this.Type -Verbose:$false -ErrorAction SilentlyContinue + } + } else { + Write-Verbose -Message "Creating resource [$($this.IPAddress)]" + $params = @{ + ip = $this.IPAddress + type = $this.Type + state = $this.State + } + Add-NSDnsNameServer @params -Verbose:$false -ErrorAction SilentlyContinue + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSDnsNameServer -IPAddress $this.IPAddress -Verbose:$false -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed DNS Server: $($this.IPAddress)" + } + } + + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + if ($NSObject.IPAddress -ne $this.IPAddress) { + Write-Verbose -Message "IP Address does not match [$($NSObject.IPAddress) <> $($this.IPAddress)]" + $pass = $false + } + if ($NSObject.Local -ne $this.Local) { + Write-Verbose -Message "Local does not match [$($NSObject.Local) <> $($this.Local)]" + $pass = $false + } + if ($NSObject.State -ne $this.State) { + Write-Verbose -Message "State does not match [$($NSObject.State) <> $($this.State)]" + $pass = $false + } + if ($NSObject.Type -ne $this.Type) { + Write-Verbose -Message "Type does not match [$($NSObject.Type) <> $($this.Type)]" + $pass = $false + } + } else { + Write-Verbose -Message "DNS server [$($this.IPAddress)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBDNSServer]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSDnsNameServer | where {$_.ip -eq $this.IPAddress} -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBDNSServer]::new() + $obj.IPAddress = $this.IPAddress + $obj.Local = $this.Local + $obj.State = $this.State + $obj.Type = $this.Type + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.IPAddress = $s.ip + $obj.Local = $s.local + $obj.State = $s.state + $obj.Type = $s.type + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBNSMode { + [DscProperty(Key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne "True") { + Write-Verbose -Message "Mode enabled, [$($this.Name)]" + Enable-NSMode -name $this.name -Confirm:$false + } + } else { + Write-Verbose -Message "Mode enabled, [$($this.Name)]" + Enable-NSMode -name $this.name -Confirm:$false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Disable-NSMode -Name $this.Name -Confirm:$false + Write-Verbose -Message "Mode disabled: $($this.Name)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne "True") { + Write-Verbose -Message "Mode is not set [$($NSObject.Name) <> $($this.Name)]" + $pass = $false + } + } else { + $pass = $false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } else { + if ($NSObject.Name -eq "True") { + $pass = $false + } + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBNSMode]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSMode -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBNSMode]::new() + $obj.Name = $this.Name + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Name = $s + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBNSFeature { + [DscProperty(Key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne "True") { + Write-Verbose -Message "Feature enabled, [$($this.Name)]" + Enable-NSFeature -name $this.name -Confirm:$false + } + } else { + Write-Verbose -Message "Feature enabled, [$($this.Name)]" + Enable-NSFeature -name $this.name -Confirm:$false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Disable-NSFeature -Name $this.Name -Confirm:$false + Write-Verbose -Message "Feature disabled: $($this.Name)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne "True") { + Write-Verbose -Message "Feature is not set [$($NSObject.Name) <> $($this.Name)]" + $pass = $false + } + } else { + $pass = $false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } else { + if ($NSObject.Name -eq "True") { + $pass = $false + } + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBNSFeature]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSFeature -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBNSFeature]::new() + $obj.Name = $this.Name + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Name = $s.name + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBSSLCertificate { + [DscProperty(Key)] + [string]$CertKeyName + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty()] + [string]$CertPath + + [DscProperty()] + [string]$KeyPath + + [DscProperty()] + [ValidateSet('PEM','DER','PFX')] + [string]$CertKeyFormat = 'PEM' + + [DscProperty()] + [securestring]$Password + + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if (($NSObject.CertKeyName -ne $this.CertKeyName) -OR ($NSObject.CertPath -ne $this.CertPath) -OR ($NSObject.KeyPath -ne $this.KeyPath) -OR ($NSObject.CertKeyFormat -ne $this.CertKeyFormat)) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.CertKeyName)], resource can only be removed and recreated" + Remove-NSCertKeyPair -CertKeyName $this.CertKeyName + } + } else { + Write-Verbose -Message "Creating resource [$($this.CertKeyName)]" + $params = @{ + CertKeyName = $this.CertKeyName + CertPath = $this.CertPath + KeyPath = $this.KeyPath + CertKeyFormat = $this.CertKeyFormat + } + Add-NSCertKeyPair @params -ErrorAction SilentlyContinue + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSResponderAction -Name $NSObject.CertKeyName -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Certificate: $($this.Name)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.certkeyname -ne $this.CertKeyName) { + Write-Verbose -Message "Certificate Key Name does not match [$($NSObject.certkeyname) <> $($this.CertKeyName)]" + $pass = $false + } + if ($NSObject.certpath -ne $this.CertPath) { + Write-Verbose -Message "Certificate Path does not match [$($NSObject.certpath) <> $($this.CertPath)]" + $pass = $false + } + if ($this.KeyPath) { + if ($NSObject.keypath -ne $this.KeyPath) { + Write-Verbose -Message "Key Path does not match [$($NSObject.keypath) <> $($this.KeyPath)]" + $pass = $false + } + } + } else { + Write-Verbose -Message "Certificate[$($this.CertKeyName)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBSSLCertificate]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSCertKeyPair -CertKeyName $this.CertKeyName -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + $obj = [LBSSLCertificate]::new() + $obj.CertKeyName = $this.CertKeyName + $obj.CertPath = $this.CertPath + $obj.CertKeyFormat = $this.CertKeyFormat + $obj.KeyPath = $this.KeyPath + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.CertKeyName = $s.certkey + $obj.CertPath = $s.cert + $obj.CertKeyFormat = $s.inform + if ($s.key) { + $obj.KeyPath = $s.key + } + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBNSIP { + [DscProperty(Key)] + [string]$IPAddress + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty(Mandatory)] + [string]$SubnetMask + + [DscProperty()] + [string]$Type = 'SNIP' + + [DscProperty(Mandatory)] + [bool]$VServer = $false + + [DscProperty(Mandatory)] + [bool]$Telnet = $false + + [DscProperty(Mandatory)] + [bool]$FTP = $false + + [DscProperty(Mandatory)] + [bool]$GUI = $false + + [DscProperty(Mandatory)] + [bool]$SSH = $false + + [DscProperty(Mandatory)] + [bool]$SNMP = $false + + [DscProperty(Mandatory)] + [bool]$MgmtAccess = $false + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.IPAddressName -ne $this.IPAddress) { + Write-Verbose -Message "Warning, the resource cannot be set to [$($this.IPAddress)]" + } + if ($NSObject.SubnetMask -ne $this.SubnetMask) { + Write-Verbose -Message "Resource name does not match [$($this.SubnetMask)]" + Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask + } + if ($NSObject.Type -ne $this.Type) { + Write-Verbose -Message "Warning, the resource cannot be set to [$($this.Type)]" + } + if ($NSObject.VServer -ne $this.VServer) { + Write-Verbose -Message "Setting vServer [$($this.VServer)]" + Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -VServer + } + if ($NSObject.Telnet -ne $this.Telnet) { + Write-Verbose -Message "Setting Telnet [$($this.Telnet)]" + Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -Telnet + } + if ($NSObject.FTP -ne $this.FTP) { + Write-Verbose -Message "Setting FTP [$($this.FTP)]" + Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -FTP + } + if ($NSObject.GUI -ne $this.GUI) { + Write-Verbose -Message "Setting GUI [$($this.GUI)]" + Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -GUI + } + if ($NSObject.SSH -ne $this.SSH) { + Write-Verbose -Message "Setting GUI [$($this.SSH)]" + Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -SSH + } + if ($NSObject.SNMP -ne $this.SNMP) { + Write-Verbose -Message "Setting SNMP [$($this.SNMP)]" + Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -SNMP + } + if ($NSObject.MgmtAccess -ne $this.MgmtAccess) { + Write-Verbose -Message "Setting Management Access [$($this.MgmtAccess)]" + Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -MgmtAccess + } + } else { + Write-Verbose -Message "Feature enabled, [$($this.IPAddress)]" + $params = @{ + ipaddress = $this.IPAddress + netmask = $this.SubnetMask + type = $this.Type + } + Add-NSIPResource @params -Confirm:$false + # $switches { + # ipaddress = $this.IPAddress + # netmask = $this.SubnetMask + # type = $this.Type + # vserver = $this.VServer + # telnet = $this.Telnet + # ftp = $this.FTP + # gui = $this.GUI + # ssh = $this.SSH + # snmp = $this.SNMP + # mgmtaccess = $this.mgmtaccess + # } + # Invoke-DscResource -Method set -ModuleName poshorigin_netscaler -Name LBNSIP -Property $switches + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Disable-NSFeature -Name $this.Name -Confirm:$false + Write-Verbose -Message "Feature disabled: $($this.Name)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # # Run tests and set any needed attributes to match desired configuration + if ($NSObject.ipaddress -ne $this.IPAddress) { + Write-Verbose -Message "IPAddress does not match [$($NSObject.ipaddress) <> $($this.IPAddress)]" + $pass = $false + } + if ($NSObject.subnetmask -ne $this.SubnetMask) { + Write-Verbose -Message "SubnetMask does not match [$($NSObject.subnetmask) <> $($this.SubnetMask)]" + $pass = $false + } + if ($NSObject.type -ne $this.Type) { + Write-Verbose -Message "Type does not match [$($NSObject.type) <> $($this.Type)]" + $pass = $false + } + if ($NSObject.vserver -ne $this.VServer) { + Write-Verbose -Message "VServer does not match [$($NSObject.vserver) <> $($this.VServer)]" + $pass = $false + } + if ($NSObject.telnet -ne $this.Telnet) { + Write-Verbose -Message "Telnet does not match [$($NSObject.telnet) <> $($this.Telnet)]" + $pass = $false + } + if ($NSObject.ftp -ne $this.FTP) { + Write-Verbose -Message "FTP does not match [$($NSObject.ftp) <> $($this.FTP)]" + $pass = $false + } + if ($NSObject.gui -ne $this.GUI) { + Write-Verbose -Message "GUI does not match [$($NSObject.gui) <> $($this.GUI)]" + $pass = $false + } + if ($NSObject.ssh -ne $this.SSH) { + Write-Verbose -Message "SSH does not match [$($NSObject.ssh) <> $($this.SSH)]" + $pass = $false + } + if ($NSObject.snmp -ne $this.SNMP) { + Write-Verbose -Message "SNMP does not match [$($NSObject.snmp) <> $($this.SNMP)]" + $pass = $false + } + if ($NSObject.mgmtaccess -ne $this.MgmtAccess) { + Write-Verbose -Message "MgmtAccess does not match [$($NSObject.mgmtaccess) <> $($this.MgmtAccess)]" + $pass = $false + } + } else { + $pass = $false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } else { + if ($NSObject.Name -eq "True") { + $pass = $false + } + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBNSIP]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSIPResource -IPAddress $this.IPAddress -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBNSIP]::new() + $obj.IPAddress = $this.IPAddress + $obj.SubnetMask = $this.SubnetMask + $obj.Type = $this.Type + $obj.VServer = $this.VServer + $obj.Telnet = $this.Telnet + $obj.FTP = $this.FTP + $obj.GUI = $this.GUI + $obj.SSH = $this.SSH + $obj.SNMP = $this.SNMP + $obj.MgmtAccess = $this.MgmtAccess + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.IPAddress = $s.ipaddress + $obj.SubnetMask = $s.netmask + $obj.Type = $s.type + $obj.VServer = $this.TestEnabledFeatures($s.VServer) + $obj.Telnet = $this.TestEnabledFeatures($s.Telnet) + $obj.FTP = $this.TestEnabledFeatures($s.FTP) + $obj.GUI = $this.TestEnabledFeatures($s.GUI) + $obj.SSH = $this.TestEnabledFeatures($s.SSH) + $obj.SNMP = $this.TestEnabledFeatures($s.SNMP) + $obj.MgmtAccess = $this.TestEnabledFeatures($s.MgmtAccess) + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } + + <# + Helper method to test switch/boolean options + #> + [bool] TestEnabledFeatures([string] $Existing){ + # $present = $true + if ($Existing -eq "ENABLED") { + $present = $true + } else { + $present = $false + } + return $present + } +} + + +[DscResource()] +class LBNSVirtualServerBinding { + [DscProperty(Key)] + [string]$VirtualServerName + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty()] + [string]$ServiceGroupName + + [DscProperty()] + [string]$ServiceName + + [DscProperty()] + [int]$Weight = 1 + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -ne $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($this.ServiceGroupName -eq $NSObject.ServiceGroupName) { + Write-Verbose -Message "Service Group Name bound, [$($this.VirtualServerName)]" + Add-NSLBVirtualServerBinding -VirtualServerName $this.VirtualServerName -ServiceGroupName $this.ServiceGroupName -Weight $this.Weight -Confirm:$false + } else { + if (($this.ServiceName -ne $null) -OR ($NSObject.NetScalerFQDN -ne $null)) { + Write-Verbose -Message "Service Name bound, [$($this.ServiceName)]" + Add-NSLBVirtualServerBinding -VirtualServerName $this.VirtualServerName -ServiceName $this.ServiceName -Weight $this.Weight -Confirm:$false + } + } + } + } 'Absent' { + if ($this.ServiceGroupName) { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSLBVirtualServerBinding -name $this.VirtualServerName -ServiceGroupName $this.ServiceGroupName -Confirm:$false + Write-Verbose -Message "Virtual Server Binding removed for $($this.VirtualServerName)" + } + } else { + Remove-NSLBVirtualServerBinding -name $this.VirtualServerName -ServiceName $this.ServiceName -Confirm:$false + Write-Verbose -Message "Virtual Server Binding removed for $($this.VirtualServerName)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ } - # Try to get the server - $server = Get-NSLBServer -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue - - if ($this.Ensure = [Ensure]::Present) { - if ($server) { - Write-Verbose -Message "Server [$($this.Name)] exists" - # Run tests against server - if ($server.ipaddress -ne $this.IPAddress) { - Write-Verbose -Message "Server IP address does not match [$($server.ipaddress) <> $($this.IPAddress)]" - $pass = $false - } - if ($server.comment -ne $this.Comments) { - Write-Verbose -Message "Server comments do not match [$($server.comment) <> $($this.Comments)]" - $pass = $false - } - if ($server.td -ne $this.TrafficDomainid) { - Write-Verbose -Message "Server traffic domain ID does not match [$($server.td) <> $($this.TrafficDomainId)]" - $pass = $false - } - if ($server.state -ne $this.State) { - Write-Verbose -Message "Server state does not match [$($server.state) <> $($this.State)]" - $pass = $false - } - } else { - Write-Verbose -Message "Server [$($this.Name)] not found" - $pass = $false - } - } else { - if ($server) { - $pass = $false - } - } - - # Export the resource parameters if told to. - # These values can be used by other DSC resources down the chain - if ($this.ParameterExport) { - $fileName = "LBServer_$($this.Name).json" - $json = $this.Get() | ConvertTo-Json - $folder = Join-Path -Path $env:USERPROFILE -ChildPath '.poshorigin' - if (-Not (Test-Path -Path $folder)) { - New-Item -ItemType Directory -Path $folder -Force - } - $fullPath = Join-Path -Path $folder -ChildPath $fileName - Write-Verbose -Message "Exporting parameters to [$fullPath]" - $json | Out-File -FilePath $fullPath -Force - } - try { Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue } catch { # Do nothing } + } - return $pass + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($this.servicegroupname -eq $NSObject.ServiceGroupName) { + if ($NSObject.virtualservername -ne $this.VirtualServerName) { + Write-Verbose -Message "VirtualServerName does not match [$($NSObject.virtualservername) <> $($this.VirtualServerName)]" + $pass = $false + } + if ($NSObject.servicegroupname -ne $this.ServiceGroupName) { + Write-Verbose -Message "ServiceGroupName does not match [$($NSObject.servicegroupname) <> $($this.ServiceGroupName)]" + $pass = $false + } + } else { + if ($NSObject.virtualservername -ne $this.VirtualServerName) { + Write-Verbose -Message "VirtualServerName does not match [$($NSObject.virtualservername) <> $($this.VirtualServerName)]" + $pass = $false + } + if ($NSObject.servicename -ne $this.ServiceName) { + Write-Verbose -Message "ServiceName does not match [$($NSObject.servicename) <> $($this.ServiceName)]" + $pass = $false + } + } + } else { + $pass = $false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } else { + if ($NSObject.Name -eq "True") { + $pass = $false + } + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass } - [LBServer]Get() { - [ref]$t = $null - if ([ipaddress]::TryParse($this.NetScalerFQDN,$t)) { - Connect-NetScaler -IPAddress $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + [LBNSVirtualServerBinding]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSLBVirtualServerBinding -Name $this.VirtualServerName -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBNSVirtualServerBinding]::new() + $obj.VirtualServerName = $this.VirtualServerName + $obj.ServiceGroupName = $this.ServiceGroupName + $obj.ServiceName = $this.ServiceName + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.VirtualServerName = $s.name + $obj.ServiceGroupName = $s.ServiceGroupName + $obj.ServiceName = $s.ServiceName } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + + +[DscResource()] +class LBSystemFile { + [DscProperty(Key)] + [string]$FileName + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty(Mandatory)] + [string]$FileLocation + + [DscProperty(Mandatory)] + [string]$Path + + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" } + } - $s = Get-NSLBServer -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() - $obj = [LBServer]::new() - $obj.Name = $this.Name - $obj.IPAddress = $this.IPAddress - $obj.Comments = $this.Comments - $obj.TrafficDomainId = $this.TrafficDomainId - $obj.State = $this.State - $obj.Credential = $this.Credential - $obj.NetScalerFQDN = $this.NetScalerFQDN - $obj.ParameterExport = $this.ParameterExport + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($NSObject.Ensure -ne $this.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if (!$NSObject.FileName) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.FileName)], resource can only be removed and recreated" + Add-NSSystemFile -Path $this.Path -FileLocation $this.FileLocation -FileName $this.FileName -Force + } + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSSystemFile -Name $this.FileName -FileLocation $this.FileLocation -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed File: $($this.Name)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.filename -ne $this.FileName) { + Write-Verbose -Message "File Name does not match [$($NSObject.filename) <> $($this.FileName)]" + $pass = $false + } + if ($NSObject.filelocation -ne $this.FileLocation) { + Write-Verbose -Message "File Location does not match [$($NSObject.filelocation) <> $($this.FileLocation)]" + $pass = $false + } + } else { + Write-Verbose -Message "File[$($this.FileName)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBSystemFile]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSSystemFile -FileName $this.FileName -FileLocation $this.FileLocation -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBSystemFile]::new() + $obj.FileName + $obj.FileLocation + $obj.Path if ($s) { $obj.Ensure = [ensure]::Present - $obj.IPAddress = $s.ipv46 - $obj.comments = $s.comment - $obj.TrafficDomainId = $s.td - $obj.State = $s.state + $obj.FileName = $s.filename + $obj.FileLocation = $s.filelocation + if ($s.Path) { + $obj.Path = $s.path + } } else { $obj.Ensure = [ensure]::Absent } @@ -847,3 +3604,203 @@ class LBMonitor { return $obj } } + +[DscResource()] +class LBVLAN { + [DscProperty(Key)] + [int]$VLANID + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty(Mandatory)] + [string]$AliasName + + [DscProperty()] + [ValidateSet('ENABLED','DISABLED')] + [string]$IPV6DynamicRouting = 'DISABLED' + + [DscProperty(Mandatory)] + [int]$MTU + + [DscProperty()] + [string]$Interface + + [DscProperty()] + [bool]$Tagged = $false + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.vlanid -ne $this.VLANID) { + Write-Warning -Message "Setting VLANID cannot be changed to [$($this.VLANID)], resource can only be removed and recreated" + } + if ($NSObject.aliasname -ne $this.AliasName) { + Write-Verbose -Message "Setting AliasName [$($this.AliasName)]" + Set-NSVLAN -VLANID $this.VLANID -AliasName $this.AliasName + } + if ($NSObject.mtu -ne $this.AliasName) { + Write-Verbose -Message "Setting AliasName [$($this.AliasName)]" + Set-NSVLAN -VLANID $this.VLANID -AliasName $this.AliasName + } + if ($NSObject.ipv6dynamicrouting -ne $this.IPV6DynamicRouting) { + Write-Verbose -Message "Setting AliasName [$($this.IPV6DynamicRouting)]" + Set-NSVLAN -VLANID $this.VLANID -IPV6DynamicRouting $this.IPV6DynamicRouting + } + if ($NSObject.mtu -ne $this.MTU) { + Write-Verbose -Message "Setting AliasName [$($this.MTU)]" + Set-NSVLAN -VLANID $this.VLANID -MTU $this.MTU + } + if ($NSObject.interface -ne $this.Interface) { + Write-Verbose -Message "Setting Interface [$($this.Interface)]" + Set-NSVLANInterfaceBinding -VLANID $this.VLANID -Interface $this.Interface + } + } else { + Write-Verbose -Message "Feature enabled, [$($this.IPAddress)]" + $params = @{ + vlanid = $this.VLANID + aliasname = $this.AliasName + ipv6dynamicrouting = $this.ipv6dynamicrouting + mtu = $this.MTU + interface = $this.Interface + } + Add-NSVLAN @params -Confirm:$false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSVLAN -VLANID $this.VLANID -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed VLANID: $($this.VLANID)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.vlanid -ne $this.VLANID) { + Write-Verbose -Message "VLANID does not match [$($NSObject.vlanid) <> $($this.VLANID)]" + $pass = $false + } + if ($NSObject.aliasname -ne $this.AliasName) { + Write-Verbose -Message "Aliasname does not match [$($NSObject.aliasname) <> $($this.AliasName)]" + $pass = $false + } + if ($NSObject.ipv6dynamicrouting -ne $this.IPV6DynamicRouting) { + Write-Verbose -Message "IPV6 Dynamic Routing does not match [$($NSObject.ipv6dynamicrouting) <> $($this.IPV6DynamicRouting)]" + $pass = $false + } + if ($NSObject.mtu -ne $this.MTU) { + Write-Verbose -Message "MTU does not match [$($NSObject.mtu) <> $($this.MTU)]" + $pass = $false + } + if ($NSObject.interface -ne $this.Interface) { + Write-Verbose -Message "Interface does not match [$($NSObject.interface) <> $($this.Interface)]" + $pass = $false + } + if ($NSObject.tagged -ne $this.Tagged) { + Write-Verbose -Message "Tagged does not match [$($NSObject.Tagged) <> $($this.Tagged)]" + $pass = $false + } + } else { + Write-Verbose -Message "File[$($this.VLANID)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBVLAN]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSVLAN -VLANID $this.VLANID -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBVLAN]::new() + $obj.VLANID = $this.VLANID + $obj.AliasName = $this.AliasName + $obj.IPV6DynamicRouting = $this.IPV6DynamicRouting + $obj.MTU = $this.MTU + $obj.Interface = $this.Interface + $obj.Tagged = $this.Tagged + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.VLANID = $s.id + if ($s.AliasName) { $obj.AliasName = $s.aliasname } + $obj.IPV6DynamicRouting = $s.ipv6dynamicrouting + if ($s.mtu) { $obj.MTU = $s.mtu } + $obj.Interface = $s.ifaces.ToString() + $obj.Tagged = $s.tagged + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} \ No newline at end of file From 6bcd04e3f080c9d30148d0866575d021095585b0 Mon Sep 17 00:00:00 2001 From: Juan Herrera Date: Mon, 12 Jun 2017 23:03:18 -0700 Subject: [PATCH 3/7] added new functions and commented not working ones --- POSHOrigin_NetScaler/Examples/holdup.ps1 | 532 ++++++++ .../POSHOrigin_NetScaler.psm1 | 1212 ++++++++--------- 2 files changed, 1138 insertions(+), 606 deletions(-) create mode 100644 POSHOrigin_NetScaler/Examples/holdup.ps1 diff --git a/POSHOrigin_NetScaler/Examples/holdup.ps1 b/POSHOrigin_NetScaler/Examples/holdup.ps1 new file mode 100644 index 0000000..770026f --- /dev/null +++ b/POSHOrigin_NetScaler/Examples/holdup.ps1 @@ -0,0 +1,532 @@ +[DscResource()] +class LBVirtualServer { + [DscProperty(key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [string]$IPAddress + + [DscProperty(Mandatory)] + [ValidateRange(1, 65534)] + [int]$Port + + [DscProperty()] + [ValidateSet('DHCPRA','DIAMTER', 'DNS', 'DNS_TCP', 'DLTS', 'FTP', 'HTTP', 'MSSQL', + 'MYSQL', 'NNTP', 'PUSH','RADIUS', 'RDP', 'RTSP', 'SIP_UDP', 'SSL', 'SSL_BRIDGE', + 'SSL_DIAMETER', 'SSL_PUSH', 'SSL_TCP', 'TCP', 'TFTP', 'UDP')] + [string]$ServiceType = 'HTTP' + + [DscProperty()] + [ValidateSet('ROUNDROBIN', 'LEASTCONNECTION', 'LEASTRESPONSETIME', 'LEASTBANDWIDTH', + 'LEASTPACKETS', 'CUSTOMLOAD', 'LRTM', 'URLHASH', 'DOMAINHASH', 'DESTINATIONIPHASH', + 'SOURCEIPHASH', 'TOKEN', 'SRCIPDESTIPHASH', 'SRCIPSRCPORTHASH', 'CALLIDHASH')] + [string]$LBMethod = 'ROUNDROBIN' + + [DscProperty()] + [string]$Service + + [DscProperty()] + [string]$ServiceGroup + + [DscProperty()] + [ValidateLength(0, 256)] + [string]$Comments = [string]::Empty + + [DscProperty()] + #[ValidateSet('ENABLED', 'DISABLED', '')] + [string]$State = 'ENABLED' + + [DscProperty()] + [bool]$ParameterExport = $false + + [LBVirtualServer]Get() { + [ref]$t = $null + if ([ipaddress]::TryParse($this.NetScalerFQDN)) { + Connect-NetScaler -IPAddress $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } else { + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } + + $vip = Get-NSLBVirtualServer -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + + $obj = [LBVirtualServer]::new() + $obj.Name = $this.Name + $obj.IPAddress = $this.IPAddress + $obj.NetScalerFQDN = $this.NetScalerFQDN + $obj.Credential = $this.Credential + $obj.ParameterExport = $this.ParameterExport + if ($vip) { + $obj.Ensure = [ensure]::Present + $obj.Port = $vip.port + $obj.ServiceType = $vip.servicetype + $obj.LBMethod = $vip.lbmethod + $obj.State = $vip.curstate + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } + + [void]Set() { + try { + $vip = $this.Get() + + switch ($this.Ensure) { + 'Present' { + [ref]$t = $null + if ([ipaddress]::TryParse($this.NetScalerFQDN)) { + Connect-NetScaler -IPAddress $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } else { + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } + + # Does the record already exist? + if ($vip.Ensure -ne [ensure]::Present) { + # Create VIP + Write-Verbose -Message "Creating virtual server [$($this.Name)]" + $params = @{ + Name = $this.Name + IPAddress = $this.IPAddress + ServiceType = $this.ServiceType + Port = $this.Port + LBMethod = $this.LBMethod + Comment = $this.Comments + Verbose = $false + Confirm = $false + } + New-NSLBVirtualServer @params + $vip = $this.Get() + [ref]$t = $null + if ([ipaddress]::TryParse($this.NetScalerFQDN)) { + Connect-NetScaler -IPAddress $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } else { + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } + } + + # Run tests and set any needed attributes to match desired configuration + + # IP check + if ($vip.IPAddress -ne $this.IPAddress) { + Set-NSLBVirtualServer -Name $this.Name -IPAddress $this.IPAddress -Verbose:$false -Confirm:$false + Write-Verbose -Message "Setting virtual server IP [$($this.IPAddress)]" + } + + # Port check + if ($vip.Port -ne $this.Port) { + Write-Warning -Message 'NetScaler does not support changing virtual server port on an existing virtual server. Virtual server must be deleted and recreated.' + } + + # Service type check + if ($vip.ServiceType -ne $this.ServiceType) { + Write-Warning -Message 'NetScaler does not support changing virtual server service type on an existing virtual server. Virtual server must be deleted and recreated.' + } + + # LB method check + if ($vip.LBMethod -ne $this.LBMethod) { + Set-NSLBVirtualServer -Name $this.Name -LBMethod $this.LBMethod -Verbose:$false -Force + Write-Verbose -Message "Setting virtual server load balance method [$($this.LBMethod)]" + } + + # Comments check + if ($vip.Comments -ne $this.Comments) { + Write-Verbose -Message "Setting virtual server comments [$($this.Comments)]" + Set-NSLBVirtualServer -Name $this.Name -Comment $this.Comments -Verbose:$false -Force + } + + # Service group binding check + $bindings = Get-NSLBVirtualServerBinding -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + $sgBinding = $bindings | where servicegroupname -eq $this.ServiceGroup + if ($this.ServiceGroup) { + if (-Not $sgBinding) { + Write-Verbose -Message "Adding virtual server service group binding [$($this.ServiceGroup)]" + Add-NSLBVirtualServerBinding -VirtualServerName $this.Name -ServiceGroupName $this.ServiceGroup -Verbose:$false -Force + } + } + + # Service binding check + $bindings = Get-NSLBVirtualServerBinding -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + $serviceBinding = $bindings | where servicename -eq $this.Service + if ($this.Service) { + if (-Not $serviceBinding) { + Write-Verbose -Message "Adding virtual server service binding [$($this.Service)]" + Add-NSLBVirtualServerBinding -VirtualServerName $this.Name -ServiceName $this.Service -Verbose:$false -Force + } + } + + # State check + if ($vip.State -ne 'DOWN') { + if ($vip.State -ne $this.State) { + Write-Verbose -Message "Setting virtual server state [$($this.State)]" + if ($this.State -eq 'ENABLED') { + Enable-NSLBVirtualServer -Name $this.Name -Verbose:$false -Force + # Check that the enable worked + $vip2 = Get-NSLBVirtualServer -Name $this.Name -Verbose:$false + if (-Not $vip2.State -eq 'ENABLED') { + Write-Error -Message "Enabling the virtual server was unsuccessful. The current state is $($vip.curstate)" + } + } else { + Disable-NSLBVirtualServer -Name $this.Name -Verbose:$false -Force + } + } + } + } + 'Absent' { + if ($vip.Ensure -eq [ensure]::Present) { + # Remove VIP + Write-Verbose -Message "Removing virtual server: $($this.Name)" + Remove-NSLBVirtualServer -Name $this.Name -Verbose:$false -Force + } else { + # Do nothing + } + } + } + + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + } + + [bool]Test() { + + $vip = $this.Get() + $pass = $true + try { + Write-Verbose -Message "Validating that virtual server $($this.Name) is $($this.Ensure.ToString().ToLower())" + if ($this.Ensure -ne $vip.Ensure) { return $false } + + if ($this.Ensure -eq [Ensure]::Present) { + if ($null -ne $vip) { + Write-Verbose -Message "VIP [$($this.Name)] exists" + $bindings = Get-NSLBVirtualServerBinding -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + + # IP check + if ($vip.IPAddress -ne $this.IPAddress) { + Write-Verbose -Message "Virtual server IP address does not match [$($vip.IPAddress) <> $($this.IPAddress)" + $pass = $false + } + + # Port check + if ($vip.Port -ne $this.Port) { + Write-Verbose -Message "Virtual server port does not match [$($vip.port) <> $($this.Port)" + $pass = $false + } + + # Service type check + if ($vip.ServiceType -ne $this.ServiceType) { + Write-Verbose -Message "Virtual server service type does not match [$($vip.servicetype) <> $($this.ServiceType)" + $pass = $false + } + + # LB method check + if ($vip.LBMethod -ne $this.LBMethod) { + Write-Verbose -Message "Virtual server load balance method does not match [$($vip.lbmethod) <> $($this.LBMethod)" + $pass = $false + } + + # Comment check + if ($vip.comment -ne $this.Comments) { + Write-Verbose -Message "Virtual server comments do not match [$($vip.comment) <> $($this.Comments)]" + $pass = $false + } + + # Service group binding check + if ($this.ServiceGroup) { + $sgBinding = $bindings | where servicegroupname -eq $this.ServiceGroup + if (-Not $sgBinding) { + Write-Verbose -Message 'Virtual server has no service group binding' + $pass = $false + } else { + if ($sgBinding.servicegroupname -ne $this.ServiceGroup) { + Write-Verbose -Message "Virtual server binding service group does not match [$($sgBinding.servicegroupname) <> $($this.ServiceGroup)]" + $pass = $false + } + } + } else { + if ($this.Service) { + $unknownBindings = $bindings | where servicename -ne $this.Service + if ($unknownBindings) { + $pass = $false + foreach ($unknownBinding in $unknownBindings) { + Write-Verbose -Message "Virtual server service group binding exists [$($unknownBinding.servicegroupname)] and should not" + } + } + } + } + + # Service binding check + $serviceBinding = $bindings | where servicename -eq $this.Service + if ($this.Service) { + if (-Not $serviceBinding) { + Write-Verbose -Message 'Virtual server has no service binding' + $pass = $false + } else { + if ($serviceBinding.servicename -ne $this.Service) { + Write-Verbose -Message "Virtual server binding service does not match [$($serviceBinding.servicename) <> $($this.Service)]" + $pass = $false + } + } + } else { + if ($this.Service) { + $unknownBindings = $bindings | where servicegroupname -ne $this.ServiceGroup + if ($unknownBindings) { + $pass = $false + foreach ($unknownBinding in $unknownBindings) { + Write-Verbose -Message "Virtual server service group binding exists [$($unknownBinding.servicegroupname)] and should not" + } + } + } + } + + # State check + if ($vip.curstate -ne 'DOWN') { + if ($this.State -eq 'DISABLED') { $this.State = 'OUT OF SERVICE'} + if ($vip.curstate -ne $this.State) { + Write-Verbose -Message "Virtual server state does not match [$($vip.curstate) <> $($this.State)]" + $pass = $false + } + } + } else { + Write-Verbose -Message "VIP [$($this.Name)] not found" + $pass = $false + } + } + } + catch { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + #return $true + } + + # Export the resource parameters if told to. + # These values can be used by other DSC resources down the chain + if ($this.ParameterExport) { + $fileName = "LBVirtualServer_$($this.Name).json" + $json = $this.Get() | ConvertTo-Json + $folder = Join-Path -Path $env:USERPROFILE -ChildPath '.poshorigin' + if (-Not (Test-Path -Path $folder)) { + New-Item -ItemType Directory -Path $folder -Force + } + $fullPath = Join-Path -Path $folder -ChildPath $fileName + Write-Verbose -Message "Exporting parameters to [$fullPath]" + $json | Out-File -FilePath $fullPath -Force + } + + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + +} + + +[DscResource()] +class LBServer { + [DscProperty(Key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [string]$IPAddress + + [DscProperty()] + [ValidateLength(0, 256)] + [string]$Comments = '' + + [DscProperty()] + [ValidateRange(0, 4094)] + [int]$TrafficDomainId + + [DscProperty()] + [ValidateSet('ENABLED', 'DISABLED')] + [string]$State = 'ENABLED' + + [DscProperty()] + [bool]$ParameterExport = $false + + + [void]Set() { + try { + # [ref]$t = $null + # if ([ipaddress]::TryParse($this.NetScalerFQDN)) { + # Connect-NetScaler -IPAddress $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + # } else { + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + # } + # Try to get the server + try { + $server = Get-NSLBServer -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $server = $null + } + + if ($null -ne $server) { + # Run tests and set any needed attributes to match desired configuration + if ($server.ipaddress -ne $this.IPAddress) { + Write-Verbose -Message "Setting server IP [$($this.IPAddress)]" + Set-NSLBServer -Name $this.Name -IPAddress $this.IPAddress -Force -Verbose:$false + } + if ($server.comment -ne $this.Comments) { + Write-Verbose -Message "Setting server comments [$($this.Comments)]" + Set-NSLBServer -Name $this.Name -Comment $this.Comments -Force -Verbose:$false + } + if ($server.state -ne $this.State) { + Write-Verbose -Message "Setting server state [$($this.State)]" + if ($this.State -eq 'ENABLED') { + Enable-NSLBServer -Name $this.Name -Force -Verbose:$false + } else { + Disable-NSLBServer -Name $this.Name -Force -Verbose:$false + } + } + } else { + Write-Verbose -Message "Creating server [$($this.Name)]" + $params = @{ + Name = $this.Name + IPAddress = $this.IPAddress + Comment = $this.Comments + Confirm = $false + Verbose = $false + } + if ($null -ne $this.TrafficDomainId) { + $params.TrafficDomainId = $this.TrafficDomainId + } + New-NSLBServer @params + } + + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + + $pass = $true + + + Connect-NetScaler -IPAddress $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + try { + $server = Get-NSLBServer -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $server = $null + } + + # Try to get the server + + + if ($this.Ensure = [ensure]::Present) { + if ($server) { + Write-Verbose -Message "Server [$($this.Name)] exists" + # Run tests against server + if ($server.ipaddress -ne $this.IPAddress) { + Write-Verbose -Message "Server IP address does not match [$($server.ipaddress) <> $($this.IPAddress)]" + $pass = $false + } + if ($server.comment -ne $this.Comments) { + Write-Verbose -Message "Server comments do not match [$($server.comment) <> $($this.Comments)]" + $pass = $false + } + if ($server.td -ne $this.TrafficDomainid) { + Write-Verbose -Message "Server traffic domain ID does not match [$($server.td) <> $($this.TrafficDomainId)]" + $pass = $false + } + if ($server.state -ne $this.State) { + Write-Verbose -Message "Server state does not match [$($server.state) <> $($this.State)]" + $pass = $false + } + } else { + Write-Verbose -Message "Server [$($this.Name)] not found" + $pass = $false + } + } else { + if ($server) { + $pass = $false + } + } + + # Export the resource parameters if told to. + # These values can be used by other DSC resources down the chain + if ($this.ParameterExport) { + $fileName = "LBServer_$($this.Name).json" + $json = $this.Get() | ConvertTo-Json + $folder = Join-Path -Path $env:USERPROFILE -ChildPath '.poshorigin' + if (-Not (Test-Path -Path $folder)) { + New-Item -ItemType Directory -Path $folder -Force + } + $fullPath = Join-Path -Path $folder -ChildPath $fileName + Write-Verbose -Message "Exporting parameters to [$fullPath]" + $json | Out-File -FilePath $fullPath -Force + } + + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + + return $pass + } + + [LBServer]Get() { + Connect-NetScaler -IPAddress $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + try { + $s = Get-NSLBServer -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + $obj = [LBServer]::new() + $obj.Name = $this.Name + $obj.IPAddress = $this.IPAddress + $obj.Comments = $this.Comments + $obj.TrafficDomainId = $this.TrafficDomainId + $obj.State = $this.State + $obj.Credential = $this.Credential + $obj.NetScalerFQDN = $this.NetScalerFQDN + $obj.ParameterExport = $this.ParameterExport + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.IPAddress = $s.ipv46 + $obj.comments = $s.comment + $obj.TrafficDomainId = $s.td + $obj.State = $s.state + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} diff --git a/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 b/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 index 71b0994..9b8ea02 100644 --- a/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 +++ b/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 @@ -1525,177 +1525,177 @@ class LBServiceGroup { } } -[DscResource()] -class LBNTPServer { - [DscProperty(Key)] - [string]$Server +# [DscResource()] +# class LBNTPServer { +# [DscProperty(Key)] +# [string]$Server - [DscProperty()] - [Ensure]$Ensure = [Ensure]::Present +# [DscProperty()] +# [Ensure]$Ensure = [Ensure]::Present - [DscProperty(Mandatory)] - [string]$NetScalerFQDN +# [DscProperty(Mandatory)] +# [string]$NetScalerFQDN - [DscProperty(Mandatory)] - [pscredential]$Credential - - [DscProperty()] - [int]$MinPollInterval - - [DscProperty()] - [ValidateRange(0, 4094)] - [int]$MaxPollInterval - - [DscProperty()] - [ValidateSet('Yes','No')] - [string]$PreferredNTPServer = 'Yes' - - Init() { - try { - Import-Module -Name Netscaler -Verbose:$false -Debug:$false - Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false - } catch { - throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" - } - } - - [void]Set() { - $t = $null - $t = $this.Init() - $NSObject = $this.Get() - - try { - Import-Module -Name Netscaler -Verbose:$false -Debug:$false - Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false - } catch { - throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" - } - - try { - switch ($this.Ensure) { - 'Present' { - if ($this.Ensure -eq $NSObject.Ensure) { - if ($NSObject.Server -ne $this.Server) { - Write-Warning -Message "The NTP server name cannot be set to [$($this.Server)], resource can only be removed and recreated" - } - if ($NSObject.MinPollInterval -ne $this.MinPollInterval) { - Write-Verbose -Message "Setting Service Group MinPollInterval [$($this.MinPollInterval)]" - Set-NSNTPServer -Server $this.Server -MinPollInterval $this.MinPollInterval -Verbose:$false - } - if ($NSObject.MaxPollInterval -ne $this.MaxPollInterval) { - Write-Verbose -Message "Setting Service Group MaxPollInterval [$($this.MaxPollInterval)]" - Set-NSNTPServer -Server $this.Server -MaxPollInterval $this.MaxPollInterval -Verbose:$false - } - if ($NSObject.PreferredNTPServer -ne $this.PreferredNTPServer) { - Write-Warning -Message "The preferred NTP server cannot be set to [$($this.PreferredNTPServer)], setting can only be set manually" - } - } else { - Write-Verbose -Message "Creating resource [$($this.Name)]" - $params = @{ - server = $this.Server - minpoll = $this.MinPollInterval - maxpoll = $this.MaxPollInterval - preferredntpserver = $this.PreferredNTPServer - } - New-NSNTPServer @params -Verbose:$false -ErrorAction SilentlyContinue - } - } 'Absent' { - if ($this.Ensure -ne $NSObject.Ensure) { - Remove-NSNTPServer -Server $this.Server -ErrorAction SilentlyContinue - Write-Verbose -Message "Removing resource: $($this.Server)" - } - } - } - } catch { - Write-Error 'There was a problem setting the resource' - Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" - Write-Error $_ - } - try { - Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue - } catch { - # Do nothing - } - } - - [bool]Test() { - $pass = $true - $t = $null - $t = $this.Init() - $NSObject = $this.Get() - try { - switch ($this.Ensure) { - 'Present' { - if ($this.Ensure -eq $NSObject.Ensure) { - # Run tests and set any needed attributes to match desired configuration - if ($NSObject.Server -ne $this.Server) { - Write-Verbose -Message "Server does not match [$($NSObject.Server) <> $($this.Server)]" - $pass = $false - } - if ($NSObject.MinPollInterval -ne $this.MinPollInterval) { - Write-Verbose -Message "Min Poll Interval does not match [$($NSObject.MinPollInterval) <> $($this.MinPollInterval)]" - $pass = $false - } - if ($NSObject.MaxPollInterval -ne $this.MaxPollInterval) { - Write-Verbose -Message "Max Poll Interval does not match [$($NSObject.MaxPollInterval) <> $($this.MaxPollInterval)]" - $pass = $false - } - if ($NSObject.PreferredNTPServer -ne $this.PreferredNTPServer) { - Write-Verbose -Message "Preferred NTP Server does not match [$($NSObject.PreferredNTPServer) <> $($this.PreferredNTPServer)]" - $pass = $false - } - } else { - Write-Verbose -Message "Resource [$($this.Server)] was not found" - $pass = $false - } - } - 'Absent' { - if ($this.Ensure -ne $NSObject.Ensure) { - $pass = $false - } - } - } - } catch { - Write-Error 'There was a problem testing the resource' - Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" - Write-Error $_ - } - try { - Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue - } catch { - # Do nothing - } - return $pass - } - - [LBNTPServer]Get() { - $t = $null - $t = $this.Init() - - try { - $s = Get-NSNTPServer -Name $this.Server -Verbose:$false -ErrorAction SilentlyContinue - } catch { - $s = $null - } - - $obj = [LBNTPServer]::new() - $obj.Server = $this.Server - $obj.MinPollInterval = $this.MinPollInterval - $obj.MaxPollInterval = $this.MaxPollInterval - $obj.PreferredNTPServer = $this.PreferredNTPServer - if ($s) { - $obj.Ensure = [ensure]::Present - $obj.Server = $s.serverip - $obj.MinPollInterval = $s.minpoll - $obj.MaxPollInterval = $s.maxpoll - $obj.PreferredNTPServer = $s.preferredntpserver - } else { - $obj.Ensure = [ensure]::Absent - } - Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue - return $obj - } -} +# [DscProperty(Mandatory)] +# [pscredential]$Credential + +# [DscProperty()] +# [int]$MinPollInterval + +# [DscProperty()] +# [ValidateRange(0, 4094)] +# [int]$MaxPollInterval + +# [DscProperty()] +# [ValidateSet('Yes','No')] +# [string]$PreferredNTPServer = 'Yes' + +# Init() { +# try { +# Import-Module -Name Netscaler -Verbose:$false -Debug:$false +# Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false +# } catch { +# throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" +# } +# } + +# [void]Set() { +# $t = $null +# $t = $this.Init() +# $NSObject = $this.Get() + +# try { +# Import-Module -Name Netscaler -Verbose:$false -Debug:$false +# Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false +# } catch { +# throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" +# } + +# try { +# switch ($this.Ensure) { +# 'Present' { +# if ($this.Ensure -eq $NSObject.Ensure) { +# if ($NSObject.Server -ne $this.Server) { +# Write-Warning -Message "The NTP server name cannot be set to [$($this.Server)], resource can only be removed and recreated" +# } +# if ($NSObject.MinPollInterval -ne $this.MinPollInterval) { +# Write-Verbose -Message "Setting Service Group MinPollInterval [$($this.MinPollInterval)]" +# Set-NSNTPServer -Server $this.Server -MinPollInterval $this.MinPollInterval -Verbose:$false +# } +# if ($NSObject.MaxPollInterval -ne $this.MaxPollInterval) { +# Write-Verbose -Message "Setting Service Group MaxPollInterval [$($this.MaxPollInterval)]" +# Set-NSNTPServer -Server $this.Server -MaxPollInterval $this.MaxPollInterval -Verbose:$false +# } +# if ($NSObject.PreferredNTPServer -ne $this.PreferredNTPServer) { +# Write-Warning -Message "The preferred NTP server cannot be set to [$($this.PreferredNTPServer)], setting can only be set manually" +# } +# } else { +# Write-Verbose -Message "Creating resource [$($this.Name)]" +# $params = @{ +# server = $this.Server +# minpoll = $this.MinPollInterval +# maxpoll = $this.MaxPollInterval +# preferredntpserver = $this.PreferredNTPServer +# } +# New-NSNTPServer @params -Verbose:$false -ErrorAction SilentlyContinue +# } +# } 'Absent' { +# if ($this.Ensure -ne $NSObject.Ensure) { +# Remove-NSNTPServer -Server $this.Server -ErrorAction SilentlyContinue +# Write-Verbose -Message "Removing resource: $($this.Server)" +# } +# } +# } +# } catch { +# Write-Error 'There was a problem setting the resource' +# Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" +# Write-Error $_ +# } +# try { +# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue +# } catch { +# # Do nothing +# } +# } + +# [bool]Test() { +# $pass = $true +# $t = $null +# $t = $this.Init() +# $NSObject = $this.Get() +# try { +# switch ($this.Ensure) { +# 'Present' { +# if ($this.Ensure -eq $NSObject.Ensure) { +# # Run tests and set any needed attributes to match desired configuration +# if ($NSObject.Server -ne $this.Server) { +# Write-Verbose -Message "Server does not match [$($NSObject.Server) <> $($this.Server)]" +# $pass = $false +# } +# if ($NSObject.MinPollInterval -ne $this.MinPollInterval) { +# Write-Verbose -Message "Min Poll Interval does not match [$($NSObject.MinPollInterval) <> $($this.MinPollInterval)]" +# $pass = $false +# } +# if ($NSObject.MaxPollInterval -ne $this.MaxPollInterval) { +# Write-Verbose -Message "Max Poll Interval does not match [$($NSObject.MaxPollInterval) <> $($this.MaxPollInterval)]" +# $pass = $false +# } +# if ($NSObject.PreferredNTPServer -ne $this.PreferredNTPServer) { +# Write-Verbose -Message "Preferred NTP Server does not match [$($NSObject.PreferredNTPServer) <> $($this.PreferredNTPServer)]" +# $pass = $false +# } +# } else { +# Write-Verbose -Message "Resource [$($this.Server)] was not found" +# $pass = $false +# } +# } +# 'Absent' { +# if ($this.Ensure -ne $NSObject.Ensure) { +# $pass = $false +# } +# } +# } +# } catch { +# Write-Error 'There was a problem testing the resource' +# Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" +# Write-Error $_ +# } +# try { +# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue +# } catch { +# # Do nothing +# } +# return $pass +# } + +# [LBNTPServer]Get() { +# $t = $null +# $t = $this.Init() + +# try { +# $s = Get-NSNTPServer -Name $this.Server -Verbose:$false -ErrorAction SilentlyContinue +# } catch { +# $s = $null +# } + +# $obj = [LBNTPServer]::new() +# $obj.Server = $this.Server +# $obj.MinPollInterval = $this.MinPollInterval +# $obj.MaxPollInterval = $this.MaxPollInterval +# $obj.PreferredNTPServer = $this.PreferredNTPServer +# if ($s) { +# $obj.Ensure = [ensure]::Present +# $obj.Server = $s.serverip +# $obj.MinPollInterval = $s.minpoll +# $obj.MaxPollInterval = $s.maxpoll +# $obj.PreferredNTPServer = $s.preferredntpserver +# } else { +# $obj.Ensure = [ensure]::Absent +# } +# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue +# return $obj +# } +# } [DscResource()] class LBResponderPolicy { @@ -2853,448 +2853,448 @@ class LBNSFeature { } } -[DscResource()] -class LBSSLCertificate { - [DscProperty(Key)] - [string]$CertKeyName +# [DscResource()] +# class LBSSLCertificate { +# [DscProperty(Key)] +# [string]$CertKeyName - [DscProperty()] - [Ensure]$Ensure = [Ensure]::Present +# [DscProperty()] +# [Ensure]$Ensure = [Ensure]::Present - [DscProperty(Mandatory)] - [string]$NetScalerFQDN +# [DscProperty(Mandatory)] +# [string]$NetScalerFQDN - [DscProperty(Mandatory)] - [pscredential]$Credential - - [DscProperty()] - [string]$CertPath - - [DscProperty()] - [string]$KeyPath - - [DscProperty()] - [ValidateSet('PEM','DER','PFX')] - [string]$CertKeyFormat = 'PEM' - - [DscProperty()] - [securestring]$Password - - - Init() { - try { - Import-Module -Name Netscaler -Verbose:$false -Debug:$false - Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false - } catch { - throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" - } - } - - [void]Set() { - $t = $null - $t = $this.Init() - $NSObject = $this.Get() - - try { - Import-Module -Name Netscaler -Verbose:$false -Debug:$false - Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false - } catch { - throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" - } - - try { - switch ($this.Ensure) { - 'Present' { - if ($this.Ensure -eq $NSObject.Ensure) { - # Run tests and set any needed attributes to match desired configuration - if (($NSObject.CertKeyName -ne $this.CertKeyName) -OR ($NSObject.CertPath -ne $this.CertPath) -OR ($NSObject.KeyPath -ne $this.KeyPath) -OR ($NSObject.CertKeyFormat -ne $this.CertKeyFormat)) { - Write-Verbose -Message "Warning, resource cannot be changed to [$($this.CertKeyName)], resource can only be removed and recreated" - Remove-NSCertKeyPair -CertKeyName $this.CertKeyName - } - } else { - Write-Verbose -Message "Creating resource [$($this.CertKeyName)]" - $params = @{ - CertKeyName = $this.CertKeyName - CertPath = $this.CertPath - KeyPath = $this.KeyPath - CertKeyFormat = $this.CertKeyFormat - } - Add-NSCertKeyPair @params -ErrorAction SilentlyContinue - } - } - 'Absent' { - if ($this.Ensure -ne $NSObject.Ensure) { - Remove-NSResponderAction -Name $NSObject.CertKeyName -ErrorAction SilentlyContinue - Write-Verbose -Message "Removed Certificate: $($this.Name)" - } - } - } - } catch { - Write-Error 'There was a problem setting the resource' - Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" - Write-Error $_ - } - try { - Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue - } catch { - # Do nothing - } - } - - [bool]Test() { - $pass = $true - $t = $null - $t = $this.Init() - $NSObject = $this.Get() - try { - switch ($this.Ensure) { - 'Present' { - if ($this.Ensure -eq $NSObject.Ensure) { - # Run tests and set any needed attributes to match desired configuration - if ($NSObject.certkeyname -ne $this.CertKeyName) { - Write-Verbose -Message "Certificate Key Name does not match [$($NSObject.certkeyname) <> $($this.CertKeyName)]" - $pass = $false - } - if ($NSObject.certpath -ne $this.CertPath) { - Write-Verbose -Message "Certificate Path does not match [$($NSObject.certpath) <> $($this.CertPath)]" - $pass = $false - } - if ($this.KeyPath) { - if ($NSObject.keypath -ne $this.KeyPath) { - Write-Verbose -Message "Key Path does not match [$($NSObject.keypath) <> $($this.KeyPath)]" - $pass = $false - } - } - } else { - Write-Verbose -Message "Certificate[$($this.CertKeyName)] was not found" - $pass = $false - } - } - 'Absent' { - if ($this.Ensure -ne $NSObject.Ensure) { - $pass = $false - } - } - } - } catch { - Write-Error 'There was a problem testing the resource' - Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" - Write-Error $_ - } - try { - Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue - } catch { - # Do nothing - } - return $pass - } - - [LBSSLCertificate]Get() { - $t = $null - $t = $this.Init() - - try { - $s = Get-NSCertKeyPair -CertKeyName $this.CertKeyName -Verbose:$false -ErrorAction SilentlyContinue - } catch { - $s = $null - } - $obj = [LBSSLCertificate]::new() - $obj.CertKeyName = $this.CertKeyName - $obj.CertPath = $this.CertPath - $obj.CertKeyFormat = $this.CertKeyFormat - $obj.KeyPath = $this.KeyPath - if ($s) { - $obj.Ensure = [ensure]::Present - $obj.CertKeyName = $s.certkey - $obj.CertPath = $s.cert - $obj.CertKeyFormat = $s.inform - if ($s.key) { - $obj.KeyPath = $s.key - } - } else { - $obj.Ensure = [ensure]::Absent - } - Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue - return $obj - } -} - -[DscResource()] -class LBNSIP { - [DscProperty(Key)] - [string]$IPAddress - - [DscProperty()] - [Ensure]$Ensure = [Ensure]::Present - - [DscProperty(Mandatory)] - [string]$NetScalerFQDN +# [DscProperty(Mandatory)] +# [pscredential]$Credential + +# [DscProperty()] +# [string]$CertPath + +# [DscProperty()] +# [string]$KeyPath + +# [DscProperty()] +# [ValidateSet('PEM','DER','PFX')] +# [string]$CertKeyFormat = 'PEM' + +# [DscProperty()] +# [securestring]$Password + + +# Init() { +# try { +# Import-Module -Name Netscaler -Verbose:$false -Debug:$false +# Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false +# } catch { +# throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" +# } +# } + +# [void]Set() { +# $t = $null +# $t = $this.Init() +# $NSObject = $this.Get() + +# try { +# Import-Module -Name Netscaler -Verbose:$false -Debug:$false +# Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false +# } catch { +# throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" +# } + +# try { +# switch ($this.Ensure) { +# 'Present' { +# if ($this.Ensure -eq $NSObject.Ensure) { +# # Run tests and set any needed attributes to match desired configuration +# if (($NSObject.CertKeyName -ne $this.CertKeyName) -OR ($NSObject.CertPath -ne $this.CertPath) -OR ($NSObject.KeyPath -ne $this.KeyPath) -OR ($NSObject.CertKeyFormat -ne $this.CertKeyFormat)) { +# Write-Verbose -Message "Warning, resource cannot be changed to [$($this.CertKeyName)], resource can only be removed and recreated" +# Remove-NSCertKeyPair -CertKeyName $this.CertKeyName +# } +# } else { +# Write-Verbose -Message "Creating resource [$($this.CertKeyName)]" +# $params = @{ +# CertKeyName = $this.CertKeyName +# CertPath = $this.CertPath +# KeyPath = $this.KeyPath +# CertKeyFormat = $this.CertKeyFormat +# } +# Add-NSCertKeyPair @params -ErrorAction SilentlyContinue +# } +# } +# 'Absent' { +# if ($this.Ensure -ne $NSObject.Ensure) { +# Remove-NSResponderAction -Name $NSObject.CertKeyName -ErrorAction SilentlyContinue +# Write-Verbose -Message "Removed Certificate: $($this.Name)" +# } +# } +# } +# } catch { +# Write-Error 'There was a problem setting the resource' +# Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" +# Write-Error $_ +# } +# try { +# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue +# } catch { +# # Do nothing +# } +# } + +# [bool]Test() { +# $pass = $true +# $t = $null +# $t = $this.Init() +# $NSObject = $this.Get() +# try { +# switch ($this.Ensure) { +# 'Present' { +# if ($this.Ensure -eq $NSObject.Ensure) { +# # Run tests and set any needed attributes to match desired configuration +# if ($NSObject.certkeyname -ne $this.CertKeyName) { +# Write-Verbose -Message "Certificate Key Name does not match [$($NSObject.certkeyname) <> $($this.CertKeyName)]" +# $pass = $false +# } +# if ($NSObject.certpath -ne $this.CertPath) { +# Write-Verbose -Message "Certificate Path does not match [$($NSObject.certpath) <> $($this.CertPath)]" +# $pass = $false +# } +# if ($this.KeyPath) { +# if ($NSObject.keypath -ne $this.KeyPath) { +# Write-Verbose -Message "Key Path does not match [$($NSObject.keypath) <> $($this.KeyPath)]" +# $pass = $false +# } +# } +# } else { +# Write-Verbose -Message "Certificate[$($this.CertKeyName)] was not found" +# $pass = $false +# } +# } +# 'Absent' { +# if ($this.Ensure -ne $NSObject.Ensure) { +# $pass = $false +# } +# } +# } +# } catch { +# Write-Error 'There was a problem testing the resource' +# Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" +# Write-Error $_ +# } +# try { +# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue +# } catch { +# # Do nothing +# } +# return $pass +# } + +# [LBSSLCertificate]Get() { +# $t = $null +# $t = $this.Init() + +# try { +# $s = Get-NSCertKeyPair -CertKeyName $this.CertKeyName -Verbose:$false -ErrorAction SilentlyContinue +# } catch { +# $s = $null +# } +# $obj = [LBSSLCertificate]::new() +# $obj.CertKeyName = $this.CertKeyName +# $obj.CertPath = $this.CertPath +# $obj.CertKeyFormat = $this.CertKeyFormat +# $obj.KeyPath = $this.KeyPath +# if ($s) { +# $obj.Ensure = [ensure]::Present +# $obj.CertKeyName = $s.certkey +# $obj.CertPath = $s.cert +# $obj.CertKeyFormat = $s.inform +# if ($s.key) { +# $obj.KeyPath = $s.key +# } +# } else { +# $obj.Ensure = [ensure]::Absent +# } +# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue +# return $obj +# } +# } + +# [DscResource()] +# class LBNSIP { +# [DscProperty(Key)] +# [string]$IPAddress + +# [DscProperty()] +# [Ensure]$Ensure = [Ensure]::Present + +# [DscProperty(Mandatory)] +# [string]$NetScalerFQDN - [DscProperty(Mandatory)] - [pscredential]$Credential - - [DscProperty(Mandatory)] - [string]$SubnetMask - - [DscProperty()] - [string]$Type = 'SNIP' - - [DscProperty(Mandatory)] - [bool]$VServer = $false - - [DscProperty(Mandatory)] - [bool]$Telnet = $false - - [DscProperty(Mandatory)] - [bool]$FTP = $false - - [DscProperty(Mandatory)] - [bool]$GUI = $false - - [DscProperty(Mandatory)] - [bool]$SSH = $false - - [DscProperty(Mandatory)] - [bool]$SNMP = $false - - [DscProperty(Mandatory)] - [bool]$MgmtAccess = $false - - Init() { - try { - Import-Module -Name Netscaler -Verbose:$false -Debug:$false - Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false - } catch { - throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" - } - } - - [void]Set() { - $t = $null - $t = $this.Init() - $NSObject = $this.Get() - - try { - Import-Module -Name Netscaler -Verbose:$false -Debug:$false - Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false - } catch { - throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" - } - - try { - switch ($this.Ensure) { - 'Present' { - if ($this.Ensure -eq $NSObject.Ensure) { - # Run tests and set any needed attributes to match desired configuration - if ($NSObject.IPAddressName -ne $this.IPAddress) { - Write-Verbose -Message "Warning, the resource cannot be set to [$($this.IPAddress)]" - } - if ($NSObject.SubnetMask -ne $this.SubnetMask) { - Write-Verbose -Message "Resource name does not match [$($this.SubnetMask)]" - Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask - } - if ($NSObject.Type -ne $this.Type) { - Write-Verbose -Message "Warning, the resource cannot be set to [$($this.Type)]" - } - if ($NSObject.VServer -ne $this.VServer) { - Write-Verbose -Message "Setting vServer [$($this.VServer)]" - Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -VServer - } - if ($NSObject.Telnet -ne $this.Telnet) { - Write-Verbose -Message "Setting Telnet [$($this.Telnet)]" - Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -Telnet - } - if ($NSObject.FTP -ne $this.FTP) { - Write-Verbose -Message "Setting FTP [$($this.FTP)]" - Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -FTP - } - if ($NSObject.GUI -ne $this.GUI) { - Write-Verbose -Message "Setting GUI [$($this.GUI)]" - Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -GUI - } - if ($NSObject.SSH -ne $this.SSH) { - Write-Verbose -Message "Setting GUI [$($this.SSH)]" - Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -SSH - } - if ($NSObject.SNMP -ne $this.SNMP) { - Write-Verbose -Message "Setting SNMP [$($this.SNMP)]" - Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -SNMP - } - if ($NSObject.MgmtAccess -ne $this.MgmtAccess) { - Write-Verbose -Message "Setting Management Access [$($this.MgmtAccess)]" - Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -MgmtAccess - } - } else { - Write-Verbose -Message "Feature enabled, [$($this.IPAddress)]" - $params = @{ - ipaddress = $this.IPAddress - netmask = $this.SubnetMask - type = $this.Type - } - Add-NSIPResource @params -Confirm:$false - # $switches { - # ipaddress = $this.IPAddress - # netmask = $this.SubnetMask - # type = $this.Type - # vserver = $this.VServer - # telnet = $this.Telnet - # ftp = $this.FTP - # gui = $this.GUI - # ssh = $this.SSH - # snmp = $this.SNMP - # mgmtaccess = $this.mgmtaccess - # } - # Invoke-DscResource -Method set -ModuleName poshorigin_netscaler -Name LBNSIP -Property $switches - } - } 'Absent' { - if ($this.Ensure -ne $NSObject.Ensure) { - Disable-NSFeature -Name $this.Name -Confirm:$false - Write-Verbose -Message "Feature disabled: $($this.Name)" - } - } - } - } catch { - Write-Error 'There was a problem setting the resource' - Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" - Write-Error $_ - } - try { - Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue - } catch { - # Do nothing - } - } - - - [bool]Test() { - $pass = $true - $t = $null - $t = $this.Init() - $NSObject = $this.Get() - try { - switch ($this.Ensure) { - 'Present' { - if ($this.Ensure -eq $NSObject.Ensure) { - # # Run tests and set any needed attributes to match desired configuration - if ($NSObject.ipaddress -ne $this.IPAddress) { - Write-Verbose -Message "IPAddress does not match [$($NSObject.ipaddress) <> $($this.IPAddress)]" - $pass = $false - } - if ($NSObject.subnetmask -ne $this.SubnetMask) { - Write-Verbose -Message "SubnetMask does not match [$($NSObject.subnetmask) <> $($this.SubnetMask)]" - $pass = $false - } - if ($NSObject.type -ne $this.Type) { - Write-Verbose -Message "Type does not match [$($NSObject.type) <> $($this.Type)]" - $pass = $false - } - if ($NSObject.vserver -ne $this.VServer) { - Write-Verbose -Message "VServer does not match [$($NSObject.vserver) <> $($this.VServer)]" - $pass = $false - } - if ($NSObject.telnet -ne $this.Telnet) { - Write-Verbose -Message "Telnet does not match [$($NSObject.telnet) <> $($this.Telnet)]" - $pass = $false - } - if ($NSObject.ftp -ne $this.FTP) { - Write-Verbose -Message "FTP does not match [$($NSObject.ftp) <> $($this.FTP)]" - $pass = $false - } - if ($NSObject.gui -ne $this.GUI) { - Write-Verbose -Message "GUI does not match [$($NSObject.gui) <> $($this.GUI)]" - $pass = $false - } - if ($NSObject.ssh -ne $this.SSH) { - Write-Verbose -Message "SSH does not match [$($NSObject.ssh) <> $($this.SSH)]" - $pass = $false - } - if ($NSObject.snmp -ne $this.SNMP) { - Write-Verbose -Message "SNMP does not match [$($NSObject.snmp) <> $($this.SNMP)]" - $pass = $false - } - if ($NSObject.mgmtaccess -ne $this.MgmtAccess) { - Write-Verbose -Message "MgmtAccess does not match [$($NSObject.mgmtaccess) <> $($this.MgmtAccess)]" - $pass = $false - } - } else { - $pass = $false - } - } 'Absent' { - if ($this.Ensure -ne $NSObject.Ensure) { - $pass = $false - } else { - if ($NSObject.Name -eq "True") { - $pass = $false - } - } - } - } - } catch { - Write-Error 'There was a problem testing the resource' - Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" - Write-Error $_ - } - try { - Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue - } catch { - # Do nothing - } - return $pass - } - - [LBNSIP]Get() { - $t = $null - $t = $this.Init() - - try { - $s = Get-NSIPResource -IPAddress $this.IPAddress -Verbose:$false -ErrorAction SilentlyContinue - } catch { - $s = $null - } - - $obj = [LBNSIP]::new() - $obj.IPAddress = $this.IPAddress - $obj.SubnetMask = $this.SubnetMask - $obj.Type = $this.Type - $obj.VServer = $this.VServer - $obj.Telnet = $this.Telnet - $obj.FTP = $this.FTP - $obj.GUI = $this.GUI - $obj.SSH = $this.SSH - $obj.SNMP = $this.SNMP - $obj.MgmtAccess = $this.MgmtAccess - if ($s) { - $obj.Ensure = [ensure]::Present - $obj.IPAddress = $s.ipaddress - $obj.SubnetMask = $s.netmask - $obj.Type = $s.type - $obj.VServer = $this.TestEnabledFeatures($s.VServer) - $obj.Telnet = $this.TestEnabledFeatures($s.Telnet) - $obj.FTP = $this.TestEnabledFeatures($s.FTP) - $obj.GUI = $this.TestEnabledFeatures($s.GUI) - $obj.SSH = $this.TestEnabledFeatures($s.SSH) - $obj.SNMP = $this.TestEnabledFeatures($s.SNMP) - $obj.MgmtAccess = $this.TestEnabledFeatures($s.MgmtAccess) - } else { - $obj.Ensure = [ensure]::Absent - } - Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue - return $obj - } - - <# - Helper method to test switch/boolean options - #> - [bool] TestEnabledFeatures([string] $Existing){ - # $present = $true - if ($Existing -eq "ENABLED") { - $present = $true - } else { - $present = $false - } - return $present - } -} +# [DscProperty(Mandatory)] +# [pscredential]$Credential + +# [DscProperty(Mandatory)] +# [string]$SubnetMask + +# [DscProperty()] +# [string]$Type = 'SNIP' + +# [DscProperty(Mandatory)] +# [bool]$VServer = $false + +# [DscProperty(Mandatory)] +# [bool]$Telnet = $false + +# [DscProperty(Mandatory)] +# [bool]$FTP = $false + +# [DscProperty(Mandatory)] +# [bool]$GUI = $false + +# [DscProperty(Mandatory)] +# [bool]$SSH = $false + +# [DscProperty(Mandatory)] +# [bool]$SNMP = $false + +# [DscProperty(Mandatory)] +# [bool]$MgmtAccess = $false + +# Init() { +# try { +# Import-Module -Name Netscaler -Verbose:$false -Debug:$false +# Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false +# } catch { +# throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" +# } +# } + +# [void]Set() { +# $t = $null +# $t = $this.Init() +# $NSObject = $this.Get() + +# try { +# Import-Module -Name Netscaler -Verbose:$false -Debug:$false +# Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false +# } catch { +# throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" +# } + +# try { +# switch ($this.Ensure) { +# 'Present' { +# if ($this.Ensure -eq $NSObject.Ensure) { +# # Run tests and set any needed attributes to match desired configuration +# if ($NSObject.IPAddressName -ne $this.IPAddress) { +# Write-Verbose -Message "Warning, the resource cannot be set to [$($this.IPAddress)]" +# } +# if ($NSObject.SubnetMask -ne $this.SubnetMask) { +# Write-Verbose -Message "Resource name does not match [$($this.SubnetMask)]" +# Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask +# } +# if ($NSObject.Type -ne $this.Type) { +# Write-Verbose -Message "Warning, the resource cannot be set to [$($this.Type)]" +# } +# if ($NSObject.VServer -ne $this.VServer) { +# Write-Verbose -Message "Setting vServer [$($this.VServer)]" +# Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -VServer +# } +# if ($NSObject.Telnet -ne $this.Telnet) { +# Write-Verbose -Message "Setting Telnet [$($this.Telnet)]" +# Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -Telnet +# } +# if ($NSObject.FTP -ne $this.FTP) { +# Write-Verbose -Message "Setting FTP [$($this.FTP)]" +# Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -FTP +# } +# if ($NSObject.GUI -ne $this.GUI) { +# Write-Verbose -Message "Setting GUI [$($this.GUI)]" +# Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -GUI +# } +# if ($NSObject.SSH -ne $this.SSH) { +# Write-Verbose -Message "Setting GUI [$($this.SSH)]" +# Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -SSH +# } +# if ($NSObject.SNMP -ne $this.SNMP) { +# Write-Verbose -Message "Setting SNMP [$($this.SNMP)]" +# Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -SNMP +# } +# if ($NSObject.MgmtAccess -ne $this.MgmtAccess) { +# Write-Verbose -Message "Setting Management Access [$($this.MgmtAccess)]" +# Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -MgmtAccess +# } +# } else { +# Write-Verbose -Message "Feature enabled, [$($this.IPAddress)]" +# $params = @{ +# ipaddress = $this.IPAddress +# netmask = $this.SubnetMask +# type = $this.Type +# } +# Add-NSIPResource @params -Confirm:$false +# # $switches { +# # ipaddress = $this.IPAddress +# # netmask = $this.SubnetMask +# # type = $this.Type +# # vserver = $this.VServer +# # telnet = $this.Telnet +# # ftp = $this.FTP +# # gui = $this.GUI +# # ssh = $this.SSH +# # snmp = $this.SNMP +# # mgmtaccess = $this.mgmtaccess +# # } +# # Invoke-DscResource -Method set -ModuleName poshorigin_netscaler -Name LBNSIP -Property $switches +# } +# } 'Absent' { +# if ($this.Ensure -ne $NSObject.Ensure) { +# Disable-NSFeature -Name $this.Name -Confirm:$false +# Write-Verbose -Message "Feature disabled: $($this.Name)" +# } +# } +# } +# } catch { +# Write-Error 'There was a problem setting the resource' +# Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" +# Write-Error $_ +# } +# try { +# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue +# } catch { +# # Do nothing +# } +# } + + +# [bool]Test() { +# $pass = $true +# $t = $null +# $t = $this.Init() +# $NSObject = $this.Get() +# try { +# switch ($this.Ensure) { +# 'Present' { +# if ($this.Ensure -eq $NSObject.Ensure) { +# # # Run tests and set any needed attributes to match desired configuration +# if ($NSObject.ipaddress -ne $this.IPAddress) { +# Write-Verbose -Message "IPAddress does not match [$($NSObject.ipaddress) <> $($this.IPAddress)]" +# $pass = $false +# } +# if ($NSObject.subnetmask -ne $this.SubnetMask) { +# Write-Verbose -Message "SubnetMask does not match [$($NSObject.subnetmask) <> $($this.SubnetMask)]" +# $pass = $false +# } +# if ($NSObject.type -ne $this.Type) { +# Write-Verbose -Message "Type does not match [$($NSObject.type) <> $($this.Type)]" +# $pass = $false +# } +# if ($NSObject.vserver -ne $this.VServer) { +# Write-Verbose -Message "VServer does not match [$($NSObject.vserver) <> $($this.VServer)]" +# $pass = $false +# } +# if ($NSObject.telnet -ne $this.Telnet) { +# Write-Verbose -Message "Telnet does not match [$($NSObject.telnet) <> $($this.Telnet)]" +# $pass = $false +# } +# if ($NSObject.ftp -ne $this.FTP) { +# Write-Verbose -Message "FTP does not match [$($NSObject.ftp) <> $($this.FTP)]" +# $pass = $false +# } +# if ($NSObject.gui -ne $this.GUI) { +# Write-Verbose -Message "GUI does not match [$($NSObject.gui) <> $($this.GUI)]" +# $pass = $false +# } +# if ($NSObject.ssh -ne $this.SSH) { +# Write-Verbose -Message "SSH does not match [$($NSObject.ssh) <> $($this.SSH)]" +# $pass = $false +# } +# if ($NSObject.snmp -ne $this.SNMP) { +# Write-Verbose -Message "SNMP does not match [$($NSObject.snmp) <> $($this.SNMP)]" +# $pass = $false +# } +# if ($NSObject.mgmtaccess -ne $this.MgmtAccess) { +# Write-Verbose -Message "MgmtAccess does not match [$($NSObject.mgmtaccess) <> $($this.MgmtAccess)]" +# $pass = $false +# } +# } else { +# $pass = $false +# } +# } 'Absent' { +# if ($this.Ensure -ne $NSObject.Ensure) { +# $pass = $false +# } else { +# if ($NSObject.Name -eq "True") { +# $pass = $false +# } +# } +# } +# } +# } catch { +# Write-Error 'There was a problem testing the resource' +# Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" +# Write-Error $_ +# } +# try { +# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue +# } catch { +# # Do nothing +# } +# return $pass +# } + +# [LBNSIP]Get() { +# $t = $null +# $t = $this.Init() + +# try { +# $s = Get-NSIPResource -IPAddress $this.IPAddress -Verbose:$false -ErrorAction SilentlyContinue +# } catch { +# $s = $null +# } + +# $obj = [LBNSIP]::new() +# $obj.IPAddress = $this.IPAddress +# $obj.SubnetMask = $this.SubnetMask +# $obj.Type = $this.Type +# $obj.VServer = $this.VServer +# $obj.Telnet = $this.Telnet +# $obj.FTP = $this.FTP +# $obj.GUI = $this.GUI +# $obj.SSH = $this.SSH +# $obj.SNMP = $this.SNMP +# $obj.MgmtAccess = $this.MgmtAccess +# if ($s) { +# $obj.Ensure = [ensure]::Present +# $obj.IPAddress = $s.ipaddress +# $obj.SubnetMask = $s.netmask +# $obj.Type = $s.type +# $obj.VServer = $this.TestEnabledFeatures($s.VServer) +# $obj.Telnet = $this.TestEnabledFeatures($s.Telnet) +# $obj.FTP = $this.TestEnabledFeatures($s.FTP) +# $obj.GUI = $this.TestEnabledFeatures($s.GUI) +# $obj.SSH = $this.TestEnabledFeatures($s.SSH) +# $obj.SNMP = $this.TestEnabledFeatures($s.SNMP) +# $obj.MgmtAccess = $this.TestEnabledFeatures($s.MgmtAccess) +# } else { +# $obj.Ensure = [ensure]::Absent +# } +# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue +# return $obj +# } + +# <# +# Helper method to test switch/boolean options +# #> +# [bool] TestEnabledFeatures([string] $Existing){ +# # $present = $true +# if ($Existing -eq "ENABLED") { +# $present = $true +# } else { +# $present = $false +# } +# return $present +# } +# } [DscResource()] From 1d6648b58521559321218555035669ac2077a971 Mon Sep 17 00:00:00 2001 From: Juan Herrera Date: Mon, 3 Jul 2017 10:55:20 -0700 Subject: [PATCH 4/7] added additional functions --- .../POSHOrigin_NetScaler.psd1 | 2 +- .../POSHOrigin_NetScaler.psm1 | 1207 +++++- .../Examples/Example_LBServer.ps1 | 51 + .../Examples/Example_LBVirtualServer.ps1 | 57 + .../Examples/Example_POSHOrigin_LBServer.ps1 | 12 + .../Example_POSHOrigin_LBVirtualServer.ps1 | 14 + old/POSHOrigin_NetScaler/Invoke.ps1 | 133 + .../POSHOrigin_NetScaler.psd1 | 44 + .../POSHOrigin_NetScaler.psm1 | 3808 +++++++++++++++++ 9 files changed, 5312 insertions(+), 16 deletions(-) create mode 100644 old/POSHOrigin_NetScaler/Examples/Example_LBServer.ps1 create mode 100644 old/POSHOrigin_NetScaler/Examples/Example_LBVirtualServer.ps1 create mode 100644 old/POSHOrigin_NetScaler/Examples/Example_POSHOrigin_LBServer.ps1 create mode 100644 old/POSHOrigin_NetScaler/Examples/Example_POSHOrigin_LBVirtualServer.ps1 create mode 100644 old/POSHOrigin_NetScaler/Invoke.ps1 create mode 100644 old/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psd1 create mode 100644 old/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 diff --git a/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psd1 b/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psd1 index 9a25762..d4d3b80 100644 --- a/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psd1 +++ b/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psd1 @@ -24,7 +24,7 @@ RequiredModules = 'NetScaler' # DSC resources to export from this module - DscResourcesToExport = @('LBVirtualServer','LBServer','LBMonitor','LBServiceGroup','LBNTPServer','LBResponderPolicy','LBResponderAction','LBSSLCertificate','LBRewritePolicy','LBRewriteAction','LBDNSServer','LBNSMode','LBNSFeature','LBNSIP','LBNSVirtualServerBinding','LBSystemFile','LBVLAN') + DscResourcesToExport = @('LBVirtualServer','LBServer','LBMonitor','LBServiceGroup','LBNTPServer','LBResponderPolicy','LBResponderAction','LBSSLCertificate','LBRewritePolicy','LBRewriteAction','LBDNSServer','LBNSMode','LBNSFeature','LBNSIP','LBNSVirtualServerBinding','LBSystemFile','LBVLAN','LBResponderPolicyBinding','LBServiceGroupMember','LBService') PrivateData = @{ PSData = @{ diff --git a/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 b/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 index 9b8ea02..9b2706f 100644 --- a/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 +++ b/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 @@ -126,11 +126,13 @@ class LBVirtualServer { Port = $this.Port LBMethod = $this.LBMethod PersistenceType = $this.PersistenceType - HttpRedirectURL = $this.HttpRedirectURL ICMPVSRResponse = $this.ICMPVSRResponse TimeOut = $this.TimeOut Comment = $this.Comment } + if ($null -ne $this.HttpRedirectURL) { + $params.HttpRedirectURL = $this.HttpRedirectURL + } New-NSLBVirtualServer @params -ErrorAction SilentlyContinue } } 'Absent' { @@ -176,7 +178,7 @@ class LBVirtualServer { if ($NSObject.comment -ne $this.Comment) { Write-Verbose -Message "Virtual server Comment do not match [$($NSObject.comment) <> $($this.Comment)]" $pass = $false - } + } if ($NSObject.port -ne $this.Port) { Write-Verbose -Message "Virtual server port does not match [$($NSObject.port) <> $($this.Port)" $pass = $false @@ -204,7 +206,7 @@ class LBVirtualServer { if ($NSObject.timeout -ne $this.TimeOut) { Write-Verbose -Message "Virtual server Timeout does not match [$($NSObject.timeout) <> $($this.TimeOut)" $pass = $false - } + } } else { Write-Verbose -Message "Resource [$($this.Name)] was not found" $pass = $false @@ -529,7 +531,7 @@ class LBMonitor { [string]$NetProfile [DscProperty()] - [ValidateSet('YES', 'NO')] + [ValidateSet('YES','NO')] [string]$TOS = 'NO' [DscProperty()] @@ -541,11 +543,11 @@ class LBMonitor { [string]$State = 'ENABLED' [DscProperty()] - [ValidateSet('Yes', 'NO')] + [ValidateSet('YES','NO')] [string]$Reverse = 'NO' [DscProperty()] - [ValidateSet('YES', 'NO')] + [ValidateSet('YES','NO')] [string]$Transparent = 'NO' [DscProperty()] @@ -553,11 +555,11 @@ class LBMonitor { [string]$LRTM = 'DISABLED' [DscProperty()] - [ValidateSet('YES', 'NO')] + [ValidateSet('YES','NO')] [string]$Secure = 'NO' [DscProperty()] - [ValidateSet('YES', 'NO')] + [ValidateSet('YES','NO')] [string]$IPTunnel = 'NO' [DscProperty()] @@ -1029,7 +1031,7 @@ class LBServiceGroup { [string]$AutoScale = 'DISABLED' [DscProperty()] - [ValidateSet('NO', 'YES')] + [ValidateSet('YES','NO')] [string]$Cacheable = 'NO' [DscProperty()] @@ -1037,7 +1039,7 @@ class LBServiceGroup { [string]$State = 'ENABLED' [DscProperty()] - [ValidateSet('NO', 'YES')] + [ValidateSet('YES','NO')] [string]$HealthMonitor = 'YES' [DscProperty()] @@ -1073,11 +1075,11 @@ class LBServiceGroup { [string]$ClientKeepAlive = 'NO' [DscProperty()] - [ValidateSet('YES', 'NO')] + [ValidateSet('YES','NO')] [string]$TCPBuffering = 'NO' [DscProperty()] - [ValidateSet('YES', 'NO')] + [ValidateSet('YES','NO')] [string]$HTTPCompression = 'YES' [DscProperty()] @@ -2182,7 +2184,7 @@ class LBRewritePolicy { if ($NSObject.Comment -ne $this.Comment) { Write-Verbose -Message "Comment does not match [$($NSObject.Comment) <> $($this.Comment)]" $pass = $false - } + } } else { Write-Verbose -Message "Responder Policy [$($this.Name)] was not found" $pass = $false @@ -2370,7 +2372,7 @@ class LBRewriteAction { if ($NSObject.comment -ne $this.Comment) { Write-Verbose -Message "Comment does not match [$($NSObject.Comment) <> $($this.Comment)]" $pass = $false - } + } } else { Write-Verbose -Message "Responder Action [$($this.Name)] was not found" $pass = $false @@ -2853,6 +2855,176 @@ class LBNSFeature { } } + + +[DscResource()] +class LBSSLCertificate { + [DscProperty(Key)] + [string]$CertKeyName + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty()] + [string]$CertPath + + [DscProperty()] + [string]$KeyPath + + [DscProperty()] + [string]$CertKeyFormat + + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if (($NSObject.CertKeyName -ne $this.CertKeyName) -OR ($NSObject.CertPath -ne $this.CertPath) -OR ($NSObject.KeyPath -ne $this.KeyPath) -OR ($NSObject.CertKeyFormat -ne $this.CertKeyFormat)) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.CertKeyName)], resource can only be removed and recreated" + Remove-NSCertKeyPair -CertKeyName $this.CertKeyName + } + } else { + Write-Verbose -Message "Creating resource [$($this.CertKeyName)]" + $params = @{ + CertKeyName = $this.CertKeyName + CertPath = $this.CertPath + } + if ($PSBoundParameters.ContainsKey('KeyPath')) { + $params.Add('KeyPath', $this.KeyPath) + } + if ($PSBoundParameters.ContainsKey('CertKeyFormat')) { + $params.Add('CertKeyFormat', $this.CertKeyFormat) + } + Add-NSCertKeyPair @params -ErrorAction SilentlyContinue + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSCertKeyPair -CertKeyName $this.CertKeyName -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Certificate: $($this.CertKeyName)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.certkeyname -ne $this.CertKeyName) { + Write-Verbose -Message "Certificate Key Name does not match [$($NSObject.certkeyname) <> $($this.CertKeyName)]" + $pass = $false + } + if ($NSObject.certpath -ne $this.CertPath) { + Write-Verbose -Message "Certificate Path does not match [$($NSObject.certpath) <> $($this.CertPath)]" + $pass = $false + } + if ($this.KeyPath) { + if ($NSObject.keypath -ne $this.KeyPath) { + Write-Verbose -Message "Key Path does not match [$($NSObject.keypath) <> $($this.KeyPath)]" + $pass = $false + } + } + } else { + Write-Verbose -Message "Certificate[$($this.CertKeyName)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBSSLCertificate]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSCertKeyPair -CertKeyName $this.CertKeyName -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + $obj = [LBSSLCertificate]::new() + $obj.CertKeyName = $this.CertKeyName + $obj.CertPath = $this.CertPath + $obj.CertKeyFormat = $this.CertKeyFormat + $obj.KeyPath = $this.KeyPath + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.CertKeyName = $s.certkey + $obj.CertPath = "/nsconfig/ssl/" + $s.cert + $obj.CertKeyFormat = $s.inform + if ($s.key) { + $obj.KeyPath = $s.key + } + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + + # [DscResource()] # class LBSSLCertificate { # [DscProperty(Key)] @@ -3103,7 +3275,7 @@ class LBNSFeature { # if ($NSObject.Telnet -ne $this.Telnet) { # Write-Verbose -Message "Setting Telnet [$($this.Telnet)]" # Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -Telnet -# } +# } # if ($NSObject.FTP -ne $this.FTP) { # Write-Verbose -Message "Setting FTP [$($this.FTP)]" # Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -FTP @@ -3803,4 +3975,1009 @@ class LBVLAN { Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue return $obj } +} + +[DscResource()] +class LBResponderPolicyBinding { + [DscProperty(Key)] + [string]$VirtualServerName + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty(Mandatory)] + [string]$PolicyName + + [DscProperty()] + [ValidateSet('REQUEST','RESPONSE')] + [string]$Bindpoint = 'REQUEST' + + [DscProperty()] + [int]$Priority = 100 + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if (($NSObject.VirtualServerName -ne $this.VirtualServerName) -OR ($NSObject.PolicyName -ne $this.PolicyName)) { + Write-Warning -Message "Setting VirtualServerName cannot be changed to [$($this.VirtualServerName)], resource can only be removed and recreated" + Remove-NSLBVirtualServerResponderPolicyBinding -VirtualServerName $this.VirtualServerName -PolicyName $this.PolicyName + Add-NSLBVirtualServerResponderPolicyBinding -VirtualServerName $this.VirtualServerName -PolicyName $this.PolicyName -Bindpoint $this.Bindpoint -Priority $this.Priority + } + } else { + Write-Verbose -Message "Added binding for, [$($this.VirtualServerName)]" + $params = @{ + virtualservername = $this.VirtualServerName + policyname = $this.PolicyName + bindpoint = $this.Bindpoint + priority = $this.Priority + } + Add-NSLBVirtualServerResponderPolicyBinding @params -Confirm:$false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSLBVirtualServerResponderPolicyBinding -VirtualServerName $this.VirtualServerName -PolicyName $this.PolicyName -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Responder Binding: $($this.PolicyName > $this.VirtualServerName)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.VirtualServerName -ne $this.VirtualServerName) { + Write-Verbose -Message "VirtualServerName does not match [$($NSObject.VirtualServerName) <> $($this.VirtualServerName)]" + $pass = $false + } + if ($NSObject.PolicyName -ne $this.PolicyName) { + Write-Verbose -Message "PolicyName does not match [$($NSObject.PolicyName) <> $($this.PolicyName)]" + $pass = $false + } + } else { + Write-Verbose -Message "File[$($this.VirtualServerName > $this.PolicyName)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBResponderPolicyBinding]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSLBVirtualServerResponderPolicyBinding -Name $this.VirtualServerName -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBResponderPolicyBinding]::new() + $obj.VirtualServerName = $this.VirtualServerName + $obj.PolicyName = $this.PolicyName + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.VirtualServerName = $s.name + $obj.PolicyName = $s.PolicyName + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + + +# [DscResource()] +# class LBServiceGroupMember { +# [DscProperty(Key)] +# [string]$Name + +# [DscProperty(Mandatory)] +# [string]$Name + +# [DscProperty()] +# [Ensure]$Ensure = [Ensure]::Present + +# [DscProperty(Mandatory)] +# [string]$NetScalerFQDN + +# [DscProperty(Mandatory)] +# [pscredential]$Credential + +# [DscProperty(Mandatory)] +# [string]$ServerName + +# [DscProperty(Mandatory)] +# [int]$Port = 80 + +# [DscProperty(Mandatory)] +# [int]$Weight = 1 + +# [DscProperty(Mandatory)] +# [int[]]$ServerID + +# [DscProperty(Mandatory)] +# [int[]]$HashID + +# [DscProperty(Mandatory)] +# [ValidateSet('ENABLED','DISABLED')] +# [string[]]$State + +# Init() { +# try { +# Import-Module -Name Netscaler -Verbose:$false -Debug:$false +# Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false +# } catch { +# throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" +# } +# } + +# [void]Set() { +# $t = $null +# $t = $this.Init() +# $NSObject = $this.Get() + +# try { +# Import-Module -Name Netscaler -Verbose:$false -Debug:$false +# Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false +# } catch { +# throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" +# } + +# try { +# switch ($this.Ensure) { +# 'Present' { +# if ($this.Ensure -eq $NSObject.Ensure) { +# # Run tests and set any needed attributes to match desired configuration +# if (($NSObject.Name -ne $this.Name) -OR ($NSObject.ServerName -ne $this.ServerName) -OR ($NSObject.Port -ne $this.Port) -OR ($NSObject.Weight -ne $this.Weight) -OR ($NSObject.State -ne $this.State)) { +# Remove-NSLBServiceGroupMemberBinding -Name $this.Name -ServerName $this.ServerName -Port $this.port +# New-NSLBServiceGroupMember -Name $this.Name -ServerName $this.ServerName -Port $this.Port -Weight $this.Weight -State $this.State +# } +# } else { +# Write-Verbose -Message "Added binding for, [$($this.VirtualServerName)]" +# $params = @{ +# Name = $this.Name +# ServerName = $this.ServerName +# Port = $this.Port +# State = $this.State +# weight = $this.weight +# } +# if ($PSBoundParameters.ContainsKey('ServerID')) { +# $params.Add('ServerID', $this.ServerID) +# } +# if ($PSBoundParameters.ContainsKey('HashID')) { +# $params.Add('HashID', $this.HashID) +# } +# New-NSLBServiceGroupMember @params -Confirm:$false +# } +# } 'Absent' { +# if ($this.Ensure -ne $NSObject.Ensure) { +# Remove-NSLBServiceGroupMemberBinding -Name $this.Name -ServerName $this.ServerName -ErrorAction SilentlyContinue +# Write-Verbose -Message "Removed $this.ServerName from: $this.Name" +# } +# } +# } +# } catch { +# Write-Error 'There was a problem setting the resource' +# Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" +# Write-Error $_ +# } +# try { +# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue +# } catch { +# # Do nothing +# } +# } + +# [bool]Test() { +# $pass = $true +# $t = $null +# $t = $this.Init() +# $NSObject = $this.Get() +# try { +# switch ($this.Ensure) { +# 'Present' { +# if ($this.Ensure -eq $NSObject.Ensure) { +# # Run tests and set any needed attributes to match desired configuration +# if ($NSObject.Name -ne $this.Name) { +# Write-Verbose -Message "ServiceGroupName does not match [$($NSObject.Name) <> $($this.Name)]" +# $pass = $false +# } +# if ($NSObject.ServerName -ne $this.ServerName) { +# Write-Verbose -Message "ServerName does not match [$($NSObject.ServerName) <> $($this.ServerName)]" +# $pass = $false +# } +# if ($NSObject.Port -ne $this.Port) { +# Write-Verbose -Message "Port does not match [$($NSObject.Port) <> $($this.Port)]" +# $pass = $false +# } +# if ($NSObject.Weight -ne $this.Weight) { +# Write-Verbose -Message "Weight does not match [$($NSObject.Weight) <> $($this.Weight)]" +# $pass = $false +# } +# if ($NSObject.ServerId -ne $this.ServerId) { +# Write-Verbose -Message "ServerId does not match [$($NSObject.ServerId) <> $($this.ServerId)]" +# $pass = $false +# } +# if ($NSObject.HashId -ne $this.HashId) { +# Write-Verbose -Message "HashId does not match [$($NSObject.HashId) <> $($this.HashId)]" +# $pass = $false +# } +# if ($NSObject.State -ne $this.State) { +# Write-Verbose -Message "State does not match [$($NSObject.State) <> $($this.State)]" +# $pass = $false +# } +# } else { +# Write-Verbose -Message "File[$($this.VirtualServerName > $this.PolicyName)] was not found" +# $pass = $false +# } +# } +# 'Absent' { +# if ($this.Ensure -ne $NSObject.Ensure) { +# $pass = $false +# } +# } +# } +# } catch { +# Write-Error 'There was a problem testing the resource' +# Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" +# Write-Error $_ +# } +# try { +# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue +# } catch { +# # Do nothing +# } +# return $pass +# } + +# [LBServiceGroupMember]Get() { +# $t = $null +# $t = $this.Init() + +# try { +# $s = Get-NSLBServiceGroupMemberBinding -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue +# } catch { +# $s = $null +# } + +# $obj = [LBServiceGroupMember]::new() +# $obj.Name = $this.Name +# $obj.ServerName = $this.ServerName +# $obj.Port = @() +# # $obj.Weight = $this.Weight +# # $obj.ServerId = $this.ServerId +# # $obj.HashId = $this.HashId +# # $obj.State = $this.State +# if ($s) { +# $obj.Ensure = [ensure]::Present +# $obj.Name = $s.servicegroupname +# $obj.ServerName = $s.servername +# $obj.Port = [int32[]]$s.port +# # $s.Port | % { $obj.port += $_.toString() } +# # for ($i=0;$i -lt $s.port.Length; $i++) { +# # $z = $s.port[$i].toString() +# # $obj.Port = $obj.Port.Add("$z") +# # } +# # $obj.Weight = $s.weight +# # $obj.ServerId = $s.serverid +# # $obj.HashId = $s.hashid +# # $obj.State = $s.state +# } else { +# $obj.Ensure = [ensure]::Absent +# } +# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue +# return $obj +# } +# } + +[DscResource()] +class LBService { + [DscProperty(Key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty()] + [ValidateSet('ADNS','ADNS_TCP','ANY','DHCPRA','DIAMETER','DNS','DNS_TCP','DTLS','FTP','HTTP','MSSQL','MYSQL','NNTP','RADIUS','RDP','RPCSVR','RTSP','SIP_UDP','SNMP','SSL','SSL_BRIDGE','SSL_DIAMETER','SSL_TCP','TCP','TFTP','UDP')] + [string]$ServiceType = 'HTTP' + + [DscProperty()] + [string]$IPAddress + + [DscProperty()] + [ValidateRange(0, 10000)] + [int]$Port = 80 + + [DscProperty(Mandatory)] + [string]$ServerName + + # [DscProperty()] + # [ValidateSet('FORWARD','TRANSPARENT','REVERSE')] + # [string]$CacheType + + [DscProperty()] + [ValidateSet('YES','NO')] + [string]$Cacheable = 'NO' + + [DscProperty()] + [string]$CurState + + [DscProperty()] + [ValidateSet('ENABLED','DISABLED')] + [string]$State = 'ENABLED' + + [DscProperty()] + [ValidateSet('YES','NO')] + [string]$HealthMonitor = 'YES' + + [DscProperty()] + [ValidateSet('DISABLED', 'ENABLED')] + [string]$AppFlowLog = 'ENABLED' + + [DscProperty()] + [ValidateLength(0, 256)] + [string]$Comment = [string]::Empty + + [DscProperty()] + [ValidateSet('ON', 'OFF')] + [string]$SureConnect = 'OFF' + + [DscProperty()] + [ValidateSet('ON', 'OFF')] + [string]$SurgeProtection = 'OFF' + + [DscProperty()] + [ValidateSet('YES','NO')] + [string]$UseProxyPort = 'YES' + + [DscProperty()] + [ValidateSet('ENABLED','DISABLED')] + [string]$DownStateFlush = 'ENABLED' + + [DscProperty()] + [ValidateSet('YES','NO')] + [string]$UseClientIP = 'NO' + + [DscProperty()] + [ValidateSet('YES','NO')] + [string]$ClientKeepAlive = 'NO' + + [DscProperty()] + [ValidateSet('YES','NO')] + [string]$TCPBuffering = 'NO' + + [DscProperty()] + [ValidateSet('YES','NO')] + [string]$HTTPCompression = 'YES' + + [DscProperty()] + [ValidateSet('ENABLED','DISABLED')] + [string]$ClientIP = 'DISABLED' + + # # [DscProperty()] + # # [ValidateSet('YES','NO')] + # # [string]$PathMonitor + + # [DscProperty()] + # [ValidateSet('YES','NO')] + # [string]$PathMonitorIndividual + + [DscProperty()] + [ValidateSet('On', 'OFF')] + [string]$RTPSessionIDRemap = 'OFF' + + [DscProperty()] + [string]$CustomServerID = 'None' + + [DscProperty()] + [ValidateRange(0, 4294967287)] + [int]$MaxBandwidthKbps + + [DscProperty()] + [ValidateSet('YES','NO')] + [string]$AccessDown = 'No' + + [DscProperty()] + [string]$TCPProfileName + + [DscProperty()] + [string]$HTTPProfileName + + [DscProperty()] + [string]$NetProfileName + + [DscProperty()] + [ValidateRange(0, 4294967287)] + [int]$HashID + + [DscProperty()] + [string]$ProcessLocal + + [DscProperty()] + [ValidateRange(0, 4294967287)] + [int]$TrafficDomain + + [DscProperty()] + [ValidateRange(0, 65535)] + [int]$ServerID + + [DscProperty()] + [ValidateRange(0, 65535)] + [int]$MonitorThreshold + + [DscProperty()] + [ValidateRange(0, 65535)] + [int]$MaxRequests + + [DscProperty()] + [ValidateRange(0, 4294967294)] + [int]$MaxClients + + [DscProperty()] + [ValidateRange(0, 31536000)] + [int]$ClientIdleTimeout = 180 + + [DscProperty()] + [ValidateRange(0, 31536000)] + [int]$ServerIdleTimeout = 360 + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne $this.Name) { + Write-Warning -Message "Setting Name cannot be changed to [$($this.Name)], resource can only be removed and recreated" + } + if ($NSObject.ServiceType -ne $this.ServiceType) { + Write-Warning -Message "Setting Name cannot be changed to [$($this.ServiceType)], resource can only be removed and recreated" + } + if ($NSObject.IPAddress -ne $this.IPAddress) { + Write-Warning -Message "Setting Name cannot be changed to [$($this.IPAddress)], resource can only be removed and recreated" + } + if ($NSObject.Port -ne $this.Port) { + Write-Warning -Message "Setting Name cannot be changed to [$($this.Port)], resource can only be removed and recreated" + } + if ($NSObject.ServerName -ne $this.ServerName) { + Write-Warning -Message "Setting Name cannot be changed to [$($this.ServerName)], resource can only be removed and recreated" + } + # if ($NSObject.CacheType -ne $this.CacheType) { + # Write-Warning -Message "Setting Name cannot be changed to [$($this.CacheType)], resource can only be removed and recreated" + # } + if ($NSObject.Cacheable -ne $this.Cacheable) { + Write-Warning -Message "Setting Name cannot be changed to [$($this.Cacheable)], resource can only be removed and recreated" + Set-NSLBService -Name $this.Name -Cacheable $this.Cacheable + } + switch ($NSObject.CurState) { + 'OUT OF SERVICE' { + if ($this.State -eq 'ENABLED') { + Write-Verbose -Message "State does not match [$($NSObject.CurState) <> $($this.State)]" + Set-NSLBService -Name $this.Name -IPAddress $this.IPAddress -State $this.State + } + } + 'DOWN' { + if ($this.State -eq 'DISABLED') { + Write-Verbose -Message "State does not match [$($NSObject.CurState) <> $($this.State)]" + Set-NSLBService -Name $this.Name -IPAddress $this.IPAddress -State $this.State + } + } + 'UP' { + if ($this.State -eq 'DISABLED') { + Write-Verbose -Message "State does not match [$($NSObject.CurState) <> $($this.State)]" + Set-NSLBService -Name $this.Name -IPAddress $this.IPAddress -State $this.State + } + } + } + if ($NSObject.HealthMonitor -ne $this.HealthMonitor) { + Set-NSLBService -Name $this.Name -HealthMonitor $this.HealthMonitor + } + if ($NSObject.AppFlowLog -ne $this.AppFlowLog) { + Set-NSLBService -Name $this.Name -AppFlowLog $this.AppFlowLog + } + if ($NSObject.Comment -ne $this.Comment) { + Set-NSLBService -Name $this.Name -Comment $this.Comment + } + if ($NSObject.SureConnect -ne $this.SureConnect) { + Set-NSLBService -Name $this.Name -SureConnect $this.SureConnect + } + if ($NSObject.SurgeProtection -ne $this.SurgeProtection) { + Set-NSLBService -Name $this.Name -SurgeProtection $this.SurgeProtection + } + if ($NSObject.UseProxyPort -ne $this.UseProxyPort) { + Set-NSLBService -Name $this.Name -UseProxyPort $this.UseProxyPort + } + if ($NSObject.DownStateFlush -ne $this.DownStateFlush) { + Set-NSLBService -Name $this.Name -DownStateFlush $this.DownStateFlush + } + if ($NSObject.UseClientIP -ne $this.UseClientIP) { + Set-NSLBService -Name $this.Name -UseClientIP $this.UseClientIP + } + if ($NSObject.ClientKeepAlive -ne $this.ClientKeepAlive) { + Set-NSLBService -Name $this.Name -ClientKeepAlive $this.ClientKeepAlive + } + if ($NSObject.TCPBuffering -ne $this.TCPBuffering) { + Set-NSLBService -Name $this.Name -TCPBuffering $this.TCPBuffering + } + if ($NSObject.HTTPCompression -ne $this.HTTPCompression) { + Set-NSLBService -Name $this.Name -HTTPCompression $this.HTTPCompression + } + if ($NSObject.ClientIP -ne $this.ClientIP) { + Write-Warning -Message "Setting Name cannot be changed to [$($this.ClientIP)], resource can only be removed and recreated" + } + # if ($NSObject.PathMonitor -ne $this.PathMonitor) { + # Set-NSLBService -Name $this.Name -PathMonitor $this.PathMonitor + # } + # if ($NSObject.PathMonitorIndividual -ne $this.PathMonitorIndividual) { + # Set-NSLBService -Name $this.Name -PathMonitorIndividual $this.HTTPCompression + # } + if ($NSObject.RTPSessionIDRemap -ne $this.RTPSessionIDRemap) { + Write-Warning -Message "Setting Name cannot be changed to [$($this.ClientIP)], resource can only be removed and recreated" + } + if ($NSObject.CustomServerID -ne $this.CustomServerID) { + Write-Warning -Message "Setting Name cannot be changed to [$($this.CustomServerID)], resource can only be removed and recreated" + } + if ($NSObject.MaxBandwidthKbps -ne $this.MaxBandwidthKbps) { + Set-NSLBService -Name $this.Name -MaxBandwidthKbps $this.MaxBandwidthKbps + } + if ($NSObject.AccessDown -ne $this.AccessDown) { + Set-NSLBService -Name $this.Name -AccessDown $this.AccessDown + } + # if ($NSObject.TCPProfileName -ne $this.TCPProfileName) { + # Set-NSLBService -Name $this.Name -TCPProfileName $this.TCPProfileName + # } + # if ($NSObject.HTTPProfileName -ne $this.HTTPProfileName) { + # Set-NSLBService -Name $this.Name -HTTPProfileName $this.HTTPProfileName + # } + # if ($NSObject.NetProfileName -ne $this.NetProfileName) { + # Set-NSLBService -Name $this.Name -NetProfileName $this.NetProfileName + # } + # if ($NSObject.HashID -ne $this.HashID) { + # Set-NSLBService -Name $this.Name -HashID $this.HashID + # } + # if ($NSObject.ProcessLocal -ne $this.ProcessLocal) { + # Set-NSLBService -Name $this.Name -ProcessLocal $this.ProcessLocal + # } + # if ($NSObject.TrafficDomain -ne $this.TrafficDomain) { + # Write-Warning -Message "Setting Name cannot be changed to [$($this.TrafficDomain)], resource can only be removed and recreated" + # } + # if ($NSObject.ServerID -ne $this.ServerID) { + # Set-NSLBService -Name $this.Name -ServerID $this.ServerID + # } + # if ($NSObject.MonitorThreshold -ne $this.MonitorThreshold) { + # Set-NSLBService -Name $this.Name -MonitorThreshold $this.MonitorThreshold + # } + if ($NSObject.MaxRequests -ne $this.MaxRequests) { + Set-NSLBService -Name $this.Name -MaxRequests $this.MaxRequests + } + if ($NSObject.MaxClients -ne $this.MaxClients) { + Set-NSLBService -Name $this.Name -MaxClients $this.MaxClients + } + # if ($NSObject.ClientIdleTimeout -ne $this.ClientIdleTimeout) { + # Set-NSLBService -Name $this.Name -ClientIdleTimeout $this.ClientIdleTimeout + # } + # if ($NSObject.ServerIdleTimeout -ne $this.ServerIdleTimeout) { + # Set-NSLBService -Name $this.Name -ServerIdleTimeout $this.ServerIdleTimeout + # } + } else { + Write-Verbose -Message "Added Service, [$($this.Name)]" + $params = @{ + name = $this.Name + servicetype = $this.ServiceType + port = $this.Port + servername = $this.ServerName + comment = $this.Comment + } + New-NSLBService @params -Confirm:$false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSLBService -Name $this.Name -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Service: $($this.Name > $this.Name)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne $this.Name) { + Write-Verbose -Message "Name does not match [$($NSObject.Name) <> $($this.Name)]" + $pass = $false + } + if ($NSObject.ServiceType -ne $this.ServiceType) { + Write-Verbose -Message "ServiceType does not match [$($NSObject.ServiceType) <> $($this.ServiceType)]" + $pass = $false + } + if ($NSObject.IPAddress -ne $this.IPAddress) { + Write-Verbose -Message "IPAddress does not match [$($NSObject.IPAddress) <> $($this.IPAddress)]" + $pass = $false + } + if ($NSObject.Port -ne $this.Port) { + Write-Verbose -Message "Port does not match [$($NSObject.Port) <> $($this.Port)]" + $pass = $false + } + if ($NSObject.ServerName -ne $this.ServerName) { + Write-Verbose -Message "ServerName does not match [$($NSObject.ServerName) <> $($this.ServerName)]" + $pass = $false + } + switch ($NSObject.CurState) { + 'OUT OF SERVICE' { + if ($this.State -eq 'ENABLED') { + Write-Verbose -Message "ServerName does not match [$($NSObject.CurState) <> $($this.State)]" + $pass = $false + } + } + 'DOWN' { + if ($this.State -eq 'DISABLED') { + Write-Verbose -Message "ServerName does not match [$($NSObject.CurState) <> $($this.State)]" + $pass = $false + } + } + 'UP' { + if ($this.State -eq 'DISABLED') { + Write-Verbose -Message "ServerName does not match [$($NSObject.CurState) <> $($this.State)]" + $pass = $false + } + } + } + # if ($NSObject.CacheType -ne $this.CacheType) { + # Write-Verbose -Message "CacheType does not match [$($NSObject.CacheType) <> $($this.CacheType)]" + # $pass = $false + # } + if ($NSObject.Cacheable -ne $this.Cacheable) { + Write-Verbose -Message "Cacheable does not match [$($NSObject.Cacheable) <> $($this.Cacheable)]" + $pass = $false + } + if ($NSObject.HealthMonitor -ne $this.HealthMonitor) { + Write-Verbose -Message "HealthMonitor does not match [$($NSObject.HealthMonitor) <> $($this.HealthMonitor)]" + $pass = $false + } + if ($NSObject.AppFlowLog -ne $this.AppFlowLog) { + Write-Verbose -Message "AppFlowLog does not match [$($NSObject.AppFlowLog) <> $($this.AppFlowLog)]" + $pass = $false + } + if ($NSObject.Comment -ne $this.Comment) { + Write-Verbose -Message "Comment does not match [$($NSObject.Comment) <> $($this.Comment)]" + $pass = $false + } + if ($NSObject.SureConnect -ne $this.SureConnect) { + Write-Verbose -Message "SureConnect does not match [$($NSObject.SureConnect) <> $($this.SureConnect)]" + $pass = $false + } + if ($NSObject.SurgeProtection -ne $this.SurgeProtection) { + Write-Verbose -Message "SurgeProtection does not match [$($NSObject.SurgeProtection) <> $($this.SurgeProtection)]" + $pass = $false + } + if ($NSObject.UseProxyPort -ne $this.UseProxyPort) { + Write-Verbose -Message "UseProxyPort does not match [$($NSObject.UseProxyPort) <> $($this.UseProxyPort)]" + $pass = $false + } + if ($NSObject.DownStateFlush -ne $this.DownStateFlush) { + Write-Verbose -Message "DownStateFlush does not match [$($NSObject.DownStateFlush) <> $($this.DownStateFlush)]" + $pass = $false + } + if ($NSObject.UseClientIP -ne $this.UseClientIP) { + Write-Verbose -Message "UseClientIP does not match [$($NSObject.UseClientIP) <> $($this.UseClientIP)]" + $pass = $false + } + if ($NSObject.ClientKeepAlive -ne $this.ClientKeepAlive) { + Write-Verbose -Message "ClientKeepAlive does not match [$($NSObject.ClientKeepAlive) <> $($this.ClientKeepAlive)]" + $pass = $false + } + if ($NSObject.TCPBuffering -ne $this.TCPBuffering) { + Write-Verbose -Message "TCPBuffering does not match [$($NSObject.TCPBuffering) <> $($this.TCPBuffering)]" + $pass = $false + } + if ($NSObject.HTTPCompression -ne $this.HTTPCompression) { + Write-Verbose -Message "HTTPCompression does not match [$($NSObject.HTTPCompression) <> $($this.HTTPCompression)]" + $pass = $false + } + if ($NSObject.ClientIP -ne $this.ClientIP) { + Write-Verbose -Message "ClientIP does not match [$($NSObject.ClientIP) <> $($this.ClientIP)]" + $pass = $false + } + # if ($NSObject.PathMonitor -ne $this.PathMonitor) { + # Write-Verbose -Message "PathMonitor does not match [$($NSObject.PathMonitor) <> $($this.PathMonitor)]" + # $pass = $false + # } + # if ($NSObject.PathMonitorIndividual -ne $this.PathMonitorIndividual) { + # Write-Verbose -Message "PathMonitorIndividual does not match [$($NSObject.PathMonitorIndividual) <> $($this.PathMonitorIndividual)]" + # $pass = $false + # } + if ($NSObject.RTPSessionIDRemap -ne $this.RTPSessionIDRemap) { + Write-Verbose -Message "RTPSessionIDRemap does not match [$($NSObject.RTPSessionIDRemap) <> $($this.RTPSessionIDRemap)]" + $pass = $false + } + if ($NSObject.CustomServerID -ne $this.CustomServerID) { + Write-Verbose -Message "CustomServerID does not match [$($NSObject.CustomServerID) <> $($this.CustomServerID)]" + $pass = $false + } + if ($NSObject.MaxBandwidthKbps -ne $this.MaxBandwidthKbps) { + Write-Verbose -Message "MaxBandwidthKbps does not match [$($NSObject.MaxBandwidthKbps) <> $($this.MaxBandwidthKbps)]" + $pass = $false + } + if ($NSObject.AccessDown -ne $this.AccessDown) { + Write-Verbose -Message "AccessDown does not match [$($NSObject.AccessDown) <> $($this.AccessDown)]" + $pass = $false + } + if ($NSObject.TCPProfileName -ne $this.TCPProfileName) { + Write-Verbose -Message "TCPProfileName does not match [$($NSObject.TCPProfileName) <> $($this.TCPProfileName)]" + $pass = $false + } + if ($NSObject.HTTPProfileName -ne $this.HTTPProfileName) { + Write-Verbose -Message "HTTPProfileName does not match [$($NSObject.HTTPProfileName) <> $($this.HTTPProfileName)]" + $pass = $false + } + if ($NSObject.NetProfileName -ne $this.NetProfileName) { + Write-Verbose -Message "NetProfileName does not match [$($NSObject.NetProfileName) <> $($this.NetProfileName)]" + $pass = $false + } + if ($NSObject.HashID -ne $this.HashID) { + Write-Verbose -Message "HashID does not match [$($NSObject.HashID) <> $($this.HashID)]" + $pass = $false + } + if ($NSObject.ProcessLocal -ne $this.ProcessLocal) { + Write-Verbose -Message "ProcessLocal does not match [$($NSObject.ProcessLocal) <> $($this.ProcessLocal)]" + $pass = $false + } + if ($NSObject.TrafficDomain -ne $this.TrafficDomain) { + Write-Verbose -Message "TrafficDomain does not match [$($NSObject.TrafficDomain) <> $($this.TrafficDomain)]" + $pass = $false + } + if ($NSObject.ServerID -ne $this.ServerID) { + Write-Verbose -Message "ServerID does not match [$($NSObject.ServerID) <> $($this.ServerID)]" + $pass = $false + } + if ($NSObject.MonitorThreshold -ne $this.MonitorThreshold) { + Write-Verbose -Message "MonitorThreshold does not match [$($NSObject.MonitorThreshold) <> $($this.MonitorThreshold)]" + $pass = $false + } + if ($NSObject.MaxRequests -ne $this.MaxRequests) { + Write-Verbose -Message "MaxRequests does not match [$($NSObject.MaxRequests) <> $($this.MaxRequests)]" + $pass = $false + } + if ($NSObject.MaxClients -ne $this.MaxClients) { + Write-Verbose -Message "MaxClients does not match [$($NSObject.MaxClients) <> $($this.MaxClients)]" + $pass = $false + } + if ($NSObject.ClientIdleTimeout -ne $this.ClientIdleTimeout) { + Write-Verbose -Message "ClientIdleTimeout does not match [$($NSObject.ClientIdleTimeout) <> $($this.ClientIdleTimeout)]" + $pass = $false + } + if ($NSObject.ServerIdleTimeout -ne $this.ServerIdleTimeout) { + Write-Verbose -Message "ServerIdleTimeout does not match [$($NSObject.ServerIdleTimeout) <> $($this.ServerIdleTimeout)]" + $pass = $false + } + } else { + Write-Verbose -Message "File[$($this.VirtualServerName > $this.PolicyName)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBService]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSLBService -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBService]::new() + $obj.Name = $this.Name + $obj.ServiceType = $this.ServiceType + $obj.IPAddress = $this.IPAddress + $obj.Port = $this.Port + $obj.ServerName = $this.ServerName + # $obj.CacheType = $this.CacheType + $obj.Cacheable = $this.Cacheable + $obj.CurState = $this.CurState + $obj.HealthMonitor = $this.HealthMonitor + $obj.AppFlowLog = $this.AppFlowLog + $obj.Comment = $this.Comment + $obj.SureConnect = $this.SureConnect + $obj.SurgeProtection = $this.SurgeProtection + $obj.UseProxyPort = $this.UseProxyPort + $obj.DownStateFlush = $this.DownStateFlush + $obj.UseClientIP = $this.UseClientIP + $obj.ClientKeepAlive = $this.ClientKeepAlive + $obj.TCPBuffering = $this.TCPBuffering + $obj.HTTPCompression = $this.HTTPCompression + $obj.ClientIP = $this.ClientIP + # $obj.PathMonitor = $this.PathMonitor + # $obj.PathMonitorIndividual = $this.PathMonitorIndividual + $obj.RTPSessionIDRemap = $this.RTPSessionIDRemap + $obj.CustomServerID = $this.CustomServerID + $obj.MaxBandwidthKbps = $this.MaxBandwidthKbps + $obj.AccessDown = $this.AccessDown + $obj.TCPProfileName = $this.TCPProfileName + $obj.HTTPProfileName = $this.HTTPProfileName + $obj.NetProfileName = $this.NetProfileName + $obj.HashID = $this.HashID + $obj.ProcessLocal = $this.ProcessLocal + $obj.TrafficDomain = $this.TrafficDomain + $obj.ServerID = $this.ServerID + $obj.MonitorThreshold = $this.MonitorThreshold + $obj.MaxRequests = $this.MaxRequests + $obj.MaxClients = $this.MaxClients + $obj.ClientIdleTimeout = $this.ClientIdleTimeout + $obj.ServerIdleTimeout = $this.ServerIdleTimeout + + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Name = $s.name + $obj.ServiceType = $s.servicetype + $obj.IPAddress = $s.ipaddress + $obj.Port = $s.port + $obj.ServerName = $s.servername + # if ($s.cachetype -ne "SERVER") { + # $obj.CacheType = $s.cachetype + # } else { + # $obj.CacheType = "SERVER" } + if ($s.cacheable) { $obj.Cacheable = $s.cacheable } + $obj.CurState = $s.svrstate + $obj.HealthMonitor = $s.healthmonitor + $obj.AppFlowLog = $s.appflowlog + $obj.Comment = $s.comment + $obj.SureConnect = $s.sc + $obj.SurgeProtection = $s.sp + $obj.UseProxyPort = $s.useproxyport + $obj.DownStateFlush = $s.downstateflush + $obj.UseClientIP = $s.usip + $obj.ClientKeepAlive = $s.cka + $obj.TCPBuffering = $s.tcpb + $obj.HTTPCompression = $s.cmp + $obj.ClientIP = $s.cip + # $obj.PathMonitor = $s.pathmonitor + # $obj.PathMonitorIndividual = $s.pathmonitorindv + $obj.RTPSessionIDRemap = $s.rtspsessionidremap + $obj.CustomServerID = $s.customserverid + $obj.MaxBandwidthKbps = $s.maxbandwidth + $obj.AccessDown = $s.accessdown + if ($s.tcpprofilename) { $obj.TCPProfileName = $s.tcpprofilename } + if ($s.httpprofilename) { $obj.HTTPProfileName = $s.httpprofilename } + if ($s.netProfile) { $obj.NetProfileName = $s.netprofile } + if ($s.hashid) { $obj.HashID = $s.hashid } + $obj.ProcessLocal = $s.processlocal + $obj.TrafficDomain = $s.td + if ($s.serverid) { $obj.ServerID = $s.serverid } + $obj.MonitorThreshold = $s.monthreshold + $obj.MaxRequests = $s.maxreq + $obj.MaxClients = $s.maxclient + $obj.ClientIdleTimeout = $s.clttimeout + $obj.ServerIdleTimeout = $s.svrtimeout + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } } \ No newline at end of file diff --git a/old/POSHOrigin_NetScaler/Examples/Example_LBServer.ps1 b/old/POSHOrigin_NetScaler/Examples/Example_LBServer.ps1 new file mode 100644 index 0000000..bbf1803 --- /dev/null +++ b/old/POSHOrigin_NetScaler/Examples/Example_LBServer.ps1 @@ -0,0 +1,51 @@ +$DscConfigData = @{ + AllNodes = @( + @{ + NodeName = "*" + PSDscAllowPlainTextPassword = $true + PSDscAllowDomainUser = $true + } + @{ + NodeName = 'localhost' + } + ) +} + +Configuration Example_LBServer { + param( + [string[]]$NodeName = 'localhost', + + [Parameter(Mandatory)] + [string]$Name, + + [Parameter(Mandatory)] + [string]$IPAddress, + + [Parameter(Mandatory)] + [string]$NetScalerFQDN, + + [Parameter(Mandatory)] + [pscredential]$Credential, + + [string]$Comments, + + [int]$TrafficDomainId, + + [string]$State + ) + + Import-DscResource -Name LBServer -ModuleName POSHOrigin_NetScaler + + Node $NodeName { + LBServer "Create$Name" { + Ensure = 'Present' + Name = $Name + IPAddress = $IPAddress + NetScalerFQDN = $NetScalerFQDN + Credential = $Credential + Comments = $Comments + TrafficDomainId = $TrafficDomainId + State = $State + } + } +} \ No newline at end of file diff --git a/old/POSHOrigin_NetScaler/Examples/Example_LBVirtualServer.ps1 b/old/POSHOrigin_NetScaler/Examples/Example_LBVirtualServer.ps1 new file mode 100644 index 0000000..ed66c6c --- /dev/null +++ b/old/POSHOrigin_NetScaler/Examples/Example_LBVirtualServer.ps1 @@ -0,0 +1,57 @@ +$DscConfigData = @{ + AllNodes = @( + @{ + NodeName = "*" + PSDscAllowPlainTextPassword = $true + PSDscAllowDomainUser = $true + } + @{ + NodeName = 'localhost' + } + ) +} + +Configuration Example_LBVirtualServer { + param( + [string[]]$NodeName = 'localhost', + + [Parameter(Mandatory)] + [string]$Name, + + [Parameter(Mandatory)] + [string]$IPAddress, + + [Parameter(Mandatory)] + [string]$NetScalerFQDN, + + [Parameter(Mandatory)] + [pscredential]$Credential, + + [int]$Port, + + [string]$ServiceType, + + [string]$LBMethod, + + [string]$Comments, + + [string]$State + ) + + Import-DscResource -Name LBVirtualServer -ModuleName POSHOrigin_NetScaler + + Node $NodeName { + LBVirtualServer "Create$Name" { + Ensure = 'Present' + Name = $Name + IPAddress = $IPAddress + NetScalerFQDN = $NetScalerFQDN + Credential = $Credential + Port = $Port + ServiceType = $ServiceType + LBMethod = $LBMethod + Comments = $Comments + State = $State + } + } +} \ No newline at end of file diff --git a/old/POSHOrigin_NetScaler/Examples/Example_POSHOrigin_LBServer.ps1 b/old/POSHOrigin_NetScaler/Examples/Example_POSHOrigin_LBServer.ps1 new file mode 100644 index 0000000..4ffc55c --- /dev/null +++ b/old/POSHOrigin_NetScaler/Examples/Example_POSHOrigin_LBServer.ps1 @@ -0,0 +1,12 @@ +resource 'POSHOrigin_NetScaler:LBServer' 'serverxyz' @{ + Ensure = 'Present' + NetScalerFQDN = 'mynetscaler.mydomain.com' + IPAddress = '192.168.100.100' + Comments = 'This is a comment' + TrafficDomainId = 1 + State = 'ENABLED' + Credential = Get-POSHOriginSecret 'pscredential' @{ + username = 'administrator' + password = 'K33p1t53cr3tK33p1t5@f3' + } +} \ No newline at end of file diff --git a/old/POSHOrigin_NetScaler/Examples/Example_POSHOrigin_LBVirtualServer.ps1 b/old/POSHOrigin_NetScaler/Examples/Example_POSHOrigin_LBVirtualServer.ps1 new file mode 100644 index 0000000..2128743 --- /dev/null +++ b/old/POSHOrigin_NetScaler/Examples/Example_POSHOrigin_LBVirtualServer.ps1 @@ -0,0 +1,14 @@ +resource 'POSHOrigin_NetScaler:LBServer' 'lbserverxyz' @{ + Ensure = 'Present' + NetScalerFQDN = 'mynetscaler.mydomain.com' + Comments = 'This is a comment' + IPAddress = '192.168.100.101' + Port = 80 + ServiceType = 'HTTP' + LBMethod = 'ROUNDROBIN' + State = 'ENABLED' + Credential = Get-POSHOriginSecret 'pscredential' @{ + username = 'administrator' + password = 'K33p1t53cr3tK33p1t5@f3' + } +} \ No newline at end of file diff --git a/old/POSHOrigin_NetScaler/Invoke.ps1 b/old/POSHOrigin_NetScaler/Invoke.ps1 new file mode 100644 index 0000000..c2e93aa --- /dev/null +++ b/old/POSHOrigin_NetScaler/Invoke.ps1 @@ -0,0 +1,133 @@ +<# + This script expects to be passed a psobject with all the needed properties + in order to invoke 'NetScaler' DSC resources. +#> +[cmdletbinding()] +param( + [parameter(mandatory)] + [psobject]$Options, + + [bool]$Direct = $false +) + +# Ensure we have a valid 'ensure' property +if ($null -eq $Options.options.Ensure) { + $Options.Options | Add-Member -MemberType NoteProperty -Name Ensure -Value 'Present' -Force +} + +# Get the resource type +$type = $Options.Resource.split(':')[1] + +$hash = @{ + Name = $Options.Name + Ensure = $Options.options.Ensure + Credential = $Options.Options.Adminuser.Credential + NetScalerFQDN = $Options.Options.NetScalerFQDN +} + +$export = $false +if ($Options.options.ParameterExport) { + $export = [bool]$Options.options.ParameterExport +} + +switch ($type) { + 'LBServer' { + if ($Direct) { + $hash.IPAddress = $Options.Options.IPAddress + $hash.Comments = $Options.Options.Description + $hash.TrafficDomainId = $Options.Options.TrafficDomainId + $hash.State = $Options.Options.State + $hash.ParameterExport = $export + return $hash + } else { + $confName = "$type" + '_' + $Options.Name + Write-Verbose -Message "Returning configuration function for resource: $confName" + Configuration $confName { + Param ( + [psobject]$ResourceOptions + ) + + Import-DscResource -Name LBServer -ModuleName POSHOrigin_NetScaler + + # Credentials may be specified in line. Test for that + if ($ResourceOptions.Options.Credential -is [pscredential]) { + $cred = $ResourceOptions.Options.Credential + } + + # Credentials may be listed under secrets. Test for that + if ($ResourceOptions.options.secrets.Credential) { + $cred = $ResourceOptions.options.secrets.Credential.credential + } + + if (-Not $ResourceOptions.options.State) { + $ResourceOptions.options | Add-Member -MemberType NoteProperty -Name State -Value 'ENABLED' + } + + LBServer $ResourceOptions.Name { + Ensure = $ResourceOptions.options.Ensure + Name = $ResourceOptions.Name + NetScalerFQDN = $ResourceOptions.options.netscalerfqdn + Credential = $cred + IPAddress = $ResourceOptions.options.IPAddress + TrafficDomainId = $ResourceOptions.options.TrafficDomainId + Comments = $ResourceOptions.options.comments + State = $ResourceOptions.options.State + ParameterExport = $export + } + } + } + } + 'LBVirtualServer' { + if ($Direct) { + $hash.IPAddress = $Options.Options.IPAddress + $hash.Port = $Options.Options.Port + $hash.LBMethod = $Options.Options.LBMethod + $hash.Comments = $Options.Options.Description + $hash.ServiceGroup = $Options.Options.ServiceGroup + $hash.Service = $Options.Options.Service + $hash.State = $Options.Options.State + $hash.ParameterExport = $export + return $hash + } else { + $confName = "$type" + '_' + $Options.Name + Write-Verbose -Message "Returning configuration function for resource: $confName" + Configuration $confName { + Param ( + [psobject]$ResourceOptions + ) + + Import-DscResource -Name LBVirtualServer -ModuleName POSHOrigin_NetScaler + + # Credentials may be specified in line. Test for that + if ($ResourceOptions.Options.Credential -is [pscredential]) { + $cred = $ResourceOptions.Options.Credential + } + + # Credentials may be listed under secrets. Test for that + if ($ResourceOptions.options.secrets.Credential) { + $cred = $ResourceOptions.options.secrets.Credential.credential + } + + if (-Not $ResourceOptions.options.State) { + $ResourceOptions.options | Add-Member -MemberType NoteProperty -Name State -Value 'ENABLED' + } + + LBVirtualServer $ResourceOptions.Name { + Ensure = $ResourceOptions.options.Ensure + Name = $ResourceOptions.Name + NetScalerFQDN = $ResourceOptions.options.netscalerfqdn + Credential = $cred + IPAddress = $ResourceOptions.options.IPAddress + Port = $ResourceOptions.options.Port + ServiceType = $ResourceOptions.options.servicetype + LBMethod = $ResourceOptions.options.lbmethod + ServiceGroup = $ResourceOptions.options.servicegroup + Service = $ResourceOptions.options.service + Comments = $ResourceOptions.options.comments + State = $ResourceOptions.options.State + ParameterExport = $export + } + } + } + } +} \ No newline at end of file diff --git a/old/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psd1 b/old/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psd1 new file mode 100644 index 0000000..9a25762 --- /dev/null +++ b/old/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psd1 @@ -0,0 +1,44 @@ +@{ + # Script module or binary module file associated with this manifest. + RootModule = 'POSHOrigin_NetScaler.psm1' + + # Version number of this module. + ModuleVersion = '1.1.2' + + # ID used to uniquely identify this module + GUID = 'bd4390dc-a8ad-4bce-8d69-f53ccf8e4163' + + # Author of this module + Author = 'Brandon Olin' + + # Copyright statement for this module + Copyright = '(c) 2015 Brandon Olin. All rights reserved.' + + # Description of the functionality provided by this module + Description = 'POSHOrigin DSC module to manage Citrix NetScaler resources.' + + # Minimum version of the Windows PowerShell engine required by this module + PowerShellVersion = '5.0' + + # Modules that must be imported into the global environment prior to importing this module + RequiredModules = 'NetScaler' + + # DSC resources to export from this module + DscResourcesToExport = @('LBVirtualServer','LBServer','LBMonitor','LBServiceGroup','LBNTPServer','LBResponderPolicy','LBResponderAction','LBSSLCertificate','LBRewritePolicy','LBRewriteAction','LBDNSServer','LBNSMode','LBNSFeature','LBNSIP','LBNSVirtualServerBinding','LBSystemFile','LBVLAN') + + PrivateData = @{ + PSData = @{ + # Tags applied to this module. These help with module discovery in online galleries. + Tags = @( + 'Desired State Configuration', + 'DSC', + 'POSHOrigin', + 'Citrix', + 'NetScaler', + 'Load balancing', + 'Infrastructure as Code', + 'IaC' + ) + } + } +} \ No newline at end of file diff --git a/old/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 b/old/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 new file mode 100644 index 0000000..cea3f67 --- /dev/null +++ b/old/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 @@ -0,0 +1,3808 @@ +#Requires -Version 5.0 +#Requires -Module NetScaler + +enum Ensure { + Absent + Present +} + +[DscResource()] +class LBVirtualServer { + [DscProperty(key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [string]$IPAddress + + [DscProperty()] + [ValidateLength(0, 256)] + [string]$Comment = '' + + [DscProperty(Mandatory)] + [ValidateRange(1, 65534)] + [int]$Port + + [DscProperty()] + [ValidateSet('DHCPRA','DIAMTER', 'DNS', 'DNS_TCP', 'DLTS', 'FTP', 'HTTP', 'MSSQL', + 'MYSQL', 'NNTP', 'PUSH','RADIUS', 'RDP', 'RTSP', 'SIP_UDP', 'SSL', 'SSL_BRIDGE', + 'SSL_DIAMETER', 'SSL_PUSH', 'SSL_TCP', 'TCP', 'TFTP', 'UDP')] + [string]$ServiceType = 'HTTP' + + [DscProperty()] + [ValidateSet('ROUNDROBIN', 'LEASTCONNECTION', 'LEASTRESPONSETIME', 'LEASTBANDWIDTH', + 'LEASTPACKETS', 'CUSTOMLOAD', 'LRTM', 'URLHASH', 'DOMAINHASH', 'DESTINATIONIPHASH', + 'SOURCEIPHASH', 'TOKEN', 'SRCIPDESTIPHASH', 'SRCIPSRCPORTHASH', 'CALLIDHASH')] + [string]$LBMethod = 'ROUNDROBIN' + + [DscProperty()] + [ValidateSet('SOURCEIP', 'COOKIEINSERT', 'SSLSESSION', 'CUSTOMSERVERID', 'RULE', 'URLPASSIVE', 'DESTIP', 'SRCIPDESTIP', 'CALLID' ,'RTSPID', 'FIXSESSION', 'NONE')] + [string]$PersistenceType = 'SOURCEIP' + + [DscProperty()] + [string]$HttpRedirectURL = '' + + [DscProperty()] + [ValidateSet('PASSIVE', 'ACTIVE')] + [string]$ICMPVSRResponse = 'PASSIVE' + + [DscProperty()] + [int]$TimeOut = 2 + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + try { + switch ($this.Ensure) { + 'Present' { + if ($NSObject.Ensure -eq [ensure]::Present) { + if ($NSObject.name -ne $this.Name) { + Write-Warning -Message 'NetScaler does not support changing virtual server name on an existing virtual server. Virtual server must be deleted and recreated.' + } + if ($NSObject.ipaddress -ne $this.IPAddress) { + Set-NSLBVirtualServer -Name $this.Name -IPAddress $this.IPAddress -Verbose:$false -Confirm:$false + Write-Verbose -Message "Setting virtual server IP [$($this.IPAddress)]" + } + if ($NSObject.comment -ne $this.Comment) { + Write-Verbose -Message "Setting virtual server Comment [$($this.Comment)]" + Set-NSLBVirtualServer -Name $this.Name -Comment $this.Comment -Verbose:$false -Force + } + if ($NSObject.Port -ne $this.Port) { + Write-Warning -Message 'NetScaler does not support changing virtual server port on an existing virtual server. Virtual server must be deleted and recreated.' + } + if ($NSObject.ServiceType -ne $this.ServiceType) { + Write-Warning -Message 'NetScaler does not support changing virtual server service type on an existing virtual server. Virtual server must be deleted and recreated.' + } + if ($NSObject.lbmethod -ne $this.LBMethod) { + Set-NSLBVirtualServer -Name $this.Name -LBMethod $this.LBMethod -Verbose:$false -Force + Write-Verbose -Message "Setting virtual server load balance method [$($this.LBMethod)]" + } + if ($NSObject.persistencetype -ne $this.PersistenceType) { + Set-NSLBVirtualServer -Name $this.Name -PersistenceType $this.PersistenceType -Verbose:$false -Force + Write-Verbose -Message "Setting virtual server persistence [$($this.PersistenceType)]" + } + if ($NSObject.httpredirecturl -ne $this.HttpRedirectURL) { + Set-NSLBVirtualServer -Name $this.Name -HttpRedirectURL $this.HttpRedirectURL -Verbose:$false -Force + Write-Verbose -Message "Setting virtual server redirect [$($this.HttpRedirectURL)]" + } + if ($NSObject.icmpvsrresponse -ne $this.ICMPVSRResponse) { + Set-NSLBVirtualServer -Name $this.Name -ICMPVSRResponse $this.ICMPVSRResponse -Verbose:$false -Force + Write-Verbose -Message "Setting virtual server icmpvsrresponse [$($this.ICMPVSRResponse)]" + } + if ($NSObject.timeout -ne $this.TimeOut) { + Set-NSLBVirtualServer -Name $this.Name -TimeOut $this.TimeOut -Verbose:$false -Force + Write-Verbose -Message "Setting virtual server timeout [$($this.TimeOut)]" + } + } else { + Write-Verbose -Message "Creating virtual server [$($this.Name)]" + $params = @{ + Name = $this.Name + IPAddress = $this.IPAddress + ServiceType = $this.ServiceType + Port = $this.Port + LBMethod = $this.LBMethod + PersistenceType = $this.PersistenceType + ICMPVSRResponse = $this.ICMPVSRResponse + TimeOut = $this.TimeOut + Comment = $this.Comment + } + if ($null -ne $this.HttpRedirectURL) { + $params.HttpRedirectURL = $this.HttpRedirectURL + } + New-NSLBVirtualServer @params -ErrorAction SilentlyContinue + } + } 'Absent' { + try { + Write-Verbose -Message "Removing virtual server: $($this.Name)" + Remove-NSLBVirtualServer -Name $this.Name -Confirm:$false -Verbose:$false -Force + } catch { + write-host "Virtual Server $this.Name was not found" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + + if ($NSObject.name -ne $this.Name) { + Write-Verbose -Message "Virtual server Name does not match [$($NSObject.name) <> $($this.Name)" + $pass = $false + } + if ($NSObject.ipaddress -ne $this.IPAddress) { + Write-Verbose -Message "Virtual server IP address does not match [$($NSObject.ipaddress) <> $($this.IPAddress)" + $pass = $false + } + if ($NSObject.comment -ne $this.Comment) { + Write-Verbose -Message "Virtual server Comment do not match [$($NSObject.comment) <> $($this.Comment)]" + $pass = $false + } + if ($NSObject.port -ne $this.Port) { + Write-Verbose -Message "Virtual server port does not match [$($NSObject.port) <> $($this.Port)" + $pass = $false + } + if ($NSObject.servicetype -ne $this.ServiceType) { + Write-Verbose -Message "Virtual server service type does not match [$($NSObject.servicetype) <> $($this.ServiceType)" + $pass = $false + } + if ($NSObject.lbmethod -ne $this.LBMethod) { + Write-Verbose -Message "Virtual server load balance method does not match [$($NSObject.lbmethod) <> $($this.LBMethod)" + $pass = $false + } + if ($NSObject.persistencetype -ne $this.PersistenceType) { + Write-Verbose -Message "Virtual server Persistence Type does not match [$($NSObject.persistencetype) <> $($this.PersistenceType)" + $pass = $false + } + if ($NSObject.ICMPVSRResponse -ne $this.ICMPVSRResponse) { + Write-Verbose -Message "Virtual server ICMP Response does not match [$($NSObject.ICMPVSRResponse) <> $($this.ICMPVSRResponse)" + $pass = $false + } + if ($NSObject.httpredirectURL -ne $this.HTTPRedirectURL) { + Write-Verbose -Message "Virtual server HTTP Redirect does not match [$($NSObject.httpredirectURL) <> $($this.HTTPRedirectURL)" + $pass = $false + } + if ($NSObject.timeout -ne $this.TimeOut) { + Write-Verbose -Message "Virtual server Timeout does not match [$($NSObject.timeout) <> $($this.TimeOut)" + $pass = $false + } + } else { + Write-Verbose -Message "Resource [$($this.Name)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBVirtualServer]Get() { + $t = $null + $t = $this.Init() + try { + $s = Get-NSLBVirtualServer -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBVirtualServer]::new() + $obj.Name = $this.Name + $obj.IPAddress = $this.IPAddress + $obj.Port = $this.Port + $obj.ServiceType = $this.ServiceType + $obj.Comment = $this.Comment + $obj.LBMethod = $this.LBMethod + $obj.PersistenceType = $this.PersistenceType + $obj.HTTPRedirectURL = $this.HTTPRedirectURL + $obj.ICMPVSRResponse = $this.ICMPVSRResponse + $obj.TimeOut = $this.TimeOut + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Name = $s.Name + $obj.IPAddress = $s.ipv46 + $obj.Port = $s.port + $obj.ServiceType = $s.servicetype + if ($s.comment) { $obj.Comment = $s.comment } + $obj.LBMethod = $s.lbmethod + $obj.PersistenceType = $s.persistencetype + if ($s.redirurl) { $obj.HTTPRedirectURL = $s.redirurl } + $obj.ICMPVSRResponse = $s.icmpvsrresponse + $obj.TimeOut = $s.timeout + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBServer { + [DscProperty(Key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [string]$IPAddress + + [DscProperty()] + [ValidateLength(0, 256)] + [string]$Comment = '' + + [DscProperty()] + [ValidateSet('ENABLED', 'DISABLED')] + [string]$State = 'ENABLED' + + [DscProperty()] + [bool]$ParameterExport = $false + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + try { + switch ($this.Ensure) { + 'Present' { + if ($NSObject.Ensure -eq [ensure]::Present) { + if ($NSObject.ipaddress -ne $this.IPAddress) { + Write-Verbose -Message "Setting server IP [$($this.IPAddress)]" + Set-NSLBServer -Name $this.Name -IPAddress $this.IPAddress -Force -Verbose:$false + } + if ($NSObject.comment -ne $this.Comment) { + Write-Verbose -Message "Setting server Comment [$($this.Comment)]" + Set-NSLBServer -Name $this.Name -Comment $this.Comment -Force -Verbose:$false + } + if ($NSObject.state -ne $this.State) { + Write-Verbose -Message "Setting server state [$($this.State)]" + if ($this.State -eq 'ENABLED') { + Enable-NSLBServer -Name $this.Name -Force -Verbose:$false + } else { + Disable-NSLBServer -Name $this.Name -Force -Verbose:$false + } + } + } else { + Write-Verbose -Message "Creating server [$($this.Name)]" + $params = @{ + Name = $this.Name + IPAddress = $this.IPAddress + Comment = $this.Comment + Confirm = $false + Verbose = $false + } + if ($null -ne $this.TrafficDomainId) { + $params.TrafficDomainId = $this.TrafficDomainId + } + New-NSLBServer @params + } + } 'Absent' { + try { + Write-Verbose -Message "Removing server: $($this.Name)" + Remove-NSLBServer -Name $this.Name -Confirm:$false -Verbose:$false -Force + } catch { + write-host "Virtual Server $this.Name was not found" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + Write-Verbose -Message "Server [$($this.Name)] exists" + + if ($NSObject.ipaddress -ne $this.IPAddress) { + Write-Verbose -Message "Server IP address does not match [$($NSObject.ipaddress) <> $($this.IPAddress)]" + $pass = $false + } + if ($NSObject.comment -ne $this.Comment) { + Write-Verbose -Message "Server Comment does not match [$($NSObject.comment) <> $($this.Comment)]" + $pass = $false + } + if ($NSObject.state -ne $this.State) { + Write-Verbose -Message "Server state does not match [$($NSObject.state) <> $($this.State)]" + $pass = $false + } + } else { + Write-Verbose -Message "Server [$($this.Name)] was not found" + $pass = $false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBServer]Get() { + $t = $null + $t = $this.Init() + try { + $s = Get-NSLBServer -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBServer]::new() + $obj.Name = $this.Name + $obj.IPAddress = $this.IPAddress + $obj.Comment = $this.Comment + $obj.State = $this.State + $obj.Credential = $this.Credential + $obj.NetScalerFQDN = $this.NetScalerFQDN + $obj.ParameterExport = $this.ParameterExport + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.IPAddress = $s.ipaddress + $obj.Comment = $s.comment + $obj.State = $s.state + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBMonitor { + [DscProperty(Key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty(Mandatory)] + [ValidateSet('PING', 'TCP', 'HTTP', 'TCP-ECV', 'HTTP-ECV', 'UDP-ECV', 'DNS', 'FTP', 'LDNS-PING', + 'LDNS-TCP', 'RADIUS', 'USER', 'HTTP-INLINE', 'SIP-UDP', 'LOAD', 'FTP-EXTENDED', 'SMTP', 'SNMP', + 'NNTP', 'MYSQL', 'MYSQL-ECV', 'MSSQL-ECV', 'ORACLE-ECV', 'LDAP', 'POP3', 'CITRIX-XML-SERVICE', + 'CITRIX-WEB-INTERFACE', 'DNS-TCP', 'RTSP', 'ARP', 'CITRIX-AG', 'CITRIX-AAC-LOGINPAGE', 'CITRIX-AAC-LAS', + 'CITRIX-XD-DDC', 'ND6', 'CITRIX-WI-EXTENDED', 'DIAMETER', 'RADIUS_ACCOUNTING', 'STOREFRONT')] + [string]$Type = 'HTTP' + + [DscProperty(Mandatory)] + [ValidateRange(1, 20940000)] + [int]$Interval = 5 + + [DscProperty(Mandatory)] + [ValidateSet('SEC', 'MSEC', 'MIN')] + [string]$IntervalType = 'SEC' + + [DscProperty(Mandatory)] + [ValidateRange(1, 20939000)] + [int]$ResponseTimeout = 2 + + [DscProperty(Mandatory)] + [ValidateSet('SEC', 'MSEC', 'MIN')] + [string]$ResponseTimeoutType = 'SEC' + + [DscProperty(Mandatory)] + [ValidateRange(1, 20939000)] + [int]$Downtime = 30 + + [DscProperty(Mandatory)] + [ValidateSet('SEC', 'MSEC', 'MIN')] + [string]$DowntimeType = 'SEC' + + [DscProperty(Mandatory)] + [DscProperty()] + [int]$DestinationPort + + [DscProperty(Mandatory)] + [ValidateRange(1, 127)] + [int]$Retries = 3 + + [DscProperty(Mandatory)] + [ValidateRange(0, 32)] + [int]$SuccessRetries = 1 + + [DscProperty()] + [string]$DestinationIP + + [DscProperty()] + [ValidateRange(0, 20939000)] + [int]$Deviation + + [DscProperty()] + [ValidateRange(0, 100)] + [int]$ResponseTimeoutThreshold + + [DscProperty()] + [ValidateRange(0, 32)] + [int]$AlertRetries + + [DscProperty()] + [ValidateRange(0, 32)] + [int]$FailureRetries + + [DscProperty()] + [ValidateRange(1, 127)] + [string]$NetProfile + + [DscProperty()] + [ValidateSet('YES', 'NO')] + [string]$TOS = 'NO' + + [DscProperty()] + [ValidateRange(1, 63)] + [int]$TOSID + + [DscProperty()] + [ValidateSet('ENABLED', 'DISABLED')] + [string]$State = 'ENABLED' + + [DscProperty()] + [ValidateSet('Yes', 'NO')] + [string]$Reverse = 'NO' + + [DscProperty()] + [ValidateSet('YES', 'NO')] + [string]$Transparent = 'NO' + + [DscProperty()] + [ValidateSet('ENABLED', 'DISABLED')] + [string]$LRTM = 'DISABLED' + + [DscProperty()] + [ValidateSet('YES', 'NO')] + [string]$Secure = 'NO' + + [DscProperty()] + [ValidateSet('YES', 'NO')] + [string]$IPTunnel = 'NO' + + [DscProperty()] + [string]$ScriptName + + [DscProperty()] + [string]$DispatcherIP + + [DscProperty()] + [int]$DispatcherPort + + [DscProperty()] + [string]$ScriptArgs + + [DscProperty()] + [System.Collections.Hashtable]$CustomProperty + + [DscProperty()] + [string]$ResponseCode + + [DscProperty()] + [string]$HTTPRequest + + [DscProperty()] + [string]$Send + + [DscProperty()] + [string]$Recv + + [DscProperty()] + [bool]$ParameterExport = $false + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $NSObject = $this.Get() + try { + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + try { + switch ($this.Ensure) { + 'Present' { + # Does the record already exist? + if ($NSObject.Ensure -eq [ensure]::Present) { + + #Run tests and set any needed attributes to match desired configuration + if ($NSObject.monitorname -ne $this.Name) { + Write-Warning -Message "Setting Name cannot be changed to [$($this.Name)]. Object must be recreated." + } + if ($NSObject.type -ne $this.Type) { + Write-Warning -Message "Setting Type cannot be changed to [$($this.Type)]. Object must be recreated." + } + if ($NSObject.interval -ne $this.Interval) { + Write-Verbose -Message "Setting Interval [$($this.Interval)]" + Set-NSLBMonitor -Name $this.Name -Interval $this.Interval -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.units3 -ne $this.IntervalType) { + Write-Verbose -Message "Setting Interval Type [$($this.IntervalType)]" + Set-NSLBMonitor -Name $this.Name -IntervalType $this.IntervalType -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.resptimeout -ne $this.ResponseTimeout) { + Write-Verbose -Message "Setting Response Timeout was changed to [$($this.ResponseTimeout)]" + Set-NSLBMonitor -Name $this.Name -ResponseTimeout $this.ResponseTimeout -ResponseTimeoutType $this.ResponseTimeoutType -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.destip -ne $this.DestinationIP) { + Write-Verbose -Message "Setting Destination IP was changed to [$($this.DestinationIP)]" + Set-NSLBMonitor -Name $this.Name -DestinationIP $this.DestinationIP -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.downtime -ne $this.Downtime) { + Write-Verbose -Message "Setting Downtime was changed to [$($this.Downtime)]" + Set-NSLBMonitor -Name $this.Name -Downtime $this.Downtime -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.units2 -ne $this.DowntimeType) { + Write-Verbose -Message "Setting Downtime Type was changed to [$($this.DowntimeType)]" + Set-NSLBMonitor -Name $this.Name -DowntimeType $this.DowntimeType -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.retries -ne $this.Retries) { + Write-Verbose -Message "Setting Retries was changed to [$($this.Retries)]" + Set-NSLBMonitor -Name $this.Name -Retries $this.Retries -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.successretries -ne $this.SuccessRetries) { + Write-Verbose -Message "Setting Success Retries was changed to [$($this.SuccessRetries)]" + Set-NSLBMonitor -Name $this.Name -SuccessRetries $this.SuccessRetries -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.tos -ne $this.TOS) { + Write-Verbose -Message "Setting TOS was changed to [$($this.TOS)]" + Set-NSLBMonitor -Name $this.Name -TOS $this.TOS -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.state -ne $this.State) { + Write-Verbose -Message "Setting State was changed to [$($this.State)]" + Set-NSLBMonitor -Name $this.Name -State $this.State -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.reverse -ne $this.Reverse) { + Write-Verbose -Message "Setting Reverse was changed to [$($this.Reverse)]" + Set-NSLBMonitor -Name $this.Name -Reverse $this.Reverse -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.transparent -ne $this.Transparent) { + Write-Verbose -Message "Setting Transparent was changed to [$($this.Transparent)]" + Set-NSLBMonitor -Name $this.Name -Transparent $this.Transparent -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.lrtm -ne $this.LRTM) { + Write-Verbose -Message "Setting LRTM was changed to [$($this.LRTM)]" + Set-NSLBMonitor -Name $this.Name -LRTM $this.LRTM -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.secure -ne $this.Secure) { + Write-Verbose -Message "Setting Secure was changed to [$($this.Secure)]" + Set-NSLBMonitor -Name $this.Name -Secure $this.Secure -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.iptunnel -ne $this.IPTunnel) { + Write-Verbose -Message "Setting IPTunnel was changed to [$($this.IPTunnel)]" + Set-NSLBMonitor -Name $this.Name -IPTunnel $this.IPTunnel -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.failureretries -ne $this.FailureRetries) { + Write-Verbose -Message "Setting Failure Retries was changed to [$($this.FailureRetries)]" + Set-NSLBMonitor -Name $this.Name -FailureRetries $this.FailureRetries -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.destport -ne $this.DestinationPort) { + Write-Verbose -Message "Setting Destination Port was changed to [$($this.DestinationPort)]" + Set-NSLBMonitor -Name $this.Name -DestinationPort $this.DestinationPort -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.respcode -ne $this.ResponseCode) { + Write-Verbose -Message "Setting Response Code was changed to [$($this.ResponseCode)]" + try { + Set-NSLBMonitor -Name $this.Name -ResponseCode $this.ResponseCode -Verbose:$false -ErrorAction SilentlyContinue + } catch { $null } + } + if ($NSObject.httprequest -ne $this.HTTPRequest) { + Write-Verbose -Message "Setting HTTP Request was changed to [$($this.HTTPRequest)]" + # Set-NSLBMonitor -Name $this.Name -HTTPRequest $this.HTTPRequest -Verbose:$false -ErrorAction SilentlyContinue + } + } else { + Write-Verbose -Message "Creating monitor [$($this.Name)]" + $params = @{ + name = $this.Name + type = $this.Type + interval = $this.Interval + intervaltype = $this.IntervalType + responseTimeoutType = $this.ResponseTimeoutType + downtime = $this.Downtime + downtimeType = $this.DowntimeType + retries = $this.Retries + responsetimeout = $this.ResponseTimeout + successretries = $this.SuccessRetries + failureRetries = $this.FailureRetries + state = $this.State + destinationport = $this.DestinationPort + destinationip = $this.DestinationIP + reverse = $this.Reverse + lrtm = $this.LRTM + transparent = $this.Transparent + tos = $this.TOS + secure = $this.Secure + } + if ($PSBoundParameters.ContainsKey('Transparent')) { + $params.Add('Transparent', $this.Transparent) + } + if ($PSBoundParameters.ContainsKey('LRTM')) { + $params.Add('LRTM', $this.LRTM) + } + if ($PSBoundParameters.ContainsKey('Secure')) { + $params.Add('Secure', $this.Secure) + } + if ($PSBoundParameters.ContainsKey('IPTunnel')) { + $params.Add('IPTunnel', $this.IPTunnel) + } + if ($PSBoundParameters.ContainsKey('TOS')) { + $params.Add('TOS', $this.TOS) + } + if ($PSBoundParameters.ContainsKey('Reverse')) { + $params.Add('Reverse', $this.Reverse) + } + if ($PSBoundParameters.ContainsKey('DestinationIP')) { + $params.Add('DestinationIP', $this.DestinationIP) + } + if ($PSBoundParameters.ContainsKey('Deviation')) { + $params.Add('Deviation', $this.Deviation) + } + if ($PSBoundParameters.ContainsKey('ResponseTimeoutThreshold')) { + $params.Add('ResponseTimeoutThreshold', $this.ResponseTimeoutThreshold) + } + if ($PSBoundParameters.ContainsKey('AlertRetries')) { + $params.Add('AlertRetries', $this.AlertRetries) + } + if ($PSBoundParameters.ContainsKey('FailureRetries')) { + $params.Add('FailureRetries', $this.FailureRetries) + } + if ($PSBoundParameters.ContainsKey('NetProfile')) { + $params.Add('NetProfile', $this.NetProfile) + } + if ($PSBoundParameters.ContainsKey('TOSID')) { + $params.Add('TOSID', $this.TOSID) + } + if ($PSBoundParameters.ContainsKey('ScriptName')) { + $params.Add('ScriptName', $this.ScriptName) + } + if ($PSBoundParameters.ContainsKey('DispatcherIP')) { + $params.Add('DispatcherIP', $this.DispatcherIP) + } + if ($PSBoundParameters.ContainsKey('ScriptArgs')) { + $params.Add('ScriptArgs', $this.ScriptArgs) + } + if ($PSBoundParameters.ContainsKey('CustomProperty')) { + ## Add each custom property to the $params Hashtable + foreach ($CustomProperty in $this.CustomProperty.Keys) { + $params.Add($CustomProperty.ToLower(), $CustomProperty[$CustomProperty]) + } + } + if ($PSBoundParameters.ContainsKey('ResponseCode')) { + $params.Add('ResponseCode', $this.ResponseCode) + } + if ($PSBoundParameters.ContainsKey('HTTPRequest')) { + $params.Add('HTTPRequest', $this.HTTPRequest) + } + if ($PSBoundParameters.ContainsKey('Send')) { + $params.Add('Send', $this.Send) + } + if ($PSBoundParameters.ContainsKey('Recv')) { + $params.Add('Recv', $this.Recv) + } + if ($PSBoundParameters.ContainsKey('DispatcherPort')) { + $params.Add('DispatcherPort', $this.DispatcherPort) + } + New-NSLBMonitor @params -ErrorAction SilentlyContinue + } + } 'Absent' { + try { + $params = @{ + name = $this.Name + type = $this.Type + } + Remove-NSLBMonitor @params -Confirm:$false -ErrorAction SilentlyContinue + Write-Verbose -Message "Removing Netscaler monitor: $($this.Name)" + } catch { + write-host "Monitor $this.Name was not found" + } + } + }# + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + Write-Verbose -Message "Monitor [$($this.Name)] exists" + if ($NSObject.Name -ne $this.Name) { + Write-Verbose -Message "Monitor Name does not match [$($NSObject.monitorname) <> $($this.Name)]" + $pass = $false + } + if ($NSObject.DestinationIP -ne $this.DestinationIP) { + Write-Verbose -Message "Monitor Destination IP does not match [$($NSObject.DestinationIP) <> $($this.DestinationIP)]" + $pass = $false + } + if ($NSObject.Interval -ne $this.Interval) { + Write-Verbose -Message "Monitor Interval does not match [$($NSObject.interval) <> $($this.Interval)]" + $pass = $false + } + if ($NSObject.IntervalType -ne $this.IntervalType) { + Write-Verbose -Message "Monitor Interval Type does not match [$($NSObject.IntervalType) <> $($this.IntervalType)]" + $pass = $false + } + if ($NSObject.ResponseTimeout -ne $this.ResponseTimeout) { + Write-Verbose -Message "Monitor Response Timeout does not match [$($NSObject.ResponseTimeout) <> $($this.ResponseTimeout)]" + $pass = $false + } + if ($NSObject.ResponseTimeoutType -ne $this.ResponseTimeoutType) { + Write-Verbose -Message "Monitor Response Timeout Type does not match [$($NSObject.ResponseTimeoutType) <> $($this.ResponseTimeoutType)]" + $pass = $false + } + if ($NSObject.Downtime -ne $this.Downtime) { + Write-Verbose -Message "Monitor Downtime does not match [$($NSObject.Downtime) <> $($this.Downtime)]" + $pass = $false + } + if ($NSObject.DowntimeType -ne $this.DowntimeType) { + Write-Verbose -Message "Monitor Downtime Type does not match [$($NSObject.DowntimeType) <> $($this.DowntimeType)]" + $pass = $false + } + if ($NSObject.Retries -ne $this.Retries) { + Write-Verbose -Message "Monitor Retries does not match [$($NSObject.Retries) <> $($this.Retries)]" + $pass = $false + } + if ($NSObject.SuccessRetries -ne $this.SuccessRetries) { + Write-Verbose -Message "Monitor Success Retries does not match [$($NSObject.SuccessRetries) <> $($this.SuccessRetries)]" + $pass = $false + } + if ($NSObject.TOS -ne $this.TOS) { + Write-Verbose -Message "Monitor TOS setting not match [$($NSObject.TOS) <> $($this.TOS)]" + $pass = $false + } + if ($NSObject.State -ne $this.State) { + Write-Verbose -Message "Monitor State does not match [$($NSObject.State) <> $($this.State)]" + $pass = $false + } + if ($NSObject.Reverse -ne $this.Reverse) { + Write-Verbose -Message "Monitor Reverse setting does not match [$($NSObject.Reverse) <> $($this.Reverse)]" + $pass = $false + } + if ($NSObject.Transparent -ne $this.Transparent) { + Write-Verbose -Message "Monitor Transparent setting does not match [$($NSObject.Transparent) <> $($this.Transparent)]" + $pass = $false + } + if ($NSObject.LRTM -ne $this.LRTM) { + Write-Verbose -Message "Monitor LRTM setting does not match [$($NSObject.LRTM) <> $($this.LRTM)]" + $pass = $false + } + if ($NSObject.Secure -ne $this.Secure) { + Write-Verbose -Message "Monitor Secure setting does not match [$($NSObject.Secure) <> $($this.Secure)]" + $pass = $false + } + if ($NSObject.IPTunnel -ne $this.IPTunnel) { + Write-Verbose -Message "Monitor IPTunnel setting does not match [$($NSObject.IPTunnel) <> $($this.IPTunnel)]" + $pass = $false + } + if ($NSObject.FailureRetries -ne $this.FailureRetries) { + Write-Verbose -Message "Monitor Failure Retries does not match [$($NSObject.FailureRetries) <> $($this.FailureRetries)]" + $pass = $false + } + if ($NSObject.DestinationPort -ne $this.DestinationPort) { + Write-Verbose -Message "Monitor Destination Port does not match [$($NSObject.DestinationPort) <> $($this.DestinationPort)]" + $pass = $false + } + if ($NSObject.ResponseCode -ne $this.ResponseCode) { + Write-Verbose -Message "Monitor Response Code does not match [$($NSObject.ResponseCode) <> $($this.ResponseCode)]" + $pass = $false + } + if ($NSObject.HTTPRequest -ne $this.HTTPRequest) { + Write-Verbose -Message "Monitor HTTPRequest setting does not match [$($NSObject.HTTPRequest) <> $($this.HTTPRequest)]" + $pass = $false + } + } else { + Write-Verbose -Message "Monitor [$($this.Name)] was not found" + $pass = $false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBMonitor]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSLBMonitor -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBMonitor]::new() + $obj.Name = $this.Name + $obj.Type = $this.Type + $obj.Interval = $this.Interval + $obj.IntervalType = $this.IntervalType + $obj.DestinationIP = $this.DestinationIP + $obj.ResponseTimeout = $this.ResponseTimeout + $obj.ResponseTimeoutType = $this.ResponseTimeoutType + $obj.Downtime = $this.Downtime + $obj.DowntimeType = $this.DowntimeType + $obj.Retries = $this.Retries + $obj.SuccessRetries = $this.SuccessRetries + $obj.TOS = $this.TOS + $obj.State = $this.State + $obj.Reverse = $this.Reverse + $obj.Transparent = $this.Transparent + $obj.LRTM = $this.LRTM + $obj.Secure = $this.Secure + $obj.IPTunnel = $this.IPTunnel + $obj.FailureRetries = $this.FailureRetries + $obj.DestinationPort = $this.DestinationPort + $obj.HTTPRequest = $this.HTTPRequest + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Name = $s.monitorname + $obj.Type = $s.type + $obj.Interval = $s.interval + $obj.IntervalType = $s.units3 + $obj.DestinationIP = $s.destip + $obj.ResponseTimeout = $s.resptimeout + $obj.ResponseTimeoutType = $s.units4 + $obj.Downtime = $s.downtime + $obj.DowntimeType = $s.units2 + $obj.Retries = $s.retries + $obj.SuccessRetries = $s.successRetries + $obj.TOS = $s.tos + $obj.State = $s.state + $obj.Reverse = $s.reverse + $obj.Transparent = $s.transparent + $obj.LRTM = $s.lrtm + $obj.Secure = $s.secure + $obj.IPTunnel = $s.iptunnel + $obj.FailureRetries = $s.failureretries + $obj.DestinationPort = $s.destport + $obj.HTTPRequest = $s.httprequest + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBServiceGroup { + [DscProperty(Key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty()] + [ValidateSet('ADNS','ADNS_TCP','ANY','DHCPRA','DIAMETER','DNS','DNS_TCP','DTLS','FTP','HTTP','MSSQL', + 'MYSQL','NNTP','RADIUS','RDP','RPCSVR','RTSP','SIP_UDP','SNMP','SSL','SSL_BRIDGE','SSL_DIAMETER','SSL_TCP','TCP','TFTP','UDP')] + [Alias('Protocol')] + [string]$ServiceType = 'HTTP' + + [DscProperty()] + [ValidateRange(0, 4094)] + [int]$TrafficDomainId = 0 + + [DscProperty()] + [ValidateSet('SERVER', 'FORWARD', 'TRANSPARENT', 'REVERSE')] + [string]$CacheType = 'SERVER' + + [DscProperty()] + [ValidateSet('DISABLED', 'DNS', 'POLICY')] + [string]$AutoScale = 'DISABLED' + + [DscProperty()] + [ValidateSet('NO', 'YES')] + [string]$Cacheable = 'NO' + + [DscProperty()] + [ValidateSet('ENABLED', 'DISABLED')] + [string]$State = 'ENABLED' + + [DscProperty()] + [ValidateSet('NO', 'YES')] + [string]$HealthMonitor = 'YES' + + [DscProperty()] + [ValidateSet('DISABLED', 'ENABLED')] + [string]$AppFlowLog = 'ENABLED' + + [DscProperty()] + [ValidateLength(0, 256)] + [string]$Comment = [string]::Empty + + [DscProperty()] + [ValidateSet('ON', 'OFF')] + [string]$SureConnect = 'OFF' + + [DscProperty()] + [ValidateSet('ON', 'OFF')] + [string]$SurgeProtection = 'OFF' + + [DscProperty()] + [ValidateSet('YES','NO')] + [string]$UseProxyPort = 'YES' + + [DscProperty()] + [ValidateSet('ENABLED','DISABLED')] + [string]$DownStateFlush = 'ENABLED' + + [DscProperty()] + [ValidateSet('YES','NO')] + [string]$UseClientIP = "No" + + [DscProperty()] + [ValidateSet('YES','NO')] + [string]$ClientKeepAlive = 'NO' + + [DscProperty()] + [ValidateSet('YES', 'NO')] + [string]$TCPBuffering = 'NO' + + [DscProperty()] + [ValidateSet('YES', 'NO')] + [string]$HTTPCompression = 'YES' + + [DscProperty()] + [ValidateSet('ENABLED','DISABLED')] + [string]$ClientIP = 'DISABLED' + + [DscProperty()] + [string]$ClientIPHeader + + [DscProperty()] + [ValidateRange(0, 4294967287)] + [int]$MaxBandwidthKbps + + [DscProperty()] + [ValidateRange(0, 65535)] + [int]$MonitorThreshold + + [DscProperty()] + [ValidateRange(0, 65535)] + [int]$MaxRequests + + [DscProperty()] + [ValidateRange(0, 4294967294)] + [int]$MaxClients + + [DscProperty()] + [ValidateRange(0, 31536000)] + [int]$ClientIdleTimeout = 180 + + [DscProperty()] + [ValidateRange(0, 31536000)] + [int]$ServerIdleTimeout = 360 + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + + [void]Set() { + $NSObject = $this.Get() + try { + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + if ($NSObject.Name -ne $this.Name) { + Write-Warning -Message "Setting Name cannot be changed to [$($this.Name)], must be recreated" + } + if ($NSObject.ServiceType -ne $this.ServiceType) { + Write-Warning -Message "Setting Service Type cannot be changed to [$($this.ServiceType)], must be recreated" + } + if ($NSObject.TrafficDomainId -ne $this.TrafficDomainId) { + Write-Warning -Message "Setting Traffic Domain cannot be changed to [$($this.TrafficDomainId)]" + } + if ($NSObject.CacheType -ne $this.CacheType) { + Write-Warning -Message "Setting Cache Type cannot be changed to[$($this.CacheType)]" + } + if ($NSObject.AutoScale -ne $this.AutoScale) { + Write-Verbose -Message "Setting Autoscale [$($this.AutoScale)]" + Set-NSLBServiceGroup -Name $this.Name -AutoScale $this.AutoScale -Force -Verbose:$false + } + if ($NSObject.Cacheable -ne $this.Cacheable) { + Write-Verbose -Message "Setting Cacheable [$($this.Cacheable)]" + Set-NSLBServiceGroup -Name $this.Name -Cacheable $this.Cacheable -Force -Verbose:$false + } + if ($NSObject.State -ne $this.State) { + Write-Verbose -Message "Setting State [$($this.State)]" + Set-NSLBServiceGroup -Name $this.Name -State $this.State -Force -Verbose:$false + } + if ($NSObject.HealthMonitor -ne $this.HealthMonitor) { + Write-Verbose -Message "Setting Health Monitor [$($this.HealthMonitor)]" + Set-NSLBServiceGroup -Name $this.Name -HealthMonitor $this.HealthMonitor -Force -Verbose:$false + } + if ($NSObject.AppFlowLog -ne $this.AppFlowLog) { + Write-Verbose -Message "Setting AppFlowLog [$($this.AppFlowLog)]" + Set-NSLBServiceGroup -Name $this.Name -AppFlowLog $this.AppFlowLog -Force -Verbose:$false + } + if ($NSObject.Comment -ne $this.Comment) { + Write-Verbose -Message "Setting Comment [$($this.Comment)]" + Set-NSLBServiceGroup -Name $this.Name -Comment $this.Comment -Force -Verbose:$false + } + if ($NSObject.SureConnect -ne $this.SureConnect) { + Write-Verbose -Message "Setting SureConnect [$($this.SureConnect)]" + Set-NSLBServiceGroup -Name $this.Name -SureConnect $this.SureConnect -Force -Verbose:$false + } + if ($NSObject.SurgeProtection -ne $this.SurgeProtection) { + Write-Verbose -Message "Setting Surge Protection [$($this.SurgeProtection)]" + Set-NSLBServiceGroup -Name $this.Name -SurgeProtection $this.SurgeProtection -Force -Verbose:$false + } + if ($NSObject.UseProxyPort -ne $this.UseProxyPort) { + Write-Verbose -Message "Setting Use Proxy Port [$($this.UseProxyPort)]" + Set-NSLBServiceGroup -Name $this.Name -UseProxyPort $this.UseProxyPort -Force -Verbose:$false + } + if ($NSObject.DownStateFlush -ne $this.DownStateFlush) { + Write-Verbose -Message "Setting DownState Flush [$($this.DownStateFlush)]" + Set-NSLBServiceGroup -Name $this.Name -DownStateFlush $this.DownStateFlush -Force -Verbose:$false + } + if ($NSObject.UseClientIP -ne $this.UseClientIP) { + Write-Verbose -Message "Setting Use Client IP [$($this.UseClientIP)]" + Set-NSLBServiceGroup -Name $this.Name -UseClientIP $this.UseClientIP -Force -Verbose:$false + } + if ($NSObject.ClientKeepAlive -ne $this.ClientKeepAlive) { + Write-Verbose -Message "Setting Client Keep Alive [$($this.ClientKeepAlive)]" + Set-NSLBServiceGroup -Name $this.Name -ClientKeepAlive $this.ClientKeepAlive -Force -Verbose:$false + } + if ($NSObject.TCPBuffering -ne $this.TCPBuffering) { + Write-Verbose -Message "Setting TCP Buffering [$($this.TCPBuffering)]" + Set-NSLBServiceGroup -Name $this.Name -TCPBuffering $this.TCPBuffering -Force -Verbose:$false + } + if ($NSObject.HTTPCompression -ne $this.HTTPCompression) { + Write-Verbose -Message "Setting HTTP Compression [$($this.HTTPCompression)]" + Set-NSLBServiceGroup -Name $this.Name -HTTPCompression $this.HTTPCompression -Force -Verbose:$false + } + if ($NSObject.ClientIP -ne $this.ClientIP) { + Write-Verbose -Message "Setting Client IP [$($this.ClientIP)]" + Set-NSLBServiceGroup -Name $this.Name -ClientIP $this.ClientIP -Force -Verbose:$false + } + if ($NSObject.MaxBandwidthKbps -ne $this.MaxBandwidthKbps) { + Write-Verbose -Message "Setting Maximum Bandwidth (Kbps) [$($this.MaxBandwidthKbps)]" + Set-NSLBServiceGroup -Name $this.Name -MaxBandwidthKbps $this.MaxBandwidthKbps -Force -Verbose:$false + } + if ($NSObject.MonitorThreshold -ne $this.MonitorThreshold) { + Write-Verbose -Message "Setting Monitor Threshold [$($this.MonitorThreshold)]" + Set-NSLBServiceGroup -Name $this.Name -MonitorThreshold $this.MonitorThreshold -Force -Verbose:$false + } + if ($NSObject.MaxRequests -ne $this.MaxRequests) { + Write-Verbose -Message "Setting Maximum Client Requests [$($this.MaxRequests)]" + Set-NSLBServiceGroup -Name $this.Name -MaxRequests $this.MaxRequests -Force -Verbose:$false + } + if ($NSObject.MaxClients -ne $this.MaxClients) { + Write-Verbose -Message "Setting Maximum Client connections [$($this.MaxClients)]" + Set-NSLBServiceGroup -Name $this.Name -MaxClients $this.MaxClients -Force -Verbose:$false + } + if ($NSObject.ClientIdleTimeout -ne $this.ClientIdleTimeout) { + Write-Verbose -Message "Setting Client Idle Timeout [$($this.ClientIdleTimeout)]" + Set-NSLBServiceGroup -Name $this.Name -ClientIdleTimeout $this.ClientIdleTimeout -Force -Verbose:$false + } + if ($NSObject.ServerIdleTimeout -ne $this.ServerIdleTimeout) { + Write-Verbose -Message "Setting Server Idle Timeout [$($this.ServerIdleTimeout)]" + Set-NSLBServiceGroup -Name $this.Name -ServerIdleTimeout $this.ServerIdleTimeout -Force -Verbose:$false + } + } else { + Write-Verbose -Message "Creating Service Group [$($this.Name)]" + $params = @{ + name = $this.Name + servicetype = $this.ServiceType + state = $this.State + comment = $this.Comment + } + if ($PSBoundParameters.ContainsKey('TrafficDomainId')) { + $params.Add('TrafficDomainId', $this.TrafficDomainId) + } + if ($PSBoundParameters.ContainsKey('MaxClients')) { + $params.Add('MaxClients', $this.MaxClients) + } + if ($PSBoundParameters.ContainsKey('CacheType')) { + $params.Add('CacheType', $this.CacheType) + } + if ($PSBoundParameters.ContainsKey('AutoScale')) { + $params.Add('AutoScale', $this.AutoScale) + } + if ($PSBoundParameters.ContainsKey('Cacheable')) { + $params.Add('Cacheable', $this.Cacheable) + } + if ($PSBoundParameters.ContainsKey('HealthMonitor')) { + $params.Add('HealthMonitor', $this.HealthMonitor) + } + if ($PSBoundParameters.ContainsKey('AppFlowLog')) { + $params.Add('AppFlowLog', $this.AppFlowLog) + } + if ($PSBoundParameters.ContainsKey('SureConnect')) { + $params.Add('SureConnect', $this.SureConnect) + } + if ($PSBoundParameters.ContainsKey('SurgeProtection')) { + $params.Add('SurgeProtection', $this.SurgeProtection) + } + if ($PSBoundParameters.ContainsKey('UseProxyPort')) { + $params.Add('UseProxyPort', $this.UseProxyPort) + } + if ($PSBoundParameters.ContainsKey('DownStateFlush')) { + $params.Add('DownStateFlush', $this.DownStateFlush) + } + if ($PSBoundParameters.ContainsKey('UseClientIP')) { + $params.Add('UseClientIP', $this.UseClientIP) + } + if ($PSBoundParameters.ContainsKey('ClientKeepAlive')) { + $params.Add('ClientKeepAlive', $this.ClientKeepAlive) + } + if ($PSBoundParameters.ContainsKey('TCPBuffering')) { + $params.Add('TCPBuffering', $this.TCPBuffering) + } + if ($PSBoundParameters.ContainsKey('HTTPCompression')) { + $params.Add('HTTPCompression', $this.HTTPCompression) + } + if ($PSBoundParameters.ContainsKey('ClientIP')) { + $params.Add('ClientIP', $this.ClientIP) + } + if ($PSBoundParameters.ContainsKey('MaxBandwidthKbps')) { + $params.Add('MaxBandwidthKbps', $this.MaxBandwidthKbps) + } + if ($PSBoundParameters.ContainsKey('DownStateFlush')) { + $params.Add('DownStateFlush', $this.DownStateFlush) + } + if ($PSBoundParameters.ContainsKey('MaxRequests')) { + $params.Add('MaxRequests', $this.MaxRequests) + } + if ($PSBoundParameters.ContainsKey('ClientIdleTimeout')) { + $params.Add('ClientIdleTimeout', $this.ClientIdleTimeout) + } + if ($PSBoundParameters.ContainsKey('ServerIdleTimeout')) { + $params.Add('ServerIdleTimeout', $this.ServerIdleTimeout) + } + New-NSLBServiceGroup @params -ErrorAction SilentlyContinue + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSLBServiceGroup -Name $NSObject.Name -Confirm:$false -ErrorAction SilentlyContinue + Write-Verbose -Message "Removing Netscaler monitor: $($this.Name)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + if ($NSObject.Name -ne $this.Name) { + Write-Verbose -Message "Service Group Name doest not match [$($NSObject.Name) <> $($this.Name)]" + $pass = $false + } + if ($NSObject.ServiceType -ne $this.ServiceType) { + Write-Verbose -Message "Service Type does not match [$($NSObject.ServiceType) <> $($this.ServiceType)]" + $pass = $false + } + if ($NSObject.TrafficDomainId -ne $this.TrafficDomainId) { + Write-Verbose -Message "Traffic Domain does not match [$($NSObject.TrafficDomainId) <> $($this.TrafficDomainId)]" + $pass = $false + } + if ($NSObject.CacheType -ne $this.CacheType) { + Write-Verbose -Message "Cache Type does not match [$($NSObject.CacheType) <> $($this.CacheType)]" + $pass = $false + } + if ($NSObject.Cacheable -ne $this.Cacheable) { + Write-Verbose -Message "Cacheable setting does not match [$($NSObject.Cacheable) <> $($this.Cacheable)]" + $pass = $false + } + if ($NSObject.State -ne $this.State) { + Write-Verbose -Message "State does not match [$($NSObject.State) <> $($this.State)]" + $pass = $false + } + if ($NSObject.HealthMonitor -ne $this.HealthMonitor) { + Write-Verbose -Message "Health Monitor does not match [$($NSObject.HealthMonitor) <> $($this.HealthMonitor)]" + $pass = $false + } + if ($NSObject.AppFlowLog -ne $this.AppFlowLog) { + Write-Verbose -Message "AppFlowLog does not match [$($NSObject.AppFlowLog) <> $($this.AppFlowLog)]" + $pass = $false + } + if ($NSObject.Comment -ne $this.Comment) { + Write-Verbose -Message "Comment does not match [$($NSObject.Comment) <> $($this.Comment)]" + $pass = $false + } + if ($NSObject.SurgeProtection -ne $this.SurgeProtection) { + Write-Verbose -Message "Surge Protection does not match [$($NSObject.SurgeProtection) <> $($this.SurgeProtection)]" + $pass = $false + } + if ($NSObject.SureConnect -ne $this.SureConnect) { + Write-Verbose -Message "Sure Connect does not match [$($NSObject.SureConnect) <> $($this.SureConnect)]" + $pass = $false + } + if ($NSObject.UseProxyPort -ne $this.UseProxyPort) { + Write-Verbose -Message "Use Proxy Port does not match [$($NSObject.UseProxyPort) <> $($this.UseProxyPort)]" + $pass = $false + } + if ($NSObject.DownStateFlush -ne $this.DownStateFlush) { + Write-Verbose -Message "DownState Flush does not match [$($NSObject.DownStateFlush) <> $($this.DownStateFlush)]" + $pass = $false + } + if ($NSObject.UseClientIP -ne $this.UseClientIP) { + Write-Verbose -Message "Use Client IP does not match [$($NSObject.UseClientIP) <> $($this.UseClientIP)]" + $pass = $false + } + if ($NSObject.ClientKeepAlive -ne $this.ClientKeepAlive) { + Write-Verbose -Message "Client Keep Alive does not match [$($NSObject.ClientKeepAlive) <> $($this.ClientKeepAlive)]" + $pass = $false + } + if ($NSObject.TCPBuffering -ne $this.TCPBuffering) { + Write-Verbose -Message "TCP Buffering does not match [$($NSObject.TCPBuffering) <> $($this.TCPBuffering)]" + $pass = $false + } + if ($NSObject.HTTPCompression -ne $this.HTTPCompression) { + Write-Verbose -Message "HTTP Compression does not match [$($NSObject.HTTPCompression) <> $($this.HTTPCompression)]" + $pass = $false + } + if ($NSObject.ClientIP -ne $this.ClientIP) { + Write-Verbose -Message "Client IP does not match [$($NSObject.ClientIP) <> $($this.ClientIP)]" + $pass = $false + } + # if ($NSObject.ClientIPHeader -ne $this.ClientIPHeader) { + # Write-Verbose -Message "ClientIP Header does not match [$($this.ClientIPHeader)]" + # $pass = $false + # } + if ($NSObject.MaxBandwidthKbps -ne $this.MaxBandwidthKbps) { + Write-Verbose -Message "Maximum Banddwith (Kbps) does not match [$($NSObject.MaxBandwidthKbps) <> $($this.MaxBandwidthKbps)]" + $pass = $false + } + if ($NSObject.MonitorThreshold -ne $this.MonitorThreshold) { + Write-Verbose -Message "Monitor Threshold does not match [$($NSObject.MonitorThreshold) <> $($this.MonitorThreshold)]" + $pass = $false + } + if ($NSObject.MaxRequests -ne $this.MaxRequests) { + Write-Verbose -Message "Maximum Client Requests does not match [$($NSObject.MaxRequests) <> $($this.MaxRequests)]" + $pass = $false + } + if ($NSObject.MaxClients -ne $this.MaxClients) { + Write-Verbose -Message "Maximum Client connections does not match [$($NSObject.MaxClients) <> $($this.MaxClients)]" + $pass = $false + } + if ($NSObject.ClientIdleTimeout -ne $this.ClientIdleTimeout) { + Write-Verbose -Message "Client Idle Timeout does not match [$($NSObject.ClientIdleTimeout) <> $($this.ClientIdleTimeout)]" + $pass = $false + } + if ($NSObject.ServerIdleTimeout -ne $this.ServerIdleTimeout) { + Write-Verbose -Message "Server Idle Timeout does not match [$($NSObject.ServerIdleTimeout) <> $($this.ServerIdleTimeout)]" + $pass = $false + } + } else { + Write-Verbose -Message "Resource [$($this.Name)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBServiceGroup]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSLBServiceGroup -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBServiceGroup]::new() + $obj.Name = $this.Name + $obj.ServiceType = $this.ServiceType + $obj.TrafficDomainID = $this.TrafficDomainID + $obj.CacheType = $this.CacheType + $obj.MaxClients = $this.MaxClients + $obj.MaxRequests = $this.MaxRequests + $obj.Cacheable = $this.Cacheable + $obj.ClientIP = $this.ClientIP + $obj.UseClientIP = $this.UseClientIP + $obj.UseProxyPort = $this.UseProxyPort + $obj.SureConnect = $this.SureConnect + $obj.SurgeProtection = $this.SurgeProtection + $obj.ClientKeepAlive = $this.ClientKeepAlive + $obj.ClientIdleTimeout = $this.ClientIdleTimeout + $obj.ServerIdleTimeout = $this.ServerIdleTimeout + $obj.TCPBuffering = $this.TCPBuffering + $obj.HTTPCompression = $this.HTTPCompression + $obj.MaxBandwidthKbps = $this.MaxBandwidthKbps + $obj.State = $this.State + $obj.DownStateFlush = $this.DownStateFlush + $obj.HealthMonitor = $this.HealthMonitor + $obj.AppFlowLog = $this.AppFlowLog + $obj.Comment = $this.Comment + # $obj.ClientIPHeader = $this.ClientIPHeader + $obj.MonitorThreshold = $this.MonitorThreshold + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Name = $s.servicegroupname + $obj.ServiceType = $s.servicetype + $obj.TrafficDomainID = $s.td + $obj.CacheType = $s.cachetype + $obj.MaxClients = $s.maxclient + $obj.MaxRequests = $s.maxreq + $obj.Cacheable = $s.cacheable + $obj.ClientIP = $s.cip + $obj.UseClientIP = $s.usip + $obj.UseProxyPort = $s.useproxyport + $obj.SureConnect = $s.sc + $obj.SurgeProtection = $s.sp + $obj.ClientKeepAlive = $s.cka + $obj.ClientIdleTimeout = $s.clttimeout + $obj.ServerIdleTimeout = $s.svrtimeout + $obj.TCPBuffering = $s.tcpb + $obj.HTTPCompression = $s.cmp + $obj.MaxBandwidthKbps = $s.maxbandwidth + $obj.State = $s.state + $obj.DownStateFlush = $s.downstateflush + $obj.HealthMonitor = $s.healthmonitor + $obj.AppFlowLog = $s.appflowlog + $obj.Comment = $s.comment + # $obj.ClientIPHeader = $s.cipheader + $obj.MonitorThreshold = $s.monthreshold + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBNTPServer { + [DscProperty(Key)] + [string]$Server + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty()] + [int]$MinPollInterval + + [DscProperty()] + [ValidateRange(0, 4094)] + [int]$MaxPollInterval + + [DscProperty()] + [ValidateSet('Yes','No')] + [string]$PreferredNTPServer = 'Yes' + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + if ($NSObject.Server -ne $this.Server) { + Write-Warning -Message "The NTP server name cannot be set to [$($this.Server)], resource can only be removed and recreated" + } + if ($NSObject.MinPollInterval -ne $this.MinPollInterval) { + Write-Verbose -Message "Setting Service Group MinPollInterval [$($this.MinPollInterval)]" + Set-NSNTPServer -Server $this.Server -MinPollInterval $this.MinPollInterval -Verbose:$false + } + if ($NSObject.MaxPollInterval -ne $this.MaxPollInterval) { + Write-Verbose -Message "Setting Service Group MaxPollInterval [$($this.MaxPollInterval)]" + Set-NSNTPServer -Server $this.Server -MaxPollInterval $this.MaxPollInterval -Verbose:$false + } + if ($NSObject.PreferredNTPServer -ne $this.PreferredNTPServer) { + Write-Warning -Message "The preferred NTP server cannot be set to [$($this.PreferredNTPServer)], setting can only be set manually" + } + } else { + Write-Verbose -Message "Creating resource [$($this.Name)]" + $params = @{ + server = $this.Server + minpoll = $this.MinPollInterval + maxpoll = $this.MaxPollInterval + preferredntpserver = $this.PreferredNTPServer + } + New-NSNTPServer @params -Verbose:$false -ErrorAction SilentlyContinue + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSNTPServer -Server $this.Server -ErrorAction SilentlyContinue + Write-Verbose -Message "Removing resource: $($this.Server)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Server -ne $this.Server) { + Write-Verbose -Message "Server does not match [$($NSObject.Server) <> $($this.Server)]" + $pass = $false + } + if ($NSObject.MinPollInterval -ne $this.MinPollInterval) { + Write-Verbose -Message "Min Poll Interval does not match [$($NSObject.MinPollInterval) <> $($this.MinPollInterval)]" + $pass = $false + } + if ($NSObject.MaxPollInterval -ne $this.MaxPollInterval) { + Write-Verbose -Message "Max Poll Interval does not match [$($NSObject.MaxPollInterval) <> $($this.MaxPollInterval)]" + $pass = $false + } + if ($NSObject.PreferredNTPServer -ne $this.PreferredNTPServer) { + Write-Verbose -Message "Preferred NTP Server does not match [$($NSObject.PreferredNTPServer) <> $($this.PreferredNTPServer)]" + $pass = $false + } + } else { + Write-Verbose -Message "Resource [$($this.Server)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBNTPServer]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSNTPServer -Name $this.Server -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBNTPServer]::new() + $obj.Server = $this.Server + $obj.MinPollInterval = $this.MinPollInterval + $obj.MaxPollInterval = $this.MaxPollInterval + $obj.PreferredNTPServer = $this.PreferredNTPServer + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Server = $s.serverip + $obj.MinPollInterval = $s.minpoll + $obj.MaxPollInterval = $s.maxpoll + $obj.PreferredNTPServer = $s.preferredntpserver + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBResponderPolicy { + [DscProperty(Key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty(Mandatory)] + [string]$Rule + + [DscProperty()] + [string]$Comment + + [DscProperty(Mandatory)] + [string]$Action + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne $this.Name) { + Write-Warning -Message "The Name cannot be changed to [$($this.Name)], resource can only be removed and recreated" + } + if ($NSObject.Rule -ne $this.Rule) { + Write-Verbose -Message "Setting Rule [$($this.Rule)]" + Set-NSResponderPolicy -Name $this.Name -Rule $this.Rule -Verbose:$false + } + if ($NSObject.Action -ne $this.Action) { + Write-Verbose -Message "Setting Service Group Name [$($this.MaxPollInterval)]" + Set-NSResponderPolicy -Name $this.Name -Action $this.Action -Verbose:$false + } + if ($NSObject.Comment -ne $this.Comment) { + Write-Verbose -Message "Setting monitor's Interval Type [$($this.Comment)]" + Set-NSResponderPolicy -Name $this.Name -Comment $this.Comment -Verbose:$false + } + } else { + Write-Verbose -Message "Creating resource [$($this.Name)]" + $params = @{ + name = $this.Name + rule = $this.Rule + action = $this.Action + comment = $this.Comment + } + New-NSResponderPolicy @params -ErrorAction SilentlyContinue + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSResponderPolicy -Name $NSObject.Name -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Responder Policy: $($this.Name)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne $this.Name) { + Write-Verbose -Message "Name does not match [$($NSObject.Name) <> $($this.Name)]" + $pass = $false + } + if ($NSObject.Rule -ne $this.Rule) { + Write-Verbose -Message "Rule does not match [$($NSObject.Rule) <> $($this.Rule)]" + $pass = $false + } + if ($NSObject.Action -ne $this.Action) { + Write-Verbose -Message "Action does not match [$($NSObject.Action) <> $($this.Action)]" + $pass = $false + } + } else { + Write-Verbose -Message "Responder Policy [$($this.Name)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBResponderPolicy]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSResponderPolicy -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBResponderPolicy]::new() + $obj.Name = $this.Name + $obj.Rule = $this.Rule + $obj.Action = $this.Action + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Name = $s.name + $obj.Rule = $s.rule + $obj.Action = $s.action.toString() + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBResponderAction { + [DscProperty(Key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty()] + [ValidateSet('NOOP','Redirect','RespondWith', 'RespondWithSQLOK','RespondWithSQLError','RespondWithHTMLPage')] + [string]$Type = 'NOOP' + + [DscProperty()] + [ValidateLength(0, 8191)] + [Alias('Expression')] + [string]$Target = [string]::Empty + + [DscProperty()] + [ValidateRange(100, 599)] + [int]$ResponseStatusCode + + [DscProperty()] + [ValidateLength(0, 8191)] + [string]$ReasonPhrase = [string]::Empty + + [DscProperty()] + [ValidateLength(0, 256)] + [string]$Comment = [string]::Empty + + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne $this.Name) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.Name)], resource can only be removed and recreated" + } + if ($NSObject.Type -ne $this.Type) { + Write-Verbose -Message "Setting Responder Action [$($this.Type)]" + Set-NSResponderAction -Name $this.Name -Type $this.Type -Verbose:$false + } + if ($NSObject.Target -ne $this.Target) { + Write-Verbose -Message "Setting Responder Action [$($this.Target)]" + Set-NSResponderAction -Name $this.Name -Target $this.Target -Verbose:$false + } + if ($NSObject.Comment -ne $this.Comment) { + Write-Verbose -Message "Setting Responder Action [$($this.Comment)]" + Set-NSResponderAction -Name $this.Name -Comment $this.Comment -Verbose:$false + } + } else { + Write-Verbose -Message "Creating resource [$($this.Name)]" + $params = @{ + name = $this.Name + type = $this.Type + target = $this.Target + comment = $this.Comment + } + New-NSResponderAction @params -ErrorAction SilentlyContinue + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSResponderAction -Name $NSObject.Name -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Responder Action: $($this.Name)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne $this.Name) { + Write-Verbose -Message "Name does not match [$($NSObject.Name) <> $($this.Name)]" + $pass = $false + } + if ($NSObject.Type -ne $this.Type) { + Write-Verbose -Message "Type does not match [$($NSObject.Type) <> $($this.Type)]" + $pass = $false + } + if ($NSObject.Target -ne $this.Target) { + Write-Verbose -Message "Target does not match [$($NSObject.Target) <> $($this.Target)]" + $pass = $false + } + } else { + Write-Verbose -Message "Responder Action [$($this.Name)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBResponderAction]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSResponderAction -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBResponderAction]::new() + $obj.Name = $this.Name + $obj.Type = $this.Type + $obj.Target = $this.Target + $obj.Comment = $this.Comment + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Name = $s.name + $obj.Type = $s.type + $obj.Target = $s.target + $obj.Comment = $s.comment + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBRewritePolicy { + [DscProperty(Key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty()] + [string]$ActionName + + [DscProperty()] + [string]$LogActionName + + [DscProperty()] + [ValidateLength(0, 8191)] + [Alias('Expression')] + [string]$Rule + + [DscProperty()] + [string]$Comment + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.name -ne $this.Name) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.Name)], resource can only be removed and recreated" + } + if ($NSObject.rule -ne $this.Rule) { + Write-Verbose -Message "Setting Rule [$($this.Rule)]" + Set-NSRewritePolicy -Name $this.Name -Rule $this.Rule -Verbose:$false + } + if ($NSObject.actionname -ne $this.ActionName) { + Write-Verbose -Message "Setting Action Name [$($this.ActionName)]" + Set-NSRewritePolicy -Name $this.Name -ActionName $this.ActionName -LogActionName $this.LogActionName -Rule $this.Rule -Verbose:$false + } + if ($NSObject.logActionname -ne "Use Global") { + if ($NSObject.logactionname -ne $this.LogActionName) { + Write-Verbose -Message "Setting LogActionName [$($this.LogActionName)]" + Set-NSRewritePolicy -Name $this.Name -LogActionName $this.LogActionName -Verbose:$false + } + } + if ($NSObject.Comment -ne $this.Comment) { + Write-Verbose -Message "Setting Comment [$($this.Comment)]" + Set-NSRewritePolicy -Name $this.Name -Comment $this.Comment -Verbose:$false + } + } else { + Write-Verbose -Message "Creating resource [$($this.Name)]" + $params = @{ + name = $this.Name + rule = $this.Rule + actionname = $this.ActionName + comment = $this.Comment + } + if ($PSBoundParameters.ContainsKey('LogActionName')) { + $params.Add('LogActionName', $this.LogActionName) + } + New-NSRewritePolicy @params -ErrorAction SilentlyContinue + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSRewritePolicy -Name $NSObject.Name -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Rewrite Policy: $($this.Name)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne $this.Name) { + Write-Verbose -Message "Name does not match [$($NSObject.Name) <> $($this.Name)]" + $pass = $false + } + if ($NSObject.Rule -ne $this.Rule) { + Write-Verbose -Message "Rule does not match [$($NSObject.Rule) <> $($this.Rule)]" + $pass = $false + } + if ($NSObject.ActionName -ne $this.ActionName) { + Write-Verbose -Message "Action Name does not match [$($NSObject.ActionName) <> $($this.ActionName)]" + $pass = $false + } + if ($NSObject.LogActionName -ne "Use Global") { + if ($NSObject.LogActionName -ne $this.LogActionName) { + Write-Verbose -Message "Log Action Name does not match [$($NSObject.LogActionName) <> $($this.LogActionName)]" + $pass = $false + } + } + if ($NSObject.Comment -ne $this.Comment) { + Write-Verbose -Message "Comment does not match [$($NSObject.Comment) <> $($this.Comment)]" + $pass = $false + } + } else { + Write-Verbose -Message "Responder Policy [$($this.Name)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBRewritePolicy]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSRewritePolicy -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBRewritePolicy]::new() + $obj.Name = $this.Name + $obj.Rule = $this.Rule + $obj.ActionName = $this.ActionName + $obj.LogActionName = $this.LogActionName + $obj.Comment = $this.Comment + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Name = $s.name + $obj.Rule = $s.rule + $obj.ActionName = $s.action + $obj.LogActionName = $s.logaction + $obj.Comment = $s.comment + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBRewriteAction { + [DscProperty(Key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty(Mandatory)] + [string]$Type + + [DscProperty(Mandatory)] + [ValidateLength(0, 8191)] + [string]$Target + + [DscProperty(Mandatory)] + [ValidateLength(0, 8191)] + [string]$Expression + + [DscProperty()] + [string]$Comment + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne $this.Name) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.Name)], resource can only be removed and recreated" + } + if ($NSObject.Type -ne $this.Type) { + Write-Verbose -Message "Setting Rule [$($this.Type)]" + Set-NSRewriteAction -Name $this.Name -Type $this.Type -Target $this.Target -Expression $this.Expression -Comment $this.Comment -Verbose:$false + } + if ($NSObject.Target -ne $this.Target) { + Write-Verbose -Message "Setting Action Name [$($this.Target)]" + Set-NSRewriteAction -Name $this.Name -Target $this.Target -Verbose:$false + } + if ($NSObject.Expression -ne $this.Expression) { + Write-Verbose -Message "Setting LogActionName [$($this.Expression)]" + Set-NSRewriteAction -Name $this.Name -Expression $this.Expression -Verbose:$false + } + if ($NSObject.Comment -ne $this.Comment) { + Write-Verbose -Message "Setting Comment [$($this.Comment)]" + Set-NSRewriteAction -Name $this.Name -Comment $this.Comment -Verbose:$false + } + } else { + Write-Verbose -Message "Creating resource [$($this.Name)]" + $params = @{ + name = $this.Name + Type = $this.Type.toLower() + Target = $this.Target + Expression = $this.Expression + Comment = $this.Comment + } + New-NSRewriteAction @params -ErrorAction SilentlyContinue + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSRewriteAction -Name $NSObject.Name -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Rewrite Action: $($this.Name)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.name -ne $this.Name) { + Write-Verbose -Message "Name does not match [$($NSObject.Name) <> $($this.Name)]" + $pass = $false + } + if ($NSObject.type -ne $this.Type) { + Write-Verbose -Message "Type does not match [$($NSObject.Type) <> $($this.Type)]" + $pass = $false + } + if ($NSObject.target -ne $this.Target) { + Write-Verbose -Message "Target does not match [$($NSObject.Target) <> $($this.Target)]" + $pass = $false + } + if ($NSObject.Expression -ne $this.Expression) { + Write-Verbose -Message "Expression does not match [$($NSObject.Expression) <> $($this.Expression)]" + $pass = $false + } + if ($NSObject.comment -ne $this.Comment) { + Write-Verbose -Message "Comment does not match [$($NSObject.Comment) <> $($this.Comment)]" + $pass = $false + } + } else { + Write-Verbose -Message "Responder Action [$($this.Name)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBRewriteAction]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSRewriteAction -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBRewriteAction]::new() + $obj.Name = $this.Name + $obj.Type = $this.Type + $obj.Target = $this.Target + $obj.Expression = $this.Expression + $obj.Comment = $this.Comment + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Name = $s.name + $obj.Type = $s.type + $obj.Target = $s.target + $obj.Expression = $s.stringbuilderexpr + $obj.Comment = $s.comment + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBDNSServer { + [DscProperty(Key)] + [string]$IPAddress + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty()] + [ValidateLength(0, 8191)] + [string]$Local = $false + + [DscProperty()] + [ValidateSet('ENABLED','DISABLED')] + [string]$State = 'ENABLED' + + [DscProperty()] + [ValidateSet('UDP', 'TCP', 'UDP_TCP')] + [string]$Type = 'UDP' + + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if (($NSObject.ip -ne $this.IPAddress) -OR ($NSObject.state -ne $this.State) -OR ($NSObject.type -ne $this.Type)) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.Name)], resource can only be removed and recreated. Resource deleted and re-added" + Remove-NSDnsNameServer -IPAddress $this.IPAddress -Verbose:$false -ErrorAction SilentlyContinue + Add-NSDnsNameServer -IPAddress $this.IPAddress -State $this.State -Type $this.Type -Verbose:$false -ErrorAction SilentlyContinue + } + } else { + Write-Verbose -Message "Creating resource [$($this.IPAddress)]" + $params = @{ + ip = $this.IPAddress + type = $this.Type + state = $this.State + } + Add-NSDnsNameServer @params -Verbose:$false -ErrorAction SilentlyContinue + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSDnsNameServer -IPAddress $this.IPAddress -Verbose:$false -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed DNS Server: $($this.IPAddress)" + } + } + + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + if ($NSObject.IPAddress -ne $this.IPAddress) { + Write-Verbose -Message "IP Address does not match [$($NSObject.IPAddress) <> $($this.IPAddress)]" + $pass = $false + } + if ($NSObject.Local -ne $this.Local) { + Write-Verbose -Message "Local does not match [$($NSObject.Local) <> $($this.Local)]" + $pass = $false + } + if ($NSObject.State -ne $this.State) { + Write-Verbose -Message "State does not match [$($NSObject.State) <> $($this.State)]" + $pass = $false + } + if ($NSObject.Type -ne $this.Type) { + Write-Verbose -Message "Type does not match [$($NSObject.Type) <> $($this.Type)]" + $pass = $false + } + } else { + Write-Verbose -Message "DNS server [$($this.IPAddress)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBDNSServer]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSDnsNameServer | where {$_.ip -eq $this.IPAddress} -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBDNSServer]::new() + $obj.IPAddress = $this.IPAddress + $obj.Local = $this.Local + $obj.State = $this.State + $obj.Type = $this.Type + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.IPAddress = $s.ip + $obj.Local = $s.local + $obj.State = $s.state + $obj.Type = $s.type + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBNSMode { + [DscProperty(Key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne "True") { + Write-Verbose -Message "Mode enabled, [$($this.Name)]" + Enable-NSMode -name $this.name -Confirm:$false + } + } else { + Write-Verbose -Message "Mode enabled, [$($this.Name)]" + Enable-NSMode -name $this.name -Confirm:$false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Disable-NSMode -Name $this.Name -Confirm:$false + Write-Verbose -Message "Mode disabled: $($this.Name)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne "True") { + Write-Verbose -Message "Mode is not set [$($NSObject.Name) <> $($this.Name)]" + $pass = $false + } + } else { + $pass = $false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } else { + if ($NSObject.Name -eq "True") { + $pass = $false + } + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBNSMode]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSMode -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBNSMode]::new() + $obj.Name = $this.Name + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Name = $s + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBNSFeature { + [DscProperty(Key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne "True") { + Write-Verbose -Message "Feature enabled, [$($this.Name)]" + Enable-NSFeature -name $this.name -Confirm:$false + } + } else { + Write-Verbose -Message "Feature enabled, [$($this.Name)]" + Enable-NSFeature -name $this.name -Confirm:$false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Disable-NSFeature -Name $this.Name -Confirm:$false + Write-Verbose -Message "Feature disabled: $($this.Name)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne "True") { + Write-Verbose -Message "Feature is not set [$($NSObject.Name) <> $($this.Name)]" + $pass = $false + } + } else { + $pass = $false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } else { + if ($NSObject.Name -eq "True") { + $pass = $false + } + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBNSFeature]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSFeature -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBNSFeature]::new() + $obj.Name = $this.Name + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Name = $s.name + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBSSLCertificate { + [DscProperty(Key)] + [string]$CertKeyName + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty()] + [string]$CertPath + + [DscProperty()] + [string]$KeyPath + + [DscProperty()] + [ValidateSet('PEM','DER','PFX')] + [string]$CertKeyFormat = 'PEM' + + [DscProperty()] + [securestring]$Password + + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if (($NSObject.CertKeyName -ne $this.CertKeyName) -OR ($NSObject.CertPath -ne $this.CertPath) -OR ($NSObject.KeyPath -ne $this.KeyPath) -OR ($NSObject.CertKeyFormat -ne $this.CertKeyFormat)) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.CertKeyName)], resource can only be removed and recreated" + Remove-NSCertKeyPair -CertKeyName $this.CertKeyName + } + } else { + Write-Verbose -Message "Creating resource [$($this.CertKeyName)]" + $params = @{ + CertKeyName = $this.CertKeyName + CertPath = $this.CertPath + KeyPath = $this.KeyPath + CertKeyFormat = $this.CertKeyFormat + } + Add-NSCertKeyPair @params -ErrorAction SilentlyContinue + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSResponderAction -Name $NSObject.CertKeyName -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Certificate: $($this.Name)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.certkeyname -ne $this.CertKeyName) { + Write-Verbose -Message "Certificate Key Name does not match [$($NSObject.certkeyname) <> $($this.CertKeyName)]" + $pass = $false + } + if ($NSObject.certpath -ne $this.CertPath) { + Write-Verbose -Message "Certificate Path does not match [$($NSObject.certpath) <> $($this.CertPath)]" + $pass = $false + } + if ($this.KeyPath) { + if ($NSObject.keypath -ne $this.KeyPath) { + Write-Verbose -Message "Key Path does not match [$($NSObject.keypath) <> $($this.KeyPath)]" + $pass = $false + } + } + } else { + Write-Verbose -Message "Certificate[$($this.CertKeyName)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBSSLCertificate]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSCertKeyPair -CertKeyName $this.CertKeyName -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + $obj = [LBSSLCertificate]::new() + $obj.CertKeyName = $this.CertKeyName + $obj.CertPath = $this.CertPath + $obj.CertKeyFormat = $this.CertKeyFormat + $obj.KeyPath = $this.KeyPath + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.CertKeyName = $s.certkey + $obj.CertPath = $s.cert + $obj.CertKeyFormat = $s.inform + if ($s.key) { + $obj.KeyPath = $s.key + } + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBNSIP { + [DscProperty(Key)] + [string]$IPAddress + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty(Mandatory)] + [string]$SubnetMask + + [DscProperty()] + [string]$Type = 'SNIP' + + [DscProperty(Mandatory)] + [bool]$VServer = $false + + [DscProperty(Mandatory)] + [bool]$Telnet = $false + + [DscProperty(Mandatory)] + [bool]$FTP = $false + + [DscProperty(Mandatory)] + [bool]$GUI = $false + + [DscProperty(Mandatory)] + [bool]$SSH = $false + + [DscProperty(Mandatory)] + [bool]$SNMP = $false + + [DscProperty(Mandatory)] + [bool]$MgmtAccess = $false + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.IPAddressName -ne $this.IPAddress) { + Write-Verbose -Message "Warning, the resource cannot be set to [$($this.IPAddress)]" + } + if ($NSObject.SubnetMask -ne $this.SubnetMask) { + Write-Verbose -Message "Resource name does not match [$($this.SubnetMask)]" + Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask + } + if ($NSObject.Type -ne $this.Type) { + Write-Verbose -Message "Warning, the resource cannot be set to [$($this.Type)]" + } + if ($NSObject.VServer -ne $this.VServer) { + Write-Verbose -Message "Setting vServer [$($this.VServer)]" + Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -VServer + } + if ($NSObject.Telnet -ne $this.Telnet) { + Write-Verbose -Message "Setting Telnet [$($this.Telnet)]" + Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -Telnet + } + if ($NSObject.FTP -ne $this.FTP) { + Write-Verbose -Message "Setting FTP [$($this.FTP)]" + Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -FTP + } + if ($NSObject.GUI -ne $this.GUI) { + Write-Verbose -Message "Setting GUI [$($this.GUI)]" + Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -GUI + } + if ($NSObject.SSH -ne $this.SSH) { + Write-Verbose -Message "Setting GUI [$($this.SSH)]" + Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -SSH + } + if ($NSObject.SNMP -ne $this.SNMP) { + Write-Verbose -Message "Setting SNMP [$($this.SNMP)]" + Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -SNMP + } + if ($NSObject.MgmtAccess -ne $this.MgmtAccess) { + Write-Verbose -Message "Setting Management Access [$($this.MgmtAccess)]" + Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -MgmtAccess + } + } else { + Write-Verbose -Message "Feature enabled, [$($this.IPAddress)]" + $params = @{ + ipaddress = $this.IPAddress + netmask = $this.SubnetMask + type = $this.Type + } + Add-NSIPResource @params -Confirm:$false + # $switches { + # ipaddress = $this.IPAddress + # netmask = $this.SubnetMask + # type = $this.Type + # vserver = $this.VServer + # telnet = $this.Telnet + # ftp = $this.FTP + # gui = $this.GUI + # ssh = $this.SSH + # snmp = $this.SNMP + # mgmtaccess = $this.mgmtaccess + # } + # Invoke-DscResource -Method set -ModuleName poshorigin_netscaler -Name LBNSIP -Property $switches + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Disable-NSFeature -Name $this.Name -Confirm:$false + Write-Verbose -Message "Feature disabled: $($this.Name)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # # Run tests and set any needed attributes to match desired configuration + if ($NSObject.ipaddress -ne $this.IPAddress) { + Write-Verbose -Message "IPAddress does not match [$($NSObject.ipaddress) <> $($this.IPAddress)]" + $pass = $false + } + if ($NSObject.subnetmask -ne $this.SubnetMask) { + Write-Verbose -Message "SubnetMask does not match [$($NSObject.subnetmask) <> $($this.SubnetMask)]" + $pass = $false + } + if ($NSObject.type -ne $this.Type) { + Write-Verbose -Message "Type does not match [$($NSObject.type) <> $($this.Type)]" + $pass = $false + } + if ($NSObject.vserver -ne $this.VServer) { + Write-Verbose -Message "VServer does not match [$($NSObject.vserver) <> $($this.VServer)]" + $pass = $false + } + if ($NSObject.telnet -ne $this.Telnet) { + Write-Verbose -Message "Telnet does not match [$($NSObject.telnet) <> $($this.Telnet)]" + $pass = $false + } + if ($NSObject.ftp -ne $this.FTP) { + Write-Verbose -Message "FTP does not match [$($NSObject.ftp) <> $($this.FTP)]" + $pass = $false + } + if ($NSObject.gui -ne $this.GUI) { + Write-Verbose -Message "GUI does not match [$($NSObject.gui) <> $($this.GUI)]" + $pass = $false + } + if ($NSObject.ssh -ne $this.SSH) { + Write-Verbose -Message "SSH does not match [$($NSObject.ssh) <> $($this.SSH)]" + $pass = $false + } + if ($NSObject.snmp -ne $this.SNMP) { + Write-Verbose -Message "SNMP does not match [$($NSObject.snmp) <> $($this.SNMP)]" + $pass = $false + } + if ($NSObject.mgmtaccess -ne $this.MgmtAccess) { + Write-Verbose -Message "MgmtAccess does not match [$($NSObject.mgmtaccess) <> $($this.MgmtAccess)]" + $pass = $false + } + } else { + $pass = $false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } else { + if ($NSObject.Name -eq "True") { + $pass = $false + } + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBNSIP]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSIPResource -IPAddress $this.IPAddress -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBNSIP]::new() + $obj.IPAddress = $this.IPAddress + $obj.SubnetMask = $this.SubnetMask + $obj.Type = $this.Type + $obj.VServer = $this.VServer + $obj.Telnet = $this.Telnet + $obj.FTP = $this.FTP + $obj.GUI = $this.GUI + $obj.SSH = $this.SSH + $obj.SNMP = $this.SNMP + $obj.MgmtAccess = $this.MgmtAccess + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.IPAddress = $s.ipaddress + $obj.SubnetMask = $s.netmask + $obj.Type = $s.type + $obj.VServer = $this.TestEnabledFeatures($s.VServer) + $obj.Telnet = $this.TestEnabledFeatures($s.Telnet) + $obj.FTP = $this.TestEnabledFeatures($s.FTP) + $obj.GUI = $this.TestEnabledFeatures($s.GUI) + $obj.SSH = $this.TestEnabledFeatures($s.SSH) + $obj.SNMP = $this.TestEnabledFeatures($s.SNMP) + $obj.MgmtAccess = $this.TestEnabledFeatures($s.MgmtAccess) + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } + + <# + Helper method to test switch/boolean options + #> + [bool] TestEnabledFeatures([string] $Existing){ + # $present = $true + if ($Existing -eq "ENABLED") { + $present = $true + } else { + $present = $false + } + return $present + } +} + + +[DscResource()] +class LBNSVirtualServerBinding { + [DscProperty(Key)] + [string]$VirtualServerName + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty()] + [string]$ServiceGroupName + + [DscProperty()] + [string]$ServiceName + + [DscProperty()] + [int]$Weight = 1 + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -ne $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($this.ServiceGroupName -eq $NSObject.ServiceGroupName) { + Write-Verbose -Message "Service Group Name bound, [$($this.VirtualServerName)]" + Add-NSLBVirtualServerBinding -VirtualServerName $this.VirtualServerName -ServiceGroupName $this.ServiceGroupName -Weight $this.Weight -Confirm:$false + } else { + if (($this.ServiceName -ne $null) -OR ($NSObject.NetScalerFQDN -ne $null)) { + Write-Verbose -Message "Service Name bound, [$($this.ServiceName)]" + Add-NSLBVirtualServerBinding -VirtualServerName $this.VirtualServerName -ServiceName $this.ServiceName -Weight $this.Weight -Confirm:$false + } + } + } + } 'Absent' { + if ($this.ServiceGroupName) { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSLBVirtualServerBinding -name $this.VirtualServerName -ServiceGroupName $this.ServiceGroupName -Confirm:$false + Write-Verbose -Message "Virtual Server Binding removed for $($this.VirtualServerName)" + } + } else { + Remove-NSLBVirtualServerBinding -name $this.VirtualServerName -ServiceName $this.ServiceName -Confirm:$false + Write-Verbose -Message "Virtual Server Binding removed for $($this.VirtualServerName)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($this.servicegroupname -eq $NSObject.ServiceGroupName) { + if ($NSObject.virtualservername -ne $this.VirtualServerName) { + Write-Verbose -Message "VirtualServerName does not match [$($NSObject.virtualservername) <> $($this.VirtualServerName)]" + $pass = $false + } + if ($NSObject.servicegroupname -ne $this.ServiceGroupName) { + Write-Verbose -Message "ServiceGroupName does not match [$($NSObject.servicegroupname) <> $($this.ServiceGroupName)]" + $pass = $false + } + } else { + if ($NSObject.virtualservername -ne $this.VirtualServerName) { + Write-Verbose -Message "VirtualServerName does not match [$($NSObject.virtualservername) <> $($this.VirtualServerName)]" + $pass = $false + } + if ($NSObject.servicename -ne $this.ServiceName) { + Write-Verbose -Message "ServiceName does not match [$($NSObject.servicename) <> $($this.ServiceName)]" + $pass = $false + } + } + } else { + $pass = $false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } else { + if ($NSObject.Name -eq "True") { + $pass = $false + } + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBNSVirtualServerBinding]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSLBVirtualServerBinding -Name $this.VirtualServerName -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBNSVirtualServerBinding]::new() + $obj.VirtualServerName = $this.VirtualServerName + $obj.ServiceGroupName = $this.ServiceGroupName + $obj.ServiceName = $this.ServiceName + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.VirtualServerName = $s.name + $obj.ServiceGroupName = $s.ServiceGroupName + $obj.ServiceName = $s.ServiceName + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + + +[DscResource()] +class LBSystemFile { + [DscProperty(Key)] + [string]$FileName + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty(Mandatory)] + [string]$FileLocation + + [DscProperty(Mandatory)] + [string]$Path + + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($NSObject.Ensure -ne $this.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if (!$NSObject.FileName) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.FileName)], resource can only be removed and recreated" + Add-NSSystemFile -Path $this.Path -FileLocation $this.FileLocation -FileName $this.FileName -Force + } + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSSystemFile -Name $this.FileName -FileLocation $this.FileLocation -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed File: $($this.Name)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.filename -ne $this.FileName) { + Write-Verbose -Message "File Name does not match [$($NSObject.filename) <> $($this.FileName)]" + $pass = $false + } + if ($NSObject.filelocation -ne $this.FileLocation) { + Write-Verbose -Message "File Location does not match [$($NSObject.filelocation) <> $($this.FileLocation)]" + $pass = $false + } + } else { + Write-Verbose -Message "File[$($this.FileName)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBSystemFile]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSSystemFile -FileName $this.FileName -FileLocation $this.FileLocation -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBSystemFile]::new() + $obj.FileName + $obj.FileLocation + $obj.Path + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.FileName = $s.filename + $obj.FileLocation = $s.filelocation + if ($s.Path) { + $obj.Path = $s.path + } + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBVLAN { + [DscProperty(Key)] + [int]$VLANID + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty(Mandatory)] + [string]$AliasName + + [DscProperty()] + [ValidateSet('ENABLED','DISABLED')] + [string]$IPV6DynamicRouting = 'DISABLED' + + [DscProperty(Mandatory)] + [int]$MTU + + [DscProperty()] + [string]$Interface + + [DscProperty()] + [bool]$Tagged = $false + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.vlanid -ne $this.VLANID) { + Write-Warning -Message "Setting VLANID cannot be changed to [$($this.VLANID)], resource can only be removed and recreated" + } + if ($NSObject.aliasname -ne $this.AliasName) { + Write-Verbose -Message "Setting AliasName [$($this.AliasName)]" + Set-NSVLAN -VLANID $this.VLANID -AliasName $this.AliasName + } + if ($NSObject.mtu -ne $this.AliasName) { + Write-Verbose -Message "Setting AliasName [$($this.AliasName)]" + Set-NSVLAN -VLANID $this.VLANID -AliasName $this.AliasName + } + if ($NSObject.ipv6dynamicrouting -ne $this.IPV6DynamicRouting) { + Write-Verbose -Message "Setting AliasName [$($this.IPV6DynamicRouting)]" + Set-NSVLAN -VLANID $this.VLANID -IPV6DynamicRouting $this.IPV6DynamicRouting + } + if ($NSObject.mtu -ne $this.MTU) { + Write-Verbose -Message "Setting AliasName [$($this.MTU)]" + Set-NSVLAN -VLANID $this.VLANID -MTU $this.MTU + } + if ($NSObject.interface -ne $this.Interface) { + Write-Verbose -Message "Setting Interface [$($this.Interface)]" + Set-NSVLANInterfaceBinding -VLANID $this.VLANID -Interface $this.Interface + } + } else { + Write-Verbose -Message "Feature enabled, [$($this.IPAddress)]" + $params = @{ + vlanid = $this.VLANID + aliasname = $this.AliasName + ipv6dynamicrouting = $this.ipv6dynamicrouting + mtu = $this.MTU + interface = $this.Interface + } + Add-NSVLAN @params -Confirm:$false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSVLAN -VLANID $this.VLANID -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed VLANID: $($this.VLANID)" + } + } + } + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.vlanid -ne $this.VLANID) { + Write-Verbose -Message "VLANID does not match [$($NSObject.vlanid) <> $($this.VLANID)]" + $pass = $false + } + if ($NSObject.aliasname -ne $this.AliasName) { + Write-Verbose -Message "Aliasname does not match [$($NSObject.aliasname) <> $($this.AliasName)]" + $pass = $false + } + if ($NSObject.ipv6dynamicrouting -ne $this.IPV6DynamicRouting) { + Write-Verbose -Message "IPV6 Dynamic Routing does not match [$($NSObject.ipv6dynamicrouting) <> $($this.IPV6DynamicRouting)]" + $pass = $false + } + if ($NSObject.mtu -ne $this.MTU) { + Write-Verbose -Message "MTU does not match [$($NSObject.mtu) <> $($this.MTU)]" + $pass = $false + } + if ($NSObject.interface -ne $this.Interface) { + Write-Verbose -Message "Interface does not match [$($NSObject.interface) <> $($this.Interface)]" + $pass = $false + } + if ($NSObject.tagged -ne $this.Tagged) { + Write-Verbose -Message "Tagged does not match [$($NSObject.Tagged) <> $($this.Tagged)]" + $pass = $false + } + } else { + Write-Verbose -Message "File[$($this.VLANID)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBVLAN]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSVLAN -VLANID $this.VLANID -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBVLAN]::new() + $obj.VLANID = $this.VLANID + $obj.AliasName = $this.AliasName + $obj.IPV6DynamicRouting = $this.IPV6DynamicRouting + $obj.MTU = $this.MTU + $obj.Interface = $this.Interface + $obj.Tagged = $this.Tagged + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.VLANID = $s.id + if ($s.AliasName) { $obj.AliasName = $s.aliasname } + $obj.IPV6DynamicRouting = $s.ipv6dynamicrouting + if ($s.mtu) { $obj.MTU = $s.mtu } + $obj.Interface = $s.ifaces.ToString() + $obj.Tagged = $s.tagged + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} \ No newline at end of file From 929308a1211b884cb2c03e52f3a4cf5c688c9989 Mon Sep 17 00:00:00 2001 From: Juan Herrera Date: Wed, 30 Aug 2017 10:13:17 -0700 Subject: [PATCH 5/7] cleaned up some classes and added additional ones --- .../POSHOrigin_NetScaler.psd1 | 2 +- .../POSHOrigin_NetScaler.psm1 | 5816 ++++++++++------- 2 files changed, 3558 insertions(+), 2260 deletions(-) diff --git a/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psd1 b/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psd1 index d4d3b80..dcea5d8 100644 --- a/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psd1 +++ b/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psd1 @@ -24,7 +24,7 @@ RequiredModules = 'NetScaler' # DSC resources to export from this module - DscResourcesToExport = @('LBVirtualServer','LBServer','LBMonitor','LBServiceGroup','LBNTPServer','LBResponderPolicy','LBResponderAction','LBSSLCertificate','LBRewritePolicy','LBRewriteAction','LBDNSServer','LBNSMode','LBNSFeature','LBNSIP','LBNSVirtualServerBinding','LBSystemFile','LBVLAN','LBResponderPolicyBinding','LBServiceGroupMember','LBService') + DscResourcesToExport = @('LBVirtualServer','LBServer','LBMonitor','LBServiceGroupMonitorBinding','LBServiceGroup','LBNTPServer','LBResponderPolicy','LBResponderAction','LBResponderHTMLPage','LBRewritePolicy','LBRewriteAction','LBDNSServer','LBNSMode','LBNSFeature','LBNSIP','LBVirtualServerBinding','LBSystemFile','LBVLAN','LBResponderPolicyBinding','LBServiceGroupMember','LBService','LBServiceMonitorBinding','LBSSLCertificate','LBSSLCertificateBinding','LBSSLCertificateLink','LBSSLProfile','LBSSLProfileBinding') PrivateData = @{ PSData = @{ diff --git a/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 b/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 index 9b2706f..1067502 100644 --- a/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 +++ b/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 @@ -28,27 +28,27 @@ class LBVirtualServer { [string]$Comment = '' [DscProperty(Mandatory)] - [ValidateRange(1, 65534)] + [ValidateRange(0, 65534)] [int]$Port [DscProperty()] - [ValidateSet('DHCPRA','DIAMTER', 'DNS', 'DNS_TCP', 'DLTS', 'FTP', 'HTTP', 'MSSQL', - 'MYSQL', 'NNTP', 'PUSH','RADIUS', 'RDP', 'RTSP', 'SIP_UDP', 'SSL', 'SSL_BRIDGE', + [ValidateSet('DHCPRA','DIAMTER', 'DNS', 'DNS_TCP', 'DLTS', 'FTP', 'HTTP', 'MSSQL', + 'MYSQL', 'NNTP', 'PUSH','RADIUS', 'RDP', 'RTSP', 'SIP_UDP', 'SSL', 'SSL_BRIDGE', 'SSL_DIAMETER', 'SSL_PUSH', 'SSL_TCP', 'TCP', 'TFTP', 'UDP')] [string]$ServiceType = 'HTTP' [DscProperty()] - [ValidateSet('ROUNDROBIN', 'LEASTCONNECTION', 'LEASTRESPONSETIME', 'LEASTBANDWIDTH', - 'LEASTPACKETS', 'CUSTOMLOAD', 'LRTM', 'URLHASH', 'DOMAINHASH', 'DESTINATIONIPHASH', + [ValidateSet('ROUNDROBIN', 'LEASTCONNECTION', 'LEASTRESPONSETIME', 'LEASTBANDWIDTH', + 'LEASTPACKETS', 'CUSTOMLOAD', 'LRTM', 'URLHASH', 'DOMAINHASH', 'DESTINATIONIPHASH', 'SOURCEIPHASH', 'TOKEN', 'SRCIPDESTIPHASH', 'SRCIPSRCPORTHASH', 'CALLIDHASH')] [string]$LBMethod = 'ROUNDROBIN' - [DscProperty()] + [DscProperty()] [ValidateSet('SOURCEIP', 'COOKIEINSERT', 'SSLSESSION', 'CUSTOMSERVERID', 'RULE', 'URLPASSIVE', 'DESTIP', 'SRCIPDESTIP', 'CALLID' ,'RTSPID', 'FIXSESSION', 'NONE')] [string]$PersistenceType = 'SOURCEIP' [DscProperty()] - [string]$HttpRedirectURL = '' + [string]$HttpRedirectURL [DscProperty()] [ValidateSet('PASSIVE', 'ACTIVE')] @@ -57,6 +57,16 @@ class LBVirtualServer { [DscProperty()] [int]$TimeOut = 2 + [DscProperty()] + [int]$ClientTimeout = 180 + + [DscProperty()] + [string]$BackupVServer + + [DscProperty()] + [ValidateSet('ENABLED', 'DISABLED')] + [string]$RedirectPortRewrite = 'DISABLED' + Init() { try { Import-Module -Name Netscaler -Verbose:$false -Debug:$false @@ -90,33 +100,45 @@ class LBVirtualServer { if ($NSObject.comment -ne $this.Comment) { Write-Verbose -Message "Setting virtual server Comment [$($this.Comment)]" Set-NSLBVirtualServer -Name $this.Name -Comment $this.Comment -Verbose:$false -Force - } + } if ($NSObject.Port -ne $this.Port) { Write-Warning -Message 'NetScaler does not support changing virtual server port on an existing virtual server. Virtual server must be deleted and recreated.' } if ($NSObject.ServiceType -ne $this.ServiceType) { Write-Warning -Message 'NetScaler does not support changing virtual server service type on an existing virtual server. Virtual server must be deleted and recreated.' } - if ($NSObject.lbmethod -ne $this.LBMethod) { + if ($NSObject.lbmethod -ne $this.LBMethod) { Set-NSLBVirtualServer -Name $this.Name -LBMethod $this.LBMethod -Verbose:$false -Force Write-Verbose -Message "Setting virtual server load balance method [$($this.LBMethod)]" } - if ($NSObject.persistencetype -ne $this.PersistenceType) { + if ($NSObject.persistencetype -ne $this.PersistenceType) { Set-NSLBVirtualServer -Name $this.Name -PersistenceType $this.PersistenceType -Verbose:$false -Force Write-Verbose -Message "Setting virtual server persistence [$($this.PersistenceType)]" } - if ($NSObject.httpredirecturl -ne $this.HttpRedirectURL) { + if (($NSObject.httpredirectURL) -AND ($NSObject.httpredirecturl -ne $this.HttpRedirectURL)) { Set-NSLBVirtualServer -Name $this.Name -HttpRedirectURL $this.HttpRedirectURL -Verbose:$false -Force Write-Verbose -Message "Setting virtual server redirect [$($this.HttpRedirectURL)]" - } - if ($NSObject.icmpvsrresponse -ne $this.ICMPVSRResponse) { + } + if ($NSObject.icmpvsrresponse -ne $this.ICMPVSRResponse) { Set-NSLBVirtualServer -Name $this.Name -ICMPVSRResponse $this.ICMPVSRResponse -Verbose:$false -Force Write-Verbose -Message "Setting virtual server icmpvsrresponse [$($this.ICMPVSRResponse)]" } - if ($NSObject.timeout -ne $this.TimeOut) { + if ($NSObject.timeout -ne $this.TimeOut) { Set-NSLBVirtualServer -Name $this.Name -TimeOut $this.TimeOut -Verbose:$false -Force Write-Verbose -Message "Setting virtual server timeout [$($this.TimeOut)]" } + if ($NSObject.clienttimeout -ne $this.ClientTimeout) { + Set-NSLBVirtualServer -Name $this.Name -ClientTimeout $this.ClientTimeout -Verbose:$false -Force + Write-Verbose -Message "Setting virtual server client timeout [$($this.ClientTimeout)]" + } + if (($NSObject.backupvserver) -AND ($NSObject.backupvserver -ne $this.BackupVServer)) { + Set-NSLBVirtualServer -Name $this.Name -BackupVServer $this.BackupVServer -Verbose:$false -Force + Write-Verbose -Message "Setting virtual server BackupVServer [$($this.BackupVServer)]" + } + if ($NSObject.RedirectPortRewrite -ne $this.RedirectPortRewrite) { + Set-NSLBVirtualServer -Name $this.Name -RedirectPortRewrite $this.RedirectPortRewrite -Verbose:$false -Force + Write-Verbose -Message "Setting virtual server RedirectPortRewrite [$($this.RedirectPortRewrite)]" + } } else { Write-Verbose -Message "Creating virtual server [$($this.Name)]" $params = @{ @@ -129,14 +151,21 @@ class LBVirtualServer { ICMPVSRResponse = $this.ICMPVSRResponse TimeOut = $this.TimeOut Comment = $this.Comment + RedirectPortRewrite = $this.RedirectPortRewrite } if ($null -ne $this.HttpRedirectURL) { $params.HttpRedirectURL = $this.HttpRedirectURL } + if ($null -ne $this.ClientTimeout) { + $params.ClientTimeout = $this.ClientTimeout + } + if ($null -ne $this.BackupVServer) { + $params.BackupVServer = $this.BackupVServer + } New-NSLBVirtualServer @params -ErrorAction SilentlyContinue } } 'Absent' { - try { + try { Write-Verbose -Message "Removing virtual server: $($this.Name)" Remove-NSLBVirtualServer -Name $this.Name -Confirm:$false -Verbose:$false -Force } catch { @@ -144,6 +173,7 @@ class LBVirtualServer { } } } + Save-NSConfig } catch { Write-Error 'There was a problem setting the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" @@ -170,7 +200,7 @@ class LBVirtualServer { if ($NSObject.name -ne $this.Name) { Write-Verbose -Message "Virtual server Name does not match [$($NSObject.name) <> $($this.Name)" $pass = $false - } + } if ($NSObject.ipaddress -ne $this.IPAddress) { Write-Verbose -Message "Virtual server IP address does not match [$($NSObject.ipaddress) <> $($this.IPAddress)" $pass = $false @@ -178,7 +208,7 @@ class LBVirtualServer { if ($NSObject.comment -ne $this.Comment) { Write-Verbose -Message "Virtual server Comment do not match [$($NSObject.comment) <> $($this.Comment)]" $pass = $false - } + } if ($NSObject.port -ne $this.Port) { Write-Verbose -Message "Virtual server port does not match [$($NSObject.port) <> $($this.Port)" $pass = $false @@ -187,26 +217,38 @@ class LBVirtualServer { Write-Verbose -Message "Virtual server service type does not match [$($NSObject.servicetype) <> $($this.ServiceType)" $pass = $false } - if ($NSObject.lbmethod -ne $this.LBMethod) { + if ($NSObject.lbmethod -ne $this.LBMethod) { Write-Verbose -Message "Virtual server load balance method does not match [$($NSObject.lbmethod) <> $($this.LBMethod)" $pass = $false } - if ($NSObject.persistencetype -ne $this.PersistenceType) { + if ($NSObject.persistencetype -ne $this.PersistenceType) { Write-Verbose -Message "Virtual server Persistence Type does not match [$($NSObject.persistencetype) <> $($this.PersistenceType)" $pass = $false } - if ($NSObject.ICMPVSRResponse -ne $this.ICMPVSRResponse) { + if ($NSObject.ICMPVSRResponse -ne $this.ICMPVSRResponse) { Write-Verbose -Message "Virtual server ICMP Response does not match [$($NSObject.ICMPVSRResponse) <> $($this.ICMPVSRResponse)" $pass = $false - } - if ($NSObject.httpredirectURL -ne $this.HTTPRedirectURL) { + } + if (($NSObject.httpredirectURL) -AND ($NSObject.httpredirectURL -ne $this.HTTPRedirectURL)) { Write-Verbose -Message "Virtual server HTTP Redirect does not match [$($NSObject.httpredirectURL) <> $($this.HTTPRedirectURL)" $pass = $false } - if ($NSObject.timeout -ne $this.TimeOut) { + if ($NSObject.timeout -ne $this.TimeOut) { Write-Verbose -Message "Virtual server Timeout does not match [$($NSObject.timeout) <> $($this.TimeOut)" $pass = $false - } + } + if ($NSObject.clienttimeout -ne $this.ClientTimeout) { + Write-Verbose -Message "Virtual server Client Timeout does not match [$($NSObject.clienttimeout) <> $($this.ClientTimeout)" + $pass = $false + } + if (($NSObject.backupvserver) -AND ($NSObject.backupvserver -ne $this.BackupVServer)) { + Write-Verbose -Message "Virtual server Backup Server does not match [$($NSObject.backupvserver) <> $($this.BackupVServer)" + $pass = $false + } + if ($NSObject.RedirectPortRewrite -ne $this.RedirectPortRewrite) { + Write-Verbose -Message "RedirectPortRewrite does not match [$($NSObject.RedirectPortRewrite) <> $($this.RedirectPortRewrite)" + $pass = $false + } } else { Write-Verbose -Message "Resource [$($this.Name)] was not found" $pass = $false @@ -228,7 +270,7 @@ class LBVirtualServer { } catch { # Do nothing } - return $pass + return $pass } [LBVirtualServer]Get() { @@ -239,36 +281,42 @@ class LBVirtualServer { } catch { $s = $null } - + $obj = [LBVirtualServer]::new() $obj.Name = $this.Name $obj.IPAddress = $this.IPAddress $obj.Port = $this.Port $obj.ServiceType = $this.ServiceType - $obj.Comment = $this.Comment + $obj.Comment = $this.Comment $obj.LBMethod = $this.LBMethod $obj.PersistenceType = $this.PersistenceType $obj.HTTPRedirectURL = $this.HTTPRedirectURL $obj.ICMPVSRResponse = $this.ICMPVSRResponse $obj.TimeOut = $this.TimeOut + $obj.ClientTimeout = $this.ClientTimeout + $obj.BackupVServer = $this.BackupVServer + $obj.RedirectPortRewrite = $this.RedirectPortRewrite if ($s) { $obj.Ensure = [ensure]::Present - $obj.Name = $s.Name + $obj.Name = $s.Name $obj.IPAddress = $s.ipv46 $obj.Port = $s.port $obj.ServiceType = $s.servicetype - if ($s.comment) { $obj.Comment = $s.comment } + $obj.Comment = $s.comment $obj.LBMethod = $s.lbmethod $obj.PersistenceType = $s.persistencetype - if ($s.redirurl) { $obj.HTTPRedirectURL = $s.redirurl } - $obj.ICMPVSRResponse = $s.icmpvsrresponse + if ($s.redirurl) { $obj.HttpRedirectURL = $s.redirurl.toString() } + $obj.ICMPVSRResponse = $s.icmpvsrresponse $obj.TimeOut = $s.timeout + $obj.ClientTimeout = $s.clttimeout + if ($s.backupvserver) { $obj.BackupVServer = $s.backupvserver } + $s.RedirectPortRewrite = $s.RedirectPortRewrite } else { $obj.Ensure = [ensure]::Absent } Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue return $obj - } + } } [DscResource()] @@ -296,9 +344,6 @@ class LBServer { [ValidateSet('ENABLED', 'DISABLED')] [string]$State = 'ENABLED' - [DscProperty()] - [bool]$ParameterExport = $false - Init() { try { Import-Module -Name Netscaler -Verbose:$false -Debug:$false @@ -321,7 +366,11 @@ class LBServer { try { switch ($this.Ensure) { 'Present' { + if ($NSObject.Ensure -eq [ensure]::Present) { + if ($NSObject.name -ne $this.Name) { + Write-Warning -Message 'NetScaler does not support changing virtual server name on an existing virtual server. Virtual server must be deleted and recreated.' + } if ($NSObject.ipaddress -ne $this.IPAddress) { Write-Verbose -Message "Setting server IP [$($this.IPAddress)]" Set-NSLBServer -Name $this.Name -IPAddress $this.IPAddress -Force -Verbose:$false @@ -330,7 +379,7 @@ class LBServer { Write-Verbose -Message "Setting server Comment [$($this.Comment)]" Set-NSLBServer -Name $this.Name -Comment $this.Comment -Force -Verbose:$false } - if ($NSObject.state -ne $this.State) { + if ($NSObject.state -ne $this.State) { Write-Verbose -Message "Setting server state [$($this.State)]" if ($this.State -eq 'ENABLED') { Enable-NSLBServer -Name $this.Name -Force -Verbose:$false @@ -341,19 +390,15 @@ class LBServer { } else { Write-Verbose -Message "Creating server [$($this.Name)]" $params = @{ - Name = $this.Name - IPAddress = $this.IPAddress - Comment = $this.Comment - Confirm = $false - Verbose = $false - } - if ($null -ne $this.TrafficDomainId) { - $params.TrafficDomainId = $this.TrafficDomainId + name = $this.Name + ipaddress = $this.IPAddress + comment = $this.Comment + state = $this.State } - New-NSLBServer @params + New-NSLBServer @params -Confirm:$false -Verbose:$false } } 'Absent' { - try { + try { Write-Verbose -Message "Removing server: $($this.Name)" Remove-NSLBServer -Name $this.Name -Confirm:$false -Verbose:$false -Force } catch { @@ -361,6 +406,7 @@ class LBServer { } } } + Save-NSConfig } catch { Write-Error 'There was a problem setting the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" @@ -392,7 +438,7 @@ class LBServer { Write-Verbose -Message "Server Comment does not match [$($NSObject.comment) <> $($this.Comment)]" $pass = $false } - if ($NSObject.state -ne $this.State) { + if ($NSObject.state -ne $this.State) { Write-Verbose -Message "Server state does not match [$($NSObject.state) <> $($this.State)]" $pass = $false } @@ -416,7 +462,7 @@ class LBServer { } catch { # Do nothing } - return $pass + return $pass } [LBServer]Get() { @@ -427,17 +473,15 @@ class LBServer { } catch { $s = $null } - + $obj = [LBServer]::new() $obj.Name = $this.Name $obj.IPAddress = $this.IPAddress $obj.Comment = $this.Comment $obj.State = $this.State - $obj.Credential = $this.Credential - $obj.NetScalerFQDN = $this.NetScalerFQDN - $obj.ParameterExport = $this.ParameterExport if ($s) { $obj.Ensure = [ensure]::Present + $obj.Name = $s.name $obj.IPAddress = $s.ipaddress $obj.Comment = $s.comment $obj.State = $s.state @@ -450,7 +494,7 @@ class LBServer { } [DscResource()] -class LBMonitor { +class LBServiceGroup { [DscProperty(Key)] [string]$Name @@ -458,140 +502,112 @@ class LBMonitor { [Ensure]$Ensure = [Ensure]::Present [DscProperty(Mandatory)] - [string]$NetScalerFQDN - - [DscProperty(Mandatory)] - [pscredential]$Credential - - [DscProperty(Mandatory)] - [ValidateSet('PING', 'TCP', 'HTTP', 'TCP-ECV', 'HTTP-ECV', 'UDP-ECV', 'DNS', 'FTP', 'LDNS-PING', - 'LDNS-TCP', 'RADIUS', 'USER', 'HTTP-INLINE', 'SIP-UDP', 'LOAD', 'FTP-EXTENDED', 'SMTP', 'SNMP', - 'NNTP', 'MYSQL', 'MYSQL-ECV', 'MSSQL-ECV', 'ORACLE-ECV', 'LDAP', 'POP3', 'CITRIX-XML-SERVICE', - 'CITRIX-WEB-INTERFACE', 'DNS-TCP', 'RTSP', 'ARP', 'CITRIX-AG', 'CITRIX-AAC-LOGINPAGE', 'CITRIX-AAC-LAS', - 'CITRIX-XD-DDC', 'ND6', 'CITRIX-WI-EXTENDED', 'DIAMETER', 'RADIUS_ACCOUNTING', 'STOREFRONT')] - [string]$Type = 'HTTP' - - [DscProperty(Mandatory)] - [ValidateRange(1, 20940000)] - [int]$Interval = 5 - - [DscProperty(Mandatory)] - [ValidateSet('SEC', 'MSEC', 'MIN')] - [string]$IntervalType = 'SEC' - - [DscProperty(Mandatory)] - [ValidateRange(1, 20939000)] - [int]$ResponseTimeout = 2 - - [DscProperty(Mandatory)] - [ValidateSet('SEC', 'MSEC', 'MIN')] - [string]$ResponseTimeoutType = 'SEC' - - [DscProperty(Mandatory)] - [ValidateRange(1, 20939000)] - [int]$Downtime = 30 + [string]$NetScalerFQDN [DscProperty(Mandatory)] - [ValidateSet('SEC', 'MSEC', 'MIN')] - [string]$DowntimeType = 'SEC' + [pscredential]$Credential - [DscProperty(Mandatory)] [DscProperty()] - [int]$DestinationPort - - [DscProperty(Mandatory)] - [ValidateRange(1, 127)] - [int]$Retries = 3 - - [DscProperty(Mandatory)] - [ValidateRange(0, 32)] - [int]$SuccessRetries = 1 + [ValidateSet('ADNS','ADNS_TCP','ANY','DHCPRA','DIAMETER','DNS','DNS_TCP','DTLS','FTP','HTTP','MSSQL', + 'MYSQL','NNTP','RADIUS','RDP','RPCSVR','RTSP','SIP_UDP','SNMP','SSL','SSL_BRIDGE','SSL_DIAMETER','SSL_TCP','TCP','TFTP','UDP')] + [Alias('Protocol')] + [string]$ServiceType = 'HTTP' [DscProperty()] - [string]$DestinationIP + [ValidateRange(0, 4094)] + [int]$TrafficDomainId = 0 [DscProperty()] - [ValidateRange(0, 20939000)] - [int]$Deviation + [ValidateSet('SERVER', 'FORWARD', 'TRANSPARENT', 'REVERSE')] + [string]$CacheType = 'SERVER' [DscProperty()] - [ValidateRange(0, 100)] - [int]$ResponseTimeoutThreshold + [ValidateSet('DISABLED', 'DNS', 'POLICY')] + [string]$AutoScale = 'DISABLED' [DscProperty()] - [ValidateRange(0, 32)] - [int]$AlertRetries + [ValidateSet('YES','NO')] + [string]$Cacheable = 'NO' [DscProperty()] - [ValidateRange(0, 32)] - [int]$FailureRetries + [ValidateSet('ENABLED', 'DISABLED')] + [string]$State = 'ENABLED' [DscProperty()] - [ValidateRange(1, 127)] - [string]$NetProfile + [ValidateSet('YES','NO')] + [string]$HealthMonitor = 'YES' [DscProperty()] - [ValidateSet('YES','NO')] - [string]$TOS = 'NO' + [ValidateSet('DISABLED', 'ENABLED')] + [string]$AppFlowLog = 'ENABLED' [DscProperty()] - [ValidateRange(1, 63)] - [int]$TOSID + [ValidateLength(0, 256)] + [string]$Comment = [string]::Empty [DscProperty()] - [ValidateSet('ENABLED', 'DISABLED')] - [string]$State = 'ENABLED' + [ValidateSet('ON', 'OFF')] + [string]$SureConnect = 'OFF' [DscProperty()] - [ValidateSet('YES','NO')] - [string]$Reverse = 'NO' + [ValidateSet('ON', 'OFF')] + [string]$SurgeProtection = 'OFF' [DscProperty()] [ValidateSet('YES','NO')] - [string]$Transparent = 'NO' + [string]$UseProxyPort = 'YES' [DscProperty()] - [ValidateSet('ENABLED', 'DISABLED')] - [string]$LRTM = 'DISABLED' + [ValidateSet('ENABLED','DISABLED')] + [string]$DownStateFlush = 'ENABLED' [DscProperty()] [ValidateSet('YES','NO')] - [string]$Secure = 'NO' + [string]$UseClientIP = "No" [DscProperty()] [ValidateSet('YES','NO')] - [string]$IPTunnel = 'NO' + [string]$ClientKeepAlive = 'NO' [DscProperty()] - [string]$ScriptName + [ValidateSet('YES','NO')] + [string]$TCPBuffering = 'NO' - [DscProperty()] - [string]$DispatcherIP + # [DscProperty()] + # [ValidateSet('YES','NO')] + # [string]$HTTPCompression = 'YES' [DscProperty()] - [int]$DispatcherPort + [ValidateSet('ENABLED','DISABLED')] + [string]$ClientIP = 'DISABLED' [DscProperty()] - [string]$ScriptArgs + [string]$ClientIPHeader [DscProperty()] - [System.Collections.Hashtable]$CustomProperty + [ValidateRange(0, 4294967287)] + [int]$MaxBandwidthKbps [DscProperty()] - [string]$ResponseCode + [ValidateRange(0, 65535)] + [int]$MonitorThreshold [DscProperty()] - [string]$HTTPRequest + [ValidateRange(0, 65535)] + [int]$MaxRequests [DscProperty()] - [string]$Send + [ValidateRange(0, 4294967294)] + [int]$MaxClients [DscProperty()] - [string]$Recv + [ValidateRange(0, 31536000)] + [int]$ClientIdleTimeout = 180 [DscProperty()] - [bool]$ParameterExport = $false - + [ValidateRange(0, 31536000)] + [int]$ServerIdleTimeout = 360 + Init() { try { Import-Module -Name Netscaler -Verbose:$false -Debug:$false @@ -601,6 +617,7 @@ class LBMonitor { } } + [void]Set() { $NSObject = $this.Get() try { @@ -608,317 +625,317 @@ class LBMonitor { } catch { throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" } - try { - switch ($this.Ensure) { - 'Present' { - # Does the record already exist? - if ($NSObject.Ensure -eq [ensure]::Present) { - - #Run tests and set any needed attributes to match desired configuration - if ($NSObject.monitorname -ne $this.Name) { - Write-Warning -Message "Setting Name cannot be changed to [$($this.Name)]. Object must be recreated." - } - if ($NSObject.type -ne $this.Type) { - Write-Warning -Message "Setting Type cannot be changed to [$($this.Type)]. Object must be recreated." - } - if ($NSObject.interval -ne $this.Interval) { - Write-Verbose -Message "Setting Interval [$($this.Interval)]" - Set-NSLBMonitor -Name $this.Name -Interval $this.Interval -Verbose:$false -ErrorAction SilentlyContinue - } - if ($NSObject.units3 -ne $this.IntervalType) { - Write-Verbose -Message "Setting Interval Type [$($this.IntervalType)]" - Set-NSLBMonitor -Name $this.Name -IntervalType $this.IntervalType -Verbose:$false -ErrorAction SilentlyContinue - } - if ($NSObject.resptimeout -ne $this.ResponseTimeout) { - Write-Verbose -Message "Setting Response Timeout was changed to [$($this.ResponseTimeout)]" - Set-NSLBMonitor -Name $this.Name -ResponseTimeout $this.ResponseTimeout -ResponseTimeoutType $this.ResponseTimeoutType -Verbose:$false -ErrorAction SilentlyContinue - } - if ($NSObject.destip -ne $this.DestinationIP) { - Write-Verbose -Message "Setting Destination IP was changed to [$($this.DestinationIP)]" - Set-NSLBMonitor -Name $this.Name -DestinationIP $this.DestinationIP -Verbose:$false -ErrorAction SilentlyContinue - } - if ($NSObject.downtime -ne $this.Downtime) { - Write-Verbose -Message "Setting Downtime was changed to [$($this.Downtime)]" - Set-NSLBMonitor -Name $this.Name -Downtime $this.Downtime -Verbose:$false -ErrorAction SilentlyContinue - } - if ($NSObject.units2 -ne $this.DowntimeType) { - Write-Verbose -Message "Setting Downtime Type was changed to [$($this.DowntimeType)]" - Set-NSLBMonitor -Name $this.Name -DowntimeType $this.DowntimeType -Verbose:$false -ErrorAction SilentlyContinue - } - if ($NSObject.retries -ne $this.Retries) { - Write-Verbose -Message "Setting Retries was changed to [$($this.Retries)]" - Set-NSLBMonitor -Name $this.Name -Retries $this.Retries -Verbose:$false -ErrorAction SilentlyContinue - } - if ($NSObject.successretries -ne $this.SuccessRetries) { - Write-Verbose -Message "Setting Success Retries was changed to [$($this.SuccessRetries)]" - Set-NSLBMonitor -Name $this.Name -SuccessRetries $this.SuccessRetries -Verbose:$false -ErrorAction SilentlyContinue - } - if ($NSObject.tos -ne $this.TOS) { - Write-Verbose -Message "Setting TOS was changed to [$($this.TOS)]" - Set-NSLBMonitor -Name $this.Name -TOS $this.TOS -Verbose:$false -ErrorAction SilentlyContinue - } - if ($NSObject.state -ne $this.State) { - Write-Verbose -Message "Setting State was changed to [$($this.State)]" - Set-NSLBMonitor -Name $this.Name -State $this.State -Verbose:$false -ErrorAction SilentlyContinue - } - if ($NSObject.reverse -ne $this.Reverse) { - Write-Verbose -Message "Setting Reverse was changed to [$($this.Reverse)]" - Set-NSLBMonitor -Name $this.Name -Reverse $this.Reverse -Verbose:$false -ErrorAction SilentlyContinue - } - if ($NSObject.transparent -ne $this.Transparent) { - Write-Verbose -Message "Setting Transparent was changed to [$($this.Transparent)]" - Set-NSLBMonitor -Name $this.Name -Transparent $this.Transparent -Verbose:$false -ErrorAction SilentlyContinue - } - if ($NSObject.lrtm -ne $this.LRTM) { - Write-Verbose -Message "Setting LRTM was changed to [$($this.LRTM)]" - Set-NSLBMonitor -Name $this.Name -LRTM $this.LRTM -Verbose:$false -ErrorAction SilentlyContinue - } - if ($NSObject.secure -ne $this.Secure) { - Write-Verbose -Message "Setting Secure was changed to [$($this.Secure)]" - Set-NSLBMonitor -Name $this.Name -Secure $this.Secure -Verbose:$false -ErrorAction SilentlyContinue - } - if ($NSObject.iptunnel -ne $this.IPTunnel) { - Write-Verbose -Message "Setting IPTunnel was changed to [$($this.IPTunnel)]" - Set-NSLBMonitor -Name $this.Name -IPTunnel $this.IPTunnel -Verbose:$false -ErrorAction SilentlyContinue - } - if ($NSObject.failureretries -ne $this.FailureRetries) { - Write-Verbose -Message "Setting Failure Retries was changed to [$($this.FailureRetries)]" - Set-NSLBMonitor -Name $this.Name -FailureRetries $this.FailureRetries -Verbose:$false -ErrorAction SilentlyContinue - } - if ($NSObject.destport -ne $this.DestinationPort) { - Write-Verbose -Message "Setting Destination Port was changed to [$($this.DestinationPort)]" - Set-NSLBMonitor -Name $this.Name -DestinationPort $this.DestinationPort -Verbose:$false -ErrorAction SilentlyContinue - } - if ($NSObject.respcode -ne $this.ResponseCode) { - Write-Verbose -Message "Setting Response Code was changed to [$($this.ResponseCode)]" - try { - Set-NSLBMonitor -Name $this.Name -ResponseCode $this.ResponseCode -Verbose:$false -ErrorAction SilentlyContinue - } catch { $null } - } - if ($NSObject.httprequest -ne $this.HTTPRequest) { - Write-Verbose -Message "Setting HTTP Request was changed to [$($this.HTTPRequest)]" - # Set-NSLBMonitor -Name $this.Name -HTTPRequest $this.HTTPRequest -Verbose:$false -ErrorAction SilentlyContinue - } - } else { - Write-Verbose -Message "Creating monitor [$($this.Name)]" - $params = @{ - name = $this.Name - type = $this.Type - interval = $this.Interval - intervaltype = $this.IntervalType - responseTimeoutType = $this.ResponseTimeoutType - downtime = $this.Downtime - downtimeType = $this.DowntimeType - retries = $this.Retries - responsetimeout = $this.ResponseTimeout - successretries = $this.SuccessRetries - failureRetries = $this.FailureRetries - state = $this.State - destinationport = $this.DestinationPort - destinationip = $this.DestinationIP - reverse = $this.Reverse - lrtm = $this.LRTM - transparent = $this.Transparent - tos = $this.TOS - secure = $this.Secure - } - if ($PSBoundParameters.ContainsKey('Transparent')) { - $params.Add('Transparent', $this.Transparent) - } - if ($PSBoundParameters.ContainsKey('LRTM')) { - $params.Add('LRTM', $this.LRTM) - } - if ($PSBoundParameters.ContainsKey('Secure')) { - $params.Add('Secure', $this.Secure) - } - if ($PSBoundParameters.ContainsKey('IPTunnel')) { - $params.Add('IPTunnel', $this.IPTunnel) - } - if ($PSBoundParameters.ContainsKey('TOS')) { - $params.Add('TOS', $this.TOS) - } - if ($PSBoundParameters.ContainsKey('Reverse')) { - $params.Add('Reverse', $this.Reverse) - } - if ($PSBoundParameters.ContainsKey('DestinationIP')) { - $params.Add('DestinationIP', $this.DestinationIP) - } - if ($PSBoundParameters.ContainsKey('Deviation')) { - $params.Add('Deviation', $this.Deviation) - } - if ($PSBoundParameters.ContainsKey('ResponseTimeoutThreshold')) { - $params.Add('ResponseTimeoutThreshold', $this.ResponseTimeoutThreshold) - } - if ($PSBoundParameters.ContainsKey('AlertRetries')) { - $params.Add('AlertRetries', $this.AlertRetries) - } - if ($PSBoundParameters.ContainsKey('FailureRetries')) { - $params.Add('FailureRetries', $this.FailureRetries) - } - if ($PSBoundParameters.ContainsKey('NetProfile')) { - $params.Add('NetProfile', $this.NetProfile) - } - if ($PSBoundParameters.ContainsKey('TOSID')) { - $params.Add('TOSID', $this.TOSID) - } - if ($PSBoundParameters.ContainsKey('ScriptName')) { - $params.Add('ScriptName', $this.ScriptName) - } - if ($PSBoundParameters.ContainsKey('DispatcherIP')) { - $params.Add('DispatcherIP', $this.DispatcherIP) - } - if ($PSBoundParameters.ContainsKey('ScriptArgs')) { - $params.Add('ScriptArgs', $this.ScriptArgs) - } - if ($PSBoundParameters.ContainsKey('CustomProperty')) { - ## Add each custom property to the $params Hashtable - foreach ($CustomProperty in $this.CustomProperty.Keys) { - $params.Add($CustomProperty.ToLower(), $CustomProperty[$CustomProperty]) - } - } - if ($PSBoundParameters.ContainsKey('ResponseCode')) { - $params.Add('ResponseCode', $this.ResponseCode) - } - if ($PSBoundParameters.ContainsKey('HTTPRequest')) { - $params.Add('HTTPRequest', $this.HTTPRequest) - } - if ($PSBoundParameters.ContainsKey('Send')) { - $params.Add('Send', $this.Send) - } - if ($PSBoundParameters.ContainsKey('Recv')) { - $params.Add('Recv', $this.Recv) - } - if ($PSBoundParameters.ContainsKey('DispatcherPort')) { - $params.Add('DispatcherPort', $this.DispatcherPort) - } - New-NSLBMonitor @params -ErrorAction SilentlyContinue - } - } 'Absent' { - try { - $params = @{ - name = $this.Name - type = $this.Type - } - Remove-NSLBMonitor @params -Confirm:$false -ErrorAction SilentlyContinue - Write-Verbose -Message "Removing Netscaler monitor: $($this.Name)" - } catch { - write-host "Monitor $this.Name was not found" - } - } - }# - } catch { - Write-Error 'There was a problem setting the resource' - Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" - Write-Error $_ - } - try { - Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue - } catch { - # Do nothing - } - } - - [bool]Test() { - $pass = $true - $t = $null - $t = $this.Init() - $NSObject = $this.Get() try { switch ($this.Ensure) { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { - Write-Verbose -Message "Monitor [$($this.Name)] exists" if ($NSObject.Name -ne $this.Name) { - Write-Verbose -Message "Monitor Name does not match [$($NSObject.monitorname) <> $($this.Name)]" - $pass = $false + Write-Warning -Message "Setting Name cannot be changed to [$($this.Name)], must be recreated" } - if ($NSObject.DestinationIP -ne $this.DestinationIP) { - Write-Verbose -Message "Monitor Destination IP does not match [$($NSObject.DestinationIP) <> $($this.DestinationIP)]" - $pass = $false + if ($NSObject.ServiceType -ne $this.ServiceType) { + Write-Warning -Message "Setting Service Type cannot be changed to [$($this.ServiceType)], must be recreated" } - if ($NSObject.Interval -ne $this.Interval) { - Write-Verbose -Message "Monitor Interval does not match [$($NSObject.interval) <> $($this.Interval)]" - $pass = $false + if ($NSObject.TrafficDomainId -ne $this.TrafficDomainId) { + Write-Warning -Message "Setting Traffic Domain cannot be changed to [$($this.TrafficDomainId)]" } - if ($NSObject.IntervalType -ne $this.IntervalType) { - Write-Verbose -Message "Monitor Interval Type does not match [$($NSObject.IntervalType) <> $($this.IntervalType)]" - $pass = $false + if ($NSObject.CacheType -ne $this.CacheType) { + Write-Warning -Message "Setting Cache Type cannot be changed to[$($this.CacheType)]" } - if ($NSObject.ResponseTimeout -ne $this.ResponseTimeout) { - Write-Verbose -Message "Monitor Response Timeout does not match [$($NSObject.ResponseTimeout) <> $($this.ResponseTimeout)]" - $pass = $false + if ($NSObject.AutoScale -ne $this.AutoScale) { + Write-Verbose -Message "Setting Autoscale [$($this.AutoScale)]" + Set-NSLBServiceGroup -Name $this.Name -AutoScale $this.AutoScale -Force -Verbose:$false } - if ($NSObject.ResponseTimeoutType -ne $this.ResponseTimeoutType) { - Write-Verbose -Message "Monitor Response Timeout Type does not match [$($NSObject.ResponseTimeoutType) <> $($this.ResponseTimeoutType)]" - $pass = $false + if ($NSObject.Cacheable -ne $this.Cacheable) { + Write-Verbose -Message "Setting Cacheable [$($this.Cacheable)]" + Set-NSLBServiceGroup -Name $this.Name -Cacheable $this.Cacheable -Force -Verbose:$false } - if ($NSObject.Downtime -ne $this.Downtime) { - Write-Verbose -Message "Monitor Downtime does not match [$($NSObject.Downtime) <> $($this.Downtime)]" - $pass = $false + if ($NSObject.State -ne $this.State) { + Write-Verbose -Message "Setting State [$($this.State)]" + Set-NSLBServiceGroup -Name $this.Name -State $this.State -Force -Verbose:$false } - if ($NSObject.DowntimeType -ne $this.DowntimeType) { - Write-Verbose -Message "Monitor Downtime Type does not match [$($NSObject.DowntimeType) <> $($this.DowntimeType)]" - $pass = $false + if ($NSObject.HealthMonitor -ne $this.HealthMonitor) { + Write-Verbose -Message "Setting Health Monitor [$($this.HealthMonitor)]" + Set-NSLBServiceGroup -Name $this.Name -HealthMonitor $this.HealthMonitor -Force -Verbose:$false } - if ($NSObject.Retries -ne $this.Retries) { - Write-Verbose -Message "Monitor Retries does not match [$($NSObject.Retries) <> $($this.Retries)]" - $pass = $false + if ($NSObject.AppFlowLog -ne $this.AppFlowLog) { + Write-Verbose -Message "Setting AppFlowLog [$($this.AppFlowLog)]" + Set-NSLBServiceGroup -Name $this.Name -AppFlowLog $this.AppFlowLog -Force -Verbose:$false } - if ($NSObject.SuccessRetries -ne $this.SuccessRetries) { - Write-Verbose -Message "Monitor Success Retries does not match [$($NSObject.SuccessRetries) <> $($this.SuccessRetries)]" - $pass = $false + if ($NSObject.Comment -ne $this.Comment) { + Write-Verbose -Message "Setting Comment [$($this.Comment)]" + Set-NSLBServiceGroup -Name $this.Name -Comment $this.Comment -Force -Verbose:$false } - if ($NSObject.TOS -ne $this.TOS) { - Write-Verbose -Message "Monitor TOS setting not match [$($NSObject.TOS) <> $($this.TOS)]" - $pass = $false + if ($NSObject.SureConnect -ne $this.SureConnect) { + Write-Verbose -Message "Setting SureConnect [$($this.SureConnect)]" + Set-NSLBServiceGroup -Name $this.Name -SureConnect $this.SureConnect -Force -Verbose:$false } - if ($NSObject.State -ne $this.State) { - Write-Verbose -Message "Monitor State does not match [$($NSObject.State) <> $($this.State)]" - $pass = $false + if ($NSObject.SurgeProtection -ne $this.SurgeProtection) { + Write-Verbose -Message "Setting Surge Protection [$($this.SurgeProtection)]" + Set-NSLBServiceGroup -Name $this.Name -SurgeProtection $this.SurgeProtection -Force -Verbose:$false } - if ($NSObject.Reverse -ne $this.Reverse) { - Write-Verbose -Message "Monitor Reverse setting does not match [$($NSObject.Reverse) <> $($this.Reverse)]" - $pass = $false + if ($NSObject.UseProxyPort -ne $this.UseProxyPort) { + Write-Verbose -Message "Setting Use Proxy Port [$($this.UseProxyPort)]" + Set-NSLBServiceGroup -Name $this.Name -UseProxyPort $this.UseProxyPort -Force -Verbose:$false } - if ($NSObject.Transparent -ne $this.Transparent) { - Write-Verbose -Message "Monitor Transparent setting does not match [$($NSObject.Transparent) <> $($this.Transparent)]" - $pass = $false + if ($NSObject.DownStateFlush -ne $this.DownStateFlush) { + Write-Verbose -Message "Setting DownState Flush [$($this.DownStateFlush)]" + Set-NSLBServiceGroup -Name $this.Name -DownStateFlush $this.DownStateFlush -Force -Verbose:$false } - if ($NSObject.LRTM -ne $this.LRTM) { - Write-Verbose -Message "Monitor LRTM setting does not match [$($NSObject.LRTM) <> $($this.LRTM)]" - $pass = $false + if ($NSObject.UseClientIP -ne $this.UseClientIP) { + Write-Verbose -Message "Setting Use Client IP [$($this.UseClientIP)]" + Set-NSLBServiceGroup -Name $this.Name -UseClientIP $this.UseClientIP -Force -Verbose:$false } - if ($NSObject.Secure -ne $this.Secure) { - Write-Verbose -Message "Monitor Secure setting does not match [$($NSObject.Secure) <> $($this.Secure)]" - $pass = $false + if ($NSObject.ClientKeepAlive -ne $this.ClientKeepAlive) { + Write-Verbose -Message "Setting Client Keep Alive [$($this.ClientKeepAlive)]" + Set-NSLBServiceGroup -Name $this.Name -ClientKeepAlive $this.ClientKeepAlive -Force -Verbose:$false } - if ($NSObject.IPTunnel -ne $this.IPTunnel) { - Write-Verbose -Message "Monitor IPTunnel setting does not match [$($NSObject.IPTunnel) <> $($this.IPTunnel)]" - $pass = $false + if ($NSObject.TCPBuffering -ne $this.TCPBuffering) { + Write-Verbose -Message "Setting TCP Buffering [$($this.TCPBuffering)]" + Set-NSLBServiceGroup -Name $this.Name -TCPBuffering $this.TCPBuffering -Force -Verbose:$false } - if ($NSObject.FailureRetries -ne $this.FailureRetries) { - Write-Verbose -Message "Monitor Failure Retries does not match [$($NSObject.FailureRetries) <> $($this.FailureRetries)]" - $pass = $false + # if ($NSObject.HTTPCompression -ne $this.HTTPCompression) { + # Write-Verbose -Message "Setting HTTP Compression [$($this.HTTPCompression)]" + # Set-NSLBServiceGroup -Name $this.Name -HTTPCompression $this.HTTPCompression -Force -Verbose:$false + # } + if ($NSObject.ClientIP -ne $this.ClientIP) { + Write-Verbose -Message "Setting Client IP [$($this.ClientIP)]" + Set-NSLBServiceGroup -Name $this.Name -ClientIP $this.ClientIP -Force -Verbose:$false } - if ($NSObject.DestinationPort -ne $this.DestinationPort) { - Write-Verbose -Message "Monitor Destination Port does not match [$($NSObject.DestinationPort) <> $($this.DestinationPort)]" - $pass = $false + if ($NSObject.MaxBandwidthKbps -ne $this.MaxBandwidthKbps) { + Write-Verbose -Message "Setting Maximum Bandwidth (Kbps) [$($this.MaxBandwidthKbps)]" + Set-NSLBServiceGroup -Name $this.Name -MaxBandwidthKbps $this.MaxBandwidthKbps -Force -Verbose:$false } - if ($NSObject.ResponseCode -ne $this.ResponseCode) { - Write-Verbose -Message "Monitor Response Code does not match [$($NSObject.ResponseCode) <> $($this.ResponseCode)]" - $pass = $false + if ($NSObject.MonitorThreshold -ne $this.MonitorThreshold) { + Write-Verbose -Message "Setting Monitor Threshold [$($this.MonitorThreshold)]" + Set-NSLBServiceGroup -Name $this.Name -MonitorThreshold $this.MonitorThreshold -Force -Verbose:$false } - if ($NSObject.HTTPRequest -ne $this.HTTPRequest) { - Write-Verbose -Message "Monitor HTTPRequest setting does not match [$($NSObject.HTTPRequest) <> $($this.HTTPRequest)]" - $pass = $false - } - } else { - Write-Verbose -Message "Monitor [$($this.Name)] was not found" - $pass = $false - } - } 'Absent' { - if ($this.Ensure -ne $NSObject.Ensure) { - $pass = $false + if ($NSObject.MaxRequests -ne $this.MaxRequests) { + Write-Verbose -Message "Setting Maximum Client Requests [$($this.MaxRequests)]" + Set-NSLBServiceGroup -Name $this.Name -MaxRequests $this.MaxRequests -Force -Verbose:$false + } + if ($NSObject.MaxClients -ne $this.MaxClients) { + Write-Verbose -Message "Setting Maximum Client connections [$($this.MaxClients)]" + Set-NSLBServiceGroup -Name $this.Name -MaxClients $this.MaxClients -Force -Verbose:$false + } + if ($NSObject.ClientIdleTimeout -ne $this.ClientIdleTimeout) { + Write-Verbose -Message "Setting Client Idle Timeout [$($this.ClientIdleTimeout)]" + Set-NSLBServiceGroup -Name $this.Name -ClientIdleTimeout $this.ClientIdleTimeout -Force -Verbose:$false + } + if ($NSObject.ServerIdleTimeout -ne $this.ServerIdleTimeout) { + Write-Verbose -Message "Setting Server Idle Timeout [$($this.ServerIdleTimeout)]" + Set-NSLBServiceGroup -Name $this.Name -ServerIdleTimeout $this.ServerIdleTimeout -Force -Verbose:$false + } + } else { + Write-Verbose -Message "Creating Service Group [$($this.Name)]" + $params = @{ + name = $this.Name + servicetype = $this.ServiceType + state = $this.State + comment = $this.Comment + } + if ($PSBoundParameters.ContainsKey('TrafficDomainId')) { + $params.Add('TrafficDomainId', $this.TrafficDomainId) + } + if ($PSBoundParameters.ContainsKey('MaxClients')) { + $params.Add('MaxClients', $this.MaxClients) + } + if ($PSBoundParameters.ContainsKey('CacheType')) { + $params.Add('CacheType', $this.CacheType) + } + if ($PSBoundParameters.ContainsKey('AutoScale')) { + $params.Add('AutoScale', $this.AutoScale) + } + if ($PSBoundParameters.ContainsKey('Cacheable')) { + $params.Add('Cacheable', $this.Cacheable) + } + if ($PSBoundParameters.ContainsKey('HealthMonitor')) { + $params.Add('HealthMonitor', $this.HealthMonitor) + } + if ($PSBoundParameters.ContainsKey('AppFlowLog')) { + $params.Add('AppFlowLog', $this.AppFlowLog) + } + if ($PSBoundParameters.ContainsKey('SureConnect')) { + $params.Add('SureConnect', $this.SureConnect) + } + if ($PSBoundParameters.ContainsKey('SurgeProtection')) { + $params.Add('SurgeProtection', $this.SurgeProtection) + } + if ($PSBoundParameters.ContainsKey('UseProxyPort')) { + $params.Add('UseProxyPort', $this.UseProxyPort) + } + if ($PSBoundParameters.ContainsKey('DownStateFlush')) { + $params.Add('DownStateFlush', $this.DownStateFlush) + } + if ($PSBoundParameters.ContainsKey('UseClientIP')) { + $params.Add('UseClientIP', $this.UseClientIP) + } + if ($PSBoundParameters.ContainsKey('ClientKeepAlive')) { + $params.Add('ClientKeepAlive', $this.ClientKeepAlive) + } + if ($PSBoundParameters.ContainsKey('TCPBuffering')) { + $params.Add('TCPBuffering', $this.TCPBuffering) + } + # if ($PSBoundParameters.ContainsKey('HTTPCompression')) { + # $params.Add('HTTPCompression', $this.HTTPCompression) + # } + if ($PSBoundParameters.ContainsKey('ClientIP')) { + $params.Add('ClientIP', $this.ClientIP) + } + if ($PSBoundParameters.ContainsKey('MaxBandwidthKbps')) { + $params.Add('MaxBandwidthKbps', $this.MaxBandwidthKbps) + } + if ($PSBoundParameters.ContainsKey('DownStateFlush')) { + $params.Add('DownStateFlush', $this.DownStateFlush) + } + if ($PSBoundParameters.ContainsKey('MaxRequests')) { + $params.Add('MaxRequests', $this.MaxRequests) + } + if ($PSBoundParameters.ContainsKey('ClientIdleTimeout')) { + $params.Add('ClientIdleTimeout', $this.ClientIdleTimeout) + } + if ($PSBoundParameters.ContainsKey('ServerIdleTimeout')) { + $params.Add('ServerIdleTimeout', $this.ServerIdleTimeout) + } + New-NSLBServiceGroup @params -ErrorAction SilentlyContinue + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSLBServiceGroup -Name $NSObject.Name -Confirm:$false -ErrorAction SilentlyContinue + Write-Verbose -Message "Removing Netscaler monitor: $($this.Name)" + } + } + } + Save-NSConfig + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + if ($NSObject.Name -ne $this.Name) { + Write-Verbose -Message "Service Group Name doest not match [$($NSObject.Name) <> $($this.Name)]" + $pass = $false + } + if ($NSObject.ServiceType -ne $this.ServiceType) { + Write-Verbose -Message "Service Type does not match [$($NSObject.ServiceType) <> $($this.ServiceType)]" + $pass = $false + } + if ($NSObject.TrafficDomainId -ne $this.TrafficDomainId) { + Write-Verbose -Message "Traffic Domain does not match [$($NSObject.TrafficDomainId) <> $($this.TrafficDomainId)]" + $pass = $false + } + if ($NSObject.CacheType -ne $this.CacheType) { + Write-Verbose -Message "Cache Type does not match [$($NSObject.CacheType) <> $($this.CacheType)]" + $pass = $false + } + if ($NSObject.Cacheable -ne $this.Cacheable) { + Write-Verbose -Message "Cacheable setting does not match [$($NSObject.Cacheable) <> $($this.Cacheable)]" + $pass = $false + } + if ($NSObject.State -ne $this.State) { + Write-Verbose -Message "State does not match [$($NSObject.State) <> $($this.State)]" + $pass = $false + } + if ($NSObject.HealthMonitor -ne $this.HealthMonitor) { + Write-Verbose -Message "Health Monitor does not match [$($NSObject.HealthMonitor) <> $($this.HealthMonitor)]" + $pass = $false + } + if ($NSObject.AppFlowLog -ne $this.AppFlowLog) { + Write-Verbose -Message "AppFlowLog does not match [$($NSObject.AppFlowLog) <> $($this.AppFlowLog)]" + $pass = $false + } + if ($NSObject.Comment -ne $this.Comment) { + Write-Verbose -Message "Comment does not match [$($NSObject.Comment) <> $($this.Comment)]" + $pass = $false + } + if ($NSObject.SurgeProtection -ne $this.SurgeProtection) { + Write-Verbose -Message "Surge Protection does not match [$($NSObject.SurgeProtection) <> $($this.SurgeProtection)]" + $pass = $false + } + if ($NSObject.SureConnect -ne $this.SureConnect) { + Write-Verbose -Message "Sure Connect does not match [$($NSObject.SureConnect) <> $($this.SureConnect)]" + $pass = $false + } + if ($NSObject.UseProxyPort -ne $this.UseProxyPort) { + Write-Verbose -Message "Use Proxy Port does not match [$($NSObject.UseProxyPort) <> $($this.UseProxyPort)]" + $pass = $false + } + if ($NSObject.DownStateFlush -ne $this.DownStateFlush) { + Write-Verbose -Message "DownState Flush does not match [$($NSObject.DownStateFlush) <> $($this.DownStateFlush)]" + $pass = $false + } + if ($NSObject.UseClientIP -ne $this.UseClientIP) { + Write-Verbose -Message "Use Client IP does not match [$($NSObject.UseClientIP) <> $($this.UseClientIP)]" + $pass = $false + } + if ($NSObject.ClientKeepAlive -ne $this.ClientKeepAlive) { + Write-Verbose -Message "Client Keep Alive does not match [$($NSObject.ClientKeepAlive) <> $($this.ClientKeepAlive)]" + $pass = $false + } + if ($NSObject.TCPBuffering -ne $this.TCPBuffering) { + Write-Verbose -Message "TCP Buffering does not match [$($NSObject.TCPBuffering) <> $($this.TCPBuffering)]" + $pass = $false + } + # if ($NSObject.HTTPCompression -ne $this.HTTPCompression) { + # Write-Verbose -Message "HTTP Compression does not match [$($NSObject.HTTPCompression) <> $($this.HTTPCompression)]" + # $pass = $false + # } + if ($NSObject.ClientIP -ne $this.ClientIP) { + Write-Verbose -Message "Client IP does not match [$($NSObject.ClientIP) <> $($this.ClientIP)]" + $pass = $false + } + # if ($NSObject.ClientIPHeader -ne $this.ClientIPHeader) { + # Write-Verbose -Message "ClientIP Header does not match [$($this.ClientIPHeader)]" + # $pass = $false + # } + if ($NSObject.MaxBandwidthKbps -ne $this.MaxBandwidthKbps) { + Write-Verbose -Message "Maximum Banddwith (Kbps) does not match [$($NSObject.MaxBandwidthKbps) <> $($this.MaxBandwidthKbps)]" + $pass = $false + } + if ($NSObject.MonitorThreshold -ne $this.MonitorThreshold) { + Write-Verbose -Message "Monitor Threshold does not match [$($NSObject.MonitorThreshold) <> $($this.MonitorThreshold)]" + $pass = $false + } + if ($NSObject.MaxRequests -ne $this.MaxRequests) { + Write-Verbose -Message "Maximum Client Requests does not match [$($NSObject.MaxRequests) <> $($this.MaxRequests)]" + $pass = $false + } + if ($NSObject.MaxClients -ne $this.MaxClients) { + Write-Verbose -Message "Maximum Client connections does not match [$($NSObject.MaxClients) <> $($this.MaxClients)]" + $pass = $false + } + if ($NSObject.ClientIdleTimeout -ne $this.ClientIdleTimeout) { + Write-Verbose -Message "Client Idle Timeout does not match [$($NSObject.ClientIdleTimeout) <> $($this.ClientIdleTimeout)]" + $pass = $false + } + if ($NSObject.ServerIdleTimeout -ne $this.ServerIdleTimeout) { + Write-Verbose -Message "Server Idle Timeout does not match [$($NSObject.ServerIdleTimeout) <> $($this.ServerIdleTimeout)]" + $pass = $false + } + } else { + Write-Verbose -Message "Resource [$($this.Name)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false } } } @@ -932,64 +949,72 @@ class LBMonitor { } catch { # Do nothing } - return $pass + return $pass } - [LBMonitor]Get() { + [LBServiceGroup]Get() { $t = $null $t = $this.Init() try { - $s = Get-NSLBMonitor -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + $s = Get-NSLBServiceGroup -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue } catch { $s = $null } - $obj = [LBMonitor]::new() + $obj = [LBServiceGroup]::new() $obj.Name = $this.Name - $obj.Type = $this.Type - $obj.Interval = $this.Interval - $obj.IntervalType = $this.IntervalType - $obj.DestinationIP = $this.DestinationIP - $obj.ResponseTimeout = $this.ResponseTimeout - $obj.ResponseTimeoutType = $this.ResponseTimeoutType - $obj.Downtime = $this.Downtime - $obj.DowntimeType = $this.DowntimeType - $obj.Retries = $this.Retries - $obj.SuccessRetries = $this.SuccessRetries - $obj.TOS = $this.TOS + $obj.ServiceType = $this.ServiceType + $obj.TrafficDomainID = $this.TrafficDomainID + $obj.CacheType = $this.CacheType + $obj.MaxClients = $this.MaxClients + $obj.MaxRequests = $this.MaxRequests + $obj.Cacheable = $this.Cacheable + $obj.ClientIP = $this.ClientIP + $obj.UseClientIP = $this.UseClientIP + $obj.UseProxyPort = $this.UseProxyPort + $obj.SureConnect = $this.SureConnect + $obj.SurgeProtection = $this.SurgeProtection + $obj.ClientKeepAlive = $this.ClientKeepAlive + $obj.ClientIdleTimeout = $this.ClientIdleTimeout + $obj.ServerIdleTimeout = $this.ServerIdleTimeout + $obj.TCPBuffering = $this.TCPBuffering + # $obj.HTTPCompression = $this.HTTPCompression + $obj.MaxBandwidthKbps = $this.MaxBandwidthKbps $obj.State = $this.State - $obj.Reverse = $this.Reverse - $obj.Transparent = $this.Transparent - $obj.LRTM = $this.LRTM - $obj.Secure = $this.Secure - $obj.IPTunnel = $this.IPTunnel - $obj.FailureRetries = $this.FailureRetries - $obj.DestinationPort = $this.DestinationPort - $obj.HTTPRequest = $this.HTTPRequest + $obj.DownStateFlush = $this.DownStateFlush + $obj.HealthMonitor = $this.HealthMonitor + $obj.AppFlowLog = $this.AppFlowLog + $obj.Comment = $this.Comment + # $obj.ClientIPHeader = $this.ClientIPHeader + $obj.MonitorThreshold = $this.MonitorThreshold if ($s) { $obj.Ensure = [ensure]::Present - $obj.Name = $s.monitorname - $obj.Type = $s.type - $obj.Interval = $s.interval - $obj.IntervalType = $s.units3 - $obj.DestinationIP = $s.destip - $obj.ResponseTimeout = $s.resptimeout - $obj.ResponseTimeoutType = $s.units4 - $obj.Downtime = $s.downtime - $obj.DowntimeType = $s.units2 - $obj.Retries = $s.retries - $obj.SuccessRetries = $s.successRetries - $obj.TOS = $s.tos - $obj.State = $s.state - $obj.Reverse = $s.reverse - $obj.Transparent = $s.transparent - $obj.LRTM = $s.lrtm - $obj.Secure = $s.secure - $obj.IPTunnel = $s.iptunnel - $obj.FailureRetries = $s.failureretries - $obj.DestinationPort = $s.destport - $obj.HTTPRequest = $s.httprequest + $obj.Name = $s.servicegroupname + $obj.ServiceType = $s.servicetype + $obj.TrafficDomainID = $s.td + $obj.CacheType = $s.cachetype + $obj.MaxClients = $s.maxclient + $obj.MaxRequests = $s.maxreq + $obj.Cacheable = $s.cacheable + $obj.ClientIP = $s.cip + $obj.UseClientIP = $s.usip + $obj.UseProxyPort = $s.useproxyport + $obj.SureConnect = $s.sc + $obj.SurgeProtection = $s.sp + $obj.ClientKeepAlive = $s.cka + $obj.ClientIdleTimeout = $s.clttimeout + $obj.ServerIdleTimeout = $s.svrtimeout + $obj.TCPBuffering = $s.tcpb + # $obj.HTTPCompression = $s.cmp + $obj.MaxBandwidthKbps = $s.maxbandwidth + $obj.State = $s.state.toUpper() + $obj.DownStateFlush = $s.downstateflush + $obj.HealthMonitor = $s.healthmonitor + $obj.AppFlowLog = $s.appflowlog + $obj.Comment = $s.comment + # $obj.ClientIPHeader = $s.cipheader + $obj.MonitorThreshold = $s.monthreshold } else { $obj.Ensure = [ensure]::Absent } @@ -999,7 +1024,7 @@ class LBMonitor { } [DscResource()] -class LBServiceGroup { +class LBMonitor { [DscProperty(Key)] [string]$Name @@ -1007,111 +1032,138 @@ class LBServiceGroup { [Ensure]$Ensure = [Ensure]::Present [DscProperty(Mandatory)] - [string]$NetScalerFQDN - + [string]$NetScalerFQDN + [DscProperty(Mandatory)] [pscredential]$Credential + [DscProperty(Mandatory)] + [ValidateSet('PING', 'TCP', 'HTTP', 'TCP-ECV', 'HTTP-ECV', 'UDP-ECV', 'DNS', 'FTP', 'LDNS-PING', + 'LDNS-TCP', 'RADIUS', 'USER', 'HTTP-INLINE', 'SIP-UDP', 'LOAD', 'FTP-EXTENDED', 'SMTP', 'SNMP', + 'NNTP', 'MYSQL', 'MYSQL-ECV', 'MSSQL-ECV', 'ORACLE-ECV', 'LDAP', 'POP3', 'CITRIX-XML-SERVICE', + 'CITRIX-WEB-INTERFACE', 'DNS-TCP', 'RTSP', 'ARP', 'CITRIX-AG', 'CITRIX-AAC-LOGINPAGE', 'CITRIX-AAC-LAS', + 'CITRIX-XD-DDC', 'ND6', 'CITRIX-WI-EXTENDED', 'DIAMETER', 'RADIUS_ACCOUNTING', 'STOREFRONT')] + [string]$Type = 'HTTP' + + [DscProperty(Mandatory)] + [ValidateRange(1, 20940000)] + [int]$Interval = 5 + + [DscProperty(Mandatory)] + [ValidateSet('SEC', 'MSEC', 'MIN')] + [string]$IntervalType = 'SEC' + + [DscProperty(Mandatory)] + [ValidateRange(1, 20939000)] + [int]$ResponseTimeout = 2 + + [DscProperty(Mandatory)] + [ValidateSet('SEC', 'MSEC', 'MIN')] + [string]$ResponseTimeoutType = 'SEC' + + [DscProperty(Mandatory)] + [ValidateRange(1, 20939000)] + [int]$Downtime = 30 + + [DscProperty(Mandatory)] + [ValidateSet('SEC', 'MSEC', 'MIN')] + [string]$DowntimeType = 'SEC' + [DscProperty()] - [ValidateSet('ADNS','ADNS_TCP','ANY','DHCPRA','DIAMETER','DNS','DNS_TCP','DTLS','FTP','HTTP','MSSQL', - 'MYSQL','NNTP','RADIUS','RDP','RPCSVR','RTSP','SIP_UDP','SNMP','SSL','SSL_BRIDGE','SSL_DIAMETER','SSL_TCP','TCP','TFTP','UDP')] - [Alias('Protocol')] - [string]$ServiceType = 'HTTP' + [int]$DestinationPort + + [DscProperty(Mandatory)] + [ValidateRange(1, 127)] + [int]$Retries = 3 + + [DscProperty(Mandatory)] + [ValidateRange(0, 32)] + [int]$SuccessRetries = 1 [DscProperty()] - [ValidateRange(0, 4094)] - [int]$TrafficDomainId = 0 + [string]$DestinationIP [DscProperty()] - [ValidateSet('SERVER', 'FORWARD', 'TRANSPARENT', 'REVERSE')] - [string]$CacheType = 'SERVER' + [ValidateRange(0, 20939000)] + [int]$Deviation [DscProperty()] - [ValidateSet('DISABLED', 'DNS', 'POLICY')] - [string]$AutoScale = 'DISABLED' + [ValidateRange(0, 100)] + [int]$ResponseTimeoutThreshold [DscProperty()] - [ValidateSet('YES','NO')] - [string]$Cacheable = 'NO' - + [ValidateRange(0, 32)] + [int]$AlertRetries + [DscProperty()] - [ValidateSet('ENABLED', 'DISABLED')] - [string]$State = 'ENABLED' + [ValidateRange(0, 32)] + [int]$FailureRetries [DscProperty()] - [ValidateSet('YES','NO')] - [string]$HealthMonitor = 'YES' + [ValidateRange(1, 127)] + [string]$NetProfile [DscProperty()] - [ValidateSet('DISABLED', 'ENABLED')] - [string]$AppFlowLog = 'ENABLED' + [ValidateSet('YES','NO')] + [string]$TOS = 'NO' [DscProperty()] - [ValidateLength(0, 256)] - [string]$Comment = [string]::Empty + [ValidateRange(1, 63)] + [int]$TOSID [DscProperty()] - [ValidateSet('ON', 'OFF')] - [string]$SureConnect = 'OFF' + [ValidateSet('ENABLED', 'DISABLED')] + [string]$State = 'ENABLED' [DscProperty()] - [ValidateSet('ON', 'OFF')] - [string]$SurgeProtection = 'OFF' + [ValidateSet('YES','NO')] + [string]$Reverse = 'NO' [DscProperty()] [ValidateSet('YES','NO')] - [string]$UseProxyPort = 'YES' + [string]$Transparent = 'NO' [DscProperty()] - [ValidateSet('ENABLED','DISABLED')] - [string]$DownStateFlush = 'ENABLED' + [ValidateSet('ENABLED', 'DISABLED')] + [string]$LRTM = 'DISABLED' [DscProperty()] [ValidateSet('YES','NO')] - [string]$UseClientIP = "No" + [string]$Secure = 'NO' [DscProperty()] [ValidateSet('YES','NO')] - [string]$ClientKeepAlive = 'NO' + [string]$IPTunnel = 'NO' [DscProperty()] - [ValidateSet('YES','NO')] - [string]$TCPBuffering = 'NO' + [string]$ScriptName [DscProperty()] - [ValidateSet('YES','NO')] - [string]$HTTPCompression = 'YES' + [string]$DispatcherIP [DscProperty()] - [ValidateSet('ENABLED','DISABLED')] - [string]$ClientIP = 'DISABLED' + [int]$DispatcherPort [DscProperty()] - [string]$ClientIPHeader + [string]$ScriptArgs [DscProperty()] - [ValidateRange(0, 4294967287)] - [int]$MaxBandwidthKbps + [System.Collections.Hashtable]$CustomProperty [DscProperty()] - [ValidateRange(0, 65535)] - [int]$MonitorThreshold + [string]$ResponseCode [DscProperty()] - [ValidateRange(0, 65535)] - [int]$MaxRequests + [string]$HTTPRequest [DscProperty()] - [ValidateRange(0, 4294967294)] - [int]$MaxClients + [string]$Send [DscProperty()] - [ValidateRange(0, 31536000)] - [int]$ClientIdleTimeout = 180 + [string]$Recv [DscProperty()] - [ValidateRange(0, 31536000)] - [int]$ServerIdleTimeout = 360 + [bool]$ParameterExport = $false Init() { try { @@ -1122,7 +1174,6 @@ class LBServiceGroup { } } - [void]Set() { $NSObject = $this.Get() try { @@ -1132,185 +1183,1390 @@ class LBServiceGroup { } try { switch ($this.Ensure) { - 'Present' { - if ($this.Ensure -eq $NSObject.Ensure) { - if ($NSObject.Name -ne $this.Name) { - Write-Warning -Message "Setting Name cannot be changed to [$($this.Name)], must be recreated" - } - if ($NSObject.ServiceType -ne $this.ServiceType) { - Write-Warning -Message "Setting Service Type cannot be changed to [$($this.ServiceType)], must be recreated" - } - if ($NSObject.TrafficDomainId -ne $this.TrafficDomainId) { - Write-Warning -Message "Setting Traffic Domain cannot be changed to [$($this.TrafficDomainId)]" - } - if ($NSObject.CacheType -ne $this.CacheType) { - Write-Warning -Message "Setting Cache Type cannot be changed to[$($this.CacheType)]" - } - if ($NSObject.AutoScale -ne $this.AutoScale) { - Write-Verbose -Message "Setting Autoscale [$($this.AutoScale)]" - Set-NSLBServiceGroup -Name $this.Name -AutoScale $this.AutoScale -Force -Verbose:$false - } - if ($NSObject.Cacheable -ne $this.Cacheable) { - Write-Verbose -Message "Setting Cacheable [$($this.Cacheable)]" - Set-NSLBServiceGroup -Name $this.Name -Cacheable $this.Cacheable -Force -Verbose:$false - } - if ($NSObject.State -ne $this.State) { - Write-Verbose -Message "Setting State [$($this.State)]" - Set-NSLBServiceGroup -Name $this.Name -State $this.State -Force -Verbose:$false - } - if ($NSObject.HealthMonitor -ne $this.HealthMonitor) { - Write-Verbose -Message "Setting Health Monitor [$($this.HealthMonitor)]" - Set-NSLBServiceGroup -Name $this.Name -HealthMonitor $this.HealthMonitor -Force -Verbose:$false - } - if ($NSObject.AppFlowLog -ne $this.AppFlowLog) { - Write-Verbose -Message "Setting AppFlowLog [$($this.AppFlowLog)]" - Set-NSLBServiceGroup -Name $this.Name -AppFlowLog $this.AppFlowLog -Force -Verbose:$false - } - if ($NSObject.Comment -ne $this.Comment) { - Write-Verbose -Message "Setting Comment [$($this.Comment)]" - Set-NSLBServiceGroup -Name $this.Name -Comment $this.Comment -Force -Verbose:$false - } - if ($NSObject.SureConnect -ne $this.SureConnect) { - Write-Verbose -Message "Setting SureConnect [$($this.SureConnect)]" - Set-NSLBServiceGroup -Name $this.Name -SureConnect $this.SureConnect -Force -Verbose:$false - } - if ($NSObject.SurgeProtection -ne $this.SurgeProtection) { - Write-Verbose -Message "Setting Surge Protection [$($this.SurgeProtection)]" - Set-NSLBServiceGroup -Name $this.Name -SurgeProtection $this.SurgeProtection -Force -Verbose:$false - } - if ($NSObject.UseProxyPort -ne $this.UseProxyPort) { - Write-Verbose -Message "Setting Use Proxy Port [$($this.UseProxyPort)]" - Set-NSLBServiceGroup -Name $this.Name -UseProxyPort $this.UseProxyPort -Force -Verbose:$false - } - if ($NSObject.DownStateFlush -ne $this.DownStateFlush) { - Write-Verbose -Message "Setting DownState Flush [$($this.DownStateFlush)]" - Set-NSLBServiceGroup -Name $this.Name -DownStateFlush $this.DownStateFlush -Force -Verbose:$false - } - if ($NSObject.UseClientIP -ne $this.UseClientIP) { - Write-Verbose -Message "Setting Use Client IP [$($this.UseClientIP)]" - Set-NSLBServiceGroup -Name $this.Name -UseClientIP $this.UseClientIP -Force -Verbose:$false - } - if ($NSObject.ClientKeepAlive -ne $this.ClientKeepAlive) { - Write-Verbose -Message "Setting Client Keep Alive [$($this.ClientKeepAlive)]" - Set-NSLBServiceGroup -Name $this.Name -ClientKeepAlive $this.ClientKeepAlive -Force -Verbose:$false - } - if ($NSObject.TCPBuffering -ne $this.TCPBuffering) { - Write-Verbose -Message "Setting TCP Buffering [$($this.TCPBuffering)]" - Set-NSLBServiceGroup -Name $this.Name -TCPBuffering $this.TCPBuffering -Force -Verbose:$false - } - if ($NSObject.HTTPCompression -ne $this.HTTPCompression) { - Write-Verbose -Message "Setting HTTP Compression [$($this.HTTPCompression)]" - Set-NSLBServiceGroup -Name $this.Name -HTTPCompression $this.HTTPCompression -Force -Verbose:$false - } - if ($NSObject.ClientIP -ne $this.ClientIP) { - Write-Verbose -Message "Setting Client IP [$($this.ClientIP)]" - Set-NSLBServiceGroup -Name $this.Name -ClientIP $this.ClientIP -Force -Verbose:$false - } - if ($NSObject.MaxBandwidthKbps -ne $this.MaxBandwidthKbps) { - Write-Verbose -Message "Setting Maximum Bandwidth (Kbps) [$($this.MaxBandwidthKbps)]" - Set-NSLBServiceGroup -Name $this.Name -MaxBandwidthKbps $this.MaxBandwidthKbps -Force -Verbose:$false - } - if ($NSObject.MonitorThreshold -ne $this.MonitorThreshold) { - Write-Verbose -Message "Setting Monitor Threshold [$($this.MonitorThreshold)]" - Set-NSLBServiceGroup -Name $this.Name -MonitorThreshold $this.MonitorThreshold -Force -Verbose:$false + 'Present' { + # Does the record already exist? + if ($NSObject.Ensure -eq [ensure]::Present) { + + #Run tests and set any needed attributes to match desired configuration + if ($NSObject.monitorname -ne $this.Name) { + Write-Warning -Message "Setting Name cannot be changed to [$($this.Name)]. Object must be recreated." + } + if ($NSObject.type -ne $this.Type) { + Write-Warning -Message "Setting Type cannot be changed to [$($this.Type)]. Object must be recreated." + } + if ($NSObject.interval -ne $this.Interval) { + Write-Verbose -Message "Setting Interval [$($this.Interval)]" + Set-NSLBMonitor -Name $this.Name -Interval $this.Interval -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.units3 -ne $this.IntervalType) { + Write-Verbose -Message "Setting Interval Type [$($this.IntervalType)]" + Set-NSLBMonitor -Name $this.Name -IntervalType $this.IntervalType -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.resptimeout -ne $this.ResponseTimeout) { + Write-Verbose -Message "Setting Response Timeout was changed to [$($this.ResponseTimeout)]" + Set-NSLBMonitor -Name $this.Name -ResponseTimeout $this.ResponseTimeout -ResponseTimeoutType $this.ResponseTimeoutType -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.destip -ne $this.DestinationIP) { + Write-Verbose -Message "Setting Destination IP was changed to [$($this.DestinationIP)]" + Set-NSLBMonitor -Name $this.Name -DestinationIP $this.DestinationIP -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.downtime -ne $this.Downtime) { + Write-Verbose -Message "Setting Downtime was changed to [$($this.Downtime)]" + Set-NSLBMonitor -Name $this.Name -Downtime $this.Downtime -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.units2 -ne $this.DowntimeType) { + Write-Verbose -Message "Setting Downtime Type was changed to [$($this.DowntimeType)]" + Set-NSLBMonitor -Name $this.Name -DowntimeType $this.DowntimeType -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.retries -ne $this.Retries) { + Write-Verbose -Message "Setting Retries was changed to [$($this.Retries)]" + Set-NSLBMonitor -Name $this.Name -Retries $this.Retries -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.successretries -ne $this.SuccessRetries) { + Write-Verbose -Message "Setting Success Retries was changed to [$($this.SuccessRetries)]" + Set-NSLBMonitor -Name $this.Name -SuccessRetries $this.SuccessRetries -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.tos -ne $this.TOS) { + Write-Verbose -Message "Setting TOS was changed to [$($this.TOS)]" + Set-NSLBMonitor -Name $this.Name -TOS $this.TOS -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.state -ne $this.State) { + Write-Verbose -Message "Setting State was changed to [$($this.State)]" + Set-NSLBMonitor -Name $this.Name -State $this.State -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.reverse -ne $this.Reverse) { + Write-Verbose -Message "Setting Reverse was changed to [$($this.Reverse)]" + Set-NSLBMonitor -Name $this.Name -Reverse $this.Reverse -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.transparent -ne $this.Transparent) { + Write-Verbose -Message "Setting Transparent was changed to [$($this.Transparent)]" + Set-NSLBMonitor -Name $this.Name -Transparent $this.Transparent -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.lrtm -ne $this.LRTM) { + Write-Verbose -Message "Setting LRTM was changed to [$($this.LRTM)]" + Set-NSLBMonitor -Name $this.Name -LRTM $this.LRTM -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.secure -ne $this.Secure) { + Write-Verbose -Message "Setting Secure was changed to [$($this.Secure)]" + Set-NSLBMonitor -Name $this.Name -Secure $this.Secure -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.iptunnel -ne $this.IPTunnel) { + Write-Verbose -Message "Setting IPTunnel was changed to [$($this.IPTunnel)]" + Set-NSLBMonitor -Name $this.Name -IPTunnel $this.IPTunnel -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.failureretries -ne $this.FailureRetries) { + Write-Verbose -Message "Setting Failure Retries was changed to [$($this.FailureRetries)]" + Set-NSLBMonitor -Name $this.Name -FailureRetries $this.FailureRetries -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.destinationport -ne $this.DestinationPort) { + Write-Verbose -Message "Setting Destination Port was changed to [$($this.DestinationPort)]" + Set-NSLBMonitor -Name $this.Name -DestinationPort $this.DestinationPort -Verbose:$false -ErrorAction SilentlyContinue + } + if ($NSObject.responsecode -ne $this.ResponseCode) { + Write-Verbose -Message "Setting Response Code was changed to [$($this.ResponseCode)]" + try { + Set-NSLBMonitor -Name $this.Name -ResponseCode $this.ResponseCode -Verbose:$false -ErrorAction SilentlyContinue + } catch { $null } + } + if ($NSObject.httprequest -ne $this.HTTPRequest) { + Write-Verbose -Message "Setting HTTP Request was changed to [$($this.HTTPRequest)]" + # Set-NSLBMonitor -Name $this.Name -HTTPRequest $this.HTTPRequest -Verbose:$false -ErrorAction SilentlyContinue + } + } else { + Write-Verbose -Message "Creating monitor [$($this.Name)]" + $params = @{ + name = $this.Name + type = $this.Type + interval = $this.Interval + intervaltype = $this.IntervalType + responseTimeoutType = $this.ResponseTimeoutType + downtime = $this.Downtime + downtimeType = $this.DowntimeType + retries = $this.Retries + responsetimeout = $this.ResponseTimeout + successretries = $this.SuccessRetries + failureRetries = $this.FailureRetries + state = $this.State + destinationip = $this.DestinationIP + reverse = $this.Reverse + lrtm = $this.LRTM + transparent = $this.Transparent + tos = $this.TOS + secure = $this.Secure + } + if ($PSBoundParameters.ContainsKey('DestinationPort')) { + $params.Add('DestinationPort', $this.DestinationPort) + } + if ($PSBoundParameters.ContainsKey('Transparent')) { + $params.Add('Transparent', $this.Transparent) + } + if ($PSBoundParameters.ContainsKey('LRTM')) { + $params.Add('LRTM', $this.LRTM) + } + if ($PSBoundParameters.ContainsKey('Secure')) { + $params.Add('Secure', $this.Secure) + } + if ($PSBoundParameters.ContainsKey('IPTunnel')) { + $params.Add('IPTunnel', $this.IPTunnel) + } + if ($PSBoundParameters.ContainsKey('TOS')) { + $params.Add('TOS', $this.TOS) + } + if ($PSBoundParameters.ContainsKey('Reverse')) { + $params.Add('Reverse', $this.Reverse) + } + if ($PSBoundParameters.ContainsKey('DestinationIP')) { + $params.Add('DestinationIP', $this.DestinationIP) + } + if ($PSBoundParameters.ContainsKey('Deviation')) { + $params.Add('Deviation', $this.Deviation) + } + if ($PSBoundParameters.ContainsKey('ResponseTimeoutThreshold')) { + $params.Add('ResponseTimeoutThreshold', $this.ResponseTimeoutThreshold) + } + if ($PSBoundParameters.ContainsKey('AlertRetries')) { + $params.Add('AlertRetries', $this.AlertRetries) + } + if ($PSBoundParameters.ContainsKey('FailureRetries')) { + $params.Add('FailureRetries', $this.FailureRetries) + } + if ($PSBoundParameters.ContainsKey('NetProfile')) { + $params.Add('NetProfile', $this.NetProfile) + } + if ($PSBoundParameters.ContainsKey('TOSID')) { + $params.Add('TOSID', $this.TOSID) + } + if ($PSBoundParameters.ContainsKey('ScriptName')) { + $params.Add('ScriptName', $this.ScriptName) + } + if ($PSBoundParameters.ContainsKey('DispatcherIP')) { + $params.Add('DispatcherIP', $this.DispatcherIP) + } + if ($PSBoundParameters.ContainsKey('ScriptArgs')) { + $params.Add('ScriptArgs', $this.ScriptArgs) + } + if ($PSBoundParameters.ContainsKey('CustomProperty')) { + ## Add each custom property to the $params Hashtable + foreach ($CustomProperty in $this.CustomProperty.Keys) { + $params.Add($CustomProperty.ToLower(), $CustomProperty[$CustomProperty]) + } + } + if ($PSBoundParameters.ContainsKey('ResponseCode')) { + $params.Add('ResponseCode', $this.ResponseCode) + } + if ($PSBoundParameters.ContainsKey('HTTPRequest')) { + $params.Add('HTTPRequest', $this.HTTPRequest) + } + if ($PSBoundParameters.ContainsKey('Send')) { + $params.Add('Send', $this.Send) + } + if ($PSBoundParameters.ContainsKey('Recv')) { + $params.Add('Recv', $this.Recv) + } + if ($PSBoundParameters.ContainsKey('DispatcherPort')) { + $params.Add('DispatcherPort', $this.DispatcherPort) + } + New-NSLBMonitor @params -ErrorAction SilentlyContinue + } + } 'Absent' { + try { + $params = @{ + name = $this.Name + type = $this.Type + } + Remove-NSLBMonitor @params -Confirm:$false -ErrorAction SilentlyContinue + Write-Verbose -Message "Removing Netscaler monitor: $($this.Name)" + } catch { + write-host "Monitor $this.Name was not found" + } + } + } + Save-NSConfig + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + Write-Verbose -Message "Monitor [$($this.Name)] exists" + if ($NSObject.Name -ne $this.Name) { + Write-Verbose -Message "Monitor Name does not match [$($NSObject.monitorname) <> $($this.Name)]" + $pass = $false + } + if ($NSObject.DestinationIP -ne $this.DestinationIP) { + Write-Verbose -Message "Monitor Destination IP does not match [$($NSObject.DestinationIP) <> $($this.DestinationIP)]" + $pass = $false + } + if ($NSObject.Interval -ne $this.Interval) { + Write-Verbose -Message "Monitor Interval does not match [$($NSObject.interval) <> $($this.Interval)]" + $pass = $false + } + if ($NSObject.IntervalType -ne $this.IntervalType) { + Write-Verbose -Message "Monitor Interval Type does not match [$($NSObject.IntervalType) <> $($this.IntervalType)]" + $pass = $false + } + if ($NSObject.ResponseTimeout -ne $this.ResponseTimeout) { + Write-Verbose -Message "Monitor Response Timeout does not match [$($NSObject.ResponseTimeout) <> $($this.ResponseTimeout)]" + $pass = $false + } + if ($NSObject.ResponseTimeoutType -ne $this.ResponseTimeoutType) { + Write-Verbose -Message "Monitor Response Timeout Type does not match [$($NSObject.ResponseTimeoutType) <> $($this.ResponseTimeoutType)]" + $pass = $false + } + if ($NSObject.Downtime -ne $this.Downtime) { + Write-Verbose -Message "Monitor Downtime does not match [$($NSObject.Downtime) <> $($this.Downtime)]" + $pass = $false + } + if ($NSObject.DowntimeType -ne $this.DowntimeType) { + Write-Verbose -Message "Monitor Downtime Type does not match [$($NSObject.DowntimeType) <> $($this.DowntimeType)]" + $pass = $false + } + if ($NSObject.Retries -ne $this.Retries) { + Write-Verbose -Message "Monitor Retries does not match [$($NSObject.Retries) <> $($this.Retries)]" + $pass = $false + } + if ($NSObject.SuccessRetries -ne $this.SuccessRetries) { + Write-Verbose -Message "Monitor Success Retries does not match [$($NSObject.SuccessRetries) <> $($this.SuccessRetries)]" + $pass = $false + } + if ($NSObject.TOS -ne $this.TOS) { + Write-Verbose -Message "Monitor TOS setting not match [$($NSObject.TOS) <> $($this.TOS)]" + $pass = $false + } + if ($NSObject.State -ne $this.State) { + Write-Verbose -Message "Monitor State does not match [$($NSObject.State) <> $($this.State)]" + $pass = $false + } + if ($NSObject.Reverse -ne $this.Reverse) { + Write-Verbose -Message "Monitor Reverse setting does not match [$($NSObject.Reverse) <> $($this.Reverse)]" + $pass = $false + } + if ($NSObject.Transparent -ne $this.Transparent) { + Write-Verbose -Message "Monitor Transparent setting does not match [$($NSObject.Transparent) <> $($this.Transparent)]" + $pass = $false + } + if ($NSObject.LRTM -ne $this.LRTM) { + Write-Verbose -Message "Monitor LRTM setting does not match [$($NSObject.LRTM) <> $($this.LRTM)]" + $pass = $false + } + if ($NSObject.Secure -ne $this.Secure) { + Write-Verbose -Message "Monitor Secure setting does not match [$($NSObject.Secure) <> $($this.Secure)]" + $pass = $false + } + if ($NSObject.IPTunnel -ne $this.IPTunnel) { + Write-Verbose -Message "Monitor IPTunnel setting does not match [$($NSObject.IPTunnel) <> $($this.IPTunnel)]" + $pass = $false + } + if ($NSObject.FailureRetries -ne $this.FailureRetries) { + Write-Verbose -Message "Monitor Failure Retries does not match [$($NSObject.FailureRetries) <> $($this.FailureRetries)]" + $pass = $false + } + if ($NSObject.DestinationPort -ne $this.DestinationPort) { + Write-Verbose -Message "Monitor Destination Port does not match [$($NSObject.DestinationPort) <> $($this.DestinationPort)]" + $pass = $false + } + if ($NSObject.ResponseCode -ne $this.ResponseCode) { + Write-Verbose -Message "Monitor Response Code does not match [$($NSObject.ResponseCode) <> $($this.ResponseCode)]" + $pass = $false + } + if ($NSObject.HTTPRequest -ne $this.HTTPRequest) { + Write-Verbose -Message "Monitor HTTPRequest setting does not match [$($NSObject.HTTPRequest) <> $($this.HTTPRequest)]" + $pass = $false + } + } else { + Write-Verbose -Message "Monitor [$($this.Name)] was not found" + $pass = $false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBMonitor]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSLBMonitor -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBMonitor]::new() + $obj.Name = $this.Name + $obj.Type = $this.Type + $obj.Interval = $this.Interval + $obj.IntervalType = $this.IntervalType + $obj.DestinationIP = $this.DestinationIP + $obj.ResponseTimeout = $this.ResponseTimeout + $obj.ResponseTimeoutType = $this.ResponseTimeoutType + $obj.Downtime = $this.Downtime + $obj.DowntimeType = $this.DowntimeType + $obj.Retries = $this.Retries + $obj.SuccessRetries = $this.SuccessRetries + $obj.TOS = $this.TOS + $obj.State = $this.State + $obj.Reverse = $this.Reverse + $obj.Transparent = $this.Transparent + $obj.LRTM = $this.LRTM + $obj.Secure = $this.Secure + $obj.IPTunnel = $this.IPTunnel + $obj.FailureRetries = $this.FailureRetries + $obj.DestinationPort = $this.DestinationPort + $obj.HTTPRequest = $this.HTTPRequest + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Name = $s.monitorname + $obj.Type = $s.type + $obj.Interval = $s.interval + $obj.IntervalType = $s.units3 + $obj.DestinationIP = $s.destip + $obj.ResponseTimeout = $s.resptimeout + $obj.ResponseTimeoutType = $s.units4 + $obj.Downtime = $s.downtime + $obj.DowntimeType = $s.units2 + $obj.Retries = $s.retries + $obj.SuccessRetries = $s.successRetries + $obj.TOS = $s.tos + $obj.State = $s.state + $obj.Reverse = $s.reverse + $obj.Transparent = $s.transparent + $obj.LRTM = $s.lrtm + $obj.Secure = $s.secure + $obj.IPTunnel = $s.iptunnel + $obj.FailureRetries = $s.failureretries + $obj.DestinationPort = $s.destport + $obj.HTTPRequest = $s.httprequest + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBServiceGroupMonitorBinding { + [DscProperty(Key)] + [string]$ServiceGroupName + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty(Mandatory)] + [string]$MonitorName + + [DscProperty()] + [ValidateSet('Enabled','Disabled')] + [string]$State = 'Enabled' + + [DscProperty()] + [int]$Weight = 1 + + [DscProperty()] + [int]$Port + + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.ServiceGroupName -ne $this.ServiceGroupName) { + Write-Warning -Message "Setting ServiceGroupName [$($this.ServiceGroupName)] does not match, rebinding" + Remove-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Confirm:$false + Add-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Weight $this.Weight -Port $this.Port -State $this.State -Confirm:$false + } + if ($NSObject.MonitorName -ne $this.MonitorName) { + Write-Warning -Message "Setting MonitorName [$($this.MonitorName)] does not match, rebinding" + Remove-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Confirm:$false + Add-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Weight $this.Weight -Port $this.Port -State $this.State -Confirm:$false + } + if ($NSObject.Weight -ne $this.Weight) { + Write-Warning -Message "Setting Weight [$($this.Weight)] does not match, rebinding" + Remove-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Confirm:$false + Add-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Weight $this.Weight -Port $this.Port -State $this.State -Confirm:$false + } + if ($NSObject.State -ne $this.State) { + Write-Warning -Message "Setting State [$($this.State)] does not match, rebinding" + Remove-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Confirm:$false + Add-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Weight $this.Weight -Port $this.Port -State $this.State -Confirm:$false + } + } else { + Write-Verbose -Message "Added [$($this.MonitorName)] binding for, [$($this.ServiceGroupName)]" + $params = @{ + ServiceGroupName = $this.ServiceGroupName + MonitorName = $this.MonitorName + Weight = $this.Weight + State = $this.State + Port = $this.Port + } + Add-NSLBServiceGroupMonitorBinding @params -Confirm:$false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Confirm:$false -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Monitor Binding: $($this.ServiceGroupName > $this.MonitorName)" + } + } + } + Save-NSConfig + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.ServiceGroupName -ne $this.ServiceGroupName) { + Write-Verbose -Message "ServiceGroupName does not match [$($NSObject.servicegroupname) <> $($this.ServiceGroupName)]" + $pass = $false + } + if ($NSObject.MonitorName -ne $this.MonitorName) { + Write-Verbose -Message "MonitorName does not match [$($NSObject.MonitorName) <> $($this.MonitorName)]" + $pass = $false + } + if ($NSObject.State -ne $this.State) { + Write-Verbose -Message "State does not match [$($NSObject.State) <> $($this.State)]" + $pass = $false + } + if ($NSObject.Weight -ne $this.Weight) { + Write-Verbose -Message "Weight does not match [$($NSObject.Weight) <> $($this.MonitorName)]" + $pass = $false + } + if ((!$NSObject.Port) -AND ($NSObject.Port -ne $this.Port)) { + Write-Verbose -Message "Port does not match [$($NSObject.Port) <> $($this.Port)]" + $pass = $false + } + } else { + Write-Verbose -Message "File [$($this.ServiceGroupName) is not bound to $($this.MonitorName)]" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBServiceGroupMonitorBinding]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBServiceGroupMonitorBinding]::new() + $obj.ServiceGroupName = $this.ServiceGroupName + $obj.MonitorName = $this.MonitorName + $obj.State = $this.State + $obj.Weight = $this.Weight + $obj.Port = $this.Port + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.ServiceGroupName = $s.servicegroupname + $obj.MonitorName = $s.monitor_name + $obj.State = $s.state + $obj.Weight = $s.weight + if ($s.port) { $obj.Port = $this.Port } + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBServiceMonitorBinding { + [DscProperty(Key)] + [string]$ServiceName + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty(Mandatory)] + [string]$MonitorName + + [DscProperty()] + [int]$Weight = 1 + + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.ServiceName -ne $this.ServiceName) { + Write-Warning -Message "Setting ServiceName [$($this.ServiceName)] does not match, rebinding" + Remove-NSLBServiceMonitorBinding -ServiceName $this.ServiceName -MonitorName $this.MonitorName -Confirm:$false + Add-NSLBServiceMonitorBinding -ServiceName $this.ServiceName -MonitorName $this.MonitorName -Weight $this.Weight -Confirm:$false + } + if ($NSObject.MonitorName -ne $this.MonitorName) { + Write-Warning -Message "Setting MonitorName [$($this.MonitorName)] does not match, rebinding" + Remove-NSLBServiceMonitorBinding -ServiceName $this.ServiceName -MonitorName $this.MonitorName -Confirm:$false + Add-NSLBServiceMonitorBinding -ServiceName $this.ServiceName -MonitorName $this.MonitorName -Weight $this.Weight -Confirm:$false + } + if ($NSObject.Weight -ne $this.Weight) { + Write-Warning -Message "Setting Weight [$($this.Weight)] does not match, rebinding" + Remove-NSLBServiceMonitorBinding -ServiceName $this.ServiceName -MonitorName $this.MonitorName -Confirm:$false + Add-NSLBServiceMonitorBinding -ServiceName $this.ServiceName -MonitorName $this.MonitorName -Weight $this.Weight -Confirm:$false + } + } else { + Write-Verbose -Message "Added [$($this.MonitorName)] binding for, [$($this.ServiceName)]" + $params = @{ + ServiceName = $this.ServiceName + MonitorName = $this.MonitorName + Weight = $this.Weight + } + Add-NSLBServiceMonitorBinding @params -ErrorAction SilentlyContinue -Confirm:$false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSLBServiceMonitorBinding -ServiceName $this.ServiceName -MonitorName $this.MonitorName -Confirm:$false -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Monitor Binding: $($this.ServiceName > $this.MonitorName)" + } + } + } + Save-NSConfig + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.ServiceName -ne $this.ServiceName) { + Write-Verbose -Message "ServiceName does not match [$($NSObject.ServiceName) <> $($this.ServiceName)]" + $pass = $false + } + if ($NSObject.MonitorName -ne $this.MonitorName) { + Write-Verbose -Message "MonitorName does not match [$($NSObject.MonitorName) <> $($this.MonitorName)]" + $pass = $false + } + if ($NSObject.Weight -ne $this.Weight) { + Write-Verbose -Message "Weight does not match [$($NSObject.Weight) <> $($this.MonitorName)]" + $pass = $false + } + } else { + Write-Verbose -Message "File [$($this.ServiceName) is not bound to $($this.MonitorName)]" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBServiceMonitorBinding]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSLBServiceMonitorBinding -ServiceName $this.ServiceName -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBServiceMonitorBinding]::new() + $obj.ServiceName = $this.ServiceName + $obj.MonitorName = $this.MonitorName + $obj.Weight = $this.Weight + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.ServiceName = $s.name.ToString() + $obj.MonitorName = $s.monitor_name.ToString() + $obj.Weight = $s.weight + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +# [DscResource()] +# class LBNTPServer { +# [DscProperty(Key)] +# [string]$Server + +# [DscProperty()] +# [Ensure]$Ensure = [Ensure]::Present + +# [DscProperty(Mandatory)] +# [string]$NetScalerFQDN + +# [DscProperty(Mandatory)] +# [pscredential]$Credential + +# [DscProperty()] +# [int]$MinPollInterval + +# [DscProperty()] +# [ValidateRange(0, 4094)] +# [int]$MaxPollInterval + +# [DscProperty()] +# [ValidateSet('Yes','No')] +# [string]$PreferredNTPServer = 'Yes' + +# Init() { +# try { +# Import-Module -Name Netscaler -Verbose:$false -Debug:$false +# Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false +# } catch { +# throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" +# } +# } + +# [void]Set() { +# $t = $null +# $t = $this.Init() +# $NSObject = $this.Get() + +# try { +# Import-Module -Name Netscaler -Verbose:$false -Debug:$false +# Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false +# } catch { +# throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" +# } + +# try { +# switch ($this.Ensure) { +# 'Present' { +# if ($this.Ensure -eq $NSObject.Ensure) { +# if ($NSObject.Server -ne $this.Server) { +# Write-Warning -Message "The NTP server name cannot be set to [$($this.Server)], resource can only be removed and recreated" +# } +# if ($NSObject.MinPollInterval -ne $this.MinPollInterval) { +# Write-Verbose -Message "Setting Service Group MinPollInterval [$($this.MinPollInterval)]" +# Set-NSNTPServer -Server $this.Server -MinPollInterval $this.MinPollInterval -Verbose:$false +# } +# if ($NSObject.MaxPollInterval -ne $this.MaxPollInterval) { +# Write-Verbose -Message "Setting Service Group MaxPollInterval [$($this.MaxPollInterval)]" +# Set-NSNTPServer -Server $this.Server -MaxPollInterval $this.MaxPollInterval -Verbose:$false +# } +# if ($NSObject.PreferredNTPServer -ne $this.PreferredNTPServer) { +# Write-Warning -Message "The preferred NTP server cannot be set to [$($this.PreferredNTPServer)], setting can only be set manually" +# } +# } else { +# Write-Verbose -Message "Creating resource [$($this.Name)]" +# $params = @{ +# server = $this.Server +# minpoll = $this.MinPollInterval +# maxpoll = $this.MaxPollInterval +# preferredntpserver = $this.PreferredNTPServer +# } +# New-NSNTPServer @params -Verbose:$false -ErrorAction SilentlyContinue +# } +# } 'Absent' { +# if ($this.Ensure -ne $NSObject.Ensure) { +# Remove-NSNTPServer -Server $this.Server -ErrorAction SilentlyContinue +# Write-Verbose -Message "Removing resource: $($this.Server)" +# } +# } +# } + #Save-NSConfig +# } catch { +# Write-Error 'There was a problem setting the resource' +# Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" +# Write-Error $_ +# } +# try { +# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue +# } catch { +# # Do nothing +# } +# } + +# [bool]Test() { +# $pass = $true +# $t = $null +# $t = $this.Init() +# $NSObject = $this.Get() +# try { +# switch ($this.Ensure) { +# 'Present' { +# if ($this.Ensure -eq $NSObject.Ensure) { +# # Run tests and set any needed attributes to match desired configuration +# if ($NSObject.Server -ne $this.Server) { +# Write-Verbose -Message "Server does not match [$($NSObject.Server) <> $($this.Server)]" +# $pass = $false +# } +# if ($NSObject.MinPollInterval -ne $this.MinPollInterval) { +# Write-Verbose -Message "Min Poll Interval does not match [$($NSObject.MinPollInterval) <> $($this.MinPollInterval)]" +# $pass = $false +# } +# if ($NSObject.MaxPollInterval -ne $this.MaxPollInterval) { +# Write-Verbose -Message "Max Poll Interval does not match [$($NSObject.MaxPollInterval) <> $($this.MaxPollInterval)]" +# $pass = $false +# } +# if ($NSObject.PreferredNTPServer -ne $this.PreferredNTPServer) { +# Write-Verbose -Message "Preferred NTP Server does not match [$($NSObject.PreferredNTPServer) <> $($this.PreferredNTPServer)]" +# $pass = $false +# } +# } else { +# Write-Verbose -Message "Resource [$($this.Server)] was not found" +# $pass = $false +# } +# } +# 'Absent' { +# if ($this.Ensure -ne $NSObject.Ensure) { +# $pass = $false +# } +# } +# } +# } catch { +# Write-Error 'There was a problem testing the resource' +# Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" +# Write-Error $_ +# } +# try { +# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue +# } catch { +# # Do nothing +# } +# return $pass +# } + +# [LBNTPServer]Get() { +# $t = $null +# $t = $this.Init() + +# try { +# $s = Get-NSNTPServer -Name $this.Server -Verbose:$false -ErrorAction SilentlyContinue +# } catch { +# $s = $null +# } + +# $obj = [LBNTPServer]::new() +# $obj.Server = $this.Server +# $obj.MinPollInterval = $this.MinPollInterval +# $obj.MaxPollInterval = $this.MaxPollInterval +# $obj.PreferredNTPServer = $this.PreferredNTPServer +# if ($s) { +# $obj.Ensure = [ensure]::Present +# $obj.Server = $s.serverip +# $obj.MinPollInterval = $s.minpoll +# $obj.MaxPollInterval = $s.maxpoll +# $obj.PreferredNTPServer = $s.preferredntpserver +# } else { +# $obj.Ensure = [ensure]::Absent +# } +# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue +# return $obj +# } +# } + + +[DscResource()] +class LBResponderPolicy { + [DscProperty(Key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty(Mandatory)] + [string]$Rule + + [DscProperty()] + [string]$Comment + + [DscProperty(Mandatory)] + [string]$Action + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne $this.Name) { + Write-Warning -Message "The Name cannot be changed to [$($this.Name)], resource can only be removed and recreated" + } + if ($NSObject.Rule -ne $this.Rule) { + Write-Verbose -Message "Setting Rule [$($this.Rule)]" + Set-NSResponderPolicy -Name $this.Name -Rule $this.Rule -Verbose:$false + } + if ($NSObject.Action -ne $this.Action) { + Write-Verbose -Message "Setting Service Group Name [$($this.MaxPollInterval)]" + Set-NSResponderPolicy -Name $this.Name -Action $this.Action -Verbose:$false + } + if ($NSObject.Comment -ne $this.Comment) { + Write-Verbose -Message "Setting monitor's Interval Type [$($this.Comment)]" + Set-NSResponderPolicy -Name $this.Name -Comment $this.Comment -Verbose:$false + } + } else { + Write-Verbose -Message "Creating resource [$($this.Name)]" + $params = @{ + name = $this.Name + rule = $this.Rule + action = $this.Action + comment = $this.Comment + } + New-NSResponderPolicy @params -ErrorAction SilentlyContinue + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSResponderPolicy -Name $NSObject.Name -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Responder Policy: $($this.Name)" + } + } + } + Save-NSConfig + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne $this.Name) { + Write-Verbose -Message "Name does not match [$($NSObject.Name) <> $($this.Name)]" + $pass = $false + } + if ($NSObject.Rule -ne $this.Rule) { + Write-Verbose -Message "Rule does not match [$($NSObject.Rule) <> $($this.Rule)]" + $pass = $false + } + if ($NSObject.Action -ne $this.Action) { + Write-Verbose -Message "Action does not match [$($NSObject.Action) <> $($this.Action)]" + $pass = $false + } + } else { + Write-Verbose -Message "Responder Policy [$($this.Name)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBResponderPolicy]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSResponderPolicy -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBResponderPolicy]::new() + $obj.Name = $this.Name + $obj.Rule = $this.Rule + $obj.Action = $this.Action + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Name = $s.name + $obj.Rule = $s.rule + $obj.Action = $s.action.toString() + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBResponderAction { + [DscProperty(Key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty()] + [ValidateSet('NOOP','Redirect','RespondWith', 'RespondWithSQLOK','RespondWithSQLError','RespondWithHTMLPage')] + [string]$Type = 'NOOP' + + [DscProperty()] + [ValidateLength(0, 8191)] + [Alias('Expression')] + [string]$Target = [string]::Empty + + [DscProperty()] + [ValidateRange(100, 599)] + [int]$ResponseStatusCode + + [DscProperty()] + [ValidateLength(0, 8191)] + [string]$ReasonPhrase = [string]::Empty + + [DscProperty()] + [ValidateLength(0, 8191)] + [string]$HTMLPage = [string]::Empty + + [DscProperty()] + [ValidateLength(0, 256)] + [string]$Comment = [string]::Empty + + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne $this.Name) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.Name)], resource can only be removed and recreated" } - if ($NSObject.MaxRequests -ne $this.MaxRequests) { - Write-Verbose -Message "Setting Maximum Client Requests [$($this.MaxRequests)]" - Set-NSLBServiceGroup -Name $this.Name -MaxRequests $this.MaxRequests -Force -Verbose:$false + if ($NSObject.Type -ne $this.Type) { + Write-Verbose -Message "Setting Responder Action [$($this.Type)]" + Set-NSResponderAction -Name $this.Name -Type $this.Type -Verbose:$false } - if ($NSObject.MaxClients -ne $this.MaxClients) { - Write-Verbose -Message "Setting Maximum Client connections [$($this.MaxClients)]" - Set-NSLBServiceGroup -Name $this.Name -MaxClients $this.MaxClients -Force -Verbose:$false + if (($NSObject.Target) -AND ($NSObject.Target -ne $this.Target)) { + Write-Verbose -Message "Setting Responder Action [$($this.Target)]" + Set-NSResponderAction -Name $this.Name -Target $this.Target -Verbose:$false } - if ($NSObject.ClientIdleTimeout -ne $this.ClientIdleTimeout) { - Write-Verbose -Message "Setting Client Idle Timeout [$($this.ClientIdleTimeout)]" - Set-NSLBServiceGroup -Name $this.Name -ClientIdleTimeout $this.ClientIdleTimeout -Force -Verbose:$false + if (($NSObject.HTMLPage) -AND ($NSObject.HTMLPage -ne $this.HTMLPage)) { + Write-Verbose -Message "Setting Responder Action [$($this.HTMLPage)]" + Set-NSResponderAction -Name $this.Name -HTMLPage $this.HTMLPage -Verbose:$false } - if ($NSObject.ServerIdleTimeout -ne $this.ServerIdleTimeout) { - Write-Verbose -Message "Setting Server Idle Timeout [$($this.ServerIdleTimeout)]" - Set-NSLBServiceGroup -Name $this.Name -ServerIdleTimeout $this.ServerIdleTimeout -Force -Verbose:$false + if ($NSObject.Comment -ne $this.Comment) { + Write-Verbose -Message "Setting Responder Action [$($this.Comment)]" + Set-NSResponderAction -Name $this.Name -Comment $this.Comment -Verbose:$false } - } else { - Write-Verbose -Message "Creating Service Group [$($this.Name)]" + } else { + Write-Verbose -Message "Creating resource [$($this.Name)]" $params = @{ name = $this.Name - servicetype = $this.ServiceType - state = $this.State - comment = $this.Comment - } - if ($PSBoundParameters.ContainsKey('TrafficDomainId')) { - $params.Add('TrafficDomainId', $this.TrafficDomainId) - } - if ($PSBoundParameters.ContainsKey('MaxClients')) { - $params.Add('MaxClients', $this.MaxClients) - } - if ($PSBoundParameters.ContainsKey('CacheType')) { - $params.Add('CacheType', $this.CacheType) - } - if ($PSBoundParameters.ContainsKey('AutoScale')) { - $params.Add('AutoScale', $this.AutoScale) - } - if ($PSBoundParameters.ContainsKey('Cacheable')) { - $params.Add('Cacheable', $this.Cacheable) - } - if ($PSBoundParameters.ContainsKey('HealthMonitor')) { - $params.Add('HealthMonitor', $this.HealthMonitor) - } - if ($PSBoundParameters.ContainsKey('AppFlowLog')) { - $params.Add('AppFlowLog', $this.AppFlowLog) + type = $this.Type + comment = $this.Comment } - if ($PSBoundParameters.ContainsKey('SureConnect')) { - $params.Add('SureConnect', $this.SureConnect) + + if ($PSBoundParameters.ContainsKey('Target')) { + $params.Add('target', $this.Target) } - if ($PSBoundParameters.ContainsKey('SurgeProtection')) { - $params.Add('SurgeProtection', $this.SurgeProtection) + if ($PSBoundParameters.ContainsKey('HTMLPage')) { + $params.Add('HTMLPage', $this.HTMLPage) } - if ($PSBoundParameters.ContainsKey('UseProxyPort')) { - $params.Add('UseProxyPort', $this.UseProxyPort) + New-NSResponderAction @params -ErrorAction SilentlyContinue + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSResponderAction -Name $NSObject.Name -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Responder Action: $($this.Name)" + } + } + } + Save-NSConfig + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne $this.Name) { + Write-Verbose -Message "Name does not match [$($NSObject.Name) <> $($this.Name)]" + $pass = $false } - if ($PSBoundParameters.ContainsKey('DownStateFlush')) { - $params.Add('DownStateFlush', $this.DownStateFlush) + if ($NSObject.Type -ne $this.Type) { + Write-Verbose -Message "Type does not match [$($NSObject.Type) <> $($this.Type)]" + $pass = $false } - if ($PSBoundParameters.ContainsKey('UseClientIP')) { - $params.Add('UseClientIP', $this.UseClientIP) + if (($NSObject.Target) -AND ($NSObject.Target -ne $this.Target)) { + Write-Verbose -Message "Target does not match [$($NSObject.Target) <> $($this.Target)]" + $pass = $false } - if ($PSBoundParameters.ContainsKey('ClientKeepAlive')) { - $params.Add('ClientKeepAlive', $this.ClientKeepAlive) + if (($NSObject.HTMLPage) -AND ($NSObject.HTMLPage -ne $this.HTMLPage)) { + Write-Verbose -Message "HTMLPage does not match [$($NSObject.HTMLPage) <> $($this.HTMLPage)]" + $pass = $false } - if ($PSBoundParameters.ContainsKey('TCPBuffering')) { - $params.Add('TCPBuffering', $this.TCPBuffering) + } else { + Write-Verbose -Message "Responder Action [$($this.Name)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBResponderAction]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSResponderAction -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBResponderAction]::new() + $obj.Name = $this.Name + $obj.Type = $this.Type + $obj.Target = $this.Target + $obj.HTMLPage = $this.HTMLPage + $obj.Comment = $this.Comment + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Name = $s.name + $obj.Type = $s.type + if ($s.target) { $obj.Target = $s.target } + if ($s.htmlpage) { $obj.HTMLPage = $s.htmlpage } + $obj.Comment = $s.comment + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBRewritePolicy { + [DscProperty(Key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty()] + [string]$ActionName + + [DscProperty()] + [string]$LogActionName + + [DscProperty()] + [ValidateLength(0, 8191)] + [Alias('Expression')] + [string]$Rule + + [DscProperty()] + [string]$Comment + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.name -ne $this.Name) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.Name)], resource can only be removed and recreated" } - if ($PSBoundParameters.ContainsKey('HTTPCompression')) { - $params.Add('HTTPCompression', $this.HTTPCompression) + if ($NSObject.rule -ne $this.Rule) { + Write-Verbose -Message "Setting Rule [$($this.Rule)]" + Set-NSRewritePolicy -Name $this.Name -Rule $this.Rule -Verbose:$false } - if ($PSBoundParameters.ContainsKey('ClientIP')) { - $params.Add('ClientIP', $this.ClientIP) + if ($NSObject.actionname -ne $this.ActionName) { + Write-Verbose -Message "Setting Action Name [$($this.ActionName)]" + Set-NSRewritePolicy -Name $this.Name -ActionName $this.ActionName -LogActionName $this.LogActionName -Rule $this.Rule -Verbose:$false } - if ($PSBoundParameters.ContainsKey('MaxBandwidthKbps')) { - $params.Add('MaxBandwidthKbps', $this.MaxBandwidthKbps) + if ($NSObject.logActionname -ne "Use Global") { + if ($NSObject.logactionname -ne $this.LogActionName) { + Write-Verbose -Message "Setting LogActionName [$($this.LogActionName)]" + Set-NSRewritePolicy -Name $this.Name -LogActionName $this.LogActionName -Verbose:$false + } } - if ($PSBoundParameters.ContainsKey('DownStateFlush')) { - $params.Add('DownStateFlush', $this.DownStateFlush) + if ($NSObject.Comment -ne $this.Comment) { + Write-Verbose -Message "Setting Comment [$($this.Comment)]" + Set-NSRewritePolicy -Name $this.Name -Comment $this.Comment -Verbose:$false } - if ($PSBoundParameters.ContainsKey('MaxRequests')) { - $params.Add('MaxRequests', $this.MaxRequests) + } else { + Write-Verbose -Message "Creating resource [$($this.Name)]" + $params = @{ + name = $this.Name + rule = $this.Rule + actionname = $this.ActionName + comment = $this.Comment } - if ($PSBoundParameters.ContainsKey('ClientIdleTimeout')) { - $params.Add('ClientIdleTimeout', $this.ClientIdleTimeout) + if ($PSBoundParameters.ContainsKey('LogActionName')) { + $params.Add('LogActionName', $this.LogActionName) } - if ($PSBoundParameters.ContainsKey('ServerIdleTimeout')) { - $params.Add('ServerIdleTimeout', $this.ServerIdleTimeout) - } - New-NSLBServiceGroup @params -ErrorAction SilentlyContinue + New-NSRewritePolicy @params -ErrorAction SilentlyContinue } - } - 'Absent' { - if ($this.Ensure -ne $NSObject.Ensure) { - Remove-NSLBServiceGroup -Name $NSObject.Name -Confirm:$false -ErrorAction SilentlyContinue - Write-Verbose -Message "Removing Netscaler monitor: $($this.Name)" + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSRewritePolicy -Name $NSObject.Name -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Rewrite Policy: $($this.Name)" } } } + Save-NSConfig } catch { Write-Error 'There was a problem setting the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" @@ -1323,7 +2579,7 @@ class LBServiceGroup { } } - [bool]Test() { + [bool]Test() { $pass = $true $t = $null $t = $this.Init() @@ -1332,108 +2588,220 @@ class LBServiceGroup { switch ($this.Ensure) { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration if ($NSObject.Name -ne $this.Name) { - Write-Verbose -Message "Service Group Name doest not match [$($NSObject.Name) <> $($this.Name)]" - $pass = $false - } - if ($NSObject.ServiceType -ne $this.ServiceType) { - Write-Verbose -Message "Service Type does not match [$($NSObject.ServiceType) <> $($this.ServiceType)]" - $pass = $false - } - if ($NSObject.TrafficDomainId -ne $this.TrafficDomainId) { - Write-Verbose -Message "Traffic Domain does not match [$($NSObject.TrafficDomainId) <> $($this.TrafficDomainId)]" - $pass = $false - } - if ($NSObject.CacheType -ne $this.CacheType) { - Write-Verbose -Message "Cache Type does not match [$($NSObject.CacheType) <> $($this.CacheType)]" - $pass = $false - } - if ($NSObject.Cacheable -ne $this.Cacheable) { - Write-Verbose -Message "Cacheable setting does not match [$($NSObject.Cacheable) <> $($this.Cacheable)]" + Write-Verbose -Message "Name does not match [$($NSObject.Name) <> $($this.Name)]" $pass = $false } - if ($NSObject.State -ne $this.State) { - Write-Verbose -Message "State does not match [$($NSObject.State) <> $($this.State)]" + if ($NSObject.Rule -ne $this.Rule) { + Write-Verbose -Message "Rule does not match [$($NSObject.Rule) <> $($this.Rule)]" $pass = $false } - if ($NSObject.HealthMonitor -ne $this.HealthMonitor) { - Write-Verbose -Message "Health Monitor does not match [$($NSObject.HealthMonitor) <> $($this.HealthMonitor)]" + if ($NSObject.ActionName -ne $this.ActionName) { + Write-Verbose -Message "Action Name does not match [$($NSObject.ActionName) <> $($this.ActionName)]" $pass = $false } - if ($NSObject.AppFlowLog -ne $this.AppFlowLog) { - Write-Verbose -Message "AppFlowLog does not match [$($NSObject.AppFlowLog) <> $($this.AppFlowLog)]" - $pass = $false + if ($NSObject.LogActionName -ne "Use Global") { + if ($NSObject.LogActionName -ne $this.LogActionName) { + Write-Verbose -Message "Log Action Name does not match [$($NSObject.LogActionName) <> $($this.LogActionName)]" + $pass = $false + } } if ($NSObject.Comment -ne $this.Comment) { Write-Verbose -Message "Comment does not match [$($NSObject.Comment) <> $($this.Comment)]" $pass = $false } - if ($NSObject.SurgeProtection -ne $this.SurgeProtection) { - Write-Verbose -Message "Surge Protection does not match [$($NSObject.SurgeProtection) <> $($this.SurgeProtection)]" - $pass = $false - } - if ($NSObject.SureConnect -ne $this.SureConnect) { - Write-Verbose -Message "Sure Connect does not match [$($NSObject.SureConnect) <> $($this.SureConnect)]" - $pass = $false - } - if ($NSObject.UseProxyPort -ne $this.UseProxyPort) { - Write-Verbose -Message "Use Proxy Port does not match [$($NSObject.UseProxyPort) <> $($this.UseProxyPort)]" - $pass = $false - } - if ($NSObject.DownStateFlush -ne $this.DownStateFlush) { - Write-Verbose -Message "DownState Flush does not match [$($NSObject.DownStateFlush) <> $($this.DownStateFlush)]" - $pass = $false - } - if ($NSObject.UseClientIP -ne $this.UseClientIP) { - Write-Verbose -Message "Use Client IP does not match [$($NSObject.UseClientIP) <> $($this.UseClientIP)]" - $pass = $false + } else { + Write-Verbose -Message "Responder Policy [$($this.Name)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBRewritePolicy]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSRewritePolicy -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBRewritePolicy]::new() + $obj.Name = $this.Name + $obj.Rule = $this.Rule + $obj.ActionName = $this.ActionName + $obj.LogActionName = $this.LogActionName + $obj.Comment = $this.Comment + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.Name = $s.name + $obj.Rule = $s.rule + $obj.ActionName = $s.action + $obj.LogActionName = $s.logaction + $obj.Comment = $s.comment + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} + +[DscResource()] +class LBRewriteAction { + [DscProperty(Key)] + [string]$Name + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty(Mandatory)] + [string]$Type + + [DscProperty(Mandatory)] + [ValidateLength(0, 8191)] + [string]$Target + + [DscProperty(Mandatory)] + [ValidateLength(0, 8191)] + [string]$Expression + + [DscProperty()] + [string]$Comment + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne $this.Name) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.Name)], resource can only be removed and recreated" } - if ($NSObject.ClientKeepAlive -ne $this.ClientKeepAlive) { - Write-Verbose -Message "Client Keep Alive does not match [$($NSObject.ClientKeepAlive) <> $($this.ClientKeepAlive)]" - $pass = $false + if ($NSObject.Type -ne $this.Type) { + Write-Verbose -Message "Setting Rule [$($this.Type)]" + Set-NSRewriteAction -Name $this.Name -Type $this.Type -Target $this.Target -Expression $this.Expression -Comment $this.Comment -Verbose:$false } - if ($NSObject.TCPBuffering -ne $this.TCPBuffering) { - Write-Verbose -Message "TCP Buffering does not match [$($NSObject.TCPBuffering) <> $($this.TCPBuffering)]" - $pass = $false + if ($NSObject.Target -ne $this.Target) { + Write-Verbose -Message "Setting Action Name [$($this.Target)]" + Set-NSRewriteAction -Name $this.Name -Target $this.Target -Verbose:$false } - if ($NSObject.HTTPCompression -ne $this.HTTPCompression) { - Write-Verbose -Message "HTTP Compression does not match [$($NSObject.HTTPCompression) <> $($this.HTTPCompression)]" - $pass = $false + if ($NSObject.Expression -ne $this.Expression) { + Write-Verbose -Message "Setting LogActionName [$($this.Expression)]" + Set-NSRewriteAction -Name $this.Name -Expression $this.Expression -Verbose:$false } - if ($NSObject.ClientIP -ne $this.ClientIP) { - Write-Verbose -Message "Client IP does not match [$($NSObject.ClientIP) <> $($this.ClientIP)]" - $pass = $false + if ($NSObject.Comment -ne $this.Comment) { + Write-Verbose -Message "Setting Comment [$($this.Comment)]" + Set-NSRewriteAction -Name $this.Name -Comment $this.Comment -Verbose:$false } - # if ($NSObject.ClientIPHeader -ne $this.ClientIPHeader) { - # Write-Verbose -Message "ClientIP Header does not match [$($this.ClientIPHeader)]" - # $pass = $false - # } - if ($NSObject.MaxBandwidthKbps -ne $this.MaxBandwidthKbps) { - Write-Verbose -Message "Maximum Banddwith (Kbps) does not match [$($NSObject.MaxBandwidthKbps) <> $($this.MaxBandwidthKbps)]" - $pass = $false + } else { + Write-Verbose -Message "Creating resource [$($this.Name)]" + $params = @{ + name = $this.Name + Type = $this.Type.toLower() + Target = $this.Target + Expression = $this.Expression + Comment = $this.Comment } - if ($NSObject.MonitorThreshold -ne $this.MonitorThreshold) { - Write-Verbose -Message "Monitor Threshold does not match [$($NSObject.MonitorThreshold) <> $($this.MonitorThreshold)]" + New-NSRewriteAction @params -ErrorAction SilentlyContinue + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSRewriteAction -Name $NSObject.Name -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Rewrite Action: $($this.Name)" + } + } + } + Save-NSConfig + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.name -ne $this.Name) { + Write-Verbose -Message "Name does not match [$($NSObject.Name) <> $($this.Name)]" $pass = $false } - if ($NSObject.MaxRequests -ne $this.MaxRequests) { - Write-Verbose -Message "Maximum Client Requests does not match [$($NSObject.MaxRequests) <> $($this.MaxRequests)]" + if ($NSObject.type -ne $this.Type) { + Write-Verbose -Message "Type does not match [$($NSObject.Type) <> $($this.Type)]" $pass = $false } - if ($NSObject.MaxClients -ne $this.MaxClients) { - Write-Verbose -Message "Maximum Client connections does not match [$($NSObject.MaxClients) <> $($this.MaxClients)]" + if ($NSObject.target -ne $this.Target) { + Write-Verbose -Message "Target does not match [$($NSObject.Target) <> $($this.Target)]" $pass = $false } - if ($NSObject.ClientIdleTimeout -ne $this.ClientIdleTimeout) { - Write-Verbose -Message "Client Idle Timeout does not match [$($NSObject.ClientIdleTimeout) <> $($this.ClientIdleTimeout)]" + if ($NSObject.Expression -ne $this.Expression) { + Write-Verbose -Message "Expression does not match [$($NSObject.Expression) <> $($this.Expression)]" $pass = $false } - if ($NSObject.ServerIdleTimeout -ne $this.ServerIdleTimeout) { - Write-Verbose -Message "Server Idle Timeout does not match [$($NSObject.ServerIdleTimeout) <> $($this.ServerIdleTimeout)]" + if ($NSObject.comment -ne $this.Comment) { + Write-Verbose -Message "Comment does not match [$($NSObject.Comment) <> $($this.Comment)]" $pass = $false } } else { - Write-Verbose -Message "Resource [$($this.Name)] was not found" + Write-Verbose -Message "Responder Action [$($this.Name)] was not found" $pass = $false } } @@ -1453,72 +2821,32 @@ class LBServiceGroup { } catch { # Do nothing } - return $pass + return $pass } - [LBServiceGroup]Get() { + [LBRewriteAction]Get() { $t = $null $t = $this.Init() try { - $s = Get-NSLBServiceGroup -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + $s = Get-NSRewriteAction -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue } catch { $s = $null } - $obj = [LBServiceGroup]::new() + $obj = [LBRewriteAction]::new() $obj.Name = $this.Name - $obj.ServiceType = $this.ServiceType - $obj.TrafficDomainID = $this.TrafficDomainID - $obj.CacheType = $this.CacheType - $obj.MaxClients = $this.MaxClients - $obj.MaxRequests = $this.MaxRequests - $obj.Cacheable = $this.Cacheable - $obj.ClientIP = $this.ClientIP - $obj.UseClientIP = $this.UseClientIP - $obj.UseProxyPort = $this.UseProxyPort - $obj.SureConnect = $this.SureConnect - $obj.SurgeProtection = $this.SurgeProtection - $obj.ClientKeepAlive = $this.ClientKeepAlive - $obj.ClientIdleTimeout = $this.ClientIdleTimeout - $obj.ServerIdleTimeout = $this.ServerIdleTimeout - $obj.TCPBuffering = $this.TCPBuffering - $obj.HTTPCompression = $this.HTTPCompression - $obj.MaxBandwidthKbps = $this.MaxBandwidthKbps - $obj.State = $this.State - $obj.DownStateFlush = $this.DownStateFlush - $obj.HealthMonitor = $this.HealthMonitor - $obj.AppFlowLog = $this.AppFlowLog + $obj.Type = $this.Type + $obj.Target = $this.Target + $obj.Expression = $this.Expression $obj.Comment = $this.Comment - # $obj.ClientIPHeader = $this.ClientIPHeader - $obj.MonitorThreshold = $this.MonitorThreshold if ($s) { $obj.Ensure = [ensure]::Present - $obj.Name = $s.servicegroupname - $obj.ServiceType = $s.servicetype - $obj.TrafficDomainID = $s.td - $obj.CacheType = $s.cachetype - $obj.MaxClients = $s.maxclient - $obj.MaxRequests = $s.maxreq - $obj.Cacheable = $s.cacheable - $obj.ClientIP = $s.cip - $obj.UseClientIP = $s.usip - $obj.UseProxyPort = $s.useproxyport - $obj.SureConnect = $s.sc - $obj.SurgeProtection = $s.sp - $obj.ClientKeepAlive = $s.cka - $obj.ClientIdleTimeout = $s.clttimeout - $obj.ServerIdleTimeout = $s.svrtimeout - $obj.TCPBuffering = $s.tcpb - $obj.HTTPCompression = $s.cmp - $obj.MaxBandwidthKbps = $s.maxbandwidth - $obj.State = $s.state - $obj.DownStateFlush = $s.downstateflush - $obj.HealthMonitor = $s.healthmonitor - $obj.AppFlowLog = $s.appflowlog + $obj.Name = $s.name + $obj.Type = $s.type + $obj.Target = $s.target + $obj.Expression = $s.stringbuilderexpr $obj.Comment = $s.comment - # $obj.ClientIPHeader = $s.cipheader - $obj.MonitorThreshold = $s.monthreshold } else { $obj.Ensure = [ensure]::Absent } @@ -1527,180 +2855,174 @@ class LBServiceGroup { } } -# [DscResource()] -# class LBNTPServer { -# [DscProperty(Key)] -# [string]$Server +[DscResource()] +class LBDNSServer { + [DscProperty(Key)] + [string]$IPAddress -# [DscProperty()] -# [Ensure]$Ensure = [Ensure]::Present + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present -# [DscProperty(Mandatory)] -# [string]$NetScalerFQDN - -# [DscProperty(Mandatory)] -# [pscredential]$Credential + [DscProperty(Mandatory)] + [string]$NetScalerFQDN -# [DscProperty()] -# [int]$MinPollInterval + [DscProperty(Mandatory)] + [pscredential]$Credential -# [DscProperty()] -# [ValidateRange(0, 4094)] -# [int]$MaxPollInterval + [DscProperty()] + [ValidateLength(0, 8191)] + [string]$Local = $false -# [DscProperty()] -# [ValidateSet('Yes','No')] -# [string]$PreferredNTPServer = 'Yes' + [DscProperty()] + [ValidateSet('ENABLED','DISABLED')] + [string]$State = 'ENABLED' -# Init() { -# try { -# Import-Module -Name Netscaler -Verbose:$false -Debug:$false -# Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false -# } catch { -# throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" -# } -# } + [DscProperty()] + [ValidateSet('UDP', 'TCP', 'UDP_TCP')] + [string]$Type = 'UDP' -# [void]Set() { -# $t = $null -# $t = $this.Init() -# $NSObject = $this.Get() -# try { -# Import-Module -Name Netscaler -Verbose:$false -Debug:$false -# Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false -# } catch { -# throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" -# } + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } -# try { -# switch ($this.Ensure) { -# 'Present' { -# if ($this.Ensure -eq $NSObject.Ensure) { -# if ($NSObject.Server -ne $this.Server) { -# Write-Warning -Message "The NTP server name cannot be set to [$($this.Server)], resource can only be removed and recreated" -# } -# if ($NSObject.MinPollInterval -ne $this.MinPollInterval) { -# Write-Verbose -Message "Setting Service Group MinPollInterval [$($this.MinPollInterval)]" -# Set-NSNTPServer -Server $this.Server -MinPollInterval $this.MinPollInterval -Verbose:$false -# } -# if ($NSObject.MaxPollInterval -ne $this.MaxPollInterval) { -# Write-Verbose -Message "Setting Service Group MaxPollInterval [$($this.MaxPollInterval)]" -# Set-NSNTPServer -Server $this.Server -MaxPollInterval $this.MaxPollInterval -Verbose:$false -# } -# if ($NSObject.PreferredNTPServer -ne $this.PreferredNTPServer) { -# Write-Warning -Message "The preferred NTP server cannot be set to [$($this.PreferredNTPServer)], setting can only be set manually" -# } -# } else { -# Write-Verbose -Message "Creating resource [$($this.Name)]" -# $params = @{ -# server = $this.Server -# minpoll = $this.MinPollInterval -# maxpoll = $this.MaxPollInterval -# preferredntpserver = $this.PreferredNTPServer -# } -# New-NSNTPServer @params -Verbose:$false -ErrorAction SilentlyContinue -# } -# } 'Absent' { -# if ($this.Ensure -ne $NSObject.Ensure) { -# Remove-NSNTPServer -Server $this.Server -ErrorAction SilentlyContinue -# Write-Verbose -Message "Removing resource: $($this.Server)" -# } -# } -# } -# } catch { -# Write-Error 'There was a problem setting the resource' -# Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" -# Write-Error $_ -# } -# try { -# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue -# } catch { -# # Do nothing -# } -# } + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() -# [bool]Test() { -# $pass = $true -# $t = $null -# $t = $this.Init() -# $NSObject = $this.Get() -# try { -# switch ($this.Ensure) { -# 'Present' { -# if ($this.Ensure -eq $NSObject.Ensure) { -# # Run tests and set any needed attributes to match desired configuration -# if ($NSObject.Server -ne $this.Server) { -# Write-Verbose -Message "Server does not match [$($NSObject.Server) <> $($this.Server)]" -# $pass = $false -# } -# if ($NSObject.MinPollInterval -ne $this.MinPollInterval) { -# Write-Verbose -Message "Min Poll Interval does not match [$($NSObject.MinPollInterval) <> $($this.MinPollInterval)]" -# $pass = $false -# } -# if ($NSObject.MaxPollInterval -ne $this.MaxPollInterval) { -# Write-Verbose -Message "Max Poll Interval does not match [$($NSObject.MaxPollInterval) <> $($this.MaxPollInterval)]" -# $pass = $false -# } -# if ($NSObject.PreferredNTPServer -ne $this.PreferredNTPServer) { -# Write-Verbose -Message "Preferred NTP Server does not match [$($NSObject.PreferredNTPServer) <> $($this.PreferredNTPServer)]" -# $pass = $false -# } -# } else { -# Write-Verbose -Message "Resource [$($this.Server)] was not found" -# $pass = $false -# } -# } -# 'Absent' { -# if ($this.Ensure -ne $NSObject.Ensure) { -# $pass = $false -# } -# } -# } -# } catch { -# Write-Error 'There was a problem testing the resource' -# Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" -# Write-Error $_ -# } -# try { -# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue -# } catch { -# # Do nothing -# } -# return $pass -# } + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if (($NSObject.ip -ne $this.IPAddress) -OR ($NSObject.state -ne $this.State) -OR ($NSObject.type -ne $this.Type)) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.Name)], resource can only be removed and recreated. Resource deleted and re-added" + Remove-NSDnsNameServer -IPAddress $this.IPAddress -Verbose:$false -ErrorAction SilentlyContinue + Add-NSDnsNameServer -IPAddress $this.IPAddress -State $this.State -Type $this.Type -Verbose:$false -ErrorAction SilentlyContinue + } + } else { + Write-Verbose -Message "Creating resource [$($this.IPAddress)]" + $params = @{ + ip = $this.IPAddress + type = $this.Type + state = $this.State + } + Add-NSDnsNameServer @params -Verbose:$false -ErrorAction SilentlyContinue + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSDnsNameServer -IPAddress $this.IPAddress -Verbose:$false -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed DNS Server: $($this.IPAddress)" + } + } + + } + Save-NSConfig + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } -# [LBNTPServer]Get() { -# $t = $null -# $t = $this.Init() + [bool]Test() { + $pass = $true + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + if ($NSObject.IPAddress -ne $this.IPAddress) { + Write-Verbose -Message "IP Address does not match [$($NSObject.IPAddress) <> $($this.IPAddress)]" + $pass = $false + } + if ($NSObject.Local -ne $this.Local) { + Write-Verbose -Message "Local does not match [$($NSObject.Local) <> $($this.Local)]" + $pass = $false + } + if ($NSObject.State -ne $this.State) { + Write-Verbose -Message "State does not match [$($NSObject.State) <> $($this.State)]" + $pass = $false + } + if ($NSObject.Type -ne $this.Type) { + Write-Verbose -Message "Type does not match [$($NSObject.Type) <> $($this.Type)]" + $pass = $false + } + } else { + Write-Verbose -Message "DNS server [$($this.IPAddress)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } -# try { -# $s = Get-NSNTPServer -Name $this.Server -Verbose:$false -ErrorAction SilentlyContinue -# } catch { -# $s = $null -# } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } -# $obj = [LBNTPServer]::new() -# $obj.Server = $this.Server -# $obj.MinPollInterval = $this.MinPollInterval -# $obj.MaxPollInterval = $this.MaxPollInterval -# $obj.PreferredNTPServer = $this.PreferredNTPServer -# if ($s) { -# $obj.Ensure = [ensure]::Present -# $obj.Server = $s.serverip -# $obj.MinPollInterval = $s.minpoll -# $obj.MaxPollInterval = $s.maxpoll -# $obj.PreferredNTPServer = $s.preferredntpserver -# } else { -# $obj.Ensure = [ensure]::Absent -# } -# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue -# return $obj -# } -# } + [LBDNSServer]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSDnsNameServer | where {$_.ip -eq $this.IPAddress} -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBDNSServer]::new() + $obj.IPAddress = $this.IPAddress + $obj.Local = $this.Local + $obj.State = $this.State + $obj.Type = $this.Type + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.IPAddress = $s.ip + $obj.Local = $s.local + $obj.State = $s.state + $obj.Type = $s.type + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} [DscResource()] -class LBResponderPolicy { +class LBNSMode { [DscProperty(Key)] [string]$Name @@ -1708,19 +3030,10 @@ class LBResponderPolicy { [Ensure]$Ensure = [Ensure]::Present [DscProperty(Mandatory)] - [string]$NetScalerFQDN - - [DscProperty(Mandatory)] - [pscredential]$Credential - - [DscProperty(Mandatory)] - [string]$Rule - - [DscProperty()] - [string]$Comment + [string]$NetScalerFQDN [DscProperty(Mandatory)] - [string]$Action + [pscredential]$Credential Init() { try { @@ -1747,39 +3060,23 @@ class LBResponderPolicy { switch ($this.Ensure) { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { - # Run tests and set any needed attributes to match desired configuration - if ($NSObject.Name -ne $this.Name) { - Write-Warning -Message "The Name cannot be changed to [$($this.Name)], resource can only be removed and recreated" - } - if ($NSObject.Rule -ne $this.Rule) { - Write-Verbose -Message "Setting Rule [$($this.Rule)]" - Set-NSResponderPolicy -Name $this.Name -Rule $this.Rule -Verbose:$false - } - if ($NSObject.Action -ne $this.Action) { - Write-Verbose -Message "Setting Service Group Name [$($this.MaxPollInterval)]" - Set-NSResponderPolicy -Name $this.Name -Action $this.Action -Verbose:$false + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne "True") { + Write-Verbose -Message "Mode enabled, [$($this.Name)]" + Enable-NSMode -name $this.name -Confirm:$false } - if ($NSObject.Comment -ne $this.Comment) { - Write-Verbose -Message "Setting monitor's Interval Type [$($this.Comment)]" - Set-NSResponderPolicy -Name $this.Name -Comment $this.Comment -Verbose:$false - } } else { - Write-Verbose -Message "Creating resource [$($this.Name)]" - $params = @{ - name = $this.Name - rule = $this.Rule - action = $this.Action - comment = $this.Comment - } - New-NSResponderPolicy @params -ErrorAction SilentlyContinue - } - } 'Absent' { - if ($this.Ensure -ne $NSObject.Ensure) { - Remove-NSResponderPolicy -Name $NSObject.Name -ErrorAction SilentlyContinue - Write-Verbose -Message "Removed Responder Policy: $($this.Name)" + Write-Verbose -Message "Mode enabled, [$($this.Name)]" + Enable-NSMode -name $this.name -Confirm:$false } - } - } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Disable-NSMode -Name $this.Name -Confirm:$false + Write-Verbose -Message "Mode disabled: $($this.Name)" + } + } + } + Save-NSConfig } catch { Write-Error 'There was a problem setting the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" @@ -1792,6 +3089,7 @@ class LBResponderPolicy { } } + [bool]Test() { $pass = $true $t = $null @@ -1801,30 +3099,24 @@ class LBResponderPolicy { switch ($this.Ensure) { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { - # Run tests and set any needed attributes to match desired configuration - if ($NSObject.Name -ne $this.Name) { - Write-Verbose -Message "Name does not match [$($NSObject.Name) <> $($this.Name)]" - $pass = $false - } - if ($NSObject.Rule -ne $this.Rule) { - Write-Verbose -Message "Rule does not match [$($NSObject.Rule) <> $($this.Rule)]" - $pass = $false - } - if ($NSObject.Action -ne $this.Action) { - Write-Verbose -Message "Action does not match [$($NSObject.Action) <> $($this.Action)]" + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne "True") { + Write-Verbose -Message "Mode is not set [$($NSObject.Name) <> $($this.Name)]" $pass = $false } } else { - Write-Verbose -Message "Responder Policy [$($this.Name)] was not found" $pass = $false } - } - 'Absent' { + } 'Absent' { if ($this.Ensure -ne $NSObject.Ensure) { $pass = $false + } else { + if ($NSObject.Name -eq "True") { + $pass = $false + } } - } - } + } + } } catch { Write-Error 'There was a problem testing the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" @@ -1835,28 +3127,24 @@ class LBResponderPolicy { } catch { # Do nothing } - return $pass + return $pass } - [LBResponderPolicy]Get() { + [LBNSMode]Get() { $t = $null $t = $this.Init() try { - $s = Get-NSResponderPolicy -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + $s = Get-NSMode -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue } catch { $s = $null } - $obj = [LBResponderPolicy]::new() - $obj.Name = $this.Name - $obj.Rule = $this.Rule - $obj.Action = $this.Action + $obj = [LBNSMode]::new() + $obj.Name = $this.Name if ($s) { - $obj.Ensure = [ensure]::Present - $obj.Name = $s.name - $obj.Rule = $s.rule - $obj.Action = $s.action.toString() + $obj.Ensure = [ensure]::Present + $obj.Name = $s } else { $obj.Ensure = [ensure]::Absent } @@ -1866,7 +3154,7 @@ class LBResponderPolicy { } [DscResource()] -class LBResponderAction { +class LBNSFeature { [DscProperty(Key)] [string]$Name @@ -1874,33 +3162,11 @@ class LBResponderAction { [Ensure]$Ensure = [Ensure]::Present [DscProperty(Mandatory)] - [string]$NetScalerFQDN - + [string]$NetScalerFQDN + [DscProperty(Mandatory)] [pscredential]$Credential - [DscProperty()] - [ValidateSet('NOOP','Redirect','RespondWith', 'RespondWithSQLOK','RespondWithSQLError','RespondWithHTMLPage')] - [string]$Type = 'NOOP' - - [DscProperty()] - [ValidateLength(0, 8191)] - [Alias('Expression')] - [string]$Target = [string]::Empty - - [DscProperty()] - [ValidateRange(100, 599)] - [int]$ResponseStatusCode - - [DscProperty()] - [ValidateLength(0, 8191)] - [string]$ReasonPhrase = [string]::Empty - - [DscProperty()] - [ValidateLength(0, 256)] - [string]$Comment = [string]::Empty - - Init() { try { Import-Module -Name Netscaler -Verbose:$false -Debug:$false @@ -1926,39 +3192,23 @@ class LBResponderAction { switch ($this.Ensure) { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { - # Run tests and set any needed attributes to match desired configuration - if ($NSObject.Name -ne $this.Name) { - Write-Verbose -Message "Warning, resource cannot be changed to [$($this.Name)], resource can only be removed and recreated" - } - if ($NSObject.Type -ne $this.Type) { - Write-Verbose -Message "Setting Responder Action [$($this.Type)]" - Set-NSResponderAction -Name $this.Name -Type $this.Type -Verbose:$false - } - if ($NSObject.Target -ne $this.Target) { - Write-Verbose -Message "Setting Responder Action [$($this.Target)]" - Set-NSResponderAction -Name $this.Name -Target $this.Target -Verbose:$false - } - if ($NSObject.Comment -ne $this.Comment) { - Write-Verbose -Message "Setting Responder Action [$($this.Comment)]" - Set-NSResponderAction -Name $this.Name -Comment $this.Comment -Verbose:$false - } - } else { - Write-Verbose -Message "Creating resource [$($this.Name)]" - $params = @{ - name = $this.Name - type = $this.Type - target = $this.Target - comment = $this.Comment + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne "True") { + Write-Verbose -Message "Feature enabled, [$($this.Name)]" + Enable-NSFeature -name $this.name -Confirm:$false } - New-NSResponderAction @params -ErrorAction SilentlyContinue - } - } 'Absent' { - if ($this.Ensure -ne $NSObject.Ensure) { - Remove-NSResponderAction -Name $NSObject.Name -ErrorAction SilentlyContinue - Write-Verbose -Message "Removed Responder Action: $($this.Name)" + } else { + Write-Verbose -Message "Feature enabled, [$($this.Name)]" + Enable-NSFeature -name $this.name -Confirm:$false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Disable-NSFeature -Name $this.Name -Confirm:$false + Write-Verbose -Message "Feature disabled: $($this.Name)" } - } - } + } + } + Save-NSConfig } catch { Write-Error 'There was a problem setting the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" @@ -1971,6 +3221,7 @@ class LBResponderAction { } } + [bool]Test() { $pass = $true $t = $null @@ -1980,30 +3231,24 @@ class LBResponderAction { switch ($this.Ensure) { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { - # Run tests and set any needed attributes to match desired configuration - if ($NSObject.Name -ne $this.Name) { - Write-Verbose -Message "Name does not match [$($NSObject.Name) <> $($this.Name)]" - $pass = $false - } - if ($NSObject.Type -ne $this.Type) { - Write-Verbose -Message "Type does not match [$($NSObject.Type) <> $($this.Type)]" - $pass = $false - } - if ($NSObject.Target -ne $this.Target) { - Write-Verbose -Message "Target does not match [$($NSObject.Target) <> $($this.Target)]" + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.Name -ne "True") { + Write-Verbose -Message "Feature is not set [$($NSObject.Name) <> $($this.Name)]" $pass = $false } } else { - Write-Verbose -Message "Responder Action [$($this.Name)] was not found" $pass = $false } - } - 'Absent' { + } 'Absent' { if ($this.Ensure -ne $NSObject.Ensure) { $pass = $false + } else { + if ($NSObject.Name -eq "True") { + $pass = $false + } } - } - } + } + } } catch { Write-Error 'There was a problem testing the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" @@ -2014,30 +3259,24 @@ class LBResponderAction { } catch { # Do nothing } - return $pass + return $pass } - [LBResponderAction]Get() { + [LBNSFeature]Get() { $t = $null $t = $this.Init() try { - $s = Get-NSResponderAction -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + $s = Get-NSFeature -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue } catch { $s = $null } - $obj = [LBResponderAction]::new() - $obj.Name = $this.Name - $obj.Type = $this.Type - $obj.Target = $this.Target - $obj.Comment = $this.Comment + $obj = [LBNSFeature]::new() + $obj.Name = $this.Name if ($s) { - $obj.Ensure = [ensure]::Present - $obj.Name = $s.name - $obj.Type = $s.type - $obj.Target = $s.target - $obj.Comment = $s.comment + $obj.Ensure = [ensure]::Present + $obj.Name = $s.name } else { $obj.Ensure = [ensure]::Absent } @@ -2047,32 +3286,31 @@ class LBResponderAction { } [DscResource()] -class LBRewritePolicy { +class LBSSLCertificate { [DscProperty(Key)] - [string]$Name + [string]$CertKeyName [DscProperty()] [Ensure]$Ensure = [Ensure]::Present [DscProperty(Mandatory)] - [string]$NetScalerFQDN - + [string]$NetScalerFQDN + [DscProperty(Mandatory)] [pscredential]$Credential [DscProperty()] - [string]$ActionName + [string]$CertPath [DscProperty()] - [string]$LogActionName + [string]$KeyPath [DscProperty()] - [ValidateLength(0, 8191)] - [Alias('Expression')] - [string]$Rule + [string]$CertKeyFormat + + # [DscProperty()] + # [securestring]$Password - [DscProperty()] - [string]$Comment Init() { try { @@ -2100,47 +3338,37 @@ class LBRewritePolicy { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { # Run tests and set any needed attributes to match desired configuration - if ($NSObject.name -ne $this.Name) { - Write-Verbose -Message "Warning, resource cannot be changed to [$($this.Name)], resource can only be removed and recreated" - } - if ($NSObject.rule -ne $this.Rule) { - Write-Verbose -Message "Setting Rule [$($this.Rule)]" - Set-NSRewritePolicy -Name $this.Name -Rule $this.Rule -Verbose:$false - } - if ($NSObject.actionname -ne $this.ActionName) { - Write-Verbose -Message "Setting Action Name [$($this.ActionName)]" - Set-NSRewritePolicy -Name $this.Name -ActionName $this.ActionName -LogActionName $this.LogActionName -Rule $this.Rule -Verbose:$false - } - if ($NSObject.logActionname -ne "Use Global") { - if ($NSObject.logactionname -ne $this.LogActionName) { - Write-Verbose -Message "Setting LogActionName [$($this.LogActionName)]" - Set-NSRewritePolicy -Name $this.Name -LogActionName $this.LogActionName -Verbose:$false - } - } - if ($NSObject.Comment -ne $this.Comment) { - Write-Verbose -Message "Setting Comment [$($this.Comment)]" - Set-NSRewritePolicy -Name $this.Name -Comment $this.Comment -Verbose:$false + if (($NSObject.CertKeyName -ne $this.CertKeyName) -OR ($NSObject.CertPath -ne $this.CertPath) -OR ($NSObject.KeyPath -ne $this.KeyPath) -OR ($NSObject.CertKeyFormat -ne $this.CertKeyFormat)) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.CertKeyName)], resource can only be removed and recreated" + Remove-NSCertKeyPair -CertKeyName $this.CertKeyName } } else { - Write-Verbose -Message "Creating resource [$($this.Name)]" + Write-Verbose -Message "Creating resource [$($this.CertKeyName)]" $params = @{ - name = $this.Name - rule = $this.Rule - actionname = $this.ActionName - comment = $this.Comment + CertKeyName = $this.CertKeyName + CertPath = $this.CertPath + CertKeyFormat = $this.CertKeyFormat } - if ($PSBoundParameters.ContainsKey('LogActionName')) { - $params.Add('LogActionName', $this.LogActionName) - } - New-NSRewritePolicy @params -ErrorAction SilentlyContinue - } - } 'Absent' { - if ($this.Ensure -ne $NSObject.Ensure) { - Remove-NSRewritePolicy -Name $NSObject.Name -ErrorAction SilentlyContinue - Write-Verbose -Message "Removed Rewrite Policy: $($this.Name)" + if ($PSBoundParameters.ContainsKey('KeyPath')) { + $params.Add('KeyPath', $this.KeyPath) + } + # if ($PSBoundParameters.ContainsKey('CertKeyFormat')) { + # $params.Add('CertKeyFormat', $this.CertKeyFormat) + # } + if ($PSBoundParameters.ContainsKey('Password')) { + $params.Add('Password', $this.Password) + } + Add-NSCertKeyPair @params -ErrorAction SilentlyContinue + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSCertKeyPair -CertKeyName $this.CertKeyName -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Certificate: $($this.CertKeyName)" } } } + Save-NSConfig } catch { Write-Error 'There was a problem setting the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" @@ -2153,6 +3381,7 @@ class LBRewritePolicy { } } + [bool]Test() { $pass = $true $t = $null @@ -2162,31 +3391,23 @@ class LBRewritePolicy { switch ($this.Ensure) { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { - # Run tests and set any needed attributes to match desired configuration - if ($NSObject.Name -ne $this.Name) { - Write-Verbose -Message "Name does not match [$($NSObject.Name) <> $($this.Name)]" - $pass = $false - } - if ($NSObject.Rule -ne $this.Rule) { - Write-Verbose -Message "Rule does not match [$($NSObject.Rule) <> $($this.Rule)]" - $pass = $false - } - if ($NSObject.ActionName -ne $this.ActionName) { - Write-Verbose -Message "Action Name does not match [$($NSObject.ActionName) <> $($this.ActionName)]" - $pass = $false - } - if ($NSObject.LogActionName -ne "Use Global") { - if ($NSObject.LogActionName -ne $this.LogActionName) { - Write-Verbose -Message "Log Action Name does not match [$($NSObject.LogActionName) <> $($this.LogActionName)]" + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.certkeyname -ne $this.CertKeyName) { + Write-Verbose -Message "Certificate Key Name does not match [$($NSObject.certkeyname) <> $($this.CertKeyName)]" $pass = $false } - } - if ($NSObject.Comment -ne $this.Comment) { - Write-Verbose -Message "Comment does not match [$($NSObject.Comment) <> $($this.Comment)]" - $pass = $false - } + if ($NSObject.certpath -ne $this.CertPath) { + Write-Verbose -Message "Certificate Path does not match [$($NSObject.certpath) <> $($this.CertPath)]" + $pass = $false + } + if ($this.KeyPath) { + if ($NSObject.keypath -ne $this.KeyPath) { + Write-Verbose -Message "Key Path does not match [$($NSObject.keypath) <> $($this.KeyPath)]" + $pass = $false + } + } } else { - Write-Verbose -Message "Responder Policy [$($this.Name)] was not found" + Write-Verbose -Message "Certificate[$($this.CertKeyName)] was not found" $pass = $false } } @@ -2206,32 +3427,31 @@ class LBRewritePolicy { } catch { # Do nothing } - return $pass + return $pass } - [LBRewritePolicy]Get() { + [LBSSLCertificate]Get() { $t = $null $t = $this.Init() try { - $s = Get-NSRewritePolicy -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + $s = Get-NSCertKeyPair -CertKeyName $this.CertKeyName -Verbose:$false -ErrorAction SilentlyContinue } catch { $s = $null } - - $obj = [LBRewritePolicy]::new() - $obj.Name = $this.Name - $obj.Rule = $this.Rule - $obj.ActionName = $this.ActionName - $obj.LogActionName = $this.LogActionName - $obj.Comment = $this.Comment + $obj = [LBSSLCertificate]::new() + $obj.CertKeyName = $this.CertKeyName + $obj.CertPath = $this.CertPath + $obj.CertKeyFormat = $this.CertKeyFormat + $obj.KeyPath = $this.KeyPath if ($s) { $obj.Ensure = [ensure]::Present - $obj.Name = $s.name - $obj.Rule = $s.rule - $obj.ActionName = $s.action - $obj.LogActionName = $s.logaction - $obj.Comment = $s.comment + $obj.CertKeyName = $s.certkey.toString() + $obj.CertPath = $s.cert.toString() + $obj.CertKeyFormat = $s.inform.toString() + if ($s.key) { + $obj.KeyPath = $s.key.toString() + } } else { $obj.Ensure = [ensure]::Absent } @@ -2241,32 +3461,22 @@ class LBRewritePolicy { } [DscResource()] -class LBRewriteAction { +class LBSSLCertificateBinding { [DscProperty(Key)] - [string]$Name + [string]$VirtualServerName [DscProperty()] [Ensure]$Ensure = [Ensure]::Present [DscProperty(Mandatory)] - [string]$NetScalerFQDN - - [DscProperty(Mandatory)] - [pscredential]$Credential - - [DscProperty(Mandatory)] - [string]$Type - - [DscProperty(Mandatory)] - [ValidateLength(0, 8191)] - [string]$Target + [string]$NetScalerFQDN [DscProperty(Mandatory)] - [ValidateLength(0, 8191)] - [string]$Expression + [pscredential]$Credential [DscProperty()] - [string]$Comment + [string]$Certificate + Init() { try { @@ -2294,43 +3504,33 @@ class LBRewriteAction { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { # Run tests and set any needed attributes to match desired configuration - if ($NSObject.Name -ne $this.Name) { - Write-Verbose -Message "Warning, resource cannot be changed to [$($this.Name)], resource can only be removed and recreated" - } - if ($NSObject.Type -ne $this.Type) { - Write-Verbose -Message "Setting Rule [$($this.Type)]" - Set-NSRewriteAction -Name $this.Name -Type $this.Type -Target $this.Target -Expression $this.Expression -Comment $this.Comment -Verbose:$false - } - if ($NSObject.Target -ne $this.Target) { - Write-Verbose -Message "Setting Action Name [$($this.Target)]" - Set-NSRewriteAction -Name $this.Name -Target $this.Target -Verbose:$false - } - if ($NSObject.Expression -ne $this.Expression) { - Write-Verbose -Message "Setting LogActionName [$($this.Expression)]" - Set-NSRewriteAction -Name $this.Name -Expression $this.Expression -Verbose:$false + if ($NSObject.virtualservername -ne $this.VirtualServerName) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.VirtualServerName)], resource can only be removed and recreated" + Remove-NSLBSSLVirtualServerCertificateBinding -VirtualServerName $this.VirtualServerName -Certificate $this.Certificate + Add-NSLBSSLVirtualServerCertificateBinding -VirtualServerName $this.VirtualServerName -Certificate $this.Certificate } - if ($NSObject.Comment -ne $this.Comment) { - Write-Verbose -Message "Setting Comment [$($this.Comment)]" - Set-NSRewriteAction -Name $this.Name -Comment $this.Comment -Verbose:$false + if ($NSObject.Certificate -ne $this.Certificate) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.Certificate)], resource can only be removed and recreated" + Remove-NSLBSSLVirtualServerCertificateBinding -VirtualServerName $this.VirtualServerName -Certificate $this.Certificate + Add-NSLBSSLVirtualServerCertificateBinding -VirtualServerName $this.VirtualServerName -Certificate $this.Certificate } } else { - Write-Verbose -Message "Creating resource [$($this.Name)]" + Write-Verbose -Message "Creating resource [$($this.CertKeyName)]" $params = @{ - name = $this.Name - Type = $this.Type.toLower() - Target = $this.Target - Expression = $this.Expression - Comment = $this.Comment + VirtualServerName = $this.VirtualServerName + Certificate = $this.Certificate } - New-NSRewriteAction @params -ErrorAction SilentlyContinue - } - } 'Absent' { - if ($this.Ensure -ne $NSObject.Ensure) { - Remove-NSRewriteAction -Name $NSObject.Name -ErrorAction SilentlyContinue - Write-Verbose -Message "Removed Rewrite Action: $($this.Name)" + Add-NSLBSSLVirtualServerCertificateBinding @params -ErrorAction SilentlyContinue + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSLBSSLVirtualServerCertificateBinding -VirtualServerName $this.VirtualServerName -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Binding of: $($this.VirtualServerName)" } } } + Save-NSConfig } catch { Write-Error 'There was a problem setting the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" @@ -2343,6 +3543,7 @@ class LBRewriteAction { } } + [bool]Test() { $pass = $true $t = $null @@ -2353,28 +3554,16 @@ class LBRewriteAction { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { # Run tests and set any needed attributes to match desired configuration - if ($NSObject.name -ne $this.Name) { - Write-Verbose -Message "Name does not match [$($NSObject.Name) <> $($this.Name)]" - $pass = $false - } - if ($NSObject.type -ne $this.Type) { - Write-Verbose -Message "Type does not match [$($NSObject.Type) <> $($this.Type)]" - $pass = $false - } - if ($NSObject.target -ne $this.Target) { - Write-Verbose -Message "Target does not match [$($NSObject.Target) <> $($this.Target)]" + if ($NSObject.virtualservername -ne $this.VirtualServerName) { + Write-Verbose -Message "Virtual Server Name Path does not match [$($NSObject.virtualservername) <> $($this.VirtualServerName)]" $pass = $false } - if ($NSObject.Expression -ne $this.Expression) { - Write-Verbose -Message "Expression does not match [$($NSObject.Expression) <> $($this.Expression)]" + if ($NSObject.certificate -ne $this.Certificate) { + Write-Verbose -Message "Certificate does not match [$($NSObject.certificate) <> $($this.Certificate)]" $pass = $false } - if ($NSObject.comment -ne $this.Comment) { - Write-Verbose -Message "Comment does not match [$($NSObject.Comment) <> $($this.Comment)]" - $pass = $false - } } else { - Write-Verbose -Message "Responder Action [$($this.Name)] was not found" + Write-Verbose -Message "Binding of Certificate[$($this.Certificate)] to VirtualServer[$($this.VirtualServerName)] was not found" $pass = $false } } @@ -2394,32 +3583,25 @@ class LBRewriteAction { } catch { # Do nothing } - return $pass + return $pass } - [LBRewriteAction]Get() { + [LBSSLCertificateBinding]Get() { $t = $null $t = $this.Init() try { - $s = Get-NSRewriteAction -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + $s = Get-NSCertKeyPair -CertKeyName $this.CertKeyName -Verbose:$false -ErrorAction SilentlyContinue } catch { $s = $null } - - $obj = [LBRewriteAction]::new() - $obj.Name = $this.Name - $obj.Type = $this.Type - $obj.Target = $this.Target - $obj.Expression = $this.Expression - $obj.Comment = $this.Comment + $obj = [LBSSLCertificateBinding]::new() + $obj.VirtualServerName = $this.VirtualServerName + $obj.Certificate = $this.Certificate if ($s) { $obj.Ensure = [ensure]::Present - $obj.Name = $s.name - $obj.Type = $s.type - $obj.Target = $s.target - $obj.Expression = $s.stringbuilderexpr - $obj.Comment = $s.comment + $obj.VirtualServerName = $s.certkey + $obj.Certificate = $s.certkey } else { $obj.Ensure = [ensure]::Absent } @@ -2429,30 +3611,21 @@ class LBRewriteAction { } [DscResource()] -class LBDNSServer { +class LBSSLCertificateLink { [DscProperty(Key)] - [string]$IPAddress + [string]$CertKeyName [DscProperty()] [Ensure]$Ensure = [Ensure]::Present [DscProperty(Mandatory)] - [string]$NetScalerFQDN - + [string]$NetScalerFQDN + [DscProperty(Mandatory)] [pscredential]$Credential - [DscProperty()] - [ValidateLength(0, 8191)] - [string]$Local = $false - - [DscProperty()] - [ValidateSet('ENABLED','DISABLED')] - [string]$State = 'ENABLED' - - [DscProperty()] - [ValidateSet('UDP', 'TCP', 'UDP_TCP')] - [string]$Type = 'UDP' + [DscProperty(Mandatory)] + [string]$IntermediateCertKeyName Init() { @@ -2481,28 +3654,33 @@ class LBDNSServer { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { # Run tests and set any needed attributes to match desired configuration - if (($NSObject.ip -ne $this.IPAddress) -OR ($NSObject.state -ne $this.State) -OR ($NSObject.type -ne $this.Type)) { - Write-Verbose -Message "Warning, resource cannot be changed to [$($this.Name)], resource can only be removed and recreated. Resource deleted and re-added" - Remove-NSDnsNameServer -IPAddress $this.IPAddress -Verbose:$false -ErrorAction SilentlyContinue - Add-NSDnsNameServer -IPAddress $this.IPAddress -State $this.State -Type $this.Type -Verbose:$false -ErrorAction SilentlyContinue + if ($NSObject.certkeyname -ne $this.CertKeyName) { + Write-Verbose -Message "Re-linking resource as [$($this.CertKeyName)], name does not match" + Remove-NSSSLCertificateLink -CertKeyName $this.CertKeyName -Verbose:$false -ErrorAction SilentlyContinue + Add-NSSSLCertificateLink -CertKeyName $this.CertKeyName -IntermediateCertKeyName $this.IntermediateCertKeyName -Verbose:$false -ErrorAction SilentlyContinue } - } else { - Write-Verbose -Message "Creating resource [$($this.IPAddress)]" + if ($NSObject.certkeyname -ne $this.IntermediateCertKeyName) { + Write-Verbose -Message "Re-linking resource as [$($this.IntermediateCertKeyName)], name does not match" + Remove-NSSSLCertificateLink -CertKeyName $this.CertKeyName -Verbose:$false -ErrorAction SilentlyContinue + Add-NSSSLCertificateLink -CertKeyName $this.CertKeyName -IntermediateCertKeyName $this.IntermediateCertKeyName -Verbose:$false -ErrorAction SilentlyContinue + } + } else { + Write-Verbose -Message "Creating resource [$($this.CertKeyName)]" $params = @{ - ip = $this.IPAddress - type = $this.Type - state = $this.State + CertKeyName = $this.CertKeyName + IntermediateCertKeyName = $this.IntermediateCertKeyName } - Add-NSDnsNameServer @params -Verbose:$false -ErrorAction SilentlyContinue + Add-NSSSLCertificateLink @params -ErrorAction SilentlyContinue } - } 'Absent' { + } + 'Absent' { if ($this.Ensure -ne $NSObject.Ensure) { - Remove-NSDnsNameServer -IPAddress $this.IPAddress -Verbose:$false -ErrorAction SilentlyContinue - Write-Verbose -Message "Removed DNS Server: $($this.IPAddress)" + Remove-NSSSLCertificateLink -CertKeyName $this.CertKeyName -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Binding of: $($this.CertKeyName)" } } - } + Save-NSConfig } catch { Write-Error 'There was a problem setting the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" @@ -2515,32 +3693,27 @@ class LBDNSServer { } } - [bool]Test() { + + [bool]Test() { $pass = $true + $t = $null $t = $this.Init() $NSObject = $this.Get() try { switch ($this.Ensure) { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { - if ($NSObject.IPAddress -ne $this.IPAddress) { - Write-Verbose -Message "IP Address does not match [$($NSObject.IPAddress) <> $($this.IPAddress)]" - $pass = $false - } - if ($NSObject.Local -ne $this.Local) { - Write-Verbose -Message "Local does not match [$($NSObject.Local) <> $($this.Local)]" - $pass = $false - } - if ($NSObject.State -ne $this.State) { - Write-Verbose -Message "State does not match [$($NSObject.State) <> $($this.State)]" - $pass = $false - } - if ($NSObject.Type -ne $this.Type) { - Write-Verbose -Message "Type does not match [$($NSObject.Type) <> $($this.Type)]" - $pass = $false - } + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.certkeyname -ne $this.CertKeyName) { + Write-Verbose -Message "CertKey does not match [$($NSObject.certkeyname) <> $($this.CertKeyName)]" + $pass = $false + } + if ($NSObject.intermediatecertKeyname -ne $this.IntermediateCertKeyName) { + Write-Verbose -Message "Certificate Link does not match [$($NSObject.linkcertkeyname) <> $($this.IntermediateCertKeyName)]" + $pass = $false + } } else { - Write-Verbose -Message "DNS server [$($this.IPAddress)] was not found" + Write-Verbose -Message "Binding of CertKey [$($this.IntermediateCertKeyName)] to VirtualServer[$($this.CertKeyName)] was not found" $pass = $false } } @@ -2549,7 +3722,6 @@ class LBDNSServer { $pass = $false } } - } } catch { Write-Error 'There was a problem testing the resource' @@ -2561,30 +3733,25 @@ class LBDNSServer { } catch { # Do nothing } - return $pass + return $pass } - [LBDNSServer]Get() { + [LBSSLCertificateLink]Get() { $t = $null $t = $this.Init() try { - $s = Get-NSDnsNameServer | where {$_.ip -eq $this.IPAddress} -Verbose:$false -ErrorAction SilentlyContinue + $s = Get-NSSSLCertificateLink -CertKeyName $this.CertKeyName -Verbose:$false -ErrorAction SilentlyContinue } catch { $s = $null } - - $obj = [LBDNSServer]::new() - $obj.IPAddress = $this.IPAddress - $obj.Local = $this.Local - $obj.State = $this.State - $obj.Type = $this.Type + $obj = [LBSSLCertificateLink]::new() + $obj.CertKeyName = $this.CertKeyName + $obj.IntermediateCertKeyName = $this.IntermediateCertKeyName if ($s) { $obj.Ensure = [ensure]::Present - $obj.IPAddress = $s.ip - $obj.Local = $s.local - $obj.State = $s.state - $obj.Type = $s.type + $obj.CertKeyName = $s.certkeyname + $obj.IntermediateCertKeyName = $s.linkcertkeyname } else { $obj.Ensure = [ensure]::Absent } @@ -2594,7 +3761,7 @@ class LBDNSServer { } [DscResource()] -class LBNSMode { +class LBSSLProfile { [DscProperty(Key)] [string]$Name @@ -2602,11 +3769,54 @@ class LBNSMode { [Ensure]$Ensure = [Ensure]::Present [DscProperty(Mandatory)] - [string]$NetScalerFQDN - + [string]$NetScalerFQDN + [DscProperty(Mandatory)] [pscredential]$Credential + [DscProperty()] + [ValidateSet('NO','FRONTEND_CLIENT','FRONTENT_CLIENTSERVER','ALL','NONSECURE')] + [string]$DenySslRenegotiation + + [DscProperty()] + [ValidateSet('FrontEnd','BackEnd')] + [string]$ProfileType + + [DscProperty()] + [ValidateSet('ENABLED','DISABLED')] + [string]$SSL2 + + [DscProperty()] + [ValidateSet('ENABLED','DISABLED')] + [string]$SSL3 + + [DscProperty()] + [ValidateSet('ENABLED','DISABLED')] + [string]$TLS1 + + [DscProperty()] + [ValidateSet('ENABLED','DISABLED')] + [string]$TLS11 + + [DscProperty()] + [ValidateSet('ENABLED','DISABLED')] + [string]$TLS12 + + [DscProperty()] + [ValidateSet('ENABLED','DISABLED')] + [string]$DH + + [DscProperty()] + [string]$DHFile + + [DscProperty()] + [ValidateRange(0,65534)] + [int]$DHCount + + [DscProperty()] + [ValidateSet('ENABLED','DISABLED')] + [string]$DHKeyExpSizeLimit + Init() { try { Import-Module -Name Netscaler -Verbose:$false -Debug:$false @@ -2632,22 +3842,86 @@ class LBNSMode { switch ($this.Ensure) { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { - # Run tests and set any needed attributes to match desired configuration - if ($NSObject.Name -ne "True") { - Write-Verbose -Message "Mode enabled, [$($this.Name)]" - Enable-NSMode -name $this.name -Confirm:$false + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.name -ne $this.Name) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.Name)], resource can only be removed and recreated" + } + if (($NSObject.denysslrenegotiation) -AND ($NSObject.denysslrenegotiation -ne $this.DenySslRenegotiation)) { + Write-Verbose -Message "Setting DenySslRenegotiation [$($this.DenySslRenegotiation)]" + Set-NSSSLProfile -Name $this.Name -DenySslRenegotiation $this.DenySslRenegotiation -Verbose:$false + } + if ($NSObject.profiletype -ne $this.ProfileType) { + Write-Verbose -Message "Setting ProfileType [$($this.ProfileType)]" + Set-NSSSLProfile -Name $this.Name -ProfileType $this.ProfileType -Verbose:$false + } + if (($NSObject.ssl2) -AND ($NSObject.ssl2 -ne $this.SSL2)) { + Write-Verbose -Message "Setting SSL2 [$($this.SSL2)]" + Set-NSSSLProfile -Name $this.Name -SSL2 $this.SSL2 -Verbose:$false + } + if (($NSObject.ssl3) -AND ($NSObject.ssl3 -ne $this.SSL3)) { + Write-Verbose -Message "Setting SSL3 [$($this.SSL3)]" + Set-NSSSLProfile -Name $this.Name -SSL3 $this.SSL3 -Verbose:$false + } + if (($NSObject.tls1) -AND ($NSObject.tls1 -ne $this.TLS1)) { + Write-Verbose -Message "Setting TLS1 [$($this.TLS1)]" + Set-NSSSLProfile -Name $this.Name -TLS1 $this.TLS1 -Verbose:$false + } + if (($NSObject.tls11) -AND ($NSObject.tls11 -ne $this.TLS11)) { + Write-Verbose -Message "Setting TLS11 [$($this.TLS11)]" + Set-NSSSLProfile -Name $this.Name -TLS11 $this.TLS11 -Verbose:$false + } + if (($NSObject.tls12) -AND ($NSObject.tls12 -ne $this.TLS12)) { + Write-Verbose -Message "Setting TLS12 [$($this.TLS12)]" + Set-NSSSLProfile -Name $this.Name -TLS12 $this.TLS12 -Verbose:$false + } + if (($NSObject.dh) -AND ($NSObject.dh -ne $this.DH)) { + Write-Verbose -Message "Setting DH [$($this.DH)]" + Set-NSSSLProfile -Name $this.Name -DH $this.DH -Verbose:$false + } + if (($NSObject.dhfile) -AND ($NSObject.dhfile -ne $this.DHFile)) { + Write-Verbose -Message "Setting DHFile [$($this.DHFile)]" + Set-NSSSLProfile -Name $this.Name -DHFile $this.DHFile -Verbose:$false + } + if (($NSObject.dhcount) -AND ($NSObject.dhcount -ne $this.DHCount)) { + Write-Verbose -Message "Setting DHCount [$($this.DHCount)]" + Set-NSSSLProfile -Name $this.Name -DHCount $this.DHCount -Verbose:$false + } + if (($NSObject.dhkeyexpsizelimit) -AND ($NSObject.dhkeyexpsizelimit -ne $this.DHKeyExpSizeLimit)) { + Write-Verbose -Message "Setting DHKeyExpSizeLimit [$($this.DHKeyExpSizeLimit)]" + Set-NSSSLProfile -Name $this.Name -DHKeyExpSizeLimit $this.DHKeyExpSizeLimit -Verbose:$false + } + if (($NSObject.denysslrenegotiation) -AND ($NSObject.DenySslRenegotiation -ne $this.DenySslRenegotiation)) { + Write-Verbose -Message "Setting DenySslRenegotiation [$($this.DenySslRenegotiation)]" + Set-NSSSLProfile -Name $this.Name -DenySslRenegotiation $this.DenySslRenegotiation -Verbose:$false } } else { - Write-Verbose -Message "Mode enabled, [$($this.Name)]" - Enable-NSMode -name $this.name -Confirm:$false + Write-Verbose -Message "Creating resource [$($this.Name)]" + $params = @{ + Name = $this.Name + ProfileType = $this.ProfileType + } + if ($PSBoundParameters.ContainsKey('SSL2')) { $params.Add('ssl2', $this.SSL2) } + if ($PSBoundParameters.ContainsKey('SSL3')) { $params.Add('ssl3', $this.SSL3) } + if ($PSBoundParameters.ContainsKey('TLS1')) { $params.Add('tls1', $this.TLS1) } + if ($PSBoundParameters.ContainsKey('TLS11')) { $params.Add('tls11', $this.TLS11) } + if ($PSBoundParameters.ContainsKey('TLS12')) { $params.Add('tls12', $this.TLS12) } + if ($PSBoundParameters.ContainsKey('DH')) { $params.Add('dh', $this.DH) } + if ($PSBoundParameters.ContainsKey('DHFile')) { $params.Add('dhfile', $this.DHFile) } + if ($PSBoundParameters.ContainsKey('DHCount')) { $params.Add('dhcount', $this.DHCount) } + if ($PSBoundParameters.ContainsKey('DHKeyExpSizeLimit')) { $params.Add('dhkeyexpsizelimit', $this.DHKeyExpSizeLimit) } + if ($PSBoundParameters.ContainsKey('DenySslRenegotiation')) { $params.Add('denysslrenegotiation', $this.DenySslRenegotiation) } + + New-NSSSLProfile @params -ErrorAction SilentlyContinue } - } 'Absent' { + } + 'Absent' { if ($this.Ensure -ne $NSObject.Ensure) { - Disable-NSMode -Name $this.Name -Confirm:$false - Write-Verbose -Message "Mode disabled: $($this.Name)" + Remove-NSSSLProfile -Name $this.Name -force -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed SSL Profile: $($this.Name)" } - } - } + } + } + Save-NSConfig } catch { Write-Error 'There was a problem setting the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" @@ -2670,24 +3944,70 @@ class LBNSMode { switch ($this.Ensure) { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { - # Run tests and set any needed attributes to match desired configuration - if ($NSObject.Name -ne "True") { - Write-Verbose -Message "Mode is not set [$($NSObject.Name) <> $($this.Name)]" + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.name -ne $this.Name) { + Write-Verbose -Message "Name does not match [$($NSObject.name) <> $($this.Name)]" + $pass = $false + } + if (($NSObject.denysslrenegotiation) -AND ($NSObject.denysslrenegotiation -ne $this.DenySslRenegotiation)) { + Write-Verbose -Message "DenySslRenegotiation does not match [$($NSObject.DenySslRenegotiation) <> $($this.DenySslRenegotiation)]" + $pass = $false + } + if ($NSObject.profiletype -ne $this.ProfileType) { + Write-Verbose -Message "ProfileType does not match [$($NSObject.profiletype) <> $($this.ProfileType)]" + $pass = $false + } + if (($NSObject.ssl2) -AND ($NSObject.ssl2 -ne $this.SSL2)) { + Write-Verbose -Message "SSL2 does not match [$($NSObject.ssl2) <> $($this.SSL2)]" + $pass = $false + } + if (($NSObject.ssl3) -AND ($NSObject.ssl3 -ne $this.SSL3)) { + Write-Verbose -Message "SSL3 does not match [$($NSObject.ssl3) <> $($this.SSL3)]" + $pass = $false + } + if (($NSObject.tls1) -AND ($NSObject.tls1 -ne $this.TLS1)) { + Write-Verbose -Message "TLS1 does not match [$($NSObject.tls1) <> $($this.TLS1)]" + $pass = $false + } + if (($NSObject.tls11) -AND ($NSObject.tls11 -ne $this.TLS11)) { + Write-Verbose -Message "TLS11 does not match [$($NSObject.tls11) <> $($this.TLS11)]" + $pass = $false + } + if (($NSObject.tls12) -AND ($NSObject.tls12 -ne $this.TLS12)) { + Write-Verbose -Message "TLS12 does not match [$($NSObject.tls12) <> $($this.TLS12)]" + $pass = $false + } + if (($NSObject.dh) -AND ($NSObject.dh -ne $this.DH)) { + Write-Verbose -Message "DH does not match [$($NSObject.dh) <> $($this.DH)]" + $pass = $false + } + if (($NSObject.dhfile) -AND ($NSObject.dhfile -ne $this.DHFile)) { + Write-Verbose -Message "DHFile does not match [$($NSObject.dhfile) <> $($this.DHFile)]" + $pass = $false + } + if (($NSObject.dhcount) -AND ($NSObject.dhcount -ne $this.DHCount)) { + Write-Verbose -Message "DHCount does not match [$($NSObject.dhcount) <> $($this.DHCount)]" + $pass = $false + } + if (($NSObject.dhkeyexpsizelimit) -AND ($NSObject.dhkeyexpsizelimit -ne $this.DHKeyExpSizeLimit)) { + Write-Verbose -Message "DHKeyExpSizeLimit does not match [$($NSObject.dhkeyexpsizelimit) <> $($this.DHKeyExpSizeLimit)]" + $pass = $false + } + if (($NSObject.denysslrenegotiation) -AND ($NSObject.DenySslRenegotiation -ne $this.DenySslRenegotiation)) { + Write-Verbose -Message "Deny SSL Renegotiation does not match [$($NSObject.denysslrenegotiation) <> $($this.DenySslRenegotiation)]" $pass = $false } } else { + Write-Verbose -Message "SSL Profile [$($this.Name)] was not found" $pass = $false } - } 'Absent' { + } + 'Absent' { if ($this.Ensure -ne $NSObject.Ensure) { $pass = $false - } else { - if ($NSObject.Name -eq "True") { - $pass = $false - } } - } - } + } + } } catch { Write-Error 'There was a problem testing the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" @@ -2698,24 +4018,47 @@ class LBNSMode { } catch { # Do nothing } - return $pass + return $pass } - [LBNSMode]Get() { + [LBSSLProfile]Get() { $t = $null $t = $this.Init() try { - $s = Get-NSMode -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + $s = Get-NSSSLProfile -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue } catch { $s = $null } - - $obj = [LBNSMode]::new() - $obj.Name = $this.Name + $obj = [LBSSLProfile]::new() + $obj.Name = $this.Name + $obj.DenySslRenegotiation = $this.DenySslRenegotiation + $obj.ProfileType = $this.ProfileType + $obj.SSL2 = $this.SSL2 + $obj.SSL3 = $this.SSL3 + $obj.TLS1 = $this.TLS1 + $obj.TLS11 = $this.TLS11 + $obj.TLS12 = $this.TLS12 + $obj.DH = $this.DH + $obj.DHFile = $this.DHFile + $obj.DHCount = $this.DHCount + $obj.DHKeyExpSizeLimit = $this.DHKeyExpSizeLimit + $obj.DenySslRenegotiation = $this.DenySslRenegotiation if ($s) { - $obj.Ensure = [ensure]::Present - $obj.Name = $s + $obj.Ensure = [ensure]::Present + $obj.Name = $s.name + $obj.DenySslRenegotiation = $s.denysslreneg + $obj.ProfileType = $s.sslprofiletype + if ($s.ssl2) { $obj.SSL2 = $s.ssl2 } + if ($s.ssl3) { $obj.SSL3 = $s.ssl3 } + if ($s.tls1) { $obj.TLS1 = $s.tls1 } + if ($s.tls11) { $obj.TLS11 = $s.tls11 } + if ($s.tls12) { $obj.TLS12 = $s.tls12 } + if ($s.dh) { $obj.DH = $s.dh } + if ($s.dhfile) { $obj.DHFile = $s.dhfile } + if ($s.dhcount) { $obj.DHCount = $s.dhcount } + if ($s.dhkeyexpsizelimit) { $obj.DHKeyExpSizeLimit = $s.dhkeyexpsizelimit } + if ($s.denysslreneg) { $obj.DenySslRenegotiation = $s.denysslreneg } } else { $obj.Ensure = [ensure]::Absent } @@ -2725,7 +4068,7 @@ class LBNSMode { } [DscResource()] -class LBNSFeature { +class LBSSLProfileBinding { [DscProperty(Key)] [string]$Name @@ -2733,11 +4076,14 @@ class LBNSFeature { [Ensure]$Ensure = [Ensure]::Present [DscProperty(Mandatory)] - [string]$NetScalerFQDN - + [string]$NetScalerFQDN + [DscProperty(Mandatory)] [pscredential]$Credential + [DscProperty()] + [string]$SSLProfile + Init() { try { Import-Module -Name Netscaler -Verbose:$false -Debug:$false @@ -2763,22 +4109,37 @@ class LBNSFeature { switch ($this.Ensure) { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { - # Run tests and set any needed attributes to match desired configuration - if ($NSObject.Name -ne "True") { - Write-Verbose -Message "Feature enabled, [$($this.Name)]" - Enable-NSFeature -name $this.name -Confirm:$false + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.name -ne $this.Name) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.Name)], resource can only be removed and recreated" + } + if ($NSObject.sslprofile -ne $this.SSLProfile) { + Write-Verbose -Message "Setting SSLProfile [$($this.SSLProfile)]" + Set-NSLBSSLVirtualServer -Name $this.Name -SSLProfile $this.SSLProfile -Verbose:$false } } else { - Write-Verbose -Message "Feature enabled, [$($this.Name)]" - Enable-NSFeature -name $this.name -Confirm:$false + Write-Verbose -Message "Creating resource [$($this.Name)]" + $params = @{ + Name = $this.Name + sslprofile = $this.SSLProfile + } + + Set-NSLBSSLVirtualServer @params -ErrorAction SilentlyContinue } - } 'Absent' { + } + 'Absent' { if ($this.Ensure -ne $NSObject.Ensure) { - Disable-NSFeature -Name $this.Name -Confirm:$false - Write-Verbose -Message "Feature disabled: $($this.Name)" + Write-Verbose -Message "Removed resource [$($this.Name)]" + $params = @{ + Name = $this.Name + sslprofile = $this.SSLProfile + } + + Set-NSLBSSLVirtualServer @params -ErrorAction SilentlyContinue } - } - } + } + } + Save-NSConfig } catch { Write-Error 'There was a problem setting the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" @@ -2801,24 +4162,26 @@ class LBNSFeature { switch ($this.Ensure) { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { - # Run tests and set any needed attributes to match desired configuration - if ($NSObject.Name -ne "True") { - Write-Verbose -Message "Feature is not set [$($NSObject.Name) <> $($this.Name)]" + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.name -ne $this.Name) { + Write-Verbose -Message "Name does not match [$($NSObject.name) <> $($this.Name)]" + $pass = $false + } + if ($NSObject.sslprofile -ne $this.SSLProfile) { + Write-Verbose -Message "SSLProfile does not match [$($NSObject.sslprofile) <> $($this.SSLProfile)]" $pass = $false } } else { + Write-Verbose -Message "SSL Profile [$($this.Name)] was not found" $pass = $false } - } 'Absent' { + } + 'Absent' { if ($this.Ensure -ne $NSObject.Ensure) { $pass = $false - } else { - if ($NSObject.Name -eq "True") { - $pass = $false - } } - } - } + } + } } catch { Write-Error 'There was a problem testing the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" @@ -2829,24 +4192,25 @@ class LBNSFeature { } catch { # Do nothing } - return $pass + return $pass } - [LBNSFeature]Get() { + [LBSSLProfileBinding]Get() { $t = $null $t = $this.Init() try { - $s = Get-NSFeature -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + $s = Get-NSSSLProfile -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue } catch { $s = $null } - - $obj = [LBNSFeature]::new() - $obj.Name = $this.Name + $obj = [LBSSLProfileBinding]::new() + $obj.Name = $this.Name + $obj.SSLProfile = $this.SSLProfile if ($s) { - $obj.Ensure = [ensure]::Present - $obj.Name = $s.name + $obj.Ensure = [ensure]::Present + $obj.Name = $s.name + $obj.SSLProfile = $s.sslprofile } else { $obj.Ensure = [ensure]::Absent } @@ -2855,31 +4219,26 @@ class LBNSFeature { } } - - [DscResource()] -class LBSSLCertificate { +class LBResponderHTMLPage { [DscProperty(Key)] - [string]$CertKeyName + [string]$Name [DscProperty()] [Ensure]$Ensure = [Ensure]::Present [DscProperty(Mandatory)] - [string]$NetScalerFQDN - + [string]$NetScalerFQDN + [DscProperty(Mandatory)] [pscredential]$Credential [DscProperty()] - [string]$CertPath - - [DscProperty()] - [string]$KeyPath + [string]$Source [DscProperty()] - [string]$CertKeyFormat - + [ValidateSet($True,$False)] + [bool]$Overwrite = $True Init() { try { @@ -2907,32 +4266,30 @@ class LBSSLCertificate { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { # Run tests and set any needed attributes to match desired configuration - if (($NSObject.CertKeyName -ne $this.CertKeyName) -OR ($NSObject.CertPath -ne $this.CertPath) -OR ($NSObject.KeyPath -ne $this.KeyPath) -OR ($NSObject.CertKeyFormat -ne $this.CertKeyFormat)) { - Write-Verbose -Message "Warning, resource cannot be changed to [$($this.CertKeyName)], resource can only be removed and recreated" - Remove-NSCertKeyPair -CertKeyName $this.CertKeyName - } - } else { - Write-Verbose -Message "Creating resource [$($this.CertKeyName)]" + if ($NSObject.name -ne $this.Name) { + Write-Verbose -Message "Readding HTML page [$($this.Name)]" + Remove-NSResponderHTMLPage -Name $this.Name -ErrorAction SilentlyContinue + New-NSResponderHTMLPage -Namev $this.Name -Source $this.Source -Overwrite $this.Overwrite -ErrorAction SilentlyContinue + } + } else { + Write-Verbose -Message "Creating resource [$($this.Name)]" $params = @{ - CertKeyName = $this.CertKeyName - CertPath = $this.CertPath + Name = $this.Name + Source = $this.Source + Overwrite = $this.Overwrite } - if ($PSBoundParameters.ContainsKey('KeyPath')) { - $params.Add('KeyPath', $this.KeyPath) - } - if ($PSBoundParameters.ContainsKey('CertKeyFormat')) { - $params.Add('CertKeyFormat', $this.CertKeyFormat) - } - Add-NSCertKeyPair @params -ErrorAction SilentlyContinue + + New-NSResponderHTMLPage @params -ErrorAction SilentlyContinue } - } + } 'Absent' { if ($this.Ensure -ne $NSObject.Ensure) { - Remove-NSCertKeyPair -CertKeyName $this.CertKeyName -ErrorAction SilentlyContinue - Write-Verbose -Message "Removed Certificate: $($this.CertKeyName)" + Remove-NSResponderHTMLPage -Name $this.Name -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Responder HTML Page: $($this.Name)" } } } + Save-NSConfig } catch { Write-Error 'There was a problem setting the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" @@ -2955,24 +4312,11 @@ class LBSSLCertificate { switch ($this.Ensure) { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { - # Run tests and set any needed attributes to match desired configuration - if ($NSObject.certkeyname -ne $this.CertKeyName) { - Write-Verbose -Message "Certificate Key Name does not match [$($NSObject.certkeyname) <> $($this.CertKeyName)]" - $pass = $false - } - if ($NSObject.certpath -ne $this.CertPath) { - Write-Verbose -Message "Certificate Path does not match [$($NSObject.certpath) <> $($this.CertPath)]" - $pass = $false - } - if ($this.KeyPath) { - if ($NSObject.keypath -ne $this.KeyPath) { - Write-Verbose -Message "Key Path does not match [$($NSObject.keypath) <> $($this.KeyPath)]" - $pass = $false - } - } - } else { - Write-Verbose -Message "Certificate[$($this.CertKeyName)] was not found" - $pass = $false + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.name -ne $this.Name) { + Write-Verbose -Message "Name does not match [$($NSObject.name) <> $($this.Name)]" + $pass = $false + } } } 'Absent' { @@ -2991,31 +4335,23 @@ class LBSSLCertificate { } catch { # Do nothing } - return $pass + return $pass } - [LBSSLCertificate]Get() { + [LBResponderHTMLPage]Get() { $t = $null $t = $this.Init() try { - $s = Get-NSCertKeyPair -CertKeyName $this.CertKeyName -Verbose:$false -ErrorAction SilentlyContinue + $s = Get-NSResponderHTMLPage -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue } catch { $s = $null } - $obj = [LBSSLCertificate]::new() - $obj.CertKeyName = $this.CertKeyName - $obj.CertPath = $this.CertPath - $obj.CertKeyFormat = $this.CertKeyFormat - $obj.KeyPath = $this.KeyPath + $obj = [LBResponderHTMLPage]::new() + $obj.Name = $this.Name if ($s) { $obj.Ensure = [ensure]::Present - $obj.CertKeyName = $s.certkey - $obj.CertPath = "/nsconfig/ssl/" + $s.cert - $obj.CertKeyFormat = $s.inform - if ($s.key) { - $obj.KeyPath = $s.key - } + $obj.Name = $s.name } else { $obj.Ensure = [ensure]::Absent } @@ -3025,172 +4361,6 @@ class LBSSLCertificate { } -# [DscResource()] -# class LBSSLCertificate { -# [DscProperty(Key)] -# [string]$CertKeyName - -# [DscProperty()] -# [Ensure]$Ensure = [Ensure]::Present - -# [DscProperty(Mandatory)] -# [string]$NetScalerFQDN - -# [DscProperty(Mandatory)] -# [pscredential]$Credential - -# [DscProperty()] -# [string]$CertPath - -# [DscProperty()] -# [string]$KeyPath - -# [DscProperty()] -# [ValidateSet('PEM','DER','PFX')] -# [string]$CertKeyFormat = 'PEM' - -# [DscProperty()] -# [securestring]$Password - - -# Init() { -# try { -# Import-Module -Name Netscaler -Verbose:$false -Debug:$false -# Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false -# } catch { -# throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" -# } -# } - -# [void]Set() { -# $t = $null -# $t = $this.Init() -# $NSObject = $this.Get() - -# try { -# Import-Module -Name Netscaler -Verbose:$false -Debug:$false -# Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false -# } catch { -# throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" -# } - -# try { -# switch ($this.Ensure) { -# 'Present' { -# if ($this.Ensure -eq $NSObject.Ensure) { -# # Run tests and set any needed attributes to match desired configuration -# if (($NSObject.CertKeyName -ne $this.CertKeyName) -OR ($NSObject.CertPath -ne $this.CertPath) -OR ($NSObject.KeyPath -ne $this.KeyPath) -OR ($NSObject.CertKeyFormat -ne $this.CertKeyFormat)) { -# Write-Verbose -Message "Warning, resource cannot be changed to [$($this.CertKeyName)], resource can only be removed and recreated" -# Remove-NSCertKeyPair -CertKeyName $this.CertKeyName -# } -# } else { -# Write-Verbose -Message "Creating resource [$($this.CertKeyName)]" -# $params = @{ -# CertKeyName = $this.CertKeyName -# CertPath = $this.CertPath -# KeyPath = $this.KeyPath -# CertKeyFormat = $this.CertKeyFormat -# } -# Add-NSCertKeyPair @params -ErrorAction SilentlyContinue -# } -# } -# 'Absent' { -# if ($this.Ensure -ne $NSObject.Ensure) { -# Remove-NSResponderAction -Name $NSObject.CertKeyName -ErrorAction SilentlyContinue -# Write-Verbose -Message "Removed Certificate: $($this.Name)" -# } -# } -# } -# } catch { -# Write-Error 'There was a problem setting the resource' -# Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" -# Write-Error $_ -# } -# try { -# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue -# } catch { -# # Do nothing -# } -# } - -# [bool]Test() { -# $pass = $true -# $t = $null -# $t = $this.Init() -# $NSObject = $this.Get() -# try { -# switch ($this.Ensure) { -# 'Present' { -# if ($this.Ensure -eq $NSObject.Ensure) { -# # Run tests and set any needed attributes to match desired configuration -# if ($NSObject.certkeyname -ne $this.CertKeyName) { -# Write-Verbose -Message "Certificate Key Name does not match [$($NSObject.certkeyname) <> $($this.CertKeyName)]" -# $pass = $false -# } -# if ($NSObject.certpath -ne $this.CertPath) { -# Write-Verbose -Message "Certificate Path does not match [$($NSObject.certpath) <> $($this.CertPath)]" -# $pass = $false -# } -# if ($this.KeyPath) { -# if ($NSObject.keypath -ne $this.KeyPath) { -# Write-Verbose -Message "Key Path does not match [$($NSObject.keypath) <> $($this.KeyPath)]" -# $pass = $false -# } -# } -# } else { -# Write-Verbose -Message "Certificate[$($this.CertKeyName)] was not found" -# $pass = $false -# } -# } -# 'Absent' { -# if ($this.Ensure -ne $NSObject.Ensure) { -# $pass = $false -# } -# } -# } -# } catch { -# Write-Error 'There was a problem testing the resource' -# Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" -# Write-Error $_ -# } -# try { -# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue -# } catch { -# # Do nothing -# } -# return $pass -# } - -# [LBSSLCertificate]Get() { -# $t = $null -# $t = $this.Init() - -# try { -# $s = Get-NSCertKeyPair -CertKeyName $this.CertKeyName -Verbose:$false -ErrorAction SilentlyContinue -# } catch { -# $s = $null -# } -# $obj = [LBSSLCertificate]::new() -# $obj.CertKeyName = $this.CertKeyName -# $obj.CertPath = $this.CertPath -# $obj.CertKeyFormat = $this.CertKeyFormat -# $obj.KeyPath = $this.KeyPath -# if ($s) { -# $obj.Ensure = [ensure]::Present -# $obj.CertKeyName = $s.certkey -# $obj.CertPath = $s.cert -# $obj.CertKeyFormat = $s.inform -# if ($s.key) { -# $obj.KeyPath = $s.key -# } -# } else { -# $obj.Ensure = [ensure]::Absent -# } -# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue -# return $obj -# } -# } - # [DscResource()] # class LBNSIP { # [DscProperty(Key)] @@ -3200,8 +4370,8 @@ class LBSSLCertificate { # [Ensure]$Ensure = [Ensure]::Present # [DscProperty(Mandatory)] -# [string]$NetScalerFQDN - +# [string]$NetScalerFQDN + # [DscProperty(Mandatory)] # [pscredential]$Credential @@ -3264,7 +4434,7 @@ class LBSSLCertificate { # if ($NSObject.SubnetMask -ne $this.SubnetMask) { # Write-Verbose -Message "Resource name does not match [$($this.SubnetMask)]" # Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -# } +# } # if ($NSObject.Type -ne $this.Type) { # Write-Verbose -Message "Warning, the resource cannot be set to [$($this.Type)]" # } @@ -3275,58 +4445,134 @@ class LBSSLCertificate { # if ($NSObject.Telnet -ne $this.Telnet) { # Write-Verbose -Message "Setting Telnet [$($this.Telnet)]" # Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -Telnet -# } +# } # if ($NSObject.FTP -ne $this.FTP) { # Write-Verbose -Message "Setting FTP [$($this.FTP)]" # Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -FTP # } -# if ($NSObject.GUI -ne $this.GUI) { -# Write-Verbose -Message "Setting GUI [$($this.GUI)]" -# Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -GUI +# if ($NSObject.GUI -ne $this.GUI) { +# Write-Verbose -Message "Setting GUI [$($this.GUI)]" +# Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -GUI +# } +# if ($NSObject.SSH -ne $this.SSH) { +# Write-Verbose -Message "Setting GUI [$($this.SSH)]" +# Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -SSH +# } +# if ($NSObject.SNMP -ne $this.SNMP) { +# Write-Verbose -Message "Setting SNMP [$($this.SNMP)]" +# Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -SNMP +# } +# if ($NSObject.MgmtAccess -ne $this.MgmtAccess) { +# Write-Verbose -Message "Setting Management Access [$($this.MgmtAccess)]" +# Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -MgmtAccess +# } +# } else { +# Write-Verbose -Message "Feature enabled, [$($this.IPAddress)]" +# $params = @{ +# ipaddress = $this.IPAddress +# netmask = $this.SubnetMask +# type = $this.Type +# } +# Add-NSIPResource @params -Confirm:$false +# # $switches { +# # ipaddress = $this.IPAddress +# # netmask = $this.SubnetMask +# # type = $this.Type +# # vserver = $this.VServer +# # telnet = $this.Telnet +# # ftp = $this.FTP +# # gui = $this.GUI +# # ssh = $this.SSH +# # snmp = $this.SNMP +# # mgmtaccess = $this.mgmtaccess +# # } +# # Invoke-DscResource -Method set -ModuleName poshorigin_netscaler -Name LBNSIP -Property $switches +# } +# } 'Absent' { +# if ($this.Ensure -ne $NSObject.Ensure) { +# Disable-NSFeature -Name $this.Name -Confirm:$false +# Write-Verbose -Message "Feature disabled: $($this.Name)" +# } +# } +# } +# } catch { +# Write-Error 'There was a problem setting the resource' +# Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" +# Write-Error $_ +# } +# try { +# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue +# } catch { +# # Do nothing +# } +# } + + +# [bool]Test() { +# $pass = $true +# $t = $null +# $t = $this.Init() +# $NSObject = $this.Get() +# try { +# switch ($this.Ensure) { +# 'Present' { +# if ($this.Ensure -eq $NSObject.Ensure) { +# # # Run tests and set any needed attributes to match desired configuration +# if ($NSObject.ipaddress -ne $this.IPAddress) { +# Write-Verbose -Message "IPAddress does not match [$($NSObject.ipaddress) <> $($this.IPAddress)]" +# $pass = $false +# } +# if ($NSObject.subnetmask -ne $this.SubnetMask) { +# Write-Verbose -Message "SubnetMask does not match [$($NSObject.subnetmask) <> $($this.SubnetMask)]" +# $pass = $false +# } +# if ($NSObject.type -ne $this.Type) { +# Write-Verbose -Message "Type does not match [$($NSObject.type) <> $($this.Type)]" +# $pass = $false +# } +# if ($NSObject.vserver -ne $this.VServer) { +# Write-Verbose -Message "VServer does not match [$($NSObject.vserver) <> $($this.VServer)]" +# $pass = $false +# } +# if ($NSObject.telnet -ne $this.Telnet) { +# Write-Verbose -Message "Telnet does not match [$($NSObject.telnet) <> $($this.Telnet)]" +# $pass = $false +# } +# if ($NSObject.ftp -ne $this.FTP) { +# Write-Verbose -Message "FTP does not match [$($NSObject.ftp) <> $($this.FTP)]" +# $pass = $false +# } +# if ($NSObject.gui -ne $this.GUI) { +# Write-Verbose -Message "GUI does not match [$($NSObject.gui) <> $($this.GUI)]" +# $pass = $false # } -# if ($NSObject.SSH -ne $this.SSH) { -# Write-Verbose -Message "Setting GUI [$($this.SSH)]" -# Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -SSH +# if ($NSObject.ssh -ne $this.SSH) { +# Write-Verbose -Message "SSH does not match [$($NSObject.ssh) <> $($this.SSH)]" +# $pass = $false # } -# if ($NSObject.SNMP -ne $this.SNMP) { -# Write-Verbose -Message "Setting SNMP [$($this.SNMP)]" -# Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -SNMP +# if ($NSObject.snmp -ne $this.SNMP) { +# Write-Verbose -Message "SNMP does not match [$($NSObject.snmp) <> $($this.SNMP)]" +# $pass = $false # } -# if ($NSObject.MgmtAccess -ne $this.MgmtAccess) { -# Write-Verbose -Message "Setting Management Access [$($this.MgmtAccess)]" -# Set-NSIPResource -IPAddress $this.IPAddress -SubnetMask $this.SubnetMask -MgmtAccess +# if ($NSObject.mgmtaccess -ne $this.MgmtAccess) { +# Write-Verbose -Message "MgmtAccess does not match [$($NSObject.mgmtaccess) <> $($this.MgmtAccess)]" +# $pass = $false # } # } else { -# Write-Verbose -Message "Feature enabled, [$($this.IPAddress)]" -# $params = @{ -# ipaddress = $this.IPAddress -# netmask = $this.SubnetMask -# type = $this.Type -# } -# Add-NSIPResource @params -Confirm:$false -# # $switches { -# # ipaddress = $this.IPAddress -# # netmask = $this.SubnetMask -# # type = $this.Type -# # vserver = $this.VServer -# # telnet = $this.Telnet -# # ftp = $this.FTP -# # gui = $this.GUI -# # ssh = $this.SSH -# # snmp = $this.SNMP -# # mgmtaccess = $this.mgmtaccess -# # } -# # Invoke-DscResource -Method set -ModuleName poshorigin_netscaler -Name LBNSIP -Property $switches +# $pass = $false # } # } 'Absent' { # if ($this.Ensure -ne $NSObject.Ensure) { -# Disable-NSFeature -Name $this.Name -Confirm:$false -# Write-Verbose -Message "Feature disabled: $($this.Name)" +# $pass = $false +# } else { +# if ($NSObject.Name -eq "True") { +# $pass = $false +# } # } # } -# } +# } # } catch { -# Write-Error 'There was a problem setting the resource' +# Write-Error 'There was a problem testing the resource' # Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" # Write-Error $_ # } @@ -3335,162 +4581,395 @@ class LBSSLCertificate { # } catch { # # Do nothing # } +# return $pass +# } + +# [LBNSIP]Get() { +# $t = $null +# $t = $this.Init() + +# try { +# $s = Get-NSIPResource -IPAddress $this.IPAddress -Verbose:$false -ErrorAction SilentlyContinue +# } catch { +# $s = $null +# } + +# $obj = [LBNSIP]::new() +# $obj.IPAddress = $this.IPAddress +# $obj.SubnetMask = $this.SubnetMask +# $obj.Type = $this.Type +# $obj.VServer = $this.VServer +# $obj.Telnet = $this.Telnet +# $obj.FTP = $this.FTP +# $obj.GUI = $this.GUI +# $obj.SSH = $this.SSH +# $obj.SNMP = $this.SNMP +# $obj.MgmtAccess = $this.MgmtAccess +# if ($s) { +# $obj.Ensure = [ensure]::Present +# $obj.IPAddress = $s.ipaddress +# $obj.SubnetMask = $s.netmask +# $obj.Type = $s.type +# $obj.VServer = $this.TestEnabledFeatures($s.VServer) +# $obj.Telnet = $this.TestEnabledFeatures($s.Telnet) +# $obj.FTP = $this.TestEnabledFeatures($s.FTP) +# $obj.GUI = $this.TestEnabledFeatures($s.GUI) +# $obj.SSH = $this.TestEnabledFeatures($s.SSH) +# $obj.SNMP = $this.TestEnabledFeatures($s.SNMP) +# $obj.MgmtAccess = $this.TestEnabledFeatures($s.MgmtAccess) +# } else { +# $obj.Ensure = [ensure]::Absent +# } +# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue +# return $obj +# } + +# <# +# Helper method to test switch/boolean options +# #> +# [bool] TestEnabledFeatures([string] $Existing){ +# # $present = $true +# if ($Existing -eq "ENABLED") { +# $present = $true +# } else { +# $present = $false +# } +# return $present # } +# } + +[DscResource()] +class LBVirtualServerBinding { + [DscProperty(Key)] + [string]$VirtualServerName + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty()] + [string]$ServiceGroupName + + [DscProperty()] + [string]$ServiceName + + [DscProperty()] + [int]$Weight = 1 + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -ne $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($this.ServiceGroupName -eq $NSObject.ServiceGroupName) { + Write-Verbose -Message "Service Group Name bound, [$($this.VirtualServerName)]" + Add-NSLBVirtualServerBinding -VirtualServerName $this.VirtualServerName -ServiceGroupName $this.ServiceGroupName -Weight $this.Weight -Confirm:$false + } else { + if (($this.ServiceName -ne $null) -OR ($NSObject.NetScalerFQDN -ne $null)) { + Write-Verbose -Message "Service Name bound, [$($this.ServiceName)]" + Add-NSLBVirtualServerBinding -VirtualServerName $this.VirtualServerName -ServiceName $this.ServiceName -Weight $this.Weight -Confirm:$false + } + } + } + } 'Absent' { + if ($this.ServiceGroupName) { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSLBVirtualServerBinding -name $this.VirtualServerName -ServiceGroupName $this.ServiceGroupName -Confirm:$false + Write-Verbose -Message "Virtual Server Binding removed for $($this.VirtualServerName)" + } + } else { + Remove-NSLBVirtualServerBinding -name $this.VirtualServerName -ServiceName $this.ServiceName -Confirm:$false + Write-Verbose -Message "Virtual Server Binding removed for $($this.VirtualServerName)" + } + } + } + Save-NSConfig + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($this.servicegroupname -eq $NSObject.ServiceGroupName) { + if ($NSObject.virtualservername -ne $this.VirtualServerName) { + Write-Verbose -Message "VirtualServerName does not match [$($NSObject.virtualservername) <> $($this.VirtualServerName)]" + $pass = $false + } + if ($NSObject.servicegroupname -ne $this.ServiceGroupName) { + Write-Verbose -Message "ServiceGroupName does not match [$($NSObject.servicegroupname) <> $($this.ServiceGroupName)]" + $pass = $false + } + } else { + if ($NSObject.virtualservername -ne $this.VirtualServerName) { + Write-Verbose -Message "VirtualServerName does not match [$($NSObject.virtualservername) <> $($this.VirtualServerName)]" + $pass = $false + } + if ($NSObject.servicename -ne $this.ServiceName) { + Write-Verbose -Message "ServiceName does not match [$($NSObject.servicename) <> $($this.ServiceName)]" + $pass = $false + } + } + } else { + $pass = $false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } else { + if ($NSObject.Name -eq "True") { + $pass = $false + } + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBVirtualServerBinding]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSLBVirtualServerBinding -Name $this.VirtualServerName -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBVirtualServerBinding]::new() + $obj.VirtualServerName = $this.VirtualServerName + $obj.ServiceGroupName = $this.ServiceGroupName + $obj.ServiceName = $this.ServiceName + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.VirtualServerName = $s.name + $obj.ServiceGroupName = $s.ServiceGroupName + $obj.ServiceName = $s.ServiceName + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} +[DscResource()] +class LBSystemFile { + [DscProperty(Key)] + [string]$FileName -# [bool]Test() { -# $pass = $true -# $t = $null -# $t = $this.Init() -# $NSObject = $this.Get() -# try { -# switch ($this.Ensure) { -# 'Present' { -# if ($this.Ensure -eq $NSObject.Ensure) { -# # # Run tests and set any needed attributes to match desired configuration -# if ($NSObject.ipaddress -ne $this.IPAddress) { -# Write-Verbose -Message "IPAddress does not match [$($NSObject.ipaddress) <> $($this.IPAddress)]" -# $pass = $false -# } -# if ($NSObject.subnetmask -ne $this.SubnetMask) { -# Write-Verbose -Message "SubnetMask does not match [$($NSObject.subnetmask) <> $($this.SubnetMask)]" -# $pass = $false -# } -# if ($NSObject.type -ne $this.Type) { -# Write-Verbose -Message "Type does not match [$($NSObject.type) <> $($this.Type)]" -# $pass = $false -# } -# if ($NSObject.vserver -ne $this.VServer) { -# Write-Verbose -Message "VServer does not match [$($NSObject.vserver) <> $($this.VServer)]" -# $pass = $false -# } -# if ($NSObject.telnet -ne $this.Telnet) { -# Write-Verbose -Message "Telnet does not match [$($NSObject.telnet) <> $($this.Telnet)]" -# $pass = $false -# } -# if ($NSObject.ftp -ne $this.FTP) { -# Write-Verbose -Message "FTP does not match [$($NSObject.ftp) <> $($this.FTP)]" -# $pass = $false -# } -# if ($NSObject.gui -ne $this.GUI) { -# Write-Verbose -Message "GUI does not match [$($NSObject.gui) <> $($this.GUI)]" -# $pass = $false -# } -# if ($NSObject.ssh -ne $this.SSH) { -# Write-Verbose -Message "SSH does not match [$($NSObject.ssh) <> $($this.SSH)]" -# $pass = $false -# } -# if ($NSObject.snmp -ne $this.SNMP) { -# Write-Verbose -Message "SNMP does not match [$($NSObject.snmp) <> $($this.SNMP)]" -# $pass = $false -# } -# if ($NSObject.mgmtaccess -ne $this.MgmtAccess) { -# Write-Verbose -Message "MgmtAccess does not match [$($NSObject.mgmtaccess) <> $($this.MgmtAccess)]" -# $pass = $false -# } -# } else { -# $pass = $false -# } -# } 'Absent' { -# if ($this.Ensure -ne $NSObject.Ensure) { -# $pass = $false -# } else { -# if ($NSObject.Name -eq "True") { -# $pass = $false -# } -# } -# } -# } -# } catch { -# Write-Error 'There was a problem testing the resource' -# Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" -# Write-Error $_ -# } -# try { -# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue -# } catch { -# # Do nothing -# } -# return $pass -# } + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present -# [LBNSIP]Get() { -# $t = $null -# $t = $this.Init() + [DscProperty(Mandatory)] + [string]$NetScalerFQDN -# try { -# $s = Get-NSIPResource -IPAddress $this.IPAddress -Verbose:$false -ErrorAction SilentlyContinue -# } catch { -# $s = $null -# } + [DscProperty(Mandatory)] + [pscredential]$Credential -# $obj = [LBNSIP]::new() -# $obj.IPAddress = $this.IPAddress -# $obj.SubnetMask = $this.SubnetMask -# $obj.Type = $this.Type -# $obj.VServer = $this.VServer -# $obj.Telnet = $this.Telnet -# $obj.FTP = $this.FTP -# $obj.GUI = $this.GUI -# $obj.SSH = $this.SSH -# $obj.SNMP = $this.SNMP -# $obj.MgmtAccess = $this.MgmtAccess -# if ($s) { -# $obj.Ensure = [ensure]::Present -# $obj.IPAddress = $s.ipaddress -# $obj.SubnetMask = $s.netmask -# $obj.Type = $s.type -# $obj.VServer = $this.TestEnabledFeatures($s.VServer) -# $obj.Telnet = $this.TestEnabledFeatures($s.Telnet) -# $obj.FTP = $this.TestEnabledFeatures($s.FTP) -# $obj.GUI = $this.TestEnabledFeatures($s.GUI) -# $obj.SSH = $this.TestEnabledFeatures($s.SSH) -# $obj.SNMP = $this.TestEnabledFeatures($s.SNMP) -# $obj.MgmtAccess = $this.TestEnabledFeatures($s.MgmtAccess) -# } else { -# $obj.Ensure = [ensure]::Absent -# } -# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue -# return $obj -# } + [DscProperty(Mandatory)] + [string]$FileLocation -# <# -# Helper method to test switch/boolean options -# #> -# [bool] TestEnabledFeatures([string] $Existing){ -# # $present = $true -# if ($Existing -eq "ENABLED") { -# $present = $true -# } else { -# $present = $false -# } -# return $present -# } -# } + [DscProperty(Mandatory)] + [string]$Path + + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($NSObject.Ensure -ne $this.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if (!$NSObject.FileName) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.FileName)], resource can only be removed and recreated" + Add-NSSystemFile -Path $this.Path -FileLocation $this.FileLocation -FileName $this.FileName -Force + } + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSSystemFile -Name $this.FileName -FileLocation $this.FileLocation -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed File: $($this.Name)" + } + } + } + Save-NSConfig + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.filename -ne $this.FileName) { + Write-Verbose -Message "File Name does not match [$($NSObject.filename) <> $($this.FileName)]" + $pass = $false + } + if ($NSObject.filelocation -ne $this.FileLocation) { + Write-Verbose -Message "File Location does not match [$($NSObject.filelocation) <> $($this.FileLocation)]" + $pass = $false + } + } else { + Write-Verbose -Message "File[$($this.FileName)] was not found" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBSystemFile]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSSystemFile -FileName $this.FileName -FileLocation $this.FileLocation -Verbose:$false -ErrorAction SilentlyContinue + } catch { + $s = $null + } + $obj = [LBSystemFile]::new() + $obj.FileName + $obj.FileLocation + $obj.Path + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.FileName = $s.filename + $obj.FileLocation = $s.filelocation + if ($s.Path) { + $obj.Path = $s.path + } + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } +} [DscResource()] -class LBNSVirtualServerBinding { +class LBVLAN { [DscProperty(Key)] - [string]$VirtualServerName + [int]$VLANID [DscProperty()] [Ensure]$Ensure = [Ensure]::Present [DscProperty(Mandatory)] - [string]$NetScalerFQDN - + [string]$NetScalerFQDN + [DscProperty(Mandatory)] [pscredential]$Credential - [DscProperty()] - [string]$ServiceGroupName + [DscProperty(Mandatory)] + [string]$AliasName [DscProperty()] - [string]$ServiceName + [ValidateSet('ENABLED','DISABLED')] + [string]$IPV6DynamicRouting = 'DISABLED' - [DscProperty()] - [int]$Weight = 1 + [DscProperty(Mandatory)] + [int]$MTU Init() { try { @@ -3516,30 +4995,41 @@ class LBNSVirtualServerBinding { try { switch ($this.Ensure) { 'Present' { - if ($this.Ensure -ne $NSObject.Ensure) { + if ($this.Ensure -eq $NSObject.Ensure) { # Run tests and set any needed attributes to match desired configuration - if ($this.ServiceGroupName -eq $NSObject.ServiceGroupName) { - Write-Verbose -Message "Service Group Name bound, [$($this.VirtualServerName)]" - Add-NSLBVirtualServerBinding -VirtualServerName $this.VirtualServerName -ServiceGroupName $this.ServiceGroupName -Weight $this.Weight -Confirm:$false - } else { - if (($this.ServiceName -ne $null) -OR ($NSObject.NetScalerFQDN -ne $null)) { - Write-Verbose -Message "Service Name bound, [$($this.ServiceName)]" - Add-NSLBVirtualServerBinding -VirtualServerName $this.VirtualServerName -ServiceName $this.ServiceName -Weight $this.Weight -Confirm:$false - } + if ($NSObject.vlanid -ne $this.VLANID) { + Write-Warning -Message "Setting VLANID cannot be changed to [$($this.VLANID)], resource can only be removed and recreated" } - } - } 'Absent' { - if ($this.ServiceGroupName) { - if ($this.Ensure -ne $NSObject.Ensure) { - Remove-NSLBVirtualServerBinding -name $this.VirtualServerName -ServiceGroupName $this.ServiceGroupName -Confirm:$false - Write-Verbose -Message "Virtual Server Binding removed for $($this.VirtualServerName)" + if ($NSObject.aliasname -ne $this.AliasName) { + Write-Verbose -Message "Setting AliasName [$($this.AliasName)]" + Set-NSVLAN -VLANID $this.VLANID -AliasName $this.AliasName } - } else { - Remove-NSLBVirtualServerBinding -name $this.VirtualServerName -ServiceName $this.ServiceName -Confirm:$false - Write-Verbose -Message "Virtual Server Binding removed for $($this.VirtualServerName)" + if ($NSObject.ipv6dynamicrouting -ne $this.IPV6DynamicRouting) { + Write-Verbose -Message "Setting AliasName [$($this.IPV6DynamicRouting)]" + Set-NSVLAN -VLANID $this.VLANID -IPV6DynamicRouting $this.IPV6DynamicRouting + } + if ($NSObject.mtu -ne $this.MTU) { + Write-Verbose -Message "Setting AliasName [$($this.MTU)]" + Set-NSVLAN -VLANID $this.VLANID -MTU $this.MTU + } + } else { + Write-Verbose -Message "Feature enabled, [$($this.IPAddress)]" + $params = @{ + vlanid = $this.VLANID + aliasname = $this.AliasName + ipv6dynamicrouting = $this.ipv6dynamicrouting + mtu = $this.MTU + } + Add-NSVLAN @params -Confirm:$false } - } - } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Remove-NSVLAN -VLANID $this.VLANID -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed VLANID: $($this.VLANID)" + } + } + } + Save-NSConfig } catch { Write-Error 'There was a problem setting the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" @@ -3561,39 +5051,34 @@ class LBNSVirtualServerBinding { switch ($this.Ensure) { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { - # Run tests and set any needed attributes to match desired configuration - if ($this.servicegroupname -eq $NSObject.ServiceGroupName) { - if ($NSObject.virtualservername -ne $this.VirtualServerName) { - Write-Verbose -Message "VirtualServerName does not match [$($NSObject.virtualservername) <> $($this.VirtualServerName)]" + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.vlanid -ne $this.VLANID) { + Write-Verbose -Message "VLANID does not match [$($NSObject.vlanid) <> $($this.VLANID)]" $pass = $false } - if ($NSObject.servicegroupname -ne $this.ServiceGroupName) { - Write-Verbose -Message "ServiceGroupName does not match [$($NSObject.servicegroupname) <> $($this.ServiceGroupName)]" + if ($NSObject.aliasname -ne $this.AliasName) { + Write-Verbose -Message "Aliasname does not match [$($NSObject.aliasname) <> $($this.AliasName)]" $pass = $false } - } else { - if ($NSObject.virtualservername -ne $this.VirtualServerName) { - Write-Verbose -Message "VirtualServerName does not match [$($NSObject.virtualservername) <> $($this.VirtualServerName)]" + if ($NSObject.ipv6dynamicrouting -ne $this.IPV6DynamicRouting) { + Write-Verbose -Message "IPV6 Dynamic Routing does not match [$($NSObject.ipv6dynamicrouting) <> $($this.IPV6DynamicRouting)]" $pass = $false - } - if ($NSObject.servicename -ne $this.ServiceName) { - Write-Verbose -Message "ServiceName does not match [$($NSObject.servicename) <> $($this.ServiceName)]" + } + if ($NSObject.mtu -ne $this.MTU) { + Write-Verbose -Message "MTU does not match [$($NSObject.mtu) <> $($this.MTU)]" $pass = $false } - } } else { + Write-Verbose -Message "File[$($this.VLANID)] was not found" $pass = $false } - } 'Absent' { + } + 'Absent' { if ($this.Ensure -ne $NSObject.Ensure) { $pass = $false - } else { - if ($NSObject.Name -eq "True") { - $pass = $false - } } - } - } + } + } } catch { Write-Error 'There was a problem testing the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" @@ -3604,28 +5089,30 @@ class LBNSVirtualServerBinding { } catch { # Do nothing } - return $pass + return $pass } - [LBNSVirtualServerBinding]Get() { + [LBVLAN]Get() { $t = $null $t = $this.Init() try { - $s = Get-NSLBVirtualServerBinding -Name $this.VirtualServerName -Verbose:$false -ErrorAction SilentlyContinue + $s = Get-NSVLAN -VLANID $this.VLANID -Verbose:$false -ErrorAction SilentlyContinue } catch { $s = $null } - $obj = [LBNSVirtualServerBinding]::new() - $obj.VirtualServerName = $this.VirtualServerName - $obj.ServiceGroupName = $this.ServiceGroupName - $obj.ServiceName = $this.ServiceName + $obj = [LBVLAN]::new() + $obj.VLANID = $this.VLANID + $obj.AliasName = $this.AliasName + $obj.IPV6DynamicRouting = $this.IPV6DynamicRouting + $obj.MTU = $this.MTU if ($s) { $obj.Ensure = [ensure]::Present - $obj.VirtualServerName = $s.name - $obj.ServiceGroupName = $s.ServiceGroupName - $obj.ServiceName = $s.ServiceName + $obj.VLANID = $s.id + if ($s.AliasName) { $obj.AliasName = $s.aliasname } + $obj.IPV6DynamicRouting = $s.ipv6dynamicrouting + if ($s.mtu) { $obj.MTU = $s.mtu } } else { $obj.Ensure = [ensure]::Absent } @@ -3634,27 +5121,26 @@ class LBNSVirtualServerBinding { } } - [DscResource()] -class LBSystemFile { +class LBVLANInterfaceBinding { [DscProperty(Key)] - [string]$FileName + [int]$VLANID [DscProperty()] [Ensure]$Ensure = [Ensure]::Present [DscProperty(Mandatory)] - [string]$NetScalerFQDN - - [DscProperty(Mandatory)] - [pscredential]$Credential + [string]$NetScalerFQDN [DscProperty(Mandatory)] - [string]$FileLocation + [pscredential]$Credential [DscProperty(Mandatory)] - [string]$Path + [string]$Interface = "0/1" + [DscProperty()] + [ValidateSet($True,$False)] + [bool]$Tagged = $False Init() { try { @@ -3680,20 +5166,60 @@ class LBSystemFile { try { switch ($this.Ensure) { 'Present' { - if ($NSObject.Ensure -ne $this.Ensure) { + if ($this.Ensure -eq $NSObject.Ensure) { # Run tests and set any needed attributes to match desired configuration - if (!$NSObject.FileName) { - Write-Verbose -Message "Warning, resource cannot be changed to [$($this.FileName)], resource can only be removed and recreated" - Add-NSSystemFile -Path $this.Path -FileLocation $this.FileLocation -FileName $this.FileName -Force - } + if ($NSObject.vlanid -ne $this.VLANID) { + Write-Warning -Message "Setting VLANID cannot be changed to [$($this.VLANID)], resource can only be removed and recreated" + } + if ((!$NSObject.interface) -OR ($NSObject.interface -ne $this.Interface)) { + Write-Verbose -Message "Setting Interface [$($this.Interface)]" + Remove-VLAN-NSVLANInterfaceBinding -VLANID $this.VLANID -Interface $this.Interface -Confirm:$false + if ($this.Tagged -eq 'No') { + Add-VLAN-NSVLANInterfaceBinding -VLANID $this.VLANID -Interface $this.Interface + } + else { + Add-VLAN-NSVLANInterfaceBinding -VLANID $this.VLANID -Interface $this.Interface -Tagged $this.Tagged + } + } + if ((!$NSObject.tagged) -OR ($NSObject.Tagged -ne $this.Tagged)) { + Write-Verbose -Message "Setting Tagged interface [$($this.Tagged)]" + Remove-VLAN-NSVLANInterfaceBinding -VLANID $this.VLANID -Interface $this.Interface -Confirm:$false + if ($this.Tagged -eq 'No') { + Add-VLAN-NSVLANInterfaceBinding -VLANID $this.VLANID -Interface $this.Interface + } + else { + Add-VLAN-NSVLANInterfaceBinding -VLANID $this.VLANID -Interface $this.Interface -Tagged $this.Tagged + } + } + } else { + Write-Verbose -Message "Feature enabled, [$($this.IPAddress)]" + if ($this.Tagged -eq $False) { + $params = @{ + vlanid = $this.VLANID + interface = $this.Interface + } + + Add-NSVLANInterfaceBinding @params -Confirm:$false + } + else { + $params = @{ + vlanid = $this.VLANID + interface = $this.Interface + tagged = $this.tagged + } + + Add-NSVLANInterfaceBinding @params -Confirm:$false + + } } } 'Absent' { if ($this.Ensure -ne $NSObject.Ensure) { - Remove-NSSystemFile -Name $this.FileName -FileLocation $this.FileLocation -ErrorAction SilentlyContinue - Write-Verbose -Message "Removed File: $($this.Name)" + Remove-VLAN-NSVLANInterfaceBinding -VLANID $this.VLANID -Interface $this.Interface -Confirm:$false -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed VLANID interface Binding: $($this.VLANID)" } } } + Save-NSConfig } catch { Write-Error 'There was a problem setting the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" @@ -3716,16 +5242,20 @@ class LBSystemFile { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { # Run tests and set any needed attributes to match desired configuration - if ($NSObject.filename -ne $this.FileName) { - Write-Verbose -Message "File Name does not match [$($NSObject.filename) <> $($this.FileName)]" + if ($NSObject.vlanid -ne $this.VLANID) { + Write-Verbose -Message "VLANID does not match [$($NSObject.vlanid) <> $($this.VLANID)]" $pass = $false } - if ($NSObject.filelocation -ne $this.FileLocation) { - Write-Verbose -Message "File Location does not match [$($NSObject.filelocation) <> $($this.FileLocation)]" + if ((!$NSObject.Interface) -OR ($NSObject.Interface -ne $this.Interface)) { + Write-Verbose -Message "The interface does not match [$($NSObject.Interface) <> $($this.Interface)]" + $pass = $false + } + if ((!$NSObject.Tagged) -OR ($NSObject.Tagged -ne $this.Tagged)) { + Write-Verbose -Message "The interface's tag does not match [$($NSObject.Tagged) <> $($this.Tagged)]" $pass = $false } } else { - Write-Verbose -Message "File[$($this.FileName)] was not found" + Write-Verbose -Message "File[$($this.VLANID)] was not found" $pass = $false } } @@ -3745,30 +5275,28 @@ class LBSystemFile { } catch { # Do nothing } - return $pass + return $pass } - [LBSystemFile]Get() { + [LBVLANInterfaceBinding]Get() { $t = $null $t = $this.Init() try { - $s = Get-NSSystemFile -FileName $this.FileName -FileLocation $this.FileLocation -Verbose:$false -ErrorAction SilentlyContinue + $s = Get-NSVLAN -VLANID $this.VLANID -Verbose:$false -ErrorAction SilentlyContinue } catch { $s = $null } - - $obj = [LBSystemFile]::new() - $obj.FileName - $obj.FileLocation - $obj.Path + + $obj = [LBVLANInterfaceBinding]::new() + $obj.VLANID = $this.VLANID + $obj.Interface = $this.Interface + $obj.Tagged = $this.Tagged if ($s) { $obj.Ensure = [ensure]::Present - $obj.FileName = $s.filename - $obj.FileLocation = $s.filelocation - if ($s.Path) { - $obj.Path = $s.path - } + $obj.VLANID = $s.id + if ($s.ifaces) { $obj.Interface = $s.ifaces } else { $obj.Interface= '' } + if ($s.tagifaces) { $obj.Tagged = $s.tagifaces } else { $obj.Tagged = '' } } else { $obj.Ensure = [ensure]::Absent } @@ -3778,34 +5306,28 @@ class LBSystemFile { } [DscResource()] -class LBVLAN { +class LBResponderPolicyBinding { [DscProperty(Key)] - [int]$VLANID + [string]$VirtualServerName [DscProperty()] [Ensure]$Ensure = [Ensure]::Present [DscProperty(Mandatory)] - [string]$NetScalerFQDN - - [DscProperty(Mandatory)] - [pscredential]$Credential + [string]$NetScalerFQDN [DscProperty(Mandatory)] - [string]$AliasName - - [DscProperty()] - [ValidateSet('ENABLED','DISABLED')] - [string]$IPV6DynamicRouting = 'DISABLED' + [pscredential]$Credential [DscProperty(Mandatory)] - [int]$MTU + [string]$PolicyName [DscProperty()] - [string]$Interface + [ValidateSet('REQUEST','RESPONSE')] + [string]$Bindpoint = 'REQUEST' [DscProperty()] - [bool]$Tagged = $false + [int]$Priority = 100 Init() { try { @@ -3833,47 +5355,29 @@ class LBVLAN { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { # Run tests and set any needed attributes to match desired configuration - if ($NSObject.vlanid -ne $this.VLANID) { - Write-Warning -Message "Setting VLANID cannot be changed to [$($this.VLANID)], resource can only be removed and recreated" - } - if ($NSObject.aliasname -ne $this.AliasName) { - Write-Verbose -Message "Setting AliasName [$($this.AliasName)]" - Set-NSVLAN -VLANID $this.VLANID -AliasName $this.AliasName - } - if ($NSObject.mtu -ne $this.AliasName) { - Write-Verbose -Message "Setting AliasName [$($this.AliasName)]" - Set-NSVLAN -VLANID $this.VLANID -AliasName $this.AliasName - } - if ($NSObject.ipv6dynamicrouting -ne $this.IPV6DynamicRouting) { - Write-Verbose -Message "Setting AliasName [$($this.IPV6DynamicRouting)]" - Set-NSVLAN -VLANID $this.VLANID -IPV6DynamicRouting $this.IPV6DynamicRouting - } - if ($NSObject.mtu -ne $this.MTU) { - Write-Verbose -Message "Setting AliasName [$($this.MTU)]" - Set-NSVLAN -VLANID $this.VLANID -MTU $this.MTU - } - if ($NSObject.interface -ne $this.Interface) { - Write-Verbose -Message "Setting Interface [$($this.Interface)]" - Set-NSVLANInterfaceBinding -VLANID $this.VLANID -Interface $this.Interface + if (($NSObject.VirtualServerName -ne $this.VirtualServerName) -OR ($NSObject.PolicyName -ne $this.PolicyName)) { + Write-Warning -Message "Setting VirtualServerName cannot be changed to [$($this.VirtualServerName)], resource can only be removed and recreated" + Remove-NSLBVirtualServerResponderPolicyBinding -VirtualServerName $this.VirtualServerName -PolicyName $this.PolicyName + Add-NSLBVirtualServerResponderPolicyBinding -VirtualServerName $this.VirtualServerName -PolicyName $this.PolicyName -Bindpoint $this.Bindpoint -Priority $this.Priority } } else { - Write-Verbose -Message "Feature enabled, [$($this.IPAddress)]" + Write-Verbose -Message "Added binding for, [$($this.VirtualServerName)]" $params = @{ - vlanid = $this.VLANID - aliasname = $this.AliasName - ipv6dynamicrouting = $this.ipv6dynamicrouting - mtu = $this.MTU - interface = $this.Interface - } - Add-NSVLAN @params -Confirm:$false + virtualservername = $this.VirtualServerName + policyname = $this.PolicyName + bindpoint = $this.Bindpoint + priority = $this.Priority + } + Add-NSLBVirtualServerResponderPolicyBinding @params -Confirm:$false } } 'Absent' { if ($this.Ensure -ne $NSObject.Ensure) { - Remove-NSVLAN -VLANID $this.VLANID -ErrorAction SilentlyContinue - Write-Verbose -Message "Removed VLANID: $($this.VLANID)" + Remove-NSLBVirtualServerResponderPolicyBinding -VirtualServerName $this.VirtualServerName -PolicyName $this.PolicyName -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed Responder Binding: $($this.PolicyName > $this.VirtualServerName)" } } } + Save-NSConfig } catch { Write-Error 'There was a problem setting the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" @@ -3896,32 +5400,16 @@ class LBVLAN { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { # Run tests and set any needed attributes to match desired configuration - if ($NSObject.vlanid -ne $this.VLANID) { - Write-Verbose -Message "VLANID does not match [$($NSObject.vlanid) <> $($this.VLANID)]" - $pass = $false - } - if ($NSObject.aliasname -ne $this.AliasName) { - Write-Verbose -Message "Aliasname does not match [$($NSObject.aliasname) <> $($this.AliasName)]" - $pass = $false - } - if ($NSObject.ipv6dynamicrouting -ne $this.IPV6DynamicRouting) { - Write-Verbose -Message "IPV6 Dynamic Routing does not match [$($NSObject.ipv6dynamicrouting) <> $($this.IPV6DynamicRouting)]" - $pass = $false - } - if ($NSObject.mtu -ne $this.MTU) { - Write-Verbose -Message "MTU does not match [$($NSObject.mtu) <> $($this.MTU)]" + if ($NSObject.VirtualServerName -ne $this.VirtualServerName) { + Write-Verbose -Message "VirtualServerName does not match [$($NSObject.VirtualServerName) <> $($this.VirtualServerName)]" $pass = $false } - if ($NSObject.interface -ne $this.Interface) { - Write-Verbose -Message "Interface does not match [$($NSObject.interface) <> $($this.Interface)]" + if ($NSObject.PolicyName -ne $this.PolicyName) { + Write-Verbose -Message "PolicyName does not match [$($NSObject.PolicyName) <> $($this.PolicyName)]" $pass = $false } - if ($NSObject.tagged -ne $this.Tagged) { - Write-Verbose -Message "Tagged does not match [$($NSObject.Tagged) <> $($this.Tagged)]" - $pass = $false - } } else { - Write-Verbose -Message "File[$($this.VLANID)] was not found" + Write-Verbose -Message "File[$($this.VirtualServerName > $this.PolicyName)] was not found" $pass = $false } } @@ -3941,34 +5429,26 @@ class LBVLAN { } catch { # Do nothing } - return $pass + return $pass } - [LBVLAN]Get() { + [LBResponderPolicyBinding]Get() { $t = $null $t = $this.Init() try { - $s = Get-NSVLAN -VLANID $this.VLANID -Verbose:$false -ErrorAction SilentlyContinue + $s = Get-NSLBVirtualServerResponderPolicyBinding -Name $this.VirtualServerName -Verbose:$false -ErrorAction SilentlyContinue } catch { $s = $null } - - $obj = [LBVLAN]::new() - $obj.VLANID = $this.VLANID - $obj.AliasName = $this.AliasName - $obj.IPV6DynamicRouting = $this.IPV6DynamicRouting - $obj.MTU = $this.MTU - $obj.Interface = $this.Interface - $obj.Tagged = $this.Tagged + + $obj = [LBResponderPolicyBinding]::new() + $obj.VirtualServerName = $this.VirtualServerName + $obj.PolicyName = $this.PolicyName if ($s) { $obj.Ensure = [ensure]::Present - $obj.VLANID = $s.id - if ($s.AliasName) { $obj.AliasName = $s.aliasname } - $obj.IPV6DynamicRouting = $s.ipv6dynamicrouting - if ($s.mtu) { $obj.MTU = $s.mtu } - $obj.Interface = $s.ifaces.ToString() - $obj.Tagged = $s.tagged + $obj.VirtualServerName = $s.name + $obj.PolicyName = $s.PolicyName } else { $obj.Ensure = [ensure]::Absent } @@ -3978,28 +5458,28 @@ class LBVLAN { } [DscResource()] -class LBResponderPolicyBinding { +class LBServiceGroupMember { [DscProperty(Key)] - [string]$VirtualServerName + [string]$ServiceGroup + + [DscProperty(Mandatory)] + [string]$ServerName [DscProperty()] [Ensure]$Ensure = [Ensure]::Present [DscProperty(Mandatory)] - [string]$NetScalerFQDN - + [string]$NetScalerFQDN + [DscProperty(Mandatory)] [pscredential]$Credential [DscProperty(Mandatory)] - [string]$PolicyName - - [DscProperty()] - [ValidateSet('REQUEST','RESPONSE')] - [string]$Bindpoint = 'REQUEST' + [int]$Port = 80 [DscProperty()] - [int]$Priority = 100 + [ValidateSet('ENABLED','DISABLED')] + [string]$State = 'ENABLED' Init() { try { @@ -4027,28 +5507,36 @@ class LBResponderPolicyBinding { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { # Run tests and set any needed attributes to match desired configuration - if (($NSObject.VirtualServerName -ne $this.VirtualServerName) -OR ($NSObject.PolicyName -ne $this.PolicyName)) { - Write-Warning -Message "Setting VirtualServerName cannot be changed to [$($this.VirtualServerName)], resource can only be removed and recreated" - Remove-NSLBVirtualServerResponderPolicyBinding -VirtualServerName $this.VirtualServerName -PolicyName $this.PolicyName - Add-NSLBVirtualServerResponderPolicyBinding -VirtualServerName $this.VirtualServerName -PolicyName $this.PolicyName -Bindpoint $this.Bindpoint -Priority $this.Priority + if (($NSObject.ServiceGroup -ne $this.ServiceGroup) -OR ($NSObject.ServerName -ne $this.ServerName) -OR ($NSObject.Port -ne $this.Port) -OR ($NSObject.State -ne $this.State)) { + Remove-NSLBServiceGroupMemberBinding -ServiceName $this.ServiceName -ServerName $this.ServerName -Port $this.port + + $params = @{ + Name = $this.ServiceGroup + ServerName = $this.ServerName + Port = $this.Port + State = $this.State + } + + Add-NSLBServiceGroupMemberBinding @params -Confirm:$false } } else { - Write-Verbose -Message "Added binding for, [$($this.VirtualServerName)]" + Write-Verbose -Message "Added binding for, [$($this.ServiceGroup)]" $params = @{ - virtualservername = $this.VirtualServerName - policyname = $this.PolicyName - bindpoint = $this.Bindpoint - priority = $this.Priority - } - Add-NSLBVirtualServerResponderPolicyBinding @params -Confirm:$false + ServiceName = $this.ServiceGroup + ServerName = $this.ServerName + Port = $this.Port + State = $this.State + } + Add-NSLBServiceGroupMemberBinding @params -Confirm:$false } } 'Absent' { if ($this.Ensure -ne $NSObject.Ensure) { - Remove-NSLBVirtualServerResponderPolicyBinding -VirtualServerName $this.VirtualServerName -PolicyName $this.PolicyName -ErrorAction SilentlyContinue - Write-Verbose -Message "Removed Responder Binding: $($this.PolicyName > $this.VirtualServerName)" + Remove-NSLBServiceGroupMemberBinding -ServiceName $this.ServiceName -ServerName $this.ServerName -Port $this.Port -ErrorAction SilentlyContinue + Write-Verbose -Message "Removed $this.ServerName from: $this.ServiceGroup" } } } + Save-NSConfig } catch { Write-Error 'There was a problem setting the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" @@ -4071,16 +5559,24 @@ class LBResponderPolicyBinding { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { # Run tests and set any needed attributes to match desired configuration - if ($NSObject.VirtualServerName -ne $this.VirtualServerName) { - Write-Verbose -Message "VirtualServerName does not match [$($NSObject.VirtualServerName) <> $($this.VirtualServerName)]" + if ($NSObject.ServiceGroup -ne $this.ServiceGroup) { + Write-Verbose -Message "ServiceGroup does not match [$($NSObject.ServiceGroup) <> $($this.ServiceGroup)]" $pass = $false } - if ($NSObject.PolicyName -ne $this.PolicyName) { - Write-Verbose -Message "PolicyName does not match [$($NSObject.PolicyName) <> $($this.PolicyName)]" + if ($NSObject.ServerName -ne $this.ServerName) { + Write-Verbose -Message "ServerName does not match [$($NSObject.ServerName) <> $($this.ServerName)]" + $pass = $false + } + if ($NSObject.Port -ne $this.Port) { + Write-Verbose -Message "Port does not match [$($NSObject.Port) <> $($this.Port)]" $pass = $false - } + } + if ($NSObject.State -ne $this.State) { + Write-Verbose -Message "State does not match [$($NSObject.State) <> $($this.State)]" + $pass = $false + } } else { - Write-Verbose -Message "File[$($this.VirtualServerName > $this.PolicyName)] was not found" + Write-Verbose -Message "Resource [$($this.ServiceGroup > $this.ServerName)] was not found" $pass = $false } } @@ -4100,26 +5596,32 @@ class LBResponderPolicyBinding { } catch { # Do nothing } - return $pass + return $pass } - [LBResponderPolicyBinding]Get() { + [LBServiceGroupMember]Get() { $t = $null $t = $this.Init() + $s = $null + try { - $s = Get-NSLBVirtualServerResponderPolicyBinding -Name $this.VirtualServerName -Verbose:$false -ErrorAction SilentlyContinue + $s = Get-NSLBServiceGroupMemberBinding -ServiceName $this.ServiceGroup | where servername -eq $this.servername -ErrorAction SilentlyContinue } catch { $s = $null } - - $obj = [LBResponderPolicyBinding]::new() - $obj.VirtualServerName = $this.VirtualServerName - $obj.PolicyName = $this.PolicyName + + $obj = [LBServiceGroupMember]::new() + $obj.ServiceGroup = $this.ServiceGroup + $obj.ServerName = $this.ServerName + $obj.Port = $this.Port + $obj.State = $this.State if ($s) { $obj.Ensure = [ensure]::Present - $obj.VirtualServerName = $s.name - $obj.PolicyName = $s.PolicyName + $obj.ServiceGroup = $s.servicegroupname + $obj.ServerName = $s.servername + $obj.Port = $s.port + $obj.State = $s.state } else { $obj.Ensure = [ensure]::Absent } @@ -4128,211 +5630,6 @@ class LBResponderPolicyBinding { } } - -# [DscResource()] -# class LBServiceGroupMember { -# [DscProperty(Key)] -# [string]$Name - -# [DscProperty(Mandatory)] -# [string]$Name - -# [DscProperty()] -# [Ensure]$Ensure = [Ensure]::Present - -# [DscProperty(Mandatory)] -# [string]$NetScalerFQDN - -# [DscProperty(Mandatory)] -# [pscredential]$Credential - -# [DscProperty(Mandatory)] -# [string]$ServerName - -# [DscProperty(Mandatory)] -# [int]$Port = 80 - -# [DscProperty(Mandatory)] -# [int]$Weight = 1 - -# [DscProperty(Mandatory)] -# [int[]]$ServerID - -# [DscProperty(Mandatory)] -# [int[]]$HashID - -# [DscProperty(Mandatory)] -# [ValidateSet('ENABLED','DISABLED')] -# [string[]]$State - -# Init() { -# try { -# Import-Module -Name Netscaler -Verbose:$false -Debug:$false -# Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false -# } catch { -# throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" -# } -# } - -# [void]Set() { -# $t = $null -# $t = $this.Init() -# $NSObject = $this.Get() - -# try { -# Import-Module -Name Netscaler -Verbose:$false -Debug:$false -# Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false -# } catch { -# throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" -# } - -# try { -# switch ($this.Ensure) { -# 'Present' { -# if ($this.Ensure -eq $NSObject.Ensure) { -# # Run tests and set any needed attributes to match desired configuration -# if (($NSObject.Name -ne $this.Name) -OR ($NSObject.ServerName -ne $this.ServerName) -OR ($NSObject.Port -ne $this.Port) -OR ($NSObject.Weight -ne $this.Weight) -OR ($NSObject.State -ne $this.State)) { -# Remove-NSLBServiceGroupMemberBinding -Name $this.Name -ServerName $this.ServerName -Port $this.port -# New-NSLBServiceGroupMember -Name $this.Name -ServerName $this.ServerName -Port $this.Port -Weight $this.Weight -State $this.State -# } -# } else { -# Write-Verbose -Message "Added binding for, [$($this.VirtualServerName)]" -# $params = @{ -# Name = $this.Name -# ServerName = $this.ServerName -# Port = $this.Port -# State = $this.State -# weight = $this.weight -# } -# if ($PSBoundParameters.ContainsKey('ServerID')) { -# $params.Add('ServerID', $this.ServerID) -# } -# if ($PSBoundParameters.ContainsKey('HashID')) { -# $params.Add('HashID', $this.HashID) -# } -# New-NSLBServiceGroupMember @params -Confirm:$false -# } -# } 'Absent' { -# if ($this.Ensure -ne $NSObject.Ensure) { -# Remove-NSLBServiceGroupMemberBinding -Name $this.Name -ServerName $this.ServerName -ErrorAction SilentlyContinue -# Write-Verbose -Message "Removed $this.ServerName from: $this.Name" -# } -# } -# } -# } catch { -# Write-Error 'There was a problem setting the resource' -# Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" -# Write-Error $_ -# } -# try { -# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue -# } catch { -# # Do nothing -# } -# } - -# [bool]Test() { -# $pass = $true -# $t = $null -# $t = $this.Init() -# $NSObject = $this.Get() -# try { -# switch ($this.Ensure) { -# 'Present' { -# if ($this.Ensure -eq $NSObject.Ensure) { -# # Run tests and set any needed attributes to match desired configuration -# if ($NSObject.Name -ne $this.Name) { -# Write-Verbose -Message "ServiceGroupName does not match [$($NSObject.Name) <> $($this.Name)]" -# $pass = $false -# } -# if ($NSObject.ServerName -ne $this.ServerName) { -# Write-Verbose -Message "ServerName does not match [$($NSObject.ServerName) <> $($this.ServerName)]" -# $pass = $false -# } -# if ($NSObject.Port -ne $this.Port) { -# Write-Verbose -Message "Port does not match [$($NSObject.Port) <> $($this.Port)]" -# $pass = $false -# } -# if ($NSObject.Weight -ne $this.Weight) { -# Write-Verbose -Message "Weight does not match [$($NSObject.Weight) <> $($this.Weight)]" -# $pass = $false -# } -# if ($NSObject.ServerId -ne $this.ServerId) { -# Write-Verbose -Message "ServerId does not match [$($NSObject.ServerId) <> $($this.ServerId)]" -# $pass = $false -# } -# if ($NSObject.HashId -ne $this.HashId) { -# Write-Verbose -Message "HashId does not match [$($NSObject.HashId) <> $($this.HashId)]" -# $pass = $false -# } -# if ($NSObject.State -ne $this.State) { -# Write-Verbose -Message "State does not match [$($NSObject.State) <> $($this.State)]" -# $pass = $false -# } -# } else { -# Write-Verbose -Message "File[$($this.VirtualServerName > $this.PolicyName)] was not found" -# $pass = $false -# } -# } -# 'Absent' { -# if ($this.Ensure -ne $NSObject.Ensure) { -# $pass = $false -# } -# } -# } -# } catch { -# Write-Error 'There was a problem testing the resource' -# Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" -# Write-Error $_ -# } -# try { -# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue -# } catch { -# # Do nothing -# } -# return $pass -# } - -# [LBServiceGroupMember]Get() { -# $t = $null -# $t = $this.Init() - -# try { -# $s = Get-NSLBServiceGroupMemberBinding -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue -# } catch { -# $s = $null -# } - -# $obj = [LBServiceGroupMember]::new() -# $obj.Name = $this.Name -# $obj.ServerName = $this.ServerName -# $obj.Port = @() -# # $obj.Weight = $this.Weight -# # $obj.ServerId = $this.ServerId -# # $obj.HashId = $this.HashId -# # $obj.State = $this.State -# if ($s) { -# $obj.Ensure = [ensure]::Present -# $obj.Name = $s.servicegroupname -# $obj.ServerName = $s.servername -# $obj.Port = [int32[]]$s.port -# # $s.Port | % { $obj.port += $_.toString() } -# # for ($i=0;$i -lt $s.port.Length; $i++) { -# # $z = $s.port[$i].toString() -# # $obj.Port = $obj.Port.Add("$z") -# # } -# # $obj.Weight = $s.weight -# # $obj.ServerId = $s.serverid -# # $obj.HashId = $s.hashid -# # $obj.State = $s.state -# } else { -# $obj.Ensure = [ensure]::Absent -# } -# Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue -# return $obj -# } -# } - [DscResource()] class LBService { [DscProperty(Key)] @@ -4342,8 +5639,8 @@ class LBService { [Ensure]$Ensure = [Ensure]::Present [DscProperty(Mandatory)] - [string]$NetScalerFQDN - + [string]$NetScalerFQDN + [DscProperty(Mandatory)] [pscredential]$Credential @@ -4465,11 +5762,11 @@ class LBService { [DscProperty()] [ValidateRange(0, 4294967287)] - [int]$TrafficDomain + [int]$TrafficDomain [DscProperty()] [ValidateRange(0, 65535)] - [int]$ServerID + [int]$ServerID [DscProperty()] [ValidateRange(0, 65535)] @@ -4557,80 +5854,80 @@ class LBService { Write-Verbose -Message "State does not match [$($NSObject.CurState) <> $($this.State)]" Set-NSLBService -Name $this.Name -IPAddress $this.IPAddress -State $this.State } - } - } + } + } if ($NSObject.HealthMonitor -ne $this.HealthMonitor) { Set-NSLBService -Name $this.Name -HealthMonitor $this.HealthMonitor } if ($NSObject.AppFlowLog -ne $this.AppFlowLog) { Set-NSLBService -Name $this.Name -AppFlowLog $this.AppFlowLog - } + } if ($NSObject.Comment -ne $this.Comment) { Set-NSLBService -Name $this.Name -Comment $this.Comment - } + } if ($NSObject.SureConnect -ne $this.SureConnect) { Set-NSLBService -Name $this.Name -SureConnect $this.SureConnect - } + } if ($NSObject.SurgeProtection -ne $this.SurgeProtection) { Set-NSLBService -Name $this.Name -SurgeProtection $this.SurgeProtection - } + } if ($NSObject.UseProxyPort -ne $this.UseProxyPort) { Set-NSLBService -Name $this.Name -UseProxyPort $this.UseProxyPort - } + } if ($NSObject.DownStateFlush -ne $this.DownStateFlush) { Set-NSLBService -Name $this.Name -DownStateFlush $this.DownStateFlush - } + } if ($NSObject.UseClientIP -ne $this.UseClientIP) { Set-NSLBService -Name $this.Name -UseClientIP $this.UseClientIP - } + } if ($NSObject.ClientKeepAlive -ne $this.ClientKeepAlive) { Set-NSLBService -Name $this.Name -ClientKeepAlive $this.ClientKeepAlive - } + } if ($NSObject.TCPBuffering -ne $this.TCPBuffering) { Set-NSLBService -Name $this.Name -TCPBuffering $this.TCPBuffering - } + } if ($NSObject.HTTPCompression -ne $this.HTTPCompression) { Set-NSLBService -Name $this.Name -HTTPCompression $this.HTTPCompression - } + } if ($NSObject.ClientIP -ne $this.ClientIP) { Write-Warning -Message "Setting Name cannot be changed to [$($this.ClientIP)], resource can only be removed and recreated" } # if ($NSObject.PathMonitor -ne $this.PathMonitor) { # Set-NSLBService -Name $this.Name -PathMonitor $this.PathMonitor - # } + # } # if ($NSObject.PathMonitorIndividual -ne $this.PathMonitorIndividual) { # Set-NSLBService -Name $this.Name -PathMonitorIndividual $this.HTTPCompression - # } + # } if ($NSObject.RTPSessionIDRemap -ne $this.RTPSessionIDRemap) { Write-Warning -Message "Setting Name cannot be changed to [$($this.ClientIP)], resource can only be removed and recreated" - } + } if ($NSObject.CustomServerID -ne $this.CustomServerID) { Write-Warning -Message "Setting Name cannot be changed to [$($this.CustomServerID)], resource can only be removed and recreated" - } + } if ($NSObject.MaxBandwidthKbps -ne $this.MaxBandwidthKbps) { Set-NSLBService -Name $this.Name -MaxBandwidthKbps $this.MaxBandwidthKbps - } + } if ($NSObject.AccessDown -ne $this.AccessDown) { Set-NSLBService -Name $this.Name -AccessDown $this.AccessDown - } + } # if ($NSObject.TCPProfileName -ne $this.TCPProfileName) { # Set-NSLBService -Name $this.Name -TCPProfileName $this.TCPProfileName # } # if ($NSObject.HTTPProfileName -ne $this.HTTPProfileName) { # Set-NSLBService -Name $this.Name -HTTPProfileName $this.HTTPProfileName - # } + # } # if ($NSObject.NetProfileName -ne $this.NetProfileName) { # Set-NSLBService -Name $this.Name -NetProfileName $this.NetProfileName - # } + # } # if ($NSObject.HashID -ne $this.HashID) { # Set-NSLBService -Name $this.Name -HashID $this.HashID - # } + # } # if ($NSObject.ProcessLocal -ne $this.ProcessLocal) { # Set-NSLBService -Name $this.Name -ProcessLocal $this.ProcessLocal - # } + # } # if ($NSObject.TrafficDomain -ne $this.TrafficDomain) { # Write-Warning -Message "Setting Name cannot be changed to [$($this.TrafficDomain)], resource can only be removed and recreated" - # } + # } # if ($NSObject.ServerID -ne $this.ServerID) { # Set-NSLBService -Name $this.Name -ServerID $this.ServerID # } @@ -4645,10 +5942,10 @@ class LBService { } # if ($NSObject.ClientIdleTimeout -ne $this.ClientIdleTimeout) { # Set-NSLBService -Name $this.Name -ClientIdleTimeout $this.ClientIdleTimeout - # } + # } # if ($NSObject.ServerIdleTimeout -ne $this.ServerIdleTimeout) { # Set-NSLBService -Name $this.Name -ServerIdleTimeout $this.ServerIdleTimeout - # } + # } } else { Write-Verbose -Message "Added Service, [$($this.Name)]" $params = @{ @@ -4657,7 +5954,7 @@ class LBService { port = $this.Port servername = $this.ServerName comment = $this.Comment - } + } New-NSLBService @params -Confirm:$false } } 'Absent' { @@ -4667,6 +5964,7 @@ class LBService { } } } + Save-NSConfig } catch { Write-Error 'There was a problem setting the resource' Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" @@ -4700,11 +5998,11 @@ class LBService { if ($NSObject.IPAddress -ne $this.IPAddress) { Write-Verbose -Message "IPAddress does not match [$($NSObject.IPAddress) <> $($this.IPAddress)]" $pass = $false - } + } if ($NSObject.Port -ne $this.Port) { Write-Verbose -Message "Port does not match [$($NSObject.Port) <> $($this.Port)]" $pass = $false - } + } if ($NSObject.ServerName -ne $this.ServerName) { Write-Verbose -Message "ServerName does not match [$($NSObject.ServerName) <> $($this.ServerName)]" $pass = $false @@ -4727,28 +6025,28 @@ class LBService { Write-Verbose -Message "ServerName does not match [$($NSObject.CurState) <> $($this.State)]" $pass = $false } - } - } + } + } # if ($NSObject.CacheType -ne $this.CacheType) { # Write-Verbose -Message "CacheType does not match [$($NSObject.CacheType) <> $($this.CacheType)]" # $pass = $false - # } + # } if ($NSObject.Cacheable -ne $this.Cacheable) { Write-Verbose -Message "Cacheable does not match [$($NSObject.Cacheable) <> $($this.Cacheable)]" $pass = $false - } + } if ($NSObject.HealthMonitor -ne $this.HealthMonitor) { Write-Verbose -Message "HealthMonitor does not match [$($NSObject.HealthMonitor) <> $($this.HealthMonitor)]" $pass = $false - } + } if ($NSObject.AppFlowLog -ne $this.AppFlowLog) { Write-Verbose -Message "AppFlowLog does not match [$($NSObject.AppFlowLog) <> $($this.AppFlowLog)]" $pass = $false - } + } if ($NSObject.Comment -ne $this.Comment) { Write-Verbose -Message "Comment does not match [$($NSObject.Comment) <> $($this.Comment)]" $pass = $false - } + } if ($NSObject.SureConnect -ne $this.SureConnect) { Write-Verbose -Message "SureConnect does not match [$($NSObject.SureConnect) <> $($this.SureConnect)]" $pass = $false @@ -4796,47 +6094,47 @@ class LBService { if ($NSObject.RTPSessionIDRemap -ne $this.RTPSessionIDRemap) { Write-Verbose -Message "RTPSessionIDRemap does not match [$($NSObject.RTPSessionIDRemap) <> $($this.RTPSessionIDRemap)]" $pass = $false - } + } if ($NSObject.CustomServerID -ne $this.CustomServerID) { Write-Verbose -Message "CustomServerID does not match [$($NSObject.CustomServerID) <> $($this.CustomServerID)]" $pass = $false - } + } if ($NSObject.MaxBandwidthKbps -ne $this.MaxBandwidthKbps) { Write-Verbose -Message "MaxBandwidthKbps does not match [$($NSObject.MaxBandwidthKbps) <> $($this.MaxBandwidthKbps)]" $pass = $false - } + } if ($NSObject.AccessDown -ne $this.AccessDown) { Write-Verbose -Message "AccessDown does not match [$($NSObject.AccessDown) <> $($this.AccessDown)]" $pass = $false - } + } if ($NSObject.TCPProfileName -ne $this.TCPProfileName) { Write-Verbose -Message "TCPProfileName does not match [$($NSObject.TCPProfileName) <> $($this.TCPProfileName)]" $pass = $false - } + } if ($NSObject.HTTPProfileName -ne $this.HTTPProfileName) { Write-Verbose -Message "HTTPProfileName does not match [$($NSObject.HTTPProfileName) <> $($this.HTTPProfileName)]" $pass = $false - } + } if ($NSObject.NetProfileName -ne $this.NetProfileName) { Write-Verbose -Message "NetProfileName does not match [$($NSObject.NetProfileName) <> $($this.NetProfileName)]" $pass = $false - } + } if ($NSObject.HashID -ne $this.HashID) { Write-Verbose -Message "HashID does not match [$($NSObject.HashID) <> $($this.HashID)]" $pass = $false - } + } if ($NSObject.ProcessLocal -ne $this.ProcessLocal) { Write-Verbose -Message "ProcessLocal does not match [$($NSObject.ProcessLocal) <> $($this.ProcessLocal)]" $pass = $false - } + } if ($NSObject.TrafficDomain -ne $this.TrafficDomain) { Write-Verbose -Message "TrafficDomain does not match [$($NSObject.TrafficDomain) <> $($this.TrafficDomain)]" $pass = $false - } + } if ($NSObject.ServerID -ne $this.ServerID) { Write-Verbose -Message "ServerID does not match [$($NSObject.ServerID) <> $($this.ServerID)]" $pass = $false - } + } if ($NSObject.MonitorThreshold -ne $this.MonitorThreshold) { Write-Verbose -Message "MonitorThreshold does not match [$($NSObject.MonitorThreshold) <> $($this.MonitorThreshold)]" $pass = $false @@ -4856,7 +6154,7 @@ class LBService { if ($NSObject.ServerIdleTimeout -ne $this.ServerIdleTimeout) { Write-Verbose -Message "ServerIdleTimeout does not match [$($NSObject.ServerIdleTimeout) <> $($this.ServerIdleTimeout)]" $pass = $false - } + } } else { Write-Verbose -Message "File[$($this.VirtualServerName > $this.PolicyName)] was not found" $pass = $false @@ -4878,7 +6176,7 @@ class LBService { } catch { # Do nothing } - return $pass + return $pass } [LBService]Get() { @@ -4890,7 +6188,7 @@ class LBService { } catch { $s = $null } - + $obj = [LBService]::new() $obj.Name = $this.Name $obj.ServiceType = $this.ServiceType @@ -4938,8 +6236,8 @@ class LBService { $obj.IPAddress = $s.ipaddress $obj.Port = $s.port $obj.ServerName = $s.servername - # if ($s.cachetype -ne "SERVER") { - # $obj.CacheType = $s.cachetype + # if ($s.cachetype -ne "SERVER") { + # $obj.CacheType = $s.cachetype # } else { # $obj.CacheType = "SERVER" } if ($s.cacheable) { $obj.Cacheable = $s.cacheable } From f94e3c947294619e318d37d69d050e0f5ed3cf08 Mon Sep 17 00:00:00 2001 From: Juan Herrera Date: Wed, 11 Oct 2017 10:55:09 -0700 Subject: [PATCH 6/7] removed psbound parameters from classes --- .../POSHOrigin_NetScaler.psm1 | 299 ++++++------------ 1 file changed, 96 insertions(+), 203 deletions(-) diff --git a/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 b/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 index 1067502..84183b1 100644 --- a/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 +++ b/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 @@ -153,15 +153,10 @@ class LBVirtualServer { Comment = $this.Comment RedirectPortRewrite = $this.RedirectPortRewrite } - if ($null -ne $this.HttpRedirectURL) { - $params.HttpRedirectURL = $this.HttpRedirectURL - } - if ($null -ne $this.ClientTimeout) { - $params.ClientTimeout = $this.ClientTimeout - } - if ($null -ne $this.BackupVServer) { - $params.BackupVServer = $this.BackupVServer - } + if ($this.HttpRedirectURL) { $params.HttpRedirectURL = $this.HttpRedirectURL} + if ($this.ClientTimeout) { $params.ClientTimeout = $this.ClientTimeout } + if ($this.BackupVServer) { $params.BackupVServer = $this.BackupVServer } + New-NSLBVirtualServer @params -ErrorAction SilentlyContinue } } 'Absent' { @@ -732,72 +727,30 @@ class LBServiceGroup { servicetype = $this.ServiceType state = $this.State comment = $this.Comment - } - if ($PSBoundParameters.ContainsKey('TrafficDomainId')) { - $params.Add('TrafficDomainId', $this.TrafficDomainId) - } - if ($PSBoundParameters.ContainsKey('MaxClients')) { - $params.Add('MaxClients', $this.MaxClients) - } - if ($PSBoundParameters.ContainsKey('CacheType')) { - $params.Add('CacheType', $this.CacheType) - } - if ($PSBoundParameters.ContainsKey('AutoScale')) { - $params.Add('AutoScale', $this.AutoScale) - } - if ($PSBoundParameters.ContainsKey('Cacheable')) { - $params.Add('Cacheable', $this.Cacheable) - } - if ($PSBoundParameters.ContainsKey('HealthMonitor')) { - $params.Add('HealthMonitor', $this.HealthMonitor) - } - if ($PSBoundParameters.ContainsKey('AppFlowLog')) { - $params.Add('AppFlowLog', $this.AppFlowLog) - } - if ($PSBoundParameters.ContainsKey('SureConnect')) { - $params.Add('SureConnect', $this.SureConnect) - } - if ($PSBoundParameters.ContainsKey('SurgeProtection')) { - $params.Add('SurgeProtection', $this.SurgeProtection) - } - if ($PSBoundParameters.ContainsKey('UseProxyPort')) { - $params.Add('UseProxyPort', $this.UseProxyPort) - } - if ($PSBoundParameters.ContainsKey('DownStateFlush')) { - $params.Add('DownStateFlush', $this.DownStateFlush) - } - if ($PSBoundParameters.ContainsKey('UseClientIP')) { - $params.Add('UseClientIP', $this.UseClientIP) - } - if ($PSBoundParameters.ContainsKey('ClientKeepAlive')) { - $params.Add('ClientKeepAlive', $this.ClientKeepAlive) - } - if ($PSBoundParameters.ContainsKey('TCPBuffering')) { - $params.Add('TCPBuffering', $this.TCPBuffering) - } - # if ($PSBoundParameters.ContainsKey('HTTPCompression')) { - # $params.Add('HTTPCompression', $this.HTTPCompression) - # } - if ($PSBoundParameters.ContainsKey('ClientIP')) { - $params.Add('ClientIP', $this.ClientIP) - } - if ($PSBoundParameters.ContainsKey('MaxBandwidthKbps')) { - $params.Add('MaxBandwidthKbps', $this.MaxBandwidthKbps) - } - if ($PSBoundParameters.ContainsKey('DownStateFlush')) { - $params.Add('DownStateFlush', $this.DownStateFlush) - } - if ($PSBoundParameters.ContainsKey('MaxRequests')) { - $params.Add('MaxRequests', $this.MaxRequests) - } - if ($PSBoundParameters.ContainsKey('ClientIdleTimeout')) { - $params.Add('ClientIdleTimeout', $this.ClientIdleTimeout) - } - if ($PSBoundParameters.ContainsKey('ServerIdleTimeout')) { - $params.Add('ServerIdleTimeout', $this.ServerIdleTimeout) - } + ServerIdleTimeout = $this.ServerIdleTimeout + ClientIdleTimeout = $this.ClientIdleTimeout + HealthMonitor = $this.HealthMonitor + SurgeProtection = $this.SurgeProtection + SureConnect = $this.SureConnect + AppFlowLog = $this.AppFlowLog + ClientKeepAlive = $this.ClientKeepAlive + ClientIP = $this.ClientIP + AutoScale = $this.AutoScale + Cacheable = $this.Cacheable + } + if ($this.TrafficDomainId) { $params.Add('TrafficDomainId', $this.TrafficDomainId) } + if ($this.MaxClients) { $params.Add('MaxClients', $this.MaxClients) } + if ($this.CacheType) { $params.Add('CacheType', $this.CacheType) } + # if ($this.UseProxyPort) { $params.Add('UseProxyPort', $this.UseProxyPort) } + # if ($this.DownStateFlush) { $params.Add('DownStateFlush', $this.DownStateFlush) } + # if ($this.UseClientIP) { $params.Add('UseClientIP', $this.UseClientIP) } + # if ($this.TCPBuffering) { $params.Add('TCPBuffering', $this.TCPBuffering) } + # if ($this.HTTPCompression) { $params.Add('HTTPCompression', $this.HTTPCompression) } + # if ($this.MaxBandwidthKbps) { $params.Add('MaxBandwidthKbps', $this.MaxBandwidthKbps) } + if ($this.MaxRequests) { $params.Add('MaxRequests', $this.MaxRequests) } + New-NSLBServiceGroup @params -ErrorAction SilentlyContinue - } + }h } 'Absent' { if ($this.Ensure -ne $NSObject.Ensure) { @@ -1270,7 +1223,7 @@ class LBMonitor { } if ($NSObject.httprequest -ne $this.HTTPRequest) { Write-Verbose -Message "Setting HTTP Request was changed to [$($this.HTTPRequest)]" - # Set-NSLBMonitor -Name $this.Name -HTTPRequest $this.HTTPRequest -Verbose:$false -ErrorAction SilentlyContinue + Set-NSLBMonitor -Name $this.Name -HTTPRequest $this.HTTPRequest -Verbose:$false -ErrorAction SilentlyContinueg } } else { Write-Verbose -Message "Creating monitor [$($this.Name)]" @@ -1287,85 +1240,42 @@ class LBMonitor { successretries = $this.SuccessRetries failureRetries = $this.FailureRetries state = $this.State - destinationip = $this.DestinationIP reverse = $this.Reverse lrtm = $this.LRTM transparent = $this.Transparent tos = $this.TOS secure = $this.Secure } - if ($PSBoundParameters.ContainsKey('DestinationPort')) { - $params.Add('DestinationPort', $this.DestinationPort) - } - if ($PSBoundParameters.ContainsKey('Transparent')) { - $params.Add('Transparent', $this.Transparent) - } - if ($PSBoundParameters.ContainsKey('LRTM')) { - $params.Add('LRTM', $this.LRTM) - } - if ($PSBoundParameters.ContainsKey('Secure')) { - $params.Add('Secure', $this.Secure) - } - if ($PSBoundParameters.ContainsKey('IPTunnel')) { - $params.Add('IPTunnel', $this.IPTunnel) - } - if ($PSBoundParameters.ContainsKey('TOS')) { - $params.Add('TOS', $this.TOS) - } - if ($PSBoundParameters.ContainsKey('Reverse')) { - $params.Add('Reverse', $this.Reverse) - } - if ($PSBoundParameters.ContainsKey('DestinationIP')) { - $params.Add('DestinationIP', $this.DestinationIP) - } - if ($PSBoundParameters.ContainsKey('Deviation')) { - $params.Add('Deviation', $this.Deviation) - } - if ($PSBoundParameters.ContainsKey('ResponseTimeoutThreshold')) { - $params.Add('ResponseTimeoutThreshold', $this.ResponseTimeoutThreshold) - } - if ($PSBoundParameters.ContainsKey('AlertRetries')) { - $params.Add('AlertRetries', $this.AlertRetries) - } - if ($PSBoundParameters.ContainsKey('FailureRetries')) { - $params.Add('FailureRetries', $this.FailureRetries) - } - if ($PSBoundParameters.ContainsKey('NetProfile')) { - $params.Add('NetProfile', $this.NetProfile) - } - if ($PSBoundParameters.ContainsKey('TOSID')) { - $params.Add('TOSID', $this.TOSID) - } - if ($PSBoundParameters.ContainsKey('ScriptName')) { - $params.Add('ScriptName', $this.ScriptName) - } - if ($PSBoundParameters.ContainsKey('DispatcherIP')) { - $params.Add('DispatcherIP', $this.DispatcherIP) - } - if ($PSBoundParameters.ContainsKey('ScriptArgs')) { - $params.Add('ScriptArgs', $this.ScriptArgs) - } - if ($PSBoundParameters.ContainsKey('CustomProperty')) { + if ($this.DestinationPort) { $params.Add('DestinationPort', $this.DestinationPort) } + if ($this.Transparent) { $params.Add('Transparent', $this.Transparent) } + if ($this.LRTM) { $params.Add('LRTM', $this.LRTM) } + if ($this.Secure) { $params.Add('Secure', $this.Secure) } + if ($this.IPTunnel) { $params.Add('IPTunnel', $this.IPTunnel) } + if ($this.TOS) { $params.Add('TOS', $this.TOS) } + if ($this.Reverse) { $params.Add('Reverse', $this.Reverse) } + # if ($this.DestinationIP) { $params.Add('DestinationIP', $this.DestinationIP) } + if ($this.DestinationIP) { $params.Add('DestinationIP', $this.DestinationIP) } + if ($this.Deviation) { $params.Add('Deviation', $this.Deviation) } + if ($this.ResponseTimeoutThreshold) { $params.Add('ResponseTimeoutThreshold', $this.ResponseTimeoutThreshold) } + if ($this.AlertRetries) { $params.Add('AlertRetries', $this.AlertRetries) } + if ($this.FailureRetries) { $params.Add('FailureRetries', $this.FailureRetries) } + if ($this.NetProfile) { $params.Add('NetProfile', $this.NetProfile) } + if ($this.TOSID) { $params.Add('TOSID', $this.TOSID) } + if ($this.ScriptName) { $params.Add('ScriptName', $this.ScriptName) } + if ($this.DispatcherIP) { $params.Add('DispatcherIP', $this.DispatcherIP) } + if ($this.ScriptArgs) { $params.Add('ScriptArgs', $this.ScriptArgs) } + if ($this.CustomProperty) { ## Add each custom property to the $params Hashtable foreach ($CustomProperty in $this.CustomProperty.Keys) { $params.Add($CustomProperty.ToLower(), $CustomProperty[$CustomProperty]) } } - if ($PSBoundParameters.ContainsKey('ResponseCode')) { - $params.Add('ResponseCode', $this.ResponseCode) - } - if ($PSBoundParameters.ContainsKey('HTTPRequest')) { - $params.Add('HTTPRequest', $this.HTTPRequest) - } - if ($PSBoundParameters.ContainsKey('Send')) { - $params.Add('Send', $this.Send) - } - if ($PSBoundParameters.ContainsKey('Recv')) { - $params.Add('Recv', $this.Recv) - } - if ($PSBoundParameters.ContainsKey('DispatcherPort')) { - $params.Add('DispatcherPort', $this.DispatcherPort) - } + if ($this.ResponseCode) { $params.Add('ResponseCode', $this.ResponseCode) } + if ($this.HTTPRequest) { $params.Add('HTTPRequest', $this.HTTPRequest) } + if ($this.Send) { $params.Add('Send', $this.Send) } + if ($this.Recv) { $params.Add('Recv', $this.Recv) } + if ($this.DispatcherPort) { $params.Add('DispatcherPort', $this.DispatcherPort) } + New-NSLBMonitor @params -ErrorAction SilentlyContinue } } 'Absent' { @@ -1598,9 +1508,6 @@ class LBServiceGroupMonitorBinding { [DscProperty()] [int]$Weight = 1 - [DscProperty()] - [int]$Port - Init() { try { @@ -1631,22 +1538,22 @@ class LBServiceGroupMonitorBinding { if ($NSObject.ServiceGroupName -ne $this.ServiceGroupName) { Write-Warning -Message "Setting ServiceGroupName [$($this.ServiceGroupName)] does not match, rebinding" Remove-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Confirm:$false - Add-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Weight $this.Weight -Port $this.Port -State $this.State -Confirm:$false + Add-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Weight $this.Weight -State $this.State -Confirm:$false } if ($NSObject.MonitorName -ne $this.MonitorName) { Write-Warning -Message "Setting MonitorName [$($this.MonitorName)] does not match, rebinding" Remove-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Confirm:$false - Add-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Weight $this.Weight -Port $this.Port -State $this.State -Confirm:$false + Add-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Weight $this.Weight -State $this.State -Confirm:$false } if ($NSObject.Weight -ne $this.Weight) { Write-Warning -Message "Setting Weight [$($this.Weight)] does not match, rebinding" Remove-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Confirm:$false - Add-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Weight $this.Weight -Port $this.Port -State $this.State -Confirm:$false + Add-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Weight $this.Weight -State $this.State -Confirm:$false } if ($NSObject.State -ne $this.State) { Write-Warning -Message "Setting State [$($this.State)] does not match, rebinding" Remove-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Confirm:$false - Add-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Weight $this.Weight -Port $this.Port -State $this.State -Confirm:$false + Add-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Weight $this.Weight -State $this.State -Confirm:$false } } else { Write-Verbose -Message "Added [$($this.MonitorName)] binding for, [$($this.ServiceGroupName)]" @@ -1655,7 +1562,6 @@ class LBServiceGroupMonitorBinding { MonitorName = $this.MonitorName Weight = $this.Weight State = $this.State - Port = $this.Port } Add-NSLBServiceGroupMonitorBinding @params -Confirm:$false } @@ -1688,27 +1594,24 @@ class LBServiceGroupMonitorBinding { switch ($this.Ensure) { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { - # Run tests and set any needed attributes to match desired configuration - if ($NSObject.ServiceGroupName -ne $this.ServiceGroupName) { - Write-Verbose -Message "ServiceGroupName does not match [$($NSObject.servicegroupname) <> $($this.ServiceGroupName)]" - $pass = $false - } - if ($NSObject.MonitorName -ne $this.MonitorName) { - Write-Verbose -Message "MonitorName does not match [$($NSObject.MonitorName) <> $($this.MonitorName)]" - $pass = $false - } - if ($NSObject.State -ne $this.State) { - Write-Verbose -Message "State does not match [$($NSObject.State) <> $($this.State)]" - $pass = $false - } - if ($NSObject.Weight -ne $this.Weight) { - Write-Verbose -Message "Weight does not match [$($NSObject.Weight) <> $($this.MonitorName)]" - $pass = $false - } - if ((!$NSObject.Port) -AND ($NSObject.Port -ne $this.Port)) { - Write-Verbose -Message "Port does not match [$($NSObject.Port) <> $($this.Port)]" - $pass = $false - } + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.ServiceGroupName -ne $this.ServiceGroupName) { + Write-Verbose -Message "ServiceGroupName does not match [$($NSObject.servicegroupname) <> $($this.ServiceGroupName)]" + $pass = $false + } + if ($NSObject.MonitorName -ne $this.MonitorName) { + Write-Verbose -Message "MonitorName does not match [$($NSObject.MonitorName) <> $($this.MonitorName)]" + $pass = $false + } + if ($NSObject.State -ne $this.State) { + Write-Verbose -Message "State does not match [$($NSObject.State) <> $($this.State)]" + $pass = $false + } + if ($NSObject.Weight -ne $this.Weight) { + Write-Verbose -Message "Weight does not match [$($NSObject.Weight) <> $($this.MonitorName)]" + $pass = $false + } + } else { Write-Verbose -Message "File [$($this.ServiceGroupName) is not bound to $($this.MonitorName)]" $pass = $false @@ -1748,14 +1651,12 @@ class LBServiceGroupMonitorBinding { $obj.MonitorName = $this.MonitorName $obj.State = $this.State $obj.Weight = $this.Weight - $obj.Port = $this.Port if ($s) { $obj.Ensure = [ensure]::Present $obj.ServiceGroupName = $s.servicegroupname $obj.MonitorName = $s.monitor_name $obj.State = $s.state $obj.Weight = $s.weight - if ($s.port) { $obj.Port = $this.Port } } else { $obj.Ensure = [ensure]::Absent } @@ -2362,12 +2263,10 @@ class LBResponderAction { comment = $this.Comment } - if ($PSBoundParameters.ContainsKey('Target')) { - $params.Add('target', $this.Target) - } - if ($PSBoundParameters.ContainsKey('HTMLPage')) { - $params.Add('HTMLPage', $this.HTMLPage) - } + if (($this.Target) -AND (!$this.HTMLPage)) { $params.Add('target', $this.Target) } + # if ($this.Target) { $params.Add('target', $this.Target) } + if ($this.HTMLPage) { $params.Add('HTMLPage', $this.HTMLPage) } + New-NSResponderAction @params -ErrorAction SilentlyContinue } } 'Absent' { @@ -2554,9 +2453,8 @@ class LBRewritePolicy { actionname = $this.ActionName comment = $this.Comment } - if ($PSBoundParameters.ContainsKey('LogActionName')) { - $params.Add('LogActionName', $this.LogActionName) - } + if ($this.LogActionName) { $params.Add('LogActionName', $this.LogActionName) } + New-NSRewritePolicy @params -ErrorAction SilentlyContinue } } 'Absent' { @@ -3349,15 +3247,10 @@ class LBSSLCertificate { CertPath = $this.CertPath CertKeyFormat = $this.CertKeyFormat } - if ($PSBoundParameters.ContainsKey('KeyPath')) { - $params.Add('KeyPath', $this.KeyPath) - } - # if ($PSBoundParameters.ContainsKey('CertKeyFormat')) { - # $params.Add('CertKeyFormat', $this.CertKeyFormat) - # } - if ($PSBoundParameters.ContainsKey('Password')) { - $params.Add('Password', $this.Password) - } + if ($this.KeyPath) { $params.Add('KeyPath', $this.KeyPath) } + # if ($this.CertKeyFormat) { $params.Add('CertKeyFormat', $this.CertKeyFormat) } + if ($this.Password) { $params.Add('Password', $this.Password) } + Add-NSCertKeyPair @params -ErrorAction SilentlyContinue } } @@ -3900,16 +3793,16 @@ class LBSSLProfile { Name = $this.Name ProfileType = $this.ProfileType } - if ($PSBoundParameters.ContainsKey('SSL2')) { $params.Add('ssl2', $this.SSL2) } - if ($PSBoundParameters.ContainsKey('SSL3')) { $params.Add('ssl3', $this.SSL3) } - if ($PSBoundParameters.ContainsKey('TLS1')) { $params.Add('tls1', $this.TLS1) } - if ($PSBoundParameters.ContainsKey('TLS11')) { $params.Add('tls11', $this.TLS11) } - if ($PSBoundParameters.ContainsKey('TLS12')) { $params.Add('tls12', $this.TLS12) } - if ($PSBoundParameters.ContainsKey('DH')) { $params.Add('dh', $this.DH) } - if ($PSBoundParameters.ContainsKey('DHFile')) { $params.Add('dhfile', $this.DHFile) } - if ($PSBoundParameters.ContainsKey('DHCount')) { $params.Add('dhcount', $this.DHCount) } - if ($PSBoundParameters.ContainsKey('DHKeyExpSizeLimit')) { $params.Add('dhkeyexpsizelimit', $this.DHKeyExpSizeLimit) } - if ($PSBoundParameters.ContainsKey('DenySslRenegotiation')) { $params.Add('denysslrenegotiation', $this.DenySslRenegotiation) } + if ($this.SSL2) { $params.Add('ssl2', $this.SSL2) } + if ($this.SSL3) { $params.Add('ssl3', $this.SSL3) } + if ($this.TLS1) { $params.Add('tls1', $this.TLS1) } + if ($this.TLS11) { $params.Add('tls11', $this.TLS11) } + if ($this.TLS12) { $params.Add('tls12', $this.TLS12) } + if ($this.DH) { $params.Add('dh', $this.DH) } + if ($this.DHFile) { $params.Add('dhfile', $this.DHFile) } + if ($this.DHCount) { $params.Add('dhcount', $this.DHCount) } + if ($this.DHKeyExpSizeLimit) { $params.Add('dhkeyexpsizelimit', $this.DHKeyExpSizeLimit) } + if ($this.DenySslRenegotiation) { $params.Add('denysslrenegotiation', $this.DenySslRenegotiation) } New-NSSSLProfile @params -ErrorAction SilentlyContinue } @@ -4691,7 +4584,7 @@ class LBVirtualServerBinding { Write-Verbose -Message "Service Group Name bound, [$($this.VirtualServerName)]" Add-NSLBVirtualServerBinding -VirtualServerName $this.VirtualServerName -ServiceGroupName $this.ServiceGroupName -Weight $this.Weight -Confirm:$false } else { - if (($this.ServiceName -ne $null) -OR ($NSObject.NetScalerFQDN -ne $null)) { + if (($this.ServiceName -ne $null) -OR ($NSObject.ServiceName -ne $null)) { Write-Verbose -Message "Service Name bound, [$($this.ServiceName)]" Add-NSLBVirtualServerBinding -VirtualServerName $this.VirtualServerName -ServiceName $this.ServiceName -Weight $this.Weight -Confirm:$false } From 04f5ad2c1d10a63d5ea948926b87762f2f9fe5a3 Mon Sep 17 00:00:00 2001 From: Herrera Date: Wed, 18 Oct 2017 15:12:49 -0700 Subject: [PATCH 7/7] refactored some classes and added cert/cipher related dscs --- .../POSHOrigin_NetScaler.psd1 | 4 +- .../POSHOrigin_NetScaler.psm1 | 351 +++++++++++++----- 2 files changed, 265 insertions(+), 90 deletions(-) diff --git a/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psd1 b/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psd1 index dcea5d8..4571e12 100644 --- a/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psd1 +++ b/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psd1 @@ -3,7 +3,7 @@ RootModule = 'POSHOrigin_NetScaler.psm1' # Version number of this module. - ModuleVersion = '1.1.2' + ModuleVersion = '1.1.3' # ID used to uniquely identify this module GUID = 'bd4390dc-a8ad-4bce-8d69-f53ccf8e4163' @@ -24,7 +24,7 @@ RequiredModules = 'NetScaler' # DSC resources to export from this module - DscResourcesToExport = @('LBVirtualServer','LBServer','LBMonitor','LBServiceGroupMonitorBinding','LBServiceGroup','LBNTPServer','LBResponderPolicy','LBResponderAction','LBResponderHTMLPage','LBRewritePolicy','LBRewriteAction','LBDNSServer','LBNSMode','LBNSFeature','LBNSIP','LBVirtualServerBinding','LBSystemFile','LBVLAN','LBResponderPolicyBinding','LBServiceGroupMember','LBService','LBServiceMonitorBinding','LBSSLCertificate','LBSSLCertificateBinding','LBSSLCertificateLink','LBSSLProfile','LBSSLProfileBinding') + DscResourcesToExport = @('LBVirtualServer','LBServer','LBMonitor','LBServiceGroupMonitorBinding','LBServiceGroup','LBNTPServer','LBResponderPolicy','LBResponderAction','LBResponderHTMLPage','LBRewritePolicy','LBRewriteAction','LBDNSServer','LBNSMode','LBNSFeature','LBNSIP','LBVirtualServerBinding','LBSystemFile','LBVLAN','LBResponderPolicyBinding','LBServiceGroupMember','LBService','LBServiceMonitorBinding','LBSSLCertificate','LBSSLCertificateBinding','LBSSLCertificateLink','LBSSLProfile','LBSSLToVserverProfileBinding','LBSSLProfileToVserverBinding','LBCipherToVserverBinding') PrivateData = @{ PSData = @{ diff --git a/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 b/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 index 84183b1..4bbaef5 100644 --- a/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 +++ b/POSHOrigin_NetScaler/POSHOrigin_NetScaler.psm1 @@ -727,30 +727,44 @@ class LBServiceGroup { servicetype = $this.ServiceType state = $this.State comment = $this.Comment - ServerIdleTimeout = $this.ServerIdleTimeout - ClientIdleTimeout = $this.ClientIdleTimeout + AutoScale = $this.AutoScale + Cacheable = $this.Cacheable HealthMonitor = $this.HealthMonitor - SurgeProtection = $this.SurgeProtection SureConnect = $this.SureConnect - AppFlowLog = $this.AppFlowLog + SurgeProtection = $this.SurgeProtection + UseProxyPort = $this.UseProxyPort + DownStateFlush = $this.DownStateFlush + UseClientIP = $this.UseClientIP ClientKeepAlive = $this.ClientKeepAlive + TCPBuffering = $this.TCPBuffering ClientIP = $this.ClientIP - AutoScale = $this.AutoScale - Cacheable = $this.Cacheable + ClientIdleTimeout = $this.ClientIdleTimeout + ServerIdleTimeout = $this.ServerIdleTimeout } - if ($this.TrafficDomainId) { $params.Add('TrafficDomainId', $this.TrafficDomainId) } - if ($this.MaxClients) { $params.Add('MaxClients', $this.MaxClients) } - if ($this.CacheType) { $params.Add('CacheType', $this.CacheType) } + # if ($this.AutoScale) { $params.Add('AutoScale', $this.AutoScale) } + # if ($this.Cacheable) { $params.Add('Cacheable', $this.Cacheable) } + # if ($this.HealthMonitor) { $params.Add('HealthMonitor', $this.HealthMonitor) } + # if ($this.AppFlowLog) { $params.Add('AppFlowLog', $this.AppFlowLog) } + # if ($this.SureConnect) { $params.Add('SureConnect', $this.SureConnect) } + # if ($this.SurgeProtection) { $params.Add('SurgeProtection', $this.SurgeProtection) } # if ($this.UseProxyPort) { $params.Add('UseProxyPort', $this.UseProxyPort) } # if ($this.DownStateFlush) { $params.Add('DownStateFlush', $this.DownStateFlush) } # if ($this.UseClientIP) { $params.Add('UseClientIP', $this.UseClientIP) } + # if ($this.ClientKeepAlive) { $params.Add('ClientKeepAlive', $this.ClientKeepAlive) } # if ($this.TCPBuffering) { $params.Add('TCPBuffering', $this.TCPBuffering) } + # if ($this.ClientIP) { $params.Add('ClientIP', $this.ClientIP) } + # if ($this.ClientIdleTimeout) { $params.Add('ClientIdleTimeout', $this.ClientIdleTimeout) } + # if ($this.ServerIdleTimeout) { $params.Add('ServerIdleTimeout', $this.ServerIdleTimeout) } + + # if ($this.TrafficDomainId) { $params.Add('TrafficDomainId', $this.TrafficDomainId) } + # if ($this.MaxClients) { $params.Add('MaxClients', $this.MaxClients) } + # if ($this.CacheType) { $params.Add('CacheType', $this.CacheType) } # if ($this.HTTPCompression) { $params.Add('HTTPCompression', $this.HTTPCompression) } # if ($this.MaxBandwidthKbps) { $params.Add('MaxBandwidthKbps', $this.MaxBandwidthKbps) } - if ($this.MaxRequests) { $params.Add('MaxRequests', $this.MaxRequests) } + # if ($this.MaxRequests) { $params.Add('MaxRequests', $this.MaxRequests) } New-NSLBServiceGroup @params -ErrorAction SilentlyContinue - }h + } } 'Absent' { if ($this.Ensure -ne $NSObject.Ensure) { @@ -1104,7 +1118,7 @@ class LBMonitor { [System.Collections.Hashtable]$CustomProperty [DscProperty()] - [string]$ResponseCode + [string[]]$ResponseCode [DscProperty()] [string]$HTTPRequest @@ -1223,7 +1237,7 @@ class LBMonitor { } if ($NSObject.httprequest -ne $this.HTTPRequest) { Write-Verbose -Message "Setting HTTP Request was changed to [$($this.HTTPRequest)]" - Set-NSLBMonitor -Name $this.Name -HTTPRequest $this.HTTPRequest -Verbose:$false -ErrorAction SilentlyContinueg + Set-NSLBMonitor -Name $this.Name -HTTPRequest $this.HTTPRequest -Verbose:$false -ErrorAction SilentlyContinue } } else { Write-Verbose -Message "Creating monitor [$($this.Name)]" @@ -1247,18 +1261,11 @@ class LBMonitor { secure = $this.Secure } if ($this.DestinationPort) { $params.Add('DestinationPort', $this.DestinationPort) } - if ($this.Transparent) { $params.Add('Transparent', $this.Transparent) } - if ($this.LRTM) { $params.Add('LRTM', $this.LRTM) } - if ($this.Secure) { $params.Add('Secure', $this.Secure) } if ($this.IPTunnel) { $params.Add('IPTunnel', $this.IPTunnel) } - if ($this.TOS) { $params.Add('TOS', $this.TOS) } - if ($this.Reverse) { $params.Add('Reverse', $this.Reverse) } - # if ($this.DestinationIP) { $params.Add('DestinationIP', $this.DestinationIP) } if ($this.DestinationIP) { $params.Add('DestinationIP', $this.DestinationIP) } if ($this.Deviation) { $params.Add('Deviation', $this.Deviation) } if ($this.ResponseTimeoutThreshold) { $params.Add('ResponseTimeoutThreshold', $this.ResponseTimeoutThreshold) } if ($this.AlertRetries) { $params.Add('AlertRetries', $this.AlertRetries) } - if ($this.FailureRetries) { $params.Add('FailureRetries', $this.FailureRetries) } if ($this.NetProfile) { $params.Add('NetProfile', $this.NetProfile) } if ($this.TOSID) { $params.Add('TOSID', $this.TOSID) } if ($this.ScriptName) { $params.Add('ScriptName', $this.ScriptName) } @@ -1270,8 +1277,8 @@ class LBMonitor { $params.Add($CustomProperty.ToLower(), $CustomProperty[$CustomProperty]) } } - if ($this.ResponseCode) { $params.Add('ResponseCode', $this.ResponseCode) } if ($this.HTTPRequest) { $params.Add('HTTPRequest', $this.HTTPRequest) } + if ($this.ResponseCode) { $params.Add('ResponseCode', $this.ResponseCode ) } if ($this.Send) { $params.Add('Send', $this.Send) } if ($this.Recv) { $params.Add('Recv', $this.Recv) } if ($this.DispatcherPort) { $params.Add('DispatcherPort', $this.DispatcherPort) } @@ -1318,7 +1325,7 @@ class LBMonitor { Write-Verbose -Message "Monitor Name does not match [$($NSObject.monitorname) <> $($this.Name)]" $pass = $false } - if ($NSObject.DestinationIP -ne $this.DestinationIP) { + if (($NSObject.DestinationIP -ne $this.DestinationIP) -AND ($this.DestinationIP -ne $null)) { Write-Verbose -Message "Monitor Destination IP does not match [$($NSObject.DestinationIP) <> $($this.DestinationIP)]" $pass = $false } @@ -1390,10 +1397,11 @@ class LBMonitor { Write-Verbose -Message "Monitor Destination Port does not match [$($NSObject.DestinationPort) <> $($this.DestinationPort)]" $pass = $false } - if ($NSObject.ResponseCode -ne $this.ResponseCode) { + if (diff $this.ResponseCode $NSObject.ResponseCode) { Write-Verbose -Message "Monitor Response Code does not match [$($NSObject.ResponseCode) <> $($this.ResponseCode)]" $pass = $false } + if ($NSObject.HTTPRequest -ne $this.HTTPRequest) { Write-Verbose -Message "Monitor HTTPRequest setting does not match [$($NSObject.HTTPRequest) <> $($this.HTTPRequest)]" $pass = $false @@ -1453,6 +1461,7 @@ class LBMonitor { $obj.FailureRetries = $this.FailureRetries $obj.DestinationPort = $this.DestinationPort $obj.HTTPRequest = $this.HTTPRequest + $obj.ResponseCode = $this.ResponseCode if ($s) { $obj.Ensure = [ensure]::Present $obj.Name = $s.monitorname @@ -1476,6 +1485,7 @@ class LBMonitor { $obj.FailureRetries = $s.failureretries $obj.DestinationPort = $s.destport $obj.HTTPRequest = $s.httprequest + $obj.ResponseCode = $s.respcode -join "," } else { $obj.Ensure = [ensure]::Absent } @@ -1538,22 +1548,22 @@ class LBServiceGroupMonitorBinding { if ($NSObject.ServiceGroupName -ne $this.ServiceGroupName) { Write-Warning -Message "Setting ServiceGroupName [$($this.ServiceGroupName)] does not match, rebinding" Remove-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Confirm:$false - Add-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Weight $this.Weight -State $this.State -Confirm:$false + Add-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Weight $this.Weight -Port $this.Port -State $this.State -Confirm:$false } if ($NSObject.MonitorName -ne $this.MonitorName) { Write-Warning -Message "Setting MonitorName [$($this.MonitorName)] does not match, rebinding" Remove-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Confirm:$false - Add-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Weight $this.Weight -State $this.State -Confirm:$false + Add-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Weight $this.Weight -Port $this.Port -State $this.State -Confirm:$false } if ($NSObject.Weight -ne $this.Weight) { Write-Warning -Message "Setting Weight [$($this.Weight)] does not match, rebinding" Remove-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Confirm:$false - Add-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Weight $this.Weight -State $this.State -Confirm:$false + Add-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Weight $this.Weight -Port $this.Port -State $this.State -Confirm:$false } if ($NSObject.State -ne $this.State) { Write-Warning -Message "Setting State [$($this.State)] does not match, rebinding" Remove-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Confirm:$false - Add-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Weight $this.Weight -State $this.State -Confirm:$false + Add-NSLBServiceGroupMonitorBinding -ServiceGroupName $this.ServiceGroupName -MonitorName $this.MonitorName -Weight $this.Weight -Port $this.Port -State $this.State -Confirm:$false } } else { Write-Verbose -Message "Added [$($this.MonitorName)] binding for, [$($this.ServiceGroupName)]" @@ -3206,8 +3216,8 @@ class LBSSLCertificate { [DscProperty()] [string]$CertKeyFormat - # [DscProperty()] - # [securestring]$Password + [DscProperty()] + [pscredential]$Password Init() { @@ -3236,11 +3246,34 @@ class LBSSLCertificate { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { # Run tests and set any needed attributes to match desired configuration - if (($NSObject.CertKeyName -ne $this.CertKeyName) -OR ($NSObject.CertPath -ne $this.CertPath) -OR ($NSObject.KeyPath -ne $this.KeyPath) -OR ($NSObject.CertKeyFormat -ne $this.CertKeyFormat)) { + $params = @{ + CertKeyName = $this.CertKeyName + CertPath = $this.CertPath + CertKeyFormat = $this.CertKeyFormat + } + if ($this.KeyPath) { $params.Add('KeyPath', $this.KeyPath) } + if ($this.Password) { + $params.Add('Password', $this.Password.Password) + } + + if ($NSObject.CertKeyName -ne $this.CertKeyName) { Write-Verbose -Message "Warning, resource cannot be changed to [$($this.CertKeyName)], resource can only be removed and recreated" Remove-NSCertKeyPair -CertKeyName $this.CertKeyName + Add-NSCertKeyPair @params -ErrorAction SilentlyContinue } - } else { + if ($NSObject.CertPath -ne $this.CertPath) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.CertPath)], resource can only be removed and recreated" + Add-NSCertKeyPair @params -ErrorAction SilentlyContinue + } + if ($NSObject.KeyPath -ne $this.KeyPath) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.KeyPath)], resource can only be removed and recreated" + Add-NSCertKeyPair @params -ErrorAction SilentlyContinue + } + if ($NSObject.CertKeyFormat -ne $this.CertKeyFormat) { + Write-Verbose -Message "Warning, resource cannot be changed to [$($this.CertKeyFormat)], resource can only be removed and recreated" + Add-NSCertKeyPair @params -ErrorAction SilentlyContinue + } + } else { Write-Verbose -Message "Creating resource [$($this.CertKeyName)]" $params = @{ CertKeyName = $this.CertKeyName @@ -3248,9 +3281,9 @@ class LBSSLCertificate { CertKeyFormat = $this.CertKeyFormat } if ($this.KeyPath) { $params.Add('KeyPath', $this.KeyPath) } - # if ($this.CertKeyFormat) { $params.Add('CertKeyFormat', $this.CertKeyFormat) } - if ($this.Password) { $params.Add('Password', $this.Password) } - + if ($this.Password) { + $params.Add('Password',$this.Password.Password) + } Add-NSCertKeyPair @params -ErrorAction SilentlyContinue } } @@ -3284,21 +3317,23 @@ class LBSSLCertificate { switch ($this.Ensure) { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { - # Run tests and set any needed attributes to match desired configuration - if ($NSObject.certkeyname -ne $this.CertKeyName) { - Write-Verbose -Message "Certificate Key Name does not match [$($NSObject.certkeyname) <> $($this.CertKeyName)]" - $pass = $false - } - if ($NSObject.certpath -ne $this.CertPath) { - Write-Verbose -Message "Certificate Path does not match [$($NSObject.certpath) <> $($this.CertPath)]" - $pass = $false - } - if ($this.KeyPath) { - if ($NSObject.keypath -ne $this.KeyPath) { - Write-Verbose -Message "Key Path does not match [$($NSObject.keypath) <> $($this.KeyPath)]" - $pass = $false - } - } + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.certkeyname -ne $this.CertKeyName) { + Write-Verbose -Message "Certificate Key Name does not match [$($NSObject.certkeyname) <> $($this.CertKeyName)]" + $pass = $false + } + if ($NSObject.certpath -ne $this.CertPath) { + Write-Verbose -Message "Certificate Path does not match [$($NSObject.certpath) <> $($this.CertPath)]" + $pass = $false + } + if ($NSObject.keypath -ne $this.KeyPath) { + Write-Verbose -Message "Key Path does not match [$($NSObject.keypath) <> $($this.KeyPath)]" + $pass = $false + } + if ($NSObject.CertKeyFormat -ne $this.CertKeyFormat) { + Write-Verbose -Message "Cert Key Format does not match [$($NSObject.CertKeyFormat) <> $($this.CertKeyFormat)]" + $pass = $false + } } else { Write-Verbose -Message "Certificate[$($this.CertKeyName)] was not found" $pass = $false @@ -3335,16 +3370,16 @@ class LBSSLCertificate { $obj = [LBSSLCertificate]::new() $obj.CertKeyName = $this.CertKeyName $obj.CertPath = $this.CertPath - $obj.CertKeyFormat = $this.CertKeyFormat $obj.KeyPath = $this.KeyPath + $obj.CertKeyFormat = $this.CertKeyFormat + # $obj.Password = $this.Password if ($s) { $obj.Ensure = [ensure]::Present - $obj.CertKeyName = $s.certkey.toString() - $obj.CertPath = $s.cert.toString() - $obj.CertKeyFormat = $s.inform.toString() - if ($s.key) { - $obj.KeyPath = $s.key.toString() - } + $obj.CertKeyName = $s.certkey + $obj.CertPath = $s.cert + if ($s.key) { $obj.KeyPath = $s.key } + $obj.CertKeyFormat = $s.inform + # if ($s.Password) { $this.Password = ''} } else { $obj.Ensure = [ensure]::Absent } @@ -3961,9 +3996,9 @@ class LBSSLProfile { } [DscResource()] -class LBSSLProfileBinding { +class LBSSLToVserverProfileBinding { [DscProperty(Key)] - [string]$Name + [string]$VirtualServerName [DscProperty()] [Ensure]$Ensure = [Ensure]::Present @@ -4003,32 +4038,22 @@ class LBSSLProfileBinding { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { # Run tests and set any needed attributes to match desired configuration - if ($NSObject.name -ne $this.Name) { - Write-Verbose -Message "Warning, resource cannot be changed to [$($this.Name)], resource can only be removed and recreated" + if ($NSObject.VirtualServerName -ne $this.VirtualServerName) { + Set-NSLBSSLVirtualServer -Name $this.VirtualServerName -SSLProfile $this.SSLProfile -Verbose:$false -ErrorAction SilentlyContinue + Write-warning -Message "Warning, attempting to change profile on [$($this.VirtualServerName), please verify" } - if ($NSObject.sslprofile -ne $this.SSLProfile) { - Write-Verbose -Message "Setting SSLProfile [$($this.SSLProfile)]" - Set-NSLBSSLVirtualServer -Name $this.Name -SSLProfile $this.SSLProfile -Verbose:$false - } - } else { - Write-Verbose -Message "Creating resource [$($this.Name)]" - $params = @{ - Name = $this.Name - sslprofile = $this.SSLProfile + if ($NSObject.SSLProfile -ne $this.SSLProfile) { + Write-warning -Message "Warning, attempting to change profile on [$($this.SSLProfile)], please verify" + Set-NSLBSSLVirtualServer -Name $this.VirtualServerName -SSLProfile $this.SSLProfile -Verbose:$false -ErrorAction SilentlyContinue } - - Set-NSLBSSLVirtualServer @params -ErrorAction SilentlyContinue + } else { + Write-Verbose -Message "Creating resource [$($this.VirtualServerName)" + Set-NSLBSSLVirtualServer -Name $this.VirtualServerName -SSLProfile $this.SSLProfile -Verbose:$false -ErrorAction SilentlyContinue } } 'Absent' { if ($this.Ensure -ne $NSObject.Ensure) { - Write-Verbose -Message "Removed resource [$($this.Name)]" - $params = @{ - Name = $this.Name - sslprofile = $this.SSLProfile - } - - Set-NSLBSSLVirtualServer @params -ErrorAction SilentlyContinue + Write-warning -Message "Warning, [$($this.SSLProfile)] must be removed manually from [$($this.VirtualServerName)]" } } } @@ -4056,8 +4081,8 @@ class LBSSLProfileBinding { 'Present' { if ($this.Ensure -eq $NSObject.Ensure) { # Run tests and set any needed attributes to match desired configuration - if ($NSObject.name -ne $this.Name) { - Write-Verbose -Message "Name does not match [$($NSObject.name) <> $($this.Name)]" + if ($NSObject.VirtualServerName -ne $this.VirtualServerName) { + Write-Verbose -Message "VirtualServer does not match [$($NSObject.VirtualServerName) <> $($this.VirtualServerName)]" $pass = $false } if ($NSObject.sslprofile -ne $this.SSLProfile) { @@ -4065,7 +4090,7 @@ class LBSSLProfileBinding { $pass = $false } } else { - Write-Verbose -Message "SSL Profile [$($this.Name)] was not found" + Write-Verbose -Message "SSL Profile for [$($this.VirtualServerName) was not found" $pass = $false } } @@ -4088,22 +4113,22 @@ class LBSSLProfileBinding { return $pass } - [LBSSLProfileBinding]Get() { + [LBSSLToVserverProfileBinding]Get() { $t = $null $t = $this.Init() try { - $s = Get-NSSSLProfile -Name $this.Name -Verbose:$false -ErrorAction SilentlyContinue + $s = Get-NSLBSSLProfileToVserverBinding -VirtualServerName $this.VirtualServerName -Verbose:$false -ErrorAction SilentlyContinue } catch { $s = $null } - $obj = [LBSSLProfileBinding]::new() - $obj.Name = $this.Name - $obj.SSLProfile = $this.SSLProfile + $obj = [LBSSLToVserverProfileBinding]::new() + $obj.VirtualServerName + $obj.SSLProfile if ($s) { $obj.Ensure = [ensure]::Present - $obj.Name = $s.name - $obj.SSLProfile = $s.sslprofile + $obj.VirtualServerName = $s.vservername + if ($s.sslprofile) { $obj.SSLProfile = $s.sslprofile } } else { $obj.Ensure = [ensure]::Absent } @@ -6171,4 +6196,154 @@ class LBService { Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue return $obj } +} + +[DscResource()] +class LBCipherToVserverBinding { + [DscProperty(Key)] + [string]$VirtualServerName + + [DscProperty()] + [Ensure]$Ensure = [Ensure]::Present + + [DscProperty(Mandatory)] + [string]$NetScalerFQDN + + [DscProperty(Mandatory)] + [pscredential]$Credential + + [DscProperty(Mandatory)] + [string]$CipherName + + Init() { + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + } + + [void]Set() { + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + + try { + Import-Module -Name Netscaler -Verbose:$false -Debug:$false + Connect-NetScaler -Hostname $this.NetScalerFQDN -Credential $this.Credential -Verbose:$false + } catch { + throw "Unable to establish a Netscaler session with $($this.NetScalerFQDN)" + } + + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.VirtualServerName -ne $this.VirtualServerName) { + Remove-NSLBSSLVirtualServerCipherGroupBinding -VirtualServerName $this.VirtualServerName -CipherName $this.CipherName + Remove-NSLBSSLVirtualServerCipherGroupBinding -VirtualServerName $this.VirtualServerName -CipherName "DEFAULT" + Add-NSLBSSLVirtualServerCipherGroupBinding -VirtualServerName $this.VirtualServerName -CipherName $this.CipherName + Write-Warning -Message "Binding Cipher [$($this.CipherName)] to virtualserver [$($this.VirtualServerName)" + } + if ($NSObject.CipherName -ne $this.CipherName) { + Remove-NSLBSSLVirtualServerCipherGroupBinding -VirtualServerName $this.VirtualServerName -CipherName $this.CipherName + Remove-NSLBSSLVirtualServerCipherGroupBinding -VirtualServerName $this.VirtualServerName -CipherName "DEFAULT" + Add-NSLBSSLVirtualServerCipherGroupBinding -VirtualServerName $this.VirtualServerName -CipherName $this.CipherName + Write-Warning -Message "Unable to unbind the resource [$($this.SSLProfile)] from virtualserver [$($this.VirtualServerName)" + } + } else { + Write-Verbose -Message "Cipher [$($this.VirtualServerName) was bound to [$($this.CipherName)]" + $params = @{ + CipherName = $this.CipherName + VirtualServer = $this.VirtualServerName + } + Remove-NSLBSSLVirtualServerCipherGroupBinding -VirtualServerName $this.VirtualServerName -CipherName "DEFAULT" + Add-NSLBSSLVirtualServerCipherGroupBinding @params -Confirm:$false + } + } 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + Write-Verbose -Message "Currently unable to remove [$($this.SSLProfile)] binding due to api bug. This must be done manually" + } + } + } + Save-NSConfig + } catch { + Write-Error 'There was a problem setting the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + } + + [bool]Test() { + $pass = $true + $t = $null + $t = $this.Init() + $NSObject = $this.Get() + try { + switch ($this.Ensure) { + 'Present' { + if ($this.Ensure -eq $NSObject.Ensure) { + # Run tests and set any needed attributes to match desired configuration + if ($NSObject.VirtualServerName -ne $this.VirtualServerName) { + Write-Verbose -Message "VirtualServer does not match [$($NSObject.VirtualServerName) <> $($this.VirtualServerName)]" + $pass = $false + } + if ($NSObject.CipherName -ne $this.CipherName) { + Write-Verbose -Message "CipherName does not match [$($NSObject.CipherName) <> $($this.CipherName)]" + $pass = $false + } + } else { + Write-Verbose -Message "Cipher group [$($this.CipherName)] is not bound" + $pass = $false + } + } + 'Absent' { + if ($this.Ensure -ne $NSObject.Ensure) { + $pass = $false + } + } + } + } catch { + Write-Error 'There was a problem testing the resource' + Write-Error "$($_.InvocationInfo.ScriptName)($($_.InvocationInfo.ScriptLineNumber)): $($_.InvocationInfo.Line)" + Write-Error $_ + } + try { + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + } catch { + # Do nothing + } + return $pass + } + + [LBCipherToVserverBinding]Get() { + $t = $null + $t = $this.Init() + + try { + $s = Get-NSLBSSLVirtualServerCipherGroupBinding -VirtualServerName $this.VirtualServerName -ErrorAction SilentlyContinue + } catch { + $s = $null + } + + $obj = [LBCipherToVserverBinding]::new() + $obj.VirtualServerName + $obj.CipherName + if ($s) { + $obj.Ensure = [ensure]::Present + $obj.VirtualServerName = $s.vservername + $obj.CipherName = $s.cipheraliasname + } else { + $obj.Ensure = [ensure]::Absent + } + Disconnect-NetScaler -Verbose:$false -ErrorAction SilentlyContinue + return $obj + } } \ No newline at end of file