Skip to content

Commit f09125d

Browse files
committed
Update PS Output Types & Format for VM/Ext/AVSet Cmdlets
1 parent 93e41fb commit f09125d

13 files changed

+206
-22
lines changed

src/ResourceManager/Compute/Commands.Compute/AvailabilitySets/NewAzureAvailabilitySetCommand.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using AutoMapper;
1516
using Microsoft.Azure.Commands.Compute.Common;
17+
using Microsoft.Azure.Commands.Compute.Models;
1618
using Microsoft.Azure.Management.Compute;
1719
using Microsoft.Azure.Management.Compute.Models;
1820
using System.Management.Automation;
1921

2022
namespace Microsoft.Azure.Commands.Compute
2123
{
2224
[Cmdlet(VerbsCommon.New, ProfileNouns.AvailabilitySet)]
25+
[OutputType(typeof(PSAvailabilitySet))]
2326
public class NewAzureAvailabilitySetCommand : AvailabilitySetBaseCmdlet
2427
{
2528
[Parameter(
@@ -73,11 +76,12 @@ public override void ExecuteCmdlet()
7376
PlatformFaultDomainCount = this.PlatformFaultDomainCount
7477
};
7578

76-
var op = this.AvailabilitySetClient.CreateOrUpdate(
79+
var result = this.AvailabilitySetClient.CreateOrUpdate(
7780
this.ResourceGroupName,
7881
avSetParams);
7982

80-
WriteObject(op);
83+
var psResult = Mapper.Map<PSAvailabilitySet>(result.AvailabilitySet);
84+
WriteObject(psResult);
8185
}
8286
}
8387
}

src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@
164164
<Compile Include="Extension\GetAzureVMExtensionCommand.cs" />
165165
<Compile Include="Images\GetAzureVMImageCommand.cs" />
166166
<Compile Include="Models\HashTableExtensions.cs" />
167+
<Compile Include="Models\PSComputeLongRunningOperation.cs" />
167168
<Compile Include="Models\PSOperation.cs" />
168169
<Compile Include="Extension\VMAccess\GetAzureVMAccessExtension.cs" />
169170
<Compile Include="Extension\VMAccess\RemoveAzureVMAccessExtension.cs" />

src/ResourceManager/Compute/Commands.Compute/Common/ComputeAutoMapperProfile.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ protected override void Configure()
7272
Mapper.CreateMap<FROM.VirtualMachine, TO.PSVirtualMachine>();
7373
Mapper.CreateMap<FROM.VirtualMachineSize, TO.PSVirtualMachineSize>();
7474
Mapper.CreateMap<FROM.Usage, TO.PSUsage>();
75+
76+
Mapper.CreateMap<FROM.ComputeLongRunningOperationResponse, TO.PSComputeLongRunningOperation>();
7577
}
7678
}
7779
}

src/ResourceManager/Compute/Commands.Compute/Extension/RemoveAzureVMExtensionCommand.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using AutoMapper;
1516
using Microsoft.Azure.Commands.Compute.Common;
17+
using Microsoft.Azure.Commands.Compute.Models;
1618
using Microsoft.Azure.Management.Compute;
17-
using Microsoft.Azure.Management.Compute.Models;
1819
using System.Management.Automation;
1920

2021
namespace Microsoft.Azure.Commands.Compute
2122
{
2223
[Cmdlet(VerbsCommon.Remove, ProfileNouns.VirtualMachineExtension)]
23-
[OutputType(typeof(ComputeLongRunningOperationResponse))]
24+
[OutputType(typeof(PSComputeLongRunningOperation))]
2425
public class RemoveAzureVMExtensionCommand : VirtualMachineExtensionBaseCmdlet
2526
{
2627
[Parameter(
@@ -61,7 +62,8 @@ public override void ExecuteCmdlet()
6162
|| this.ShouldContinue(Properties.Resources.VirtualMachineExtensionRemovalConfirmation, Properties.Resources.VirtualMachineExtensionRemovalCaption))
6263
{
6364
var op = this.VirtualMachineExtensionClient.Delete(this.ResourceGroupName, this.VMName, this.Name);
64-
WriteObject(op);
65+
var result = Mapper.Map<PSComputeLongRunningOperation>(op);
66+
WriteObject(result);
6567
}
6668
}
6769
}

src/ResourceManager/Compute/Commands.Compute/Extension/SetAzureVMExtensionCommand.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using AutoMapper;
1516
using Microsoft.Azure.Commands.Compute.Common;
17+
using Microsoft.Azure.Commands.Compute.Models;
1618
using Microsoft.Azure.Management.Compute;
1719
using Microsoft.Azure.Management.Compute.Models;
1820
using Newtonsoft.Json;
@@ -25,6 +27,7 @@ namespace Microsoft.Azure.Commands.Compute
2527
VerbsCommon.Set,
2628
ProfileNouns.VirtualMachineExtension,
2729
DefaultParameterSetName = SettingsParamSet)]
30+
[OutputType(typeof(PSComputeLongRunningOperation))]
2831
public class SetAzureVMExtensionCommand : VirtualMachineExtensionBaseCmdlet
2932
{
3033
protected const string SettingStringParamSet = "SettingString";
@@ -124,8 +127,6 @@ public override void ExecuteCmdlet()
124127
{
125128
base.ExecuteCmdlet();
126129

127-
128-
129130
if (this.Settings != null)
130131
{
131132
this.SettingString = JsonConvert.SerializeObject(Settings);
@@ -149,7 +150,8 @@ public override void ExecuteCmdlet()
149150
this.VMName,
150151
parameters);
151152

152-
WriteObject(op);
153+
var result = Mapper.Map<PSComputeLongRunningOperation>(op);
154+
WriteObject(result);
153155
}
154156
}
155157
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,93 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Configuration>
33
<ViewDefinitions>
4+
<View>
5+
<Name>Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineInstanceView</Name>
6+
<ViewSelectedBy>
7+
<TypeName>Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineInstanceView</TypeName>
8+
</ViewSelectedBy>
9+
<ListControl>
10+
<ListEntries>
11+
<ListEntry>
12+
<ListItems>
13+
<ListItem>
14+
<Label>ResourceGroupName</Label>
15+
<PropertyName>ResourceGroupName</PropertyName>
16+
</ListItem>
17+
<ListItem>
18+
<Label>Name</Label>
19+
<PropertyName>Name</PropertyName>
20+
</ListItem>
21+
<ListItem>
22+
<Label>Disks</Label>
23+
<PropertyName>DisksText</PropertyName>
24+
</ListItem>
25+
<ListItem>
26+
<Label>Extensions</Label>
27+
<PropertyName>ExtensionsText</PropertyName>
28+
</ListItem>
29+
<ListItem>
30+
<Label>PlatformFaultDomain</Label>
31+
<PropertyName>PlatformFaultDomain</PropertyName>
32+
</ListItem>
33+
<ListItem>
34+
<Label>PlatformUpdateDomain</Label>
35+
<PropertyName>PlatformUpdateDomain</PropertyName>
36+
</ListItem>
37+
<ListItem>
38+
<Label>RemoteDesktopThumbprint</Label>
39+
<PropertyName>RemoteDesktopThumbprint</PropertyName>
40+
</ListItem>
41+
<ListItem>
42+
<Label>VMAgent</Label>
43+
<PropertyName>VMAgentText</PropertyName>
44+
</ListItem>
45+
<ListItem>
46+
<Label>Statuses</Label>
47+
<PropertyName>StatusesText</PropertyName>
48+
</ListItem>
49+
</ListItems>
50+
</ListEntry>
51+
</ListEntries>
52+
</ListControl>
53+
</View>
54+
<View>
55+
<Name>Microsoft.Azure.Commands.Compute.Models.PSComputeLongRunningOperation</Name>
56+
<ViewSelectedBy>
57+
<TypeName>Microsoft.Azure.Commands.Compute.Models.PSComputeLongRunningOperation</TypeName>
58+
</ViewSelectedBy>
59+
<ListControl>
60+
<ListEntries>
61+
<ListEntry>
62+
<ListItems>
63+
<ListItem>
64+
<Label>TrackingOperationId</Label>
65+
<PropertyName>TrackingOperationId</PropertyName>
66+
</ListItem>
67+
<ListItem>
68+
<Label>Status</Label>
69+
<PropertyName>Status</PropertyName>
70+
</ListItem>
71+
<ListItem>
72+
<Label>Output</Label>
73+
<PropertyName>Output</PropertyName>
74+
</ListItem>
75+
<ListItem>
76+
<Label>StartTime</Label>
77+
<PropertyName>StartTime</PropertyName>
78+
</ListItem>
79+
<ListItem>
80+
<Label>EndTime</Label>
81+
<PropertyName>EndTime</PropertyName>
82+
</ListItem>
83+
<ListItem>
84+
<Label>Error</Label>
85+
<PropertyName>ErrorText</PropertyName>
86+
</ListItem>
87+
</ListItems>
88+
</ListEntry>
89+
</ListEntries>
90+
</ListControl>
91+
</View>
492
</ViewDefinitions>
593
</Configuration>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
using Microsoft.Azure.Management.Compute.Models;
18+
using Newtonsoft.Json;
19+
using System;
20+
21+
namespace Microsoft.Azure.Commands.Compute.Models
22+
{
23+
public class PSComputeLongRunningOperation
24+
{
25+
public string TrackingOperationId { get; set; }
26+
27+
public string RequestId { get; set; }
28+
29+
public ComputeOperationStatus Status { get; set; }
30+
31+
public string Output { get; set; }
32+
33+
public DateTimeOffset StartTime { get; set; }
34+
35+
public DateTimeOffset? EndTime { get; set; }
36+
37+
public ApiError Error { get; set; }
38+
39+
[JsonIgnore]
40+
public string ErrorText
41+
{
42+
get { return JsonConvert.SerializeObject(Error, Formatting.Indented); }
43+
}
44+
}
45+
}

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure.Management.Compute.Models;
16-
using System;
16+
using Newtonsoft.Json;
1717
using System.Collections.Generic;
18-
using System.Linq;
1918

2019
namespace Microsoft.Azure.Commands.Compute.Models
2120
{
@@ -27,8 +26,20 @@ public class PSVirtualMachineInstanceView
2726

2827
public IList<DiskInstanceView> Disks { get; set; }
2928

29+
[JsonIgnore]
30+
public string DisksText
31+
{
32+
get { return JsonConvert.SerializeObject(Disks, Formatting.Indented); }
33+
}
34+
3035
public IList<VirtualMachineExtensionInstanceView> Extensions { get; set; }
3136

37+
[JsonIgnore]
38+
public string ExtensionsText
39+
{
40+
get { return JsonConvert.SerializeObject(Extensions, Formatting.Indented); }
41+
}
42+
3243
public int? PlatformFaultDomain { get; set; }
3344

3445
public int? PlatformUpdateDomain { get; set; }
@@ -37,7 +48,19 @@ public class PSVirtualMachineInstanceView
3748

3849
public VirtualMachineAgentInstanceView VMAgent { get; set; }
3950

51+
[JsonIgnore]
52+
public string VMAgentText
53+
{
54+
get { return JsonConvert.SerializeObject(VMAgent, Formatting.Indented); }
55+
}
56+
4057
public IList<InstanceViewStatus> Statuses { get; set; }
58+
59+
[JsonIgnore]
60+
public string StatusesText
61+
{
62+
get { return JsonConvert.SerializeObject(Statuses, Formatting.Indented); }
63+
}
4164
}
4265

4366
public static class PSVirtualMachineInstanceViewExtension

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Action/RestartAzureVMCommand.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using System.Management.Automation;
15+
using AutoMapper;
1616
using Microsoft.Azure.Commands.Compute.Common;
17+
using Microsoft.Azure.Commands.Compute.Models;
1718
using Microsoft.Azure.Management.Compute;
19+
using System.Management.Automation;
1820

1921
namespace Microsoft.Azure.Commands.Compute
2022
{
2123
[Cmdlet(VerbsLifecycle.Restart, ProfileNouns.VirtualMachine)]
24+
[OutputType(typeof(PSComputeLongRunningOperation))]
2225
public class RestartAzureVMCommand : VirtualMachineBaseCmdlet
2326
{
2427
[Parameter(
@@ -40,7 +43,8 @@ public class RestartAzureVMCommand : VirtualMachineBaseCmdlet
4043
public override void ExecuteCmdlet()
4144
{
4245
var op = this.VirtualMachineClient.Restart(this.ResourceGroupName, this.Name);
43-
WriteObject(op);
46+
var result = Mapper.Map<PSComputeLongRunningOperation>(op);
47+
WriteObject(result);
4448
}
4549
}
4650
}

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Action/SaveAzureVMImageCommand.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using AutoMapper;
1516
using Microsoft.Azure.Commands.Compute.Common;
17+
using Microsoft.Azure.Commands.Compute.Models;
1618
using Microsoft.Azure.Management.Compute;
1719
using Microsoft.Azure.Management.Compute.Models;
1820
using System.Management.Automation;
1921

2022
namespace Microsoft.Azure.Commands.Compute
2123
{
2224
[Cmdlet(VerbsData.Save, ProfileNouns.VirtualMachineImage)]
23-
[OutputType(typeof(ComputeLongRunningOperationResponse))]
25+
[OutputType(typeof(PSComputeLongRunningOperation))]
2426
public class SaveAzureVMImageCommand : VirtualMachineBaseCmdlet
2527
{
2628
public string Name { get; set; }
@@ -82,7 +84,8 @@ public override void ExecuteCmdlet()
8284
this.VMName,
8385
parameters);
8486

85-
WriteObject(op);
87+
var result = Mapper.Map<PSComputeLongRunningOperation>(op);
88+
WriteObject(result);
8689
}
8790
}
8891
}

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Action/StartAzureVMCommand.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using System.Management.Automation;
15+
using AutoMapper;
1616
using Microsoft.Azure.Commands.Compute.Common;
17+
using Microsoft.Azure.Commands.Compute.Models;
1718
using Microsoft.Azure.Management.Compute;
19+
using System.Management.Automation;
1820

1921
namespace Microsoft.Azure.Commands.Compute
2022
{
2123
[Cmdlet(VerbsLifecycle.Start, ProfileNouns.VirtualMachine)]
24+
[OutputType(typeof(PSComputeLongRunningOperation))]
2225
public class StartAzureVMCommand : VirtualMachineBaseCmdlet
2326
{
2427
[Parameter(
@@ -40,7 +43,8 @@ public class StartAzureVMCommand : VirtualMachineBaseCmdlet
4043
public override void ExecuteCmdlet()
4144
{
4245
var op = this.VirtualMachineClient.Start(this.ResourceGroupName, this.Name);
43-
WriteObject(op);
46+
var result = Mapper.Map<PSComputeLongRunningOperation>(op);
47+
WriteObject(result);
4448
}
4549
}
4650
}

0 commit comments

Comments
 (0)