Skip to content

Commit a6b1f54

Browse files
committed
Adding Content Switching Policy cmdlets
Added new cmdlets for managing the Content Switching Policy objects and their binding to content switching virtual servers.
1 parent ee6af6b commit a6b1f54

File tree

4 files changed

+304
-3
lines changed

4 files changed

+304
-3
lines changed

NetScaler/NetScaler.psd1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ FunctionsToExport = @(
7575
'Add-NSLBServiceGroupMonitorBinding',
7676
'Add-NSLBSSLVirtualServerCertificateBinding',
7777
'Add-NSLBVirtualServerBinding',
78+
'Add-NSCSVirtualServerPolicyBinding',
7879
'Add-NSLBVirtualServerResponderPolicyBinding',
7980
'Add-NSLBVirtualServerRewritePolicyBinding',
8081
'Add-NSRSAKey',
8182
'Add-NSServerCertificate',
8283
'Add-NSSSLCertificateLink',
8384
'Add-NSSystemFile',
8485
'Add-NSVPNVirtualServerBinding',
85-
'Clear-NSAAASession',
8686
'Clear-NSConfig',
8787
'Connect-NetScaler',
8888
'Disable-NSFeature',
@@ -126,6 +126,7 @@ FunctionsToExport = @(
126126
'Get-NSLBStat',
127127
'Get-NSLBVirtualServer',
128128
'Get-NSLBVirtualServerBinding',
129+
'Get-NSCSVirtualServerPolicyBinding',
129130
'Get-NSLBVirtualServerResponderPolicyBinding',
130131
'Get-NSLBVirtualServerRewritePolicyBinding',
131132
'Get-NSLDAPAuthenticationPolicy',
@@ -154,6 +155,7 @@ FunctionsToExport = @(
154155
'Install-NSLicense',
155156
'Invoke-Nitro',
156157
'New-NSBackup',
158+
'New-NSCSPolicy',
157159
'New-NSCSVirtualServer',
158160
'New-NSKCDAccount',
159161
'New-NSLBMonitor',
@@ -167,8 +169,6 @@ FunctionsToExport = @(
167169
'New-NSNTPServer',
168170
'New-NSResponderAction',
169171
'New-NSResponderPolicy',
170-
'New-NSRewriteAction',
171-
'New-NSRewritePolicy',
172172
'New-NSNTPServer',
173173
'New-NSSSLProfile',
174174
'New-NSVPNSessionPolicy',
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<#
2+
Copyright 2017 Eric Carr
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-NSCSVirtualServerPolicyBinding {
18+
<#
19+
.SYNOPSIS
20+
Adds a new content switching virtual server policy binding.
21+
22+
.DESCRIPTION
23+
Adds a new content switching virtual server policy binding.
24+
25+
.EXAMPLE
26+
Add-NSCSVirtualServerPolicyBinding -Name 'cs01' -PolicyName 'pol01' -TargetLBVServer 'vserver01' -Priority '100'
27+
28+
Bind the policy 'pol01' as a policy with a priority of 100 to virtual server 'vserver01'.
29+
30+
.PARAMETER Session
31+
The NetScaler session object.
32+
33+
.PARAMETER -Name
34+
Name of the content switching virtual server.
35+
36+
.PARAMETER -PolicyName
37+
Name for the content switching policy to bind.
38+
39+
.PARAMETER -TargetLBVServer
40+
Name for the load balance virtual server.
41+
42+
Minimum length = 1
43+
44+
.PARAMETER Priority
45+
Policy priority.
46+
47+
.PARAMETER Passthru
48+
Return the load balancer server object.
49+
#>
50+
[cmdletbinding(SupportsShouldProcess = $true, ConfirmImpact='Medium')]
51+
param(
52+
$Session = $script:session,
53+
54+
[parameter(Mandatory=$True)]
55+
[string]
56+
$Name,
57+
58+
[parameter(Mandatory=$True)]
59+
[string]
60+
$PolicyName,
61+
62+
[parameter(Mandatory=$True)]
63+
[string]
64+
$TargetLBVServer,
65+
66+
[ValidateRange(1, 2147483647)]
67+
[int]
68+
$Priority,
69+
70+
[Switch]$PassThru
71+
)
72+
73+
begin {
74+
_AssertSessionActive
75+
}
76+
77+
process {
78+
if ($PSCmdlet.ShouldProcess($Name, 'Add Content Switching Virtual Server Binding')) {
79+
try {
80+
if ($Priority) {
81+
$params = @{
82+
name = $Name
83+
policyname = $PolicyName
84+
targetlbvserver = $TargetLBVServer
85+
priority = $Priority
86+
}
87+
} else {
88+
$params = @{
89+
name = $Name
90+
policyname = $PolicyName
91+
targetlbvserver = $TargetLBVServer
92+
}
93+
}
94+
95+
_InvokeNSRestApi -Session $Session -Method PUT -Type csvserver_cspolicy_binding -Payload $params
96+
97+
if ($PSBoundParameters.ContainsKey('PassThru')) {
98+
return Get-NSCSVirtualServerPolicyBinding -Session $Session -Name $Name
99+
}
100+
} catch {
101+
throw $_
102+
}
103+
}
104+
}
105+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<#
2+
Copyright 2017 Eric Carr
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-NSCSVirtualServerPolicyBinding {
18+
<#
19+
.SYNOPSIS
20+
Gets the specified content switching virtual server policy binding object.
21+
22+
.DESCRIPTION
23+
Gets the specified content switching virtual server policy binding object.
24+
25+
.EXAMPLE
26+
Get-NSCSVirtualServerPolicyBinding
27+
28+
Get all content switching load balancer virtual server bindings.
29+
30+
.EXAMPLE
31+
Get-NSCSVirtualServerPolicyBinding -Name 'vserver01'
32+
33+
Get the policy bindings for the content switching 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.
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 csvserver_cspolicy_binding -Resource $item
58+
if ($response.errorcode -ne 0) { throw $response }
59+
60+
foreach ($entry in $response) {
61+
if ($entry.PSobject.Properties.name -contains 'csvserver_cspolicy_binding') {
62+
$result += $entry.csvserver_cspolicy_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 csvserver_cspolicy_binding -Resource $item.name
70+
if ($response.errorcode -ne 0) { throw $bindings }
71+
if ($response.PSobject.Properties.name -contains 'csvserver_cspolicy_binding') {
72+
$result += $response.csvserver_cspolicy_binding
73+
}
74+
}
75+
}
76+
return $result
77+
}
78+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<#
2+
Copyright 2017 Eric Carr
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 New-NSCSPolicy {
18+
<#
19+
.SYNOPSIS
20+
Adds a content switching policy.
21+
22+
.DESCRIPTION
23+
Adds a content switching policy.
24+
25+
.EXAMPLE
26+
New-NSCSPolicy -Name 'policy-CS' -Rule 'CLIENT.IP.SRC.SUBNET(24).EQ(10.217.84.0)'
27+
28+
Creates a new content switching policy using the rule provided
29+
30+
.PARAMETER Session
31+
The NetScaler session object.
32+
33+
.PARAMETER Name
34+
The name of content switching policy.
35+
36+
.PARAMETER Domain
37+
The domain to match against for this policy.
38+
39+
.PARAMETER URL
40+
The URL or part of URL that is matched for the policy.
41+
42+
.PARAMETER Rule
43+
The rule/expression that has to be matched for this policy to apply.
44+
45+
Minimum length: 0
46+
Maximum length: 8191
47+
48+
.PARAMETER Action
49+
The name of the action to execute when this policy is matched.
50+
51+
.PARAMETER Passthru
52+
Return the newly created rewrite policy.
53+
#>
54+
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact='Low')]
55+
param(
56+
$Session = $script:session,
57+
58+
[Parameter(Mandatory, ValueFromPipeline = $true, Position = 0, ValueFromPipelineByPropertyName = $true)]
59+
[string[]]$Name,
60+
61+
[Parameter(Mandatory = $true, ParameterSetName = "Domain")]
62+
[string]$Domain,
63+
64+
[Parameter(Mandatory = $true, ParameterSetName = "URL")]
65+
[string]$URL,
66+
67+
[Parameter(Mandatory = $true, ParameterSetName = "Rule")]
68+
[ValidateLength(0, 8191)]
69+
[string]$Rule,
70+
71+
[Parameter(ParameterSetName = "Rule")]
72+
[string]$Action,
73+
74+
[Switch]$PassThru
75+
)
76+
77+
begin {
78+
_AssertSessionActive
79+
}
80+
81+
process {
82+
foreach ($Item in $Name) {
83+
if ($PSCmdlet.ShouldProcess($Item, 'Create content switching policy')) {
84+
try {
85+
if ($Domain) {
86+
$params = @{
87+
policyname = $Item
88+
domain = $Domain
89+
}
90+
} elseif ($URL) {
91+
$params = @{
92+
policyname = $Item
93+
url = $URL
94+
}
95+
} elseif ($Action) {
96+
$params = @{
97+
policyname = $Item
98+
rule = $Rule
99+
action = $Action
100+
}
101+
} else {
102+
$params = @{
103+
policyname = $Item
104+
rule = $Rule
105+
}
106+
}
107+
_InvokeNSRestApi -Session $Session -Method POST -Type cspolicy -Payload $params -Action add
108+
109+
if ($PSBoundParameters.ContainsKey('PassThru')) {
110+
return Get-NSCSPolicy -Session $Session -Name $Item
111+
}
112+
} catch {
113+
throw $_
114+
}
115+
}
116+
}
117+
}
118+
}

0 commit comments

Comments
 (0)