Azure-Samples / virtual-machines-python-manage

An example illustrating how to use Python to manage your Azure Virtual Machines
MIT License
104 stars 84 forks source link

How can I set the Nic?I want to get a public IP. #20

Closed lizhiwei-666 closed 5 years ago

lizhiwei-666 commented 5 years ago

the sample code is: async_vnet_creation = network_client.virtual_networks.create_or_update( GROUP_NAME, VNET_NAME, { 'location': LOCATION, 'address_space': { 'address_prefixes': ['10.0.0.0/16'] } }, )

lmazuel commented 5 years ago

You need to create a PublicIP first using the Network client:

        params_create = azure.mgmt.network.models.PublicIPAddress(
            location=location,
            public_ip_allocation_method=azure.mgmt.network.models.IPAllocationMethod.dynamic,
            tags={
                'key': 'value',
            },
        )
        result_create = self.network_client.public_ip_addresses.create_or_update(
            resource_group.name,
            public_ip_name,
            params_create,
        )
        result_create.wait() # AzureOperationPoller

Then, you can assign it at NIC creation, in the public_ip_address field: https://docs.microsoft.com/en-us/python/api/azure-mgmt-network/azure.mgmt.network.v2018_08_01.models.networkinterfaceipconfiguration?view=azure-python