Skip to content

Conversation

@rajshah11
Copy link
Contributor

@rajshah11 rajshah11 commented Feb 14, 2018

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

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.
  • The pull request does not introduce breaking changes (unless a major version change occurs in the assembly and module).

Testing Guidelines

  • Pull request includes test coverage for the included changes.
  • PowerShell scripts used in tests should do any necessary setup as part of the test or suite setup, and should not use hard-coded values for locations or existing resources.

Cmdlet Signature Guidelines

  • New cmdlets that make changes or have side effects should implement ShouldProcess and have SupportShouldProcess=true specified in the cmdlet attribute. You can find more information on ShouldProcess here.
  • Cmdlet specifies OutputType attribute if any output is produced - if the cmdlet produces no output, it should implement a PassThru parameter.

Cmdlet Parameter Guidelines

  • Parameter types should not expose types from the management library - complex parameter types should be defined in the module.
  • Complex parameter types are discouraged - a parameter type should be simple types as often as possible. If complex types are used, they should be shallow and easily creatable from a constructor or another cmdlet.
  • Cmdlet parameter sets should be mutually exclusive - each parameter set must have at least one mandatory parameter not in other parameter sets.

markcowl and others added 30 commits November 2, 2017 17:28
Bring preview branch up to date
Update preview branch after 5.0.0 release
…Subscription where SubscriptionId was accidentally SubscriptonId.
Copy link
Member

@cormacpayne cormacpayne left a 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'
Copy link
Member

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?

Copy link
Contributor Author

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
Copy link
Member

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.

Copy link
Contributor Author

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 -

  1. We need to release preview as soon as possible to our public preview customers.
  2. By API Design, Get is not meant to show children without -Expand and -Recurse
  3. 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;
Copy link
Member

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?

Copy link
Contributor Author

@rajshah11 rajshah11 Feb 16, 2018

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; }
Copy link
Member

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

Copy link
Contributor Author

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,
Copy link
Member

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()
{

Copy link
Member

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?

Copy link
Contributor Author

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))]
Copy link
Member

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

Copy link
Contributor Author

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; }
Copy link
Member

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

Copy link
Contributor Author

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,
Copy link
Member

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

Copy link
Contributor Author

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;
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will make the change.

@rajshah11
Copy link
Contributor Author

@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.

@cormacpayne
Copy link
Member

Copy link
Member

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.

Copy link
Member

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

Copy link
Member

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

@rajshah11
Copy link
Contributor Author

@markcowl @cormacpayne Made the suggested changes. Thanks!

@cormacpayne
Copy link
Member

}
}

public void PreregisterSubscription()
Copy link
Member

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?

@markcowl
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants