如何解决无法在Azure中获取使用Python SDK设置的虚拟机规模的公共IP地址
我有一个虚拟机规模集,并且连接了两个VM,我想使用Python SDK来获取其公共IP地址。
我正在使用此脚本来获取IP配置。
def get_vmss_vm_ips():
# List all network interfaces of the VMSS instance
vmss_nics = network_client.network_interfaces.list_virtual_machine_scale_set_network_interfaces(
rg,vmscalesetname)
niclist = [nic.serialize() for nic in vmss_nics]
print "IP addresses in the given VM Scale Set:"
for nic in niclist:
ipconf = nic['properties']['ipConfigurations']
print ipconf
这是我的输出:
{'id': u'/subscriptions/sub_id/resourceGroups/test/providers/Microsoft.Compute/virtualMachineScaleSets/EchoServer/virtualMachines/2/networkInterfaces/test-vnet-nic01/ipConfigurations/test-vnet-nic01-defaultIpConfiguration','properties': {'subnet': {'id': u'/subscriptions/sub_id/resourceGroups/test/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/default'},'privateIPAddressVersion': u'IPv4','publicIPAddress': {'id': u'/subscriptions/sub_id/resourceGroups/test/providers/Microsoft.Compute/virtualMachineScaleSets/EchoServer/virtualMachines/2/networkInterfaces/test-vnet-nic01/ipConfigurations/test-vnet-nic01-defaultIpConfiguration/publicIPAddresses/publicIp-test-vnet-nic01'},'privateIPAllocationMethod': u'Dynamic','primary': True,'privateIPAddress': u'10.0.0.9'},'name': u'test-vnet-nic01-defaultIpConfiguration'}]
我可以看到privateIPAddress
,但看不到publicIPAddress
。如何获取公共IP地址?
解决方法
如果要使用Azure规模设置虚拟机的公用IP地址,请参考以下脚本
-
创建服务主体并将
for row in range(2,sheet.max_row + 1): cell = sheet.cell(row,3) new_price = cell.value new_price = float(new_price.replace("$","")) * 0.9 new_price_cell = sheet.cell(row,4) new_price_cell.value = new_price
角色分配给服务主体Contributor
-
代码
az login az ad sp create-for-rbac -n "MyApp" --role contributor \ --scopes /subscriptions/{SubID} --sdk-auth true
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。