Skip to content

Commit aef6297

Browse files
vidai-msfthaaghawyunchi-msVeryEarly
authored
[Compute] Community Gallery cmdlets changes (#19957)
* gallery changes * Changes for community gallery * updated changelog * help change * get-azgalleryimageversion help * Adding to required assemblies * Fixing errors in PR * fix help * fix get-azgallery community parameter set * bug fix * update bug fix community gallery * changes to community gallery permission * Adding fixes * adding vmstrategy * docs * update parameter set * Adding breaking change exception * changes suggested in comments * undo help files * Breaking change restore * Updating help * Update ChangeLog.md Co-authored-by: Haider Agha <[email protected]> Co-authored-by: haagha <[email protected]> Co-authored-by: Yunchi Wang <[email protected]> Co-authored-by: Yabo Hu <[email protected]>
1 parent ccdf8c7 commit aef6297

File tree

10 files changed

+278
-89
lines changed

10 files changed

+278
-89
lines changed

src/Compute/Compute/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
* Improved cmdlet description for `Set-AzVM` and added examples.
3232
* Updated property mapping for parameter `Encryption` of `New-AzGalleryImageVersion`
3333
* Updated list format to display all VmssVmRunCommand properties for `Get-AzVmssVmRunCommand`
34+
* Updated `Get-AzGallery`, `New-AzGallery`, `Update-AzGallery`, `Get-AzGalleryImageDefinition`, `Get-AzGalleryImageVersion`, `New-AzVm` and `New-AzVmss` to support community galleries
3435

3536
## Version 5.0.0
3637
* Added the `TimeCreated` property to the Virtual Machine and Virtual Machine Scale Set models.

src/Compute/Compute/Generated/Gallery/GalleryCreateOrUpdateMethod.cs

Lines changed: 87 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -256,105 +256,123 @@ public override void ExecuteCmdlet()
256256
}
257257

258258
}
259-
260-
259+
261260
SharingUpdate sharingUpdate = new SharingUpdate();
261+
if (this.Reset.IsPresent)
262+
{
263+
sharingUpdate.OperationType = "Reset";
264+
}
265+
else if (this.Community.IsPresent)
266+
{
267+
sharingUpdate.OperationType = "EnableCommunity";
268+
}
269+
270+
262271
if (this.Share.IsPresent)
263272
{
264273
if (this.Reset.IsPresent)
265274
{
266275
// if sub or tenant is present return error
267-
if (this.IsParameterBound(c => c.Subscription) || this.IsParameterBound(c => c.Tenant))
268-
{
269-
throw new Exception("Parameter '-Reset' cannot be used with parameters '-Tenant', '-Subscription' or 'Community'.");
270-
}
271-
else
272-
{
273-
sharingUpdate.OperationType = "Reset";
274-
}
276+
//if (this.IsParameterBound(c => c.Subscription) || this.IsParameterBound(c => c.Tenant) || this.IsParameterBound(c => c.RemoveTenant) || this.IsParameterBound(c => c.RemoveSubscription))
277+
//{
278+
// throw new Exception("Parameter '-Reset' cannot be used with parameters '-Tenant', '-Subscription' or '-Community'.");
279+
//}
280+
sharingUpdate.OperationType = "Reset";
275281
}
276-
if (this.IsParameterBound(c => c.Subscription))
282+
else if (this.IsParameterBound(c => c.Community))
277283
{
278-
if (sharingUpdate.Groups == null)
284+
if (this.Community.IsPresent)
279285
{
280-
sharingUpdate.Groups = new List<SharingProfileGroup>();
281-
}
282-
SharingProfileGroup sharingProfile = new SharingProfileGroup();
283-
sharingProfile.Type = "Subscriptions";
284-
sharingProfile.Ids = new List<string>();
285-
foreach (var id in this.Subscription)
286-
{
287-
sharingProfile.Ids.Add(id);
288-
}
289-
sharingUpdate.Groups.Add(sharingProfile);
290-
sharingUpdate.OperationType = "Add";
291-
}
292-
if (this.IsParameterBound(c => c.Tenant))
293-
{
294-
if (sharingUpdate.Groups == null)
295-
{
296-
sharingUpdate.Groups = new List<SharingProfileGroup>();
297-
}
298-
SharingProfileGroup sharingProfile = new SharingProfileGroup();
299-
sharingProfile.Type = "AADTenants";
300-
sharingProfile.Ids = new List<string>();
301-
foreach (var id in this.Tenant)
302-
{
303-
sharingProfile.Ids.Add(id);
286+
sharingUpdate.OperationType = "EnableCommunity";
304287
}
305-
sharingUpdate.Groups.Add(sharingProfile);
306-
sharingUpdate.OperationType = "Add";
307288
}
308-
if (this.IsParameterBound(c => c.RemoveTenant))
289+
else if (this.IsParameterBound(c => c.Subscription) || this.IsParameterBound(c => c.Tenant) || this.IsParameterBound(c => c.RemoveTenant) || this.IsParameterBound(c => c.RemoveSubscription))
309290
{
310-
if (sharingUpdate.Groups == null)
291+
if (this.IsParameterBound(c => c.Subscription))
311292
{
312-
sharingUpdate.Groups = new List<SharingProfileGroup>();
293+
if (sharingUpdate.Groups == null)
294+
{
295+
sharingUpdate.Groups = new List<SharingProfileGroup>();
296+
}
297+
SharingProfileGroup sharingProfile = new SharingProfileGroup();
298+
sharingProfile.Type = "Subscriptions";
299+
sharingProfile.Ids = new List<string>();
300+
foreach (var id in this.Subscription)
301+
{
302+
sharingProfile.Ids.Add(id);
303+
}
304+
sharingUpdate.Groups.Add(sharingProfile);
305+
sharingUpdate.OperationType = "Add";
313306
}
314-
SharingProfileGroup sharingProfile = new SharingProfileGroup();
315-
sharingProfile.Type = "AADTenants";
316-
sharingProfile.Ids = new List<string>();
317-
foreach (var id in this.RemoveTenant)
307+
if (this.IsParameterBound(c => c.Tenant))
318308
{
319-
sharingProfile.Ids.Add(id);
309+
if (sharingUpdate.Groups == null)
310+
{
311+
sharingUpdate.Groups = new List<SharingProfileGroup>();
312+
}
313+
SharingProfileGroup sharingProfile = new SharingProfileGroup();
314+
sharingProfile.Type = "AADTenants";
315+
sharingProfile.Ids = new List<string>();
316+
foreach (var id in this.Tenant)
317+
{
318+
sharingProfile.Ids.Add(id);
319+
}
320+
sharingUpdate.Groups.Add(sharingProfile);
321+
sharingUpdate.OperationType = "Add";
320322
}
321-
sharingUpdate.Groups.Add(sharingProfile);
322-
sharingUpdate.OperationType = "Remove";
323-
}
324-
if (this.IsParameterBound(c => c.RemoveSubscription))
325-
{
326-
if (sharingUpdate.Groups == null)
323+
if (this.IsParameterBound(c => c.RemoveTenant))
327324
{
328-
sharingUpdate.Groups = new List<SharingProfileGroup>();
325+
if (sharingUpdate.Groups == null)
326+
{
327+
sharingUpdate.Groups = new List<SharingProfileGroup>();
328+
}
329+
SharingProfileGroup sharingProfile = new SharingProfileGroup();
330+
sharingProfile.Type = "AADTenants";
331+
sharingProfile.Ids = new List<string>();
332+
foreach (var id in this.RemoveTenant)
333+
{
334+
sharingProfile.Ids.Add(id);
335+
}
336+
sharingUpdate.Groups.Add(sharingProfile);
337+
sharingUpdate.OperationType = "Remove";
329338
}
330-
SharingProfileGroup sharingProfile = new SharingProfileGroup();
331-
sharingProfile.Type = "Subscriptions";
332-
sharingProfile.Ids = new List<string>();
333-
foreach (var id in this.RemoveSubscription)
339+
if (this.IsParameterBound(c => c.RemoveSubscription))
334340
{
335-
sharingProfile.Ids.Add(id);
341+
if (sharingUpdate.Groups == null)
342+
{
343+
sharingUpdate.Groups = new List<SharingProfileGroup>();
344+
}
345+
SharingProfileGroup sharingProfile = new SharingProfileGroup();
346+
sharingProfile.Type = "Subscriptions";
347+
sharingProfile.Ids = new List<string>();
348+
foreach (var id in this.RemoveSubscription)
349+
{
350+
sharingProfile.Ids.Add(id);
351+
}
352+
sharingUpdate.Groups.Add(sharingProfile);
353+
sharingUpdate.OperationType = "Remove";
336354
}
337-
sharingUpdate.Groups.Add(sharingProfile);
338-
sharingUpdate.OperationType = "Remove";
339355
}
340-
if (this.IsParameterBound(c => c.Community))
356+
else
341357
{
342-
if(this.Community.IsPresent)
343-
sharingUpdate.OperationType = "EnableCommunity";
358+
throw new Exception("Parameters '-Subscription', '-Tenant', '-RemoveSubscription', '-RemoveTenant', '-Community' or '-Reset' must be used with '-Share' parameter.");
344359
}
345-
346360
}
347-
else if (this.IsParameterBound(c => c.Subscription) || this.IsParameterBound(c => c.Tenant) || this.Reset.IsPresent || this.IsParameterBound(c => c.RemoveSubscription) || this.IsParameterBound(c => c.RemoveTenant))
361+
else if (this.IsParameterBound(c => c.Subscription) || this.IsParameterBound(c => c.Tenant) || this.IsParameterBound(c => c.RemoveTenant) || this.IsParameterBound(c => c.RemoveSubscription))
348362
{
349-
throw new Exception("Parameters '-Subscription', '-Tenant', '-RemoveSubscription', '-RemoveTenant', and '-Reset' must be used with '-Share' parameter.");
363+
throw new Exception("Parameters '-Subscription', '-Tenant', '-RemoveSubscription' or '-RemoveTenant' must be used with '-Share' parameter.");
350364
}
351-
352-
var result = GalleriesClient.CreateOrUpdate(resourceGroupName, galleryName, gallery);
353-
if (this.Share.IsPresent)
365+
366+
Gallery result = new Gallery();
367+
if (this.Share.IsPresent || this.Community.IsPresent || this.Reset.IsPresent)
354368
{
355369
GallerySharingProfileClient.Update(resourceGroupName, galleryName, sharingUpdate);
356370
result = GalleriesClient.Get(ResourceGroupName, galleryName, "Permissions");
357371
}
372+
else
373+
{
374+
GalleriesClient.CreateOrUpdate(resourceGroupName, galleryName, gallery);
375+
}
358376
var psObject = new PSGallery();
359377
ComputeAutomationAutoMapperProfile.Mapper.Map<Gallery, PSGallery>(result, psObject);
360378
WriteObject(psObject);

src/Compute/Compute/Generated/Gallery/GalleryGetMethod.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,28 +168,35 @@ public void SharedGalleryGet()
168168

169169
public void CommunityGalleryGet()
170170
{
171-
if (this.IsParameterBound(c => c.GalleryPublicName))
171+
if (this.IsParameterBound(c => c.GalleryPublicName) && this.IsParameterBound(c=> c.Location))
172172
{
173173
CommunityGallery result = CommunityGalleriesClient.Get(this.Location, this.GalleryPublicName);
174174
var psObject = new PSCommunityGallery();
175175
ComputeAutomationAutoMapperProfile.Mapper.Map<CommunityGallery, PSCommunityGallery>(result, psObject);
176176
WriteObject(psObject);
177177
}
178-
else
178+
else if(this.IsParameterBound(c=> c.Community))
179179
{
180-
//find out if its ok to create client locally
181180
ResourceGraphClient rgClient = AzureSession.Instance.ClientFactory.CreateArmClient<ResourceGraphClient>(DefaultContext, AzureEnvironment.Endpoint.ResourceManager);
182181
QueryRequest request = new QueryRequest();
183-
string query = "communitygalleryresources | where type == 'microsoft.compute/locations/communitygalleries' | project name, type, id, location";
184-
182+
string query;
183+
if (this.IsParameterBound(c => c.Location))
184+
{
185+
query = "communitygalleryresources | where type == 'microsoft.compute/locations/communitygalleries' | where location =='" + this.Location + "' | project name, type, id, location";
186+
}
187+
else
188+
{
189+
query = "communitygalleryresources | where type == 'microsoft.compute/locations/communitygalleries' | project name, type, id, location";
190+
}
185191
request.Query = query;
186192
QueryResponse response = rgClient.Resources(request);
187-
Dictionary<string,string> output = new Dictionary<string, string>();
188-
193+
Dictionary<string, string> output = new Dictionary<string, string>();
189194
var data = JsonConvert.DeserializeObject<List<PSCommunityGallery>>(response.Data.ToString());
190-
191195
WriteObject(data);
192-
196+
}
197+
else if(this.IsParameterBound(c => c.GalleryPublicName))
198+
{
199+
throw new Exception("Location cannot be null. Add location using -Location parameter.");
193200
}
194201
}
195202

@@ -244,7 +251,7 @@ public void CommunityGalleryGet()
244251
ValueFromPipelineByPropertyName = true,
245252
ParameterSetName = "SharedGalleryParameterSet")]
246253
[Parameter(
247-
Mandatory = true,
254+
Mandatory = false,
248255
ValueFromPipelineByPropertyName = true,
249256
ParameterSetName = "CommunityGalleryParameterSet")]
250257
[LocationCompleter("Microsoft.Compute/Galleries", "Microsoft.Compute/CommunityGalleries")]
@@ -260,7 +267,7 @@ public void CommunityGalleryGet()
260267
public string Expand { get; set; }
261268

262269
[Parameter(
263-
Mandatory = true,
270+
Mandatory = false,
264271
ValueFromPipelineByPropertyName = true,
265272
ParameterSetName = "CommunityGalleryParameterSet",
266273
HelpMessage = "List community galleries.")]

src/Compute/Compute/Generated/GalleryImage/GalleryImageGetMethod.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
using Microsoft.WindowsAzure.Commands.Utilities.Common;
3232
using Microsoft.Azure.Management.ResourceGraph;
3333
using Microsoft.Azure.Management.Internal.Resources;
34+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
35+
using Microsoft.Azure.Commands.Common.Authentication;
36+
using Microsoft.Azure.Management.ResourceGraph.Models;
37+
using Newtonsoft.Json;
3438

3539
namespace Microsoft.Azure.Commands.Compute.Automation
3640
{
@@ -59,6 +63,9 @@ public override void ExecuteCmdlet()
5963
case "CommunityGalleryParameterSet":
6064
CommunityGalleryGet();
6165
return;
66+
case "ListCommunityGalleryParameterSet":
67+
ListCommunityGallery();
68+
return;
6269
default:
6370
resourceGroupName = this.ResourceGroupName;
6471
galleryName = this.GalleryName;
@@ -174,6 +181,27 @@ public void CommunityGalleryGet()
174181
}
175182
}
176183

184+
public void ListCommunityGallery()
185+
{
186+
ResourceGraphClient rgClient = AzureSession.Instance.ClientFactory.CreateArmClient<ResourceGraphClient>(DefaultContext, AzureEnvironment.Endpoint.ResourceManager);
187+
QueryRequest request = new QueryRequest();
188+
string query;
189+
if (this.IsParameterBound(c => c.Location))
190+
{
191+
query = "communitygalleryresources | where type == 'microsoft.compute/locations/communitygalleries/images' | where location =='" + this.Location + "' | project name, type, id, location";
192+
}
193+
//find out if its ok to create client locally
194+
else
195+
{
196+
query = "communitygalleryresources | where type == 'microsoft.compute/locations/communitygalleries/images' | project name, type, id, location";
197+
}
198+
request.Query = query;
199+
QueryResponse response = rgClient.Resources(request);
200+
Dictionary<string, string> output = new Dictionary<string, string>();
201+
var data = JsonConvert.DeserializeObject<List<PSCommunityGallery>>(response.Data.ToString());
202+
WriteObject(data);
203+
}
204+
177205
[Parameter(
178206
ParameterSetName = "DefaultParameter",
179207
Position = 0,
@@ -240,8 +268,19 @@ public void CommunityGalleryGet()
240268
Mandatory = true,
241269
ValueFromPipelineByPropertyName = true,
242270
ParameterSetName = "CommunityGalleryParameterSet")]
271+
[Parameter(
272+
Mandatory = false,
273+
ValueFromPipelineByPropertyName = true,
274+
ParameterSetName = "ListCommunityGalleryParameterSet")]
243275
[LocationCompleter("Microsoft.Compute/Galleries", "Microsoft.Compute/CommunityGalleries")]
244276
[ValidateNotNullOrEmpty]
245277
public string Location { get; set; }
278+
279+
[Parameter(
280+
Mandatory = false,
281+
ValueFromPipelineByPropertyName = true,
282+
ParameterSetName = "ListCommunityGalleryParameterSet",
283+
HelpMessage = "List community galleries.")]
284+
public SwitchParameter Community { get; set; }
246285
}
247286
}

0 commit comments

Comments
 (0)