Skip to content

Commit 376e9cc

Browse files
author
jasper-schneider
committed
Restart/Reimage Batch compute node and set pool OS
1 parent 9e89d66 commit 376e9cc

12 files changed

+368
-0
lines changed

src/ResourceManager/AzureBatch/Commands.Batch/Commands.Batch.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@
154154
<Compile Include="Accounts\NewBatchAccountCommand.cs" />
155155
<Compile Include="Accounts\NewBatchAccountKeyCommand.cs" />
156156
<Compile Include="Accounts\SetBatchAccountCommand.cs" />
157+
<Compile Include="ComputeNodes\ResetBatchComputeNodeCommand.cs" />
158+
<Compile Include="ComputeNodes\RestartBatchComputeNodeCommand.cs" />
157159
<Compile Include="Files\GetBatchNodeFileCommand.cs" />
158160
<Compile Include="Files\GetBatchNodeFileContentCommand.cs" />
159161
<Compile Include="Files\GetBatchRemoteDesktopProtocolFileCommand.cs" />
@@ -190,6 +192,7 @@
190192
<Compile Include="Models\BatchClient.ComputeNodes.cs" />
191193
<Compile Include="Models\BatchClient.JobSchedules.cs" />
192194
<Compile Include="Models\BatchClientParametersBase.cs" />
195+
<Compile Include="Models\ChangeOSVersionParameters.cs" />
193196
<Compile Include="Models\DownloadNodeFileOptions.cs" />
194197
<Compile Include="Models\DownloadRemoteDesktopProtocolFileOptions.cs" />
195198
<Compile Include="Models\JobOperationParameters.cs" />
@@ -241,6 +244,8 @@
241244
<Compile Include="Models.Generated\PSUsageStatistics.cs" />
242245
<Compile Include="Models\PoolResizeParameters.cs" />
243246
<Compile Include="Models\ComputeNodeUserOperationParameters.cs" />
247+
<Compile Include="Models\RebootComputeNodeParameters.cs" />
248+
<Compile Include="Models\ReimageComputeNodeParameters.cs" />
244249
<Compile Include="Models\TaskOperationParameters.cs" />
245250
<Compile Include="Models\ComputeNodeOperationParameters.cs" />
246251
<Compile Include="Models\JobScheduleOperationParameters.cs" />
@@ -249,6 +254,7 @@
249254
<Compile Include="Pools\GetBatchPoolCommand.cs" />
250255
<Compile Include="Pools\NewBatchPoolCommand.cs" />
251256
<Compile Include="Pools\RemoveBatchPoolCommand.cs" />
257+
<Compile Include="Pools\SetBatchPoolOSVersionCommand.cs" />
252258
<Compile Include="Pools\StartBatchPoolResizeCommand.cs" />
253259
<Compile Include="Pools\StopBatchPoolResizeCommand.cs" />
254260
<Compile Include="Pools\TestBatchAutoScaleCommand.cs" />
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
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+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Batch;
16+
using Microsoft.Azure.Batch.Common;
17+
using Microsoft.Azure.Commands.Batch.Models;
18+
using System;
19+
using System.Management.Automation;
20+
using Constants = Microsoft.Azure.Commands.Batch.Utils.Constants;
21+
22+
namespace Microsoft.Azure.Commands.Batch
23+
{
24+
[Cmdlet(VerbsCommon.Reset, Constants.AzureBatchComputeNode, DefaultParameterSetName = Constants.IdParameterSet)]
25+
public class ResetBatchComputeNodeCommand : BatchObjectModelCmdletBase
26+
{
27+
[Parameter(Position = 0, ParameterSetName = Constants.IdParameterSet, Mandatory = true, HelpMessage = "The id of the pool that contains the compute node.")]
28+
[ValidateNotNullOrEmpty]
29+
public string PoolId { get; set; }
30+
31+
[Parameter(Position = 1, ParameterSetName = Constants.IdParameterSet, Mandatory = true, HelpMessage = "The id of the compute node to reimage.")]
32+
[ValidateNotNullOrEmpty]
33+
public string Id { get; set; }
34+
35+
[Parameter(Position = 0, ParameterSetName = Constants.ParentObjectParameterSet, ValueFromPipeline = true)]
36+
[ValidateNotNullOrEmpty]
37+
public PSComputeNode ComputeNode { get; set; }
38+
39+
[Parameter]
40+
[ValidateNotNullOrEmpty]
41+
public ComputeNodeReimageOption? ReimageOption { get; set; }
42+
43+
public override void ExecuteCmdlet()
44+
{
45+
ReimageComputeNodeParameters parameters = new ReimageComputeNodeParameters(this.BatchContext, this.PoolId,
46+
this.Id, this.ComputeNode, this.AdditionalBehaviors)
47+
{
48+
ReimageOption = this.ReimageOption
49+
};
50+
BatchClient.ReimageComputeNode(parameters);
51+
}
52+
}
53+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
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+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Batch;
16+
using Microsoft.Azure.Batch.Common;
17+
using Microsoft.Azure.Commands.Batch.Models;
18+
using System;
19+
using System.Management.Automation;
20+
using Constants = Microsoft.Azure.Commands.Batch.Utils.Constants;
21+
22+
namespace Microsoft.Azure.Commands.Batch
23+
{
24+
[Cmdlet(VerbsLifecycle.Restart, Constants.AzureBatchComputeNode, DefaultParameterSetName = Constants.IdParameterSet)]
25+
public class RestartBatchComputeNodeCommand : BatchObjectModelCmdletBase
26+
{
27+
[Parameter(Position = 0, ParameterSetName = Constants.IdParameterSet, Mandatory = true, HelpMessage = "The id of the pool that contains the compute node.")]
28+
[ValidateNotNullOrEmpty]
29+
public string PoolId { get; set; }
30+
31+
[Parameter(Position = 1, ParameterSetName = Constants.IdParameterSet, Mandatory = true, HelpMessage = "The id of the compute node to reboot.")]
32+
[ValidateNotNullOrEmpty]
33+
public string Id { get; set; }
34+
35+
[Parameter(Position = 0, ParameterSetName = Constants.ParentObjectParameterSet, ValueFromPipeline = true)]
36+
[ValidateNotNullOrEmpty]
37+
public PSComputeNode ComputeNode { get; set; }
38+
39+
[Parameter(Position = 2)]
40+
[ValidateNotNullOrEmpty]
41+
public ComputeNodeRebootOption? RebootOption { get; set; }
42+
43+
public override void ExecuteCmdlet()
44+
{
45+
RebootComputeNodeParameters parameters = new RebootComputeNodeParameters(this.BatchContext, this.PoolId,
46+
this.Id, this.ComputeNode, this.AdditionalBehaviors)
47+
{
48+
RebootOption = this.RebootOption
49+
};
50+
BatchClient.RebootComputeNode(parameters);
51+
}
52+
}
53+
}

src/ResourceManager/AzureBatch/Commands.Batch/Models/BatchClient.ComputeNodes.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,56 @@ public IEnumerable<PSComputeNode> ListComputeNodes(ListComputeNodeOptions option
6969
computeNodes, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount)));
7070
}
7171
}
72+
73+
/// <summary>
74+
/// Reboots the specified compute node.
75+
/// </summary>
76+
/// <param name="parameters">The parameters specifying the compute node to reboot and the reboot option.</param>
77+
public void RebootComputeNode(RebootComputeNodeParameters parameters)
78+
{
79+
if (parameters == null)
80+
{
81+
throw new ArgumentNullException("parameters");
82+
}
83+
84+
string computeNodeId = parameters.ComputeNode == null ? parameters.ComputeNodeId : parameters.ComputeNode.Id;
85+
WriteVerbose(string.Format(Resources.RebootComputeNode, computeNodeId));
86+
87+
if (parameters.ComputeNode != null)
88+
{
89+
parameters.ComputeNode.omObject.Reboot(parameters.RebootOption, parameters.AdditionalBehaviors);
90+
}
91+
else
92+
{
93+
PoolOperations poolOperations = parameters.Context.BatchOMClient.PoolOperations;
94+
poolOperations.Reboot(parameters.PoolId, parameters.ComputeNodeId, parameters.RebootOption, parameters.AdditionalBehaviors);
95+
}
96+
}
97+
98+
99+
/// <summary>
100+
/// Reinstalls the operating system on the specified compute node.
101+
/// </summary>
102+
/// <param name="parameters">The parameters specifying the compute node to reimage and the reimage option.</param>
103+
public void ReimageComputeNode(ReimageComputeNodeParameters parameters)
104+
{
105+
if (parameters == null)
106+
{
107+
throw new ArgumentNullException("parameters");
108+
}
109+
110+
string computeNodeId = parameters.ComputeNode == null ? parameters.ComputeNodeId : parameters.ComputeNode.Id;
111+
WriteVerbose(string.Format(Resources.ReimageComputeNode, computeNodeId));
112+
113+
if (parameters.ComputeNode != null)
114+
{
115+
parameters.ComputeNode.omObject.Reimage(parameters.ReimageOption, parameters.AdditionalBehaviors);
116+
}
117+
else
118+
{
119+
PoolOperations poolOperations = parameters.Context.BatchOMClient.PoolOperations;
120+
poolOperations.Reimage(parameters.PoolId, parameters.ComputeNodeId, parameters.ReimageOption, parameters.AdditionalBehaviors);
121+
}
122+
}
72123
}
73124
}

src/ResourceManager/AzureBatch/Commands.Batch/Models/BatchClient.Pools.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,5 +237,23 @@ public PSAutoScaleEvaluation EvaluateAutoScale(AutoScaleParameters parameters)
237237
AutoScaleEvaluation evaluation = poolOperations.EvaluateAutoScale(poolId, parameters.AutoScaleFormula, parameters.AdditionalBehaviors);
238238
return new PSAutoScaleEvaluation(evaluation);
239239
}
240+
241+
/// <summary>
242+
/// Changes the operating system version of the specified pool.
243+
/// </summary>
244+
/// <param name="parameters">The parameters specifying the pool and target OS version.</param>
245+
public void ChangeOSVersion(ChangeOSVersionParameters parameters)
246+
{
247+
if (parameters == null)
248+
{
249+
throw new ArgumentNullException("parameters");
250+
}
251+
252+
string poolId = parameters.Pool == null ? parameters.PoolId : parameters.Pool.Id;
253+
254+
WriteVerbose(string.Format(Resources.ChangeOSVersion, poolId, parameters.TargetOSVersion));
255+
PoolOperations poolOperations = parameters.Context.BatchOMClient.PoolOperations;
256+
poolOperations.ChangeOSVersion(poolId, parameters.TargetOSVersion, parameters.AdditionalBehaviors);
257+
}
240258
}
241259
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
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+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Batch;
16+
using Microsoft.Azure.Batch.Common;
17+
using System;
18+
using System.Collections.Generic;
19+
20+
namespace Microsoft.Azure.Commands.Batch.Models
21+
{
22+
public class ChangeOSVersionParameters : PoolOperationParameters
23+
{
24+
public ChangeOSVersionParameters(BatchAccountContext context, string poolId, PSCloudPool pool, string targetOSVersion,
25+
IEnumerable<BatchClientBehavior> additionalBehaviors = null) : base(context, poolId, pool, additionalBehaviors)
26+
{
27+
if (string.IsNullOrWhiteSpace(targetOSVersion))
28+
{
29+
throw new ArgumentNullException("targetOSVersion");
30+
}
31+
32+
this.TargetOSVersion = targetOSVersion;
33+
}
34+
35+
/// <summary>
36+
/// The Azure Guest OS version to be installed on the virtual machines in the pool.
37+
/// </summary>
38+
public string TargetOSVersion { get; private set; }
39+
}
40+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
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+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Batch;
16+
using Microsoft.Azure.Batch.Common;
17+
using System;
18+
using System.Collections.Generic;
19+
20+
namespace Microsoft.Azure.Commands.Batch.Models
21+
{
22+
public class RebootComputeNodeParameters : ComputeNodeOperationParameters
23+
{
24+
public RebootComputeNodeParameters(BatchAccountContext context, string poolId, string computeNodeId, PSComputeNode computeNode,
25+
IEnumerable<BatchClientBehavior> additionalBehaviors = null)
26+
: base(context, poolId, computeNodeId, computeNode, additionalBehaviors)
27+
{ }
28+
29+
/// <summary>
30+
/// Specifies when to reboot the node and what to do with currently running tasks.
31+
/// </summary>
32+
public ComputeNodeRebootOption? RebootOption { get; set; }
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
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+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Batch;
16+
using Microsoft.Azure.Batch.Common;
17+
using System;
18+
using System.Collections.Generic;
19+
20+
namespace Microsoft.Azure.Commands.Batch.Models
21+
{
22+
public class ReimageComputeNodeParameters : ComputeNodeOperationParameters
23+
{
24+
public ReimageComputeNodeParameters(BatchAccountContext context, string poolId, string computeNodeId, PSComputeNode computeNode,
25+
IEnumerable<BatchClientBehavior> additionalBehaviors = null)
26+
: base(context, poolId, computeNodeId, computeNode, additionalBehaviors)
27+
{ }
28+
29+
/// <summary>
30+
/// Specifies when to reimage the node and what to do with currently running tasks.
31+
/// </summary>
32+
public ComputeNodeReimageOption? ReimageOption { get; set; }
33+
}
34+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
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+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Batch;
16+
using Microsoft.Azure.Batch.Common;
17+
using Microsoft.Azure.Commands.Batch.Models;
18+
using System;
19+
using System.Management.Automation;
20+
using Constants = Microsoft.Azure.Commands.Batch.Utils.Constants;
21+
22+
namespace Microsoft.Azure.Commands.Batch
23+
{
24+
[Cmdlet(VerbsCommon.Set, Constants.AzureBatchPoolOSVersion)]
25+
public class SetBatchPoolOSVersionCommand : BatchObjectModelCmdletBase
26+
{
27+
[Parameter(Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "The id of the pool.")]
28+
[ValidateNotNullOrEmpty]
29+
public string Id { get; set; }
30+
31+
[Parameter(Position = 1, Mandatory = true, HelpMessage = "The Azure Guest OS version to be installed on the virtual machines in the pool.")]
32+
[ValidateNotNullOrEmpty]
33+
public string TargetOSVersion { get; set; }
34+
35+
public override void ExecuteCmdlet()
36+
{
37+
ChangeOSVersionParameters parameters = new ChangeOSVersionParameters(this.BatchContext, this.Id, null,
38+
this.TargetOSVersion, this.AdditionalBehaviors);
39+
BatchClient.ChangeOSVersion(parameters);
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)