Skip to content

Commit 5477837

Browse files
mbrat2005Copilot
andauthored
Nat rule migration improvements (#161)
* add milliseconds to logging * Remove use of AzJob for LB save to simplify flow * v2.5.40 * Update AzureBasicLoadBalancerUpgrade/module/AzureBasicLoadBalancerUpgrade/modules/NatRulesMigration/NatRulesMigration.psm1 Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 80bbe1e commit 5477837

File tree

3 files changed

+6
-16
lines changed

3 files changed

+6
-16
lines changed

AzureBasicLoadBalancerUpgrade/module/AzureBasicLoadBalancerUpgrade/AzureBasicLoadBalancerUpgrade.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'AzureBasicLoadBalancerUpgrade'
1313

1414
# Version number of this module.
15-
ModuleVersion = '2.5.39'
15+
ModuleVersion = '2.5.40'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()
@@ -107,7 +107,7 @@
107107
# IconUri = ''
108108

109109
# ReleaseNotes of this module
110-
ReleaseNotes = 'Improve NAT Rule migration logging and error handling.'
110+
ReleaseNotes = 'Simplify NAT Rule migration.'
111111

112112
# Prerelease string of this module
113113
# Prerelease = 'beta'

AzureBasicLoadBalancerUpgrade/module/AzureBasicLoadBalancerUpgrade/modules/Log/Log.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function log {
1717
$terminateOnError
1818
)
1919

20-
$timestamp = Get-Date -Format 'yyyy-MM-ddTHH:mm:sszz'
20+
$timestamp = Get-Date -Format 'yyyy-MM-ddTHH:mm:ss.ffzz'
2121
Add-Content -Path ("Start-AzBasicLoadBalancerUpgrade.log") -Value ($timestamp + " " + "[$Severity] - " + $Message) -Force
2222
$outputMessage = "{0} [{1}]:{2}" -f $timestamp, $Severity,($Message -replace '\s\s+?','')
2323
If ($global:FollowLog) {

AzureBasicLoadBalancerUpgrade/module/AzureBasicLoadBalancerUpgrade/modules/NatRulesMigration/NatRulesMigration.psm1

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -152,24 +152,14 @@ function NatRulesMigration {
152152
return
153153
}
154154
else {
155-
log -Message "[NatRulesMigration] $($StdLoadBalancer.InboundNatRules.Count) NAT Rules migrated. Saving Standard Load Balancer '$($StdLoadBalancer.Name)'..."
155+
log -Message "[NatRulesMigration] $($StdLoadBalancer.InboundNatRules.Count) NAT Rules applied to LB config. Saving Standard Load Balancer '$($StdLoadBalancer.Name)'..."
156156

157157
try {
158158
$ErrorActionPreference = 'Stop'
159-
160-
$UpdateLBNATRulesJob = Set-AzLoadBalancer -LoadBalancer $StdLoadBalancer -AsJob
161-
162-
While ($UpdateLBNATRulesJob.State -eq 'Running') {
163-
Start-Sleep -Seconds 15
164-
log -Message "[NatRulesMigration] Waiting for saving standard load balancer $($StdLoadBalancer.Name) job to complete..."
165-
}
166-
167-
If ($UpdateLBNATRulesJob.Error -or $UpdateLBNATRulesJob.State -eq 'Failed') {
168-
log -Severity Error -Message "Saving Standard Load Balancer $($StdLoadBalancer.Name) failed with the following errors: $($UpdateLBNATRulesJob.error; $UpdateLBNATRulesJob | Receive-Job). Migration will continue--to recover, manually add the NAT rules to the load balancer, then correct NAT Rule NIC membership after the script completes."
169-
}
159+
Set-AzLoadBalancer -LoadBalancer $StdLoadBalancer > $null
170160
}
171161
catch {
172-
$message = "[NatRulesMigration] Failed to update new standard load balancer '$($stdLoadBalancer.Name)' in resource group '$($StdLoadBalancer.ResourceGroupName)' after attempting to add migrated inbound NAT rule configurations. Migration will continue, INBOUND NAT RULES WILL NEED TO BE MANUALLY ADDED to the load balancer. Error: $_"
162+
$message = "[NatRulesMigration] Failed to update new standard load balancer '$($stdLoadBalancer.Name)' in resource group '$($StdLoadBalancer.ResourceGroupName)' after attempting to apply NAT Rules to LB config. Migration will continue, INBOUND NAT RULES WILL NEED TO BE MANUALLY ADDED to the load balancer. Error: $_"
173163
log "Error" $message
174164
}
175165
}

0 commit comments

Comments
 (0)