Skip to content
This repository was archived by the owner on Apr 15, 2024. It is now read-only.

Commit 53eb41c

Browse files
authored
Merge pull request #230 from ojongerius/add-service-meta-parameter
Allow adding meta data when registering service
2 parents 4ddec9b + 56b5ea3 commit 53eb41c

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

consul/base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ def register(
819819
tags=None,
820820
check=None,
821821
token=None,
822+
meta=None,
822823
# *deprecated* use check parameter
823824
script=None,
824825
interval=None,
@@ -848,6 +849,9 @@ def register(
848849
Note this call will return successful even if the token doesn't
849850
have permissions to register this service.
850851
852+
*meta* specifies arbitrary KV metadata linked to the service
853+
formatted as {k1:v1, k2:v2}.
854+
851855
*script*, *interval*, *ttl*, *http*, and *timeout* arguments
852856
are deprecated. use *check* instead.
853857
@@ -873,7 +877,8 @@ def register(
873877
payload['port'] = port
874878
if tags:
875879
payload['tags'] = tags
876-
880+
if meta:
881+
payload['meta'] = meta
877882
if check:
878883
payload['check'] = check
879884

tests/test_base.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import collections
2+
import json
23

34
import pytest
45

@@ -62,6 +63,14 @@ def _should_support_node_meta(c):
6263
)
6364

6465

66+
def _should_support_meta(c):
67+
return (
68+
# agent
69+
lambda **kw: c.agent.service.register('foo', **kw),
70+
lambda **kw: c.agent.service.register('foo', 'bar', **kw),
71+
)
72+
73+
6574
class TestIndex(object):
6675
"""
6776
Tests read requests that should support blocking on an index
@@ -107,6 +116,18 @@ def test_node_meta(self):
107116
sorted([('node-meta', 'net:1'), ('node-meta', 'env:prod')])
108117

109118

119+
class TestMeta(object):
120+
"""
121+
Tests read requests that should support meta
122+
"""
123+
124+
def test_meta(self):
125+
c = Consul()
126+
for r in _should_support_meta(c):
127+
d = json.loads(r(meta={'env': 'prod', 'net': 1}).data)
128+
assert sorted(d['meta']) == sorted({'env': 'prod', 'net': 1})
129+
130+
110131
class TestCB(object):
111132

112133
def test_status_200_passes(self):

0 commit comments

Comments
 (0)