Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for services #104

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions NetScaler/NetScaler.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ FunctionsToExport = @(
'Add-NSDnsNameServer',
'Add-NSDnsSuffix',
'Add-NSIPResource',
'Add-NSLBServiceMonitorBinding',
'Add-NSLBServiceGroupMonitorBinding',
'Add-NSLBSSLVirtualServerCertificateBinding',
'Add-NSLBVirtualServerBinding',
Expand Down Expand Up @@ -123,6 +124,8 @@ FunctionsToExport = @(
'Get-NSKCDAccount',
'Get-NSLBMonitor',
'Get-NSLBServer',
'Get-NSLBService',
'Get-NSLBServiceMonitorBinding',
'Get-NSLBServiceGroup',
'Get-NSLBServiceGroupMemberBinding',
'Get-NSLBServiceGroupMonitorBinding',
Expand Down Expand Up @@ -168,6 +171,7 @@ FunctionsToExport = @(
'New-NSKCDAccount',
'New-NSLBMonitor',
'New-NSLBServer',
'New-NSLBService',
'New-NSLBServiceGroup',
'New-NSLBServiceGroupMember',
'New-NSLBServiceGroupMonitor',
Expand All @@ -187,6 +191,8 @@ FunctionsToExport = @(
'Remove-NSDnsSuffix',
'Remove-NSLBMonitor',
'Remove-NSLBServer',
'Remove-NSLBService',
'Remove-NSLBServiceMonitorBinding',
'Remove-NSLBServiceGroup',
'Remove-NSLBServiceGroupMonitorBinding',
'Remove-NSLBSSLVirtualServerProfile',
Expand All @@ -204,6 +210,7 @@ FunctionsToExport = @(
'Save-NSConfig',
'Set-NSHostname',
'Set-NSLBServer',
'Set-NSLBService',
'Set-NSLBServiceGroup',
'Set-NSLBSSLVirtualServer',
'Set-NSLBSSLVirtualServerProfile',
Expand Down
118 changes: 118 additions & 0 deletions NetScaler/Public/Add-NSLBServiceMonitorBinding.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<#
Copyright 2019 Olli Janatuinen

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#>

function Add-NSLBServiceMonitorBinding {
<#
.SYNOPSIS
Adds a new service monitor binding.

.DESCRIPTION
Adds a new service monitor binding.

.EXAMPLE
Add-NSLBServiceMonitorBinding -ServiceName 'sg01' -MonitorName 'mon01'

Bind the monitor 'mon01' to service 'sg01'.

.EXAMPLE
Add-NSLBServiceMonitorBinding -ServiceName 'sg01' -MonitorName 'mon01' -Force -PassThru

Bind the monitor 'mon01' to service 'sg01'', suppress the confirmation and return the result.

.PARAMETER Session
The NetScaler session object.

.PARAMETER ServiceName
Name of the service to bind the monitor to.

.PARAMETER MonitorName
Name of the monitor to bind to the service.

.PARAMETER Port
Port number of the service. Each service must have a unique port number.

Range: 1 - 65535

.PARAMETER State
Initial state of the service after binding.

Default value: ENABLED
Possible values: ENABLED, DISABLED

.PARAMETER Weight
Weight to assign to the servers in the service. Specifies the capacity of the servers relative to the other servers in the load balancing configuration. The higher the weight, the higher the percentage of requests sent to the service.

Range: 1 - 100

.PARAMETER Force
Suppress confirmation when binding the certificate key to the virtual server.

.PARAMETER Passthru
Return the load balancer server object.
#>
[cmdletbinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')]
param(
$Session = $script:session,

[parameter(Mandatory)]
[string]$ServiceName,

[parameter(Mandatory)]
[string]$MonitorName,

[ValidateSet('ENABLED','DISABLED')]
[string]$State = 'ENABLED',

[ValidateRange(1,100)]
[int]$Weight,

[ValidateRange(1,65535)]
[int]$Port,

[Switch]$Force,

[Switch]$PassThru
)

begin {
_AssertSessionActive
}

process {
if ($Force -or $PSCmdlet.ShouldProcess($ServiceName, 'Add Monitor Binding')) {
try {
$params = @{
name = $ServiceName
monitor_name = $MonitorName
}
if ($PSBoundParameters.ContainsKey('Weight')) {
$params.Add('weight', $Weight)
}
if ($PSBoundParameters.ContainsKey('Port')) {
$params.Add('port', $Port)
}

_InvokeNSRestApi -Session $Session -Method PUT -Type service_lbmonitor_binding -Payload $params

if ($PSBoundParameters.ContainsKey('PassThru')) {
return Get-NSLBServiceMonitorBinding -Session $Session -Name $ServiceName
}
} catch {
throw $_
}
}
}
}
69 changes: 69 additions & 0 deletions NetScaler/Public/Get-NSLBService.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<#
Copyright 2019 Olli Janatuinen

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#>

function Get-NSLBService {
<#
.SYNOPSIS
Gets the specified load balancer service object.

.DESCRIPTION
Gets the specified load balancer service object.

.EXAMPLE
Get-NSLBService

Get all load balancer service objects.

.EXAMPLE
Get-NSLBService -Name 'sg01'

Get the load balancer service named 'sg01'.

.PARAMETER Session
The NetScaler session object.

.PARAMETER Name
The name or names of the load balancer service to get.
#>
[cmdletbinding()]
param(
$Session = $script:session,

[parameter(ValueFromPipeline = $true, Position = 0, ValueFromPipelineByPropertyName)]
[string[]]$Name = @()
)

begin {
_AssertSessionActive
$services = @()
}

process {
if ($Name.Count -gt 0) {
foreach ($item in $Name) {
$services = _InvokeNSRestApi -Session $Session -Method Get -Type service -Action Get -Resource $item
if ($Services.psobject.properties.name -contains 'service') {
return $services.service
}
}
} else {
$services = _InvokeNSRestApi -Session $Session -Method Get -Type service -Action Get
if ($Services.psobject.properties.name -contains 'service') {
return $services.service
}
}
}
}
67 changes: 67 additions & 0 deletions NetScaler/Public/Get-NSLBServiceMonitorBinding.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<#
Copyright 2019 Olli Janatuinen

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#>

function Get-NSLBServiceMonitorBinding {
<#
.SYNOPSIS
Gets the service binding for a service.

.DESCRIPTION
Gets the service binding for a service.

.EXAMPLE
Get-NSLBServiceMonitorBinding -Name $sg

Gets the service bindings for the 'sg' service.

.PARAMETER Session
The NetScaler session object.

.PARAMETER Name
The name or names of the service to get the service member binding for.

.PARAMETER MonitorName
Filters the returned monitors to only include the name specified
#>
[cmdletbinding()]
param(
$Session = $script:session,

[parameter(Mandatory, ValueFromPipeline = $true, Position = 0, ValueFromPipelineByPropertyName)]
[string[]]$Name,

[parameter()]
[string]$MonitorName
)

begin {
_AssertSessionActive
}

process {
try {
# Contruct a filter hash if we specified any filters
$Filters = @{}
if ($PSBoundParameters.ContainsKey('MonitorName')) {
$Filters['monitor_name'] = $MonitorName
}
_InvokeNSRestApiGet -Session $Session -Type service_lbmonitor_binding -Name $Name -Filters $Filters
}
catch {
throw $_
}
}
}
Loading