Skip to content

Commit a94d789

Browse files
hyonholeemsJinLei
authored andcommitted
Add Set-AzVmssOrchestrationServiceState cmdlet
1 parent 61052a2 commit a94d789

File tree

9 files changed

+5253
-841
lines changed

9 files changed

+5253
-841
lines changed

src/Compute/Compute.Test/ScenarioTests/VirtualMachineScaleSetTests.ps1

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2322,9 +2322,27 @@ function Test-VirtualMachineScaleSetAutoRepair
23222322
New-AzVmss -ResourceGroupName $rgname -Name $vmssName -VirtualMachineScaleSet $vmss;
23232323

23242324
$vmssResult = Get-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;
2325+
Assert-True { $vmssResult.AutomaticRepairsPolicy.Enabled };
2326+
Assert-AreEqual "PT10S" $vmssResult.AutomaticRepairsPolicy.GracePeriod;
2327+
$vmssInstanceViewResult = Get-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName -InstanceView;
2328+
Assert-AreEqual "AutomaticRepairs" $vmssInstanceViewResult.OrchestrationServices[0].ServiceName;
2329+
Assert-AreEqual "Running" $vmssInstanceViewResult.OrchestrationServices[0].ServiceState;
23252330

2331+
Set-AzVmssOrchestrationServiceState -ResourceGroupName $rgname -VMScaleSetName $vmssName -ServiceName "AutomaticRepairs" -Action "Suspend";
2332+
$vmssResult = Get-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;
23262333
Assert-True { $vmssResult.AutomaticRepairsPolicy.Enabled };
23272334
Assert-AreEqual "PT10S" $vmssResult.AutomaticRepairsPolicy.GracePeriod;
2335+
$vmssInstanceViewResult = Get-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName -InstanceView;
2336+
Assert-AreEqual "AutomaticRepairs" $vmssInstanceViewResult.OrchestrationServices[0].ServiceName;
2337+
Assert-AreEqual "Suspended" $vmssInstanceViewResult.OrchestrationServices[0].ServiceState;
2338+
2339+
$vmssResult | Set-AzVmssOrchestrationServiceState -ServiceName "AutomaticRepairs" -Action "Resume";
2340+
$vmssResult = Get-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;
2341+
Assert-True { $vmssResult.AutomaticRepairsPolicy.Enabled };
2342+
Assert-AreEqual "PT10S" $vmssResult.AutomaticRepairsPolicy.GracePeriod;
2343+
$vmssInstanceViewResult = Get-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName -InstanceView;
2344+
Assert-AreEqual "AutomaticRepairs" $vmssInstanceViewResult.OrchestrationServices[0].ServiceName;
2345+
Assert-AreEqual "Running" $vmssInstanceViewResult.OrchestrationServices[0].ServiceState;
23282346

23292347
Update-AzVmss -ResourceGroupName $rgname -Name $vmssName -EnableAutomaticRepair $false;
23302348

@@ -2339,4 +2357,3 @@ function Test-VirtualMachineScaleSetAutoRepair
23392357
Clean-ResourceGroup $rgname
23402358
}
23412359
}
2342-

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

Lines changed: 4870 additions & 831 deletions
Large diffs are not rendered by default.

src/Compute/Compute.sln

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
2-
# Visual Studio 15
3-
VisualStudioVersion = 15.0.27703.2042
2+
# Visual Studio Version 16
3+
VisualStudioVersion = 16.0.29920.165
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Compute", "Compute\Compute.csproj", "{52643BD5-6378-49BD-9F6E-DAC9DD8A867B}"
66
EndProject
@@ -14,8 +14,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Accounts", "..\Accounts\Acc
1414
EndProject
1515
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KeyVault", "..\KeyVault\KeyVault\KeyVault.csproj", "{9FFC40CC-A341-4D0C-A25D-DC6B78EF6C94}"
1616
EndProject
17-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ManagedServiceIdentity", "..\ManagedServiceIdentity\ManagedServiceIdentity.csproj", "{228EB071-FA04-43B3-95F9-7D76DBF0B850}"
18-
EndProject
1917
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Authentication", "..\Accounts\Authentication\Authentication.csproj", "{FF81DC73-B8EC-4082-8841-4FBF2B16E7CE}"
2018
EndProject
2119
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Authentication.ResourceManager", "..\Accounts\Authentication.ResourceManager\Authentication.ResourceManager.csproj", "{3E016018-D65D-4336-9F64-17DA97783AD0}"
@@ -50,10 +48,6 @@ Global
5048
{9FFC40CC-A341-4D0C-A25D-DC6B78EF6C94}.Debug|Any CPU.Build.0 = Debug|Any CPU
5149
{9FFC40CC-A341-4D0C-A25D-DC6B78EF6C94}.Release|Any CPU.ActiveCfg = Release|Any CPU
5250
{9FFC40CC-A341-4D0C-A25D-DC6B78EF6C94}.Release|Any CPU.Build.0 = Release|Any CPU
53-
{228EB071-FA04-43B3-95F9-7D76DBF0B850}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
54-
{228EB071-FA04-43B3-95F9-7D76DBF0B850}.Debug|Any CPU.Build.0 = Debug|Any CPU
55-
{228EB071-FA04-43B3-95F9-7D76DBF0B850}.Release|Any CPU.ActiveCfg = Release|Any CPU
56-
{228EB071-FA04-43B3-95F9-7D76DBF0B850}.Release|Any CPU.Build.0 = Release|Any CPU
5751
{FF81DC73-B8EC-4082-8841-4FBF2B16E7CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
5852
{FF81DC73-B8EC-4082-8841-4FBF2B16E7CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
5953
{FF81DC73-B8EC-4082-8841-4FBF2B16E7CE}.Release|Any CPU.ActiveCfg = Release|Any CPU

src/Compute/Compute/Az.Compute.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ CmdletsToExport = 'Remove-AzAvailabilitySet', 'Get-AzAvailabilitySet',
167167
'Get-AzHostGroup', 'Remove-AzHostGroup', 'New-AzHost', 'Get-AzHost',
168168
'Remove-AzHost', 'New-AzDiskEncryptionSetConfig',
169169
'New-AzDiskEncryptionSet', 'Get-AzDiskEncryptionSet',
170-
'Remove-AzDiskEncryptionSet', 'Update-AzDiskEncryptionSet'
170+
'Remove-AzDiskEncryptionSet', 'Update-AzDiskEncryptionSet',
171+
'Set-AzVmssOrchestrationServiceState'
171172

172173
# Variables to export from this module
173174
# VariablesToExport = @()

src/Compute/Compute/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
- Additional information about change #1
2020
-->
2121
## Upcoming Release
22+
* Added Set-AzVmssOrchestrationServiceState cmdlet.
23+
* Get-AzVmss with -InstanceView shows OrchestrationService states.
2224

2325
## Version 3.6.0
2426
* Added the following parameters to `New-AzDiskConfig` cmdlet:

src/Compute/Compute/Generated/Models/PSVirtualMachineScaleSetInstanceView.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public partial class PSVirtualMachineScaleSetInstanceView
3030
public VirtualMachineScaleSetInstanceViewStatusesSummary VirtualMachine { get; set; }
3131
public IList<VirtualMachineScaleSetVMExtensionsSummary> Extensions { get; set; }
3232
public IList<InstanceViewStatus> Statuses { get; set; }
33+
public IList<OrchestrationServiceSummary> OrchestrationServices { get; set; }
3334

3435
}
3536
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
//
2+
// Copyright (c) Microsoft and contributors. All rights reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
//
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
// Warning: This code was generated by a tool.
18+
//
19+
// Changes to this file may cause incorrect behavior and will be lost if the
20+
// code is regenerated.
21+
22+
using System;
23+
using System.Collections;
24+
using System.Collections.Generic;
25+
using System.Linq;
26+
using System.Management.Automation;
27+
using Microsoft.Azure.Commands.Compute.Automation.Models;
28+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
29+
using Microsoft.Azure.Management.Compute;
30+
using Microsoft.Azure.Management.Compute.Models;
31+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
32+
33+
namespace Microsoft.Azure.Commands.Compute.Automation
34+
{
35+
[Cmdlet(VerbsCommon.Set, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VmssOrchestrationServiceState", DefaultParameterSetName = "DefaultParameter", SupportsShouldProcess = true)]
36+
[OutputType(typeof(PSOperationStatusResponse))]
37+
public partial class SetAzureRmVmssOrchestrationServiceState : ComputeAutomationBaseCmdlet
38+
{
39+
public override void ExecuteCmdlet()
40+
{
41+
base.ExecuteCmdlet();
42+
ExecuteClientAction(() =>
43+
{
44+
if (ShouldProcess(this.VMScaleSetName, VerbsCommon.Set))
45+
{
46+
string resourceGroupName;
47+
string vmScaleSetName;
48+
switch (this.ParameterSetName)
49+
{
50+
case "ResourceIdParameter":
51+
resourceGroupName = GetResourceGroupName(this.ResourceId);
52+
vmScaleSetName = GetResourceName(this.ResourceId, "Microsoft.Compute/virtualMachineScaleSets");
53+
break;
54+
case "ObjectParameter":
55+
resourceGroupName = GetResourceGroupName(this.InputObject.Id);
56+
vmScaleSetName = GetResourceName(this.InputObject.Id, "Microsoft.Compute/virtualMachineScaleSets");
57+
break;
58+
default:
59+
resourceGroupName = this.ResourceGroupName;
60+
vmScaleSetName = this.VMScaleSetName;
61+
break;
62+
}
63+
64+
OrchestrationServiceStateInput parameters = new OrchestrationServiceStateInput();
65+
parameters.ServiceName = this.ServiceName;
66+
parameters.Action = this.Action;
67+
68+
var result = VirtualMachineScaleSetsClient.SetOrchestrationServiceStateWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, parameters).GetAwaiter().GetResult();
69+
PSOperationStatusResponse output = new PSOperationStatusResponse
70+
{
71+
StartTime = this.StartTime,
72+
EndTime = DateTime.Now
73+
};
74+
75+
if (result != null && result.Request != null && result.Request.RequestUri != null)
76+
{
77+
output.Name = GetOperationIdFromUrlString(result.Request.RequestUri.ToString());
78+
}
79+
80+
WriteObject(output);
81+
}
82+
});
83+
}
84+
85+
[Parameter(
86+
ParameterSetName = "DefaultParameter",
87+
Position = 0,
88+
Mandatory = true,
89+
ValueFromPipelineByPropertyName = true)]
90+
[ResourceGroupCompleter]
91+
public string ResourceGroupName { get; set; }
92+
93+
[Parameter(
94+
ParameterSetName = "DefaultParameter",
95+
Position = 1,
96+
Mandatory = true,
97+
ValueFromPipelineByPropertyName = true)]
98+
[ResourceNameCompleter("Microsoft.Compute/virtualMachineScaleSets", "ResourceGroupName")]
99+
[Alias("Name")]
100+
public string VMScaleSetName { get; set; }
101+
102+
[Parameter(
103+
Position = 2,
104+
Mandatory = true,
105+
ValueFromPipelineByPropertyName = true)]
106+
[PSArgumentCompleter("AutomaticRepairs")]
107+
public string ServiceName { get; set; }
108+
109+
[Parameter(
110+
Position = 3,
111+
Mandatory = true,
112+
ValueFromPipelineByPropertyName = true)]
113+
public string Action { get; set; }
114+
115+
[Parameter(
116+
ParameterSetName = "ResourceIdParameter",
117+
Position = 0,
118+
Mandatory = true,
119+
ValueFromPipelineByPropertyName = true)]
120+
public string ResourceId { get; set; }
121+
122+
[Parameter(
123+
ParameterSetName = "ObjectParameter",
124+
Position = 0,
125+
Mandatory = true,
126+
ValueFromPipeline = true)]
127+
[ValidateNotNullOrEmpty]
128+
public PSVirtualMachineScaleSet InputObject { get; set; }
129+
130+
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
131+
public SwitchParameter AsJob { get; set; }
132+
}
133+
}

src/Compute/Compute/help/Az.Compute.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,9 @@ Sets the virtual machine scale set boot diagnostics profile.
533533
### [Set-AzVmssDiskEncryptionExtension](Set-AzVmssDiskEncryptionExtension.md)
534534
Enables disk encryption on a VM scale set.
535535

536+
### [Set-AzVmssOrchestrationServiceState](Set-AzVmssOrchestrationServiceState.md)
537+
Sets the orchestration service state for the VMSS.
538+
536539
### [Set-AzVmssOsProfile](Set-AzVmssOsProfile.md)
537540
Sets the VMSS operating system profile properties.
538541

0 commit comments

Comments
 (0)