def destroy_schema(host):

    keyspaces = get_keyspaces(host)

    for k in keyspaces:
        print('Dropping keyspace: %s' % k)
        cassandra_query(host, 'DROP KEYSPACE %s;' % k)
Beispiel #2
0
def destroy_schema(host):

    keyspaces = get_keyspaces(host)

    for k in keyspaces:
        print('Dropping keyspace: %s' % k)
        cassandra_query(host, 'DROP KEYSPACE %s;' % k)
Beispiel #3
0
def restore_schema(host, load_path, keyspace):
    # This function opens the schema files in each keyspace and writes it in
    # cqlsh

    schema_location = load_path + '/' + keyspace + '/' + keyspace + '_schema.cql'

    if not os.path.exists(schema_location):
        raise Exception('Schema not found: %s' % schema_location)

    with open(schema_location, 'r') as f:
        cassandra_query(host, f.read())
Beispiel #4
0
def restore_schema(host, load_path, keyspace):
    # This function opens the schema files in each keyspace and writes it in 
    # cqlsh

    schema_location = load_path + '/' + keyspace + '/' + keyspace + '_schema.cql'

    if not os.path.exists(schema_location):
        raise Exception('Schema not found: %s' % schema_location)

    with open(schema_location, 'r') as f:
        cassandra_query(host, f.read())
Beispiel #5
0
def destroy_schema(host, flag=None):

    success = False
    destroy = False
    keyspaces = get_keyspaces(host)

    if len(keyspaces) > 0:

        print('Removing keyspaces:')
        for k in keyspaces:
            print('\t' + k)
        if not flag:  # check if user wahts to destroy listed keyspaces

            option = raw_input('Destroy keyspaces? [y/n]')
            if option == 'y' or option == 'Y':
                destroy = True

        elif flag == '-y':
            destroy = True

        else:  # should never happen
            raise Exception('Invalid flag parameter')

        if destroy:

            for k in keyspaces:  # drop old keyspaces
                print('Dropping keyspace: %s' % k)
                cassandra_query(host, 'DROP KEYSPACE %s;' % k)

            data_dir = get_data_dir()
            active_dirs = os.listdir(data_dir)

            print('Removing old keyspace directories')
            for d in active_dirs:
                if d in keyspaces:
                    print('Removing keyspace directory: %s/%s' % (data_dir, d))
                    shutil.rmtree(data_dir + '/' + d)

            success = True

    else:
        success = True

    return success
Beispiel #6
0
def destroy_schema(host, flag=None):

    success = False
    destroy = False
    keyspaces = get_keyspaces(host)

    if len(keyspaces) > 0:

        print('Removing keyspaces:')
        for k in keyspaces:
            print('\t' + k)
        if not flag: # check if user wahts to destroy listed keyspaces

            option = raw_input('Destroy keyspaces? [y/n]')
            if option == 'y' or option == 'Y':
                destroy = True

        elif flag == '-y':
            destroy = True

        else: # should never happen
            raise Exception('Invalid flag parameter')

        if destroy:

            for k in keyspaces: # drop old keyspaces
                print('Dropping keyspace: %s' % k)
                cassandra_query(host, 'DROP KEYSPACE %s;' % k)

            data_dir = get_data_dir()
            active_dirs = os.listdir(data_dir)

            print('Removing old keyspace directories')
            for d in active_dirs:
                if d in keyspaces:
                    print('Removing keyspace directory: %s/%s' % (data_dir, d))
                    shutil.rmtree(data_dir + '/' + d)
                
            success = True

    else:
        success = True

    return success
Beispiel #7
0
def _load(host, load_path):

    # The load path is the location of the .cql file which contains the schema
    with open(load_path, 'r') as f:
        cassandra_query(host, f.read())
def _load(host, load_path):
    
    # The load path is the location of the .cql file which contains the schema
    with open(load_path, 'r') as f:
        cassandra_query(host, f.read())