Skip to content

Commit

Permalink
Revert 23H2 registration blocker (#25457)
Browse files Browse the repository at this point in the history
  • Loading branch information
priyjain358 authored Jul 17, 2024
1 parent a9de509 commit a6e0102
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 39 deletions.
3 changes: 0 additions & 3 deletions src/StackHCI/StackHCI.Autorest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
This directory contains the PowerShell module for the StackHci service.

---
## Status
[![Az.StackHCI](https://img.shields.io/powershellgallery/v/Az.StackHCI.svg?style=flat-square&label=Az.StackHCI "Az.StackHCI")](https://www.powershellgallery.com/packages/Az.StackHCI/)

## Info
- Modifiable: yes
- Generated: all
Expand Down
8 changes: 4 additions & 4 deletions src/StackHCI/StackHCI.Autorest/custom/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Custom
This directory contains custom implementation for non-generated cmdlets for the `Az.StackHCI` module. Both scripts (`.ps1`) and C# files (`.cs`) can be implemented here. They will be used during the build process in `build-module.ps1`, and create cmdlets into the `../exports` folder. The only generated file into this folder is the `Az.StackHCI.custom.psm1`. This file should not be modified.
This directory contains custom implementation for non-generated cmdlets for the `Az.StackHCI` module. Both scripts (`.ps1`) and C# files (`.cs`) can be implemented here. They will be used during the build process in `build-module.ps1`, and create cmdlets into the `..\exports` folder. The only generated file into this folder is the `Az.StackHCI.custom.psm1`. This file should not be modified.

## Info
- Modifiable: yes
Expand All @@ -15,10 +15,10 @@ For C# cmdlets, they are compiled with the rest of the generated low-level cmdle
For script cmdlets, these are loaded via the `Az.StackHCI.custom.psm1`. Then, during the build process, this module is loaded and processed in the same manner as the C# cmdlets. The fundamental difference is the script cmdlets use the `ParameterSetName` attribute and C# cmdlets do not. To create a script cmdlet variant of a generated cmdlet, simply decorate all parameters in the script with the new `ParameterSetName` in the `Parameter` attribute. This will appropriately treat each parameter set as a separate variant when processed to be exported during the build.

## Purpose
This allows the modules to have cmdlets that were not defined in the REST specification. It also allows combining logic using generated cmdlets. This is a level of customization beyond what can be done using the [readme configuration options](https://github.com/Azure/autorest/blob/master/docs/powershell/options.md) that are currently available. These custom cmdlets are then referenced by the cmdlets created at build-time in the `../exports` folder.
This allows the modules to have cmdlets that were not defined in the REST specification. It also allows combining logic using generated cmdlets. This is a level of customization beyond what can be done using the [readme configuration options](https://github.com/Azure/autorest/blob/master/docs/powershell/options.md) that are currently available. These custom cmdlets are then referenced by the cmdlets created at build-time in the `..\exports` folder.

## Usage
The easiest way currently to start developing custom cmdlets is to copy an existing cmdlet. For C# cmdlets, copy one from the `generated/cmdlets` folder. For script cmdlets, build the project using `build-module.ps1` and copy one of the scripts from the `../exports` folder. After that, if you want to add new parameter sets, follow the guidelines in the `Details` section above. For implementing a new cmdlets, at minimum, please keep these parameters:
The easiest way currently to start developing custom cmdlets is to copy an existing cmdlet. For C# cmdlets, copy one from the `generated/cmdlets` folder. For script cmdlets, build the project using `build-module.ps1` and copy one of the scripts from the `..\exports` folder. After that, if you want to add new parameter sets, follow the guidelines in the `Details` section above. For implementing a new cmdlets, at minimum, please keep these parameters:
- Break
- DefaultProfile
- HttpPipelineAppend
Expand All @@ -36,6 +36,6 @@ For processing the cmdlets, we've created some additional attributes:
- `Microsoft.Azure.PowerShell.Cmdlets.StackHCI.DoNotExportAttribute`
- Used in C# and script cmdlets to suppress creating an exported cmdlet at build-time. These cmdlets will *not be exposed* by `Az.StackHCI`.
- `Microsoft.Azure.PowerShell.Cmdlets.StackHCI.InternalExportAttribute`
- Used in C# cmdlets to route exported cmdlets to the `../internal`, which are *not exposed* by `Az.StackHCI`. For more information, see [README.md](../internal/README.md) in the `../internal` folder.
- Used in C# cmdlets to route exported cmdlets to the `..\internal`, which are *not exposed* by `Az.StackHCI`. For more information, see [README.md](..\internal/README.md) in the `..\internal` folder.
- `Microsoft.Azure.PowerShell.Cmdlets.StackHCI.ProfileAttribute`
- Used in C# and script cmdlets to define which Azure profiles the cmdlet supports. This is only supported for Azure (`--azure`) modules.
27 changes: 0 additions & 27 deletions src/StackHCI/StackHCI.Autorest/custom/stackhci.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ $StartingArcAgentMessage = "Enabling Azure Arc integration on every clustered no
$VerifyingArcMessage = "Verifying Azure Arc for Servers registration"
$WaitingUnregisterMessage = "Disabling Azure Arc integration on every clustered node"
$CleanArcMessage = "Cleaning up Azure Arc integration"
$NonCloudDeploymentFor23H2DevicesErrorMessage = "Azure stack HCI version 23H2 and higher cannot be registered using this method. See details: https://learn.microsoft.com/en-us/azure-stack/hci/deploy/deploy-via-portal"

$MissingDependentModulesError = "Can't find PowerShell module(s): {0}. Please install the missing module(s) using 'Install-Module -Name <Module_Name>' and try again."
$ArcAlreadyEnabledInADifferentResourceError = "Below mentioned cluster node(s) are already Arc enabled with a different ARM Resource Id:`n{0}`nDisconnect Arc agent on these nodes and run Register-AzStackHCI again."
Expand Down Expand Up @@ -2895,21 +2894,6 @@ param(
Write-VerboseLog ("Cloud Management supported: {0}" -f $isCloudManagementSupported)
Write-VerboseLog ("Cloud Management Infra supported: {0}" -f $isCloudManagementInfraSupported)
Write-VerboseLog ("Installing Mandatory extensions supported: {0}" -f $isDefaultExtensionSupported)

$allowFor23H2Devices = Verify-23H2VanillaRegistration -clusterNodeSession $clusterNodeSession
if(([Int]::Parse($osVersionInfo.BuildNumber) -ge $23H2BuildNumber) -and !($allowFor23H2Devices))
{
#error message
Write-ErrorLog -Message $NonCloudDeploymentFor23H2DevicesErrorMessage -Category OperationStopped
$resultValue = [OperationStatus]::Failed
$registrationOutput | Add-Member -MemberType NoteProperty -Name $OutputPropertyResult -Value [OperationStatus]::Failed -ErrorAction Continue
$NonCloudDeploymentFor23H2DevicesErrorCode = 9132
Set-WacOutputProperty -IsWAC $IsWAC -PropertyName $OutputPropertyWacResult -PropertyValue $resultValue.ToString() -Output $registrationOutput
Set-WacOutputProperty -IsWAC $IsWAC -PropertyName $OutputPropertyWacErrorCode -PropertyValue $NonCloudDeploymentFor23H2DevicesErrorCode -Output $registrationOutput
Write-Output $registrationOutput | Format-List
Write-NodeEventLog -Message $NonCloudDeploymentFor23H2DevicesErrorMessage -EventID 9132 -IsManagementNode $IsManagementNode -credentials $Credential -ComputerName $ComputerName -Level Error
throw
}

if(-Not ([string]::IsNullOrEmpty($RegContext.AzureResourceUri)))
{
Expand Down Expand Up @@ -3888,17 +3872,6 @@ Set-WacOutputProperty -IsWAC $IsWAC -PropertyName $OutputPropertyWacResult -Prop
}
}

function Verify-23H2VanillaRegistration {
[Microsoft.Azure.PowerShell.Cmdlets.StackHCI.DoNotExportAttribute()]
param(
[System.Management.Automation.Runspaces.PSSession] $clusterNodeSession
)

$detectRegKeyfor23H2 = { $lcmRegKey = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\LCMAzureStackStampInformation" -Name "InitializationComplete" -ErrorAction SilentlyContinue; $lcmRegKey -ne $null }
$allowFor23H2Devices = Invoke-Command -Session $clusterNodeSession -ScriptBlock $detectRegKeyfor23H2

return $allowFor23H2Devices
}

function Set-ArcRoleforRPSpn {
[Microsoft.Azure.PowerShell.Cmdlets.StackHCI.DoNotExportAttribute()]
Expand Down
4 changes: 2 additions & 2 deletions src/StackHCI/StackHCI.Autorest/docs/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Docs
This directory contains the documentation of the cmdlets for the `Az.StackHCI` module. To run documentation generation, use the `generate-help.ps1` script at the root module folder. Files in this folder will *always be overridden on regeneration*. To update documentation examples, please use the `../examples` folder.
This directory contains the documentation of the cmdlets for the `Az.StackHCI` module. To run documentation generation, use the `generate-help.ps1` script at the root module folder. Files in this folder will *always be overridden on regeneration*. To update documentation examples, please use the `..\examples` folder.

## Info
- Modifiable: no
Expand All @@ -8,4 +8,4 @@ This directory contains the documentation of the cmdlets for the `Az.StackHCI` m
- Packaged: yes

## Details
The process of documentation generation loads `Az.StackHCI` and analyzes the exported cmdlets from the module. It recognizes the [help comments](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_comment_based_help) that are generated into the scripts in the `../exports` folder. Additionally, when writing custom cmdlets in the `../custom` folder, you can use the help comments syntax, which decorate the exported scripts at build-time. The documentation examples are taken from the `../examples` folder.
The process of documentation generation loads `Az.StackHCI` and analyzes the exported cmdlets from the module. It recognizes the [help comments](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_comment_based_help) that are generated into the scripts in the `..\exports` folder. Additionally, when writing custom cmdlets in the `..\custom` folder, you can use the help comments syntax, which decorate the exported scripts at build-time. The documentation examples are taken from the `..\examples` folder.
2 changes: 1 addition & 1 deletion src/StackHCI/StackHCI.Autorest/resources/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Resources
This directory can contain any additional resources for module that are not required at runtime. This directory **does not** get packaged with the module. If you have assets for custom implementation, place them into the `../custom` folder.
This directory can contain any additional resources for module that are not required at runtime. This directory **does not** get packaged with the module. If you have assets for custom implementation, place them into the `..\custom` folder.

## Info
- Modifiable: yes
Expand Down
2 changes: 1 addition & 1 deletion src/StackHCI/StackHCI.Autorest/test/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Test
This directory contains the [Pester](https://www.powershellgallery.com/packages/Pester) tests to run for the module. We use Pester as it is the unofficial standard for PowerShell unit testing. Test stubs for custom cmdlets (created in `../custom`) will be generated into this folder when `build-module.ps1` is ran. These test stubs will fail automatically, to indicate that tests should be written for custom cmdlets.
This directory contains the [Pester](https://www.powershellgallery.com/packages/Pester) tests to run for the module. We use Pester as it is the unofficial standard for PowerShell unit testing. Test stubs for custom cmdlets (created in `..\custom`) will be generated into this folder when `build-module.ps1` is ran. These test stubs will fail automatically, to indicate that tests should be written for custom cmdlets.

## Info
- Modifiable: yes
Expand Down
2 changes: 1 addition & 1 deletion src/StackHCI/StackHCI.Autorest/test/loadEnv.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ if (Test-Path -Path (Join-Path $PSScriptRoot $envFile)) {
$env = @{}
if (Test-Path -Path $envFilePath) {
$env = Get-Content (Join-Path $PSScriptRoot $envFile) | ConvertFrom-Json
$PSDefaultParameterValues=@{"*:SubscriptionId"=$env.SubscriptionId; "*:Tenant"=$env.Tenant}
$PSDefaultParameterValues=@{"*:Tenant"=$env.Tenant}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
param()
if ($env:AzPSAutorestTestPlaybackMode) {
$loadEnvPath = Join-Path $PSScriptRoot '..' 'test' 'loadEnv.ps1'
. ($loadEnvPath)
return $env.SubscriptionId
}
return (Get-AzContext).Subscription.Id

0 comments on commit a6e0102

Please sign in to comment.