Skip to content

Commit 760a3a2

Browse files
haaghawyunchi-msisra-fel
authored
[Compute] Communitygallery changes (#19121)
* 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 Co-authored-by: Yunchi Wang <[email protected]> Co-authored-by: Yeming Liu <[email protected]>
1 parent 4a82d5f commit 760a3a2

18 files changed

+881
-35
lines changed

src/Compute/Compute/Az.Compute.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ RequiredModules = @(@{ModuleName = 'Az.Accounts'; ModuleVersion = '2.9.0'; })
5858

5959
# Assemblies that must be loaded prior to importing this module
6060
RequiredAssemblies = 'AutoMapper.dll', 'Microsoft.Azure.Management.Compute.dll',
61-
'Microsoft.WindowsAzure.Storage.dll',
61+
'Microsoft.WindowsAzure.Storage.dll', 'Microsoft.Azure.Management.ResourceGraph.dll',
6262
'Compute.Autorest\bin\Az.Compute.private.dll',
6363
'Microsoft.Azure.PowerShell.Cmdlets.Compute.Helpers.dll'
6464

src/Compute/Compute/ChangeLog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727
* Improved printed output for `Get-AzComputeResourceSku`
2828
* Updated `Update-AzVm` to give constructive error messages when empty variables are passed in parameters. [#15081]
2929
* Added `Zone` and `IntentVMSizeList` optional parameters to the cmdlet `New-AzProximityPlacementGroup`.
30+
* Added parameters to Gallery cmdlets for Community Galleries
3031
* For `New-AzGalleryImageVersion`, `CVMEncryptionType` and `CVMDiskEncryptionSetID` added as keys for parameter `-Target`.
3132

3233
## Version 4.30.0
33-
* Added parameters `PackageFileName`, `ConfigFileName` for `New-AzGalleryApplicationVersion`
34+
* Added parameters `PackageFileName`, `ConfigFileName` for `New-AzGalleryApplicationVersion`
3435

3536
## Version 4.29.0
3637
* Added image alias 'Win2022AzureEditionCore'

src/Compute/Compute/Compute.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
<ItemGroup>
1616
<PackageReference Include="AutoMapper" Version="6.2.2" />
17+
<PackageReference Include="Microsoft.Azure.Management.ResourceGraph" Version="2.1.0" />
1718
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="57.0.0" />
1819
<PackageReference Include="System.Security.Permissions" Version="4.5.0" />
1920
<PackageReference Include="System.ServiceModel.Primitives" Version="4.7.0" />

src/Compute/Compute/Generated/ComputeAutomationBaseCmdlet.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,30 @@ public ISharedGalleriesOperations SharedGalleriesClient
168168
}
169169
}
170170

171+
public ICommunityGalleriesOperations CommunityGalleriesClient
172+
{
173+
get
174+
{
175+
return ComputeClient.ComputeManagementClient.CommunityGalleries;
176+
}
177+
}
178+
179+
public ICommunityGalleryImagesOperations CommunityGalleryImagesClient
180+
{
181+
get
182+
{
183+
return ComputeClient.ComputeManagementClient.CommunityGalleryImages;
184+
}
185+
}
186+
187+
public ICommunityGalleryImageVersionsOperations CommunityGalleryImageVersionsClient
188+
{
189+
get
190+
{
191+
return ComputeClient.ComputeManagementClient.CommunityGalleryImageVersions;
192+
}
193+
}
194+
171195
public ISharedGalleryImagesOperations SharedGalleryImagesClient
172196
{
173197
get

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

Lines changed: 128 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,52 @@ public override void ExecuteCmdlet()
4747
string galleryName = this.Name;
4848
Gallery gallery = new Gallery();
4949
gallery.Location = this.Location;
50-
if (this.IsParameterBound(c => c.Permission)){
51-
gallery.SharingProfile = new SharingProfile();
52-
gallery.SharingProfile.Permissions = this.Permission;
53-
}
50+
CommunityGalleryInfo communityGalleryInfo = new CommunityGalleryInfo();
51+
5452

5553
if (this.IsParameterBound(c => c.Description))
5654
{
5755
gallery.Description = this.Description;
5856
}
5957

58+
if (this.IsParameterBound(c => c.PublisherUri))
59+
{
60+
communityGalleryInfo.PublisherUri = this.PublisherUri;
61+
}
62+
63+
if (this.IsParameterBound(c => c.PublisherContact))
64+
{
65+
communityGalleryInfo.PublisherContact = this.PublisherContact;
66+
}
67+
68+
if (this.IsParameterBound(c => c.Eula))
69+
{
70+
communityGalleryInfo.Eula = this.Eula;
71+
}
72+
73+
if (this.IsParameterBound(c => c.PublicNamePrefix))
74+
{
75+
communityGalleryInfo.PublicNamePrefix = this.PublicNamePrefix;
76+
}
77+
78+
if (this.IsParameterBound(c => c.Permission))
79+
{
80+
gallery.SharingProfile = new SharingProfile();
81+
gallery.SharingProfile.Permissions = this.Permission;
82+
83+
if (gallery.SharingProfile.Permissions.ToLower() == "community")
84+
{
85+
gallery.SharingProfile.CommunityGalleryInfo = communityGalleryInfo;
86+
}
87+
}
88+
89+
6090
if (this.IsParameterBound(c => c.Tag))
6191
{
6292
gallery.Tags = this.Tag.Cast<DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value);
6393
}
6494

95+
6596
var result = GalleriesClient.CreateOrUpdate(resourceGroupName, galleryName, gallery);
6697
var psObject = new PSGallery();
6798
ComputeAutomationAutoMapperProfile.Mapper.Map<Gallery, PSGallery>(result, psObject);
@@ -110,9 +141,34 @@ public override void ExecuteCmdlet()
110141
[Parameter(
111142
Mandatory = false,
112143
ValueFromPipelineByPropertyName = true,
113-
HelpMessage = "This property allows you to specify the permission of sharing gallery. Possible values are: 'Private' and 'Groups'.")]
114-
[PSArgumentCompleter("Private","Groups")]
144+
HelpMessage = "This property allows you to specify the permission of sharing gallery. Possible values are: 'Private', 'Groups' and 'Community'.")]
145+
[PSArgumentCompleter("Private","Groups","Community")]
115146
public string Permission { get; set; }
147+
148+
[Parameter(
149+
Mandatory = false,
150+
ValueFromPipelineByPropertyName = true,
151+
HelpMessage = "Gets or sets the link to the publisher website. Visible to all users.")]
152+
public string PublisherUri { get; set; }
153+
154+
[Parameter(
155+
Mandatory = false,
156+
ValueFromPipelineByPropertyName = true,
157+
HelpMessage = "Gets or sets community gallery publisher support email. The email address of the publisher. Visible to all users.")]
158+
public string PublisherContact { get; set; }
159+
160+
[Parameter(
161+
Mandatory = false,
162+
ValueFromPipelineByPropertyName = true,
163+
HelpMessage = "Gets or sets end-user license agreement for community gallery image.")]
164+
public string Eula { get; set; }
165+
166+
[Parameter(
167+
Mandatory = false,
168+
ValueFromPipelineByPropertyName = true,
169+
HelpMessage = "Gets or sets the prefix of the gallery name that will be displayed publicly. Visible to all users.")]
170+
public string PublicNamePrefix { get; set; }
171+
116172
}
117173

118174
[Cmdlet(VerbsData.Update, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "Gallery", DefaultParameterSetName = "DefaultParameter", SupportsShouldProcess = true)]
@@ -145,6 +201,7 @@ public override void ExecuteCmdlet()
145201
}
146202

147203
Gallery gallery = new Gallery();
204+
CommunityGalleryInfo communityGalleryInfo = new CommunityGalleryInfo();
148205

149206
if (this.ParameterSetName == "ObjectParameter")
150207
{
@@ -160,17 +217,44 @@ public override void ExecuteCmdlet()
160217
gallery.Description = this.Description;
161218
}
162219

220+
if (this.IsParameterBound(c => c.PublisherUri))
221+
{
222+
communityGalleryInfo.PublisherUri = this.PublisherUri;
223+
}
224+
225+
if (this.IsParameterBound(c => c.PublisherContact))
226+
{
227+
communityGalleryInfo.PublisherContact = this.PublisherContact;
228+
}
229+
230+
if (this.IsParameterBound(c => c.Eula))
231+
{
232+
communityGalleryInfo.Eula = this.Eula;
233+
}
234+
235+
if (this.IsParameterBound(c => c.PublicNamePrefix))
236+
{
237+
communityGalleryInfo.PublicNamePrefix = this.PublicNamePrefix;
238+
}
239+
163240
if (this.IsParameterBound(c => c.Tag))
164241
{
165242
gallery.Tags = this.Tag.Cast<DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value);
166243
}
244+
167245
if (this.IsParameterBound(c => c.Permission))
168246
{
169247
if (gallery.SharingProfile == null)
170248
{
171249
gallery.SharingProfile = new SharingProfile();
172250
}
173251
gallery.SharingProfile.Permissions = this.Permission;
252+
253+
if (gallery.SharingProfile.Permissions.ToLower() == "community")
254+
{
255+
gallery.SharingProfile.CommunityGalleryInfo = communityGalleryInfo;
256+
}
257+
174258
}
175259

176260

@@ -182,7 +266,7 @@ public override void ExecuteCmdlet()
182266
// if sub or tenant is present return error
183267
if (this.IsParameterBound(c => c.Subscription) || this.IsParameterBound(c => c.Tenant))
184268
{
185-
throw new Exception("Parameter '-Reset' cannot be used with parameters '-Tenant' or '-Subscription'.");
269+
throw new Exception("Parameter '-Reset' cannot be used with parameters '-Tenant', '-Subscription' or 'Community'.");
186270
}
187271
else
188272
{
@@ -253,6 +337,11 @@ public override void ExecuteCmdlet()
253337
sharingUpdate.Groups.Add(sharingProfile);
254338
sharingUpdate.OperationType = "Remove";
255339
}
340+
if (this.IsParameterBound(c => c.Community))
341+
{
342+
if(this.Community.IsPresent)
343+
sharingUpdate.OperationType = "EnableCommunity";
344+
}
256345

257346
}
258347
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))
@@ -320,8 +409,8 @@ public override void ExecuteCmdlet()
320409
[Parameter(
321410
Mandatory = false,
322411
ValueFromPipelineByPropertyName = true,
323-
HelpMessage = "This property allows you to specify the permission of the sharing gallery. Possible values are: 'Private' and 'Groups'.")]
324-
[PSArgumentCompleter("Private", "Groups")]
412+
HelpMessage = "This property allows you to specify the permission of the sharing gallery. Possible values are: 'Private', 'Groups' and 'Community'.")]
413+
[PSArgumentCompleter("Private", "Groups", "Community")]
325414
public string Permission { get; set; }
326415

327416
[Parameter(
@@ -354,10 +443,40 @@ public override void ExecuteCmdlet()
354443
HelpMessage = "Update sharing profile of the gallery.")]
355444
public SwitchParameter Share { get; set; }
356445

446+
[Parameter(
447+
Mandatory = false,
448+
ValueFromPipelineByPropertyName = true,
449+
HelpMessage = "Update sharing profile of the gallery to community.")]
450+
public SwitchParameter Community { get; set; }
451+
357452
[Parameter(
358453
Mandatory = false,
359454
ValueFromPipelineByPropertyName = true,
360455
HelpMessage = "Resets the sharing permission of the gallery to 'Private'.")]
361456
public SwitchParameter Reset { get; set; }
457+
458+
[Parameter(
459+
Mandatory = false,
460+
ValueFromPipelineByPropertyName = true,
461+
HelpMessage = "Gets or sets the link to the publisher website. Visible to all users.")]
462+
public string PublisherUri { get; set; }
463+
464+
[Parameter(
465+
Mandatory = false,
466+
ValueFromPipelineByPropertyName = true,
467+
HelpMessage = "Gets or sets community gallery publisher support email. The email address of the publisher. Visible to all users.")]
468+
public string PublisherContact { get; set; }
469+
470+
[Parameter(
471+
Mandatory = false,
472+
ValueFromPipelineByPropertyName = true,
473+
HelpMessage = "Gets or sets end-user license agreement for community gallery image.")]
474+
public string Eula { get; set; }
475+
476+
[Parameter(
477+
Mandatory = false,
478+
ValueFromPipelineByPropertyName = true,
479+
HelpMessage = "Gets or sets the prefix of the gallery name that will be displayed publicly. Visible to all users.")]
480+
public string PublicNamePrefix { get; set; }
362481
}
363482
}

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

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
using Microsoft.Azure.Management.Compute;
3030
using Microsoft.Azure.Management.Compute.Models;
3131
using Microsoft.WindowsAzure.Commands.Utilities.Common;
32+
using Microsoft.Azure.Management.ResourceGraph;
33+
using Microsoft.Azure.Management.ResourceGraph.Models;
34+
using Microsoft.Azure.Management.Internal.Resources;
35+
using Microsoft.Azure.Commands.Common.Authentication;
36+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
37+
using Newtonsoft.Json;
3238

3339
namespace Microsoft.Azure.Commands.Compute.Automation
3440
{
@@ -52,6 +58,9 @@ public override void ExecuteCmdlet()
5258
case "SharedGalleryParameterSet":
5359
SharedGalleryGet();
5460
return;
61+
case "CommunityGalleryParameterSet":
62+
CommunityGalleryGet();
63+
return;
5564
default:
5665
resourceGroupName = this.ResourceGroupName;
5766
galleryName = this.Name;
@@ -126,7 +135,7 @@ public void SharedGalleryGet()
126135
}
127136
else
128137
{
129-
Rest.Azure.IPage<SharedGallery> result = new Page<SharedGallery>();
138+
Rest.Azure.IPage<SharedGallery> result = new Azure.Management.Compute.Models.Page<SharedGallery>();
130139

131140
if (this.IsParameterBound(c => c.Scope) && this.Scope != "subscription")
132141
{
@@ -157,6 +166,33 @@ public void SharedGalleryGet()
157166
}
158167
}
159168

169+
public void CommunityGalleryGet()
170+
{
171+
if (this.IsParameterBound(c => c.GalleryPublicName))
172+
{
173+
CommunityGallery result = CommunityGalleriesClient.Get(this.Location, this.GalleryPublicName);
174+
var psObject = new PSCommunityGallery();
175+
ComputeAutomationAutoMapperProfile.Mapper.Map<CommunityGallery, PSCommunityGallery>(result, psObject);
176+
WriteObject(psObject);
177+
}
178+
else
179+
{
180+
//find out if its ok to create client locally
181+
ResourceGraphClient rgClient = AzureSession.Instance.ClientFactory.CreateArmClient<ResourceGraphClient>(DefaultContext, AzureEnvironment.Endpoint.ResourceManager);
182+
QueryRequest request = new QueryRequest();
183+
string query = "communitygalleryresources | where type == 'microsoft.compute/locations/communitygalleries' | project name, type, id, location";
184+
185+
request.Query = query;
186+
QueryResponse response = rgClient.Resources(request);
187+
Dictionary<string,string> output = new Dictionary<string, string>();
188+
189+
var data = JsonConvert.DeserializeObject<List<PSCommunityGallery>>(response.Data.ToString());
190+
191+
WriteObject(data);
192+
193+
}
194+
}
195+
160196
[Parameter(
161197
ParameterSetName = "DefaultParameter",
162198
Position = 0,
@@ -187,6 +223,14 @@ public void SharedGalleryGet()
187223
HelpMessage = "The unique name of the Shared Image Gallery.")]
188224
public string GalleryUniqueName { get; set; }
189225

226+
[Parameter(
227+
Mandatory = false,
228+
ValueFromPipelineByPropertyName = true,
229+
ParameterSetName = "CommunityGalleryParameterSet",
230+
HelpMessage = "The public name of the Shared Image Gallery.")]
231+
public string GalleryPublicName { get; set; }
232+
233+
190234
[Parameter(
191235
Mandatory = false,
192236
ValueFromPipelineByPropertyName = true,
@@ -199,7 +243,11 @@ public void SharedGalleryGet()
199243
Mandatory = true,
200244
ValueFromPipelineByPropertyName = true,
201245
ParameterSetName = "SharedGalleryParameterSet")]
202-
[LocationCompleter("Microsoft.Compute/Galleries")]
246+
[Parameter(
247+
Mandatory = true,
248+
ValueFromPipelineByPropertyName = true,
249+
ParameterSetName = "CommunityGalleryParameterSet")]
250+
[LocationCompleter("Microsoft.Compute/Galleries", "Microsoft.Compute/CommunityGalleries")]
203251
[ValidateNotNullOrEmpty]
204252
public string Location { get; set; }
205253

@@ -210,5 +258,13 @@ public void SharedGalleryGet()
210258
HelpMessage = "The expand query option to apply on the operation.")]
211259
[PSArgumentCompleter("SharingProfile/Groups")]
212260
public string Expand { get; set; }
261+
262+
[Parameter(
263+
Mandatory = true,
264+
ValueFromPipelineByPropertyName = true,
265+
ParameterSetName = "CommunityGalleryParameterSet",
266+
HelpMessage = "List community galleries.")]
267+
public SwitchParameter Community { get; set; }
268+
213269
}
214270
}

0 commit comments

Comments
 (0)