Commit 49209ec7 authored by Daniele Venzano's avatar Daniele Venzano
Browse files

Implement basic service discovery

parent 2a8c617a
# Zoe Changelog
## Version 0.10.1
* Service discovery API endpoint: simple, read-only, unauthenticated access to a list DNS names of services. Needed for frameworks that need a list of hosts for configuration, can be used by scripts in the images.
## Version 0.10.0
* This version is the start of a new series of releases moving toward a new architecture
......@@ -116,6 +116,12 @@ class APIEndpoint:
raise zoe_api.exceptions.ZoeAuthException()
return service
def service_list(self, uid, role, **filters):
"""Generate a optionally filtered list of services."""
services = self.sql.service_list(**filters)
ret = [s for s in services if s.user_id == uid or role == 'admin']
return ret
def retry_submit_error_executions(self):
"""Resubmit any execution forgotten by the master."""
waiting_execs = self.sql.execution_list(status=zoe_lib.sql_manager.Execution.SUBMIT_STATUS)
......@@ -24,6 +24,7 @@ from flask_restful import Api
from zoe_api.rest_api.execution import ExecutionAPI, ExecutionCollectionAPI, ExecutionDeleteAPI
from import InfoAPI
from zoe_api.rest_api.service import ServiceAPI
from zoe_api.rest_api.discovery import DiscoveryAPI
from zoe_lib.version import ZOE_API_VERSION
......@@ -41,6 +42,8 @@ def api_init(api_endpoint) -> Blueprint:
api.add_resource(ExecutionCollectionAPI, API_PATH + '/execution', resource_class_kwargs={'api_endpoint': api_endpoint})
api.add_resource(ServiceAPI, API_PATH + '/service/<int:service_id>', resource_class_kwargs={'api_endpoint': api_endpoint})
api.add_resource(DiscoveryAPI, API_PATH + '/discovery/by_group/<int:execution_id>/<service_group>', resource_class_kwargs={'api_endpoint': api_endpoint})
return api_bp
# Work around a Python 3.4.0 bug that affects Flask
# Copyright (c) 2016, Daniele Venzano
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The Discovery API endpoint."""
from flask_restful import Resource
import zoe_api.api_endpoint
from zoe_api.rest_api.utils import catch_exceptions
class DiscoveryAPI(Resource):
"""The Discovery API endpoint."""
def __init__(self, api_endpoint: zoe_api.api_endpoint.APIEndpoint) -> None:
self.api_endpoint = api_endpoint
def get(self, execution_id: int, service_group: str):
"""HTTP GET method."""
services = self.api_endpoint.service_list(0, 'admin', service_group=service_group, execution_id=execution_id)
ret = {
'service_type': service_group,
'execution_id': execution_id,
'dns_names': [s.dns_name for s in services]
return ret
......@@ -372,3 +372,9 @@ class Service(Base):
swarm = SwarmClient(get_conf())
s_info = swarm.inspect_container(self.docker_id)
return s_info['ip_address'][get_conf().overlay_network_name]
def user_id(self):
"""Getter for the user_id, that is actually taken form the parent execution."""
execution = self.sql_manager.execution_list(only_one=True, id=self.execution_id)
return execution.user_id
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment