Skip to content

Add parameter set AzureRmResourceGroup #1054

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

Merged
merged 1 commit into from
Oct 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function Test-RemoveNonExistingResourceGroup
# Setup
$rgname = Get-ResourceGroupName

Assert-Throws { Remove-AzureRmResourceGroup $rgname -Force } "Provided resource group does not exist."
Assert-Throws { Remove-AzureRmResourceGroup -Name $rgname -Force } "Provided resource group does not exist."
}

<#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,25 @@ public ResourceIdentifier(string idFromServer)
}
}

public static ResourceIdentifier FromResourceGroupIdentifier(string resourceGroupId)
{
if (!string.IsNullOrEmpty(resourceGroupId))
{
string[] tokens = resourceGroupId.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
if (tokens.Length < 4)
{
throw new ArgumentException(ProjectResources.InvalidFormatOfResourceGroupId, "resourceGroupId");
}
return new ResourceIdentifier
{
Subscription = tokens[1],
ResourceGroupName = tokens[3],
};
}

return new ResourceIdentifier();
}

public static string GetProviderFromResourceType(string resourceType)
{
if (resourceType == null)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@
<data name="InvalidFormatOfResourceId" xml:space="preserve">
<value>Invalid format of the resource identifier.</value>
</data>
<data name="InvalidFormatOfResourceGroupId" xml:space="preserve">
<value>Invalid format of the resource group identifier. Expected 'subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}'.</value>
</data>
<data name="InvalidTagFormat" xml:space="preserve">
<value>Invalid tag format. Expect @{Name = "tagName"} or @{Name = "tagName"; Value = "tagValue"}</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,24 @@

namespace Microsoft.Azure.Commands.Resources
{
using System.Linq;

/// <summary>
/// Filters resource groups.
/// </summary>
[Cmdlet(VerbsCommon.Get, "AzureRmResourceGroup"), OutputType(typeof(List<PSResourceGroup>))]
[Cmdlet(VerbsCommon.Get, "AzureRmResourceGroup", DefaultParameterSetName = ResourceGroupNameParameterSet), OutputType(typeof(List<PSResourceGroup>))]
public class GetAzureResourceGroupCommand : ResourcesBaseCmdlet
{
/// <summary>
/// List resources group by name parameter set.
/// </summary>
internal const string ResourceGroupNameParameterSet = "Lists the resource group based in the name.";

/// <summary>
/// List resources group by Id parameter set.
/// </summary>
internal const string ResourceGroupIdParameterSet = "Lists the resource group based in the Id.";

[Alias("ResourceGroupName")]
[Parameter(Position = 0, Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = "GetSingle")]
[Parameter(Mandatory = false, ParameterSetName = ResourceGroupNameParameterSet, ValueFromPipelineByPropertyName = true)]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

Expand All @@ -36,16 +44,14 @@ public class GetAzureResourceGroupCommand : ResourcesBaseCmdlet
public string Location { get; set; }

[Alias("ResourceGroupId", "ResourceId")]
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group Id.")]
[Parameter(Mandatory = false, ParameterSetName = ResourceGroupIdParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group Id.")]
[ValidateNotNullOrEmpty]
public string Id { get; set; }

protected override void ProcessRecord()
{
WriteWarning("The output object of this cmdlet will be modified in a future release.");
Name = string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(Id)
? Id.Split('/').Last()
: Name;
Name = Name ?? ResourceIdentifier.FromResourceGroupIdentifier(this.Id).ResourceGroupName;

this.WriteObject(
ResourcesClient.FilterResourceGroups(name: this.Name, tag: null, detailed: false, location: this.Location),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,26 @@ namespace Microsoft.Azure.Commands.Resources
/// <summary>
/// Removes a new resource group.
/// </summary>
[Cmdlet(VerbsCommon.Remove, "AzureRmResourceGroup", SupportsShouldProcess = true), OutputType(typeof(bool))]
[Cmdlet(VerbsCommon.Remove, "AzureRmResourceGroup", SupportsShouldProcess = true, DefaultParameterSetName = ResourceGroupNameParameterSet), OutputType(typeof(bool))]
public class RemoveAzureResourceGroupCommand : ResourcesBaseCmdlet
{
/// <summary>
/// List resources group by name parameter set.
/// </summary>
internal const string ResourceGroupNameParameterSet = "Lists the resource group based in the name.";

/// <summary>
/// List resources group by Id parameter set.
/// </summary>
internal const string ResourceGroupIdParameterSet = "Lists the resource group based in the Id.";

[Alias("ResourceGroupName")]
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The name of the resource group.")]
[Parameter(Mandatory = true, ParameterSetName = ResourceGroupNameParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = "The name of the resource group.")]
[ValidateNotNullOrEmpty]
public string Name {get; set;}

[Alias("ResourceGroupId", "ResourceId")]
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, HelpMessage = "The resource group Id.")]
[Parameter(Mandatory = true, ParameterSetName = ResourceGroupIdParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group Id.")]
[ValidateNotNullOrEmpty]
public string Id { get; set; }

Expand All @@ -41,9 +51,7 @@ public class RemoveAzureResourceGroupCommand : ResourcesBaseCmdlet

protected override void ProcessRecord()
{
Name = string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(Id)
? Id.Split('/').Last()
: Name;
Name = Name ?? ResourceIdentifier.FromResourceGroupIdentifier(this.Id).ResourceGroupName;

ConfirmAction(
Force.IsPresent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,31 @@
// ----------------------------------------------------------------------------------

using System.Collections;
using System.Linq;
using System.Management.Automation;
using Microsoft.Azure.Commands.Resources.Models;

namespace Microsoft.Azure.Commands.Resources
{
using System.Linq;

/// <summary>
/// Updates an existing resource group.
/// </summary>
[Cmdlet(VerbsCommon.Set, "AzureRmResourceGroup"), OutputType(typeof(PSResourceGroup))]
[Cmdlet(VerbsCommon.Set, "AzureRmResourceGroup", DefaultParameterSetName = ResourceGroupNameParameterSet), OutputType(typeof(PSResourceGroup))]
public class SetAzureResourceGroupCommand : ResourcesBaseCmdlet
{
/// <summary>
/// List resources group by name parameter set.
/// </summary>
internal const string ResourceGroupNameParameterSet = "Lists the resource group based in the name.";

/// <summary>
/// List resources group by Id parameter set.
/// </summary>
internal const string ResourceGroupIdParameterSet = "Lists the resource group based in the Id.";

[Alias("ResourceGroupName")]
[Parameter(Mandatory = true, Position = 0, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group name.")]
[Parameter(Mandatory = true, ParameterSetName = ResourceGroupNameParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group name.")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

Expand All @@ -36,17 +46,15 @@ public class SetAzureResourceGroupCommand : ResourcesBaseCmdlet
public Hashtable[] Tag { get; set; }

[Alias("ResourceGroupId", "ResourceId")]
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, HelpMessage = "The resource group Id.")]
[Parameter(Mandatory = true, ParameterSetName = ResourceGroupIdParameterSet, ValueFromPipelineByPropertyName = false, HelpMessage = "The resource group Id.")]
[ValidateNotNullOrEmpty]
public string Id { get; set; }

protected override void ProcessRecord()
{
UpdatePSResourceGroupParameters parameters = new UpdatePSResourceGroupParameters
{
ResourceGroupName = string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(Id)
? Id.Split('/').Last()
: Name,
ResourceGroupName = Name ?? ResourceIdentifier.FromResourceGroupIdentifier(this.Id).ResourceGroupName,
Tag = Tag,
};
WriteWarning("The output object of this cmdlet will be modified in a future release.");
Expand Down