若要在 Azure 门户中查看已发布的 VM 应用程序的属性,请执行以下作:
- 登录到 Azure 门户。
- 搜索 Azure 计算画廊。
- 选择包含虚拟机应用程序的图库。
- 单击要查看的 VM 应用程序名称 。
-
概述/属性 面板显示有关 VM 应用的信息。
- “ 概述/版本 ”边栏选项卡显示所有已发布版本及其基本属性,如目标区域、预配状态和复制状态。
- 选择 特定版本 以查看其所有详细信息。
使用 REST API 查看已发布的 VM 应用程序或特定版本的属性:
获取 VM 应用程序详细信息:
GET
https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{galleryApplicationName}?api-version=2024-03-03
示例响应:
{
"id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{galleryApplicationName}",
"name": "{galleryApplicationName}",
"type": "Microsoft.Compute/galleries/applications",
"location": "chinanorth2",
"properties": {
"description": "Sample VM Application",
"provisioningState": "Succeeded",
"supportedOSTypes": ["Windows", "Linux"],
"endOfLifeDate": null,
"privacyStatementUri": "https://contoso.com/privacy",
"releaseNoteUri": "https://contoso.com/release-notes"
}
}
获取 VM 应用程序版本详细信息:
GET
https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{galleryApplicationName}/versions/{galleryApplicationVersionName}?api-version=2024-03-03
示例响应:
{
"id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{galleryApplicationName}/versions/{galleryApplicationVersionName}",
"name": "{galleryApplicationVersionName}",
"type": "Microsoft.Compute/galleries/applications/versions",
"location": "chinanorth2",
"properties": {
"provisioningState": "Succeeded",
"publishingProfile": {
"source": {
"mediaLink": "https://storageaccount.blob.core.chinacloudapi.cn/vmapps/app.zip"
},
"replicaCount": 1,
"targetRegions": [
{
"name": "chinanorth",
"regionalReplicaCount": 1
}
]
},
"storageAccountType": "Standard_LRS"
}
}
响应包括有关应用程序或版本的属性,例如名称、位置、预配状态、说明和其他元数据。
设置变量:
rgName="myResourceGroup"
galleryName="myGallery"
appName="myVmApp"
versionName="1.0.0"
列出库中的所有 VM 应用程序:
az sig gallery-application list \
--resource-group $rgName \
--gallery-name $galleryName \
-o table
显示 VM 应用程序的属性:
az sig gallery-application show \
--resource-group $rgName \
--gallery-name $galleryName \
--application-name $appName
列出 VM 应用程序的所有版本:
az sig gallery-application version list \
--resource-group $rgName \
--gallery-name $galleryName \
--application-name $appName \
--query "[].{version:name, provisioningState:properties.provisioningState}" -o table
显示特定 VM 应用程序版本的属性:
az sig gallery-application version show \
--resource-group $rgName \
--gallery-name $galleryName \
--application-name $appName \
--version-name $versionName
使用 Azure PowerShell 查看 Azure 计算库中的 VM 应用程序和版本详细信息。
设置变量:
$rgName = "myResourceGroup"
$galleryName = "myGallery"
$appName = "myVmApp"
$versionName = "1.0.0"
列出库中的所有 VM 应用程序:
Get-AzGalleryApplication `
-ResourceGroupName $rgName `
-GalleryName $galleryName |
Select-Object Name, Location, ProvisioningState
显示 VM 应用程序的属性:
Get-AzGalleryApplication `
-ResourceGroupName $rgName `
-GalleryName $galleryName `
-Name $appName |
ConvertTo-Json -Depth 5
列出 VM 应用程序的所有版本:
Get-AzGalleryApplicationVersion `
-ResourceGroupName $rgName `
-GalleryName $galleryName `
-GalleryApplicationName $appName |
Select-Object Name, @{n="ProvisioningState";e={$_.ProvisioningState}}
显示特定 VM 应用程序版本的属性:
Get-AzGalleryApplicationVersion `
-ResourceGroupName $rgName `
-GalleryName $galleryName `
-GalleryApplicationName $appName `
-Name $versionName |
ConvertTo-Json -Depth 6
若要显示 VM 应用程序状态,请转到 “扩展 + 应用程序 ”选项卡/设置并检查 VMAppExtension 的状态:
若要显示规模集的 VM 应用程序状态,请转到 Azure 门户虚拟机规模集页。 在“实例”部分中,选择列出的规模集之一,然后转到 VMAppExtension:
如果未在 VM 上安装 VM 应用程序,该值为空。
若要获取 VM 实例视图的结果,请执行以下作:
GET
/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{VMName}/instanceView?api-version=2024-03-03
结果如下所示:
{
...
"extensions" [
...
{
"name": "VMAppExtension",
"type": "Microsoft.CPlat.Core.VMApplicationManagerLinux",
"typeHandlerVersion": "1.0.9",
"statuses": [
{
"code": "ProvisioningState/succeeded",
"level": "Info",
"displayStatus": "Provisioning succeeded",
"message": "Enable succeeded: {\n \"CurrentState\": [\n {\n \"applicationName\": \"doNothingLinux\",\n \"version\": \"1.0.0\",\n \"result\": \"Install SUCCESS\"\n },\n {
\n \"applicationName\": \"badapplinux\",\n \"version\": \"1.0.0\",\n \"result\": \"Install FAILED Error executing command \u0027exit 1\u0027: command terminated with exit status=1\"\n }\n ],\n \"ActionsPerformed\": []\n}
"
}
]
}
...
]
}
VM 应用状态处于实例视图中 VM 应用扩展结果的状态消息中。
若要获取虚拟机规模集上应用程序的状态,请执行以下步骤:
GET
/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/ virtualMachineScaleSets/{VMSSName}/virtualMachines/{instanceId}/instanceView?api-version=2019-03-01
输出类似于前面的 VM 示例。
若要验证 VM 上的应用程序部署状态,请使用 “az vm get-instance-view”:
az vm get-instance-view -g myResourceGroup -n myVM --query "instanceView.extensions[?name == 'VMAppExtension']"
若要验证虚拟机规模集上的应用程序部署状态,请使用 “az vmss get-instance-view”:
az vmss get-instance-view --ids (az vmss list-instances -g myResourceGroup -n myVmss --query "[*].id" -o tsv) --query "[*].extensions[?name == 'VMAppExtension']"
注释
上一个虚拟机规模集部署状态命令不列出具有结果的实例 ID。 若要显示每个实例中扩展状态的实例 ID,需要更多脚本。 请参阅以下包含 PowerShell 语法的 CLI 示例:
$ids = az vmss list-instances -g myResourceGroup -n myVmss --query "[*].{id: id, instanceId: instanceId}" | ConvertFrom-Json
$ids | Foreach-Object {
$iid = $_.instanceId
Write-Output "instanceId: $iid"
az vmss get-instance-view --ids $_.id --query "extensions[?name == 'VMAppExtension']"
}
验证应用程序是否成功:
$rgName = "myResourceGroup"
$vmName = "myVM"
$result = Get-AzVM -ResourceGroupName $rgName -VMName $vmName -Status
$result.Extensions | Where-Object {$_.Name -eq "VMAppExtension"} | ConvertTo-Json
若要在虚拟机规模集上验证,请执行以下操作:
$rgName = "myResourceGroup"
$vmssName = "myVMss"
$result = Get-AzVmssVM -ResourceGroupName $rgName -VMScaleSetName $vmssName -InstanceView
$resultSummary = New-Object System.Collections.ArrayList
$result | ForEach-Object {
$res = @{ instanceId = $_.InstanceId; vmappStatus = $_.InstanceView.Extensions | Where-Object {$_.Name -eq "VMAppExtension"}}
$resultSummary.Add($res) | Out-Null
}
$resultSummary | ConvertTo-Json -Depth 5
- 打开 Azure 门户,转到目标虚拟机(VM)或虚拟机规模集。
- 在“设置”中,选择“ 扩展 + 应用程序”,然后选择“ VM 应用程序 ”选项卡。
- 单击 VM 应用程序上的“卸载”按钮并保存。
- 在“通知”中跟踪进度,或检查 VMAppExtension 状态的实例视图。
为了移除 VM 应用程序,请更新 applicationProfile
,通过清除或排除目标应用程序。
从单个 VM 中删除:
PATCH
https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}?api-version=2024-03-03
Body
{
"properties": {
"applicationProfile": {
"galleryApplications": []
}
}
}
从 VM 规模集(模型)中删除:
PATCH
https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmssName}?api-version=2024-03-03
Body
{
"properties": {
"virtualMachineProfile": {
"applicationProfile": {
"galleryApplications": []
}
}
}
}
将更改应用到现有 VMSS 实例(在 upgradePolicy.mode 为手动时需要):
POST
https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmssName}/updateInstances?api-version=2024-03-03
Body
{
"instanceIds": ["0", "1"]
}
从单个 VM 中删除:
az vm update -g myResourceGroup -n myVM --set "properties.applicationProfile.galleryApplications=[]"
从 VM 规模集(模型)中删除:
az vmss update -g myResourceGroup -n myVMss --set "virtualMachineProfile.applicationProfile.galleryApplications=[]"
将更改应用到现有 VMSS 实例(手动升级策略):
az vmss update-instances -g myResourceGroup -n myVMss --instance-ids "*"
从单个 VM 中删除:
$rgName = "myResourceGroup"
$vmName = "myVM"
$vm = Get-AzVM -ResourceGroupName $rgName -Name $vmName
$vm.ApplicationProfile.GalleryApplications = @()
Update-AzVM -ResourceGroupName $rgName -VM $vm
从 VM 规模集(模型)中删除并应用于实例:
$rgName = "myResourceGroup"
$vmssName = "myVMss"
$vmss = Get-AzVmss -ResourceGroupName $rgName -VMScaleSetName $vmssName
$vmss.VirtualMachineProfile.ApplicationProfile.GalleryApplications = @()
Update-AzVmss -ResourceGroupName $rgName -VMScaleSetName $vmssName -VirtualMachineScaleSet $vmss
$instanceIds = (Get-AzVmssVM -ResourceGroupName $rgName -VMScaleSetName $vmssName).InstanceId
Update-AzVmssInstance -ResourceGroupName $rgName -VMScaleSetName $vmssName -InstanceId $instanceIds
若要删除 VM 应用程序资源,首先需要删除其所有版本。 删除应用程序版本会导致从 Azure 计算库及其所有副本中删除应用程序版本资源。 用于创建应用程序版本的存储帐户中的应用程序 Blob 不受影响。
- 登录到 Azure 门户。
- 搜索 Azure Compute Gallery 并打开目标库。
- 选择要删除的 VM 应用程序。
- 选择要删除的一个或多个版本。
- 若要删除 VM 应用程序,请先删除所有版本。 然后点击“删除”(在界面顶部)。
- 监控通知以检查完成情况。 如果删除被阻止,请删除任何锁定,并确保没有 VM 或虚拟机规模集引用该应用。
删除 VM 应用程序版本:
DELETE
https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{galleryApplicationName}/versions/{galleryApplicationVersionName}?api-version=2024-03-03
请在删除 VM 应用程序的所有版本后删除该应用程序。
DELETE
https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{galleryApplicationName}?api-version=2024-03-03
删除 VM 应用程序版本:
az sig gallery-application version delete --resource-group $rg-name --gallery-name $gallery-name --application-name $app-name --version-name $version-name
请在删除 VM 应用程序的所有版本后删除该应用程序。
az sig gallery-application delete --resource-group $rg-name --gallery-name $gallery-name --application-name $app-name
删除 VM 应用程序版本:
Remove-AzGalleryApplicationVersion -ResourceGroupName $rgNmae -GalleryName $galleryName -GalleryApplicationName $galleryApplicationName -Name $name
请在删除 VM 应用程序的所有版本后删除该应用程序。
Remove-AzGalleryApplication -ResourceGroupName $rgNmae -GalleryName $galleryName -Name $name