当前位置: 首页>>代码示例>>Python>>正文


Python Connection.describe_ring方法代码示例

本文整理汇总了Python中connection.Connection.describe_ring方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.describe_ring方法的具体用法?Python Connection.describe_ring怎么用?Python Connection.describe_ring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在connection.Connection的用法示例。


在下文中一共展示了Connection.describe_ring方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SystemManager

# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import describe_ring [as 别名]
class SystemManager(object):
    """
    Lets you examine and modify schema definitions as well as get basic
    information about the cluster.

    This class is mainly designed to be used manually in a python shell,
    not as part of a program, although it can be used that way.

    All operations which modify a keyspace or column family definition
    will block until the cluster reports that all nodes have accepted
    the modification.

    Example Usage:

    .. code-block:: python

        >>> from pycassa.system_manager import *
        >>> sys = SystemManager('192.168.10.2:9160')
        >>> sys.create_keyspace('TestKeyspace', replication_factor=1)
        >>> sys.create_column_family('TestKeyspace', 'TestCF', column_type='Standard',
        ...                          comparator_type=LONG_TYPE)
        >>> sys.alter_column_family('TestKeyspace', 'TestCF', key_cache_size=42, gc_grace_seconds=1000)
        >>> sys.drop_keyspace('TestKeyspace')
        >>> sys.close()

    """

    def __init__(self, server='localhost:9160', credentials=None, framed_transport=True,
                 timeout=_DEFAULT_TIMEOUT):
        self._conn = Connection(None, server, framed_transport, timeout, credentials)

    def close(self):
        """ Closes the underlying connection """
        self._conn.close()

    def get_keyspace_column_families(self, keyspace, use_dict_for_col_metadata=False):
        """
        Returns a raw description of the keyspace, which is more useful for use
        in programs than :meth:`describe_keyspace()`.

        If `use_dict_for_col_metadata` is ``True``, the CfDef's column_metadata will
        be stored as a dictionary where the keys are column names instead of a list.

        Returns a dictionary of the form ``{column_family_name: CfDef}``

        """
        if keyspace is None:
            keyspace = self._keyspace

        ks_def = self._conn.describe_keyspace(keyspace)
        cf_defs = dict()
        for cf_def in ks_def.cf_defs:
            cf_defs[cf_def.name] = cf_def
            if use_dict_for_col_metadata:
                old_metadata = cf_def.column_metadata
                new_metadata = dict()
                for datum in old_metadata:
                    new_metadata[datum.name] = datum
                cf_def.column_metadata = new_metadata
        return cf_defs

    def get_keyspace_description(self, *args, **kwargs):
        """
        Alias for :meth:`get_keyspace_column_families()`

        .. deprecated:: 1.0.4
            Use :meth:`get_keyspace_column_families()`
        """
        warnings.warn("SystemManager.get_keyspace_description() is deprecated; " +
                      "use get_keyspace_column_families instead.", DeprecationWarning)
        return self.get_keyspace_column_families(*args, **kwargs)

    def get_keyspace_properties(self, keyspace):
        """
        Gets a keyspace's properties.

        Returns a :class:`dict` with 'replication_factor', 'strategy_class',
        and 'strategy_options' as keys.
        """
        if keyspace is None:
            keyspace = self._keyspace

        ks_def = self._conn.describe_keyspace(keyspace)
        return {'replication_factor': ks_def.replication_factor,
                'replication_strategy': ks_def.strategy_class,
                'strategy_options': ks_def.strategy_options}


    def list_keyspaces(self):
        """ Returns a list of all keyspace names. """
        return [ks.name for ks in self._conn.describe_keyspaces()]

    def describe_ring(self, keyspace):
        """ Describes the Cassandra cluster """
        return self._conn.describe_ring(keyspace)

    def describe_cluster_name(self):
        """ Gives the cluster name """
        return self._conn.describe_cluster_name()

#.........这里部分代码省略.........
开发者ID:amorton,项目名称:cassandra-unicode-bug,代码行数:103,代码来源:system_manager.py

示例2: SystemManager

# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import describe_ring [as 别名]

#.........这里部分代码省略.........
        if cfdef.row_cache_save_period_in_seconds == 0:
            s = 'Disabled'
        else:
            s = str(cfdef.row_cache_save_period_in_seconds) + ' seconds'
        print "  Row Cache:", spaces, s

        spaces = " " * (35 - len('  Key Cache:'))
        if cfdef.key_cache_save_period_in_seconds == 0:
            s = 'Disabled'
        else:
            s = str(cfdef.key_cache_save_period_in_seconds) + ' seconds'
        print "  Key Cache:", spaces, s
        print

        if cfdef.column_metadata:
            print "Column Metadata"
            for coldef in cfdef.column_metadata:
                spaces = " " * (35 - len('  - Name:'))
                print "  - Name:", spaces, coldef.name

                spaces = " " * (35 - len('    Value Type:'))
                s = coldef.validation_class
                print "    Value Type:", spaces, s[s.rfind('.') + 1: ]

                if coldef.index_type is not None:
                    spaces = " " * (35 - len('    Index Type:'))
                    s = IndexType._VALUES_TO_NAMES[coldef.index_type]
                    print "    Index Type:", spaces, s[s.rfind('.') + 1: ]

                    spaces = " " * (35 - len('    Index Name:'))
                    print "    Index Name:", spaces, coldef.index_name
                print

    def describe_ring(self, keyspace):
        """ Describes the Cassandra cluster """
        return self._conn.describe_ring(keyspace)

    def describe_cluster_name(self):
        """ Gives the cluster name """
        return self._conn.describe_cluster_name()

    def describe_version(self):
        """ Gives the server's API version """
        return self._conn.describe_version()

    def _system_add_keyspace(self, ksdef):
        schema_version = self._conn.system_add_keyspace(ksdef) 
        self._wait_for_agreement()
        return schema_version

    def _system_update_keyspace(self, ksdef):
        schema_version = self._conn.system_update_keyspace(ksdef) 
        self._wait_for_agreement()
        return schema_version

    def create_keyspace(self, name, replication_factor,
                        replication_strategy=SIMPLE_STRATEGY,
                        strategy_options=None):

        """
        Creates a new keyspace.  Column families may be added to this keyspace
        after it is created using :meth:`create_column_family()`.

        `replication_strategy` determines how replicas are chosen for this keyspace.
        The strategies that Cassandra provides by default
        are available as :const:`SIMPLE_STRATEGY`, :const:`NETWORK_TOPOLOGY_STRATEGY`,
开发者ID:trhowe,项目名称:pycassa,代码行数:70,代码来源:system_manager.py


注:本文中的connection.Connection.describe_ring方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。