Skip to content

Commit 3ed267b

Browse files
handle exception
1 parent 54a26f7 commit 3ed267b

File tree

6 files changed

+64
-7
lines changed

6 files changed

+64
-7
lines changed

src/ResourceManager/Common/Commands.Common.Strategies/SyncTaskScheduler.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public void Wait(Task task)
4747
Thread.Yield();
4848
}
4949
HandleActions();
50+
if (task.IsFaulted)
51+
{
52+
throw task.Exception.InnerException;
53+
}
5054
}
5155

5256
void HandleActions()

src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachine.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,7 @@ public string ResourceGroupName
9898

9999
// Gets or sets the virtual machine zones.
100100
public IList<string> Zones { get; set; }
101+
102+
public string Fqdn { get; set; }
101103
}
102104
}

src/ResourceManager/Compute/Commands.Compute/Strategies/AsyncCmdletExtensions.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
using Microsoft.Azure.Commands.Common.Strategies;
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.Commands.Common.Strategies;
216
using System;
317
using System.Management.Automation;
418
using System.Threading.Tasks;
@@ -34,6 +48,9 @@ public void WriteVerbose(string message)
3448

3549
public Task<bool> ShouldProcessAsync(string target, string action)
3650
=> Scheduler.Invoke(() => _Cmdlet.ShouldProcess(target, action));
51+
52+
public void WriteObject(object value)
53+
=> Scheduler.BeginInvoke(() => _Cmdlet.WriteObject(value));
3754
}
3855
}
3956
}

src/ResourceManager/Compute/Commands.Compute/Strategies/Client.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
using Microsoft.Azure.Commands.Common.Authentication;
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.Commands.Common.Authentication;
216
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
317
using Microsoft.Azure.Commands.Common.Strategies;
418
using Microsoft.Rest;
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
using System.Threading.Tasks;
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 System.Threading.Tasks;
216

317
namespace Microsoft.Azure.Commands.Compute.Strategies
418
{
@@ -7,5 +21,7 @@ interface IAsyncCmdlet
721
void WriteVerbose(string message);
822

923
Task<bool> ShouldProcessAsync(string target, string action);
24+
25+
void WriteObject(object value);
1026
}
1127
}

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/NewAzureVMCommand.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace Microsoft.Azure.Commands.Compute
4949
ProfileNouns.VirtualMachine,
5050
SupportsShouldProcess = true,
5151
DefaultParameterSetName = "DefaultParameterSet")]
52-
[OutputType(typeof(PSAzureOperationResponse))]
52+
[OutputType(typeof(PSAzureOperationResponse), typeof(PSVirtualMachine))]
5353
public class NewAzureVMCommand : VirtualMachineBaseCmdlet
5454
{
5555
public const string DefaultParameterSet = "DefaultParameterSet";
@@ -210,8 +210,9 @@ async Task StrategyExecuteCmdletAsync(IAsyncCmdlet asyncCmdlet)
210210
adminPassword: new NetworkCredential(string.Empty, Credential.Password).Password,
211211
image: image.Image);
212212

213-
// get state
214213
var client = new Client(DefaultProfile.DefaultContext);
214+
215+
// get current Azure state
215216
var current = await virtualMachine.GetStateAsync(client, new CancellationToken());
216217

217218
if (Location == null)
@@ -227,14 +228,17 @@ async Task StrategyExecuteCmdletAsync(IAsyncCmdlet asyncCmdlet)
227228
var target = virtualMachine.GetTargetState(current, client.SubscriptionId, Location);
228229

229230
// apply target state
230-
var result = await virtualMachine
231+
var newState = await virtualMachine
231232
.UpdateStateAsync(
232233
client,
233234
target,
234235
new CancellationToken(),
235236
new ShouldProcess(asyncCmdlet),
236237
new ProgressReport(asyncCmdlet));
237-
WriteObject(result);
238+
239+
var result = newState.Get(virtualMachine);
240+
var psResult = ComputeAutoMapperProfile.Mapper.Map<PSVirtualMachine>(result);
241+
asyncCmdlet.WriteObject(psResult);
238242
}
239243

240244
public void DefaultExecuteCmdlet()

0 commit comments

Comments
 (0)