Azure-Samples/virtual-machines-python-manage

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

lizhiwei-666 opened this issue · 1 comments

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']
}
},
)

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