Skip to content

Commit 1c36802

Browse files
authored
Merge pull request #66 from dbroeglin/feature/traffic-policy-binding
Added Get-NSLBVirtualServerTrafficPolicyBinding and Add-NSLBVirtualServerTrafficPolicyBinding
2 parents 4c3ea7b + 6016edc commit 1c36802

5 files changed

+188
-8
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+
}

NetScaler/Public/Get-NSLBVirtualServerResponderPolicyBinding.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ limitations under the License.
1717
function Get-NSLBVirtualServerResponderPolicyBinding {
1818
<#
1919
.SYNOPSIS
20-
Gets the specified load balancer virtual server binding object.
20+
Gets the responder policy binding objects for the specified load balancer
21+
virtual server.
2122
2223
.DESCRIPTION
23-
Gets the specified load balancer virtual server binding object.
24+
Gets the responder policy binding objects for the specified load balancer
25+
virtual server.
2426
2527
.EXAMPLE
2628
Get-NSLBVirtualServerResponderPolicyBinding
2729
28-
Get all load balancer virtual server bindings.
30+
Get all load balancer virtual server responder policy bindings.
2931
3032
.EXAMPLE
3133
Get-NSLBVirtualServerResponderPolicyBinding -Name 'vserver01'
@@ -36,7 +38,7 @@ function Get-NSLBVirtualServerResponderPolicyBinding {
3638
The NetScaler session object.
3739
3840
.PARAMETER Name
39-
The name or names of the load balancer virtual server to get.
41+
The name or names of the load balancer virtual server to get policy bindings for.
4042
#>
4143
[cmdletbinding()]
4244
param(

NetScaler/Public/Get-NSLBVirtualServerRewritePolicyBinding.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ limitations under the License.
1717
function Get-NSLBVirtualServerRewritePolicyBinding {
1818
<#
1919
.SYNOPSIS
20-
Gets the specified load balancer virtual server binding object.
20+
Gets the rewrite policy binding objects for the specified load balancer
21+
virtual server.
2122
2223
.DESCRIPTION
23-
Gets the specified load balancer virtual server binding object.
24+
Gets the rewrite policy binding objects for the specified load balancer
25+
virtual server.
2426
2527
.EXAMPLE
2628
Get-NSLBVirtualServerRewritePolicyBinding
2729
28-
Get all load balancer virtual server bindings.
30+
Get all load balancer virtual server rewrite policy bindings.
2931
3032
.EXAMPLE
3133
Get-NSLBVirtualServerRewritePolicyBinding -Name 'vserver01'
@@ -36,7 +38,7 @@ function Get-NSLBVirtualServerRewritePolicyBinding {
3638
The NetScaler session object.
3739
3840
.PARAMETER Name
39-
The name or names of the load balancer virtual server to get.
41+
The name or names of the load balancer virtual server to get policy bindings for.
4042
#>
4143
[cmdletbinding()]
4244
param(
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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 traffic policy binding objects for the specified load balancer
21+
virtual server.
22+
23+
.DESCRIPTION
24+
Gets the traffic policy binding objects for the specified load balancer
25+
virtual server.
26+
27+
.EXAMPLE
28+
Get-NSLBVirtualServerTrafficPolicyBinding
29+
30+
Get all load balancer virtual server bindings.
31+
32+
.EXAMPLE
33+
Get-NSLBVirtualServerTrafficPolicyBinding -Name 'vserver01'
34+
35+
Get the traffic policy bindings for the load balancer virtual server named 'vserver01'.
36+
37+
.PARAMETER Session
38+
The NetScaler session object.
39+
40+
.PARAMETER Name
41+
The name or names of the load balancer virtual server to get policy bindings for.
42+
#>
43+
[cmdletbinding()]
44+
param(
45+
$Session = $script:session,
46+
47+
[parameter(ValueFromPipeline = $true, Position = 0, ValueFromPipelineByPropertyName = $true)]
48+
[string[]]$Name = @()
49+
)
50+
51+
begin {
52+
_AssertSessionActive
53+
$result = @()
54+
}
55+
56+
process {
57+
if ($Name.Count -gt 0) {
58+
foreach ($item in $Name) {
59+
$response = _InvokeNSRestApi -Session $Session -Method Get -Type lbvserver_tmtrafficpolicy_binding -Resource $item
60+
if ($response.errorcode -ne 0) { throw $response }
61+
62+
foreach ($entry in $response) {
63+
if ($entry.PSobject.Properties.name -contains 'lbvserver_tmtrafficpolicy_binding') {
64+
$result += $entry.lbvserver_tmtrafficpolicy_binding
65+
}
66+
}
67+
}
68+
} else {
69+
$vServers = Get-NSLBVirtualServer -Session $Session -Verbose:$false
70+
foreach ($item in $vServers) {
71+
$response = _InvokeNSRestApi -Session $Session -Method Get -Type lbvserver_tmtrafficpolicy_binding -Resource $item.name
72+
if ($response.errorcode -ne 0) { throw $bindings }
73+
if ($response.PSobject.Properties.name -contains 'lbvserver_tmtrafficpolicy_binding') {
74+
$result += $response.lbvserver_tmtrafficpolicy_binding
75+
}
76+
}
77+
}
78+
return $result
79+
}
80+
}

0 commit comments

Comments
 (0)