Skip to content

Commit c0a38fa

Browse files
committed
address all feedback from review meeting
1 parent b382344 commit c0a38fa

27 files changed

+9860
-13940
lines changed
Binary file not shown.

src/ResourceManager/ContainerInstance/Commands.ContainerInstance.Test/Commands.ContainerInstance.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
<None Include="SessionRecords\Microsoft.Azure.Commands.ContainerInstance.Test.ScenarioTests.ContainerInstanceTests\TestContainerGroupCommands.json">
198198
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
199199
</None>
200-
<None Include="SessionRecords\Microsoft.Azure.Commands.ContainerInstance.Test.ScenarioTests.ContainerInstanceTests\TestGetContainerGroupLogs.json">
200+
<None Include="SessionRecords\Microsoft.Azure.Commands.ContainerInstance.Test.ScenarioTests.ContainerInstanceTests\TestContainerInstanceLog.json">
201201
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
202202
</None>
203203
</ItemGroup>

src/ResourceManager/ContainerInstance/Commands.ContainerInstance.Test/ScenarioTests/ContainerInstanceTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ public void TestContainerGroupCommands()
3838

3939
[Fact]
4040
[Trait(Category.AcceptanceType, Category.CheckIn)]
41-
public void TestGetContainerGroupLogs()
41+
public void TestContainerInstanceLog()
4242
{
43-
TestController.NewInstance.RunPowerShellTest("Test-AzureRmContainerGroupLogs");
43+
TestController.NewInstance.RunPowerShellTest("Test-AzureRmContainerInstanceLog");
4444
}
4545
}
4646
}

src/ResourceManager/ContainerInstance/Commands.ContainerInstance.Test/ScenarioTests/ContainerInstanceTests.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ function Test-AzureRmContainerGroup
5757

5858
<#
5959
.SYNOPSIS
60-
Test Get-AzureRmContainerGroupLogs
60+
Test Get-AzureRmContainerInstanceLog
6161
#>
62-
function Test-AzureRmContainerGroupLogs
62+
function Test-AzureRmContainerInstanceLog
6363
{
6464
$resourceGroupName = Get-RandomResourceGroupName
6565
$containerGroupName = Get-RandomContainerGroupName
@@ -71,10 +71,10 @@ function Test-AzureRmContainerGroupLogs
7171
{
7272
New-AzureRmResourceGroup -Name $resourceGroupName -Location $location
7373
$containerGroupCreated = New-AzureRmContainerGroup -ResourceGroupName $resourceGroupName -Name $containerGroupName -Image $image -OsType $osType -IpAddressType "public"
74+
$containerInstanceName = $containerGroupName
7475

75-
Export-AzureRmContainerGroupLogs -ResourceGroupName $resourceGroupName -Name $containerGroupName -Dir "."
76-
$log = $containerGroupName + "_log"
77-
Assert-True {Test-Path $log}
76+
$log = $containerGroupCreated | Get-AzureRmContainerInstanceLog -Name $containerInstanceName
77+
Assert-NotNull $log
7878

7979
Remove-AzureRmContainerGroup -ResourceGroupName $resourceGroupName -Name $containerGroupName
8080
}

src/ResourceManager/ContainerInstance/Commands.ContainerInstance.Test/SessionRecords/Microsoft.Azure.Commands.ContainerInstance.Test.ScenarioTests.ContainerInstanceTests/TestContainerGroupCommands.json

Lines changed: 3728 additions & 10748 deletions
Large diffs are not rendered by default.
Lines changed: 5369 additions & 2561 deletions
Large diffs are not rendered by default.

src/ResourceManager/ContainerInstance/Commands.ContainerInstance/Commands.ContainerInstance.csproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,24 @@
4545
</ItemGroup>
4646
<ItemGroup>
4747
<Compile Include="Commands\GetAzureContainerGroupCommand.cs" />
48-
<Compile Include="Commands\ExportAzureContainerGroupLogsCommand.cs" />
48+
<Compile Include="Commands\GetAzureContainerInstanceLogCommand.cs" />
4949
<Compile Include="Commands\NewAzureContainerGroupCommand.cs" />
5050
<Compile Include="Commands\RemoveAzureContainerGroupCommand.cs" />
5151
<Compile Include="Models\ContainerGroupCreationParameters.cs" />
5252
<Compile Include="Commands\ContainerInstanceCmdletBase.cs" />
5353
<Compile Include="Models\PSContainer.cs" />
54+
<Compile Include="Models\PSContainerEvent.cs" />
5455
<Compile Include="Models\PSContainerGroup.cs" />
56+
<Compile Include="Models\PSContainerGroupList.cs" />
57+
<Compile Include="Models\PSContainerState.cs" />
58+
<Compile Include="Models\PSPort.cs" />
5559
<Compile Include="Properties\AssemblyInfo.cs" />
5660
</ItemGroup>
5761
<ItemGroup>
62+
<Reference Include="AutoMapper, Version=3.1.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
63+
<SpecificVersion>False</SpecificVersion>
64+
<HintPath>..\..\..\packages\AutoMapper.3.1.1\lib\net40\AutoMapper.dll</HintPath>
65+
</Reference>
5866
<Reference Include="Microsoft.Azure.Management.ContainerInstance, Version=0.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
5967
<HintPath>..\..\..\packages\Microsoft.Azure.Management.ContainerInstance.1.0.0-preview\lib\net452\Microsoft.Azure.Management.ContainerInstance.dll</HintPath>
6068
</Reference>

src/ResourceManager/ContainerInstance/Commands.ContainerInstance/Commands/ContainerInstanceCmdletBase.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.Collections;
1717
using System.Collections.Generic;
1818
using System.Linq;
19+
using AutoMapper;
1920
using Microsoft.Azure.Commands.Common.Authentication;
2021
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
2122
using Microsoft.Azure.Commands.ContainerInstance.Models;
@@ -39,7 +40,7 @@ public abstract class ContainerInstanceCmdletBase : AzureRMCmdlet
3940
/// <summary>
4041
/// Noun for container group logs.
4142
/// </summary>
42-
protected const string ContainerLogsNoun = "AzureRmContainerGroupLogs";
43+
protected const string ContainerInstanceLogNoun = "AzureRmContainerInstanceLog";
4344

4445
/// <summary>
4546
/// Container instance management client.
@@ -173,5 +174,33 @@ public IDictionary<string, string> ConvertHashtableToDictionary(Hashtable hashta
173174
}
174175
return dictionary;
175176
}
177+
178+
/// <summary>
179+
/// Initialize AutoMapper.
180+
/// </summary>
181+
public static void InitializeAutoMapper()
182+
{
183+
Mapper.Initialize(cfg => {
184+
cfg.CreateMap<PSContainerGroup, PSContainerGroupList>();
185+
cfg.CreateMap<Port, PSPort>();
186+
cfg.CreateMap<ContainerEvent, PSContainerEvent>();
187+
cfg.CreateMap<ContainerState, PSContainerState>();
188+
});
189+
}
190+
191+
/// <summary>
192+
/// Implement ExecuteCmdlet.
193+
/// </summary>
194+
public override void ExecuteCmdlet()
195+
{
196+
ContainerInstanceCmdletBase.InitializeAutoMapper();
197+
this.ExecuteCmdletInternal();
198+
199+
}
200+
201+
/// <summary>
202+
/// The internal cmdlet execution for subclasses to implement.
203+
/// </summary>
204+
protected abstract void ExecuteCmdletInternal();
176205
}
177206
}

src/ResourceManager/ContainerInstance/Commands.ContainerInstance/Commands/ExportAzureContainerGroupLogsCommand.cs

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

src/ResourceManager/ContainerInstance/Commands.ContainerInstance/Commands/GetAzureContainerGroupCommand.cs

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,26 @@
1414

1515
using System.Collections.Generic;
1616
using System.Management.Automation;
17+
using AutoMapper;
1718
using Microsoft.Azure.Commands.ContainerInstance.Models;
1819
using Microsoft.Azure.Management.ContainerInstance;
1920
using Microsoft.Azure.Management.ContainerInstance.Models;
21+
using Microsoft.Azure.Management.Internal.Resources;
2022
using Microsoft.Rest.Azure;
2123

2224
namespace Microsoft.Azure.Commands.ContainerInstance
2325
{
2426
/// <summary>
2527
/// Get-AzureRmContainerGroup.
2628
/// </summary>
27-
[Cmdlet(VerbsCommon.Get, ContainerGroupNoun, DefaultParameterSetName = ListAllContainerGroupParamSet)]
29+
[Cmdlet(VerbsCommon.Get, ContainerGroupNoun, DefaultParameterSetName = ListContainerGroupParamSet)]
2830
[OutputType(typeof(PSContainerGroup))]
2931
public class GetAzureContainerGroupCommand : ContainerInstanceCmdletBase
3032
{
3133
protected const string GetContainerGroupInResourceGroupParamSet = "GetContainerGroupInResourceGroupParamSet";
32-
protected const string ListContainerGroupInResourceGroupParamSet = "ListContainerGroupInResourceGroupParamSet";
33-
protected const string ListAllContainerGroupParamSet = "ListAllContainerGroupParamSet";
34+
protected const string GetContainerGroupByResourceIdParamSet = "GetContainerGroupByResourceIdParamSet";
35+
protected const string ListContainerGroupParamSet = "ListContainerGroupParamSet";
3436

35-
[Parameter(
36-
Position = 0,
37-
Mandatory = false,
38-
ParameterSetName = ListAllContainerGroupParamSet,
39-
ValueFromPipelineByPropertyName = true,
40-
HelpMessage = "The resource Group Name.")]
4137
[Parameter(
4238
Position = 0,
4339
Mandatory = true,
@@ -46,8 +42,8 @@ public class GetAzureContainerGroupCommand : ContainerInstanceCmdletBase
4642
HelpMessage = "The resource Group Name.")]
4743
[Parameter(
4844
Position = 0,
49-
Mandatory = true,
50-
ParameterSetName = ListContainerGroupInResourceGroupParamSet,
45+
Mandatory = false,
46+
ParameterSetName = ListContainerGroupParamSet,
5147
ValueFromPipelineByPropertyName = true,
5248
HelpMessage = "The resource Group Name.")]
5349
[ValidateNotNullOrEmpty]
@@ -62,29 +58,49 @@ public class GetAzureContainerGroupCommand : ContainerInstanceCmdletBase
6258
[ValidateNotNullOrEmpty]
6359
public string Name { get; set; }
6460

65-
public override void ExecuteCmdlet()
61+
[Parameter(
62+
Mandatory = true,
63+
ParameterSetName = GetContainerGroupByResourceIdParamSet,
64+
ValueFromPipelineByPropertyName = true,
65+
HelpMessage = "The resource id.")]
66+
[ValidateNotNullOrEmpty]
67+
public string ResourceId { get; set; }
68+
69+
protected override void ExecuteCmdletInternal()
6670
{
71+
ContainerInstanceCmdletBase.InitializeAutoMapper();
72+
6773
if (!string.IsNullOrEmpty(this.ResourceGroupName) && !string.IsNullOrEmpty(this.Name))
6874
{
6975
var psContainerGroup = PSContainerGroup.FromContainerGroup(
7076
this.ContainerClient.ContainerGroups.Get(this.ResourceGroupName, this.Name));
7177
this.WriteObject(psContainerGroup);
7278
}
79+
else if (!string.IsNullOrEmpty(this.ResourceId))
80+
{
81+
var resource = this.ResourceClient.Resources.GetById(this.ResourceId, this.ResourceClient.ApiVersion);
82+
if (resource != null)
83+
{
84+
var psContainerGroup = PSContainerGroup.FromContainerGroup(
85+
this.ContainerClient.ContainerGroups.Get(resource.ResourceGroupName, resource.Name));
86+
this.WriteObject(psContainerGroup);
87+
}
88+
}
7389
else
7490
{
75-
var psContainerGroups = new List<PSContainerGroup>();
91+
var psContainerGroups = new List<PSContainerGroupList>();
7692
var containerGroups = this.ListContainerGroups();
7793
foreach (var containerGroup in containerGroups)
7894
{
79-
psContainerGroups.Add(PSContainerGroup.FromContainerGroup(containerGroup));
95+
psContainerGroups.Add(Mapper.Map<PSContainerGroupList>(PSContainerGroup.FromContainerGroup(containerGroup)));
8096
}
8197

8298
while (!string.IsNullOrEmpty(containerGroups.NextPageLink))
8399
{
84100
containerGroups = this.ListContainerGroupsNext(containerGroups.NextPageLink);
85101
foreach (var containerGroup in containerGroups)
86102
{
87-
psContainerGroups.Add(PSContainerGroup.FromContainerGroup(containerGroup));
103+
psContainerGroups.Add(Mapper.Map<PSContainerGroupList>(PSContainerGroup.FromContainerGroup(containerGroup)));
88104
}
89105
}
90106

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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.Management.Automation;
16+
using Microsoft.Azure.Commands.ContainerInstance.Models;
17+
using Microsoft.Azure.Management.ContainerInstance;
18+
using Microsoft.Azure.Management.Internal.Resources;
19+
20+
namespace Microsoft.Azure.Commands.ContainerInstance
21+
{
22+
/// <summary>
23+
/// Get-AzureRmContainerGroupLogs
24+
/// </summary>
25+
[Cmdlet(VerbsCommon.Get, ContainerInstanceLogNoun), OutputType(typeof(string))]
26+
public class GetAzureContainerInstanceLogCommand : ContainerInstanceCmdletBase
27+
{
28+
protected const string GetContainerInstanceLogByNamesParamSet = "GetContainerInstanceLogByNamesParamSet";
29+
protected const string GetContainerInstanceLogByPSContainerGroupParamSet = "GetContainerInstanceLogByPSContainerGroupParamSet";
30+
protected const string GetContainerInstanceLogByResourceIdParamSet = "GetContainerInstanceLogByResourceIdParamSet";
31+
32+
[Parameter(
33+
Position = 0,
34+
Mandatory = true,
35+
ParameterSetName = GetContainerInstanceLogByNamesParamSet,
36+
HelpMessage = "The resource group name.")]
37+
[ValidateNotNullOrEmpty]
38+
public string ResourceGroupName { get; set; }
39+
40+
[Parameter(
41+
Mandatory = true,
42+
ParameterSetName = GetContainerInstanceLogByNamesParamSet,
43+
HelpMessage = "The container group name.")]
44+
[ValidateNotNullOrEmpty]
45+
public string ContainerGroupName { get; set; }
46+
47+
[Parameter(
48+
Mandatory = true,
49+
ParameterSetName = GetContainerInstanceLogByPSContainerGroupParamSet,
50+
ValueFromPipeline = true,
51+
HelpMessage = "The input container group object.")]
52+
[ValidateNotNullOrEmpty]
53+
public PSContainerGroup InputContainerGroup { get; set; }
54+
55+
[Parameter(
56+
Mandatory = true,
57+
ParameterSetName = GetContainerInstanceLogByResourceIdParamSet,
58+
ValueFromPipelineByPropertyName = true,
59+
HelpMessage = "The resource id.")]
60+
[ValidateNotNullOrEmpty]
61+
public string ResourceId { get; set; }
62+
63+
[Parameter(
64+
Mandatory = false,
65+
HelpMessage = "The container instance name in the container group. Default: the same as the container group name")]
66+
[ValidateNotNullOrEmpty]
67+
public string Name { get; set; }
68+
69+
[Parameter(
70+
Mandatory = false,
71+
HelpMessage = "The number of lines to tail the log. If not specify, the cmdlet will return up to 4MB tailed log")]
72+
[ValidateNotNullOrEmpty]
73+
public int? Tail { get; set; }
74+
75+
protected override void ExecuteCmdletInternal()
76+
{
77+
var resourceGroupName = this.InputContainerGroup?.ResourceGroupName ?? this.ResourceGroupName;
78+
var containerGroupName = this.InputContainerGroup?.Name ?? this.ContainerGroupName;
79+
80+
if (string.IsNullOrWhiteSpace(resourceGroupName)
81+
&& string.IsNullOrWhiteSpace(containerGroupName)
82+
&& !string.IsNullOrWhiteSpace(this.ResourceId))
83+
{
84+
var resource = this.ResourceClient.Resources.GetById(this.ResourceId, this.ResourceClient.ApiVersion);
85+
if (resource != null)
86+
{
87+
var containerGroup = this.ContainerClient.ContainerGroups.Get(resource.ResourceGroupName, resource.Name);
88+
resourceGroupName = resource.ResourceGroupName;
89+
containerGroupName = containerGroup?.Name;
90+
}
91+
}
92+
93+
var containerName = this.Name ?? containerGroupName;
94+
95+
var log = this.ContainerClient.ContainerLogs.List(resourceGroupName, containerGroupName, containerName, this.Tail)?.Content;
96+
97+
this.WriteObject(log);
98+
}
99+
}
100+
}

0 commit comments

Comments
 (0)