Skip to content

Instantly share code, notes, and snippets.

@elijahgagne
Created May 31, 2018 00:00
Show Gist options
  • Save elijahgagne/a962ad36ec9244de87c5dd1e1bbdcf1c to your computer and use it in GitHub Desktop.
Save elijahgagne/a962ad36ec9244de87c5dd1e1bbdcf1c to your computer and use it in GitHub Desktop.
function Get-Policy
{
param (
[Parameter(Mandatory=$true)][string]$LTM,
[Parameter(Mandatory=$true)][System.Management.Automation.PSCredential]$Credential,
[Parameter(Mandatory=$true)][string]$Partition,
[Parameter(Mandatory=$true)][string]$PolicyName,
[Parameter(Mandatory=$false)][string]$LTMVersion = $DefaultLTMVersion
)
$Uri = "https://$LTM/mgmt/tm/ltm/policy/~$($Partition)~$($PolicyName)`?ver=$LTMVersion"
$Response = Invoke-RestMethodOverride -Method Get -Uri $Uri -Credential $Credential
$Response | ConvertTo-Json
}
function Get-PolicyRuleList
{
param (
[Parameter(Mandatory=$true)][string]$LTM,
[Parameter(Mandatory=$true)][System.Management.Automation.PSCredential]$Credential,
[Parameter(Mandatory=$true)][string]$Partition,
[Parameter(Mandatory=$true)][string]$PolicyName,
[Parameter(Mandatory=$false)][string]$LTMVersion = $DefaultLTMVersion
)
$Uri = "https://$LTM/mgmt/tm/ltm/policy/~$($Partition)~$($PolicyName)/rules`?ver=$LTMVersion"
$Response = Invoke-RestMethodOverride -Method Get -Uri $Uri -Credential $Credential
$Response | ConvertTo-Json
}
function Get-PolicyRule
{
param (
[Parameter(Mandatory=$true)][string]$LTM,
[Parameter(Mandatory=$true)][System.Management.Automation.PSCredential]$Credential,
[Parameter(Mandatory=$true)][string]$Partition,
[Parameter(Mandatory=$true)][string]$PolicyName,
[Parameter(Mandatory=$true)][string]$RuleName,
[Parameter(Mandatory=$false)][string]$LTMVersion = $DefaultLTMVersion
)
$Uri = "https://$LTM/mgmt/tm/ltm/policy/~$($Partition)~$($PolicyName)/rules/$($RuleName)`?ver=$LTMVersion"
$Response = Invoke-RestMethodOverride -Method Get -Uri $Uri -Credential $Credential
$Response | ConvertTo-Json
}
function Get-PolicyRuleActions
{
param (
[Parameter(Mandatory=$true)][string]$LTM,
[Parameter(Mandatory=$true)][System.Management.Automation.PSCredential]$Credential,
[Parameter(Mandatory=$true)][string]$Partition,
[Parameter(Mandatory=$true)][string]$PolicyName,
[Parameter(Mandatory=$true)][string]$RuleName,
[Parameter(Mandatory=$false)][string]$LTMVersion = $DefaultLTMVersion
)
$Uri = "https://$LTM/mgmt/tm/ltm/policy/~$($Partition)~$($PolicyName)/rules/$($RuleName)/actions`?ver=$LTMVersion"
$Response = Invoke-RestMethodOverride -Method Get -Uri $Uri -Credential $Credential
$Response | ConvertTo-Json
}
function Get-PolicyRuleConditions
{
param (
[Parameter(Mandatory=$true)][string]$LTM,
[Parameter(Mandatory=$true)][System.Management.Automation.PSCredential]$Credential,
[Parameter(Mandatory=$true)][string]$Partition,
[Parameter(Mandatory=$true)][string]$PolicyName,
[Parameter(Mandatory=$true)][string]$RuleName,
[Parameter(Mandatory=$false)][string]$LTMVersion = $DefaultLTMVersion
)
$Uri = "https://$LTM/mgmt/tm/ltm/policy/~$($Partition)~$($PolicyName)/rules/$($RuleName)/conditions`?ver=$LTMVersion"
$Response = Invoke-RestMethodOverride -Method Get -Uri $Uri -Credential $Credential
$Response | ConvertTo-Json
}
function Get-PolicyRuleAction
{
param (
[Parameter(Mandatory=$true)][string]$LTM,
[Parameter(Mandatory=$true)][System.Management.Automation.PSCredential]$Credential,
[Parameter(Mandatory=$true)][string]$Partition,
[Parameter(Mandatory=$true)][string]$PolicyName,
[Parameter(Mandatory=$true)][string]$RuleName,
[Parameter(Mandatory=$true)][int]$Ordinal,
[Parameter(Mandatory=$false)][string]$LTMVersion = $DefaultLTMVersion
)
$Uri = "https://$LTM/mgmt/tm/ltm/policy/~$($Partition)~$($PolicyName)/rules/$($RuleName)/actions/$($Ordinal)`?ver=$LTMVersion"
$Response = Invoke-RestMethodOverride -Method Get -Uri $Uri -Credential $Credential
$Response | ConvertTo-Json
}
function Get-PolicyRuleCondition
{
param (
[Parameter(Mandatory=$true)][string]$LTM,
[Parameter(Mandatory=$true)][System.Management.Automation.PSCredential]$Credential,
[Parameter(Mandatory=$true)][string]$Partition,
[Parameter(Mandatory=$true)][string]$PolicyName,
[Parameter(Mandatory=$true)][string]$RuleName,
[Parameter(Mandatory=$true)][int]$Ordinal,
[Parameter(Mandatory=$false)][string]$LTMVersion = $DefaultLTMVersion
)
$Uri = "https://$LTM/mgmt/tm/ltm/policy/~$($Partition)~$($PolicyName)/rules/$($RuleName)/conditions/$($Ordinal)`?ver=$LTMVersion"
$Response = Invoke-RestMethodOverride -Method Get -Uri $Uri -Credential $Credential
$Response | ConvertTo-Json
}
function New-PolicyRuleForward
{
param (
[Parameter(Mandatory=$true)][string]$LTM,
[Parameter(Mandatory=$true)][System.Management.Automation.PSCredential]$Credential,
[Parameter(Mandatory=$true)][string]$Partition,
[Parameter(Mandatory=$true)][string]$PolicyName,
[Parameter(Mandatory=$true)][string]$RuleName,
[Parameter(Mandatory=$true)][string]$TargetPool,
[Parameter(Mandatory=$false)][string]$LTMVersion = $DefaultLTMVersion
)
$JSONBody = @"
{
"name" : "$RuleName",
"ordinal" : 0,
"actionsReference" : {
"items" : [{
"name" : "0",
"code" : 0,
"forward" : true,
"pool" : "$TargetPool",
"port" : 0,
"request" : true,
"select" : true,
"status" : 0,
"vlanId" : 0
}
]
},
"conditionsReference" : {
"items" : [{
"name" : "0",
"caseInsensitive" : true,
"equals" : true,
"external" : true,
"host" : true,
"httpHost" : true,
"index" : 0,
"present" : true,
"remote" : true,
"request" : true,
"values" : ["$RuleName"]
}
]
}
}
"@
$Uri = "https://$LTM/mgmt/tm/ltm/policy/~$($Partition)~$($PolicyName)/rules`?ver=$LTMVersion"
$Response = Invoke-RestMethodOverride -Method POST -Uri "$URI" -Credential $Credential -Body $JSONBody -ContentType 'application/json'
$Response
}
function New-PolicyRuleRedirect
{
param (
[Parameter(Mandatory=$true)][string]$LTM,
[Parameter(Mandatory=$true)][System.Management.Automation.PSCredential]$Credential,
[Parameter(Mandatory=$true)][string]$Partition,
[Parameter(Mandatory=$true)][string]$PolicyName,
[Parameter(Mandatory=$true)][string]$RuleName,
[Parameter(Mandatory=$true)][string]$TargetURL,
[Parameter(Mandatory=$false)][string]$LTMVersion = $DefaultLTMVersion
)
$JSONBody = @"
{
"name" : "$RuleName",
"ordinal" : 0,
"actionsReference" : {
"items" : [{
"name" : "0",
"code" : 0,
"httpReply" : true,
"location" : "$TargetURL",
"port" : 0,
"redirect" : true,
"request" : true,
"status" : 0,
"vlanId" : 0
}
]
},
"conditionsReference" : {
"items" : [{
"name" : "0",
"caseInsensitive" : true,
"equals" : true,
"external" : true,
"host" : true,
"httpHost" : true,
"index" : 0,
"present" : true,
"remote" : true,
"request" : true,
"values" : ["$RuleName"]
}
]
}
}
"@
$Uri = "https://$LTM/mgmt/tm/ltm/policy/~$($Partition)~$($PolicyName)/rules`?ver=$LTMVersion"
$Response = Invoke-RestMethodOverride -Method POST -Uri "$URI" -Credential $Credential -Body $JSONBody -ContentType 'application/json'
$Response
}
function New-PolicyRuleRedirectWithMatch
{
param (
[Parameter(Mandatory=$true)][string]$LTM,
[Parameter(Mandatory=$true)][System.Management.Automation.PSCredential]$Credential,
[Parameter(Mandatory=$true)][string]$Partition,
[Parameter(Mandatory=$true)][string]$PolicyName,
[Parameter(Mandatory=$true)][string]$RuleName,
[Parameter(Mandatory=$true)][string]$HostMatch,
[Parameter(Mandatory=$true)][string]$UriMatch,
[Parameter(Mandatory=$true)][string]$TargetURL,
[Parameter(Mandatory=$false)][string]$LTMVersion = $DefaultLTMVersion
)
$JSONBody = @"
{
"name" : "$RuleName",
"ordinal" : 0,
"actionsReference" : {
"items" : [{
"name" : "0",
"code" : 0,
"httpReply" : true,
"location" : "$TargetURL",
"port" : 0,
"redirect" : true,
"request" : true,
"status" : 0,
"vlanId" : 0
}
]
},
"conditionsReference" : {
"items" : [{
"name" : "0",
"caseInsensitive" : true,
"equals" : true,
"external" : true,
"host" : true,
"httpHost" : true,
"index" : 0,
"present" : true,
"remote" : true,
"request" : true,
"values" : ["$HostMatch"]
},
{
"name" : "1",
"caseInsensitive" : true,
"external" : true,
"httpUri": true,
"index" : 0,
"path": true,
"present" : true,
"remote" : true,
"request" : true,
"startsWith": true,
"values" : ["$UriMatch"]
}
]
}
}
"@
$Uri = "https://$LTM/mgmt/tm/ltm/policy/~$($Partition)~$($PolicyName)/rules`?ver=$LTMVersion"
$Response = Invoke-RestMethodOverride -Method POST -Uri "$URI" -Credential $Credential -Body $JSONBody -ContentType 'application/json'
$Response
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment