Skip to content

Commit 1eb322b

Browse files
SandidoVeryEarly
andauthored
PatchMode and PatchStatus parameters added to Set-AzVMOperatingSystem, and also 2020-12-01 functionality (#14186)
* initial uptake of .net sdk pkg 44 * uefi build error * removed container service test * dev patchmode * enablehotpatch dev and changelog * cleanup * help doc and small edit * initial test, still fails * patchmode and hotpatch test windows * final containerservice .md file removed * omode test update * Create BreakingChangeIssues.csv * linux patchmode test * update test * proj version updates * changelog breaking change description * removed AutoByPlat check per feedback * weird csproj addition removed Co-authored-by: Yabo Hu <[email protected]>
1 parent 78af49e commit 1eb322b

File tree

19 files changed

+4199
-1293
lines changed

19 files changed

+4199
-1293
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="43.0.0-preview" />
15+
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="44.0.0" />
1616
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="3.1.0-preview.2" />
1717
<PackageReference Include="Microsoft.Azure.Management.Network" Version="20.3.0" />
1818
</ItemGroup>

src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,5 +367,12 @@ public void TestVirtualMachineGetVMExtensionPiping()
367367
{
368368
TestRunner.RunTestScript("Test-VirtualMachineGetVMExtensionPiping");
369369
}
370+
371+
[Fact]
372+
[Trait(Category.AcceptanceType, Category.CheckIn)]
373+
public void TestVirtualMachinePatchAPI()
374+
{
375+
TestRunner.RunTestScript("Test-VirtualMachinePatchAPI");
376+
}
370377
}
371378
}

src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4565,4 +4565,56 @@ function Test-VirtualMachineGetVMExtensionPiping
45654565
# Cleanup
45664566
Clean-ResourceGroup $rgname;
45674567
}
4568+
}
4569+
4570+
<#
4571+
.SYNOPSIS
4572+
Windows machine enable hot patching, linux machines patchmode
4573+
#>
4574+
function Test-VirtualMachinePatchAPI
4575+
{
4576+
# Setup
4577+
$rgname = Get-ComputeTestResourceName;
4578+
$loc = Get-ComputeVMLocation;
4579+
4580+
try
4581+
{
4582+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
4583+
4584+
# VM Profile & Hardware
4585+
$vmsize = 'Standard_E2s_v3';
4586+
$vmname0 = 'v' + $rgname;
4587+
4588+
# Creating a VM using simple parameter set
4589+
$username = "admin01";
4590+
$password = Get-PasswordForVM | ConvertTo-SecureString -AsPlainText -Force;
4591+
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password;
4592+
[string]$domainNameLabel = "d"+ $rgname;
4593+
$computerName = 'test';
4594+
$patchMode = "AutomaticByPlatform";
4595+
4596+
# EnableHotPatching for Windows machine.
4597+
$vm0 = New-AzVM -ResourceGroupName $rgname -Location $loc -Name $vmname0 -Credential $cred -Zone "2" -Size $vmsize -DomainNameLabel $domainNameLabel;
4598+
$p = Set-AzVMOperatingSystem -VM $vm0 -Windows -ComputerName $computerName -Credential $cred -EnableHotpatching -PatchMode $patchMode;
4599+
Assert-True {$vm0.OSProfile.WindowsConfiguration.PatchSettings.EnableHotpatching};
4600+
Assert-AreEqual $vm0.OSProfile.WindowsConfiguration.PatchSettings.PatchMode $patchMode;
4601+
4602+
# Test Linux VM PatchMode scenario.
4603+
# This currently requires creating a Linux (Ubuntu) VM manually in the Azure Portal as the DefaultCRPLinuxImageOffline cmd uses a
4604+
# storage account that Compute does not currently support.
4605+
$rgname2 = "adamddeast";
4606+
$vmname = "linuxtest";
4607+
$linuxvm = Get-AzVM -ResourceGroupName $rgname2 -Name $vmname;
4608+
$securePassword = Get-PasswordForVM | ConvertTo-SecureString -AsPlainText -Force;
4609+
$user = "usertest";
4610+
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
4611+
$vmset = Set-AzVMOperatingSystem -VM $linuxvm -Linux -ComputerName $computerName -Credential $cred -PatchMode $patchMode;
4612+
4613+
Assert-AreEqual $linuxvm.OSProfile.LinuxConfiguration.PatchSettings.PatchMode $patchMode;
4614+
}
4615+
finally
4616+
{
4617+
# Cleanup
4618+
Clean-ResourceGroup $rgname
4619+
}
45684620
}

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineScaleSetTests/TestVirtualMachineScaleSetOrchestrationVM.json

Lines changed: 1140 additions & 1262 deletions
Large diffs are not rendered by default.

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineTests/TestVirtualMachinePatchAPI.json

Lines changed: 2853 additions & 0 deletions
Large diffs are not rendered by default.

src/Compute/Compute.sln

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ Global
4848
{142D7B0B-388A-4CEB-A228-7F6D423C5C2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
4949
{142D7B0B-388A-4CEB-A228-7F6D423C5C2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
5050
{142D7B0B-388A-4CEB-A228-7F6D423C5C2E}.Release|Any CPU.Build.0 = Release|Any CPU
51+
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
52+
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Debug|Any CPU.Build.0 = Debug|Any CPU
53+
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Release|Any CPU.ActiveCfg = Release|Any CPU
54+
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Release|Any CPU.Build.0 = Release|Any CPU
5155
{9FFC40CC-A341-4D0C-A25D-DC6B78EF6C94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
5256
{9FFC40CC-A341-4D0C-A25D-DC6B78EF6C94}.Debug|Any CPU.Build.0 = Debug|Any CPU
5357
{9FFC40CC-A341-4D0C-A25D-DC6B78EF6C94}.Release|Any CPU.ActiveCfg = Release|Any CPU

src/Compute/Compute/ChangeLog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@
2020
2121
-->
2222
## Upcoming Release
23+
* Added parameter `-EnableHotpatching` to the `Set-AzVMOperatingSystem` cmdlet for Windows machines.
24+
* Added parameter `-PatchMode` to the Linux parameter sets in the cmdlet `Set-AzVMOperatingSystem`.
25+
* [Breaking Change] Breaking changes for users in the public preview for the VM Guest Patching feature.
26+
- Removed property `RebootStatus` from the `Microsoft.Azure.Management.Compute.Models.LastPatchInstallationSummary` object.
27+
- Removed property `StartedBy` from the `Microsoft.Azure.Management.Compute.Models.LastPatchInstallationSummary` object.
28+
- Renamed property `Kbid` to `KbId` in the `Microsoft.Azure.Management.Compute.Models.VirtualMachineSoftwarePatchProperties` object.
29+
- Renamed property `patches` to `availablePatches` in the `Microsoft.Azure.Management.Compute.Models.VirtualMachineAssessPatchesResult` object.
30+
- Renamed object `Microsoft.Azure.Management.Compute.Models.SoftwareUpdateRebootBehavior` to `Microsoft.Azure.Management.Compute.Models.VMGuestPatchRebootBehavior`.
31+
- Renamed object `Microsoft.Azure.Management.Compute.Models.InGuestPatchMode` to `Microsoft.Azure.Management.Compute.Models.WindowsVMGuestPatchMode`.
2332
* [Breaking Change] Removed all `ContainerService` cmdlets. The Container Service API was deprecated in January 2020.
2433
- `Add-AzContainerServiceAgentPoolProfile`
2534
- `Get-AzContainerService`

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="43.0.0-preview" />
16+
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="44.0.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" />

src/Compute/Compute/Generated/ComputeAutomationBaseCmdlet.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,6 @@ protected static object[] ConvertFromArgumentsToObjects(object[] arguments)
8282
return objects;
8383
}
8484

85-
public IContainerServicesOperations ContainerServicesClient
86-
{
87-
get
88-
{
89-
return ComputeClient.ComputeManagementClient.ContainerServices;
90-
}
91-
}
92-
9385
public IDedicatedHostGroupsOperations DedicatedHostGroupsClient
9486
{
9587
get

src/Compute/Compute/Generated/VirtualMachineScaleSet/Config/NewAzureRmVmssConfigCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ private void Run()
640640
ProximityPlacementGroup = vProximityPlacementGroup,
641641
AdditionalCapabilities = vAdditionalCapabilities,
642642
ScaleInPolicy = vScaleInPolicy,
643-
Identity = vIdentity,
643+
Identity = vIdentity
644644
};
645645

646646
WriteObject(vVirtualMachineScaleSet);

src/Compute/Compute/Strategies/ComputeRp/VirtualMachineScaleSetStrategy.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ internal static ResourceConfig<VirtualMachineScaleSet> CreateVirtualMachineScale
6262
string[] scaleInPolicy,
6363
bool doNotRunExtensionsOnOverprovisionedVMs,
6464
bool encryptionAtHost,
65-
int? platformFaultDomainCount)
65+
int? platformFaultDomainCount
66+
)
6667
=> Strategy.CreateResourceConfig(
6768
resourceGroup: resourceGroup,
6869
name: name,
@@ -84,7 +85,7 @@ internal static ResourceConfig<VirtualMachineScaleSet> CreateVirtualMachineScale
8485
PlatformFaultDomainCount = platformFaultDomainCount,
8586
VirtualMachineProfile = new VirtualMachineScaleSetVMProfile
8687
{
87-
SecurityProfile = (encryptionAtHost == true) ? new SecurityProfile(encryptionAtHost) : null,
88+
SecurityProfile = (encryptionAtHost == true) ? new SecurityProfile(encryptionAtHost: encryptionAtHost) : null,
8889
OsProfile = new VirtualMachineScaleSetOSProfile
8990
{
9091
ComputerNamePrefix = name.Substring(0, Math.Min(name.Length, 9)),

src/Compute/Compute/Strategies/ComputeRp/VirtualMachineStrategy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static ResourceConfig<VirtualMachine> CreateVirtualMachineConfig(
101101
Priority = priority,
102102
EvictionPolicy = evictionPolicy,
103103
BillingProfile = (maxPrice == null) ? null : new BillingProfile(maxPrice),
104-
SecurityProfile = (encryptionAtHostPresent == true) ? new SecurityProfile(encryptionAtHostPresent) : null
104+
SecurityProfile = (encryptionAtHostPresent == true) ? new SecurityProfile(encryptionAtHost: encryptionAtHostPresent) : null
105105
});
106106

107107
public static ResourceConfig<VirtualMachine> CreateVirtualMachineConfig(
@@ -163,7 +163,7 @@ bool encryptionAtHostPresent
163163
Priority = priority,
164164
EvictionPolicy = evictionPolicy,
165165
BillingProfile = (maxPrice == null) ? null : new BillingProfile(maxPrice),
166-
SecurityProfile = (encryptionAtHostPresent == true) ? new SecurityProfile(encryptionAtHostPresent) : null
166+
SecurityProfile = (encryptionAtHostPresent == true) ? new SecurityProfile(encryptionAtHost: encryptionAtHostPresent) : null
167167
});
168168
}
169169
}

src/Compute/Compute/VirtualMachine/Config/SetAzureVMOperatingSystemCommand.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,31 @@ public class SetAzureVMOperatingSystemCommand : Microsoft.Azure.Commands.Resourc
245245
ParameterSetName = WindowsDisableVMAgentWinRmHttpsParamSet,
246246
ValueFromPipelineByPropertyName = true,
247247
HelpMessage = "Choose one of the following settings: 'Manual', 'AutomaticByOS', or 'AutomaticByPlatform'")]
248-
[ValidateNotNullOrEmpty]
248+
[Parameter(
249+
ParameterSetName = LinuxParamSet,
250+
ValueFromPipelineByPropertyName = true,
251+
HelpMessage = "Choose one of the following settings: 'Manual', 'AutomaticByOS', or 'AutomaticByPlatform'")]
249252
[PSArgumentCompleter("Manual", "AutomaticByOS", "AutomaticByPlatform")]
250253
public string PatchMode { get; set; }
251254

255+
[Parameter(
256+
ParameterSetName = WindowsParamSet,
257+
ValueFromPipelineByPropertyName = true,
258+
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'.")]
259+
[Parameter(
260+
ParameterSetName = WinRmHttpsParamSet,
261+
ValueFromPipelineByPropertyName = true,
262+
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'.")]
263+
[Parameter(
264+
ParameterSetName = WindowsDisableVMAgentParamSet,
265+
ValueFromPipelineByPropertyName = true,
266+
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'.")]
267+
[Parameter(
268+
ParameterSetName = WindowsDisableVMAgentWinRmHttpsParamSet,
269+
ValueFromPipelineByPropertyName = true,
270+
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'.")]
271+
public SwitchParameter EnableHotpatching { get; set; }
272+
252273
// Linux Parameter Sets
253274
[Parameter(
254275
ParameterSetName = LinuxParamSet,
@@ -280,6 +301,16 @@ public override void ExecuteCmdlet()
280301
this.VM.OSProfile.LinuxConfiguration = new LinuxConfiguration();
281302
}
282303

304+
//seting patchmode
305+
if (this.IsParameterBound(c => c.PatchMode))
306+
{
307+
if (this.VM.OSProfile.LinuxConfiguration.PatchSettings == null)
308+
{
309+
this.VM.OSProfile.LinuxConfiguration.PatchSettings = new LinuxPatchSettings();
310+
}
311+
this.VM.OSProfile.LinuxConfiguration.PatchSettings.PatchMode = this.PatchMode;
312+
}
313+
283314
this.VM.OSProfile.LinuxConfiguration.DisablePasswordAuthentication =
284315
(this.DisablePasswordAuthentication.IsPresent)
285316
? (bool?)true
@@ -352,6 +383,13 @@ public override void ExecuteCmdlet()
352383
}
353384
this.VM.OSProfile.WindowsConfiguration.PatchSettings.PatchMode = this.PatchMode;
354385
}
386+
387+
if (this.IsParameterBound(c => c.EnableHotpatching))
388+
{
389+
this.VM.OSProfile.WindowsConfiguration.PatchSettings.EnableHotpatching = this.EnableHotpatching;
390+
}
391+
392+
355393
}
356394

357395
WriteObject(this.VM);

0 commit comments

Comments
 (0)