Skip to content

Commit 0787052

Browse files
committed
Merge pull request Azure#39 from huangpf/crp2
Crp2
2 parents 70a0463 + ab1b163 commit 0787052

File tree

10 files changed

+294
-41
lines changed

10 files changed

+294
-41
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ public class NewAzureAvailabilitySetCommand : AvailabilitySetBaseCmdlet
5252
ValueFromPipelineByPropertyName = true,
5353
HelpMessage = "The Platform Update Domain Count.")]
5454
[ValidateNotNullOrEmpty]
55-
public int PlatformUpdateDomainCount { get; set; }
55+
public int? PlatformUpdateDomainCount { get; set; }
5656

5757
[Parameter(
5858
Position = 4,
5959
ValueFromPipelineByPropertyName = true,
6060
HelpMessage = "The Platform Fault Domain Count.")]
6161
[ValidateNotNullOrEmpty]
62-
public int PlatformFaultDomainCount { get; set; }
62+
public int? PlatformFaultDomainCount { get; set; }
6363

6464
public override void ExecuteCmdlet()
6565
{

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,10 @@
150150
<Compile Include="StorageAccount\RemoveAzureStorageAccount.cs" />
151151
<Compile Include="StorageAccount\SetAzureStorageAccount.cs" />
152152
<Compile Include="StorageAccount\StorageAccountBaseCmdlet.cs" />
153-
<Compile Include="VirtualMachine\Action\CaptureAzureVMCommand.cs" />
154-
<Compile Include="VirtualMachine\Action\GeneralizeAzureVMCommand.cs" />
153+
<Compile Include="VirtualMachineSizes\GetAzureVMSizeCommand.cs" />
154+
<Compile Include="VirtualMachineSizes\VirtualMachineSizeBaseCmdlet.cs" />
155+
<Compile Include="VirtualMachine\Action\SaveAzureVMImageCommand.cs" />
156+
<Compile Include="VirtualMachine\Action\SetAzureVMCommand.cs" />
155157
<Compile Include="VirtualMachine\Config\RemoveAzureVMDataDiskCommand.cs" />
156158
<Compile Include="VirtualMachine\Config\SetAzureVMSourceImage.cs" />
157159
<Compile Include="VirtualMachine\Config\SetAzureVMOSDiskCommand.cs" />

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,9 @@ public static class ProfileNouns
6868

6969
public const string AvailabilitySet = "AzureAvailabilitySet";
7070
public const string VirtualMachineConfig = "AzureVMConfig";
71+
72+
public const string VirtualMachineSize = "AzureVMSize";
73+
74+
public const string VirtualMachineImage = "AzureVMImage";
7175
}
7276
}

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

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

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Action/CaptureAzureVMCommand.cs renamed to src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Action/SaveAzureVMImageCommand.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919

2020
namespace Microsoft.Azure.Commands.Compute
2121
{
22-
[Cmdlet(VerbsData.Save, ProfileNouns.VirtualMachine)]
23-
public class SaveAzureVMCommand : VirtualMachineBaseCmdlet
22+
[Cmdlet(VerbsData.Save, ProfileNouns.VirtualMachineImage)]
23+
[OutputType(typeof(ComputeLongRunningOperationResponse))]
24+
public class SaveAzureVMImageCommand : VirtualMachineBaseCmdlet
2425
{
2526
[Parameter(
2627
Mandatory = true,
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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.Management.Compute;
17+
using System.Management.Automation;
18+
19+
namespace Microsoft.Azure.Commands.Compute
20+
{
21+
[Cmdlet(VerbsCommon.Set, ProfileNouns.VirtualMachine, DefaultParameterSetName = GeneralizeVirtualMachineParamSet)]
22+
[OutputType(typeof(AzureOperationResponse))]
23+
public class SetAzureVMCommand : VirtualMachineBaseCmdlet
24+
{
25+
protected const string GeneralizeVirtualMachineParamSet = "GeneralizeVirtualMachineParamSet";
26+
27+
[Parameter(
28+
Mandatory = true,
29+
ParameterSetName = GeneralizeVirtualMachineParamSet,
30+
Position = 0,
31+
ValueFromPipelineByPropertyName = true,
32+
HelpMessage = "The resource group name.")]
33+
[ValidateNotNullOrEmpty]
34+
public override string ResourceGroupName { get; set; }
35+
36+
[Parameter(
37+
Mandatory = true,
38+
ParameterSetName = GeneralizeVirtualMachineParamSet,
39+
Position = 1,
40+
ValueFromPipelineByPropertyName = true,
41+
HelpMessage = "The virtual machine name.")]
42+
[ValidateNotNullOrEmpty]
43+
public override string Name { get; set; }
44+
45+
[Parameter(
46+
Mandatory = true,
47+
ParameterSetName = GeneralizeVirtualMachineParamSet,
48+
Position = 2,
49+
ValueFromPipelineByPropertyName = true,
50+
HelpMessage = "To generalize virtual machine.")]
51+
[ValidateNotNullOrEmpty]
52+
public SwitchParameter Generalized { get; set; }
53+
54+
public override void ExecuteCmdlet()
55+
{
56+
base.ExecuteCmdlet();
57+
58+
var op = this.VirtualMachineClient.Generalize(this.ResourceGroupName, this.Name);
59+
WriteObject(op);
60+
}
61+
}
62+
}

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/GetAzureVMCommand.cs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
using Microsoft.Azure.Commands.Compute.Common;
1616
using Microsoft.Azure.Commands.Compute.Models;
1717
using Microsoft.Azure.Management.Compute;
18+
using Microsoft.Azure.Management.Compute.Models;
19+
using System;
1820
using System.Management.Automation;
1921

2022
namespace Microsoft.Azure.Commands.Compute
@@ -25,17 +27,27 @@ public class GetAzureVMCommand : VirtualMachineBaseCmdlet
2527
{
2628
protected const string GetVirtualMachineParamSet = "GetVirtualMachineParamSet";
2729
protected const string ListVirtualMachineParamSet = "ListVirtualMachineParamSet";
30+
protected const string ListAllVirtualMachinesParamSet = "ListAllVirtualMachinesParamSet";
31+
protected const string ListNextVirtualMachinesParamSet = "ListNextVirtualMachinesParamSet";
2832

2933
[Parameter(
3034
Mandatory = true,
3135
Position = 0,
36+
ParameterSetName = ListVirtualMachineParamSet,
37+
ValueFromPipelineByPropertyName = true,
38+
HelpMessage = "The resource group name.")]
39+
[Parameter(
40+
Mandatory = true,
41+
Position = 0,
42+
ParameterSetName = GetVirtualMachineParamSet,
3243
ValueFromPipelineByPropertyName = true,
3344
HelpMessage = "The resource group name.")]
3445
[ValidateNotNullOrEmpty]
3546
public override string ResourceGroupName { get; set; }
3647

3748
[Alias("ResourceName", "VMName")]
3849
[Parameter(
50+
Mandatory = true,
3951
Position = 1,
4052
ParameterSetName = GetVirtualMachineParamSet,
4153
ValueFromPipelineByPropertyName = true,
@@ -51,6 +63,24 @@ public class GetAzureVMCommand : VirtualMachineBaseCmdlet
5163
[ValidateNotNullOrEmpty]
5264
public SwitchParameter Status { get; set; }
5365

66+
[Parameter(
67+
Mandatory = true,
68+
Position = 1,
69+
ParameterSetName = ListAllVirtualMachinesParamSet,
70+
ValueFromPipelineByPropertyName = true,
71+
HelpMessage = "To list all virtual machines.")]
72+
[ValidateNotNullOrEmpty]
73+
public SwitchParameter All { get; set; }
74+
75+
[Parameter(
76+
Mandatory = true,
77+
Position = 1,
78+
ParameterSetName = ListNextVirtualMachinesParamSet,
79+
ValueFromPipelineByPropertyName = true,
80+
HelpMessage = "The link to the next page of virtual machines.")]
81+
[ValidateNotNullOrEmpty]
82+
public Uri NextLink { get; set; }
83+
5484
public override void ExecuteCmdlet()
5585
{
5686
base.ExecuteCmdlet();
@@ -70,7 +100,22 @@ public override void ExecuteCmdlet()
70100
}
71101
else
72102
{
73-
var result = this.VirtualMachineClient.List(this.ResourceGroupName);
103+
VirtualMachineListResponse result = null;
104+
105+
if (this.All.IsPresent)
106+
{
107+
var listParams = new ListParameters();
108+
result = this.VirtualMachineClient.ListAll(listParams);
109+
}
110+
else if (this.NextLink != null)
111+
{
112+
result = this.VirtualMachineClient.ListNext(this.NextLink.ToString());
113+
}
114+
else
115+
{
116+
result = this.VirtualMachineClient.List(this.ResourceGroupName);
117+
}
118+
74119
WriteObject(result.ToPSVirtualMachineList(this.ResourceGroupName), true);
75120
}
76121
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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.Management.Compute;
17+
using Microsoft.Azure.Management.Compute.Models;
18+
using System.Collections.Generic;
19+
using System.Management.Automation;
20+
21+
namespace Microsoft.Azure.Commands.Compute
22+
{
23+
[Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachineSize, DefaultParameterSetName = ListVirtualMachineSizeParamSet)]
24+
[OutputType(typeof(VirtualMachineSize))]
25+
public class GetAzureVMSizeCommand : VirtualMachineSizeBaseCmdlet
26+
{
27+
protected const string ListVirtualMachineSizeParamSet = "ListVirtualMachineSizeParamSet";
28+
protected const string ListAvailableSizesForAvailabilitySet = "ListAvailableSizesForAvailabilitySet";
29+
protected const string ListAvailableSizesForVirtualMachine = "ListAvailableSizesForVirtualMachine";
30+
31+
[Parameter(
32+
Mandatory = true,
33+
Position = 0,
34+
ParameterSetName = ListVirtualMachineSizeParamSet,
35+
ValueFromPipelineByPropertyName = true,
36+
HelpMessage = "The location name.")]
37+
[ValidateNotNullOrEmpty]
38+
public string Location { get; set; }
39+
40+
[Parameter(
41+
Mandatory = true,
42+
Position = 0,
43+
ParameterSetName = ListAvailableSizesForAvailabilitySet,
44+
ValueFromPipelineByPropertyName = true,
45+
HelpMessage = "The resource group name.")]
46+
[Parameter(
47+
Mandatory = true,
48+
Position = 0,
49+
ParameterSetName = ListAvailableSizesForVirtualMachine,
50+
ValueFromPipelineByPropertyName = true,
51+
HelpMessage = "The resource group name.")]
52+
[ValidateNotNullOrEmpty]
53+
public string ResourceGroupName { get; set; }
54+
55+
[Parameter(
56+
Mandatory = true,
57+
Position = 1,
58+
ParameterSetName = ListAvailableSizesForAvailabilitySet,
59+
ValueFromPipelineByPropertyName = true,
60+
HelpMessage = "The availability set name.")]
61+
[ValidateNotNullOrEmpty]
62+
public string AvailabilitySetName { get; set; }
63+
64+
[Parameter(
65+
Mandatory = true,
66+
Position = 1,
67+
ParameterSetName = ListAvailableSizesForVirtualMachine,
68+
ValueFromPipelineByPropertyName = true,
69+
HelpMessage = "The virtual machine name.")]
70+
[ValidateNotNullOrEmpty]
71+
public string VMName { get; set; }
72+
73+
public override void ExecuteCmdlet()
74+
{
75+
base.ExecuteCmdlet();
76+
77+
VirtualMachineSizeListResponse result = null;
78+
79+
if (!string.IsNullOrEmpty(this.VMName))
80+
{
81+
result = this.VirtualMachineClient.ListAvailableSizes(
82+
this.ResourceGroupName,
83+
this.VMName);
84+
}
85+
else if (!string.IsNullOrEmpty(this.AvailabilitySetName))
86+
{
87+
result = this.AvailabilitySetClient.ListAvailableSizes(
88+
this.ResourceGroupName,
89+
this.AvailabilitySetName);
90+
}
91+
else
92+
{
93+
result = this.VirtualMachineSizeClient.List(this.Location);
94+
}
95+
96+
WriteObject(result.VirtualMachineSizes, true);
97+
}
98+
}
99+
}

0 commit comments

Comments
 (0)