diff --git a/src/ResourceManager/Compute/AzureRM.Compute.psd1 b/src/ResourceManager/Compute/AzureRM.Compute.psd1 index c47916898ce6..e09328b9938e 100644 --- a/src/ResourceManager/Compute/AzureRM.Compute.psd1 +++ b/src/ResourceManager/Compute/AzureRM.Compute.psd1 @@ -61,7 +61,8 @@ TypesToProcess = @( # Format files (.ps1xml) to be loaded when importing this module FormatsToProcess = @( '.\Microsoft.Azure.Commands.Compute.format.ps1xml', - '.\Microsoft.Azure.Commands.Compute.format.generated.ps1xml' + '.\Microsoft.Azure.Commands.Compute.format.generated.ps1xml', + '.\Microsoft.Azure.Commands.Compute.Automation.format.generated.ps1xml', ) # Modules to import as nested modules of the module specified in ModuleToProcess diff --git a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineScaleSetTests.ps1 b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineScaleSetTests.ps1 index 6f9bf9b1001c..e7d04fd97100 100644 --- a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineScaleSetTests.ps1 +++ b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineScaleSetTests.ps1 @@ -120,34 +120,66 @@ function Test-VirtualMachineScaleSet $vmss.VirtualMachineProfile.StorageProfile.OSDisk.VirtualHardDiskContainers.Add($vhdContainer); $st = New-AzureVirtualMachineScaleSet -ResourceGroupName $rgname -VirtualMachineScaleSetCreateOrUpdateParameters $vmss; + + Write-Verbose ('Running Command : ' + 'Get-AzureVirtualMachineScaleSet'); $vmssResult = Get-AzureVirtualMachineScaleSet -ResourceGroupName $rgname -VMScaleSetName $vmss.Name; Assert-True { $vmss.Name -eq $vmssResult.VirtualMachineScaleSet.Name }; + $output = $vmssResult | Out-String; + Assert-True { $output.Contains("VirtualMachineScaleSet") }; + Write-Verbose ($output); # List All + Write-Verbose ('Running Command : ' + 'Get-AzureVirtualMachineScaleSetAllList'); $vmssList = Get-AzureVirtualMachineScaleSetAllList -VirtualMachineScaleSetListAllParameters $null; Assert-True { ($vmssList.VirtualMachineScaleSets | select -ExpandProperty Name) -contains $vmss.Name }; + $output = $vmssList | Out-String; + Assert-True { $output.Contains("VirtualMachineScaleSets") }; + Write-Verbose ($output); # List from RG + Write-Verbose ('Running Command : ' + 'Get-AzureVirtualMachineScaleSetList'); $vmssList = Get-AzureVirtualMachineScaleSetList -ResourceGroupName $rgname; Assert-True { ($vmssList.VirtualMachineScaleSets | select -ExpandProperty Name) -contains $vmss.Name }; + $output = $vmssList | Out-String; + Assert-True { $output.Contains("VirtualMachineScaleSets") }; + Write-Verbose ($output); # List Skus + Write-Verbose ('Running Command : ' + 'Get-AzureVirtualMachineScaleSetSkusList'); $skuList = Get-AzureVirtualMachineScaleSetSkusList -ResourceGroupName $rgname -VMScaleSetName $vmss.Name; + $output = $skuList | Out-String; + Assert-True { $output.Contains("VirtualMachineScaleSetSku") }; + Write-Verbose ($output); # List All VMs $vmListParams = New-AzureComputeParameterObject -FriendlyName VirtualMachineScaleSetVMListParameters; $vmListParams.ResourceGroupName = $rgname; $vmListParams.VirtualMachineScaleSetName = $vmss.Name; + + Write-Verbose ('Running Command : ' + 'Get-AzureVirtualMachineScaleSetVMList'); $vmListResult = Get-AzureVirtualMachineScaleSetVMList -VirtualMachineScaleSetVMListParameters $vmListParams; + $output = $vmListResult | Out-String; + Assert-True { $output.Contains("VirtualMachineScaleSetVM") }; + Write-Verbose ($output); + $vmList = $vmListResult.VirtualMachineScaleSetVMs; # List each VM for ($i = 0; $i -lt $vmList.Count; $i++) { + Write-Verbose ('Running Command : ' + 'Get-AzureVirtualMachineScaleSetVM'); $vm = Get-AzureVirtualMachineScaleSetVM -ResourceGroupName $rgname -VMScaleSetName $vmss.Name -InstanceId $i; Assert-NotNull $vm.VirtualMachineScaleSetVM; + $output = $vm | Out-String; + Assert-True { $output.Contains("VirtualMachineScaleSetVM") }; + Write-Verbose ($output); + + Write-Verbose ('Running Command : ' + 'Get-AzureVirtualMachineScaleSetVMInstanceView'); $vmInstance = Get-AzureVirtualMachineScaleSetVMInstanceView -ResourceGroupName $rgname -VMScaleSetName $vmss.Name -InstanceId $i; Assert-NotNull $vmInstance.VirtualMachineScaleSetVMInstanceView; + $output = $vmInstance | Out-String; + Assert-True { $output.Contains("VirtualMachineScaleSetVMInstanceView") }; + Write-Verbose($output); } # List Next (negative test) diff --git a/src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj b/src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj index 0360177df7a5..e1630baba41d 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj +++ b/src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj @@ -376,6 +376,9 @@ AzureRM.Compute.psd1 PreserveNewest + + Always + Always diff --git a/src/ResourceManager/Compute/Commands.Compute/Microsoft.Azure.Commands.Compute.Automation.format.generated.ps1xml b/src/ResourceManager/Compute/Commands.Compute/Microsoft.Azure.Commands.Compute.Automation.format.generated.ps1xml new file mode 100644 index 000000000000..b8dd744e83f2 --- /dev/null +++ b/src/ResourceManager/Compute/Commands.Compute/Microsoft.Azure.Commands.Compute.Automation.format.generated.ps1xml @@ -0,0 +1,299 @@ + + + + + + Microsoft.Azure.Management.Compute.Models.DeleteOperationResponse + + Microsoft.Azure.Management.Compute.Models.DeleteOperationResponse + + + + + + + + EndTime + + + + [Newtonsoft.Json.JsonConvert]::SerializeObject($_.Error, [Newtonsoft.Json.Formatting]::Indented) + + + + StartTime + + + + [Newtonsoft.Json.JsonConvert]::SerializeObject($_.Status, [Newtonsoft.Json.Formatting]::Indented) + + + + TrackingOperationId + + + + AzureAsyncOperation + + + + RequestId + + + + StatusCode + + + + + + + + Microsoft.Azure.Management.Compute.Models.VirtualMachineScaleSetGetResponse + + Microsoft.Azure.Management.Compute.Models.VirtualMachineScaleSetGetResponse + + + + + + + + [Newtonsoft.Json.JsonConvert]::SerializeObject($_.VirtualMachineScaleSet, [Newtonsoft.Json.Formatting]::Indented) + + + + RequestId + + + + StatusCode + + + + + + + + Microsoft.Azure.Management.Compute.Models.VirtualMachineScaleSetListResponse + + Microsoft.Azure.Management.Compute.Models.VirtualMachineScaleSetListResponse + + + + + + + + NextLink + + + + if ($_.VirtualMachineScaleSets -eq $null) { 0 } else { $_.VirtualMachineScaleSets.Count } + + + + foreach ($item in $_.VirtualMachineScaleSets) { [Newtonsoft.Json.JsonConvert]::SerializeObject($item, [Newtonsoft.Json.Formatting]::Indented) } + + + + RequestId + + + + StatusCode + + + + + + + + Microsoft.Azure.Management.Compute.Models.VirtualMachineScaleSet + + Microsoft.Azure.Management.Compute.Models.VirtualMachineScaleSet + + + + + + + + [Newtonsoft.Json.JsonConvert]::SerializeObject($_, [Newtonsoft.Json.Formatting]::Indented) + + + + + + + + Microsoft.Azure.Management.Compute.Models.VirtualMachineScaleSetListSkusResponse + + Microsoft.Azure.Management.Compute.Models.VirtualMachineScaleSetListSkusResponse + + + + + + + + if ($_.VirtualMachineScaleSetAvailableSkus -eq $null) { 0 } else { $_.VirtualMachineScaleSetAvailableSkus.Count } + + + + foreach ($item in $_.VirtualMachineScaleSetAvailableSkus) { [Newtonsoft.Json.JsonConvert]::SerializeObject($item, [Newtonsoft.Json.Formatting]::Indented) } + + + + RequestId + + + + StatusCode + + + + + + + + Microsoft.Azure.Management.Compute.Models.VirtualMachineScaleSetSku + + Microsoft.Azure.Management.Compute.Models.VirtualMachineScaleSetSku + + + + + + + + [Newtonsoft.Json.JsonConvert]::SerializeObject($_, [Newtonsoft.Json.Formatting]::Indented) + + + + + + + + Microsoft.Azure.Management.Compute.Models.VirtualMachineScaleSetVMGetResponse + + Microsoft.Azure.Management.Compute.Models.VirtualMachineScaleSetVMGetResponse + + + + + + + + [Newtonsoft.Json.JsonConvert]::SerializeObject($_.VirtualMachineScaleSetVM, [Newtonsoft.Json.Formatting]::Indented) + + + + RequestId + + + + StatusCode + + + + + + + + Microsoft.Azure.Management.Compute.Models.VirtualMachineScaleSetVMGetInstanceViewResponse + + Microsoft.Azure.Management.Compute.Models.VirtualMachineScaleSetVMGetInstanceViewResponse + + + + + + + + [Newtonsoft.Json.JsonConvert]::SerializeObject($_.VirtualMachineScaleSetVMInstanceView, [Newtonsoft.Json.Formatting]::Indented) + + + + RequestId + + + + StatusCode + + + + + + + + Microsoft.Azure.Management.Compute.Models.VirtualMachineScaleSetVMListResponse + + Microsoft.Azure.Management.Compute.Models.VirtualMachineScaleSetVMListResponse + + + + + + + + if ($_.VirtualMachineScaleSetVMs -eq $null) { 0 } else { $_.VirtualMachineScaleSetVMs.Count } + + + + foreach ($item in $_.VirtualMachineScaleSetVMs) { [Newtonsoft.Json.JsonConvert]::SerializeObject($item, [Newtonsoft.Json.Formatting]::Indented) } + + + + RequestId + + + + StatusCode + + + + + + + + Microsoft.Azure.Management.Compute.Models.VirtualMachineScaleSetVM + + Microsoft.Azure.Management.Compute.Models.VirtualMachineScaleSetVM + + + + + + + + [Newtonsoft.Json.JsonConvert]::SerializeObject($_, [Newtonsoft.Json.Formatting]::Indented) + + + + + + + + diff --git a/src/ResourceManager/Resources/Commands.Resources/AzureResourceManager.psd1 b/src/ResourceManager/Resources/Commands.Resources/AzureResourceManager.psd1 index b5e603879492..504e5f6b3b81 100644 --- a/src/ResourceManager/Resources/Commands.Resources/AzureResourceManager.psd1 +++ b/src/ResourceManager/Resources/Commands.Resources/AzureResourceManager.psd1 @@ -72,6 +72,7 @@ FormatsToProcess = @( '.\AzureRM.StreamAnalytics\Microsoft.Azure.Commands.StreamAnalytics.format.ps1xml', '.\AzureRM.Compute\Microsoft.Azure.Commands.Compute.format.ps1xml', '.\AzureRM.Compute\Microsoft.Azure.Commands.Compute.format.generated.ps1xml', + '.\AzureRM.Compute\Microsoft.Azure.Commands.Compute.Automation.format.generated.ps1xml', '.\AzureRM.Network\Microsoft.Azure.Commands.Network.format.ps1xml', '.\Azure.Storage\Microsoft.WindowsAzure.Commands.Storage.format.ps1xml', '.\AzureRM.StorageManagement\Microsoft.Azure.Commands.Management.Storage.format.ps1xml', diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Preview/Automation/RunCodeGeneration.ps1 b/src/ServiceManagement/Compute/Commands.ServiceManagement.Preview/Automation/RunCodeGeneration.ps1 index c34b376ee7b1..e51cfbae9d02 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Preview/Automation/RunCodeGeneration.ps1 +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Preview/Automation/RunCodeGeneration.ps1 @@ -1754,6 +1754,157 @@ function Get-SubComplexParameterList return Get-SubComplexParameterListFromType $param_info.ParameterType $client_name_space; } +# Get proper type name +function Get-ProperTypeName +{ + param([System.Type] $itemType) + + if ($itemType.IsGenericType -and ($itemType.Name.StartsWith('IList') -or $itemType.Name.StartsWith('List'))) + { + $typeStr = 'IList<' + $itemType.GenericTypeArguments[0].Name + '>'; + } + elseif ($itemType.IsGenericType -and ($itemType.Name.StartsWith('IDictionary') -or $itemType.Name.StartsWith('Dictionary'))) + { + $typeStr = 'IDictionary<' + $itemType.GenericTypeArguments[0].Name + ',' + $itemType.GenericTypeArguments[1].Name + '>'; + } + elseif ($itemType.IsGenericType -and $itemType.Name.StartsWith('Nullable')) + { + $typeStr = $itemType.GenericTypeArguments[0].Name + '?'; + } + else + { + $typeStr = $itemType.Name; + } + + $typeStr = $typeStr.Replace("System.String", "string"); + $typeStr = $typeStr.Replace("String", "string"); + $typeStr = $typeStr.Replace("System.Boolean", "bool"); + $typeStr = $typeStr.Replace("Boolean", "bool"); + $typeStr = $typeStr.Replace("System.UInt32", "uint"); + $typeStr = $typeStr.Replace("UInt32", "uint"); + $typeStr = $typeStr.Replace("System.Int32", "int"); + $typeStr = $typeStr.Replace("Int32", "int"); + + return $typeStr; +} + + +# Process the list return type +function Process-ListType +{ + param([Type] $rt, [System.String] $name) + + $result = $null; + + if ($rt -eq $null) + { + return $result; + } + + $xml = '' + $rt.FullName + ''; + $xml += '' + $rt.FullName + '' + [System.Environment]::NewLine; + $xml += '' + [System.Environment]::NewLine; + + $itemLabel = $itemName = $rt.Name; + $xml += "[Newtonsoft.Json.JsonConvert]::SerializeObject(" + "$" + "_, [Newtonsoft.Json.Formatting]::Indented)" + [System.Environment]::NewLine; + $xml += '' + [System.Environment]::NewLine; + $xml = '' + [System.Environment]::NewLine + $xml + '' + [System.Environment]::NewLine; + + Write-Verbose ("Xml: " + $xml); + + return $xml; +} + +# Process the return type +function Process-ReturnType +{ + param([Type] $rt) + + $result = $null; + + if ($rt -eq $null) + { + return $result; + } + + + if ($rt.Name -like '*LongRunning*' -or $rt.Name -like '*computeoperationresponse*' -or $rt.Name -like '*AzureOperationResponse*') + { + return $result; + } + + $xml = '' + $rt.FullName + ''; + $xml += '' + $rt.FullName + '' + [System.Environment]::NewLine; + $xml += '' + [System.Environment]::NewLine; + + $props = $rt.GetProperties([System.Reflection.BindingFlags]::Public -bor [System.Reflection.BindingFlags]::Instance -bor [System.Reflection.BindingFlags]::Static); + + foreach ($pr1 in $props) + { + $typeStr = Get-ProperTypeName $pr1.PropertyType; + $itemLabel = $itemName = $pr1.Name; + + if ($typeStr -eq 'string' ` + -or $typeStr -eq 'string[]' ` + -or $typeStr -eq 'uint' ` + -or $typeStr -eq 'uint?' ` + -or $typeStr -eq 'int' ` + -or $typeStr -eq 'int?' ` + -or $typeStr -eq 'bool' ` + -or $typeStr -eq 'bool?' ` + -or $typeStr -eq 'DateTime' ` + -or $typeStr -eq 'DateTime?' ` + -or $typeStr -eq 'DateTimeOffset' ` + -or $typeStr -eq 'DateTimeOffset?' ` + -or $typeStr -eq 'HttpStatusCode' ) + { + $xml += "${itemName}" + [System.Environment]::NewLine; + } + elseif ($typeStr.StartsWith('IList') ` + -or $typeStr.StartsWith('IDictionary')) + { + $elementType = $pr1.PropertyType.GenericTypeArguments[0]; + + if (-not $elementType.FullName.Contains("String")) + { + $addxml = Process-ListType -rt $pr1.PropertyType.GenericTypeArguments[0] -name ${itemName}; + } + + $xml += " if (" + "$" + "_.${itemName} -eq $" + "null) { 0 } else { $" + "_.${itemName}.Count }" + [System.Environment]::NewLine; + $xml += " foreach ($" + "item in $" + "_.${itemName}) { [Newtonsoft.Json.JsonConvert]::SerializeObject(" + "$" + "item, [Newtonsoft.Json.Formatting]::Indented) } " + [System.Environment]::NewLine; + } + else + { + $xml += "[Newtonsoft.Json.JsonConvert]::SerializeObject(" + "$" + "_." + ${itemName} + ", [Newtonsoft.Json.Formatting]::Indented)" + [System.Environment]::NewLine; + } + } + + $xml += '' + [System.Environment]::NewLine; + $xml = '' + [System.Environment]::NewLine + $xml + '' + [System.Environment]::NewLine; + + if (-not [System.String]::IsNullOrEmpty($addxml)) + { + $xml += $addxml; + } + + Write-Verbose ("Xml: " + $xml); + + return $xml; +} + +# Get proper type name +function Format-XML ([xml]$xml, $indent = 2) +{ + $StringWriter = New-Object System.IO.StringWriter; + $XmlWriter = New-Object System.XMl.XmlTextWriter $StringWriter; + $xmlWriter.Formatting = "indented"; + $xmlWriter.Indentation = $Indent; + $xml.WriteContentTo($XmlWriter); + $XmlWriter.Flush(); + $StringWriter.Flush(); + Write-Output $StringWriter.ToString(); +} + # Sample: NewAzureVirtualMachineCreateParameters.cs function Write-ParameterCmdletFile { @@ -1927,6 +2078,9 @@ else $dynamic_param_method_code = @(); $invoke_cmdlet_method_code = @(); $parameter_cmdlet_method_code = @(); + $all_return_type_names = @(); + $formatXml = ""; + $cli_command_method_code = @" /** @@ -2025,6 +2179,18 @@ exports.init = function (cli) { } } } + + $rt = $mt.ReturnType.GenericTypeArguments[0]; + + if ($all_return_type_names.Contains($rt.Name)) + { + Write-Verbose("Already Exists: " + $rt.Name); + } + else + { + $all_return_type_names += $rt.Name; + $formatXml += Process-ReturnType -rt $mt.ReturnType.GenericTypeArguments[0]; + } } Write-InvokeCmdletFile $invoke_cmdlet_file_name $invoke_cmdlet_class_name $auto_base_cmdlet_name $clientClassType $filtered_types $invoke_cmdlet_method_code $dynamic_param_method_code; @@ -2042,4 +2208,24 @@ exports.init = function (cli) { Write-Output "============================================="; Write-Output "Finished."; Write-Output "============================================="; + + $outFolder = $outFolder.Replace('/Generated', ""); + $xmlFilePath = ($outFolder + '\' + $code_common_namespace + '.format.generated.ps1xml'); + + Write-Host ('Writing XML Format File: ' + $xmlFilePath); + + $xmlCommentHeader = '' + [System.Environment]::NewLine; + + $xmlContent = [xml]($xmlCommentHeader + '' + [System.Environment]::NewLine + $formatXml + '' + [System.Environment]::NewLine); + $node = $xmlContent.CreateXmlDeclaration('1.0', 'UTF-8', $null); + $xmlContent.InsertBefore($node, $xmlContent.ChildNodes[0]); + + $formattedXmlContent = Format-XML $xmlContent.OuterXml; + Set-Content -Force -Path $xmlFilePath -Value $formattedXmlContent; + Write-Verbose($formattedXmlContent); }