Skip to content

Clu #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 10, 2015
Merged

Clu #77

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Azure PowerShell specific
src/Publish/
src/Package/
drop/

obj
TestResults
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Management.Compute;

namespace Microsoft.Azure.Commands.Compute
{
public abstract class AvailabilitySetBaseCmdlet : ComputeClientBaseCmdlet
{
public IAvailabilitySetsOperations AvailabilitySetClient
{
get
{
return ComputeClient.ComputeManagementClient.AvailabilitySets;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using AutoMapper;
using Microsoft.Azure.Commands.Compute.Common;
using Microsoft.Azure.Commands.Compute.Models;
using Microsoft.Azure.Management.Compute;
using System.Collections.Generic;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.Compute
{
[Cmdlet(VerbsCommon.Get, ProfileNouns.AvailabilitySet)]
[OutputType(typeof(PSAvailabilitySet))]
public class GetAzureAvailabilitySetCommand : AvailabilitySetBaseCmdlet
{
[Parameter(
Mandatory = true,
Position = 0,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource group name.")]
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

[Alias("ResourceName", "AvailabilitySetName")]
[Parameter(
Position = 1,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The availability set name.")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

protected override void ProcessRecord()
{
base.ProcessRecord();

ExecuteClientAction(() =>
{
if (string.IsNullOrEmpty(this.Name))
{
var result = this.AvailabilitySetClient.List(this.ResourceGroupName);

List<PSAvailabilitySet> psResultList = new List<PSAvailabilitySet>();
foreach (var item in result)
{
var psItem = Mapper.Map<PSAvailabilitySet>(item);
psResultList.Add(psItem);
}

WriteObject(psResultList, true);
}
else
{
var result = this.AvailabilitySetClient.Get(this.ResourceGroupName, this.Name);
var psResult = Mapper.Map<PSAvailabilitySet>(result);
WriteObject(psResult);
}
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using AutoMapper;
using Microsoft.Azure.Commands.Compute.Common;
using Microsoft.Azure.Commands.Compute.Models;
using Microsoft.Azure.Management.Compute;
using Microsoft.Azure.Management.Compute.Models;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.Compute
{
[Cmdlet(VerbsCommon.New, ProfileNouns.AvailabilitySet)]
[OutputType(typeof(PSAvailabilitySet))]
public class NewAzureAvailabilitySetCommand : AvailabilitySetBaseCmdlet
{
[Parameter(
Mandatory = true,
Position = 0,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource group name.")]
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

[Alias("ResourceName", "AvailabilitySetName")]
[Parameter(
Mandatory = true,
Position = 1,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource name.")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(
Mandatory = true,
Position = 2,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The location.")]
[ValidateNotNullOrEmpty]
public string Location { get; set; }

[Parameter(
Position = 3,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The Platform Update Domain Count.")]
[ValidateNotNullOrEmpty]
public int? PlatformUpdateDomainCount { get; set; }

[Parameter(
Position = 4,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The Platform Fault Domain Count.")]
[ValidateNotNullOrEmpty]
public int? PlatformFaultDomainCount { get; set; }

protected override void ProcessRecord()
{
base.ProcessRecord();

ExecuteClientAction(() =>
{
var avSetParams = new AvailabilitySet
{
//Name = this.Name,
Location = this.Location,
PlatformUpdateDomainCount = this.PlatformUpdateDomainCount,
PlatformFaultDomainCount = this.PlatformFaultDomainCount
};

var result = this.AvailabilitySetClient.CreateOrUpdate(this.ResourceGroupName, this.Name, avSetParams);

var psResult = Mapper.Map<PSAvailabilitySet>(result);
WriteObject(psResult);
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.Compute.Common;
using Microsoft.Azure.Commands.Compute.Models;
using Microsoft.Azure.Management.Compute;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.Compute
{
[Cmdlet(VerbsCommon.Remove, ProfileNouns.AvailabilitySet)]
[OutputType(typeof(PSOperation))]
public class RemoveAzureAvailabilitySetCommand : AvailabilitySetBaseCmdlet
{
[Parameter(
Mandatory = true,
Position = 0,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource group name.")]
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

[Alias("ResourceName", "AvailabilitySetName")]
[Parameter(
Position = 1,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The availability set name.")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(
Position = 2,
HelpMessage = "To force the removal.")]
[ValidateNotNullOrEmpty]
public SwitchParameter Force { get; set; }

protected override void ProcessRecord()
{
base.ProcessRecord();

ExecuteClientAction(() =>
{
if (this.Force.IsPresent || this.ShouldContinue("Continue?", "Confirmation"))
{
this.AvailabilitySetClient.Delete(this.ResourceGroupName, this.Name);
}
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using AutoMapper;
using System;
using System.Collections;
using System.Collections.Generic;
using FROM = Microsoft.Azure.Management.Compute.Models;
using TO = Microsoft.Azure.Commands.Compute.Models;

namespace Microsoft.Azure.Commands.Compute
{
public static class ComputeMapperExtension
{
public static IMappingExpression<TSource, TDestination> ForItems<TSource, TDestination, T>(
this IMappingExpression<TSource, TDestination> mapper)
where TSource : IEnumerable
where TDestination : ICollection<T>
{
mapper.AfterMap((c, s) =>
{
if (c != null && s != null)
{
foreach (var t in c)
{
s.Add(Mapper.Map<T>(t));
}
}
});

return mapper;
}
}

public class ComputeAutoMapperProfile : AutoMapper.Profile
{
private static readonly Lazy<bool> initialize;

public ComputeAutoMapperProfile() : base("ComputeAutoMapperProfile")
{
}

static ComputeAutoMapperProfile()
{
initialize = new Lazy<bool>(() =>
{
Mapper.AddProfile<ComputeAutoMapperProfile>();
return true;
});
}

public static bool Initialize()
{
return initialize.Value;
}

protected override void Configure()
{
//Mapper.CreateMap<Microsoft.Azure.AzureOperationResponse, TO.PSOperation>();
//Mapper.CreateMap<FROM.ComputeLongRunningOperationResponse, TO.PSComputeLongRunningOperation>();
//Mapper.CreateMap<FROM.DeleteOperationResponse, TO.PSComputeLongRunningOperation>();

Mapper.CreateMap<FROM.AvailabilitySet, TO.PSAvailabilitySet>();
//Mapper.CreateMap<Microsoft.Azure.AzureOperationResponse, TO.PSAvailabilitySet>();

//Mapper.CreateMap<FROM.VirtualMachine, TO.PSVirtualMachine>();
//Mapper.CreateMap<Microsoft.Azure.AzureOperationResponse, TO.PSVirtualMachine>();

Mapper.CreateMap<FROM.VirtualMachineSize, TO.PSVirtualMachineSize>();
//Mapper.CreateMap<Microsoft.Azure.AzureOperationResponse, TO.PSVirtualMachineSize>();

//Mapper.CreateMap<FROM.Usage, TO.PSUsage>();
//Mapper.CreateMap<Microsoft.Azure.AzureOperationResponse, TO.PSUsage>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ComputeClient
public Action<string> ErrorLogger { get; set; }

public ComputeClient(IClientFactory clientFactory, AzureContext context)
: this(clientFactory.CreateClient<ComputeManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager))
: this(clientFactory.CreateArmClient<ComputeManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager))
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public ComputeClient ComputeClient
protected override void ProcessRecord()
{
base.ProcessRecord();
ComputeAutoMapperProfile.Initialize();
}

protected void ExecuteClientAction(Action action)
Expand Down
2 changes: 1 addition & 1 deletion src/CLU/Microsoft.Azure.Commands.Compute/Content/azure.lx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RtPackage: Microsoft.CLU
RtPackage: Microsoft.CLU.Commands
RtEntry: Microsoft.CLU.CommandModel.CmdletCommandModel.Run
RtAssembly: Microsoft.CLU.dll
Modules: Microsoft.Azure.Commands.Compute
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0.24711" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.24711</VisualStudioVersion>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
Expand All @@ -14,8 +14,5 @@
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<ProduceOutputsOnBuild>True</ProduceOutputsOnBuild>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
Loading