def main(argv): usage = "Usage: dbschema [options] [{resource}]" args, kwargs = parse(argv) host = kwargs.get('host', settings.DEFAULT_CASSANDRA_HOST) port = kwargs.get('port', settings.DEFAULT_CASSANDRA_PORT) try: system = SystemManager("%s:%s" % (host, port)) # FOR TESTING ONLY # print str(argv) if len(argv) == 0: list_keyspaces(system) return if len(argv) == 1: ksname = argv[0] list_keyspace(system, ksname) if len(argv) == 2: ksname = argv[0] cfname = argv[1] if cfname != 'ANY': list_column_family(system, ksname, cfname) else: list_keyspace(system, ksname) except: error(output, excinfo(), 2)
def main(argv): usage = "Usage: dbinsert [options] {cfpath} {key} {fields}" args, kwargs = parse(argv) host = kwargs.get("host", settings.DEFAULT_CASSANDRA_HOST) port = kwargs.get("port", settings.DEFAULT_CASSANDRA_PORT) batchsize = kwargs.get("batchsize", settings.DEFAULT_BATCHSIZE) if not port.isdigit(): error(output, "Invalid port", 2) port = int(port) if not batchsize.isdigit() or int(batchsize) < 1: error(output, "Invalid batchsize", 2) batchsize = int(batchsize) if len(args) != 3: error(output, usage, 2) cfpath, keycol, fields = args fields = fields.split(",") cfpath = cfpath.split(".") if len(cfpath) != 2: error(output, "Invalid column family path", 2) ksname, cfname = cfpath try: server = "%s:%d" % (host, port) pool = pycassa.connect(ksname, [server]) cfam = pycassa.ColumnFamily(pool, cfname) except pycassa.cassandra.c08.ttypes.InvalidRequestException, e: error(output, e.why, 2)
def main(argv): usage = "Usage: dbinsert [options] {cfpath} {key} {fields}" args, kwargs = parse(argv) host = kwargs.get('host', settings.DEFAULT_CASSANDRA_HOST) port = kwargs.get('port', settings.DEFAULT_CASSANDRA_PORT) batchsize = kwargs.get('batchsize', settings.DEFAULT_BATCHSIZE) if not port.isdigit(): error(output, "Invalid port", 2) port = int(port) if not batchsize.isdigit() or int(batchsize) < 1: error(output, "Invalid batchsize", 2) batchsize = int(batchsize) if len(args) != 3: error(output, usage, 2) cfpath, keycol, fields = args fields = fields.split(',') cfpath = cfpath.split('.') if len(cfpath) != 2: error(output, "Invalid column family path", 2) ksname, cfname = cfpath try: server = "%s:%d" % (host, port) pool = pycassa.connect(ksname, [server]) cfam = pycassa.ColumnFamily(pool, cfname) except pycassa.cassandra.c08.ttypes.InvalidRequestException, e: error(output, e.why, 2)
def _del(self, *args): category = self._getCategoryFromSelection() entryCount = len(category.entries) if entryCount == 0: self.controller.deleteCategory(category, self) else: apputils.error(_("There are %d entries related to this category,\n" "cann't delete.") % entryCount)
def _del(self, *args): category = self._getCategoryFromSelection() entryCount = len(category.entries) if entryCount == 0: self.controller.deleteCategory(category, self) else: apputils.error( _("There are %d entries related to this category,\n" "cann't delete.") % entryCount)
def main(argv): usage = "Usage: dbdiscover.py" args, kwargs = parse(argv) host = kwargs.get('host', settings.DEFAULT_CASSANDRA_HOST) port = kwargs.get('port', settings.DEFAULT_CASSANDRA_PORT) try: system = SystemManager("%s:%s" % (host, port)) ksprops = system.get_keyspace_properties("system").keys() # header = ["keyspace"] + sorted(ksprops) header = ["keyspace", "column_family"] writer = csv.writer(output) writer.writerow(header) for keyspace in system.list_keyspaces(): ksinfo = system.get_keyspace_column_families(keyspace, use_dict_for_col_metadata=True) attrs = [ "id", "column_type", "comment", "comparator_type", "default_validation_class", "gc_grace_seconds", "key_alias", "key_cache_save_period_in_seconds", "key_cache_size", "key_validation_class", "max_compaction_threshold", "memtable_operations_in_millions", "memtable_throughput_in_mb", "memtable_flush_after_mins", "merge_shards_chance", "min_compaction_threshold", "read_repair_chance", "replicate_on_write", "row_cache_provider", "row_cache_save_period_in_seconds", "row_cache_size", "subcomparator_type", ] for cfname, cfdef in ksinfo.iteritems(): ks = ("keyspace="+ keyspace) cf = ("column_family="+ cfname) row =(ks, cf) writer.writerow(row) return except: error(output, excinfo(), 2)
def main(argv): usage = "Usage: dbdiscover.py" args, kwargs = parse(argv) host = kwargs.get('host', settings.DEFAULT_CASSANDRA_HOST) port = kwargs.get('port', settings.DEFAULT_CASSANDRA_PORT) try: system = SystemManager("%s:%s" % (host, port)) ksprops = system.get_keyspace_properties("system").keys() # header = ["keyspace"] + sorted(ksprops) header = ["keyspace", "column_family"] writer = csv.writer(output) writer.writerow(header) for keyspace in system.list_keyspaces(): ksinfo = system.get_keyspace_column_families( keyspace, use_dict_for_col_metadata=True) attrs = [ "id", "column_type", "comment", "comparator_type", "default_validation_class", "gc_grace_seconds", "key_alias", "key_cache_save_period_in_seconds", "key_cache_size", "key_validation_class", "max_compaction_threshold", "memtable_operations_in_millions", "memtable_throughput_in_mb", "memtable_flush_after_mins", "merge_shards_chance", "min_compaction_threshold", "read_repair_chance", "replicate_on_write", "row_cache_provider", "row_cache_save_period_in_seconds", "row_cache_size", "subcomparator_type", ] for cfname, cfdef in ksinfo.iteritems(): ks = ("keyspace=" + keyspace) cf = ("column_family=" + cfname) row = (ks, cf) writer.writerow(row) return except: error(output, excinfo(), 2)
def main(argv): usage = "Usage: dbgetkeys [{Keyspace, Column_Family}]" args, kwargs = parse(argv) host = kwargs.get('host', settings.DEFAULT_CASSANDRA_HOST) port = kwargs.get('port', settings.DEFAULT_CASSANDRA_PORT) if len(argv) == 2: ksname = argv[0] cfname = argv[1] try: server = "%s:%s" % (host, port) pool = pycassa.connect(ksname, [server]) cfam = pycassa.ColumnFamily(pool, cfname) except pycassa.cassandra.c08.ttypes.InvalidRequestException, e: error(output, e.why, 2)
def main(argv): usage = "Usage: dbcql {query}" args, kwargs = parse(argv) if len(args) > 1: error(output, "Unexpected argument: '%s'" % args[1], 2) if len(args) < 1: error(output, "No query argument", 2) keyspace = kwargs.get('keyspace', None) host = kwargs.get('host', settings.DEFAULT_CASSANDRA_HOST) port = kwargs.get('port', settings.DEFAULT_CASSANDRA_PORT) # UNDONE: credentials .. query = args[0] if query is None: error(output, "Command requires a single query argument", 2) # A query may consist of multiple expressions. We execute each of # the expressions in order and output the results from the final # expression. The primary scenario is: # # "USE {keyspace}; SELECT * FROM .." # # However, arbitrary query expressions may be combined in this way. expressions = query.split(';') # Scan the expressions looking for anything we need to disable for expression in expressions: # UNDONE: The following disables usage of the CLQ DROP command # in order to prevent users from inadvertently (or maliciously) # dropping of critical keyspace data until we can properly enable # the capability by integrating with Splunk's role based access # control (where this would be an admin-only capability). if re.match("\s*drop ", expression, re.I): error(output, "The CQL DROP command has been disabled.", 2) connection = None cursor = None try: connection = cql.connect(host, port, keyspace) cursor = connection.cursor() # Everything looks ok .. so run them. for expression in expressions: cursor.execute(expression) # A 'SELECT *' expression requires special handling because the # results may be "ragged", meaning that we don't know what fields # will appear for any given row. In order to handle this case we # scan an initial `batchsize` set of rows, collecting all fields # that we see. We then use those fields for the results header and # collect any additional fields that we subsequently see into an # "_extra" MV field. Note that a row in Cassandra can contain up # to 2B columns, so "SELECT *" may have other issues aside from the # incrimental processing impact on this search script. if re.search("select\s+\*", expression, re.I): ragged(cursor) else: normal(cursor) except: error(output, excinfo(), 2) finally: if cursor is not None: cursor.close() if connection is not None: connection.close()
def main(argv): usage = "Usage: dbcql {query}" args, kwargs = parse(argv) if len(args) > 1: error(output, "Unexpected argument: '%s'" % args[1], 2) if len(args) < 1: error(output, "No query argument", 2) keyspace = kwargs.get('keyspace', None) host = kwargs.get('host', settings.DEFAULT_CASSANDRA_HOST) port = kwargs.get('port', settings.DEFAULT_CASSANDRA_PORT) # UNDONE: credentials .. query = args[0] if query is None: error(output, "Command requires a single query argument", 2) # A query may consist of multiple expressions. We execute each of # the expressions in order and output the results from the final # expression. The primary scenario is: # # "USE {keyspace}; SELECT * FROM .." # # However, arbitrary query expressions may be combined in this way. expressions = query.split(';') # Scan the expressions looking for anything we need to disable for expression in expressions: # UNDONE: The following disables usage of the CLQ DROP command # in order to prevent users from inadvertently (or maliciously) # dropping of critical keyspace data until we can properly enable # the capability by integrating with Splunk's role based access # control (where this would be an admin-only capability). if re.match("\s*drop ", expression, re.I): error(output, "The CQL DROP command has been disabled.", 2); connection = None cursor = None try: connection = cql.connect(host, port, keyspace) cursor = connection.cursor() # Everything looks ok .. so run them. for expression in expressions: cursor.execute(expression) # A 'SELECT *' expression requires special handling because the # results may be "ragged", meaning that we don't know what fields # will appear for any given row. In order to handle this case we # scan an initial `batchsize` set of rows, collecting all fields # that we see. We then use those fields for the results header and # collect any additional fields that we subsequently see into an # "_extra" MV field. Note that a row in Cassandra can contain up # to 2B columns, so "SELECT *" may have other issues aside from the # incrimental processing impact on this search script. if re.search("select\s+\*", expression, re.I): ragged(cursor) else: normal(cursor) except: error(output, excinfo(), 2) finally: if cursor is not None: cursor.close() if connection is not None: connection.close()
cfpath, keycol, fields = args fields = fields.split(',') cfpath = cfpath.split('.') if len(cfpath) != 2: error(output, "Invalid column family path", 2) ksname, cfname = cfpath try: server = "%s:%d" % (host, port) pool = pycassa.connect(ksname, [server]) cfam = pycassa.ColumnFamily(pool, cfname) except pycassa.cassandra.c08.ttypes.InvalidRequestException, e: error(output, e.why, 2) except pycassa.cassandra.c08.ttypes.NotFoundException, e: error(output, e.why, 2) except: error(output, excinfo(), 2) for line in sys.stdin: if line == '\n': break reader = csv.DictReader(sys.stdin) header = reader.fieldnames if keycol not in header: error(output, "Key field '%s' not found" % keycol, 2) header.extend(fields) writer = csv.DictWriter(output, header) writer.writer.writerow(header)
host = kwargs.get('host', settings.DEFAULT_CASSANDRA_HOST) port = kwargs.get('port', settings.DEFAULT_CASSANDRA_PORT) if len(argv) == 2: ksname = argv[0] cfname = argv[1] try: server = "%s:%s" % (host, port) pool = pycassa.connect(ksname, [server]) cfam = pycassa.ColumnFamily(pool, cfname) except pycassa.cassandra.c08.ttypes.InvalidRequestException, e: error(output, e.why, 2) except pycassa.cassandra.c08.ttypes.NotFoundException, e: error(output, e.why, 2) except: error(output, excinfo(), 2) # Get All Keys for given cf header = ["Keyspace","Column_Family","Key"] writer = csv.writer(output) writer.writerow(header) ks = ("keyspace="+ ksname) cf = ("column_family="+ cfname) for value in cfam.get_range(column_count=0): key = ("Key="+ value[0]) row = (ks, cf, key) writer.writerow(row)