Skip to content

Commit

Permalink
killing consul_request, mostly
Browse files Browse the repository at this point in the history
  • Loading branch information
smn committed Jul 17, 2015
1 parent af34ef4 commit 1d3955d
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions consular/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,8 @@ def marathon_request(self, method, path, data=None):
return self._request(
method, '%s%s' % (self.marathon_endpoint, path), data)

def consul_request(self, agent_endpoint, method, path, data=None):
d = self._request(
method, '%s%s' % (agent_endpoint, path), data,
timeout=self.fallback_timeout)
def consul_request(self, method, url, data=None):
d = self._request(method, url, data, timeout=self.fallback_timeout)
d.addErrback(self.consul_request_error_handler)
return d

Expand Down Expand Up @@ -180,20 +178,26 @@ def handle_unknown_event(self, request, event):
'error': 'Event type %s not supported.' % (event_type,)
})

def register_service(self, node, app_id, service_id, address, port):
def register_service(self, agent_endpoint,
app_id, service_id, address, port):
log.msg('Registering %s at %s with %s at %s:%s.' % (
app_id, node, service_id, address, port))
return self.consul_request(node, 'PUT', '/v1/agent/service/register', {
'Name': app_id,
'ID': service_id,
'Address': address,
'Port': port,
})

def deregister_service(self, node, app_id, service_id):
log.msg('Deregistering %s at %s with %s' % (app_id, node, service_id,))
app_id, agent_endpoint, service_id, address, port))
return self.consul_request(
'PUT',
'%s/v1/agent/service/register' % (agent_endpoint,),
{
'Name': app_id,
'ID': service_id,
'Address': address,
'Port': port,
})

def deregister_service(self, agent_endpoint, app_id, service_id):
log.msg('Deregistering %s at %s with %s' % (
app_id, agent_endpoint, service_id,))
return self.consul_request(
node, 'PUT', '/v1/agent/service/deregister/%s' % (service_id,))
'PUT', '%s/v1/agent/service/deregister/%s' % (
agent_endpoint, service_id,))

def sync_apps(self, purge=False):
d = self.marathon_request('GET', '/v2/apps')
Expand Down Expand Up @@ -223,8 +227,8 @@ def sync_app_labels(self, app):
# we're already connected to, they're not local to the agents.
return gatherResults([
self.consul_request(
self.consul_endpoint,
'PUT', '/v1/kv/consular/%s/%s' % (
'PUT', '%s/v1/kv/consular/%s/%s' % (
self.consul_endpoint,
quote(get_appid(app['id'])), quote(key)), value)
for key, value in labels.items()
])
Expand All @@ -244,7 +248,7 @@ def sync_app_task(self, app, task):

def purge_dead_services(self):
d = self.consul_request(
self.consul_endpoint, 'GET', '/v1/catalog/nodes')
'GET', '%s/v1/catalog/nodes' % (self.consul_endpoint,))
d.addCallback(lambda response: response.json())
d.addCallback(lambda data: gatherResults([
self.purge_dead_agent_services(node['Address']) for node in data
Expand All @@ -255,7 +259,7 @@ def purge_dead_services(self):
def purge_dead_agent_services(self, node):
agent_endpoint = get_agent_endpoint(node)
response = yield self.consul_request(
agent_endpoint, 'GET', '/v1/agent/services')
'GET', '%s/v1/agent/services' % (agent_endpoint,))
data = yield response.json()

# collect the task ids for the service name
Expand Down

0 comments on commit 1d3955d

Please sign in to comment.