Create a new cassandra user with credentials and superuser status.

    :param username:       The name of the new user.
    :type  username:       str
    :param password:       The password of the new user.
    :type  password:       str
    :param superuser:      Is the new user going to be a superuser? default: False
    :type  superuser:      bool
    :param contact_points: The Cassandra cluster addresses, can either be a string or a list of IPs.
    :type  contact_points: str | list[str]
    :param cql_user:       The Cassandra user if authentication is turned on.
    :type  cql_user:       str
    :param cql_pass:       The Cassandra user password if authentication is turned on.
    :type  cql_pass:       str
    :param port:           The Cassandra cluster port, defaults to None.
    :type  port:           int
    :return:
    :rtype:

    CLI Example:

    .. code-block:: bash

        salt 'minion1' cassandra_cql.create_user username=joe password=secret

        salt 'minion1' cassandra_cql.create_user username=joe password=secret superuser=True

        salt 'minion1' cassandra_cql.create_user username=joe password=secret superuser=True contact_points=minion1

def create_user(username, password, superuser=False, contact_points=None, port=None, cql_user=None, cql_pass=None):
    '''
    Create a new cassandra user with credentials and superuser status.

    :param username:       The name of the new user.
    :type  username:       str
    :param password:       The password of the new user.
    :type  password:       str
    :param superuser:      Is the new user going to be a superuser? default: False
    :type  superuser:      bool
    :param contact_points: The Cassandra cluster addresses, can either be a string or a list of IPs.
    :type  contact_points: str | list[str]
    :param cql_user:       The Cassandra user if authentication is turned on.
    :type  cql_user:       str
    :param cql_pass:       The Cassandra user password if authentication is turned on.
    :type  cql_pass:       str
    :param port:           The Cassandra cluster port, defaults to None.
    :type  port:           int
    :return:
    :rtype:

    CLI Example:

    .. code-block:: bash

        salt 'minion1' cassandra_cql.create_user username=joe password=secret

        salt 'minion1' cassandra_cql.create_user username=joe password=secret superuser=True

        salt 'minion1' cassandra_cql.create_user username=joe password=secret superuser=True contact_points=minion1
    '''
    superuser_cql = 'superuser' if superuser else 'nosuperuser'
    query = '''create user if not exists {0} with password '{1}' {2};'''.format(username, password, superuser_cql)
    log.debug("Attempting to create a new user with username=%s superuser=%s", username, superuser_cql)

    # The create user query doesn't actually return anything if the query succeeds.
    # If the query fails, catch the exception, log a messange and raise it again.
    try:
        cql_query(query, contact_points, port, cql_user, cql_pass)
    except CommandExecutionError:
        log.critical('Could not create user.')
        raise
    except BaseException as e:
        log.critical('Unexpected error while creating user: %s', e)
        raise

    return True