Skip to content

Commit

Permalink
Added EdgeZone parameter to resource config cmdlets (#14739)
Browse files Browse the repository at this point in the history
* updated disk,img,snapshot cmdlets for edge zones

* Update DiskRPTests.ps1

cleaned syntax

* adding required defaultparameterset

* addressed Theodore's feedback

* updated the cmdlets

* updated help to match lack of parameterization

* updated test recording

* minor help change

* minor help doc update

Co-authored-by: Andrew Sager <[email protected]>
  • Loading branch information
2 people authored and dingmeng-xue committed May 18, 2021
1 parent bc98285 commit 5007b53
Show file tree
Hide file tree
Showing 12 changed files with 1,193 additions and 35 deletions.
7 changes: 7 additions & 0 deletions src/Compute/Compute.Test/ScenarioTests/DiskRPTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public void TestDisk()
TestRunner.RunTestScript("Test-Disk");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestEdgeZoneConfigurations()
{
TestRunner.RunTestScript("Test-EdgeZoneConfigurations");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSnapshot()
Expand Down
34 changes: 33 additions & 1 deletion src/Compute/Compute.Test/ScenarioTests/DiskRPTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1374,4 +1374,36 @@ function Test-SnapshotDuplicateCreationFails
# Cleanup
Clean-ResourceGroup $rgname
}
}
}

function Test-EdgeZoneConfigurations
{
$rgname = Get-ComputeTestResourceName;
$loc = "eastus2euap";
$edge = "eastus2euapmockedge";

try
{
New-AzResourceGroup -Name $rgname -Location $loc -Force;

$diskconfig = New-AzDiskConfig -Location $loc -EdgeZone $edge -DiskSizeGB 1 -AccountType "Premium_LRS" -OsType "Windows" -CreateOption "Empty" -HyperVGeneration "V1";
$diskname = "disk" + $rgname;
$disk = New-AzDisk -ResourceGroupName $rgname -DiskName $diskname -Disk $diskconfig;
Assert-AreEqual $disk.Location $loc;
Assert-AreEqual $disk.ExtendedLocation.Name $edge;

$snapshotconfig = New-AzSnapshotConfig -Location $loc -EdgeZone $edge -DiskSizeGB 5 -SkuName Premium_LRS -OsType Windows -CreateOption Empty;
$snapshotname = "snapshot" + $rgname
$snapshot = New-AzSnapshot -ResourceGroupName $rgname -SnapshotName $snapshotname -Snapshot $snapshotconfig;
Assert-AreEqual $snapshot.Location $loc;
Assert-AreEqual $snapshot.ExtendedLocation.Name $edge

$imageConfig = New-AzImageConfig -Location $loc -EdgeZone $edge -HyperVGeneration "V1";
Assert-AreEqual $imageConfig.ExtendedLocation.Name $edge
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ public partial class NewAzureRmDiskConfigCommand : Microsoft.Azure.Commands.Reso
[LocationCompleter("Microsoft.Compute/disks")]
public string Location { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Sets the edge zone name. If set, the query will be routed to the specified edgezone instead of the main region.")]
public string EdgeZone { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true)]
Expand Down Expand Up @@ -215,6 +221,9 @@ private void Run()
// Encryption
Encryption vEncryption = null;

// ExtendedLocation
ExtendedLocation vExtendedLocation = null;

if (this.IsParameterBound(c => c.SkuName))
{
if (vSku == null)
Expand Down Expand Up @@ -363,6 +372,11 @@ private void Run()
vEncryption.Type = this.EncryptionType;
}

if (this.IsParameterBound(c => c.EdgeZone))
{
vExtendedLocation = new ExtendedLocation { Name = this.EdgeZone, Type = ExtendedLocationTypes.EdgeZone };
}

var vDisk = new PSDisk
{
Zones = this.IsParameterBound(c => c.Zone) ? this.Zone : null,
Expand All @@ -375,6 +389,7 @@ private void Run()
DiskMBpsReadOnly = this.IsParameterBound(c => c.DiskMBpsReadOnly) ? this.DiskMBpsReadOnly : (long?)null,
MaxShares = this.IsParameterBound(c => c.MaxSharesCount) ? this.MaxSharesCount : (int?)null,
Location = this.IsParameterBound(c => c.Location) ? this.Location : null,
ExtendedLocation = vExtendedLocation,
Tags = this.IsParameterBound(c => c.Tag) ? this.Tag.Cast<DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value) : null,
Sku = vSku,
CreationData = vCreationData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public partial class NewAzureRmImageConfigCommand : Microsoft.Azure.Commands.Res
[LocationCompleter("Microsoft.Compute/images")]
public string Location { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Sets the edge zone name. If set, the query will be routed to the specified edgezone instead of the main region.")]
public string EdgeZone { get; set; }

[Parameter(
Mandatory = false,
Position = 1,
Expand Down Expand Up @@ -91,6 +97,9 @@ private void Run()
// StorageProfile
ImageStorageProfile vStorageProfile = null;

// ExtendedLocation
ExtendedLocation vExtendedLocation = null;

if (this.IsParameterBound(c => c.SourceVirtualMachineId))
{
if (vSourceVirtualMachine == null)
Expand Down Expand Up @@ -124,10 +133,16 @@ private void Run()
}
vStorageProfile.ZoneResilient = this.ZoneResilient.IsPresent;

if (this.IsParameterBound(c => c.EdgeZone))
{
vExtendedLocation = new ExtendedLocation { Name = this.EdgeZone, Type = ExtendedLocationTypes.EdgeZone };
}

var vImage = new PSImage
{
HyperVGeneration = this.IsParameterBound(c => c.HyperVGeneration) ? this.HyperVGeneration : "V1",
Location = this.IsParameterBound(c => c.Location) ? this.Location : null,
ExtendedLocation = vExtendedLocation,
Tags = this.IsParameterBound(c => c.Tag) ? this.Tag.Cast<DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value) : null,
SourceVirtualMachine = vSourceVirtualMachine,
StorageProfile = vStorageProfile,
Expand Down
1 change: 1 addition & 0 deletions src/Compute/Compute/Generated/Models/PSDisk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public string ResourceGroupName
public string Name { get; set; }
public string Type { get; set; }
public string Location { get; set; }
public ExtendedLocation ExtendedLocation { get; set; }
public IDictionary<string, string> Tags { get; set; }
// Gets or sets possible values include: 'AllowAll', 'AllowPrivate', 'DenyAll'
public string NetworkAccessPolicy { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/Compute/Compute/Generated/Models/PSImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public string ResourceGroupName
public string Name { get; set; }
public string Type { get; set; }
public string Location { get; set; }
public ExtendedLocation ExtendedLocation { get; set; }
public IDictionary<string, string> Tags { get; set; }

}
}
1 change: 1 addition & 0 deletions src/Compute/Compute/Generated/Models/PSSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public string ResourceGroupName
public string Name { get; set; }
public string Type { get; set; }
public string Location { get; set; }
public ExtendedLocation ExtendedLocation { get; set; }
public IDictionary<string, string> Tags { get; set; }
// Gets or sets possible values include: 'AllowAll', 'AllowPrivate', 'DenyAll'
public string NetworkAccessPolicy { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public partial class NewAzureRmSnapshotConfigCommand : Microsoft.Azure.Commands.
[LocationCompleter("Microsoft.Compute/snapshots")]
public string Location { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Sets the edge zone name. If set, the query will be routed to the specified edgezone instead of the main region.")]
public string EdgeZone { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true)]
Expand Down Expand Up @@ -162,6 +168,9 @@ private void Run()
// Encryption
Encryption vEncryption = null;

// ExtendedLocation
ExtendedLocation vExtendedLocation = null;

if (this.IsParameterBound(c => c.SkuName))
{
if (vSku == null)
Expand Down Expand Up @@ -283,13 +292,19 @@ private void Run()
vEncryption.Type = this.EncryptionType;
}

if (this.IsParameterBound(c => c.EdgeZone))
{
vExtendedLocation = new ExtendedLocation { Name = this.EdgeZone, Type = ExtendedLocationTypes.EdgeZone };
}

var vSnapshot = new PSSnapshot
{
OsType = this.IsParameterBound(c => c.OsType) ? this.OsType : (OperatingSystemTypes?)null,
HyperVGeneration = this.IsParameterBound(c => c.HyperVGeneration) ? this.HyperVGeneration : null,
DiskSizeGB = this.IsParameterBound(c => c.DiskSizeGB) ? this.DiskSizeGB : (int?)null,
Incremental = this.Incremental.IsPresent,
Location = this.IsParameterBound(c => c.Location) ? this.Location : null,
ExtendedLocation = vExtendedLocation,
Tags = this.IsParameterBound(c => c.Tag) ? this.Tag.Cast<DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value) : null,
Sku = vSku,
CreationData = vCreationData,
Expand Down
21 changes: 18 additions & 3 deletions src/Compute/Compute/help/New-AzDiskConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ Creates a configurable disk object.

```
New-AzDiskConfig [[-SkuName] <String>] [-Tier <String>] [-LogicalSectorSize <Int32>]
[[-OsType] <OperatingSystemTypes>] [[-DiskSizeGB] <Int32>] [[-Location] <String>]
[[-OsType] <OperatingSystemTypes>] [[-DiskSizeGB] <Int32>] [[-Location] <String>] [-EdgeZone <String>]
[-Zone <String[]>] [-HyperVGeneration <String>] [-DiskIOPSReadWrite <Int64>] [-DiskMBpsReadWrite <Int64>]
[-DiskIOPSReadOnly <Int64>] [-DiskMBpsReadOnly <Int64>] [-MaxSharesCount <Int32>] [-Tag <Hashtable>]
[-CreateOption <String>] [-StorageAccountId <String>] [-ImageReference <ImageDiskReference>]
[-GalleryImageReference <ImageDiskReference>] [-SourceUri <String>] [-SourceResourceId <String>]
[-UploadSizeInBytes <Int64>] [-EncryptionSettingsEnabled <Boolean>]
[-DiskEncryptionKey <KeyVaultAndSecretReference>] [-KeyEncryptionKey <KeyVaultAndKeyReference>]
[-DiskEncryptionSetId <String>] [-EncryptionType <String>] [-DiskAccessId <String>]
[-NetworkAccessPolicy <String>] [-BurstingEnabled <Boolean>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
[<CommonParameters>]
[-NetworkAccessPolicy <String>] [-BurstingEnabled <Boolean>] [-DefaultProfile <IAzureContextContainer>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -354,6 +354,21 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -EdgeZone
Sets the edge zone name. If set, the query will be routed to the specified edgezone instead of the main region.
```yaml
Type: System.String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -LogicalSectorSize
Logical sector size in bytes for Ultra disks.
Expand Down
17 changes: 16 additions & 1 deletion src/Compute/Compute/help/New-AzImageConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Creates a configurable image object.
## SYNTAX

```
New-AzImageConfig [[-Location] <String>] [[-Tag] <Hashtable>] [[-SourceVirtualMachineId] <String>]
New-AzImageConfig [[-Location] <String>] [-EdgeZone <String>] [[-Tag] <Hashtable>] [[-SourceVirtualMachineId] <String>]
[[-OsDisk] <ImageOSDisk>] [-HyperVGeneration <String>] [-DataDisk <ImageDataDisk[]>] [-ZoneResilient]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```
Expand Down Expand Up @@ -105,6 +105,21 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -EdgeZone
Sets the edge zone name. If set, the query will be routed to the specified edgezone instead of the main region.
```yaml
Type: System.String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -OsDisk
Specifies the operating system Disk.
Expand Down
Loading

0 comments on commit 5007b53

Please sign in to comment.