本文整理汇总了Python中connection.Connection.describe_keyspace方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.describe_keyspace方法的具体用法?Python Connection.describe_keyspace怎么用?Python Connection.describe_keyspace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类connection.Connection
的用法示例。
在下文中一共展示了Connection.describe_keyspace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SystemManager
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import describe_keyspace [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()
#.........这里部分代码省略.........
示例2: SystemManager
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import describe_keyspace [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):
self._conn = Connection(None, server, framed_transport, _TIMEOUT, credentials)
def close(self):
""" Closes the underlying connection """
self._conn.close()
def get_keyspace_description(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 describe_keyspace(self, keyspace):
"""
Returns a human readable description of the Keyspace.
For use in a program, use :meth:`get_keyspace_description()` instead.
"""
ksdef = self._conn.describe_keyspace(keyspace)
print
spaces = " " * (35 - len('Name:'))
print "Name:", spaces, ksdef.name
print
spaces = " " * (35 - len('Replication Strategy:'))
s = ksdef.strategy_class
print "Replication Strategy:", spaces, s[s.rfind('.') + 1: ]
if ksdef.strategy_options:
spaces = " " * (35 - len('Strategy Options:'))
print "Strategy Options:", spaces, ksdef.strategy_options
spaces = " " * (35 - len('Replication Factor:'))
print "Replication Factor:", spaces, ksdef.replication_factor
print
print "Column Families:"
for cfdef in ksdef.cf_defs:
print " ", cfdef.name
print
def describe_column_family(self, keyspace, column_family):
""" Returns a human readable description of the Column Family """
try:
cfdef = self.get_keyspace_description(keyspace)[column_family]
except KeyError:
print "Column family %s does not exist in keyspace %s" % (column_family, keyspace)
return
#.........这里部分代码省略.........