gpt4 book ai didi

azure - 如何使用 Azure 资源管理器选择最新的 Ubuntu 14.04 LTS 镜像?

转载 作者:行者123 更新时间:2023-12-04 19:01:48 26 4
gpt4 key购买 nike

创建经典 Azure VM 时,我可以使用此 PowerShell 找到最新的 Ubuntu 14.04 镜像:

Get-AzureVMImage | where { $_.ImageFamily -eq "Ubuntu Server 14.04 LTS" } | sort PublishedDate -Descending | select -First 1

目前这给了我 14.04.5-LTS,这是完美的。

如何使用资源管理器 PowerShell commandlet 执行相同操作?我能算出的最接近的是:

Get-AzureRMVMImageSku -Location "East US" -Publisher "Canonical" -Offer "UbuntuServer"

返回

Skus              Offer        PublisherName Location Id
---- ----- ------------- -------- --
...
12.10 UbuntuServer Canonical eastus /Subscriptions/3523a95a-af89-4e37-98f5-bdbd56dce1ba/Providers/Microsoft.Compute/Locations/eastus/Publishers/Canonical/ArtifactTypes/VMImage/Offers/UbuntuServer/Skus/12.10
14.04-beta UbuntuServer Canonical eastus /Subscriptions/3523a95a-af89-4e37-98f5-bdbd56dce1ba/Providers/Microsoft.Compute/Locations/eastus/Publishers/Canonical/ArtifactTypes/VMImage/Offers/UbuntuServer/Skus/14.04-beta
14.04.0-LTS UbuntuServer Canonical eastus /Subscriptions/3523a95a-af89-4e37-98f5-bdbd56dce1ba/Providers/Microsoft.Compute/Locations/eastus/Publishers/Canonical/ArtifactTypes/VMImage/Offers/UbuntuServer/Skus/14.04.0-LTS
14.04.1-LTS UbuntuServer Canonical eastus /Subscriptions/3523a95a-af89-4e37-98f5-bdbd56dce1ba/Providers/Microsoft.Compute/Locations/eastus/Publishers/Canonical/ArtifactTypes/VMImage/Offers/UbuntuServer/Skus/14.04.1-LTS
14.04.2-LTS UbuntuServer Canonical eastus /Subscriptions/3523a95a-af89-4e37-98f5-bdbd56dce1ba/Providers/Microsoft.Compute/Locations/eastus/Publishers/Canonical/ArtifactTypes/VMImage/Offers/UbuntuServer/Skus/14.04.2-LTS
14.04.3-LTS UbuntuServer Canonical eastus /Subscriptions/3523a95a-af89-4e37-98f5-bdbd56dce1ba/Providers/Microsoft.Compute/Locations/eastus/Publishers/Canonical/ArtifactTypes/VMImage/Offers/UbuntuServer/Skus/14.04.3-LTS
14.04.4-LTS UbuntuServer Canonical eastus /Subscriptions/3523a95a-af89-4e37-98f5-bdbd56dce1ba/Providers/Microsoft.Compute/Locations/eastus/Publishers/Canonical/ArtifactTypes/VMImage/Offers/UbuntuServer/Skus/14.04.4-LTS
14.04.5-DAILY-LTS UbuntuServer Canonical eastus /Subscriptions/3523a95a-af89-4e37-98f5-bdbd56dce1ba/Providers/Microsoft.Compute/Locations/eastus/Publishers/Canonical/ArtifactTypes/VMImage/Offers/UbuntuServer/Skus/14.04.5-DAILY-LTS
14.04.5-LTS UbuntuServer Canonical eastus /Subscriptions/3523a95a-af89-4e37-98f5-bdbd56dce1ba/Providers/Microsoft.Compute/Locations/eastus/Publishers/Canonical/ArtifactTypes/VMImage/Offers/UbuntuServer/Skus/14.04.5-LTS
14.10 UbuntuServer Canonical eastus /Subscriptions/3523a95a-af89-4e37-98f5-bdbd56dce1ba/Providers/Microsoft.Compute/Locations/eastus/Publishers/Canonical/ArtifactTypes/VMImage/Offers/UbuntuServer/Skus/14.10
14.10-beta UbuntuServer Canonical eastus /Subscriptions/3523a95a-af89-4e37-98f5-bdbd56dce1ba/Providers/Microsoft.Compute/Locations/eastus/Publishers/Canonical/ArtifactTypes/VMImage/Offers/UbuntuServer/Skus/14.10-beta
14.10-DAILY UbuntuServer Canonical eastus /Subscriptions/3523a95a-af89-4e37-98f5-bdbd56dce1ba/Providers/Microsoft.Compute/Locations/eastus/Publishers/Canonical/ArtifactTypes/VMImage/Offers/UbuntuServer/Skus/14.10-DAILY
15.04 UbuntuServer Canonical eastus /Subscriptions/3523a95a-af89-4e37-98f5-bdbd56dce1ba/Providers/Microsoft.Compute/Locations/eastus/Publishers/Canonical/ArtifactTypes/VMImage/Offers/UbuntuServer/Skus/15.04
...

我想我可以 grep 出最后一个 ^14.04(.\d+)?-LTS$,但我不喜欢依赖保持不变的命名约定。 classic的ImageFamily和PublishedDate在哪里?

最佳答案

在ARM模块中,图像没有PublishedDate,我们可以使用sku列出最新的:

Get-AzureRmVMImageSku -Location "East Us" -PublisherName "canonical" -Offer "UbuntuServer" | ?{($_.skus -like '14.04.*-lts') -and ($_.skus -notlike '14.04.*-da*')} | Sort-Object -Descending skus | select -First 1

enter image description here

$a = (Get-AzureRmVMImageSku -Location "East Us" -PublisherName "canonical" -Offer "UbuntuServer" | ?{($_.skus -like '14.04.*-lts') -and ($_.skus -notlike '14.04.*-da*')} | Sort-Object skus).skus
$b = ([int[]](($a -split '-' -split 'LTS' -split '14.04.') | sort -Descending)) | select -Unique | select -First 1
$c = '14.04.'+$b+'-LTS'
Get-AzureRmVMImageSku -Location "East Us" -PublisherName "canonical" -Offer "UbuntuServer" | ?{($_.skus -eq $c)}

enter image description here

更新:
你是对的,依赖命名方案是一个坏主意。我发现在Azure ARM模块中,我们可以使用Get-AzureRmVMImage |排序对象-降序-属性发布日期:

$ossku = "16.04-beta"
Get-AzureRmVMImage -Location "East Us" -PublisherName 'canonical' -Offer 'UbuntuServer' -Skus $osSKU | Sort-Object -Descending -Property PublishedDate
Version FilterExpression Skus Offer PublisherName Location Id
------- ---------------- ---- ----- ------------- -------- --
16.04.201603220 16.04-beta UbuntuServer canonical eastus /Subscriptions/53847bbb-222b-49c3-9488-0361e29a7b15/Providers/Microsoft.Compute/Locations/eastus/Publishers/canonical/ArtifactTypes/VMImage/Of...
16.04.201602231 16.04-beta UbuntuServer canonical eastus /Subscriptions/53847bbb-222b-49c3-9488-0361e29a7b15/Providers/Microsoft.Compute/Locations/eastus/Publishers/canonical/ArtifactTypes/VMImage/Of...

关于azure - 如何使用 Azure 资源管理器选择最新的 Ubuntu 14.04 LTS 镜像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41478123/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com