r'''
    A function to connect to a bigip device and create a profile.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    profile_type
        The type of profile to create
    name
        The name of the profile to create
    kwargs
        ``[ arg=val ] ... [arg=key1:val1,key2:val2] ...``

        Consult F5 BIGIP user guide for specific options for each monitor type.
        Typically, tmsh arg names are used.

    Creating Complex Args
        Profiles can get pretty complicated in terms of the amount of possible
        config options. Use the following shorthand to create complex arguments such
        as lists, dictionaries, and lists of dictionaries. An option is also
        provided to pass raw json as well.

        lists ``[i,i,i]``:
            ``param='item1,item2,item3'``

        Dictionary ``[k:v,k:v,k,v]``:
            ``param='key-1:val-1,key-2:val2,key-3:va-3'``

        List of Dictionaries ``[k:v,k:v|k:v,k:v|k:v,k:v]``:
           ``param='key-1:val-1,key-2:val-2|key-1:val-1,key-2:val-2|key-1:val-1,key-2:val-2'``

        JSON: ``'j{ ... }j'``:
           ``cert-key-chain='j{ "default": { "cert": "default.crt", "chain": "default.crt", "key": "default.key" } }j'``

        Escaping Delimiters:
            Use ``\,`` or ``\:`` or ``\|`` to escape characters which shouldn't
            be treated as delimiters i.e. ``ciphers='DEFAULT\:!SSLv3'``

    CLI Examples::

        salt '*' bigip.create_profile bigip admin admin http my-http-profile defaultsFrom='/Common/http'
        salt '*' bigip.create_profile bigip admin admin http my-http-profile defaultsFrom='/Common/http' \
            enforcement=maxHeaderCount:3200,maxRequests:10

def create_profile(hostname, username, password, profile_type, name, **kwargs):
    r'''
    A function to connect to a bigip device and create a profile.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    profile_type
        The type of profile to create
    name
        The name of the profile to create
    kwargs
        ``[ arg=val ] ... [arg=key1:val1,key2:val2] ...``

        Consult F5 BIGIP user guide for specific options for each monitor type.
        Typically, tmsh arg names are used.

    Creating Complex Args
        Profiles can get pretty complicated in terms of the amount of possible
        config options. Use the following shorthand to create complex arguments such
        as lists, dictionaries, and lists of dictionaries. An option is also
        provided to pass raw json as well.

        lists ``[i,i,i]``:
            ``param='item1,item2,item3'``

        Dictionary ``[k:v,k:v,k,v]``:
            ``param='key-1:val-1,key-2:val2,key-3:va-3'``

        List of Dictionaries ``[k:v,k:v|k:v,k:v|k:v,k:v]``:
           ``param='key-1:val-1,key-2:val-2|key-1:val-1,key-2:val-2|key-1:val-1,key-2:val-2'``

        JSON: ``'j{ ... }j'``:
           ``cert-key-chain='j{ "default": { "cert": "default.crt", "chain": "default.crt", "key": "default.key" } }j'``

        Escaping Delimiters:
            Use ``\,`` or ``\:`` or ``\|`` to escape characters which shouldn't
            be treated as delimiters i.e. ``ciphers='DEFAULT\:!SSLv3'``

    CLI Examples::

        salt '*' bigip.create_profile bigip admin admin http my-http-profile defaultsFrom='/Common/http'
        salt '*' bigip.create_profile bigip admin admin http my-http-profile defaultsFrom='/Common/http' \
            enforcement=maxHeaderCount:3200,maxRequests:10

    '''

    #build session
    bigip_session = _build_session(username, password)

    #construct the payload
    payload = {}
    payload['name'] = name

    #there's a ton of different profiles and a ton of options for each type of profile.
    #this logic relies that the end user knows which options are meant for which profile types
    for key, value in six.iteritems(kwargs):
        if not key.startswith('__'):
            if key not in ['hostname', 'username', 'password', 'profile_type']:
                key = key.replace('_', '-')

                try:
                    payload[key] = _set_value(value)
                except salt.exceptions.CommandExecutionError:
                    return 'Error: Unable to Parse JSON data for parameter: {key}\n{value}'.format(key=key, value=value)

    #post to REST
    try:
        response = bigip_session.post(
            BIG_IP_URL_BASE.format(host=hostname) + '/ltm/profile/{type}'.format(type=profile_type),
            data=salt.utils.json.dumps(payload)
        )
    except requests.exceptions.ConnectionError as e:
        return _load_connection_error(hostname, e)

    return _load_response(response)