Skip to content

New-AzVm cmdlet dev and test work #12595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,5 +311,12 @@ public void TestSetAzVMOperatingSystemError()
{
TestRunner.RunTestScript("Test-SetAzVMOperatingSystemError");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestHostGroupPropertySetOnVirtualMachine()
{
TestRunner.RunTestScript("Test-HostGroupPropertySetOnVirtualMachine");
}
}
}
44 changes: 44 additions & 0 deletions src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4171,3 +4171,47 @@ function Test-SetAzVMOperatingSystemError
}
}

<#
.SYNOPSIS
Test HostGroup property is set on a VM correctly when HostGroup.Id is passed as a parameter.
#>
function Test-HostGroupPropertySetOnVirtualMachine
{
# Setup
$rgname = Get-ComputeTestResourceName

try
{
# Common
[string]$loc = Get-Location "Microsoft.Resources" "resourceGroups" "East US 2 EUAP";
$loc = $loc.Replace(' ', '');

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

# Create a VM first
$hostGroupName = $rgname + 'hostgroup'
$hostGroup = New-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName -Location $loc -PlatformFaultDomain 2 -Zone "2";

$hostName = $rgname + 'host'
New-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName -Location $loc -Sku "ESv3-Type1" -PlatformFaultDomain 1;

# VM Profile & Hardware
$vmsize = 'Standard_E2s_v3';
$vmname0 = 'v' + $rgname;

# Creating a VM using simple parameter set
$username = "admin01"
$password = Get-PasswordForVM | ConvertTo-SecureString -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password

$vm0 = New-AzVM -ResourceGroupName $rgname -Location $loc -Name $vmname0 -Credential $cred -Zone "2" -Size $vmsize -HostGroupId $hostGroup.Id;

Assert-AreEqual $hostGroup.Id $vm0.HostGroup.Id;
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

1 change: 1 addition & 0 deletions src/Compute/Compute/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* Added '-EncryptionAtHost' parameter to New-AzVm, New-AzVmss, New-AzVMConfig, New-AzVmssConfig, Update-AzVM, and Update-AzVmss
* Added 'SecurityProfile' to Get-AzVM and Get-AzVmss return object
* Added the '-InstanceView' switch as optional parameter to Get-AzHostGroup
* Added the '-HostGroupId' parameter to New-AzVm.

## Version 4.2.1
* Added warning when using `New-AzVmss` without "latest" image version
Expand Down
3 changes: 3 additions & 0 deletions src/Compute/Compute/Models/PSVirtualMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,8 @@ public string ResourceGroupName

// Gets or sets the Priority
public string Priority { get; set; }

// Gets or sets the HostGroup
public SubResource HostGroup { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static ResourceConfig<VirtualMachine> CreateVirtualMachineConfig(
bool ultraSSDEnabled,
Func<IEngine, SubResource> proximityPlacementGroup,
string hostId,
string hostGroupId,
string priority,
string evictionPolicy,
double? maxPrice,
Expand Down Expand Up @@ -94,6 +95,7 @@ public static ResourceConfig<VirtualMachine> CreateVirtualMachineConfig(
AdditionalCapabilities = ultraSSDEnabled ? new AdditionalCapabilities(true) : null,
ProximityPlacementGroup = proximityPlacementGroup(engine),
Host = string.IsNullOrEmpty(hostId) ? null : new SubResource(hostId),
HostGroup = string.IsNullOrEmpty(hostId) ? null : new SubResource(hostGroupId),
Priority = priority,
EvictionPolicy = evictionPolicy,
BillingProfile = (maxPrice == null) ? null : new BillingProfile(maxPrice),
Expand All @@ -114,6 +116,7 @@ public static ResourceConfig<VirtualMachine> CreateVirtualMachineConfig(
bool ultraSSDEnabled,
Func<IEngine, SubResource> proximityPlacementGroup,
string hostId,
string hostGroupId,
string priority,
string evictionPolicy,
double? maxPrice,
Expand Down Expand Up @@ -152,6 +155,7 @@ public static ResourceConfig<VirtualMachine> CreateVirtualMachineConfig(
AdditionalCapabilities = ultraSSDEnabled ? new AdditionalCapabilities(true) : null,
ProximityPlacementGroup = proximityPlacementGroup(engine),
Host = string.IsNullOrEmpty(hostId) ? null : new SubResource(hostId),
HostGroup = string.IsNullOrEmpty(hostId) ? null : new SubResource(hostGroupId),
Priority = priority,
EvictionPolicy = evictionPolicy,
BillingProfile = (maxPrice == null) ? null : new BillingProfile(maxPrice),
Expand Down
10 changes: 10 additions & 0 deletions src/Compute/Compute/VirtualMachine/Operation/NewAzureVMCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ public class NewAzureVMCommand : VirtualMachineBaseCmdlet
[Parameter(ParameterSetName = DiskFileParameterSet, Mandatory = false,
HelpMessage = "EncryptionAtHost property can be used by user in the request to enable or disable the Host Encryption for the virtual machine. This will enable the encryption for all the disks including Resource/Temp disk at host itself.")]
public SwitchParameter EncryptionAtHost { get; set; } = false;

[Parameter(ParameterSetName = SimpleParameterSet, Mandatory = false,
HelpMessage = "The resource id of the dedicated host group, on which the customer wants their VM placed using automatic placement.",
ValueFromPipelineByPropertyName = true)]
[Parameter(ParameterSetName = DiskFileParameterSet, Mandatory = false,
HelpMessage = "The resource id of the dedicated host group, on which the customer wants their VM placed using automatic placement.",
ValueFromPipelineByPropertyName = true)]
public string HostGroupId { get; set; }

public override void ExecuteCmdlet()
{
Expand Down Expand Up @@ -392,6 +400,7 @@ public async Task<ResourceConfig<VirtualMachine>> CreateConfigAsync()
identity: _cmdlet.GetVMIdentityFromArgs(),
proximityPlacementGroup: ppgSubResourceFunc,
hostId: _cmdlet.HostId,
hostGroupId: _cmdlet.HostGroupId,
priority: _cmdlet.Priority,
evictionPolicy: _cmdlet.EvictionPolicy,
maxPrice: _cmdlet.IsParameterBound(c => c.MaxPrice) ? _cmdlet.MaxPrice : (double?)null,
Expand All @@ -417,6 +426,7 @@ public async Task<ResourceConfig<VirtualMachine>> CreateConfigAsync()
identity: _cmdlet.GetVMIdentityFromArgs(),
proximityPlacementGroup: ppgSubResourceFunc,
hostId: _cmdlet.HostId,
hostGroupId: _cmdlet.HostGroupId,
priority: _cmdlet.Priority,
evictionPolicy: _cmdlet.EvictionPolicy,
maxPrice: _cmdlet.IsParameterBound(c => c.MaxPrice) ? _cmdlet.MaxPrice : (double?)null,
Expand Down