This article shows how to use the 'pycassaShell' client tool to retrieve and modify the Cassandra Database in a user-friendly manner.
The pycassaShell is an interactive Cassandra Python shell. It is useful for exploring a Cassandra Database. It is recommended (but not required) to install IPython before invoking pycassaShell to provide extra user-friendly features. When started, pycassaShell will create a ColumnFamily object for every existing column family in the Cassandra cluster and prints the names of the objects. It also provides all the necessary methods to insert and retrieve data easily from the Cassandra Database.
The following capture demonstrates how to start pycassaShell and use it to retrieve data from the Contrail config database:
Execute the command and connect to the config database:
$ pycassaShell -H 172.222.19.197 -k config_db_uuid ---------------------------------- Cassandra Interactive Python Shell ---------------------------------- Keyspace: config_db_uuid Host: 172.222.19.197:9160 Available ColumnFamily instances: * OBJ_FQ_NAME_TABLE ( obj_fq_name_table ) * OBJ_SHARED_TABLE ( obj_shared_table ) * OBJ_UUID_TABLE ( obj_uuid_table ) Schema definition tools and cluster information are available through SYSTEM_MANAGER. In [2]: OBJ_FQ_NAME_TABLE? Type: ColumnFamily String Form: <pycassa.columnfamily.ColumnFamily object at 0x7f9450180bd0> Namespace: Interactive (global) File: /usr/lib/python2.7/dist-packages/pycassa/columnfamily.py Docstring: An abstraction of a Cassandra column family or super column family. Operations on this, such as :meth:`get` or :meth:`insert` will get data from or insert data into the corresponding Cassandra column family. Constructor Docstring: `pool` is a :class:`~pycassa.pool.ConnectionPool` that the column family will use for all operations. A connection is drawn from the pool before each operations and is returned afterwards. `column_family` should be the name of the column family that you want to use in Cassandra. Note that the keyspace to be used is determined by the pool.
OBJ_FQ_NAME_TABLE.buffer_size OBJ_FQ_NAME_TABLE.get OBJ_FQ_NAME_TABLE.super OBJ_FQ_NAME_TABLE.column_buffer_size OBJ_FQ_NAME_TABLE.get_count OBJ_FQ_NAME_TABLE.super_column_name_class OBJ_FQ_NAME_TABLE.autopack_keys OBJ_FQ_NAME_TABLE.get_indexed_slices OBJ_FQ_NAME_TABLE.pool OBJ_FQ_NAME_TABLE.autopack_names OBJ_FQ_NAME_TABLE.get_range OBJ_FQ_NAME_TABLE.truncate OBJ_FQ_NAME_TABLE.column_validators OBJ_FQ_NAME_TABLE.insert OBJ_FQ_NAME_TABLE.write_consistency_level OBJ_FQ_NAME_TABLE.batch OBJ_FQ_NAME_TABLE.key_validation_class OBJ_FQ_NAME_TABLE.xget OBJ_FQ_NAME_TABLE.dict_class OBJ_FQ_NAME_TABLE.retry_counter_mutations OBJ_FQ_NAME_TABLE.MAX_COUNT OBJ_FQ_NAME_TABLE.multiget OBJ_FQ_NAME_TABLE.add OBJ_FQ_NAME_TABLE.multiget_count OBJ_FQ_NAME_TABLE.column_family OBJ_FQ_NAME_TABLE.timestamp OBJ_FQ_NAME_TABLE.column_name_class OBJ_FQ_NAME_TABLE.read_consistency_level OBJ_FQ_NAME_TABLE.autopack_values OBJ_FQ_NAME_TABLE.remove OBJ_FQ_NAME_TABLE.default_validation_class OBJ_FQ_NAME_TABLE.remove_counter OBJ_FQ_NAME_TABLE.batch_insert OBJ_FQ_NAME_TABLE.load_schema
In [6]: OBJ_FQ_NAME_TABLE.get_range() Out[6]: <generator object get_range at 0x7f944f1c6f00> In [7]: d=dict(OBJ_FQ_NAME_TABLE.get_range()) In [8]: d.keys() Out[8]: ['service_appliance_set', 'domain', 'virtual_router', 'global_system_config', 'network_policy', 'loadbalancer_pool', 'route_table', 'interface_route_table', 'routing_instance', 'service_appliance', 'network_ipam', 'config_node', 'namespace', 'logical_router', 'api_access_list', 'virtual_machine', 'service_instance', 'analytics_node', 'service_template', 'bgp_router', 'floating_ip', 'discovery_service_assignment', 'floating_ip_pool', 'loadbalancer_member', 'access_control_list', 'qos_queue', 'database_node', 'route_target', 'virtual_machine_interface', 'instance_ip', 'global_vrouter_config', 'project', 'loadbalancer_healthmonitor', 'port_tuple', 'virtual_ip', 'security_group', 'virtual_network']
In [12]: d.get('bgp_router') Out[12]: OrderedDict([('default-domain:default-project:ip-fabric:__default__:camaro:9474e9f8-af1f-48c2-b6a3-cef3fbbdede0', u'null'), ('default-domain:default-project:ip-fabric:__default__:cl100ct197:2ac71de9-d3ae-40c9-b90d-042b00d94e0f', u'null')])