.. versionadded:: 2019.2.0

    Create a new Netbox circuit provider

    name
        The name of the circuit provider
    asn
        The ASN of the circuit provider

    CLI Example:

    .. code-block:: bash

        salt myminion netbox.create_circuit_provider Telia 1299

def create_circuit_provider(name, asn=None):
    '''
    .. versionadded:: 2019.2.0

    Create a new Netbox circuit provider

    name
        The name of the circuit provider
    asn
        The ASN of the circuit provider

    CLI Example:

    .. code-block:: bash

        salt myminion netbox.create_circuit_provider Telia 1299
    '''

    nb_circuit_provider = get_('circuits', 'providers', name=name)
    payload = {}
    if nb_circuit_provider:
        if nb_circuit_provider['asn'] == asn:
            return False
        else:
            log.error('Duplicate provider with different ASN: %s: %s', name, asn)
            raise CommandExecutionError(
                'Duplicate provider with different ASN: {}: {}'.format(name, asn)
            )
    else:
        payload = {
            'name': name,
            'slug': slugify(name)
        }
        if asn:
            payload['asn'] = asn
        circuit_provider = _add('circuits', 'providers', payload)
        if circuit_provider:
            return {'circuits': {'providers': {circuit_provider['id']: payload}}}
        else:
            return circuit_provider