Skip to content

Commit b00bedd

Browse files
authored
Merge pull request #63 from daimhin/my_contribution
Add NonAddressable Virtual Server Support
2 parents 88c1937 + d27e683 commit b00bedd

File tree

5 files changed

+334
-15
lines changed

5 files changed

+334
-15
lines changed

NetScaler/NetScaler.psd1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ FunctionsToExport = @(
7575
'Add-NSLBServiceGroupMonitorBinding',
7676
'Add-NSLBSSLVirtualServerCertificateBinding',
7777
'Add-NSLBVirtualServerBinding',
78+
'Add-NSCSVirtualServerPolicyBinding',
7879
'Add-NSLBVirtualServerResponderPolicyBinding',
7980
'Add-NSLBVirtualServerRewritePolicyBinding',
8081
'Add-NSLBVirtualServerTrafficPolicyBinding',
@@ -128,6 +129,7 @@ FunctionsToExport = @(
128129
'Get-NSLBStat',
129130
'Get-NSLBVirtualServer',
130131
'Get-NSLBVirtualServerBinding',
132+
'Get-NSCSVirtualServerPolicyBinding',
131133
'Get-NSLBVirtualServerResponderPolicyBinding',
132134
'Get-NSLBVirtualServerRewritePolicyBinding',
133135
'Get-NSLBVirtualServerTrafficPolicyBinding',
@@ -157,6 +159,7 @@ FunctionsToExport = @(
157159
'Install-NSLicense',
158160
'Invoke-Nitro',
159161
'New-NSBackup',
162+
'New-NSCSPolicy',
160163
'New-NSCSVirtualServer',
161164
'New-NSKCDAccount',
162165
'New-NSLBMonitor',
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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 (-not $Priority) {
81+
# No priority was passed so find the highest currently used and add 10 to it
82+
$CSP = Get-NSCSVirtualServerPolicyBinding $Name | Sort-Object Priority -Descending | Select-Object -First 1
83+
$Priority = [double]$CSP.Priority + 10
84+
}
85+
86+
$params = @{
87+
name = $Name
88+
policyname = $PolicyName
89+
targetlbvserver = $TargetLBVServer
90+
priority = $Priority
91+
}
92+
93+
_InvokeNSRestApi -Session $Session -Method PUT -Type csvserver_cspolicy_binding -Payload $params
94+
95+
if ($PSBoundParameters.ContainsKey('PassThru')) {
96+
return Get-NSCSVirtualServerPolicyBinding -Session $Session -Name $Name
97+
}
98+
} catch {
99+
throw $_
100+
}
101+
}
102+
}
103+
}
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)