Skip to content

Commit 42620ad

Browse files
committed
ARM code changes
1 parent ab72618 commit 42620ad

File tree

10 files changed

+301
-1158
lines changed

10 files changed

+301
-1158
lines changed

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Commands.Resources.Rest.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@
133133
<Compile Include="Implementation\Policy\PolicyCmdletBase.cs" />
134134
<Compile Include="Implementation\Policy\RemoveAzurePolicySetDefinition.cs" />
135135
<Compile Include="Implementation\Policy\SetAzurePolicySetDefinition.cs" />
136-
<Compile Include="Implementation\ResourceGroups\FindAzureResourceGroupCmdlet.cs" />
137136
<Compile Include="Implementation\ResourceGroups\ExportAzureResourceGroupCmdlet.cs" />
138137
<Compile Include="Implementation\Providers\GetAzureProviderCmdlet.cs" />
139138
<Compile Include="Implementation\Providers\RegisterAzureProviderCmdlet.cs" />
@@ -152,7 +151,6 @@
152151
<Compile Include="Implementation\ResourceGroupDeployments\GetAzureResourceGroupDeploymentOperationCmdlet.cs" />
153152
<Compile Include="Implementation\Lock\GetAzureResourceLockCmdlet.cs" />
154153
<Compile Include="Implementation\Resource\InvokeAzureResourceActionCmdlet.cs" />
155-
<Compile Include="Implementation\Resource\FindAzureResourceCmdlet.cs" />
156154
<Compile Include="Implementation\Resource\MoveAzureResourceCmdlet.cs" />
157155
<Compile Include="Implementation\Lock\NewAzureResourceLockCmdlet.cs" />
158156
<Compile Include="Implementation\Policy\GetAzurePolicyAssignment.cs" />
@@ -211,6 +209,7 @@
211209
<Compile Include="SdkModels\ResourceProvider\PSResourceProvider.cs" />
212210
<Compile Include="SdkModels\ResourceProvider\PSResourceProviderResourceType.cs" />
213211
<Compile Include="Components\ResourceIdentifier.cs" />
212+
<Compile Include="SdkModels\Resources\PSResource.cs" />
214213
<Compile Include="Utilities\FileUtility.cs" />
215214
<Compile Include="Utilities\HttpUtility.cs" />
216215
<Compile Include="Utilities\TemplateUtility.cs" />

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/Providers/GetAzureProviderCmdlet.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
2222
using System;
2323
using System.Linq;
2424
using System.Management.Automation;
25+
using WindowsAzure.Commands.Utilities.Common;
2526
using ProjectResources = Microsoft.Azure.Commands.ResourceManager.Cmdlets.Properties.Resources;
2627

2728
/// <summary>
@@ -45,7 +46,7 @@ public class GetAzureProviderCmdlet : ResourceManagerCmdletBase
4546
/// </summary>
4647
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource provider namespace.", ParameterSetName = GetAzureProviderCmdlet.IndividualProviderParameterSet)]
4748
[ValidateNotNullOrEmpty]
48-
public string ProviderNamespace { get; set; }
49+
public string[] ProviderNamespace { get; set; }
4950

5051
/// <summary>
5152
/// Gets or sets the provider namespace
@@ -68,7 +69,7 @@ public override void ExecuteCmdlet()
6869
{
6970
var providers = this.ListPSResourceProviders();
7071

71-
if (!string.IsNullOrEmpty(this.ProviderNamespace))
72+
if (this.IsParameterBound(c => c.ProviderNamespace))
7273
{
7374
var expandedProviders = providers
7475
.SelectMany(provider =>
@@ -106,9 +107,13 @@ private PSResourceProvider[] ListPSResourceProviders()
106107
listAvailable: true);
107108

108109
var providers = allProviders;
109-
if (!string.IsNullOrEmpty(this.ProviderNamespace))
110+
if (this.IsParameterBound(c => c.ProviderNamespace))
110111
{
111-
providers = this.ResourceManagerSdkClient.ListResourceProviders(providerName: this.ProviderNamespace);
112+
providers = new System.Collections.Generic.List<Management.ResourceManager.Models.Provider>();
113+
foreach (var providerNamespace in this.ProviderNamespace)
114+
{
115+
providers.AddRange(this.ResourceManagerSdkClient.ListResourceProviders(providerName: providerNamespace));
116+
}
112117
}
113118
else if (this.ListAvailable == false)
114119
{
@@ -140,7 +145,7 @@ private PSResourceProvider[] ListPSResourceProviders()
140145
}
141146

142147
var providerWithResourceTypes = providers.ToDictionary(
143-
provider => provider,
148+
provider => provider,
144149
provider => provider.ResourceTypes
145150
.Where(type => !type.Locations.Any() || type.Locations.Any(loc => loc.EqualsAsLocation(this.Location)))
146151
.ToList());

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/Resource/FindAzureResourceCmdlet.cs

Lines changed: 0 additions & 527 deletions
This file was deleted.

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/Resource/GetAzureResourceCmdlet.cs

Lines changed: 97 additions & 513 deletions
Large diffs are not rendered by default.

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/ResourceGroups/FindAzureResourceGroupCmdlet.cs

Lines changed: 0 additions & 106 deletions
This file was deleted.

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/ResourceGroups/GetAzureResourceGroupCmdlet.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
1919
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
2020
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
2121
using System;
22+
using System.Collections;
2223
using System.Collections.Generic;
2324
using System.IO;
2425
using System.Management.Automation;
@@ -57,12 +58,16 @@ public class GetAzureResourceGroupCmdlet : ResourceManagerCmdletBase
5758
[ValidateNotNullOrEmpty]
5859
public string Id { get; set; }
5960

61+
[Parameter(Mandatory = false, ParameterSetName = ResourceGroupNameParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = "The tag hashtable to filter resource groups by.")]
62+
[ValidateNotNullOrEmpty]
63+
public Hashtable Tag { get; set; }
64+
6065
public override void ExecuteCmdlet()
6166
{
6267
Name = Name ?? ResourceIdentifier.FromResourceGroupIdentifier(this.Id).ResourceGroupName;
6368

6469
this.WriteObject(
65-
ResourceManagerSdkClient.FilterResourceGroups(name: this.Name, tag: null, detailed: false, location: this.Location),
70+
ResourceManagerSdkClient.FilterResourceGroups(name: this.Name, tag: this.Tag, detailed: false, location: this.Location),
6671
true);
6772
}
6873

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Microsoft.Azure.Commands.ResourceManager.Cmdlets.format.ps1xml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,5 +337,73 @@
337337
</ListEntries>
338338
</ListControl>
339339
</View>
340+
<View>
341+
<Name>Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSResource</Name>
342+
<ViewSelectedBy>
343+
<TypeName>Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSResource</TypeName>
344+
</ViewSelectedBy>
345+
<ListControl>
346+
<ListEntries>
347+
<ListEntry>
348+
<ListItems>
349+
<ListItem>
350+
<Label>Name</Label>
351+
<PropertyName>Name</PropertyName>
352+
</ListItem>
353+
<ListItem>
354+
<Label>ResourceGroupName</Label>
355+
<PropertyName>ResourceGroupName</PropertyName>
356+
</ListItem>
357+
<ListItem>
358+
<Label>ResourceType</Label>
359+
<PropertyName>Type</PropertyName>
360+
</ListItem>
361+
<ListItem>
362+
<Label>Location</Label>
363+
<PropertyName>Location</PropertyName>
364+
</ListItem>
365+
<ListItem>
366+
<Label>ResourceId</Label>
367+
<PropertyName>Id</PropertyName>
368+
</ListItem>
369+
</ListItems>
370+
</ListEntry>
371+
</ListEntries>
372+
</ListControl>
373+
</View>
374+
<View>
375+
<Name>Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSResource</Name>
376+
<ViewSelectedBy>
377+
<TypeName>Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSResource</TypeName>
378+
</ViewSelectedBy>
379+
<TableControl>
380+
<TableHeaders>
381+
<TableColumnHeader/>
382+
<TableColumnHeader/>
383+
<TableColumnHeader>
384+
<Label>ResourceType</Label>
385+
</TableColumnHeader>
386+
<TableColumnHeader/>
387+
</TableHeaders>
388+
<TableRowEntries>
389+
<TableRowEntry>
390+
<TableColumnItems>
391+
<TableColumnItem>
392+
<PropertyName>Name</PropertyName>
393+
</TableColumnItem>
394+
<TableColumnItem>
395+
<PropertyName>ResourceGroupName</PropertyName>
396+
</TableColumnItem>
397+
<TableColumnItem>
398+
<PropertyName>Type</PropertyName>
399+
</TableColumnItem>
400+
<TableColumnItem>
401+
<PropertyName>Location</PropertyName>
402+
</TableColumnItem>
403+
</TableColumnItems>
404+
</TableRowEntry>
405+
</TableRowEntries>
406+
</TableControl>
407+
</View>
340408
</ViewDefinitions>
341409
</Configuration>

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/SdkClient/ResourceManagerSdkClient.cs

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
using Newtonsoft.Json.Linq;
3838
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
3939
using ProjectResources = Microsoft.Azure.Commands.ResourceManager.Cmdlets.Properties.Resources;
40+
using Microsoft.Azure.Commands.ResourceManager.Common.Paging;
4041

4142
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkClient
4243
{
@@ -315,8 +316,8 @@ private DeploymentExtended WaitDeploymentStatus(
315316
DeploymentExtended deployment;
316317

317318
// Poll deployment state and deployment operations after RetryAfter.
318-
// If no RetryAfter provided: In phase one, poll every 5 seconds. Phase one
319-
// takes 400 seconds. In phase two, poll every 60 seconds.
319+
// If no RetryAfter provided: In phase one, poll every 5 seconds. Phase one
320+
// takes 400 seconds. In phase two, poll every 60 seconds.
320321
const int counterUnit = 1000;
321322
int step = 5;
322323
int phaseOne = 400;
@@ -594,7 +595,7 @@ public virtual List<PSResourceGroup> FilterResourceGroups(string name, Hashtable
594595
{
595596
List<PSResourceGroup> result = new List<PSResourceGroup>();
596597

597-
if (string.IsNullOrEmpty(name))
598+
if (string.IsNullOrEmpty(name) || name.Contains("*"))
598599
{
599600
List<ResourceGroup> resourceGroups = new List<ResourceGroup>();
600601

@@ -607,6 +608,28 @@ public virtual List<PSResourceGroup> FilterResourceGroups(string name, Hashtable
607608
resourceGroups.AddRange(listResult);
608609
}
609610

611+
if (!string.IsNullOrEmpty(name))
612+
{
613+
if (name.StartsWith("*"))
614+
{
615+
name = name.TrimStart('*');
616+
if (name.EndsWith("*"))
617+
{
618+
name = name.TrimEnd('*');
619+
resourceGroups = resourceGroups.Where(g => g.Name.Contains(name)).ToList();
620+
}
621+
else
622+
{
623+
resourceGroups = resourceGroups.Where(g => g.Name.EndsWith(name)).ToList();
624+
}
625+
}
626+
else if (name.EndsWith("*"))
627+
{
628+
name = name.TrimEnd('*');
629+
resourceGroups = resourceGroups.Where(g => g.Name.StartsWith(name)).ToList();
630+
}
631+
}
632+
610633
resourceGroups = !string.IsNullOrEmpty(location)
611634
? resourceGroups.Where(resourceGroup => resourceGroup.Location.EqualsAsLocation(location)).ToList()
612635
: resourceGroups;
@@ -852,5 +875,27 @@ public virtual List<PSResourceManagerError> ValidatePSResourceGroupDeployment(PS
852875
}
853876
return validationInfo.Errors.Select(e => e.ToPSResourceManagerError()).ToList();
854877
}
878+
879+
public virtual IEnumerable<PSResource> ListResources(Rest.Azure.OData.ODataQuery<GenericResourceFilter> filter = null, ulong first = ulong.MaxValue, ulong skip = ulong.MinValue)
880+
{
881+
return new PageEnumerable<GenericResource>(
882+
delegate()
883+
{
884+
return ResourceManagementClient.Resources.List(filter);
885+
}, ResourceManagementClient.Resources.ListNext, first, skip).Select(r => new PSResource(r));
886+
}
887+
888+
public virtual IEnumerable<PSResource> ListByResourceGroup(
889+
string resourceGroupName,
890+
Rest.Azure.OData.ODataQuery<GenericResourceFilter> filter,
891+
ulong first = ulong.MaxValue,
892+
ulong skip = ulong.MinValue)
893+
{
894+
return new PageEnumerable<GenericResource>(
895+
delegate ()
896+
{
897+
return ResourceManagementClient.Resources.ListByResourceGroup(resourceGroupName, filter);
898+
}, ResourceManagementClient.Resources.ListByResourceGroupNext, first, skip).Select(r => new PSResource(r));
899+
}
855900
}
856901
}

0 commit comments

Comments
 (0)