Skip to content

Commit 170c30e

Browse files
committed
Merge pull request #33 from huangpf/vmss
Vmss
2 parents 6ca7f85 + 190032d commit 170c30e

File tree

9 files changed

+19560
-6
lines changed

9 files changed

+19560
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.0.19.2-preview\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
6868
</Reference>
6969
<Reference Include="Microsoft.Azure.Management.Compute, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
70-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Compute.9.0.2-preview\lib\net40\Microsoft.Azure.Management.Compute.dll</HintPath>
70+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Compute.9.0.3-preview\lib\net40\Microsoft.Azure.Management.Compute.dll</HintPath>
7171
<Private>True</Private>
7272
</Reference>
7373
<Reference Include="Microsoft.Azure.Management.Network, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.0.19.2-preview\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
7979
</Reference>
8080
<Reference Include="Microsoft.Azure.Management.Compute, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
81-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Compute.9.0.2-preview\lib\net40\Microsoft.Azure.Management.Compute.dll</HintPath>
81+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Compute.9.0.3-preview\lib\net40\Microsoft.Azure.Management.Compute.dll</HintPath>
8282
<Private>True</Private>
8383
</Reference>
8484
<Reference Include="Microsoft.Azure.Management.Network, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">

src/ResourceManager/Compute/Commands.Compute/Generated/cli.js

Lines changed: 352 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 133 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,33 @@ function Get-NormalizedName
162162
return $outputName;
163163
}
164164

165+
function Get-UnnormalizedName
166+
{
167+
# Sample: 'VMName' to 'vmName', 'VirtualMachine' => 'virtualMachine', 'ResourceGroup' => 'resourceGroup', etc.
168+
param(
169+
[Parameter(Mandatory = $True)]
170+
[string]$inputName
171+
)
172+
173+
if ([string]::IsNullOrEmpty($inputName))
174+
{
175+
return $inputName;
176+
}
177+
178+
if ($inputName.StartsWith('VM'))
179+
{
180+
$outputName = 'vm' + $inputName.Substring(2);
181+
}
182+
else
183+
{
184+
[char]$firstChar = $inputName[0];
185+
$firstChar = [System.Char]::ToLower($firstChar);
186+
$outputName = $firstChar + $inputName.Substring(1);
187+
}
188+
189+
return $outputName;
190+
}
191+
165192
function Get-NormalizedTypeName
166193
{
167194
param(
@@ -1289,6 +1316,7 @@ function Write-OperationCmdletFile
12891316
[System.Collections.ArrayList]$invoke_param_names = @();
12901317
[System.Collections.ArrayList]$invoke_local_param_names = @();
12911318
[System.Collections.ArrayList]$create_local_param_names = @();
1319+
[System.Collections.ArrayList]$cli_command_param_names = @();
12921320
$position_index = 1;
12931321
foreach ($pt in $params)
12941322
{
@@ -1537,6 +1565,49 @@ ${cmdlet_partial_class_code}
15371565
Write-Output $dynamic_param_source_template;
15381566
Write-Output $invoke_cmdlt_source_template;
15391567
Write-Output $parameter_cmdlt_source_template;
1568+
1569+
# CLI Code
1570+
$cli_op_name = Get-UnnormalizedName $opShortName;
1571+
$cli_method_name = Get-UnnormalizedName $methodName;
1572+
1573+
$cli_op_code_content = "//" + $opShortName + "." + $methodName + $new_line_str;
1574+
$component_name = 'compute';
1575+
$cli_op_code_content += "var $opShortName = compute.category('$cli_op_name').description(`$('Commands for Azure Compute'));";
1576+
1577+
$cli_op_code_content += "${opShortName}.command('${methodName}')" + $new_line_str;
1578+
$cli_op_code_content += ".description(`$('${opShortName} ${methodName}'))" + $new_line_str;
1579+
$cli_op_code_content += ".usage('[options]')" + $new_line_str;
1580+
for ($index = 0; $index -lt $param_names.Count; $index++)
1581+
{
1582+
$cli_param_name = $param_names[$index];
1583+
$cli_op_code_content += ".option('--${cli_param_name} <${cli_param_name}>', `$('${cli_param_name}'))" + $new_line_str;
1584+
}
1585+
$cli_op_code_content += ".option('-s, --subscription <subscription>', `$('the subscription identifier'))" + $new_line_str;
1586+
$cli_op_code_content += ".execute(function ("
1587+
for ($index = 0; $index -lt $param_names.Count; $index++)
1588+
{
1589+
if ($index -gt 0) { $cli_op_code_content += ", "; }
1590+
$cli_param_name = $param_names[$index];
1591+
$cli_op_code_content += "$cli_param_name";
1592+
}
1593+
$cli_op_code_content += ", options, _) {" + $new_line_str;
1594+
$cli_op_code_content += " var subscription = profile.current.getSubscription(options.subscription);" + $new_line_str;
1595+
$cli_op_code_content += " var computeManagementClient = utils.createComputeResourceProviderClient(subscription);" + $new_line_str;
1596+
$cli_op_code_content += " var result = computeManagementClient.${cli_op_name}s.${cli_method_name}(";
1597+
for ($index = 0; $index -lt $param_names.Count; $index++)
1598+
{
1599+
if ($index -gt 0) { $cli_op_code_content += ", "; }
1600+
$cli_param_name = $param_names[$index];
1601+
$cli_op_code_content += "$cli_param_name";
1602+
}
1603+
$cli_op_code_content += ", _);" + $new_line_str;
1604+
$cli_op_code_content += " cli.output.json(result);" + $new_line_str;
1605+
$cli_op_code_content += "});" + $new_line_str;
1606+
1607+
1608+
1609+
1610+
Write-Output $cli_op_code_content;
15401611
}
15411612

15421613
# Sample: VirtualMachineCreateParameters
@@ -1784,6 +1855,23 @@ ${cmdlet_generated_code}
17841855
$st = Set-Content -Path $file_full_path -Value $cmdlt_source_template -Force;
17851856
}
17861857

1858+
1859+
# Sample: NewAzureVirtualMachineCreateParameters.cs
1860+
function Write-CLICommandFile
1861+
{
1862+
param(
1863+
[Parameter(Mandatory = $True)]
1864+
[string]$fileOutputFolder,
1865+
1866+
[Parameter(Mandatory = $True)]
1867+
$commandCodeLines
1868+
)
1869+
1870+
$fileFullPath = $fileOutputFolder + '/' + 'cli.js';
1871+
1872+
$st = Set-Content -Path $fileFullPath -Value $commandCodeLines -Force;
1873+
}
1874+
17871875
# Code Generation Main Run
17881876
$outFolder += '/Generated';
17891877

@@ -1839,6 +1927,40 @@ else
18391927
$dynamic_param_method_code = @();
18401928
$invoke_cmdlet_method_code = @();
18411929
$parameter_cmdlet_method_code = @();
1930+
$cli_command_method_code =
1931+
@"
1932+
/**
1933+
* Copyright (c) Microsoft. All rights reserved.
1934+
*
1935+
* Licensed under the Apache License, Version 2.0 (the "License");
1936+
* you may not use this file except in compliance with the License.
1937+
* You may obtain a copy of the License at
1938+
* http://www.apache.org/licenses/LICENSE-2.0
1939+
*
1940+
* Unless required by applicable law or agreed to in writing, software
1941+
* distributed under the License is distributed on an "AS IS" BASIS,
1942+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1943+
* See the License for the specific language governing permissions and
1944+
* limitations under the License.
1945+
*/
1946+
1947+
'use strict';
1948+
1949+
var __ = require('underscore');
1950+
var util = require('util');
1951+
1952+
var profile = require('../../../util/profile');
1953+
var utils = require('../../../util/utils');
1954+
1955+
var $ = utils.getLocaleString;
1956+
1957+
exports.init = function (cli) {
1958+
1959+
var compute = cli.category('compute')
1960+
.description(`$('Commands for Azure Compute'));
1961+
1962+
1963+
"@;
18421964

18431965
# Write Operation Cmdlet Files
18441966
foreach ($ft in $filtered_types)
@@ -1869,9 +1991,10 @@ else
18691991
$outputs = Write-OperationCmdletFile $opOutFolder $opShortName $mt $invoke_cmdlet_class_name $parameter_cmdlet_class_name;
18701992
if ($outputs.Count -ne $null)
18711993
{
1872-
$dynamic_param_method_code += $outputs[-3];
1873-
$invoke_cmdlet_method_code += $outputs[-2];
1874-
$parameter_cmdlet_method_code += $outputs[-1];
1994+
$dynamic_param_method_code += $outputs[-4];
1995+
$invoke_cmdlet_method_code += $outputs[-3];
1996+
$parameter_cmdlet_method_code += $outputs[-2];
1997+
$cli_command_method_code += $outputs[-1];
18751998
}
18761999

18772000
[System.Reflection.ParameterInfo]$parameter_type_info = (Get-MethodComplexParameter $mt $client_library_namespace);
@@ -1909,6 +2032,13 @@ else
19092032
Write-NewParameterObjectCmdletFile $new_object_cmdlet_file_name $new_object_cmdlet_class_name $auto_base_cmdlet_name $clientClassType $filtered_types $parameter_cmdlet_method_code;
19102033
}
19112034

2035+
# CLI
2036+
$cli_command_method_code += $new_line_str + "};";
2037+
if ($cmdletFlavor -eq 'CLI')
2038+
{
2039+
Write-CLICommandFile $outFolder $cli_command_method_code;
2040+
}
2041+
19122042
Write-Output "=============================================";
19132043
Write-Output "Finished.";
19142044
Write-Output "=============================================";

src/ServiceManagement/Compute/Commands.ServiceManagement.Preview/Commands.ServiceManagement.Preview.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>
7575
</Reference>
7676
<Reference Include="Microsoft.Azure.Management.Compute, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
77-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Compute.9.0.2-preview\lib\net40\Microsoft.Azure.Management.Compute.dll</HintPath>
77+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Compute.9.0.3-preview\lib\net40\Microsoft.Azure.Management.Compute.dll</HintPath>
7878
<Private>True</Private>
7979
</Reference>
8080
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">

0 commit comments

Comments
 (0)