-1

我从这里使用模板创建了一个 DTL - https://github.com/Azure/azure-devtestlab/blob/master/Samples/101-dtl-create-lab/azuredeploy.json

之后,我正在更改子网并使用以下脚本创建 P2S VPN -

$VNetName = "dtlinfratest2"
$RG = "infratest2"
$Location = "westeurope"
$MyP2SRootCertPubKeyBase64 = "XXXXXXX"

# each virtaul network is inside a dev test lab so below values can hold good for all cases.
# Note: This is going to fail if VM exists in the virtual network
$GWSubName = "GatewaySubnet"
$VNetPrefix1 = "10.0.0.0/16"
$SubPrefix = "10.0.0.0/24"
$GWSubPrefix = "10.0.200.0/26"
$VPNClientAddressPool = "132.16.201.0/24"
$GWName = "GateWay"
$GWIPName = "GateWayIP"
$GWIPconfName = "GateWayIPConfig"

$vnet = Get-AzureRmVirtualNetwork -Name $VNetName -ResourceGroupName $RG

$fesub = New-AzureRmVirtualNetworkSubnetConfig -Name $vnet.Subnets.name -AddressPrefix $SubPrefix
$gwsub = New-AzureRmVirtualNetworkSubnetConfig -Name $GWSubName -AddressPrefix $GWSubPrefix
$vn = New-AzureRmVirtualNetwork -Name $VNetName -ResourceGroupName $RG -Location $Location -AddressPrefix $VNetPrefix1 -Subnet $fesub, $gwsub -Force

$subnet = Get-AzureRmVirtualNetworkSubnetConfig -Name $GWSubName -VirtualNetwork $vn

$pip = New-AzureRmPublicIpAddress -Name $GWIPName -ResourceGroupName $RG -Location $Location -AllocationMethod Dynamic
$ipconf = New-AzureRmVirtualNetworkGatewayIpConfig -Name $GWIPconfName -Subnet $subnet -PublicIpAddress $pip

$p2srootcert = New-AzureRmVpnClientRootCertificate -Name "P2SVNETRootCertName" -PublicCertData $MyP2SRootCertPubKeyBase64
New-AzureRmVirtualNetworkGateway -Name $GWName -ResourceGroupName $RG -Location $Location -IpConfigurations $ipconf -GatewayType Vpn -VpnType RouteBased -EnableBgp $false -GatewaySku Standard -VpnClientAddressPool $VPNClientAddressPool -VpnClientRootCertificates $p2srootcert 

我正在创建子网中没有任何问题的虚拟机,并且在预定义的时间后虚拟机到期,之后我观察到虚拟机创建在实验室内失败。错误信息-

子网 DtlInfraTest2子网未启用或不是指定虚拟网络的一部分 /subscriptions/XXXXX/resourcegroups/infratest2/providers/microsoft.devtestlab/labs/infratest2/virtualnetworks/dtlinfratest2

我检查了实验室内的网络选项卡,发现“在虚拟机创建中使用”已关闭,除非我手动勾选绿色,否则我无法创建 VM。

在此处输入图像描述

我尝试搜索 powershell 命令,但找不到。默认情况下,当我们使用模板创建虚拟机时,“在虚拟机创建中使用”,但当所有虚拟机自动过期时会关闭

4

2 回答 2

1

我尝试搜索 powershell 命令,但找不到。

尝试以下命令将USE IN VIRTUAL MACHINE CREATION实验室子网设置为Yes.

$a = Get-AzureRmResource -ResourceGroupName <ResourceGroupName> -ResourceType Microsoft.DevTestLab/labs/virtualnetworks -ResourceName "<your DevTest Lab name>/<Vnet name>" -ApiVersion 2016-05-15
$labSubnet = $a.Properties.subnetOverrides | Where-Object {$_.labSubnetName -eq "your labsubnet name"} 
$labSubnet.useInVmCreationPermission = "Allow"
$a | Set-AzureRmResource -Force -ApiVersion 2016-05-15

在此处输入图像描述

检查门户

在此处输入图像描述

于 2018-10-17T09:36:19.337 回答
0

该错误消息意味着您需要启用子网才能创建 VM。我按照您链接的模板和您提供的脚本成功创建了 DTL 和 P2S VPN 和子网。这是运行脚本后的默认虚拟网络设置。您可以尝试单击下面的红色分区以启用USE IN VIRTUAL MACHINE CREATION

在此处输入图像描述

或者在您的代码中包含subnetOverrides模板以启用子网。您可以获得一个示例模板

   "subnetOverrides": [
                            {
                                "name": "[parameters('existingSubnetName')]",
                                "resourceId": "[variables('existingSubnetId')]",
                                "useInVmCreationPermission": "Allow",
                                "usePublicIpAddressPermission": "Allow"
                            }
                        ]
于 2018-10-17T08:58:34.413 回答