Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change parsing logic in ATC custom cmdlet #24828

Merged
merged 5 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -167,23 +167,33 @@ param(
)

process {
$rg = $PSBoundParameters.ResourceGroupName

$hasIngestionPolicyIngestionSource = $PSBoundParameters.Remove('IngestionPolicyIngestionSource')
# Ensure exr circuit bandwidth 1G or more
$cktname = $IngestionPolicyIngestionSource.ResourceId | Where {$IngestionPolicyIngestionSource.ResourceId -match "/*subscriptions/(?<subid>.*)/resourceGroups/(?<rgname>.*)/providers/Microsoft.Network/expressRouteCircuits/(?<circuitname>.*)"} | Foreach {$Matches['circuitname']}
Import-Module Az.Network -Force
$exrCircuit = Get-AzExpressRouteCircuit -Name $cktname -ResourceGroupName $rg
$bandwidthInGbps = $exrCircuit.BandwidthInGbps
$bandwidthInMbps = $exrCircuit.ServiceProviderProperties.BandwidthInMbps

if ($bandwidthInGbps -and ($bandwidthInGbps -lt 1)) {
throw "CollectorPolicy can not be updated because circuit has bandwidth less than 1G. Circuit size with a bandwidth of 1G or more is supported."
}

if ($bandwidthInMbps -and ($bandwidthInMbps -lt 1000)) {
throw "CollectorPolicy can not be updated because circuit has bandwidth less than 1G. Circuit size with a bandwidth of 1G or more is supported."
if ($hasIngestionPolicyIngestionSource) {
kukulkarni1 marked this conversation as resolved.
Show resolved Hide resolved
Import-Module Az.Network -Force
$ResourceIdSplit = $IngestionPolicyIngestionSource.ResourceId.Split(' ')
foreach ($ResourceId in $ResourceIdSplit)
{
$Splits = $ResourceId -split "/"
$cktsub = $Splits[2]
$cktrg = $Splits[4]
$cktname = $Splits[8]
Set-AzContext $cktsub -ErrorVariable notPresent -ErrorAction SilentlyContinue
$exrCircuit = Get-AzExpressRouteCircuit -Name $cktname -ResourceGroupName $cktrg
$bandwidthInGbps = $exrCircuit.BandwidthInGbps
$bandwidthInMbps = $exrCircuit.ServiceProviderProperties.BandwidthInMbps

if ($bandwidthInGbps -and ($bandwidthInGbps -lt 1)) {
throw "CollectorPolicy can not be created because circuit has bandwidth less than 1G. Circuit size with a bandwidth of 1G or more is supported."
}

if ($bandwidthInMbps -and ($bandwidthInMbps -lt 1000)) {
throw "CollectorPolicy can not be created because circuit has bandwidth less than 1G. Circuit size with a bandwidth of 1G or more is supported."
}
}
}

Set-AzContext $SubscriptionId -ErrorVariable notPresent -ErrorAction SilentlyContinue
$PSBoundParameters.Add('IngestionPolicyIngestionSource', $IngestionPolicyIngestionSource)
Az.NetworkFunction.internal\New-AzNetworkFunctionCollectorPolicy @PSBoundParameters
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,23 +173,33 @@ process {
$null = $PSBoundParameters.Remove('WhatIf')
$null = $PSBoundParameters.Remove('Confirm')
$null = $PSBoundParameters.Remove('Location')
$rg = $PSBoundParameters.ResourceGroupName

# 2. Ensure exr circuit bandwidth 1G or more
$cktname = $IngestionPolicyIngestionSource.ResourceId | Where {$IngestionPolicyIngestionSource.ResourceId -match "/*subscriptions/(?<subid>.*)/resourceGroups/(?<rgname>.*)/providers/Microsoft.Network/expressRouteCircuits/(?<circuitname>.*)"} | Foreach {$Matches['circuitname']}
Import-Module Az.Network -Force
$exrCircuit = Get-AzExpressRouteCircuit -Name $cktname -ResourceGroupName $rg
$bandwidthInGbps = $exrCircuit.BandwidthInGbps
$bandwidthInMbps = $exrCircuit.ServiceProviderProperties.BandwidthInMbps

if ($bandwidthInGbps -and ($bandwidthInGbps -lt 1)) {
throw "CollectorPolicy can not be updated because circuit has bandwidth less than 1G. Circuit size with a bandwidth of 1G or more is supported."
}

if ($bandwidthInMbps -and ($bandwidthInMbps -lt 1000)) {
throw "CollectorPolicy can not be updated because circuit has bandwidth less than 1G. Circuit size with a bandwidth of 1G or more is supported."
if ($hasIngestionPolicyIngestionSource) {
Import-Module Az.Network -Force
# Ensure exr circuit bandwidth 1G or more
$ResourceIdSplit = $IngestionPolicyIngestionSource.ResourceId.Split(' ')
foreach ($ResourceId in $ResourceIdSplit)
{
$Splits = $ResourceId -split "/"
$cktsub = $Splits[2]
$cktrg = $Splits[4]
$cktname = $Splits[8]
Set-AzContext $cktsub -ErrorVariable notPresent -ErrorAction SilentlyContinue
$exrCircuit = Get-AzExpressRouteCircuit -Name $cktname -ResourceGroupName $cktrg
$bandwidthInGbps = $exrCircuit.BandwidthInGbps
$bandwidthInMbps = $exrCircuit.ServiceProviderProperties.BandwidthInMbps

if ($bandwidthInGbps -and ($bandwidthInGbps -lt 1)) {
throw "CollectorPolicy can not be updated because circuit has bandwidth less than 1G. Circuit size with a bandwidth of 1G or more is supported."
}

if ($bandwidthInMbps -and ($bandwidthInMbps -lt 1000)) {
throw "CollectorPolicy can not be updated because circuit has bandwidth less than 1G. Circuit size with a bandwidth of 1G or more is supported."
}
}
}

Set-AzContext $SubscriptionId -ErrorVariable notPresent -ErrorAction SilentlyContinue
$cp = Get-AzNetworkFunctionCollectorPolicy @PSBoundParameters

# 3. PUT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ Describe 'New-AzNetworkFunctionCollectorPolicy' {
}
}

It 'CreateExpanded2' {
{
{ New-AzNetworkFunctionCollectorPolicy -collectorpolicyname $env.collectorPolicyName -azuretrafficcollectorname $env.azureTrafficCollectorName -resourcegroupname $env.resourceGroup -location $env.location -IngestionPolicyIngestionSource @{ResourceId = $env.ResourceIdLessThan1G}, @{ResourceId = $env.ResourceId1G} -IngestionPolicyIngestionType $env.IngestionType } | Should -Throw -ExpectedMessage "CollectorPolicy can not be updated because circuit has bandwidth less than 1G. Circuit size with a bandwidth of 1G or more is supported."
}
}

It 'Create' {
{
{ New-AzNetworkFunctionCollectorPolicy -collectorpolicyname $env.collectorPolicyName -azuretrafficcollectorname $env.azureTrafficCollectorName -resourcegroupname $env.resourceGroup -location $env.location -IngestionPolicyIngestionSource @{ResourceId = $env.ResourceId1G} -IngestionPolicyIngestionType $env.IngestionType } | Should -Not -Throw
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@ Describe 'Update-AzNetworkFunctionCollectorPolicy' {
{ Update-AzNetworkFunctionCollectorPolicy -collectorpolicyname $env.collectorPolicyName -azuretrafficcollectorname $env.azureTrafficCollectorName -resourcegroupname $env.resourceGroup -location $env.location -IngestionPolicyIngestionSource @{ResourceId = $env.ResourceIdLessThan1G} -IngestionPolicyIngestionType $env.IngestionType } | Should Throw -ExpectedMessage "CollectorPolicy can not be updated because circuit has bandwidth less than 1G. Circuit size with a bandwidth of 1G or more is supported."
}
}

It 'UpdateExpanded2' {
{
{ Update-AzNetworkFunctionCollectorPolicy -collectorpolicyname $env.collectorPolicyName -azuretrafficcollectorname $env.azureTrafficCollectorName -resourcegroupname $env.resourceGroup -location $env.location -IngestionPolicyIngestionSource @{ResourceId = $env.ResourceIdLessThan1G}, @{ResourceId = $env.ResourceId1G} -IngestionPolicyIngestionType $env.IngestionType } | Should Throw -ExpectedMessage "CollectorPolicy can not be updated because circuit has bandwidth less than 1G. Circuit size with a bandwidth of 1G or more is supported."
}
}
}