-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Powershell for ManagementGroups #5536
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
Powershell for ManagementGroups #5536
Conversation
Bring preview branch up to date
Update preview branch after 5.0.0 release
…Subscription where SubscriptionId was accidentally SubscriptonId.
… to auto register.
… into powershell-for-groupsrp
…nto powershell-for-groupsrp
…nto powershell-for-groupsrp
cormacpayne
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rajshah11 some additional comments to take a look at. I need to sync up with @markcowl tomorrow about the auto-registration changes being made in here
| # External dependent modules of this module | ||
| # ExternalModuleDependencies = '' | ||
|
|
||
| Prerelease = 'preview' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rajshah11 nit: would you mind fixing the indentation for this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks
|
|
||
| namespace Microsoft.Azure.Commands.ManagementGroups.Models | ||
| { | ||
| public class PSManagementGroupNoChildren |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rajshah11 from the previous PR:
The issue is with output formatting. Children are shown only when -Expand is supplied. When it is not, the output has Children with null (even though the group may have children). This might give an impression to the user that the group has no children and to avoid this behavior I added a new object which does not have children at all.
I think a possible solution would be to get rid of this class and have all of the functionality in the PSManagementGroup class, which has a Children property that is null by default. We can make it so the formatting file checks if the value of Children is null or not, and if it isn't, we will output the contents of the property, and hide it otherwise. Then, we can make it so the Children property gets its value from a lazy call to the SDK, meaning that whenever a user wants to access the Children for a given management group, accessing that property will make the underlying SDK call to get the children, which means users would never see a null or empty value returned unless the management group did in fact have zero children.
Let me know what you think of this idea. It will make it so we have a consistent type that is being returned and passed around, as well as mitigate and confusion the user may have about the children of a management group.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cormacpayne We can have a single class by changing the formatting file. However, rather than making the Lazy calls, we would prefer adding a note when Get is called (without -Expand or -Recurse) saying that the user needs to pass -Expand or -Recurse to access the children. This is because of three reasons -
- We need to release preview as soon as possible to our public preview customers.
- By API Design, Get is not meant to show children without
-Expandand-Recurse - I think we have already made all the changes needed for the preview as suggested in the review meeting. This change is something that can be aded in the future. Also, our new Powershell design is already in progress, which will provide the users which such flexibilty eventually.
I will be making the other changes. Please confirm if I can proceed with having one class by changing the formatting file and adding a note.
| [Parameter(ParameterSetName = Constants.ParameterSetNames.GroupOperationsParameterSet, Mandatory = false, | ||
| HelpMessage = Constants.HelpMessages.ParentId)] | ||
| [ValidateNotNullOrEmpty] | ||
| public string ParentId { get; set; } = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rajshah11 do you think it would make sense to have another parameter set that allows the user to pass in the PSManagementGroup object of the parent that they want for this new management group?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I think it would make sense. Will make the change.
| [Parameter(ParameterSetName = Constants.ParameterSetNames.ManagementGroupParameterSet, Mandatory = false, | ||
| HelpMessage = Constants.HelpMessages.InputObject, ValueFromPipeline = true)] | ||
| [ValidateNotNullOrEmpty] | ||
| public PSManagementGroup ManagementGroup { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rajshah11 this should be renamed to InputObject
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks.
| public class RemoveAzureRmManagementGroup : AzureManagementGroupsCmdletBase | ||
| { | ||
|
|
||
| [Parameter(ParameterSetName = Constants.ParameterSetNames.ManagementGroupParameterSet, Mandatory = false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rajshah11 nit: this should be mandatory
|
|
||
| public override void ExecuteCmdlet() | ||
| { | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rajshah11 nit: can you remove these extra new lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks
|
|
||
| namespace Microsoft.Azure.Commands.ManagementGroups.Cmdlets | ||
| { | ||
| [Cmdlet("Update", "AzureRmManagementGroup", DefaultParameterSetName = Constants.ParameterSetNames.GroupOperationsParameterSet, SupportsShouldProcess = true), OutputType(typeof(PSManagementGroupNoChildren))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rajshah11 nit: change "Update" to VerbsCommon.Update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verbs.Common does not have "Update" for me
| [Parameter(ParameterSetName = Constants.ParameterSetNames.ManagementGroupParameterSet, Mandatory = false, | ||
| HelpMessage = Constants.HelpMessages.InputObject, ValueFromPipeline = true)] | ||
| [ValidateNotNullOrEmpty] | ||
| public PSManagementGroup ManagementGroup { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rajshah11 same comment about renaming this to InputObject
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks.
| [Cmdlet("Update", "AzureRmManagementGroup", DefaultParameterSetName = Constants.ParameterSetNames.GroupOperationsParameterSet, SupportsShouldProcess = true), OutputType(typeof(PSManagementGroupNoChildren))] | ||
| public class UpdateAzureRmManagementGroup : AzureManagementGroupsCmdletBase | ||
| { | ||
| [Parameter(ParameterSetName = Constants.ParameterSetNames.ManagementGroupParameterSet, Mandatory = false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rajshah11 nit: this should be mandatory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| [Parameter(ParameterSetName = Constants.ParameterSetNames.GroupOperationsParameterSet, Mandatory = false, | ||
| HelpMessage = Constants.HelpMessages.ParentId)] | ||
| [ValidateNotNullOrEmpty] | ||
| public string ParentId { get; set; } = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rajshah11 same question about whether or not it makes sense to allow the user to pass the PSManagementGroup object they want to be the parent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will make the change.
|
@cormacpayne All changes are done and updated the help file. This build should succeed. Please confirm if this is good to go once the build succeeds. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rajshah11 Adding a handler to the client factory impacts all clinets created from the ClientFactory. Please follow the pattern in Reservations cmdlets for registration, in which this registration is simply performed in BeginProcessing, without using a delegating handler.
setup/azurecmdfiles.wxi
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert any changes to this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be updated to 4.3.0
|
@markcowl @cormacpayne Made the suggested changes. Thanks! |
| } | ||
| } | ||
|
|
||
| public void PreregisterSubscription() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this code repeated?
Description
This PR adds Powershell preview for Management Groups
This PR is based off a new branch, since some erroneous commits were added to the previous PR #5421
This checklist is used to make sure that common guidelines for a pull request are followed. You can find a more complete discussion of PowerShell cmdlet best practices here.
General Guidelines
Testing Guidelines
Cmdlet Signature Guidelines
ShouldProcessand haveSupportShouldProcess=truespecified in the cmdlet attribute. You can find more information onShouldProcesshere.OutputTypeattribute if any output is produced - if the cmdlet produces no output, it should implement aPassThruparameter.Cmdlet Parameter Guidelines