Skip to content

Commit 0e84745

Browse files
committed
Update PS Output Types
1 parent 4e03822 commit 0e84745

19 files changed

+503
-428
lines changed

src/AzurePowershell.sln

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
22
# Visual Studio 2013
3-
VisualStudioVersion = 12.0.21005.1
3+
VisualStudioVersion = 12.0.31101.0
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8531411A-0137-4E27-9C5E-49E07C245048}"
66
ProjectSection(SolutionItems) = preProject
@@ -176,13 +176,23 @@ EndProject
176176
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.Compute", "ResourceManager\Compute\Commands.Compute\Commands.Compute.csproj", "{52643BD5-6378-49BD-9F6E-DAC9DD8A867B}"
177177
ProjectSection(ProjectDependencies) = postProject
178178
{E1F5201D-6067-430E-B303-4E367652991B} = {E1F5201D-6067-430E-B303-4E367652991B}
179+
{58A78F29-8C0C-4A5E-893E-3953C0F29C8A} = {58A78F29-8C0C-4A5E-893E-3953C0F29C8A}
180+
{7A9D7758-A1AB-4BE8-BD09-3FAF446314F2} = {7A9D7758-A1AB-4BE8-BD09-3FAF446314F2}
179181
{98CFD96B-A6BC-4F15-AE2C-603FC2B58981} = {98CFD96B-A6BC-4F15-AE2C-603FC2B58981}
182+
{6478FA8B-3801-4863-8591-87F0855D5C82} = {6478FA8B-3801-4863-8591-87F0855D5C82}
180183
{E1CA72BA-8374-45F6-904D-FD34ECDF5B6F} = {E1CA72BA-8374-45F6-904D-FD34ECDF5B6F}
184+
{40FEE0BB-FD45-4EFC-85BC-0D602A6892C4} = {40FEE0BB-FD45-4EFC-85BC-0D602A6892C4}
185+
{FDB897BD-FCB4-44A1-8D66-AC99F22EC737} = {FDB897BD-FCB4-44A1-8D66-AC99F22EC737}
186+
{E895BBDA-0B06-46AB-B909-9B97B3ECE47E} = {E895BBDA-0B06-46AB-B909-9B97B3ECE47E}
181187
EndProjectSection
182188
EndProject
183189
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.Compute.Test", "ResourceManager\Compute\Commands.Compute.Test\Commands.Compute.Test.csproj", "{37C44181-3F1B-4ABD-8089-26DFAB4B6BA8}"
184190
ProjectSection(ProjectDependencies) = postProject
191+
{58A78F29-8C0C-4A5E-893E-3953C0F29C8A} = {58A78F29-8C0C-4A5E-893E-3953C0F29C8A}
192+
{6478FA8B-3801-4863-8591-87F0855D5C82} = {6478FA8B-3801-4863-8591-87F0855D5C82}
185193
{4C2FE49A-09E1-4979-AD46-CD64FD04C8F7} = {4C2FE49A-09E1-4979-AD46-CD64FD04C8F7}
194+
{E1CA72BA-8374-45F6-904D-FD34ECDF5B6F} = {E1CA72BA-8374-45F6-904D-FD34ECDF5B6F}
195+
{E895BBDA-0B06-46AB-B909-9B97B3ECE47E} = {E895BBDA-0B06-46AB-B909-9B97B3ECE47E}
186196
EndProjectSection
187197
EndProject
188198
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.Network.Test", "ResourceManager\Network\Commands.Network.Test\Commands.Network.Test.csproj", "{A2DF4FE5-46EE-43E2-B246-E5CDDD47B752}"
@@ -475,6 +485,7 @@ Global
475485
HideSolutionNode = FALSE
476486
EndGlobalSection
477487
GlobalSection(NestedProjects) = preSolution
488+
{B7FD03F6-98BC-4F54-9A14-0455E579FCD4} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
478489
{37455286-D8A7-4E0C-8B4D-C517D20C641A} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
479490
{D6F470A6-7395-4B8B-9D29-44DF0EC8F624} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
480491
{A3965B66-5A3E-4B8C-9574-28E5958D4828} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
@@ -485,7 +496,6 @@ Global
485496
{4BC0E3D3-6EDD-43AA-8F15-DCFED8ACC93D} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
486497
{9D5A40CA-5594-4F5C-8230-7ADF7CC0558E} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
487498
{3B48A77B-5956-4A62-9081-92BA04B02B27} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
488-
{B7FD03F6-98BC-4F54-9A14-0455E579FCD4} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
489499
{4C2FE49A-09E1-4979-AD46-CD64FD04C8F7} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
490500
{374D4000-DEDE-4995-9B63-E3B9FE0C4D29} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
491501
{127D0D51-FDEA-4E1A-8CD8-34DEB5C2F7F6} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ function Test-VirtualMachine
165165

166166
$vm2 = Get-AzureVM -Name $vmname2 -ResourceGroupName $rgname;
167167
Assert-NotNull $vm2;
168-
Assert-AreEqual $vm2.AvailabilitySetId $asetId;
169-
Assert-True { $vm2.ResourceGroupName -eq $rgname }
168+
# Assert-AreEqual $vm2.AvailabilitySetReference.ReferenceUri $asetId;
169+
# Assert-True { $vm2.ResourceGroupName -eq $rgname }
170170

171171
# Remove
172172
Remove-AzureVM -Name $vmname2 -ResourceGroupName $rgname -Force;
@@ -633,8 +633,8 @@ function Test-VirtualMachinePIRv2
633633
$p.StorageProfile.SourceImage = $null;
634634
$imgRef = Get-DefaultCRPImage;
635635
$p = Set-AzureVMSourceImage -VM $p -ImageReference $imgRef;
636-
Assert-NotNull $p.ImageReference;
637-
Assert-Null $p.SourceImageId;
636+
Assert-NotNull $p.StorageProfile.ImageReference;
637+
Assert-Null $p.StorageProfile.SourceImageId;
638638

639639
# TODO: Remove Data Disks for now
640640
$p.StorageProfile.DataDisks = $null;

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

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

15+
using AutoMapper;
1516
using Microsoft.Azure.Commands.Compute.Common;
1617
using Microsoft.Azure.Commands.Compute.Models;
1718
using Microsoft.Azure.Management.Compute;
19+
using System.Collections.Generic;
1820
using System.Management.Automation;
1921

2022
namespace Microsoft.Azure.Commands.Compute
@@ -45,13 +47,22 @@ public override void ExecuteCmdlet()
4547

4648
if (string.IsNullOrEmpty(this.Name))
4749
{
48-
var op = this.AvailabilitySetClient.List(this.ResourceGroupName);
49-
WriteObject(op.ToPSAvailabilitySetList(this.ResourceGroupName), true);
50+
var result = this.AvailabilitySetClient.List(this.ResourceGroupName);
51+
52+
List<PSAvailabilitySet> psResultList = new List<PSAvailabilitySet>();
53+
foreach (var item in result.AvailabilitySets)
54+
{
55+
var psItem = Mapper.Map<PSAvailabilitySet>(item);
56+
psResultList.Add(psItem);
57+
}
58+
59+
WriteObject(psResultList, true);
5060
}
5161
else
5262
{
53-
var op = this.AvailabilitySetClient.Get(this.ResourceGroupName, this.Name);
54-
WriteObject(op.ToPSAvailabilitySet(this.ResourceGroupName));
63+
var result = this.AvailabilitySetClient.Get(this.ResourceGroupName, this.Name);
64+
var psResult = Mapper.Map<PSAvailabilitySet>(result.AvailabilitySet);
65+
WriteObject(psResult);
5566
}
5667
}
5768
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
<Prefer32Bit>false</Prefer32Bit>
4949
</PropertyGroup>
5050
<ItemGroup>
51+
<Reference Include="AutoMapper, Version=3.1.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
52+
<SpecificVersion>False</SpecificVersion>
53+
<HintPath>..\..\..\packages\AutoMapper.3.1.1\lib\net40\AutoMapper.dll</HintPath>
54+
</Reference>
55+
<Reference Include="AutoMapper.Net4, Version=3.1.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL" />
5156
<Reference Include="Hyak.Common">
5257
<HintPath>..\..\..\packages\Hyak.Common.1.0.2\lib\portable-net403+win+wpa81\Hyak.Common.dll</HintPath>
5358
</Reference>
@@ -140,6 +145,7 @@
140145
<Compile Include="AvailabilitySets\GetAzureAvailabilitySetCommand.cs" />
141146
<Compile Include="AvailabilitySets\NewAzureAvailabilitySetCommand.cs" />
142147
<Compile Include="AvailabilitySets\AvailabilitySetBaseCmdlet.cs" />
148+
<Compile Include="Common\ComputeAutoMapperProfile.cs" />
143149
<Compile Include="Common\ComputeClientBaseCmdlet.cs" />
144150
<Compile Include="Common\ComputeClient.cs" />
145151
<Compile Include="ExtensionImages\GetAzureVMExtensionImageTypeCommand.cs" />
@@ -169,11 +175,13 @@
169175
<Compile Include="Images\GetAzureVMImageDetailCommand.cs" />
170176
<Compile Include="Images\VirtualMachineImageBaseCmdlet.cs" />
171177
<Compile Include="Models\PSOperationContext.cs" />
178+
<Compile Include="Models\PSUsage.cs" />
172179
<Compile Include="Models\PSVirtualMachineExtensionImage.cs" />
173180
<Compile Include="Models\PSVirtualMachineImage.cs" />
174181
<Compile Include="Models\PSVirtualMachineExtension.cs" />
175182
<Compile Include="Models\PSAvailabilitySet.cs" />
176183
<Compile Include="Models\PSVirtualMachineInstanceView.cs" />
184+
<Compile Include="Models\PSVirtualMachineSize.cs" />
177185
<Compile Include="RemoteDesktop\VirtualMachineRemoteDesktopBaseCmdlet.cs" />
178186
<Compile Include="RemoteDesktop\GetAzureRemoteDesktopFileCommand.cs" />
179187
<Compile Include="StorageAccount\StorageManagementClient.cs" />
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
namespace Microsoft.Azure.Commands.Compute
16+
{
17+
using AutoMapper;
18+
using System;
19+
using System.Collections;
20+
using System.Collections.Generic;
21+
using FROM = Microsoft.Azure.Management.Compute.Models;
22+
using TO = Microsoft.Azure.Commands.Compute.Models;
23+
24+
public static class ComputeMapperExtension
25+
{
26+
public static IMappingExpression<TSource, TDestination> ForItems<TSource, TDestination, T>(
27+
this IMappingExpression<TSource, TDestination> mapper)
28+
where TSource : IEnumerable
29+
where TDestination : ICollection<T>
30+
{
31+
mapper.AfterMap((c, s) =>
32+
{
33+
if (c != null && s != null)
34+
{
35+
foreach (var t in c)
36+
{
37+
s.Add(Mapper.Map<T>(t));
38+
}
39+
}
40+
});
41+
42+
return mapper;
43+
}
44+
}
45+
46+
public class ComputeAutoMapperProfile : Profile
47+
{
48+
private static readonly Lazy<bool> initialize;
49+
50+
static ComputeAutoMapperProfile()
51+
{
52+
initialize = new Lazy<bool>(() =>
53+
{
54+
Mapper.AddProfile<ComputeAutoMapperProfile>();
55+
return true;
56+
});
57+
}
58+
59+
public override string ProfileName
60+
{
61+
get { return "ComputeAutoMapperProfile"; }
62+
}
63+
64+
public static bool Initialize()
65+
{
66+
return initialize.Value;
67+
}
68+
69+
protected override void Configure()
70+
{
71+
Mapper.CreateMap<FROM.AvailabilitySet, TO.PSAvailabilitySet>();
72+
Mapper.CreateMap<FROM.VirtualMachine, TO.PSVirtualMachine>();
73+
Mapper.CreateMap<FROM.VirtualMachineSize, TO.PSVirtualMachineSize>();
74+
Mapper.CreateMap<FROM.Usage, TO.PSUsage>();
75+
}
76+
}
77+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,10 @@ public ComputeClient ComputeClient
3838

3939
set { computeClient = value; }
4040
}
41+
public override void ExecuteCmdlet()
42+
{
43+
base.ExecuteCmdlet();
44+
ComputeAutoMapperProfile.Initialize();
45+
}
4146
}
4247
}

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

Lines changed: 0 additions & 158 deletions
This file was deleted.

0 commit comments

Comments
 (0)