Skip to content

Commit 18300cf

Browse files
committed
Added Add/Get-NSLBVirtualServerTrafficPolicyBinding
1 parent 4c3ea7b commit 18300cf

File tree

3 files changed

+174
-0
lines changed

3 files changed

+174
-0
lines changed

NetScaler/NetScaler.psd1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ FunctionsToExport = @(
7777
'Add-NSLBVirtualServerBinding',
7878
'Add-NSLBVirtualServerResponderPolicyBinding',
7979
'Add-NSLBVirtualServerRewritePolicyBinding',
80+
'Add-NSLBVirtualServerTrafficPolicyBinding',
8081
'Add-NSRSAKey',
8182
'Add-NSServerCertificate',
8283
'Add-NSSSLCertificateLink',
@@ -128,6 +129,7 @@ FunctionsToExport = @(
128129
'Get-NSLBVirtualServerBinding',
129130
'Get-NSLBVirtualServerResponderPolicyBinding',
130131
'Get-NSLBVirtualServerRewritePolicyBinding',
132+
'Get-NSLBVirtualServerTrafficPolicyBinding',
131133
'Get-NSLDAPAuthenticationPolicy',
132134
'Get-NSLDAPAuthenticationServer',
133135
'Get-NSResponderAction',
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<#
2+
Copyright 2017 Dominique Broeglin
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
#>
16+
17+
function Add-NSLBVirtualServerTrafficPolicyBinding {
18+
<#
19+
.SYNOPSIS
20+
Adds a new load balancer traffic policy binding.
21+
22+
.DESCRIPTION
23+
Adds a new load balancer traffic policy binding.
24+
25+
.EXAMPLE
26+
Add-NSLBVirtualServerTrafficPolicyBinding -VirtualServerName 'vserver01' -PolicyName 'pol01' -Priority '100'
27+
28+
Bind the policy 'pol01' as a traffic policy with a priority of 100 to virtual server 'vserver01'.
29+
30+
.PARAMETER Session
31+
The NetScaler session object.
32+
33+
.PARAMETER VirtualServerName
34+
Name for the virtual server. Must begin with an ASCII alphanumeric or underscore (_) character, and must contain
35+
only ASCII alphanumeric, underscore, hash (#), period (.), space, colon (:), at sign (@), equal sign (=),
36+
and hyphen (-) characters. Can be changed after the virtual server is created.
37+
38+
Minimum length = 1
39+
40+
.PARAMETER PolicyName
41+
Name of the policy bound to the LB virtual server.
42+
43+
.PARAMETER Priority
44+
Policy priority.
45+
46+
.PARAMETER Passthru
47+
Return the policy binding object.
48+
#>
49+
[cmdletbinding(SupportsShouldProcess = $true, ConfirmImpact='Medium')]
50+
param(
51+
$Session = $script:session,
52+
53+
[parameter(Mandatory=$True)]
54+
[string]
55+
$VirtualServerName,
56+
57+
[parameter(Mandatory=$True)]
58+
[string]
59+
$PolicyName,
60+
61+
[parameter(Mandatory=$True)]
62+
[ValidateRange(1, 2147483647)]
63+
[int]
64+
$Priority,
65+
66+
[Switch]$PassThru
67+
)
68+
69+
begin {
70+
_AssertSessionActive
71+
}
72+
73+
process {
74+
if ($PSCmdlet.ShouldProcess($VirtualServerName, 'Add Virtual Server Binding')) {
75+
try {
76+
77+
$params = @{
78+
name = $VirtualServerName
79+
policyname = $PolicyName
80+
bindpoint = 'REQUEST'
81+
priority = $Priority
82+
}
83+
84+
_InvokeNSRestApi -Session $Session -Method PUT -Type lbvserver_tmtrafficpolicy_binding -Payload $params
85+
86+
if ($PSBoundParameters.ContainsKey('PassThru')) {
87+
return Get-NSLBVirtualServerTrafficPolicyBinding -Session $Session -Name $VirtualServerName
88+
}
89+
} catch {
90+
throw $_
91+
}
92+
}
93+
}
94+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<#
2+
Copyright 2017 Dominique Broeglin
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
#>
16+
17+
function Get-NSLBVirtualServerTrafficPolicyBinding {
18+
<#
19+
.SYNOPSIS
20+
Gets the specified load balancer virtual server binding object.
21+
22+
.DESCRIPTION
23+
Gets the specified load balancer virtual server binding object.
24+
25+
.EXAMPLE
26+
Get-NSLBVirtualServerTrafficPolicyBinding
27+
28+
Get all load balancer virtual server bindings.
29+
30+
.EXAMPLE
31+
Get-NSLBVirtualServerTrafficPolicyBinding -Name 'vserver01'
32+
33+
Get the traffic policy bindings for the load balancer virtual server named 'vserver01'.
34+
35+
.PARAMETER Session
36+
The NetScaler session object.
37+
38+
.PARAMETER Name
39+
The name or names of the load balancer virtual server to get policy bindings for.
40+
#>
41+
[cmdletbinding()]
42+
param(
43+
$Session = $script:session,
44+
45+
[parameter(ValueFromPipeline = $true, Position = 0, ValueFromPipelineByPropertyName = $true)]
46+
[string[]]$Name = @()
47+
)
48+
49+
begin {
50+
_AssertSessionActive
51+
$result = @()
52+
}
53+
54+
process {
55+
if ($Name.Count -gt 0) {
56+
foreach ($item in $Name) {
57+
$response = _InvokeNSRestApi -Session $Session -Method Get -Type lbvserver_tmtrafficpolicy_binding -Resource $item
58+
if ($response.errorcode -ne 0) { throw $response }
59+
60+
foreach ($entry in $response) {
61+
if ($entry.PSobject.Properties.name -contains 'lbvserver_tmtrafficpolicy_binding') {
62+
$result += $entry.lbvserver_tmtrafficpolicy_binding
63+
}
64+
}
65+
}
66+
} else {
67+
$vServers = Get-NSLBVirtualServer -Session $Session -Verbose:$false
68+
foreach ($item in $vServers) {
69+
$response = _InvokeNSRestApi -Session $Session -Method Get -Type lbvserver_tmtrafficpolicy_binding -Resource $item.name
70+
if ($response.errorcode -ne 0) { throw $bindings }
71+
if ($response.PSobject.Properties.name -contains 'lbvserver_tmtrafficpolicy_binding') {
72+
$result += $response.lbvserver_tmtrafficpolicy_binding
73+
}
74+
}
75+
}
76+
return $result
77+
}
78+
}

0 commit comments

Comments
 (0)