Skip to content

Commit 620c548

Browse files
authored
Feature/cplat add ip address warning (#19250)
* Added Warning for Allocation Method and PublicIpAddress Added a check for allocation method and Public Ip * Added PublicIpSku parameter * Added -PublicIpSku parameter to NewAzVm and added PublicIpSku Warning Added new Parameter `-PublicIpSku` to the `NewAzVM` cmdlet with acceptable values : "Basic" and "Standard". Added Generic Breaking Change PublicIpSku Warning. Overridden `-Zone` logic when `-PublicIpSku` is explicitly provided. * Code refactoring Changed to older version * Updated Compute.csproj Removed unnecessary output type that was added as part of version change * Changed Invalid PublicIpSku Parameter logic
1 parent 7e4e36c commit 620c548

File tree

5 files changed

+58
-16
lines changed

5 files changed

+58
-16
lines changed

src/Compute/Compute/ChangeLog.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
2121
-->
2222
## Upcoming Release
23+
* Added new Parameter `-PublicIpSku` to the `NewAzVM` cmdlet with acceptable values : "Basic" and "Standard".
24+
* Added Generic Breaking Change PublicIpSku Warning and Overridden `-Zone` logic when `-PublicIpSku` is explicitly provided.
2325
* Added Disk Delete Optional parameters `OsDisk Deletion Option` and `Delete Option` to the `Set-AzVmssStorageProfile` (OS Disk) and `Add-AzVmssDataDisk` (Data Disk)
24-
2526
* Improve printed output for `Get-AzComputeResourceSku`
26-
2727
* Updated `Update-AzVm` to give constructive error messages when empty variables are passed in parameters. [#15081]
2828

2929
## Version 4.30.0

src/Compute/Compute/Compute.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<PsModuleName>Compute</PsModuleName>

src/Compute/Compute/VirtualMachine/Operation/NewAzureVMCommand.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@
5050
using SM = Microsoft.Azure.PowerShell.Cmdlets.Compute.Helpers.Storage.Models;
5151
using Microsoft.Azure.Commands.Compute;
5252
using Microsoft.Azure.PowerShell.Cmdlets.Compute.Helpers.Network.Models;
53-
53+
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
5454

5555
namespace Microsoft.Azure.Commands.Compute
5656
{
57+
[GenericBreakingChange("It is recommended to use parameter \"-PublicIpSku Standard\" in order to create a new VM with a Standard public IP.Specifying zone(s) using the \"-Zone\" parameter will also result in a Standard public IP.If \"-Zone\" and \"-PublicIpSku\" are not specified, the VM will be created with a Basic public IP instead.Please note that the Standard SKU IPs will become the default behavior for VM creation in the future")]
5758
[Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VM", SupportsShouldProcess = true, DefaultParameterSetName = "SimpleParameterSet")]
5859
[OutputType(typeof(PSAzureOperationResponse), typeof(PSVirtualMachine))]
5960
public class NewAzureVMCommand : VirtualMachineBaseCmdlet
@@ -117,6 +118,17 @@ public class NewAzureVMCommand : VirtualMachineBaseCmdlet
117118
[ValidateNotNullOrEmpty]
118119
public string[] Zone { get; set; }
119120

121+
[Parameter(
122+
ParameterSetName = SimpleParameterSet,
123+
Mandatory = false,
124+
HelpMessage = "Specify public IP sku name")]
125+
[Parameter(
126+
ParameterSetName = DiskFileParameterSet,
127+
Mandatory = false,
128+
HelpMessage = "Specify public IP sku name")]
129+
[PSArgumentCompleter("Basic","Standard")]
130+
public string PublicIpSku { get; set; }
131+
120132
[Parameter(
121133
ParameterSetName = DefaultParameterSet,
122134
HelpMessage = "Disable BG Info Extension")]
@@ -510,6 +522,19 @@ public async Task<ResourceConfig<VirtualMachine>> CreateConfigAsync()
510522
}
511523
}
512524

525+
//Override Zone logic if PublicIpSku is explicitly provided
526+
PublicIPAddressStrategy.Sku publicIpSku;
527+
if (_cmdlet.PublicIpSku != null) {
528+
if (_cmdlet.PublicIpSku != "Basic" && _cmdlet.PublicIpSku != "Standard")
529+
{
530+
throw new InvalidDataException("Invalid PublicIpSku parameter entry. Acceptable values for PublicIpSku parameter are \"Basic\" or \"Standard\" only");
531+
}
532+
publicIpSku = _cmdlet.PublicIpSku == "Basic" ? PublicIPAddressStrategy.Sku.Basic : PublicIPAddressStrategy.Sku.Standard;
533+
}
534+
else {
535+
publicIpSku = _cmdlet.Zone == null ? PublicIPAddressStrategy.Sku.Basic : PublicIPAddressStrategy.Sku.Standard;
536+
}
537+
513538
var resourceGroup = ResourceGroupStrategy.CreateResourceGroupConfig(_cmdlet.ResourceGroupName);
514539
var virtualNetwork = resourceGroup.CreateVirtualNetworkConfig(
515540
name: _cmdlet.VirtualNetworkName, edgeZone: _cmdlet.EdgeZone, addressPrefix: _cmdlet.AddressPrefix);
@@ -519,7 +544,7 @@ public async Task<ResourceConfig<VirtualMachine>> CreateConfigAsync()
519544
edgeZone: _cmdlet.EdgeZone,
520545
domainNameLabel: _cmdlet.DomainNameLabel,
521546
allocationMethod: _cmdlet.AllocationMethod,
522-
sku: _cmdlet.Zone == null ? PublicIPAddressStrategy.Sku.Basic : PublicIPAddressStrategy.Sku.Standard,
547+
sku: publicIpSku,
523548
zones: _cmdlet.Zone);
524549

525550
_cmdlet.OpenPorts = ImageAndOsType.UpdatePorts(_cmdlet.OpenPorts);
@@ -672,7 +697,6 @@ async Task StrategyExecuteCmdletAsync(IAsyncCmdlet asyncCmdlet)
672697
{
673698
WriteInformation("No Size value has been provided. The VM will be created with the default size Standard_D2s_v3.", new string[] { "PSHOST" });
674699
}
675-
676700
if (DiskFile != null)
677701
{
678702
if (!resourceClient.ResourceGroups.CheckExistence(ResourceGroupName))

src/Compute/Compute/help/New-AzVM.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Creates a virtual machine.
1616
### SimpleParameterSet (Default)
1717
```
1818
New-AzVM [[-ResourceGroupName] <String>] [[-Location] <String>] [-EdgeZone <String>] [[-Zone] <String[]>]
19-
-Name <String> -Credential <PSCredential> [-NetworkInterfaceDeleteOption <String>]
19+
[-PublicIpSku <String>] -Name <String> -Credential <PSCredential> [-NetworkInterfaceDeleteOption <String>]
2020
[-VirtualNetworkName <String>] [-AddressPrefix <String>] [-SubnetName <String>]
2121
[-SubnetAddressPrefix <String>] [-PublicIpAddressName <String>] [-DomainNameLabel <String>]
2222
[-AllocationMethod <String>] [-SecurityGroupName <String>] [-OpenPorts <Int32[]>] [-Image <String>]
@@ -41,14 +41,15 @@ New-AzVM [-ResourceGroupName] <String> [-Location] <String> [-EdgeZone <String>]
4141

4242
### DiskFileParameterSet
4343
```
44-
New-AzVM [[-ResourceGroupName] <String>] [[-Location] <String>] [-EdgeZone <String>] -Name <String>
45-
[-NetworkInterfaceDeleteOption <String>] [-VirtualNetworkName <String>] [-AddressPrefix <String>]
46-
[-SubnetName <String>] [-SubnetAddressPrefix <String>] [-PublicIpAddressName <String>]
47-
[-DomainNameLabel <String>] [-AllocationMethod <String>] [-SecurityGroupName <String>] [-OpenPorts <Int32[]>]
48-
-DiskFile <String> [-Linux] [-Size <String>] [-AvailabilitySetName <String>] [-SystemAssignedIdentity]
49-
[-UserAssignedIdentity <String>] [-AsJob] [-OSDiskDeleteOption <String>] [-DataDiskSizeInGb <Int32[]>]
50-
[-DataDiskDeleteOption <String>] [-EnableUltraSSD] [-ProximityPlacementGroupId <String>] [-HostId <String>]
51-
[-VmssId <String>] [-Priority <String>] [-EvictionPolicy <String>] [-MaxPrice <Double>] [-EncryptionAtHost]
44+
New-AzVM [[-ResourceGroupName] <String>] [[-Location] <String>] [-EdgeZone <String>] [-PublicIpSku <String>]
45+
-Name <String> [-NetworkInterfaceDeleteOption <String>] [-VirtualNetworkName <String>]
46+
[-AddressPrefix <String>] [-SubnetName <String>] [-SubnetAddressPrefix <String>]
47+
[-PublicIpAddressName <String>] [-DomainNameLabel <String>] [-AllocationMethod <String>]
48+
[-SecurityGroupName <String>] [-OpenPorts <Int32[]>] -DiskFile <String> [-Linux] [-Size <String>]
49+
[-AvailabilitySetName <String>] [-SystemAssignedIdentity] [-UserAssignedIdentity <String>] [-AsJob]
50+
[-OSDiskDeleteOption <String>] [-DataDiskSizeInGb <Int32[]>] [-DataDiskDeleteOption <String>]
51+
[-EnableUltraSSD] [-ProximityPlacementGroupId <String>] [-HostId <String>] [-VmssId <String>]
52+
[-Priority <String>] [-EvictionPolicy <String>] [-MaxPrice <Double>] [-EncryptionAtHost]
5253
[-HostGroupId <String>] [-CapacityReservationGroupId <String>] [-UserData <String>]
5354
[-PlatformFaultDomain <Int32>] [-HibernationEnabled] [-vCPUCountAvailable <Int32>] [-vCPUCountPerCore <Int32>]
5455
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
@@ -860,6 +861,23 @@ Accept pipeline input: False
860861
Accept wildcard characters: False
861862
```
862863

864+
### -PublicIpSku
865+
Specifies public IP sku name
866+
867+
Accpeted Values are "Basic" and "Standard"
868+
869+
```yaml
870+
Type: System.String
871+
Parameter Sets: SimpleParameterSet, DiskFileParameterSet
872+
Aliases:
873+
874+
Required: False
875+
Position: Named
876+
Default value: None
877+
Accept pipeline input: False
878+
Accept wildcard characters: False
879+
```
880+
863881
### -ResourceGroupName
864882
Specifies the name of a resource group.
865883

src/RecoveryServices/RecoveryServices.Backup.Test/RecoveryServices.Backup.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<PackageReference Include="Microsoft.Azure.Management.Network" Version="23.0.0" />
1515
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="56.0.0" />
1616
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices" Version="4.3.3-preview" />
17-
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="5.0.0-preview" />
17+
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="5.0.0-preview" />
1818
</ItemGroup>
1919

2020
<ItemGroup>

0 commit comments

Comments
 (0)