Skip to content

Commit

Permalink
Merge pull request #118 from Imaclean74/add-servicemeta-support
Browse files Browse the repository at this point in the history
Add support for service metadata. fixes #117
  • Loading branch information
gmr committed Jul 16, 2018
2 parents 312f362 + f9ee783 commit b5476c8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion consulate/api/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ def register(self,
address=None,
port=None,
tags=None,
meta=None,
check=None,
checks=None,
enable_tag_override=None):
Expand All @@ -208,6 +209,7 @@ def register(self,
:param str address: The service IP address
:param int port: The service port
:param list tags: A list of tags for the service
:param list meta: A list of KV pairs for the service
:param check: An optional check definition for the service
:type check: :class:`consulate.models.agent.Check`
:param checks: A list of check definitions for the service
Expand All @@ -221,7 +223,7 @@ def register(self,
['register'], None,
dict(models.Service(
name=name, id=service_id, address=address, port=port,
tags=tags, check=check, checks=checks,
tags=tags, meta=meta, check=check, checks=checks,
enable_tag_override=enable_tag_override)))

def deregister(self, service_id):
Expand Down
9 changes: 8 additions & 1 deletion consulate/models/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def __init__(self, **kwargs):
class Service(base.Model):
"""Model for making Check API requests to Consul."""

__slots__ = ['id', 'name', 'tags', 'address', 'port', 'check',
__slots__ = ['id', 'name', 'tags', 'meta', 'address', 'port', 'check',
'checks', 'enable_tag_override']

__attributes__ = {
Expand All @@ -212,6 +212,13 @@ class Service(base.Model):
'type': list,
'validator': lambda t, _m: all([isinstance(v, str) for v in t])
},
'meta': {
'key': 'Meta',
'type': dict,
'validator': lambda h, _m: all(
[(isinstance(k, str) and isinstance(v, str))
for k, v in h.items()]),
},
'address': {
'key': 'Address',
'type': str
Expand Down
4 changes: 2 additions & 2 deletions tests/agent_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ def test_self_forbidden(self):

def test_service_registration(self):
self.consul.agent.service.register(
'test-service', address='10.0.0.1', port=5672, tags=['foo', 'bar'])
'test-service', address='10.0.0.1', port=5672, tags=['foo', 'bar'], meta={'foo' : 'bar' })
self.assertIn('test-service', self.consul.agent.services())
self.consul.agent.service.deregister('test-service')

def test_service_maintenance(self):
self.consul.agent.service.register(
'test-service', address='10.0.0.1', port=5672, tags=['foo', 'bar'])
'test-service', address='10.0.0.1', port=5672, tags=['foo', 'bar'], meta={'foo' : 'bar' } )
self.assertIn('test-service', self.consul.agent.services())
reason = 'Down for Acceptance'
self.consul.agent.service.maintenance('test-service', reason=reason)
Expand Down

0 comments on commit b5476c8

Please sign in to comment.