diff --git a/consul/base.py b/consul/base.py index 0c86d406..ee6ab254 100755 --- a/consul/base.py +++ b/consul/base.py @@ -819,6 +819,7 @@ def register( tags=None, check=None, token=None, + meta=None, # *deprecated* use check parameter script=None, interval=None, @@ -848,6 +849,9 @@ def register( Note this call will return successful even if the token doesn't have permissions to register this service. + *meta* specifies arbitrary KV metadata linked to the service + formatted as {k1:v1, k2:v2}. + *script*, *interval*, *ttl*, *http*, and *timeout* arguments are deprecated. use *check* instead. @@ -873,7 +877,8 @@ def register( payload['port'] = port if tags: payload['tags'] = tags - + if meta: + payload['meta'] = meta if check: payload['check'] = check diff --git a/tests/test_base.py b/tests/test_base.py index cd894146..ef76a9fa 100755 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -1,4 +1,5 @@ import collections +import json import pytest @@ -62,6 +63,14 @@ def _should_support_node_meta(c): ) +def _should_support_meta(c): + return ( + # agent + lambda **kw: c.agent.service.register('foo', **kw), + lambda **kw: c.agent.service.register('foo', 'bar', **kw), + ) + + class TestIndex(object): """ Tests read requests that should support blocking on an index @@ -107,6 +116,18 @@ def test_node_meta(self): sorted([('node-meta', 'net:1'), ('node-meta', 'env:prod')]) +class TestMeta(object): + """ + Tests read requests that should support meta + """ + + def test_meta(self): + c = Consul() + for r in _should_support_meta(c): + d = json.loads(r(meta={'env': 'prod', 'net': 1}).data) + assert sorted(d['meta']) == sorted({'env': 'prod', 'net': 1}) + + class TestCB(object): def test_status_200_passes(self):