diff options
Diffstat (limited to 'api')
-rw-r--r-- | api/__init__.py | 4 | ||||
-rw-r--r-- | api/server.py | 14 |
2 files changed, 15 insertions, 3 deletions
diff --git a/api/__init__.py b/api/__init__.py index dda12aa07..4622802df 100644 --- a/api/__init__.py +++ b/api/__init__.py @@ -57,9 +57,9 @@ class ApiResource(Resource): class Url(object): - def __init__(self, url, endpoint): + def __init__(self, url, target): super(Url, self).__init__() self.url = url - self.endpoint = endpoint + self.target = target common_utils.import_modules_from_package("api.resources") diff --git a/api/server.py b/api/server.py index 344874c77..c1548ca10 100644 --- a/api/server.py +++ b/api/server.py @@ -10,6 +10,7 @@ from __future__ import absolute_import import inspect import logging +import socket from six.moves import filter from flasgger import Swagger @@ -24,6 +25,12 @@ from api.urls import urlpatterns from api import ApiResource from yardstick import _init_logging from yardstick.common import utils +from yardstick.common import constants as consts + +try: + from urlparse import urljoin +except ImportError: + from urllib.parse import urljoin logger = logging.getLogger(__name__) @@ -64,8 +71,13 @@ def app_wrapper(*args, **kwargs): return app(*args, **kwargs) +def get_endpoint(url): + ip = socket.gethostbyname(socket.gethostname()) + return urljoin('http://{}:{}'.format(ip, consts.API_PORT), url) + + for u in urlpatterns: - api.add_resource(get_resource(u.endpoint), u.url, endpoint=u.endpoint) + api.add_resource(get_resource(u.target), u.url, endpoint=get_endpoint(u.url)) if __name__ == '__main__': |