Etcd: How to use curl with etcd 3.0.6?

Created on 12 Mar 2017  Â·  11Comments  Â·  Source: etcd-io/etcd

I have a rkt container image running etcd 3.0.6:

$ sudo rkt list
UUID        APP IMAGE NAME      STATE   CREATED     STARTED     NETWORKS
b07fae0f    etcd    coreos.com/etcd:v3.0.6  running 1 day ago   1 day ago   default:ip4=172.16.28.68

$ curl -LsS http://172.16.28.68:2379/v2/keys | python -mjson.tool
{
    "action": "get",
    "node": {
        "dir": true
    }
}

As you can see above, there are no keys in the store.

I'm trying to use the python-etcd3 library to create and set keys in the etcd3 server, and then double-check my code by using curl within my functional tests. When I use python-etcd3 to create a key, things seem to work fine:

import etcd3


client = etcd3.client(
    host='172.16.28.68',
    port=2379,
)   

res = client.put('/testing/foo', 'fizzlesticks')

for val, meta in client.get_prefix('/testing'):
    print val, meta
$ python test.py 
fizzlesticks <etcd3.client.KVMetadata object at 0x7fc2e0796890>

However, when I curl to get the key I just added, they aren't found:

$ curl -LsS http://172.16.28.68:2379/v2/keys | python -mjson.tool
{
    "action": "get",
    "node": {
        "dir": true
    }
}

I've tried looking in the /v3alpha and /v3 key spaces, but nothing:

$ curl -LsS http://172.16.28.68:2379/v3alpha
Not Found
(py27) jaypipes@uberbox:~/src/github.com/jaypipes/os-lively$ curl -LsS http://172.16.28.68:2379/v3
404 page not found
(py27) jaypipes@uberbox:~/src/github.com/jaypipes/os-lively$ curl -LsS http://172.16.28.68:2379/v3/keys
404 page not found

Am I missing something? Is there a proxy of some sort that needs to be running somewhere? Any help would be most appreciated. Thanks in advance!

-jay

All 11 comments

@jaypipes the v3 API differs from v2.

Here is the example how to use it:
curl -X POST -d '{"key": "L2FwcA==", "range_end": "L2I="}' http://localhost:2379/v3alpha/kv/range

The main difficulty - keys and values are base64-encoded, so it's not convenient to use it in real life.
Better to use etcdctl directly.

Hey, thanks @mwf, that's exactly the information I needed. :)

BTW, is that documented anywhere? I couldn't find any docs, but I know it's alpha so not expecting anything. I can contribute some docs if folks would like?

OK, thanks again, @mwf, really appreciate the assist :)

@mwf @jaypipes there's documentation on the grpc gateway at https://github.com/coreos/etcd/blob/master/Documentation/dev-guide/api_grpc_gateway.md

@mwf Hi, Now I have a problem that I want to get all keys by rest api(etcd v3).But no solution.Can you do me a favor?Thanks.

Hi @tantjp

curl -X POST -d '{"key": "AA==", "range_end": "AA=="}' http://localhost:2379/v3beta/kv/range

As posted here https://github.com/coreos/etcd/blob/v3.3.9/etcdserver/etcdserverpb/rpc.proto#L379

If both key and range_end are '0', then the range request returns all keys.

So, first we should encode '0'-byte to base64:

$ printf '\0' | base64
AA==

And use the base64 value in the curl call.

@mwf it works, thanks.

@mwf @jaypipes there's documentation on the grpc gateway at https://github.com/coreos/etcd/blob/master/Documentation/dev-guide/api_grpc_gateway.md

This documentation says it will work with v3 and not with v3alpha or v3beta, however on the latest etcd version it does not work with v3:

 $ curl -L http://192.168.121.20:31379/v3beta/kv/put -X POST -d '{"key": "Zm9v", "value": "YmFy"}'
{"header":{"cluster_id":"14841639068965178418","member_id":"10276657743932975437","revision":"354","raft_term":"2"}}%   

 $ curl -L http://192.168.121.20:31379/v3/kv/put -X POST -d '{"key": "Zm9v", "value": "YmFy"}' 
404 page not found

 $ curl -L http://192.168.121.20:31379/version                                                
{"etcdserver":"3.3.8","etcdcluster":"3.3.0"}

Docs clearly state

  • etcd v3.3 uses [CLIENT-URL]/v3beta/* while keeping
    [CLIENT-URL]/v3alpha/*

/v3 will be available in 3.4+

On Thu, May 30, 2019 at 5:46 AM gunix notifications@github.com wrote:

@mwf https://github.com/mwf @jaypipes https://github.com/jaypipes
there's documentation on the grpc gateway at
https://github.com/coreos/etcd/blob/master/Documentation/dev-guide/api_grpc_gateway.md

This documentation says it will work with v3 and not with v3alpha or
v3beta, however on the latest etcd version it does not work with v3:

$ curl -L http://192.168.121.20:31379/v3beta/kv/put -X POST -d '{"key": "Zm9v", "value": "YmFy"}'

{"header":{"cluster_id":"14841639068965178418","member_id":"10276657743932975437","revision":"354","raft_term":"2"}}%

$ curl -L http://192.168.121.20:31379/v3/kv/put -X POST -d '{"key": "Zm9v", "value": "YmFy"}'

404 page not found

$ curl -L http://192.168.121.20:31379/version

{"etcdserver":"3.3.8","etcdcluster":"3.3.0"}

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/etcd-io/etcd/issues/7484?email_source=notifications&email_token=AAJRDVOLEDXSC5DNL6QBXZTPX6PAVA5CNFSM4DDKTLEKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWR4LUY#issuecomment-497272275,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAJRDVMCEYWKK5A4FTSFXNDPX6PAVANCNFSM4DDKTLEA
.

>

—

Hi May i know how to store local files in etcd using the curl command?

Was this page helpful?
0 / 5 - 0 ratings