Skip to content

Commit 056135f

Browse files
committed
Merge pull request #77 from huangpf/clu
Clu
2 parents 1687664 + c4e41e5 commit 056135f

15 files changed

+513
-22
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Azure PowerShell specific
22
src/Publish/
33
src/Package/
4+
drop/
45

56
obj
67
TestResults
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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.Management.Compute;
16+
17+
namespace Microsoft.Azure.Commands.Compute
18+
{
19+
public abstract class AvailabilitySetBaseCmdlet : ComputeClientBaseCmdlet
20+
{
21+
public IAvailabilitySetsOperations AvailabilitySetClient
22+
{
23+
get
24+
{
25+
return ComputeClient.ComputeManagementClient.AvailabilitySets;
26+
}
27+
}
28+
}
29+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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 AutoMapper;
16+
using Microsoft.Azure.Commands.Compute.Common;
17+
using Microsoft.Azure.Commands.Compute.Models;
18+
using Microsoft.Azure.Management.Compute;
19+
using System.Collections.Generic;
20+
using System.Management.Automation;
21+
22+
namespace Microsoft.Azure.Commands.Compute
23+
{
24+
[Cmdlet(VerbsCommon.Get, ProfileNouns.AvailabilitySet)]
25+
[OutputType(typeof(PSAvailabilitySet))]
26+
public class GetAzureAvailabilitySetCommand : AvailabilitySetBaseCmdlet
27+
{
28+
[Parameter(
29+
Mandatory = true,
30+
Position = 0,
31+
ValueFromPipelineByPropertyName = true,
32+
HelpMessage = "The resource group name.")]
33+
[ValidateNotNullOrEmpty]
34+
public string ResourceGroupName { get; set; }
35+
36+
[Alias("ResourceName", "AvailabilitySetName")]
37+
[Parameter(
38+
Position = 1,
39+
ValueFromPipelineByPropertyName = true,
40+
HelpMessage = "The availability set name.")]
41+
[ValidateNotNullOrEmpty]
42+
public string Name { get; set; }
43+
44+
protected override void ProcessRecord()
45+
{
46+
base.ProcessRecord();
47+
48+
ExecuteClientAction(() =>
49+
{
50+
if (string.IsNullOrEmpty(this.Name))
51+
{
52+
var result = this.AvailabilitySetClient.List(this.ResourceGroupName);
53+
54+
List<PSAvailabilitySet> psResultList = new List<PSAvailabilitySet>();
55+
foreach (var item in result)
56+
{
57+
var psItem = Mapper.Map<PSAvailabilitySet>(item);
58+
psResultList.Add(psItem);
59+
}
60+
61+
WriteObject(psResultList, true);
62+
}
63+
else
64+
{
65+
var result = this.AvailabilitySetClient.Get(this.ResourceGroupName, this.Name);
66+
var psResult = Mapper.Map<PSAvailabilitySet>(result);
67+
WriteObject(psResult);
68+
}
69+
});
70+
}
71+
}
72+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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 AutoMapper;
16+
using Microsoft.Azure.Commands.Compute.Common;
17+
using Microsoft.Azure.Commands.Compute.Models;
18+
using Microsoft.Azure.Management.Compute;
19+
using Microsoft.Azure.Management.Compute.Models;
20+
using System.Management.Automation;
21+
22+
namespace Microsoft.Azure.Commands.Compute
23+
{
24+
[Cmdlet(VerbsCommon.New, ProfileNouns.AvailabilitySet)]
25+
[OutputType(typeof(PSAvailabilitySet))]
26+
public class NewAzureAvailabilitySetCommand : AvailabilitySetBaseCmdlet
27+
{
28+
[Parameter(
29+
Mandatory = true,
30+
Position = 0,
31+
ValueFromPipelineByPropertyName = true,
32+
HelpMessage = "The resource group name.")]
33+
[ValidateNotNullOrEmpty]
34+
public string ResourceGroupName { get; set; }
35+
36+
[Alias("ResourceName", "AvailabilitySetName")]
37+
[Parameter(
38+
Mandatory = true,
39+
Position = 1,
40+
ValueFromPipelineByPropertyName = true,
41+
HelpMessage = "The resource name.")]
42+
[ValidateNotNullOrEmpty]
43+
public string Name { get; set; }
44+
45+
[Parameter(
46+
Mandatory = true,
47+
Position = 2,
48+
ValueFromPipelineByPropertyName = true,
49+
HelpMessage = "The location.")]
50+
[ValidateNotNullOrEmpty]
51+
public string Location { get; set; }
52+
53+
[Parameter(
54+
Position = 3,
55+
ValueFromPipelineByPropertyName = true,
56+
HelpMessage = "The Platform Update Domain Count.")]
57+
[ValidateNotNullOrEmpty]
58+
public int? PlatformUpdateDomainCount { get; set; }
59+
60+
[Parameter(
61+
Position = 4,
62+
ValueFromPipelineByPropertyName = true,
63+
HelpMessage = "The Platform Fault Domain Count.")]
64+
[ValidateNotNullOrEmpty]
65+
public int? PlatformFaultDomainCount { get; set; }
66+
67+
protected override void ProcessRecord()
68+
{
69+
base.ProcessRecord();
70+
71+
ExecuteClientAction(() =>
72+
{
73+
var avSetParams = new AvailabilitySet
74+
{
75+
//Name = this.Name,
76+
Location = this.Location,
77+
PlatformUpdateDomainCount = this.PlatformUpdateDomainCount,
78+
PlatformFaultDomainCount = this.PlatformFaultDomainCount
79+
};
80+
81+
var result = this.AvailabilitySetClient.CreateOrUpdate(this.ResourceGroupName, this.Name, avSetParams);
82+
83+
var psResult = Mapper.Map<PSAvailabilitySet>(result);
84+
WriteObject(psResult);
85+
});
86+
}
87+
}
88+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.Compute.Common;
16+
using Microsoft.Azure.Commands.Compute.Models;
17+
using Microsoft.Azure.Management.Compute;
18+
using System.Management.Automation;
19+
20+
namespace Microsoft.Azure.Commands.Compute
21+
{
22+
[Cmdlet(VerbsCommon.Remove, ProfileNouns.AvailabilitySet)]
23+
[OutputType(typeof(PSOperation))]
24+
public class RemoveAzureAvailabilitySetCommand : AvailabilitySetBaseCmdlet
25+
{
26+
[Parameter(
27+
Mandatory = true,
28+
Position = 0,
29+
ValueFromPipelineByPropertyName = true,
30+
HelpMessage = "The resource group name.")]
31+
[ValidateNotNullOrEmpty]
32+
public string ResourceGroupName { get; set; }
33+
34+
[Alias("ResourceName", "AvailabilitySetName")]
35+
[Parameter(
36+
Position = 1,
37+
ValueFromPipelineByPropertyName = true,
38+
HelpMessage = "The availability set name.")]
39+
[ValidateNotNullOrEmpty]
40+
public string Name { get; set; }
41+
42+
[Parameter(
43+
Position = 2,
44+
HelpMessage = "To force the removal.")]
45+
[ValidateNotNullOrEmpty]
46+
public SwitchParameter Force { get; set; }
47+
48+
protected override void ProcessRecord()
49+
{
50+
base.ProcessRecord();
51+
52+
ExecuteClientAction(() =>
53+
{
54+
if (this.Force.IsPresent || this.ShouldContinue("Continue?", "Confirmation"))
55+
{
56+
this.AvailabilitySetClient.Delete(this.ResourceGroupName, this.Name);
57+
}
58+
});
59+
}
60+
}
61+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 AutoMapper;
16+
using System;
17+
using System.Collections;
18+
using System.Collections.Generic;
19+
using FROM = Microsoft.Azure.Management.Compute.Models;
20+
using TO = Microsoft.Azure.Commands.Compute.Models;
21+
22+
namespace Microsoft.Azure.Commands.Compute
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 : AutoMapper.Profile
47+
{
48+
private static readonly Lazy<bool> initialize;
49+
50+
public ComputeAutoMapperProfile() : base("ComputeAutoMapperProfile")
51+
{
52+
}
53+
54+
static ComputeAutoMapperProfile()
55+
{
56+
initialize = new Lazy<bool>(() =>
57+
{
58+
Mapper.AddProfile<ComputeAutoMapperProfile>();
59+
return true;
60+
});
61+
}
62+
63+
public static bool Initialize()
64+
{
65+
return initialize.Value;
66+
}
67+
68+
protected override void Configure()
69+
{
70+
//Mapper.CreateMap<Microsoft.Azure.AzureOperationResponse, TO.PSOperation>();
71+
//Mapper.CreateMap<FROM.ComputeLongRunningOperationResponse, TO.PSComputeLongRunningOperation>();
72+
//Mapper.CreateMap<FROM.DeleteOperationResponse, TO.PSComputeLongRunningOperation>();
73+
74+
Mapper.CreateMap<FROM.AvailabilitySet, TO.PSAvailabilitySet>();
75+
//Mapper.CreateMap<Microsoft.Azure.AzureOperationResponse, TO.PSAvailabilitySet>();
76+
77+
//Mapper.CreateMap<FROM.VirtualMachine, TO.PSVirtualMachine>();
78+
//Mapper.CreateMap<Microsoft.Azure.AzureOperationResponse, TO.PSVirtualMachine>();
79+
80+
Mapper.CreateMap<FROM.VirtualMachineSize, TO.PSVirtualMachineSize>();
81+
//Mapper.CreateMap<Microsoft.Azure.AzureOperationResponse, TO.PSVirtualMachineSize>();
82+
83+
//Mapper.CreateMap<FROM.Usage, TO.PSUsage>();
84+
//Mapper.CreateMap<Microsoft.Azure.AzureOperationResponse, TO.PSUsage>();
85+
}
86+
}
87+
}

src/CLU/Microsoft.Azure.Commands.Compute/Common/ComputeClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class ComputeClient
2828
public Action<string> ErrorLogger { get; set; }
2929

3030
public ComputeClient(IClientFactory clientFactory, AzureContext context)
31-
: this(clientFactory.CreateClient<ComputeManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager))
31+
: this(clientFactory.CreateArmClient<ComputeManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager))
3232
{
3333
}
3434

src/CLU/Microsoft.Azure.Commands.Compute/Common/ComputeClientBaseCmdlet.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public ComputeClient ComputeClient
5151
protected override void ProcessRecord()
5252
{
5353
base.ProcessRecord();
54+
ComputeAutoMapperProfile.Initialize();
5455
}
5556

5657
protected void ExecuteClientAction(Action action)

src/CLU/Microsoft.Azure.Commands.Compute/Content/azure.lx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
RtPackage: Microsoft.CLU
1+
RtPackage: Microsoft.CLU.Commands
22
RtEntry: Microsoft.CLU.CommandModel.CmdletCommandModel.Run
33
RtAssembly: Microsoft.CLU.dll
44
Modules: Microsoft.Azure.Commands.Compute
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="14.0.24711" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
4-
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.24711</VisualStudioVersion>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
55
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
66
</PropertyGroup>
77
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
@@ -14,8 +14,5 @@
1414
<PropertyGroup>
1515
<SchemaVersion>2.0</SchemaVersion>
1616
</PropertyGroup>
17-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
18-
<ProduceOutputsOnBuild>True</ProduceOutputsOnBuild>
19-
</PropertyGroup>
2017
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
2118
</Project>

0 commit comments

Comments
 (0)