Skip to content

Commit 5490a91

Browse files
committed
Combine Get Methods
1 parent 090768d commit 5490a91

File tree

8 files changed

+120
-167
lines changed

8 files changed

+120
-167
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ Add-AzureRmVmssNetworkInterfaceConfiguration 1.2.3 AzureRM.Compute
2828
Add-AzureRmVmssPublicKey 1.2.3 AzureRM.Compute
2929
Add-AzureRmVmssSecret 1.2.3 AzureRM.Compute
3030
Get-AzureRmVmss 1.2.3 AzureRM.Compute
31-
Get-AzureRmVmssList 1.2.3 AzureRM.Compute
3231
Get-AzureRmVmssSkusList 1.2.3 AzureRM.Compute
3332
Get-AzureRmVmssVM 1.2.3 AzureRM.Compute
34-
Get-AzureRmVmssVMList 1.2.3 AzureRM.Compute
3533
New-AzureRmVmss 1.2.3 AzureRM.Compute
3634
New-AzureRmVmssConfig 1.2.3 AzureRM.Compute
3735
New-AzureRmVmssIpConfigurationConfig 1.2.3 AzureRM.Compute
@@ -123,15 +121,15 @@ function Test-VirtualMachineScaleSet
123121

124122
$argList = New-AzureComputeArgumentList -MethodName VirtualMachineScaleSetsListAll;
125123
$args = ($argList | select -ExpandProperty Value);
126-
$vmssList = Get-AzureRmVmssList -All;
124+
$vmssList = Get-AzureRmVmss;
127125
Assert-True { ($vmssList | select -ExpandProperty Name) -contains $vmssName };
128126
$output = $vmssList | Out-String;
129127
Write-Verbose ($output);
130128
Assert-True { $output.Contains("VirtualMachineProfile") };
131129

132130
# List from RG
133-
Write-Verbose ('Running Command : ' + 'Get-AzureRmVmssList');
134-
$vmssList = Get-AzureRmVmssList -ResourceGroupName $rgname;
131+
Write-Verbose ('Running Command : ' + 'Get-AzureRmVmss List');
132+
$vmssList = Get-AzureRmVmss -ResourceGroupName $rgname;
135133
Assert-True { ($vmssList | select -ExpandProperty Name) -contains $vmssName };
136134
$output = $vmssList | Out-String;
137135
Write-Verbose ($output);
@@ -145,13 +143,13 @@ function Test-VirtualMachineScaleSet
145143
Assert-True { $output.Contains("Sku") };
146144

147145
# List All VMs
148-
Write-Verbose ('Running Command : ' + 'Get-AzureRmVmssVMList');
146+
Write-Verbose ('Running Command : ' + 'Get-AzureRmVmssVM List');
149147

150148
$argList = New-AzureComputeArgumentList -MethodName VirtualMachineScaleSetVMsList;
151149
$argList[0].Value = $rgname;
152150
$argList[1].Value = $vmssName;
153151
$args = ($argList | select -ExpandProperty Value);
154-
$vmListResult = Get-AzureRmVmssVMList -ResourceGroupName $rgname -VirtualMachineScaleSetName $vmssName -Select $null;
152+
$vmListResult = Get-AzureRmVmssVM -ResourceGroupName $rgname -VMScaleSetName $vmssName; # -Select $null;
155153
$output = $vmListResult | Out-String;
156154
Write-Verbose ($output);
157155
Assert-True { $output.Contains("StorageProfile") };

src/ResourceManager/Compute/Commands.Compute/Generated/VirtualMachineScaleSet/VirtualMachineScaleSetGetMethod.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,23 @@ protected void ExecuteVirtualMachineScaleSetGetMethod(object[] invokeMethodInput
7979
string resourceGroupName = (string)ParseParameter(invokeMethodInputParameters[0]);
8080
string vmScaleSetName = (string)ParseParameter(invokeMethodInputParameters[1]);
8181

82-
var result = VirtualMachineScaleSetsClient.Get(resourceGroupName, vmScaleSetName);
83-
WriteObject(result);
82+
if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(vmScaleSetName))
83+
{
84+
var result = VirtualMachineScaleSetsClient.Get(resourceGroupName, vmScaleSetName);
85+
WriteObject(result);
86+
}
87+
else if (!string.IsNullOrEmpty(resourceGroupName))
88+
{
89+
var result = VirtualMachineScaleSetsClient.List(resourceGroupName);
90+
WriteObject(result);
91+
}
92+
else
93+
{
94+
var result = VirtualMachineScaleSetsClient.ListAll();
95+
WriteObject(result);
96+
}
8497
}
98+
8599
}
86100

87101
public partial class NewAzureComputeArgumentListCmdlet : ComputeAutomationBaseCmdlet

src/ResourceManager/Compute/Commands.Compute/Generated/VirtualMachineScaleSet/VirtualMachineScaleSetListMethod.cs

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -93,87 +93,4 @@ protected PSArgument[] CreateVirtualMachineScaleSetListParameters()
9393
new object[] { resourceGroupName });
9494
}
9595
}
96-
97-
[Cmdlet("Get", "AzureRmVmssList", DefaultParameterSetName = "InvokeByDynamicParameters")]
98-
public partial class GetAzureRmVMSSList : InvokeAzureComputeMethodCmdlet
99-
{
100-
public GetAzureRmVMSSList()
101-
{
102-
}
103-
104-
public override string MethodName { get; set; }
105-
106-
protected override void ProcessRecord()
107-
{
108-
if (this.ParameterSetName == "InvokeByDynamicParameters")
109-
{
110-
this.MethodName = "VirtualMachineScaleSetList";
111-
}
112-
else
113-
{
114-
this.MethodName = "VirtualMachineScaleSetListAll";
115-
}
116-
base.ProcessRecord();
117-
}
118-
119-
public override object GetDynamicParameters()
120-
{
121-
dynamicParameters = new RuntimeDefinedParameterDictionary();
122-
var pResourceGroupName = new RuntimeDefinedParameter();
123-
pResourceGroupName.Name = "ResourceGroupName";
124-
pResourceGroupName.ParameterType = typeof(string);
125-
pResourceGroupName.Attributes.Add(new ParameterAttribute
126-
{
127-
ParameterSetName = "InvokeByDynamicParameters",
128-
Position = 1,
129-
Mandatory = false
130-
});
131-
pResourceGroupName.Attributes.Add(new ParameterAttribute
132-
{
133-
ParameterSetName = "InvokeByDynamicParametersForFriendMethod",
134-
Position = 1,
135-
Mandatory = false
136-
});
137-
pResourceGroupName.Attributes.Add(new AllowNullAttribute());
138-
dynamicParameters.Add("ResourceGroupName", pResourceGroupName);
139-
140-
var pArgumentList = new RuntimeDefinedParameter();
141-
pArgumentList.Name = "ArgumentList";
142-
pArgumentList.ParameterType = typeof(object[]);
143-
pArgumentList.Attributes.Add(new ParameterAttribute
144-
{
145-
ParameterSetName = "InvokeByStaticParameters",
146-
Position = 2,
147-
Mandatory = true
148-
});
149-
pArgumentList.Attributes.Add(new ParameterAttribute
150-
{
151-
ParameterSetName = "InvokeByStaticParametersForFriendMethod",
152-
Position = 2,
153-
Mandatory = true
154-
});
155-
pArgumentList.Attributes.Add(new AllowNullAttribute());
156-
dynamicParameters.Add("ArgumentList", pArgumentList);
157-
158-
var pAll = new RuntimeDefinedParameter();
159-
pAll.Name = "All";
160-
pAll.ParameterType = typeof(SwitchParameter);
161-
pAll.Attributes.Add(new ParameterAttribute
162-
{
163-
ParameterSetName = "InvokeByDynamicParametersForFriendMethod",
164-
Position = 2,
165-
Mandatory = true
166-
});
167-
pAll.Attributes.Add(new ParameterAttribute
168-
{
169-
ParameterSetName = "InvokeByStaticParametersForFriendMethod",
170-
Position = 3,
171-
Mandatory = true
172-
});
173-
pAll.Attributes.Add(new AllowNullAttribute());
174-
dynamicParameters.Add("All", pAll);
175-
176-
return dynamicParameters;
177-
}
178-
}
17996
}

src/ResourceManager/Compute/Commands.Compute/Generated/VirtualMachineScaleSetVM/VirtualMachineScaleSetVMGetMethod.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,18 @@ protected void ExecuteVirtualMachineScaleSetVMGetMethod(object[] invokeMethodInp
9292
string vmScaleSetName = (string)ParseParameter(invokeMethodInputParameters[1]);
9393
string instanceId = (string)ParseParameter(invokeMethodInputParameters[2]);
9494

95-
var result = VirtualMachineScaleSetVMsClient.Get(resourceGroupName, vmScaleSetName, instanceId);
96-
WriteObject(result);
95+
if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(vmScaleSetName) && !string.IsNullOrEmpty(instanceId))
96+
{
97+
var result = VirtualMachineScaleSetVMsClient.Get(resourceGroupName, vmScaleSetName, instanceId);
98+
WriteObject(result);
99+
}
100+
else if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(vmScaleSetName))
101+
{
102+
var result = VirtualMachineScaleSetVMsClient.List(resourceGroupName, vmScaleSetName);
103+
WriteObject(result);
104+
}
97105
}
106+
98107
}
99108

100109
public partial class NewAzureComputeArgumentListCmdlet : ComputeAutomationBaseCmdlet

src/ResourceManager/Compute/Commands.Compute/Generated/VirtualMachineScaleSetVM/VirtualMachineScaleSetVMListMethod.cs

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -123,74 +123,4 @@ protected PSArgument[] CreateVirtualMachineScaleSetVMListParameters()
123123
new object[] { resourceGroupName, virtualMachineScaleSetName, odataQuery, select });
124124
}
125125
}
126-
127-
[Cmdlet("Get", "AzureRmVmssVMList", DefaultParameterSetName = "InvokeByDynamicParameters")]
128-
public partial class GetAzureRmVMSSVMList : InvokeAzureComputeMethodCmdlet
129-
{
130-
public GetAzureRmVMSSVMList()
131-
{
132-
}
133-
134-
public override string MethodName { get; set; }
135-
136-
protected override void ProcessRecord()
137-
{
138-
this.MethodName = "VirtualMachineScaleSetVMList";
139-
base.ProcessRecord();
140-
}
141-
142-
public override object GetDynamicParameters()
143-
{
144-
dynamicParameters = new RuntimeDefinedParameterDictionary();
145-
var pResourceGroupName = new RuntimeDefinedParameter();
146-
pResourceGroupName.Name = "ResourceGroupName";
147-
pResourceGroupName.ParameterType = typeof(string);
148-
pResourceGroupName.Attributes.Add(new ParameterAttribute
149-
{
150-
ParameterSetName = "InvokeByDynamicParameters",
151-
Position = 1,
152-
Mandatory = false
153-
});
154-
pResourceGroupName.Attributes.Add(new AllowNullAttribute());
155-
dynamicParameters.Add("ResourceGroupName", pResourceGroupName);
156-
157-
var pVirtualMachineScaleSetName = new RuntimeDefinedParameter();
158-
pVirtualMachineScaleSetName.Name = "VirtualMachineScaleSetName";
159-
pVirtualMachineScaleSetName.ParameterType = typeof(string);
160-
pVirtualMachineScaleSetName.Attributes.Add(new ParameterAttribute
161-
{
162-
ParameterSetName = "InvokeByDynamicParameters",
163-
Position = 2,
164-
Mandatory = false
165-
});
166-
pVirtualMachineScaleSetName.Attributes.Add(new AllowNullAttribute());
167-
dynamicParameters.Add("VirtualMachineScaleSetName", pVirtualMachineScaleSetName);
168-
169-
var pSelect = new RuntimeDefinedParameter();
170-
pSelect.Name = "Select";
171-
pSelect.ParameterType = typeof(string);
172-
pSelect.Attributes.Add(new ParameterAttribute
173-
{
174-
ParameterSetName = "InvokeByDynamicParameters",
175-
Position = 3,
176-
Mandatory = false
177-
});
178-
pSelect.Attributes.Add(new AllowNullAttribute());
179-
dynamicParameters.Add("Select", pSelect);
180-
181-
var pArgumentList = new RuntimeDefinedParameter();
182-
pArgumentList.Name = "ArgumentList";
183-
pArgumentList.ParameterType = typeof(object[]);
184-
pArgumentList.Attributes.Add(new ParameterAttribute
185-
{
186-
ParameterSetName = "InvokeByStaticParameters",
187-
Position = 4,
188-
Mandatory = true
189-
});
190-
pArgumentList.Attributes.Add(new AllowNullAttribute());
191-
dynamicParameters.Add("ArgumentList", pArgumentList);
192-
193-
return dynamicParameters;
194-
}
195-
}
196126
}

src/ServiceManagement/Compute/Commands.ServiceManagement.Preview/Automation/Generate-FunctionCommand.ps1

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ param
3434
[System.Reflection.MethodInfo]$FriendMethodInfo = $null,
3535

3636
[Parameter(Mandatory = $false)]
37-
[System.Reflection.MethodInfo]$PageMethodInfo = $null
37+
[System.Reflection.MethodInfo]$PageMethodInfo = $null,
38+
39+
[Parameter(Mandatory = $false)]
40+
[bool]$CombineGetAndList = $false,
41+
42+
[Parameter(Mandatory = $false)]
43+
[bool]$CombineGetAndListAll = $false
3844
)
3945

4046
. "$PSScriptRoot\Import-StringFunction.ps1";
@@ -425,6 +431,63 @@ ${invoke_local_param_code_content}
425431
}
426432
"@;
427433
}
434+
elseif ($methodName -eq 'Get' -and $ModelClassNameSpace -like "*.Azure.Management.*Model*")
435+
{
436+
# Only for ARM Cmdlets
437+
[System.Collections.ArrayList]$paramLocalNameList2 = @();
438+
for ($i2 = 0; $i2 -lt $paramLocalNameList.Count - 1; $i2++)
439+
{
440+
$item2 = $paramLocalNameList[$i2];
441+
$paramLocalNameList2 += $item2;
442+
}
443+
$invoke_cmdlt_source_template = " protected void Execute${invoke_param_set_name}Method(object[] ${invoke_input_params_name})" + $NEW_LINE;
444+
$invoke_cmdlt_source_template += " {" + $NEW_LINE;
445+
$invoke_cmdlt_source_template += "${invoke_local_param_code_content}" + $NEW_LINE;
446+
$invoke_cmdlt_source_template += " if ("
447+
for ($i2 = 0; $i2 -lt $paramLocalNameList.Count; $i2++)
448+
{
449+
if ($i2 -gt 0)
450+
{
451+
$invoke_cmdlt_source_template += " && ";
452+
}
453+
$invoke_cmdlt_source_template += "!string.IsNullOrEmpty(" + $paramLocalNameList[$i2] + ")"
454+
}
455+
$invoke_cmdlt_source_template += ")" + $NEW_LINE;
456+
$invoke_cmdlt_source_template += " {" + $NEW_LINE;
457+
$invoke_cmdlt_source_template += " var result = ${OperationName}Client.${methodName}(${invoke_params_join_str});" + $NEW_LINE;
458+
$invoke_cmdlt_source_template += " WriteObject(result);" + $NEW_LINE;
459+
$invoke_cmdlt_source_template += " }" + $NEW_LINE;
460+
461+
if ($CombineGetAndList)
462+
{
463+
$invoke_params_join_str_for_list = [string]::Join(', ', $paramLocalNameList2.ToArray());
464+
$invoke_cmdlt_source_template += " else if ("
465+
for ($i2 = 0; $i2 -lt $paramLocalNameList2.Count; $i2++)
466+
{
467+
if ($i2 -gt 0)
468+
{
469+
$invoke_cmdlt_source_template += " && ";
470+
}
471+
$invoke_cmdlt_source_template += "!string.IsNullOrEmpty(" + $paramLocalNameList2[$i2] + ")"
472+
}
473+
$invoke_cmdlt_source_template += ")" + $NEW_LINE;
474+
$invoke_cmdlt_source_template += " {" + $NEW_LINE;
475+
$invoke_cmdlt_source_template += " var result = ${OperationName}Client.List(${invoke_params_join_str_for_list});" + $NEW_LINE;
476+
$invoke_cmdlt_source_template += " WriteObject(result);" + $NEW_LINE;
477+
$invoke_cmdlt_source_template += " }" + $NEW_LINE;
478+
}
479+
480+
if ($CombineGetAndListAll)
481+
{
482+
$invoke_cmdlt_source_template += " else" + $NEW_LINE;
483+
$invoke_cmdlt_source_template += " {" + $NEW_LINE;
484+
$invoke_cmdlt_source_template += " var result = ${OperationName}Client.ListAll();" + $NEW_LINE;
485+
$invoke_cmdlt_source_template += " WriteObject(result);" + $NEW_LINE;
486+
$invoke_cmdlt_source_template += " }" + $NEW_LINE;
487+
}
488+
489+
$invoke_cmdlt_source_template += " }" + $NEW_LINE;
490+
}
428491
else
429492
{
430493
$invoke_cmdlt_source_template =

src/ServiceManagement/Compute/Commands.ServiceManagement.Preview/Automation/Import-CommonVariables.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ $component_name = $client_library_namespace.Substring($client_library_namespace.
7979

8080
$all_return_type_names = @();
8181

82-
$SKIP_VERB_NOUN_CMDLET_LIST = @('PowerOff', 'ListNext', 'ListAllNext', 'ListSkusNext', 'GetInstanceView', 'ListAll');
82+
$SKIP_VERB_NOUN_CMDLET_LIST = @('PowerOff', 'ListNext', 'ListAllNext', 'ListSkusNext', 'GetInstanceView', 'List', 'ListAll');
8383

8484
Write-Verbose $BAR_LINE;
8585
Write-Verbose "Input Parameters:";

src/ServiceManagement/Compute/Commands.ServiceManagement.Preview/Automation/RunCodeGeneration.ps1

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,26 @@ else
12641264
{
12651265
$pageMethodMessage = 'Page=' + ($pageMethodInfo.Name.Replace('Async', '')) + '';
12661266
}
1267+
1268+
# Combine Get and List/ListAll Methods (if any)
1269+
$combineGetAndList = $false;
1270+
$combineGetAndListAll = $false;
1271+
if ($mtItem.Name -eq 'Get')
1272+
{
1273+
$methods3 = Get-OperationMethods $operation_type;
1274+
$foundMethod1 = Find-MatchedMethod 'List' $methods3;
1275+
$foundMethod2 = Find-MatchedMethod 'ListAll' $methods3;
1276+
1277+
if ($foundMethod1 -ne $null)
1278+
{
1279+
$combineGetAndList = $true;
1280+
}
1281+
1282+
if ($foundMethod2 -ne $null)
1283+
{
1284+
$combineGetAndListAll = $true;
1285+
}
1286+
}
12671287

12681288
# Output Info for Method Signature
12691289
Write-Verbose "";
@@ -1310,7 +1330,9 @@ else
13101330
-FileOutputFolder $opOutFolder `
13111331
-FunctionCmdletFlavor $opCmdletFlavor `
13121332
-FriendMethodInfo $friendMethodInfo `
1313-
-PageMethodInfo $pageMethodInfo);
1333+
-PageMethodInfo $pageMethodInfo `
1334+
-CombineGetAndList $combineGetAndList `
1335+
-CombineGetAndListAll $combineGetAndListAll );
13141336

13151337
if ($outputs.Count -ne $null)
13161338
{

0 commit comments

Comments
 (0)