Skip to content
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

Fix a bug in container instance #15235

Closed
Closed
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
7 changes: 2 additions & 5 deletions src/ContainerInstance/Az.ContainerInstance.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Microsoft Corporation
#
# Generated on: 5/20/2021
# Generated on: 6/10/2021
#

@{
Expand Down Expand Up @@ -121,10 +121,7 @@ PrivateData = @{
# IconUri = ''

# ReleaseNotes of this module
ReleaseNotes = '* Added new cmdlets: ''Start-AzContainerGroup'', ''Stop-AzContainerGroup'' [#10773], ''Invoke-AzContainerInstanceCommand'' [#7648], ''Update-AzContainerGroup'', ''Add-AzContainerInstanceOutput'', ''Get-AzContainerInstanceCachedImage'', ''Get-AzContainerInstanceCapability'', ''Get-AzContainerInstanceUsage'', ''New-AzContainerGroupImageRegistryCredentialObject'', ''New-AzContainerGroupPortObject'', ''New-AzContainerGroupVolumeObject'', ''New-AzContainerInstanceEnvironmentVariableObject'', ''New-AzContainerInstanceInitDefinitionObject'', ''New-AzContainerInstanceObject'', ''New-AzContainerInstancePortObject'' and ''New-AzContainerInstanceVolumeMountObject''
* Supported Log Analytics parameters in ''New-AzContainerGroup'' [#11117]
* Added support to specify network profile and the name of Azure File Share in ''New-AzContainerGroup'' [#9993] [#12218]
* Added support to specify environment variables as SecureValue [#10110] [#10640]'
# ReleaseNotes = ''

# Prerelease string of this module
# Prerelease = ''
Expand Down
5 changes: 4 additions & 1 deletion src/ContainerInstance/build-module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ $null = New-Item -ItemType Directory -Force -Path $examplesFolder

Write-Host -ForegroundColor Green 'Creating cmdlets for specified models...'
$modelCmdlets = @()
. (Join-Path $PSScriptRoot 'create-model-cmdlets.ps1') -Models $modelCmdlets
if ($modelCmdlets.Count -gt 0) {
. (Join-Path $PSScriptRoot 'create-model-cmdlets.ps1')
CreateModelCmdlet($modelCmdlets)
}

if($NoDocs) {
Write-Host -ForegroundColor Green 'Creating exports...'
Expand Down
251 changes: 127 additions & 124 deletions src/ContainerInstance/create-model-cmdlets.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,154 +12,157 @@
# limitations under the License.
# ----------------------------------------------------------------------------------

param([string[]]$Models)
function CreateModelCmdlet {

if ($Models.Count -eq 0)
{
return
}
param([string[]]$Models)

$ModelCsPath = Join-Path (Join-Path $PSScriptRoot 'generated\api') 'Models'
$ModuleName = 'Az.ContainerInstance'.Split(".")[1]
$OutputDir = Join-Path $PSScriptRoot 'custom\autogen-model-cmdlets'
$null = New-Item -ItemType Directory -Force -Path $OutputDir
if ($Models.Count -eq 0)
{
return
}

$CsFiles = Get-ChildItem -Path $ModelCsPath -Recurse -Filter *.cs
$Content = ''
$null = $CsFiles | ForEach-Object -Process { if ($_.Name.Split('.').count -eq 2 )
{ $Content += get-content $_.fullname -raw
} }
$ModelCsPath = Join-Path (Join-Path $PSScriptRoot 'generated\api') 'Models'
$ModuleName = 'Az.ContainerInstance'.Split(".")[1]
$OutputDir = Join-Path $PSScriptRoot 'custom\autogen-model-cmdlets'
$null = New-Item -ItemType Directory -Force -Path $OutputDir

$Tree = [Microsoft.CodeAnalysis.CSharp.SyntaxFactory]::ParseCompilationUnit($Content)
$Nodes = $Tree.ChildNodes().ChildNodes()
foreach ($Model in $Models)
{
$InterfaceNode = $Nodes | Where-Object { ($_.Keyword.value -eq 'interface') -and ($_.Identifier.value -eq "I$Model") }
if ($InterfaceNode.count -eq 0) {
continue
}
# through a queue, we iterate all the parent models.
$Queue = @($InterfaceNode)
$visited = @("I$Model")
$AllInterfaceNodes = @()
while ($Queue.count -ne 0)
$CsFiles = Get-ChildItem -Path $ModelCsPath -Recurse -Filter *.cs
$Content = ''
$null = $CsFiles | ForEach-Object -Process { if ($_.Name.Split('.').count -eq 2 )
{ $Content += get-content $_.fullname -raw
} }

$Tree = [Microsoft.CodeAnalysis.CSharp.SyntaxFactory]::ParseCompilationUnit($Content)
$Nodes = $Tree.ChildNodes().ChildNodes()
foreach ($Model in $Models)
{
$AllInterfaceNodes += $Queue[0]
# Baselist contains the direct parent models.
foreach ($parent in $Queue[0].BaseList.Types)
$InterfaceNode = $Nodes | Where-Object { ($_.Keyword.value -eq 'interface') -and ($_.Identifier.value -eq "I$Model") }
if ($InterfaceNode.count -eq 0) {
continue
}
# through a queue, we iterate all the parent models.
$Queue = @($InterfaceNode)
$visited = @("I$Model")
$AllInterfaceNodes = @()
while ($Queue.count -ne 0)
{
if (($parent.Type.Right.Identifier.Value -ne 'IJsonSerializable') -and (-not $visited.Contains($parent.Type.Right.Identifier.Value)))
$AllInterfaceNodes += $Queue[0]
# Baselist contains the direct parent models.
foreach ($parent in $Queue[0].BaseList.Types)
{
$Queue = [Array]$Queue + ($Nodes | Where-Object { ($_.Keyword.value -eq 'interface') -and ($_.Identifier.value -eq $parent.Type.Right.Identifier.Value) })
$visited = [Array]$visited + $parent.Type.Right.Identifier.Value
if (($parent.Type.Right.Identifier.Value -ne 'IJsonSerializable') -and (-not $visited.Contains($parent.Type.Right.Identifier.Value)))
{
$Queue = [Array]$Queue + ($Nodes | Where-Object { ($_.Keyword.value -eq 'interface') -and ($_.Identifier.value -eq $parent.Type.Right.Identifier.Value) })
$visited = [Array]$visited + $parent.Type.Right.Identifier.Value
}
}
$first, $Queue = $Queue
}
$first, $Queue = $Queue
}

$Namespace = $InterfaceNode.Parent.Name
$ObjectType = $Model
$ObjectTypeWithNamespace = "${Namespace}.${ObjectType}"
# remove duplicated module name
if ($ObjectType.StartsWith($ModuleName)) {
$ModulePrefix = ''
} else {
$ModulePrefix = $ModuleName
}
$OutputPath = Join-Path -ChildPath "New-Az${ModulePrefix}${ObjectType}Object.ps1" -Path $OutputDir
$Namespace = $InterfaceNode.Parent.Name
$ObjectType = $Model
$ObjectTypeWithNamespace = "${Namespace}.${ObjectType}"
# remove duplicated module name
if ($ObjectType.StartsWith($ModuleName)) {
$ModulePrefix = ''
} else {
$ModulePrefix = $ModuleName
}
$OutputPath = Join-Path -ChildPath "New-Az${ModulePrefix}${ObjectType}Object.ps1" -Path $OutputDir

$ParameterDefineScriptList = New-Object System.Collections.Generic.List[string]
$ParameterAssignScriptList = New-Object System.Collections.Generic.List[string]
foreach ($Node in $AllInterfaceNodes)
{
foreach ($Member in $Node.Members)
$ParameterDefineScriptList = New-Object System.Collections.Generic.List[string]
$ParameterAssignScriptList = New-Object System.Collections.Generic.List[string]
foreach ($Node in $AllInterfaceNodes)
{
$Arguments = $Member.AttributeLists.Attributes.ArgumentList.Arguments
$Required = $false
$Description = ""
$Readonly = $False
foreach ($Argument in $Arguments)
foreach ($Member in $Node.Members)
{
if ($Argument.NameEquals.Name.Identifier.Value -eq "Required")
$Arguments = $Member.AttributeLists.Attributes.ArgumentList.Arguments
$Required = $false
$Description = ""
$Readonly = $False
foreach ($Argument in $Arguments)
{
$Required = $Argument.Expression.Token.Value
if ($Argument.NameEquals.Name.Identifier.Value -eq "Required")
{
$Required = $Argument.Expression.Token.Value
}
if ($Argument.NameEquals.Name.Identifier.Value -eq "Description")
{
$Description = $Argument.Expression.Token.Value.Trim('.').replace('"', '`"')
}
if ($Argument.NameEquals.Name.Identifier.Value -eq "Readonly")
{
$Readonly = $Argument.Expression.Token.Value
}
}
if ($Argument.NameEquals.Name.Identifier.Value -eq "Description")
if ($Readonly)
{
$Description = $Argument.Expression.Token.Value.Trim('.').replace('"', '`"')
continue
}
if ($Argument.NameEquals.Name.Identifier.Value -eq "Readonly")
$Identifier = $Member.Identifier.Value
$Type = $Member.Type.ToString().replace('?', '').Split("::")[-1]
$ParameterDefinePropertyList = New-Object System.Collections.Generic.List[string]
if ($Required)
{
$Readonly = $Argument.Expression.Token.Value
$ParameterDefinePropertyList.Add("Mandatory")
}
if ($Description -ne "")
{
$ParameterDefinePropertyList.Add("HelpMessage=`"${Description}.`"")
}
$ParameterDefineProperty = [System.String]::Join(", ", $ParameterDefinePropertyList)
$ParameterDefineScript = "
[Parameter($ParameterDefineProperty)]
[${Type}]
`$${Identifier}"
$ParameterDefineScriptList.Add($ParameterDefineScript)
$ParameterAssignScriptList.Add("
`$Object.${Identifier} = `$${Identifier}")
}
if ($Readonly)
{
continue
}
$Identifier = $Member.Identifier.Value
$Type = $Member.Type.ToString().replace('?', '').Split("::")[-1]
$ParameterDefinePropertyList = New-Object System.Collections.Generic.List[string]
if ($Required)
{
$ParameterDefinePropertyList.Add("Mandatory")
}
if ($Description -ne "")
{
$ParameterDefinePropertyList.Add("HelpMessage=`"${Description}.`"")
}
$ParameterDefineProperty = [System.String]::Join(", ", $ParameterDefinePropertyList)
$ParameterDefineScript = "
[Parameter($ParameterDefineProperty)]
[${Type}]
`$${Identifier}"
$ParameterDefineScriptList.Add($ParameterDefineScript)
$ParameterAssignScriptList.Add("
`$Object.${Identifier} = `$${Identifier}")
}
}
$ParameterDefineScript = $ParameterDefineScriptList | Join-String -Separator ","
$ParameterAssignScript = $ParameterAssignScriptList | Join-String -Separator ""
$ParameterDefineScript = $ParameterDefineScriptList | Join-String -Separator ","
$ParameterAssignScript = $ParameterAssignScriptList | Join-String -Separator ""

$Script = "
# ----------------------------------------------------------------------------------
#
# 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.
# ----------------------------------------------------------------------------------
$Script = "
# ----------------------------------------------------------------------------------
#
# 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.
# ----------------------------------------------------------------------------------

<#
.Synopsis
Create a in-memory object for ${ObjectType}
.Description
Create a in-memory object for ${ObjectType}
<#
.Synopsis
Create a in-memory object for ${ObjectType}
.Description
Create a in-memory object for ${ObjectType}

.Outputs
${ObjectTypeWithNamespace}
.Link
https://docs.microsoft.com/powershell/module/az.${ModuleName}/new-Az${ModulePrefix}${ObjectType}Object
#>
function New-Az${ModulePrefix}${ObjectType}Object {
[OutputType('${ObjectTypeWithNamespace}')]
[CmdletBinding(PositionalBinding=`$false)]
Param(
${ParameterDefineScript}
)
.Outputs
${ObjectTypeWithNamespace}
.Link
https://docs.microsoft.com/powershell/module/az.${ModuleName}/new-Az${ModulePrefix}${ObjectType}Object
#>
function New-Az${ModulePrefix}${ObjectType}Object {
[OutputType('${ObjectTypeWithNamespace}')]
[CmdletBinding(PositionalBinding=`$false)]
Param(
${ParameterDefineScript}
)

process {
`$Object = [${ObjectTypeWithNamespace}]::New()
${ParameterAssignScript}
return `$Object
process {
`$Object = [${ObjectTypeWithNamespace}]::New()
${ParameterAssignScript}
return `$Object
}
}
"
Set-Content -Path $OutputPath -Value $Script
}
}
"
Set-Content -Path $OutputPath -Value $Script
}
10 changes: 5 additions & 5 deletions src/ContainerInstance/generate-info.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"node": "v14.15.5",
"autorest_powershell": "3.0.434",
"autorest_core": "3.0.6375",
"autorest_modelerfour": "4.15.414",
"swagger_commit": "3f1d9a2fd7d79c0e10cca4a4750a00e725ddc541",
"autorest": "`-- (empty)",
"autorest_powershell": "3.0.428",
"autorest_core": "3.4.2"
"node": "v10.15.3",
"swagger_commit": "5d011b57ab387ed9b2eff5b6f17857476cf19d86",
"autorest": "3.0.6187"
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ internal Capabilities(global::System.Collections.IDictionary content)
((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).Location = (string) content.GetValueForProperty("Location",((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).Location, global::System.Convert.ToString);
((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).IPAddressType = (string) content.GetValueForProperty("IPAddressType",((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).IPAddressType, global::System.Convert.ToString);
((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).Gpu = (string) content.GetValueForProperty("Gpu",((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).Gpu, global::System.Convert.ToString);
((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).CapabilityMaxCpu = (float?) content.GetValueForProperty("CapabilityMaxCpu",((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).CapabilityMaxCpu, (__y)=> (float) global::System.Convert.ChangeType(__y, typeof(float)));
((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).CapabilityMaxMemoryInGb = (float?) content.GetValueForProperty("CapabilityMaxMemoryInGb",((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).CapabilityMaxMemoryInGb, (__y)=> (float) global::System.Convert.ChangeType(__y, typeof(float)));
((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).CapabilityMaxCpu = (float?) content.GetValueForProperty("CapabilityMaxCpu",((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).CapabilityMaxCpu, (__y)=> (float) global::System.Convert.ChangeType(__y, typeof(float)));
((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).CapabilityMaxGpuCount = (float?) content.GetValueForProperty("CapabilityMaxGpuCount",((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).CapabilityMaxGpuCount, (__y)=> (float) global::System.Convert.ChangeType(__y, typeof(float)));
AfterDeserializeDictionary(content);
}
Expand All @@ -101,8 +101,8 @@ internal Capabilities(global::System.Management.Automation.PSObject content)
((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).Location = (string) content.GetValueForProperty("Location",((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).Location, global::System.Convert.ToString);
((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).IPAddressType = (string) content.GetValueForProperty("IPAddressType",((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).IPAddressType, global::System.Convert.ToString);
((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).Gpu = (string) content.GetValueForProperty("Gpu",((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).Gpu, global::System.Convert.ToString);
((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).CapabilityMaxCpu = (float?) content.GetValueForProperty("CapabilityMaxCpu",((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).CapabilityMaxCpu, (__y)=> (float) global::System.Convert.ChangeType(__y, typeof(float)));
((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).CapabilityMaxMemoryInGb = (float?) content.GetValueForProperty("CapabilityMaxMemoryInGb",((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).CapabilityMaxMemoryInGb, (__y)=> (float) global::System.Convert.ChangeType(__y, typeof(float)));
((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).CapabilityMaxCpu = (float?) content.GetValueForProperty("CapabilityMaxCpu",((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).CapabilityMaxCpu, (__y)=> (float) global::System.Convert.ChangeType(__y, typeof(float)));
((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).CapabilityMaxGpuCount = (float?) content.GetValueForProperty("CapabilityMaxGpuCount",((Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210301.ICapabilitiesInternal)this).CapabilityMaxGpuCount, (__y)=> (float) global::System.Convert.ChangeType(__y, typeof(float)));
AfterDeserializePSObject(content);
}
Expand Down
Loading