'Create a virtual network interface (NIC).
:param name: Name of the NIC resource
:type name: ``str``
:param subnet: The subnet to attach the NIC
:type subnet: :class:`.AzureSubnet`
:param resource_group: The resource group to create the NIC
:type resource_group: ``str``
:param location: The location at which to create the NIC
(if None, use default location specified as \'region\' in __init__)
:type location: :class:`.NodeLocation`
:param public_ip: Associate a public IP resource with this NIC
(optional).
:type public_ip: :class:`.AzureIPAddress`
:return: The newly created NIC
:rtype: :class:`.AzureNic`'

def ex_create_network_interface(self, name, subnet, resource_group, location=None, public_ip=None):

    if (location is None):
        if self.default_location:
            location = self.default_location
        else:
            raise ValueError('location    is    required.')
    target = ('/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/networkInterfaces/%s' % (self.subscription_id, resource_group, name))
    data = {'location': location.id, 'tags': {}, 'properties': {'ipConfigurations': [{'name': 'myip1', 'properties': {'subnet': {'id': subnet.id}, 'privateIPAllocationMethod': 'Dynamic'}}]}}
    if public_ip:
        ip_config = data['properties']['ipConfigurations'][0]
        ip_config['properties']['publicIPAddress'] = {'id': public_ip.id}
    r = self.connection.request(target, params={'api-version': '2015-06-15'}, data=data, method='PUT')
    return AzureNic(r.object['id'], r.object['name'], r.object['location'], r.object['properties'])
