Get IP from VM object using azure sdk in python

前端 未结 2 679
夕颜
夕颜 2021-01-20 20:01

I am trying to get all the IPs (attached to VMs) from an azure subscription.

I have pulled all the VMs using

compute_client = ComputeManagementClien         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-20 20:17

    As your said, indeed, something has changed, but not much.

    First as below, NetworkManagementClientConfiguration has been remove, see the details in the link.

    network_client = NetworkManagementClient(credentials,subscription_id)
    

    Second, according to the source code, the parameter public_ip_address_name is the name of the subnet, cease to be the vm name.

    # Resource Group
    GROUP_NAME = 'azure-sample-group-virtual-machines'
    # Network
    SUBNET_NAME = 'azure-sample-subnet'
    PUBLIC_IP_NAME = SUBNET_NAME
    public_ip_address = network_client.public_ip_addresses.get(GROUP_NAME, PUBLIC_IP_NAME)
    

    Then, you can also the private_ip_address & public_ip_address via the IPConfiguration from the PublicIPAddress

    print(public_ip_address.ip_configuration.private_ip_address)
    print(public_ip_address.ip_configuration.public_ip_address)
    

提交回复
热议问题