Skip to content
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

PatchMode and PatchStatus parameters added to Set-AzVMOperatingSystem, and also 2020-12-01 functionality #14186

Merged
merged 22 commits into from
Feb 26, 2021
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
2 changes: 1 addition & 1 deletion src/Compute/Compute.Test/Compute.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Graph.RBAC" Version="3.4.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="43.0.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="44.0.0" />
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="3.1.0-preview.2" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="20.3.0" />
</ItemGroup>
Expand Down
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 @@ -367,5 +367,12 @@ public void TestVirtualMachineGetVMExtensionPiping()
{
TestRunner.RunTestScript("Test-VirtualMachineGetVMExtensionPiping");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestVirtualMachinePatchAPI()
{
TestRunner.RunTestScript("Test-VirtualMachinePatchAPI");
}
}
}
52 changes: 52 additions & 0 deletions src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4565,4 +4565,56 @@ function Test-VirtualMachineGetVMExtensionPiping
# Cleanup
Clean-ResourceGroup $rgname;
}
}

<#
.SYNOPSIS
Windows machine enable hot patching, linux machines patchmode
#>
function Test-VirtualMachinePatchAPI
{
# Setup
$rgname = Get-ComputeTestResourceName;
$loc = Get-ComputeVMLocation;

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

# 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;
[string]$domainNameLabel = "d"+ $rgname;
$computerName = 'test';
$patchMode = "AutomaticByPlatform";

# EnableHotPatching for Windows machine.
$vm0 = New-AzVM -ResourceGroupName $rgname -Location $loc -Name $vmname0 -Credential $cred -Zone "2" -Size $vmsize -DomainNameLabel $domainNameLabel;
$p = Set-AzVMOperatingSystem -VM $vm0 -Windows -ComputerName $computerName -Credential $cred -EnableHotpatching -PatchMode $patchMode;
Assert-True {$vm0.OSProfile.WindowsConfiguration.PatchSettings.EnableHotpatching};
Assert-AreEqual $vm0.OSProfile.WindowsConfiguration.PatchSettings.PatchMode $patchMode;

# Test Linux VM PatchMode scenario.
# This currently requires creating a Linux (Ubuntu) VM manually in the Azure Portal as the DefaultCRPLinuxImageOffline cmd uses a
# storage account that Compute does not currently support.
$rgname2 = "adamddeast";
$vmname = "linuxtest";
$linuxvm = Get-AzVM -ResourceGroupName $rgname2 -Name $vmname;
$securePassword = Get-PasswordForVM | ConvertTo-SecureString -AsPlainText -Force;
$user = "usertest";
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
$vmset = Set-AzVMOperatingSystem -VM $linuxvm -Linux -ComputerName $computerName -Credential $cred -PatchMode $patchMode;

Assert-AreEqual $linuxvm.OSProfile.LinuxConfiguration.PatchSettings.PatchMode $patchMode;
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/Compute/Compute.sln
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ Global
{142D7B0B-388A-4CEB-A228-7F6D423C5C2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{142D7B0B-388A-4CEB-A228-7F6D423C5C2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{142D7B0B-388A-4CEB-A228-7F6D423C5C2E}.Release|Any CPU.Build.0 = Release|Any CPU
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Release|Any CPU.Build.0 = Release|Any CPU
{9FFC40CC-A341-4D0C-A25D-DC6B78EF6C94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9FFC40CC-A341-4D0C-A25D-DC6B78EF6C94}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9FFC40CC-A341-4D0C-A25D-DC6B78EF6C94}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
9 changes: 9 additions & 0 deletions src/Compute/Compute/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@

-->
## Upcoming Release
* Added parameter `-EnableHotpatching` to the `Set-AzVMOperatingSystem` cmdlet for Windows machines.
dingmeng-xue marked this conversation as resolved.
Show resolved Hide resolved
* Added parameter `-PatchMode` to the Linux parameter sets in the cmdlet `Set-AzVMOperatingSystem`.
* [Breaking Change] Breaking changes for users in the public preview for the VM Guest Patching feature.
- Removed property `RebootStatus` from the `Microsoft.Azure.Management.Compute.Models.LastPatchInstallationSummary` object.
- Removed property `StartedBy` from the `Microsoft.Azure.Management.Compute.Models.LastPatchInstallationSummary` object.
- Renamed property `Kbid` to `KbId` in the `Microsoft.Azure.Management.Compute.Models.VirtualMachineSoftwarePatchProperties` object.
- Renamed property `patches` to `availablePatches` in the `Microsoft.Azure.Management.Compute.Models.VirtualMachineAssessPatchesResult` object.
- Renamed object `Microsoft.Azure.Management.Compute.Models.SoftwareUpdateRebootBehavior` to `Microsoft.Azure.Management.Compute.Models.VMGuestPatchRebootBehavior`.
- Renamed object `Microsoft.Azure.Management.Compute.Models.InGuestPatchMode` to `Microsoft.Azure.Management.Compute.Models.WindowsVMGuestPatchMode`.
* [Breaking Change] Removed all `ContainerService` cmdlets. The Container Service API was deprecated in January 2020.
- `Add-AzContainerServiceAgentPoolProfile`
- `Get-AzContainerService`
Expand Down
2 changes: 1 addition & 1 deletion src/Compute/Compute/Compute.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<ItemGroup>
<PackageReference Include="AutoMapper" Version="6.2.2" />
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="43.0.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="44.0.0" />
<PackageReference Include="System.Security.Permissions" Version="4.5.0" />
<PackageReference Include="System.ServiceModel.Primitives" Version="4.4.1" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.0" />
Expand Down
8 changes: 0 additions & 8 deletions src/Compute/Compute/Generated/ComputeAutomationBaseCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,6 @@ protected static object[] ConvertFromArgumentsToObjects(object[] arguments)
return objects;
}

public IContainerServicesOperations ContainerServicesClient
{
get
{
return ComputeClient.ComputeManagementClient.ContainerServices;
}
}

public IDedicatedHostGroupsOperations DedicatedHostGroupsClient
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ private void Run()
ProximityPlacementGroup = vProximityPlacementGroup,
AdditionalCapabilities = vAdditionalCapabilities,
ScaleInPolicy = vScaleInPolicy,
Identity = vIdentity,
Identity = vIdentity
};

WriteObject(vVirtualMachineScaleSet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ internal static ResourceConfig<VirtualMachineScaleSet> CreateVirtualMachineScale
string[] scaleInPolicy,
bool doNotRunExtensionsOnOverprovisionedVMs,
bool encryptionAtHost,
int? platformFaultDomainCount)
int? platformFaultDomainCount
)
=> Strategy.CreateResourceConfig(
resourceGroup: resourceGroup,
name: name,
Expand All @@ -84,7 +85,7 @@ internal static ResourceConfig<VirtualMachineScaleSet> CreateVirtualMachineScale
PlatformFaultDomainCount = platformFaultDomainCount,
VirtualMachineProfile = new VirtualMachineScaleSetVMProfile
{
SecurityProfile = (encryptionAtHost == true) ? new SecurityProfile(encryptionAtHost) : null,
SecurityProfile = (encryptionAtHost == true) ? new SecurityProfile(encryptionAtHost: encryptionAtHost) : null,
OsProfile = new VirtualMachineScaleSetOSProfile
{
ComputerNamePrefix = name.Substring(0, Math.Min(name.Length, 9)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static ResourceConfig<VirtualMachine> CreateVirtualMachineConfig(
Priority = priority,
EvictionPolicy = evictionPolicy,
BillingProfile = (maxPrice == null) ? null : new BillingProfile(maxPrice),
SecurityProfile = (encryptionAtHostPresent == true) ? new SecurityProfile(encryptionAtHostPresent) : null
SecurityProfile = (encryptionAtHostPresent == true) ? new SecurityProfile(encryptionAtHost: encryptionAtHostPresent) : null
});

public static ResourceConfig<VirtualMachine> CreateVirtualMachineConfig(
Expand Down Expand Up @@ -163,7 +163,7 @@ bool encryptionAtHostPresent
Priority = priority,
EvictionPolicy = evictionPolicy,
BillingProfile = (maxPrice == null) ? null : new BillingProfile(maxPrice),
SecurityProfile = (encryptionAtHostPresent == true) ? new SecurityProfile(encryptionAtHostPresent) : null
SecurityProfile = (encryptionAtHostPresent == true) ? new SecurityProfile(encryptionAtHost: encryptionAtHostPresent) : null
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,31 @@ public class SetAzureVMOperatingSystemCommand : Microsoft.Azure.Commands.Resourc
ParameterSetName = WindowsDisableVMAgentWinRmHttpsParamSet,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Choose one of the following settings: 'Manual', 'AutomaticByOS', or 'AutomaticByPlatform'")]
[ValidateNotNullOrEmpty]
[Parameter(
ParameterSetName = LinuxParamSet,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Choose one of the following settings: 'Manual', 'AutomaticByOS', or 'AutomaticByPlatform'")]
[PSArgumentCompleter("Manual", "AutomaticByOS", "AutomaticByPlatform")]
public string PatchMode { get; set; }

[Parameter(
ParameterSetName = WindowsParamSet,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Enables customers to patch their Azure VMs without requiring a reboot. For enableHotpatching, the 'provisionVMAgent' must be set to true and 'patchMode' must be set to 'AutomaticByPlatform'.")]
[Parameter(
ParameterSetName = WinRmHttpsParamSet,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Enables customers to patch their Azure VMs without requiring a reboot. For enableHotpatching, the 'provisionVMAgent' must be set to true and 'patchMode' must be set to 'AutomaticByPlatform'.")]
[Parameter(
ParameterSetName = WindowsDisableVMAgentParamSet,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Enables customers to patch their Azure VMs without requiring a reboot. For enableHotpatching, the 'provisionVMAgent' must be set to true and 'patchMode' must be set to 'AutomaticByPlatform'.")]
[Parameter(
ParameterSetName = WindowsDisableVMAgentWinRmHttpsParamSet,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Enables customers to patch their Azure VMs without requiring a reboot. For enableHotpatching, the 'provisionVMAgent' must be set to true and 'patchMode' must be set to 'AutomaticByPlatform'.")]
public SwitchParameter EnableHotpatching { get; set; }

// Linux Parameter Sets
[Parameter(
ParameterSetName = LinuxParamSet,
Expand Down Expand Up @@ -280,6 +301,16 @@ public override void ExecuteCmdlet()
this.VM.OSProfile.LinuxConfiguration = new LinuxConfiguration();
}

//seting patchmode
if (this.IsParameterBound(c => c.PatchMode))
{
if (this.VM.OSProfile.LinuxConfiguration.PatchSettings == null)
{
this.VM.OSProfile.LinuxConfiguration.PatchSettings = new LinuxPatchSettings();
}
this.VM.OSProfile.LinuxConfiguration.PatchSettings.PatchMode = this.PatchMode;
}

this.VM.OSProfile.LinuxConfiguration.DisablePasswordAuthentication =
(this.DisablePasswordAuthentication.IsPresent)
? (bool?)true
Expand Down Expand Up @@ -352,6 +383,13 @@ public override void ExecuteCmdlet()
}
this.VM.OSProfile.WindowsConfiguration.PatchSettings.PatchMode = this.PatchMode;
}

if (this.IsParameterBound(c => c.EnableHotpatching))
{
this.VM.OSProfile.WindowsConfiguration.PatchSettings.EnableHotpatching = this.EnableHotpatching;
}


}

WriteObject(this.VM);
Expand Down
Loading