Merge "test_monitor_multi: speedup unittests, sleep less"
[yardstick.git] / api / resources / v2 / environments.py
1 import uuid
2 import logging
3
4 from api import ApiResource
5 from api.database.v2.handlers import V2EnvironmentHandler
6 from yardstick.common.utils import result_handler
7 from yardstick.common import constants as consts
8
9 LOG = logging.getLogger(__name__)
10 LOG.setLevel(logging.DEBUG)
11
12
13 class V2Environments(ApiResource):
14
15     def post(self):
16         return self._dispatch_post()
17
18     def create_environment(self, args):
19         try:
20             name = args['name']
21         except KeyError:
22             return result_handler(consts.API_ERROR, 'name must be provided')
23
24         env_id = str(uuid.uuid4())
25
26         environment_handler = V2EnvironmentHandler()
27         env_init_data = {
28             'name': name,
29             'uuid': env_id
30         }
31         environment_handler.insert(env_init_data)
32
33         return result_handler(consts.API_SUCCESS, {'uuid': env_id})