Put vnf_test pass if more than 80% of vnf test result are OK
[functest.git] / functest / api / resources / v1 / envs.py
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8
9 """
10 Resources to handle environment related requests
11 """
12
13 from flask import jsonify
14
15 from functest.api.base import ApiResource
16 from functest.cli.commands.cli_env import Env
17 from functest.api.common import api_utils
18 import functest.utils.functest_utils as ft_utils
19
20
21 class V1Envs(ApiResource):
22     """ V1Envs Resource class"""
23
24     def get(self):  # pylint: disable=no-self-use
25         """ Get environment """
26         environment_show = Env().show()
27         return jsonify(environment_show)
28
29     def post(self):
30         """ Used to handle post request """
31         return self._dispatch_post()
32
33     def prepare(self, args):  # pylint: disable=no-self-use, unused-argument
34         """ Prepare environment """
35         try:
36             ft_utils.execute_command("prepare_env start")
37         except Exception as err:  # pylint: disable=broad-except
38             return api_utils.result_handler(status=1, data=str(err))
39         return api_utils.result_handler(
40             status=0, data="Prepare env successfully")