예제 #1
0
def main(argv):
    parser = create_option_parser()
    (options, args) = parser.parse_args()
    try:
        if not options.bucket_name:
            parser.print_help()
            return 1
        if not options.key:
            parser.print_help()
            return 1
        params = get_params(options)
        client = HttpClient(options.host, options.port)
        if options.bucket_type:
            context = "/types/{}/buckets/{}/keys/{}/".format(
                client.escape_slash(options.bucket_type),
                client.escape_slash(options.bucket_name),
                client.escape_slash(options.key))
        else:
            context = "/buckets/{}/keys/{}/".format(
                client.escape_slash(options.bucket_name),
                client.escape_slash(options.key))
        response = client.get(context, params=params)
        client.pretty_print_response(response, options.verbose, options.b64)
        return 0
    except Exception as e:
        print("An error occurred creating {{{{{}, {}}}, {}}}: {}".format(
            options.bucket_type, options.bucket_name, options.key, e))
        #import traceback
        #traceback.print_exc()
        return -1
예제 #2
0
def get_value(host, port, bucket_type, bucket_name, key):
    #quoted_key = urllib.quote(key.encode('utf8'), safe="")
    context = "/types/{}/buckets/{}/keys/{}".format(
        HttpClient.escape_slash(bucket_type), HttpClient.escape_slash(bucket_name), HttpClient.escape_slash(key)
    )
    riak_util.log("Context: {}".format(context))
    client = HttpClient(host, port)
    return client.get(context)['body']
예제 #3
0
def get_keys(host, port, bucket):
    bucket_type, bucket_name = bucket
    context = "/types/{}/buckets/{}/keys?keys=true".format(
        HttpClient.escape_slash(bucket_type),
        HttpClient.escape_slash(bucket_name))
    client = HttpClient(host, port)
    body = client.get(context)['body']
    log("Context: {} BODY: {}".format(context, body))
    data = json.loads(body.decode())
    return data['keys']
예제 #4
0
def main(argv):
    parser = create_option_parser()
    (options, args) = parser.parse_args()
    try:
        (options, args) = parser.parse_args()
        if not options.bucket_name:
            parser.print_help()
            return 1
        if not options.key:
            parser.print_help()
            return 1
        if not options.value and not options.file:
            parser.print_help()
            return 1
        params = get_params(options)
        client = HttpClient(options.host, options.port)
        if options.bucket_type:
            context = "/types/{}/buckets/{}/keys/{}/".format(
                client.escape_slash(options.bucket_type),
                client.escape_slash(options.bucket_name),
                client.escape_slash(options.key))
        else:
            context = "/buckets/{}/keys/{}/".format(
                client.escape_slash(options.bucket_name),
                client.escape_slash(options.key))
        vclock = None
        if not options.force:
            result = client.get(context)
            if result['status'] != 404:
                if 'X-Riak-Vclock' in result['headers']:
                    vclock = result['headers']['X-Riak-Vclock']
        body = get_data(options)
        headers = {'X-Riak-Vclock': vclock} if vclock else {}
        response = client.put(context,
                              body=body,
                              content_type=options.content_type,
                              headers=headers,
                              params=params)
        client.pretty_print_response(response, options.verbose)
        return 0
    except Exception as e:
        print("An error occurred creating {{{{{}, {}}}, {}}}: {}".format(
            options.bucket_type, options.bucket_name, options.key, e))
        import traceback
        traceback.print_exc()
        return -1
예제 #5
0
def delete(host, port, bucket_type, bucket_name, key):
    context = "/types/{}/buckets/{}/keys/{}".format(
        HttpClient.escape_slash(bucket_type),
        HttpClient.escape_slash(bucket_name), HttpClient.escape_slash(key))
    client = HttpClient(host, port)
    return client.delete(context)