summaryrefslogtreecommitdiffstats
path: root/api/server.py
diff options
context:
space:
mode:
authorchenjiankun <chenjiankun1@huawei.com>2017-07-12 10:45:17 +0000
committerchenjiankun <chenjiankun1@huawei.com>2017-07-12 15:14:10 +0000
commitb6d8765f2acbeefeb8e8f756b2243e8bac2a06b6 (patch)
treecb2a91b5b52b1980cb8a6ebab192d5b61013fe42 /api/server.py
parent29484c3071028df6c897797706117082a4b8c3f5 (diff)
Change endpoint to url in API
There are come conflict with new architecture. Also it is more proper to use url as endpoint. Change-Id: Idce331e36d85d0720bbf3255dca29ba6022e18b2 Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'api/server.py')
-rw-r--r--api/server.py14
1 files changed, 13 insertions, 1 deletions
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__':