Exemplo n.º 1
0
    def get(self):
        """
        backup the profile
        """
        result = {}
        args = PROFILE_GET_PARSER.parse_args()
        current_app.logger.info(args)
        section = args.get(self.section).upper()
        config = args.get("config")
        backup_dir = args.get("path")

        modules = section.split(".")
        submodule = modules[1] if len(modules) > 1 else None
        configurators = CPI.get_configurators(modules[0], submodule)

        if len(configurators) < 1:
            result["status"] = "FAILED"
            result["value"] = "module: {}, submodule: {} is not exist".format(
                modules[0], submodule)
            return result, 200

        configurator = configurators[0]
        real_value = configurator.backup(config, backup_dir)
        if isinstance(real_value, Exception):
            result["status"] = "FAILED"
            result["value"] = str(real_value)
        else:
            if real_value is None:
                result["status"] = "FAILED"
                result["value"] = "UNKNOWN"
            else:
                result["status"] = "SUCCESS"
                result["value"] = real_value

        return result, 200
Exemplo n.º 2
0
    def put(self):
        """
        resume the profile
        """
        result = {}
        args = PROFILE_PUT_PARSER.parse_args()
        current_app.logger.info(args)
        section = args.get(self.section).upper()
        modules = section.split(".")
        submodule = None
        if len(modules) > 1:
            submodule = modules[1]
        configurators = CPI.get_configurators(modules[0], submodule)
        if len(configurators) < 1:
            abort(404)

        configurator = configurators[0]

        config = args.get("config")
        ret = configurator.resume(config)
        if ret is not None:
            result["status"] = str(ret)
        else:
            result["status"] = "OK"

        return result, 200
Exemplo n.º 3
0
    def get(self):
        """
        calling the cpi check method to check the value of the given key
        :param section:  The section of the cpi
        :param key: the key to be get
        :returns status: the status compare the expect value with the real value
        :returns value: the system real value
        """
        result = {}
        args = CONFIGURATOR_GET_PARSER.parse_args()
        current_app.logger.info(args)
        section = args.get(self.section).upper()
        key = args.get("key")

        modules = section.split(".")
        submodule = modules[1] if len(modules) > 1 else modules[0]

        configurators = CPI.get_configurators(modules[0], submodule)
        if len(configurators) < 1:
            abort(404)

        configurator = configurators[0]
        real_value = configurator.get(key)
        if isinstance(real_value, Exception):
            result["value"] = str(real_value)
            result["status"] = "FAILED"
            return result, 200

        result["value"] = real_value
        result["status"] = "OK"

        return result, 200
Exemplo n.º 4
0
    def put(self):
        """
        calling cpi set method to set the value of the given key
        :param section:  The section of the cpi
        :param key: the key to be set
        :param value: the value of the given key
        :returns status: the status return by the cpi set method
        :returns value: the message return by the cpi set method
        """
        result = {}
        args = PROPERTY_PUT_PARSER.parse_args()
        current_app.logger.info(args)
        section = args.get(self.section).upper()
        modules = section.split(".")
        submodule = None
        if len(modules) > 1:
            submodule = modules[1]
        configurators = CPI.get_configurators(modules[0], submodule)
        if len(configurators) < 1:
            result["status"] = "module %s is not exist" % (section)
            return result, 200
        configurator = configurators[0]

        key = args.get("key")
        value = args.get("value")
        params = key + "=" + value
        ret = configurator.set(params)
        if not ret:
            result["status"] = "OK"
        elif isinstance(ret, Warning):
            result["status"] = "WARNING"
            result["value"] = str(ret)
        elif isinstance(ret, Exception):
            result["status"] = "ERROR"
            result["value"] = str(ret)

        return result, 200
Exemplo n.º 5
0
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v2 for more details.
# Create: 2019-10-29
"""
Temporary tool to generate the api help info, will be replaced by Sphinx.
"""

import sys

sys.path.insert(0, "./../")
from analysis.plugin.plugin import CPI, MPI

print("The CPI & MPI api manual")
print("========================\n")

CPI_HELP = CPI()
help(CPI_HELP)

CPIS_HELP = CPI_HELP.get_configurators()
for i in CPIS_HELP:
    help(i)

MPI_HELP = MPI()
help(MPI_HELP)

MPIS_HELP = MPI_HELP.get_monitors()
for i in MPIS_HELP:
    help(i)
Exemplo n.º 6
0
Tool to generate an example of profile configuration.
"""

import sys

sys.path.insert(0, "./../")
from analysis.plugin.plugin import CPI

print("#")
print("# example of atuned profile configuration")
print("#\n")

GLOBAL_SECTIONS = (("main", "list it's parent profile"), (
    "tip", "the recommended optimization, which should be performed manunaly"),
                   ("check", "check the environment"))

for i in GLOBAL_SECTIONS:
    print("[{}]".format(i[0]))
    print("# {}".format(i[1]))
    print("\n")

CPI_INSTANCE = CPI()
CPIS = CPI_INSTANCE.get_configurators()
for i in CPIS:
    if i.module() == i.submod():
        print("[{}]".format(i.module().lower()))
    else:
        print("[{}.{}]".format(i.module().lower(), i.submod().lower()))
    print("# {}".format(i.__doc__.lower()))
    print("\n")