Skip to content

Commit dc7c0fb

Browse files
authored
Merge pull request #620 from rakku-ms/az-dis-usagereporting-marketplacesyndication
[Az] Disable UsageReporting and MarketplaceSyndication for disconnected registration/Capacity billing model
2 parents 75e1d29 + 2c3839f commit dc7c0fb

1 file changed

Lines changed: 20 additions & 28 deletions

File tree

Registration/RegisterWithAzure.psm1

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ function Set-AzsRegistration{
346346
[switch] $MarketplaceSyndicationEnabled = $true,
347347

348348
[Parameter(Mandatory = $false, ParameterSetName = "Register")]
349-
[switch] $UsageReportingEnabled = @{'Capacity'=$true;
349+
[switch] $UsageReportingEnabled = @{'Capacity'=$false;
350350
'PayAsYouUse'=$true;
351351
'Development'=$true;
352352
'Custom'=$false;
@@ -416,11 +416,6 @@ function Set-AzsRegistration{
416416
TokenVersion = Get-RegistrationTokenVersion -AzureContext $AzureContext
417417
}
418418
Log-Output "Get-RegistrationToken parameters: $(ConvertTo-Json $getTokenParams)"
419-
if (($BillingModel -eq 'Capacity') -and ($UsageReportingEnabled))
420-
{
421-
Log-Warning "Billing model is set to Capacity and Usage Reporting is enabled. This data will be used to guide product improvements and will not be used for billing purposes. If this is not desired please halt this operation and rerun with -UsageReportingEnabled:`$false. Execution will continue in 20 seconds."
422-
Start-Sleep -Seconds 20
423-
}
424419
$registrationToken = Get-RegistrationToken @getTokenParams -Session $privilegedEndpointSession -StampInfo $stampInfo
425420

426421
# Register environment with Azure
@@ -645,12 +640,6 @@ Function Get-AzsRegistrationToken{
645640
[ValidateNotNullOrEmpty()]
646641
[String] $TokenOutputFilePath,
647642

648-
[Parameter(Mandatory = $false)]
649-
[Switch] $UsageReportingEnabled = $false,
650-
651-
[Parameter(Mandatory = $false)]
652-
[Switch] $MarketplaceSyndicationEnabled = $false,
653-
654643
[Parameter(Mandatory = $false)]
655644
[ValidateNotNull()]
656645
[string] $AgreementNumber,
@@ -666,16 +655,6 @@ Function Get-AzsRegistrationToken{
666655
New-RegistrationLogFile -RegistrationFunction $PSCmdlet.MyInvocation.MyCommand.Name
667656

668657
Validate-BillingModel -BillingModel $BillingModel -MsAssetTag $MsAssetTag
669-
if(($BillingModel -eq 'Capacity') -and ([String]::IsNullOrEmpty($AgreementNumber)))
670-
{
671-
Log-Throw -Message "Agreement number is null or empty when BillingModel is set to Capacity" -CallingFunction $PSCmdlet.MyInvocation.MyCommand.Name
672-
}
673-
674-
if (($BillingModel -eq 'Capacity') -and ($UsageReportingEnabled))
675-
{
676-
Log-Warning "Billing model is set to Capacity and Usage Reporting is enabled. This data will be used to guide product improvements and will not be used for billing purposes. If this is not desired please halt this operation and rerun with -UsageReportingEnabled:`$false. Execution will continue in 20 seconds."
677-
Start-Sleep -Seconds 20
678-
}
679658

680659
if ($TokenOutputFilePath -and (-not (Test-Path -Path $TokenOutputFilePath -PathType Leaf)))
681660
{
@@ -697,8 +676,8 @@ Function Get-AzsRegistrationToken{
697676
PrivilegedEndpointCredential = $PrivilegedEndpointCredential
698677
PrivilegedEndpoint = $PrivilegedEndpoint
699678
BillingModel = $BillingModel
700-
MarketplaceSyndicationEnabled = $MarketplaceSyndicationEnabled
701-
UsageReportingEnabled = $UsageReportingEnabled
679+
MarketplaceSyndicationEnabled = $false
680+
UsageReportingEnabled = $false
702681
AgreementNumber = $AgreementNumber
703682
TokenOutputFilePath = $TokenOutputFilePath
704683
MsAssetTag = $MsAssetTag
@@ -1261,8 +1240,17 @@ Function Get-RegistrationToken{
12611240
if( ($StampVersion -lt $CustomBillingModelVersion) -and ($BillingModel -eq 'Custom') ){
12621241
Log-Throw -Message "Custom BillingModel is not supported for StampVersion less than $CustomBillingModelVersion" -CallingFunction $PSCmdlet.MyInvocation.MyCommand.Name
12631242
}
1243+
1244+
if (($BillingModel -eq 'Capacity') -and ([String]::IsNullOrEmpty($AgreementNumber))) {
1245+
Log-Throw -Message "Agreement number is null or empty when BillingModel is set to Capacity" -CallingFunction $PSCmdlet.MyInvocation.MyCommand.Name
1246+
}
1247+
1248+
if (($BillingModel -eq 'Capacity') -and ($UsageReportingEnabled)) {
1249+
Log-Warning "Disabling Usage Reporting as it is not supported for Capacity billing model."
1250+
$UsageReportingEnabled = $false
1251+
}
12641252

1265-
$regTokenParams = @{
1253+
$regTokenParams = @{
12661254
BillingModel = $BillingModel
12671255
MarketplaceSyndicationEnabled = $MarketplaceSyndicationEnabled
12681256
UsageReportingEnabled = $UsageReportingEnabled
@@ -1879,7 +1867,7 @@ function Remove-RegistrationResource{
18791867

18801868
$currentAttempt = 0
18811869
$maxAttempt = 3
1882-
$sleepSeconds = 10
1870+
$sleepSeconds = 30
18831871
do
18841872
{
18851873
try
@@ -1890,13 +1878,17 @@ function Remove-RegistrationResource{
18901878

18911879
$resourceType = 'Microsoft.Azurestack/registrations'
18921880
$lock = Get-AzResourceLock -LockName 'RegistrationResourceLock' -ResourceGroupName $ResourceGroupName -ResourceType $resourceType -ResourceName $resourceName -ErrorAction SilentlyContinue
1893-
if ($lock)
1894-
{
1881+
if ($lock) {
18951882
Write-Verbose "Removing Registration resource lock 'RegistrationResourceLock'..." -Verbose
18961883
Remove-AzResourceLock -LockId $lock.LockId -Force
18971884
}
18981885

18991886
Remove-AzResource -ResourceId $ResourceId -ApiVersion $azureResourceApiVersion -Force -Verbose
1887+
## check if the remove registration resource is successful
1888+
Write-Verbose "Validating if registration resource removal succeeded." -Verbose
1889+
if (Get-AzResource -ResourceId $ResourceId -ApiVersion $azureResourceApiVersion -ErrorAction SilentlyContinue) {
1890+
throw "Removal of registration resource failed."
1891+
}
19001892
break
19011893
}
19021894
catch

0 commit comments

Comments
 (0)