summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorRex Lee <limingjiang@huawei.com>2017-07-14 03:56:16 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-07-14 03:56:16 +0000
commit6acd5d156ba25d1eed49763fb220a117a43d5ef8 (patch)
tree605b149c78ff2997f50cc054f301ea3edc5b804f /api
parentebf9803aa3f8c9851e845f80145329f59863267c (diff)
parentcc3c7796ccb30b021c219cabdbe73bfc14fb38cc (diff)
Merge "Add API to get environments"
Diffstat (limited to 'api')
-rw-r--r--api/database/v2/handlers.py3
-rw-r--r--api/resources/v2/environments.py18
-rw-r--r--api/urls.py1
3 files changed, 22 insertions, 0 deletions
diff --git a/api/database/v2/handlers.py b/api/database/v2/handlers.py
index eb732817d..095ad724c 100644
--- a/api/database/v2/handlers.py
+++ b/api/database/v2/handlers.py
@@ -24,6 +24,9 @@ class V2EnvironmentHandler(object):
db_session.commit()
return environment
+ def list_all(self):
+ return V2Environment.query.all()
+
def get_by_uuid(self, uuid):
environment = V2Environment.query.filter_by(uuid=uuid).first()
if not environment:
diff --git a/api/resources/v2/environments.py b/api/resources/v2/environments.py
index dc6eac725..4b27c45b8 100644
--- a/api/resources/v2/environments.py
+++ b/api/resources/v2/environments.py
@@ -1,9 +1,12 @@
import uuid
import logging
+from oslo_serialization import jsonutils
+
from api import ApiResource
from api.database.v2.handlers import V2EnvironmentHandler
from yardstick.common.utils import result_handler
+from yardstick.common.utils import change_obj_to_dict
from yardstick.common import constants as consts
LOG = logging.getLogger(__name__)
@@ -12,6 +15,20 @@ LOG.setLevel(logging.DEBUG)
class V2Environments(ApiResource):
+ def get(self):
+ environment_handler = V2EnvironmentHandler()
+ environments = [change_obj_to_dict(e) for e in environment_handler.list_all()]
+
+ for e in environments:
+ container_info = e['container_id']
+ e['container_id'] = jsonutils.loads(container_info) if container_info else {}
+
+ data = {
+ 'environments': environments
+ }
+
+ return result_handler(consts.API_SUCCESS, data)
+
def post(self):
return self._dispatch_post()
@@ -24,6 +41,7 @@ class V2Environments(ApiResource):
env_id = str(uuid.uuid4())
environment_handler = V2EnvironmentHandler()
+
env_init_data = {
'name': name,
'uuid': env_id
diff --git a/api/urls.py b/api/urls.py
index 0ffba89c9..0c63fb040 100644
--- a/api/urls.py
+++ b/api/urls.py
@@ -22,5 +22,6 @@ urlpatterns = [
Url('/yardstick/env/action', 'v1_env'),
# api v2
+ Url('/api/v2/yardstick/environments', 'v2_environments'),
Url('/api/v2/yardstick/environments/action', 'v2_environments'),
]