List column families in a Cassandra cluster for all keyspaces or just the provided one.

    :param keyspace:       The keyspace to provide the column families for, optional.
    :type  keyspace:       str
    :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:               The column families in this Cassandra cluster.
    :rtype:                list[dict]

    CLI Example:

    .. code-block:: bash

        salt 'minion1' cassandra_cql.list_column_families

        salt 'minion1' cassandra_cql.list_column_families contact_points=minion1

        salt 'minion1' cassandra_cql.list_column_families keyspace=system

def list_column_families(keyspace=None, contact_points=None, port=None, cql_user=None, cql_pass=None):
    '''
    List column families in a Cassandra cluster for all keyspaces or just the provided one.

    :param keyspace:       The keyspace to provide the column families for, optional.
    :type  keyspace:       str
    :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:               The column families in this Cassandra cluster.
    :rtype:                list[dict]

    CLI Example:

    .. code-block:: bash

        salt 'minion1' cassandra_cql.list_column_families

        salt 'minion1' cassandra_cql.list_column_families contact_points=minion1

        salt 'minion1' cassandra_cql.list_column_families keyspace=system
    '''
    where_clause = "where keyspace_name = '{0}'".format(keyspace) if keyspace else ""

    query = {
        '2': '''select columnfamily_name from system.schema_columnfamilies
                {0};'''.format(where_clause),
        '3': '''select column_name from system_schema.columns
                {0};'''.format(where_clause),
    }

    ret = {}

    try:
        ret = cql_query(query, contact_points, port, cql_user, cql_pass)
    except CommandExecutionError:
        log.critical('Could not list column families.')
        raise
    except BaseException as e:
        log.critical('Unexpected error while listing column families: %s', e)
        raise

    return ret