Skip to content

Commit 9b3029f

Browse files
vmgalleryapplication cmdlets (#16179)
* add all changes * update * update parameter name * new cmdlets for VMGalleryApplication * add online version link * added supportshouldProcess * wrapping Co-authored-by: Beisi Zhou <[email protected]>
1 parent 4517b12 commit 9b3029f

26 files changed

+1067
-8
lines changed

src/Compute/Compute.Test/Compute.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<ItemGroup>
1414
<PackageReference Include="Microsoft.Azure.Graph.RBAC" Version="3.4.0-preview" />
15-
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="49.1.0" />
15+
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="49.2.0" />
1616
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="3.1.0-preview.2" />
1717
<PackageReference Include="Microsoft.Azure.Management.Network" Version="20.6.0" />
1818
</ItemGroup>

src/Compute/Compute/Az.Compute.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ CmdletsToExport = 'Remove-AzAvailabilitySet', 'Get-AzAvailabilitySet',
180180
'New-AzRestorePointCollection', 'Get-AzRestorePointCollection',
181181
'Update-AzRestorePointCollection',
182182
'Remove-AzRestorePointCollection', 'New-AzRestorePoint',
183-
'Get-AzRestorePoint', 'Remove-AzRestorePoint'
183+
'Get-AzRestorePoint', 'Remove-AzRestorePoint', 'New-AzVmGalleryApplication', 'New-AzVmssGalleryApplication',
184+
'Add-AzVmGalleryApplication', 'Add-AzVmssGalleryApplication', 'Remove-AzVmGalleryApplication', 'Remove-AzVmssGalleryApplication'
184185

185186
# Variables to export from this module
186187
# VariablesToExport = @()

src/Compute/Compute/ChangeLog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
2121
-->
2222
## Upcoming Release
23+
* Added cmdlets for adding VMGalleryApplication property to VM/VMSS
24+
- New-AzVmGalleryApplication
25+
- New-AzVmssGalleryApplication
26+
- Add-AzVmGalleryApplication
27+
- Add-AzVmssGalleryApplication
28+
- Remove-AzVmGalleryApplication
29+
- Remove-AzVmssGalleryApplication
2330
* Added support for proxy and debug settings for VM Extension for SAP (AEM)
2431
* Updated New-AzGalleryImageVersion to take in the 'Encryption' property correctly from '-TargetRegion' parameter.
2532
* Updated Set-AzVmBootDiagnostic to default to managed storage account if not provided.

src/Compute/Compute/Compute.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<ItemGroup>
1515
<PackageReference Include="AutoMapper" Version="6.2.2" />
16-
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="49.1.0" />
16+
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="49.2.0" />
1717
<PackageReference Include="System.Security.Permissions" Version="4.5.0" />
1818
<PackageReference Include="System.ServiceModel.Primitives" Version="4.4.1" />
1919
<PackageReference Include="WindowsAzure.Storage" Version="9.3.0" />
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Management.Automation;
16+
using Microsoft.Azure.Commands.Compute.Common;
17+
using Microsoft.Azure.Management.Compute.Models;
18+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
19+
using Microsoft.Azure.Commands.Compute.Models;
20+
using Microsoft.Azure.Commands.Compute.Automation.Models;
21+
using System.Collections.Generic;
22+
23+
24+
namespace Microsoft.Azure.Commands.Compute.Automation
25+
{
26+
[Cmdlet("Add", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VmGalleryApplication", SupportsShouldProcess = true)]
27+
[OutputType(typeof(PSVirtualMachine))]
28+
public class AddAzureVmGalleryApplicationCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet
29+
{
30+
[Parameter(
31+
Mandatory = true,
32+
HelpMessage = "The PSVirtualMachine object to add a Gallery Application Reference ID.")]
33+
public PSVirtualMachine VM { get; set; }
34+
35+
[Parameter(
36+
Mandatory = true,
37+
HelpMessage = "VM Gallery Application Object.")]
38+
public PSVMGalleryApplication GalleryApplication { get; set; }
39+
40+
[Parameter(
41+
Mandatory = false)]
42+
public int Order { get; set; }
43+
44+
public override void ExecuteCmdlet()
45+
{
46+
if (VM.ApplicationProfile == null)
47+
{
48+
VM.ApplicationProfile = new PSApplicationProfile();
49+
}
50+
if (VM.ApplicationProfile.GalleryApplications == null)
51+
{
52+
VM.ApplicationProfile.GalleryApplications = new List<PSVMGalleryApplication>();
53+
}
54+
55+
if (this.IsParameterBound(c => c.Order))
56+
{
57+
GalleryApplication.Order = this.Order;
58+
}
59+
60+
VM.ApplicationProfile.GalleryApplications.Add(GalleryApplication);
61+
62+
WriteObject(VM);
63+
}
64+
}
65+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Management.Automation;
16+
using Microsoft.Azure.Commands.Compute.Common;
17+
using Microsoft.Azure.Management.Compute.Models;
18+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
19+
using Microsoft.Azure.Commands.Compute.Models;
20+
using Microsoft.Azure.Commands.Compute.Automation.Models;
21+
using System.Collections.Generic;
22+
23+
namespace Microsoft.Azure.Commands.Compute.Automation
24+
{
25+
[Cmdlet("Add", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VmssGalleryApplication", SupportsShouldProcess = true)]
26+
[OutputType(typeof(PSVirtualMachineScaleSetVMProfile))]
27+
public class AddAzureVmssGalleryApplicationCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet
28+
{
29+
[Parameter(
30+
Mandatory = true,
31+
HelpMessage = "The PSVirtualMachineScaleSetVMProfile object to add a Gallery Application Reference ID.")]
32+
public PSVirtualMachineScaleSetVMProfile VirtualMachineScaleSetVM { get; set; }
33+
34+
[Parameter(
35+
Mandatory = true,
36+
HelpMessage = "VM Gallery Application Object.")]
37+
public PSVMGalleryApplication GalleryApplication { get; set; }
38+
39+
[Parameter(
40+
Mandatory = false)]
41+
public int Order { get; set; }
42+
43+
public override void ExecuteCmdlet()
44+
{
45+
if (VirtualMachineScaleSetVM.ApplicationProfile == null)
46+
{
47+
VirtualMachineScaleSetVM.ApplicationProfile = new PSApplicationProfile();
48+
}
49+
if (VirtualMachineScaleSetVM.ApplicationProfile.GalleryApplications == null)
50+
{
51+
VirtualMachineScaleSetVM.ApplicationProfile.GalleryApplications = new List<PSVMGalleryApplication>();
52+
}
53+
54+
if (this.IsParameterBound(c => c.Order))
55+
{
56+
GalleryApplication.Order = this.Order;
57+
}
58+
59+
VirtualMachineScaleSetVM.ApplicationProfile.GalleryApplications.Add(GalleryApplication);
60+
61+
WriteObject(VirtualMachineScaleSetVM);
62+
}
63+
}
64+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Management.Automation;
16+
using Microsoft.Azure.Commands.Compute.Common;
17+
using Microsoft.Azure.Management.Compute.Models;
18+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
19+
using Microsoft.Azure.Commands.Compute.Models;
20+
using Microsoft.Azure.Commands.Compute.Automation.Models;
21+
22+
23+
namespace Microsoft.Azure.Commands.Compute.Automation
24+
{
25+
[Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VmGalleryApplication", SupportsShouldProcess = true)]
26+
[OutputType(typeof(PSVMGalleryApplication))]
27+
public class NewAzureVmGalleryApplicationCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet
28+
{
29+
[Parameter(
30+
Mandatory = true,
31+
HelpMessage = "Package Reference Id of the Gallery Application.")]
32+
[ValidateNotNullOrEmpty]
33+
public string PackageReferenceId { get; set; }
34+
35+
[Parameter(
36+
Mandatory = false,
37+
HelpMessage = "Configuration Reference Id of the Gallery Application.")]
38+
[ValidateNotNullOrEmpty]
39+
public string ConfigReferenceId { get; set; }
40+
41+
public override void ExecuteCmdlet()
42+
{
43+
44+
var vmGal = new PSVMGalleryApplication();
45+
vmGal.PackageReferenceId = PackageReferenceId;
46+
if (this.IsParameterBound(c => c.ConfigReferenceId))
47+
{
48+
vmGal.ConfigurationReference = this.ConfigReferenceId;
49+
}
50+
51+
WriteObject(vmGal);
52+
}
53+
}
54+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Management.Automation;
16+
using Microsoft.Azure.Commands.Compute.Common;
17+
using Microsoft.Azure.Management.Compute.Models;
18+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
19+
using Microsoft.Azure.Commands.Compute.Models;
20+
using Microsoft.Azure.Commands.Compute.Automation.Models;
21+
22+
namespace Microsoft.Azure.Commands.Compute.Automation
23+
{
24+
[Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VmssGalleryApplication", SupportsShouldProcess = true)]
25+
[OutputType(typeof(PSVMGalleryApplication))]
26+
public class NewAzureVmssGalleryApplicationCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet
27+
{
28+
[Parameter(
29+
Mandatory = true,
30+
HelpMessage = "Package Reference Id of the Gallery Application.")]
31+
[ValidateNotNullOrEmpty]
32+
public string PackageReferenceId { get; set; }
33+
34+
[Parameter(
35+
Mandatory = false,
36+
HelpMessage = "Configuration Reference Id of the Gallery Application.")]
37+
[ValidateNotNullOrEmpty]
38+
public string ConfigReferenceId { get; set; }
39+
40+
public override void ExecuteCmdlet()
41+
{
42+
43+
var vmGal = new PSVMGalleryApplication();
44+
vmGal.PackageReferenceId = PackageReferenceId;
45+
if (this.IsParameterBound(c => c.ConfigReferenceId))
46+
{
47+
vmGal.ConfigurationReference = this.ConfigReferenceId;
48+
}
49+
50+
WriteObject(vmGal);
51+
}
52+
}
53+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Management.Automation;
16+
using Microsoft.Azure.Commands.Compute.Common;
17+
using Microsoft.Azure.Management.Compute.Models;
18+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
19+
using Microsoft.Azure.Commands.Compute.Models;
20+
21+
namespace Microsoft.Azure.Commands.Compute.Automation
22+
{
23+
[Cmdlet("Remove", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VmGalleryApplication", SupportsShouldProcess = true)]
24+
[OutputType(typeof(PSVirtualMachine))]
25+
public class RemoveAzureVmGalleryApplicationCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet
26+
{
27+
[Parameter(
28+
Mandatory = true,
29+
HelpMessage = "The PSVirtualMachine object to delete a Gallery Application Reference ID from.")]
30+
public PSVirtualMachine VM { get; set; }
31+
32+
[Parameter(
33+
Mandatory = true,
34+
HelpMessage = "Package Reference Id of the Gallery Application to delete.")]
35+
[ValidateNotNullOrEmpty]
36+
public string GalleryApplicationsReferenceId { get; set; }
37+
38+
public override void ExecuteCmdlet()
39+
{
40+
if (VM.ApplicationProfile == null)
41+
{
42+
WriteObject(VM);
43+
}
44+
45+
for (int i = 0; i < VM.ApplicationProfile.GalleryApplications.Count; i++)
46+
{
47+
if (VM.ApplicationProfile.GalleryApplications[i].PackageReferenceId == GalleryApplicationsReferenceId)
48+
{
49+
VM.ApplicationProfile.GalleryApplications.RemoveAt(i);
50+
break;
51+
}
52+
}
53+
WriteObject(VM);
54+
}
55+
}
56+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Management.Automation;
16+
using Microsoft.Azure.Commands.Compute.Common;
17+
using Microsoft.Azure.Management.Compute.Models;
18+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
19+
using Microsoft.Azure.Commands.Compute.Models;
20+
using Microsoft.Azure.Commands.Compute.Automation.Models;
21+
22+
namespace Microsoft.Azure.Commands.Compute.Automation
23+
{
24+
[Cmdlet("Remove", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VmssGalleryApplication", SupportsShouldProcess = true)]
25+
[OutputType(typeof(PSVirtualMachineScaleSetVMProfile))]
26+
public class RemoveAzureVmssGalleryApplicationCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet
27+
{
28+
[Parameter(
29+
Mandatory = true,
30+
HelpMessage = "The PSVirtualMachineScaleSetVMProfile object to delete a Gallery Application Reference ID from.")]
31+
public PSVirtualMachineScaleSetVMProfile VirtualMachineScaleSetVM { get; set; }
32+
33+
[Parameter(
34+
Mandatory = true,
35+
HelpMessage = "Package Reference Id of the Gallery Application to delete.")]
36+
[ValidateNotNullOrEmpty]
37+
public string GalleryApplicationsReferenceId { get; set; }
38+
39+
public override void ExecuteCmdlet()
40+
{
41+
if (VirtualMachineScaleSetVM.ApplicationProfile == null)
42+
{
43+
WriteObject(VirtualMachineScaleSetVM);
44+
}
45+
46+
for (int i = 0; i < VirtualMachineScaleSetVM.ApplicationProfile.GalleryApplications.Count; i++)
47+
{
48+
if (VirtualMachineScaleSetVM.ApplicationProfile.GalleryApplications[i].PackageReferenceId == GalleryApplicationsReferenceId)
49+
{
50+
VirtualMachineScaleSetVM.ApplicationProfile.GalleryApplications.RemoveAt(i);
51+
break;
52+
}
53+
}
54+
WriteObject(VirtualMachineScaleSetVM);
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)