当我在Python中使用Azurerm时,如何解决Azure中的以下错误“代码”:“ NoRegisteredProviderFound”?

时间:2019-08-20 12:51:28

标签: python azure azure-sdk-python azure-rm

我在代码中使用了以下azurerm函数:

public_ips = azurerm.get_vmss_public_ips(access_token, SUBSCRIPTION_ID, 
GROUP_NAME, CUScaleSet)

print(public_ips)

我得到以下输出:

  

{u'error':{u'message':u“未找到以下注册资源提供商   类型的位置“ eastus”和API版本“ 2019-03-01”   “ virtualMachineScaleSets / publicIPAddresses”。支持的   api-versions是'2017-03-30,2017-12-01,2018-04-01,2018-06-01,   2018-10-01'。受支持的位置是“ eastus,eastus2,westus,   中部,北中部,南中部,北欧洲,西欧洲,   东亚,东南亚,日本东部,日本西部,澳大利亚东部,   澳大利亚东南部,澳大利亚中部,巴西拉苏特,南印度,   Centralindia,westindia,canadacentral,canadaeast,westus2,   西centralus,uksouth,ukwest,koreacentral,koreasouth,   法国中央,Southafricanorth,uaenorth'。”,u'code':   u'NoRegisteredProviderFound'}}

注意:几天前,同一段代码正在运行。

1 个答案:

答案 0 :(得分:1)

如果要求获取VMSS实例中VM的所有IP,则可以如下使用官方的Azure SDK for Python

# Imports
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.network import NetworkManagementClient

# Set subscription ID
SUBSCRIPTION_ID = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'


def get_credentials():
    credentials = ServicePrincipalCredentials(
        client_id='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
        secret='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
        tenant='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
    )

    return credentials


# Get credentials
credentials = get_credentials()


# Initialize management client
network_client = NetworkManagementClient(
    credentials,
    SUBSCRIPTION_ID
)


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(
        "<VMSS Resource group name>", "<VMSS instance name>")

    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']

        for ip in ipconf:
            print ip['properties']['privateIPAddress']


# Get all IPs of VMs in VMSS
get_vmss_vm_ips()

参考:

希望这会有所帮助!