summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/__init__.py4
-rw-r--r--api/server.py14
-rw-r--r--yardstick/common/constants.py1
3 files changed, 16 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__':
diff --git a/yardstick/common/constants.py b/yardstick/common/constants.py
index c5a37b605..d71975af4 100644
--- a/yardstick/common/constants.py
+++ b/yardstick/common/constants.py
@@ -84,6 +84,7 @@ GRAFANA_IMAGE = get_param('grafana.image', 'grafana/grafana')
GRAFANA_TAG = get_param('grafana.tag', '3.1.1')
# api
+API_PORT = 5000
DOCKER_URL = 'unix://var/run/docker.sock'
INSTALLERS = ['apex', 'compass', 'fuel', 'joid']
SQLITE = 'sqlite:////tmp/yardstick.db'